This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix acos (-1) in round-downwards mode on x86 (bug 14034)


On 04/29/2012 05:01 PM, Joseph S. Myers wrote:
Bug 14034 is the problem that acos (-1) returns -pi instead of pi in
round-downwards mode, for x86 for all floating-point formats and for
x86_64 for long double (x86_64 #includes the x86 implementation of
acosl).  The ISO C requirement is that the result is always in the
range [0, pi].

The problem is that the fsqrt instruction follows the IEEE 754
requirement that sqrt(-0) is -0, and a previous subtraction resulted
in -0 (x-x is -0 in round-downwards mode), so the fpatan instruction
gets a -0 value where it needs a value without the sign bit set to
produce results in the correct quadrant.  I propose this patch fixing
this in the obvious way by taking the absolute values of the square
roots.  I've added tests for acos in all rounding modes - and for asin
although the similar square roots there do not cause any problems.

Tested x86 and x86_64 and ulps updated accordingly.

2012-04-29 Joseph Myers<joseph@codesourcery.com>

	[BZ #14034]
	* sysdeps/i386/fpu/e_acos.S (__ieee754_acos): Take absolute value
	of square root.
	* sysdeps/i386/fpu/e_acosf.S (__ieee754_acosf): Likewise.
	* sysdeps/i386/fpu/e_acosl.c (__ieee754_acosl): Likewise.
	* math/libm-test.inc (acos_test_tonearest): New function.
	(acos_test_towardzero): Likewise.
	(acos_test_downward): Likewise.
	(acos_test_upward): Likewise.
	(asin_test_tonearest): Likewise.
	(asin_test_towardzero): Likewise.
	(asin_test_downward): Likewise.
	(asin_test_upward): Likewise.
	(main): Call the new functions.
	* sysdeps/i386/fpu/libm-test-ulps: Update.
	* sysdeps/x86_64/fpu/libm-test-ulps: Update.

thanks, this is ok.


Andreas

--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]