Re: math:exp() erlang bug on SPARC
Jesper Louis Andersen <[email protected]> Thu, 14 Apr 2016 13:24:36 +0200
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <CAGrdgiV255iN_Fxqh29=RjT3dyY2XNDcnK+J_VYm4MhxP=WsUg@mail.gmail.com> |
--===============9030107605780785249== Content-Type: multipart/alternative; boundary=001a1133665011f63a0530702629 --001a1133665011f63a0530702629 Content-Type: text/plain; charset=UTF-8 On Wed, Apr 13, 2016 at 3:46 PM, Matt Keenan <[email protected]> wrote: > Just wanted to report a SPARC specific issue with Erlang. I'm not entirely convinced it is with Erlang, so consider this inquiry. Sparc uses a 64bit wide internal representation of IEEE 754 double binary fp numbers, whereas the internal representation in x86 is 80 bit wide (due to that being the width of the 387 coprocessor back in the day). exp(-1162.102134881488) is 2.02048... x 10^-505 which is smaller than the smallest representable float. The limit, as x -> -infty is 0 for exp(_), so one would argue that the correct output in this case is 0.0. Erlang simply calls into the C math.h exp function for this, but it does FP exception checks around the point. One way to figure out what happens would be to get hold of a SPARC machine, write a simple C program doing the same and verifying that the SPARC compilers agrees on that one with an x86 program. I could imagine some way it provokes an FP exception on the SPARC architecture, but not on x86 due to the extra bits x86 has in internal encoding width. -- J. --001a1133665011f63a0530702629 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">= On Wed, Apr 13, 2016 at 3:46 PM, Matt Keenan <span dir=3D"ltr"><<a href= =3D"mailto:[email protected]" target=3D"_blank">[email protected]= </a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin= :0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"= >Just wanted to report a SPARC specific issue with Erlang.</blockquote></di= v><br></div><div class=3D"gmail_extra">I'm not entirely convinced it is= with Erlang, so consider this inquiry. Sparc uses a 64bit wide internal re= presentation of IEEE 754 double binary fp numbers, whereas the internal rep= resentation in x86 is 80 bit wide (due to that being the width of the 387 c= oprocessor back in the day).<br><br></div><div class=3D"gmail_extra">exp(-1= 162.102134881488)<br><br></div><div class=3D"gmail_extra">is 2.02048... x 1= 0^-505 which is smaller than the smallest representable float. The limit, a= s x -> -infty is 0 for exp(_), so one would argue that the correct outpu= t in this case is 0.0.<br><br></div><div class=3D"gmail_extra">Erlang simpl= y calls into the C math.h exp function for this, but it does FP exception c= hecks around the point. One way to figure out what happens would be to get = hold of a SPARC machine, write a simple C program doing the same and verify= ing that the SPARC compilers agrees on that one with an x86 program. I coul= d imagine some way it provokes an FP exception on the SPARC architecture, b= ut not on x86 due to the extra bits x86 has in internal encoding width.<br>= </div><div class=3D"gmail_extra"><br clear=3D"all"></div><div class=3D"gmai= l_extra">-- <br><div class=3D"gmail_signature">J.</div> </div></div> --001a1133665011f63a0530702629-- --===============9030107605780785249== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ erlang-bugs mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-bugs --===============9030107605780785249==--