Skip to content

Commit

Permalink
Fix tanf spurious underflows (bug 18221).
Browse files Browse the repository at this point in the history
The flt-32 implementation of tanf produces spurious underflow
exceptions for some small arguments, through computing values on the
order of x^5.  This patch fixes this by adjusting the threshold for
returning x (or, as applicable, +/- 1/x) to 2**-13 (the next term in
the power series being x^3/3).

Tested for x86_64 and x86.

	[BZ #18221]
	* sysdeps/ieee754/flt-32/k_tanf.c (__kernel_tanf): Use 2**-13 not
	2**-28 as threshold for returning x or +/- 1/x.
	* math/auto-libm-test-in: Add more tests of tan.
	* math/auto-libm-test-out: Regenerated.
  • Loading branch information
Joseph Myers committed May 15, 2015
1 parent ff069f0 commit 5a608cc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
2015-05-15 Joseph Myers <joseph@codesourcery.com>

[BZ #18221]
* sysdeps/ieee754/flt-32/k_tanf.c (__kernel_tanf): Use 2**-13 not
2**-28 as threshold for returning x or +/- 1/x.
* math/auto-libm-test-in: Add more tests of tan.
* math/auto-libm-test-out: Regenerated.

[BZ #18220]
* sysdeps/ieee754/flt-32/e_lgammaf_r.c (__ieee754_lgammaf_r): Use
2**26 not 2**58 as threshold for returning x * (log (x) - 1).
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Version 2.22
17999, 18007, 18019, 18020, 18029, 18030, 18032, 18036, 18038, 18039,
18042, 18043, 18046, 18047, 18068, 18080, 18093, 18100, 18104, 18110,
18111, 18125, 18128, 18138, 18185, 18196, 18197, 18206, 18210, 18211,
18217, 18220, 18247, 18287, 18319, 18333, 18346, 18397, 18409.
18217, 18220, 18221, 18247, 18287, 18319, 18333, 18346, 18397, 18409.

* Cache information can be queried via sysconf() function on s390 e.g. with
_SC_LEVEL1_ICACHE_SIZE as argument.
Expand Down
2 changes: 2 additions & 0 deletions math/auto-libm-test-in
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,8 @@ tan pi/4
tan 0.75
tan 0x1p65
tan -0x1p65
tan 0x1p-27
tan -0x1p-27
tan 0xc.9p-4
tan 0xc.908p-4
tan 0xc.90cp-4
Expand Down
50 changes: 50 additions & 0 deletions math/auto-libm-test-out
Original file line number Diff line number Diff line change
Expand Up @@ -186618,6 +186618,56 @@ tan -0x1p65
= tan tonearest ldbl-128ibm -0x2p+64L : 0xc.17b0bfdb2b8061e7b11d500874p-8L : inexact-ok
= tan towardzero ldbl-128ibm -0x2p+64L : 0xc.17b0bfdb2b8061e7b11d50087p-8L : inexact-ok
= tan upward ldbl-128ibm -0x2p+64L : 0xc.17b0bfdb2b8061e7b11d500874p-8L : inexact-ok
tan 0x1p-27
= tan downward flt-32 0x2p-28f : 0x2p-28f : inexact-ok
= tan tonearest flt-32 0x2p-28f : 0x2p-28f : inexact-ok
= tan towardzero flt-32 0x2p-28f : 0x2p-28f : inexact-ok
= tan upward flt-32 0x2p-28f : 0x2.000004p-28f : inexact-ok
= tan downward dbl-64 0x2p-28 : 0x2p-28 : inexact-ok
= tan tonearest dbl-64 0x2p-28 : 0x2p-28 : inexact-ok
= tan towardzero dbl-64 0x2p-28 : 0x2p-28 : inexact-ok
= tan upward dbl-64 0x2p-28 : 0x2.0000000000002p-28 : inexact-ok
= tan downward ldbl-96-intel 0x2p-28L : 0x2.00000000000002a8p-28L : inexact-ok
= tan tonearest ldbl-96-intel 0x2p-28L : 0x2.00000000000002acp-28L : inexact-ok
= tan towardzero ldbl-96-intel 0x2p-28L : 0x2.00000000000002a8p-28L : inexact-ok
= tan upward ldbl-96-intel 0x2p-28L : 0x2.00000000000002acp-28L : inexact-ok
= tan downward ldbl-96-m68k 0x2p-28L : 0x2.00000000000002a8p-28L : inexact-ok
= tan tonearest ldbl-96-m68k 0x2p-28L : 0x2.00000000000002acp-28L : inexact-ok
= tan towardzero ldbl-96-m68k 0x2p-28L : 0x2.00000000000002a8p-28L : inexact-ok
= tan upward ldbl-96-m68k 0x2p-28L : 0x2.00000000000002acp-28L : inexact-ok
= tan downward ldbl-128 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan tonearest ldbl-128 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan towardzero ldbl-128 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan upward ldbl-128 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaabp-28L : inexact-ok
= tan downward ldbl-128ibm 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaap-28L : inexact-ok
= tan tonearest ldbl-128ibm 0x2p-28L : 0x2.00000000000002aaaaaaaaaaabp-28L : inexact-ok
= tan towardzero ldbl-128ibm 0x2p-28L : 0x2.00000000000002aaaaaaaaaaaap-28L : inexact-ok
= tan upward ldbl-128ibm 0x2p-28L : 0x2.00000000000002aaaaaaaaaaabp-28L : inexact-ok
tan -0x1p-27
= tan downward flt-32 -0x2p-28f : -0x2.000004p-28f : inexact-ok
= tan tonearest flt-32 -0x2p-28f : -0x2p-28f : inexact-ok
= tan towardzero flt-32 -0x2p-28f : -0x2p-28f : inexact-ok
= tan upward flt-32 -0x2p-28f : -0x2p-28f : inexact-ok
= tan downward dbl-64 -0x2p-28 : -0x2.0000000000002p-28 : inexact-ok
= tan tonearest dbl-64 -0x2p-28 : -0x2p-28 : inexact-ok
= tan towardzero dbl-64 -0x2p-28 : -0x2p-28 : inexact-ok
= tan upward dbl-64 -0x2p-28 : -0x2p-28 : inexact-ok
= tan downward ldbl-96-intel -0x2p-28L : -0x2.00000000000002acp-28L : inexact-ok
= tan tonearest ldbl-96-intel -0x2p-28L : -0x2.00000000000002acp-28L : inexact-ok
= tan towardzero ldbl-96-intel -0x2p-28L : -0x2.00000000000002a8p-28L : inexact-ok
= tan upward ldbl-96-intel -0x2p-28L : -0x2.00000000000002a8p-28L : inexact-ok
= tan downward ldbl-96-m68k -0x2p-28L : -0x2.00000000000002acp-28L : inexact-ok
= tan tonearest ldbl-96-m68k -0x2p-28L : -0x2.00000000000002acp-28L : inexact-ok
= tan towardzero ldbl-96-m68k -0x2p-28L : -0x2.00000000000002a8p-28L : inexact-ok
= tan upward ldbl-96-m68k -0x2p-28L : -0x2.00000000000002a8p-28L : inexact-ok
= tan downward ldbl-128 -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaabp-28L : inexact-ok
= tan tonearest ldbl-128 -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan towardzero ldbl-128 -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan upward ldbl-128 -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaaaep-28L : inexact-ok
= tan downward ldbl-128ibm -0x2p-28L : -0x2.00000000000002aaaaaaaaaaabp-28L : inexact-ok
= tan tonearest ldbl-128ibm -0x2p-28L : -0x2.00000000000002aaaaaaaaaaabp-28L : inexact-ok
= tan towardzero ldbl-128ibm -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaap-28L : inexact-ok
= tan upward ldbl-128ibm -0x2p-28L : -0x2.00000000000002aaaaaaaaaaaap-28L : inexact-ok
tan 0xc.9p-4
= tan downward flt-32 0xc.9p-4f : 0xf.fe04cp-4f : inexact-ok
= tan tonearest flt-32 0xc.9p-4f : 0xf.fe04dp-4f : inexact-ok
Expand Down
2 changes: 1 addition & 1 deletion sysdeps/ieee754/flt-32/k_tanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ float __kernel_tanf(float x, float y, int iy)
int32_t ix,hx;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x31800000) /* x < 2**-28 */
if(ix<0x39000000) /* x < 2**-13 */
{if((int)x==0) { /* generate inexact */
if((ix|(iy+1))==0) return one/fabsf(x);
else return (iy==1)? x: -one/x;
Expand Down

0 comments on commit 5a608cc

Please sign in to comment.