amd64/144448: sin() broken in libm on amd64

Peter Jeremy peterjeremy at
Wed Mar 3 22:40:04 UTC 2010

The following reply was made to PR standards/144448; it has been noted by GNATS.

From: Peter Jeremy <peterjeremy at>
To: "Eugene M. Zheganin" <emz at>
Cc: freebsd-gnats-submit at
Subject: Re: amd64/144448: sin() broken in libm on amd64
Date: Thu, 4 Mar 2010 09:39:04 +1100

 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 On 2010-Mar-03 13:33:53 +0000, "Eugene M. Zheganin" <emz at> wro=
 >The following code, being compiled, is printing different results on
 >i386 and amd64 platforms. The result on amd64 is invalid.
 I agree they are different but why do you think the i386 result is valid?
 Between imperfect rounding of trig functions and throwing away high
 bits (when intermediate results are outside +/-pi), after iterating
 20 times, your result is not much better than noise in either case.
 Evaluating the following bc program at both scale=3D100 and scale=3D200
 gives the same output when truncated to ~73 digits:
 =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=
 prevval =3D 734
 curval =3D s(734)
 print "p",prevval, "\nc", curval, "\n"
 for (i =3D 0; i < 19; i++) {
  curval =3D 16 * curval
  prevval =3D curval
  curval =3D s(curval)
  print "p",prevval, "\nc", curval, "\n"
 =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=3D=3D 8-< =3D=3D=
 To demonstrate, save the above as sin.bc and run
 $ echo scale=3D100 | cat - sin.bc | BC_LINE_LENGTH=3D300 bc -l | cut -c 1-7=
 5 > sin.100
 $ echo scale=3D200 | cat - sin.bc | BC_LINE_LENGTH=3D300 bc -l | cut -c 1-7=
 5 > sin.200
 $ cmp sin.100 sin.200
 and the resultant files are identical - suggesting that the result is
 evaluated to sufficient accuracy.  I agree that this is not perfect
 but don't immediately have access to any other arbitrary-precision
 trig functions for cross-checking.
 The last few lines of the bc calculation are:
 This is nothing like the double-precision results from either i386
 or amd64.
 Peter Jeremy
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 Version: GnuPG v2.0.14 (FreeBSD)

More information about the freebsd-standards mailing list