Fix cos computation for multiple precision fallback (bz #20357)

Message ID 1468313523-18716-1-git-send-email-siddhesh@sourceware.org
State Committed
Headers

Commit Message

Siddhesh Poyarekar July 12, 2016, 8:52 a.m. UTC
  During the sincos consolidation I made two mistakes, one was a logical
error due to which cos(0x1.8475e5afd4481p+0) returned
sin(0x1.8475e5afd4481p+0) instead.

The second issue was an error in negating inputs for the correct
quadrants for sine.  I could not find a suitable test case for this
despite running a program to search for such an input for a couple of
hours.

Following patch fixes both issues.  Tested on x86_64.  Thanks to Matt
(Clay?) for identifying the issue.

	[BZ #20357]
	* sysdeps/ieee754/dbl-64/s_sin.c (sloww): Fix up condition
	to call __mpsin/__mpcos and to negate values.
	* math/auto-libm-test-in: Add test.
	* math/auto-libm-test-out: Regenerate.
---
 math/auto-libm-test-in         |   3 +
 math/auto-libm-test-out        | 207 +++++++++++++++++++++++++++++++++++++++++
 sysdeps/ieee754/dbl-64/s_sin.c |   4 +-
 3 files changed, 212 insertions(+), 2 deletions(-)
  

Comments

Siddhesh Poyarekar July 13, 2016, 10:43 a.m. UTC | #1
On Tue, Jul 12, 2016 at 02:22:03PM +0530, Siddhesh Poyarekar wrote:
> During the sincos consolidation I made two mistakes, one was a logical
> error due to which cos(0x1.8475e5afd4481p+0) returned
> sin(0x1.8475e5afd4481p+0) instead.
> 
> The second issue was an error in negating inputs for the correct
> quadrants for sine.  I could not find a suitable test case for this
> despite running a program to search for such an input for a couple of
> hours.

FYI, I have added this as a blocker for 2.24.

Siddhesh
  
Siddhesh Poyarekar July 18, 2016, 10:02 a.m. UTC | #2
Ping!

On Wed, Jul 13, 2016 at 04:13:25PM +0530, Siddhesh Poyarekar wrote:
> On Tue, Jul 12, 2016 at 02:22:03PM +0530, Siddhesh Poyarekar wrote:
> > During the sincos consolidation I made two mistakes, one was a logical
> > error due to which cos(0x1.8475e5afd4481p+0) returned
> > sin(0x1.8475e5afd4481p+0) instead.
> > 
> > The second issue was an error in negating inputs for the correct
> > quadrants for sine.  I could not find a suitable test case for this
> > despite running a program to search for such an input for a couple of
> > hours.
> 
> FYI, I have added this as a blocker for 2.24.
> 
> Siddhesh
  
Paul E. Murphy July 18, 2016, 2:47 p.m. UTC | #3
On 07/12/2016 03:52 AM, Siddhesh Poyarekar wrote:
> During the sincos consolidation I made two mistakes, one was a logical
> error due to which cos(0x1.8475e5afd4481p+0) returned
> sin(0x1.8475e5afd4481p+0) instead.
> 
> The second issue was an error in negating inputs for the correct
> quadrants for sine.  I could not find a suitable test case for this
> despite running a program to search for such an input for a couple of
> hours.
> 
> Following patch fixes both issues.  Tested on x86_64.  Thanks to Matt
> (Clay?) for identifying the issue.
> 
> 	[BZ #20357]
> 	* sysdeps/ieee754/dbl-64/s_sin.c (sloww): Fix up condition
> 	to call __mpsin/__mpcos and to negate values.
> 	* math/auto-libm-test-in: Add test.
> 	* math/auto-libm-test-out: Regenerate.
> ---
>  math/auto-libm-test-in         |   3 +
>  math/auto-libm-test-out        | 207 +++++++++++++++++++++++++++++++++++++++++
>  sysdeps/ieee754/dbl-64/s_sin.c |   4 +-
>  3 files changed, 212 insertions(+), 2 deletions(-)
> 
> diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
> index ffcc40a..51c152c 100644
> --- a/math/auto-libm-test-in
> +++ b/math/auto-libm-test-in
> @@ -1144,6 +1144,7 @@ cos 0x4.7857dp+68
>  cos -0x1.02e34cp+0
>  cos 0xf.f0274p+4
>  cos 0x3.042d88p+0
> +cos 0x1.8475e5afd4481p+0
> 
>  cosh 0
>  cosh -0
> @@ -3818,6 +3819,7 @@ sin min
>  sin -min
>  sin min_subnorm
>  sin -min_subnorm
> +sin 0x1.8475e5afd4481p+0
> 
>  sincos 0
>  sincos -0
> @@ -3852,6 +3854,7 @@ sincos min
>  sincos -min
>  sincos min_subnorm
>  sincos -min_subnorm
> +sincos 0x1.8475e5afd4481p+0
> 
>  sinh 0
>  sinh -0

Ok.

> diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
> index ca2532f..7c9a079 100644
> --- a/sysdeps/ieee754/dbl-64/s_sin.c
> +++ b/sysdeps/ieee754/dbl-64/s_sin.c
> @@ -803,7 +803,7 @@ sloww (double x, double dx, double orig, int k)
>    a = t - y;
>    da = ((t - a) - y) + da;
> 
> -  if (n == 2 || n == 1)
> +  if (n & 2)

That looks ok.  I had to do double check the unification.  It wasn't
immediately obvious this was correct.

>      {
>        a = -a;
>        da = -da;
> @@ -817,7 +817,7 @@ sloww (double x, double dx, double orig, int k)
>    if (w[0] == w[0] + cor)
>      return (a > 0) ? w[0] : -w[0];
> 
> -  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
> +  return k ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);

OK, that fix looks fairly obvious after reviewing commit
b300455644e2945da05eb49d12d3a037f1408be1.
  
Siddhesh Poyarekar July 18, 2016, 3:59 p.m. UTC | #4
On Mon, Jul 18, 2016 at 09:47:43AM -0500, Paul E. Murphy wrote:
> > diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
> > index ca2532f..7c9a079 100644
> > --- a/sysdeps/ieee754/dbl-64/s_sin.c
> > +++ b/sysdeps/ieee754/dbl-64/s_sin.c
> > @@ -803,7 +803,7 @@ sloww (double x, double dx, double orig, int k)
> >    a = t - y;
> >    da = ((t - a) - y) + da;
> > 
> > -  if (n == 2 || n == 1)
> > +  if (n & 2)
> 
> That looks ok.  I had to do double check the unification.  It wasn't
> immediately obvious this was correct.

Yeah, the n == 1 check in csloww had thrown me off the last time - it
is because the input to csloww was always in quadrant 0 or 1 (0.855469
<|x| <2.426265) and hence the check for n == 2 is unnecessary in that
context.  Rotating that by pi/2 for sin is consistent with the n & 2
check.

> > @@ -817,7 +817,7 @@ sloww (double x, double dx, double orig, int k)
> >    if (w[0] == w[0] + cor)
> >      return (a > 0) ? w[0] : -w[0];
> > 
> > -  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
> > +  return k ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
> 
> OK, that fix looks fairly obvious after reviewing commit
> b300455644e2945da05eb49d12d3a037f1408be1.

Thanks.  Adhemerval, do you want to take another look at this or is it
OK if I commit it?

Siddhesh
  
Adhemerval Zanella Netto July 18, 2016, 4:53 p.m. UTC | #5
On 18/07/2016 12:59, Siddhesh Poyarekar wrote:
> On Mon, Jul 18, 2016 at 09:47:43AM -0500, Paul E. Murphy wrote:
>>> diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
>>> index ca2532f..7c9a079 100644
>>> --- a/sysdeps/ieee754/dbl-64/s_sin.c
>>> +++ b/sysdeps/ieee754/dbl-64/s_sin.c
>>> @@ -803,7 +803,7 @@ sloww (double x, double dx, double orig, int k)
>>>    a = t - y;
>>>    da = ((t - a) - y) + da;
>>>
>>> -  if (n == 2 || n == 1)
>>> +  if (n & 2)
>>
>> That looks ok.  I had to do double check the unification.  It wasn't
>> immediately obvious this was correct.
> 
> Yeah, the n == 1 check in csloww had thrown me off the last time - it
> is because the input to csloww was always in quadrant 0 or 1 (0.855469
> <|x| <2.426265) and hence the check for n == 2 is unnecessary in that
> context.  Rotating that by pi/2 for sin is consistent with the n & 2
> check.
> 
>>> @@ -817,7 +817,7 @@ sloww (double x, double dx, double orig, int k)
>>>    if (w[0] == w[0] + cor)
>>>      return (a > 0) ? w[0] : -w[0];
>>>
>>> -  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
>>> +  return k ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
>>
>> OK, that fix looks fairly obvious after reviewing commit
>> b300455644e2945da05eb49d12d3a037f1408be1.
> 
> Thanks.  Adhemerval, do you want to take another look at this or is it
> OK if I commit it?

LGTM!
  

Patch

diff --git a/math/auto-libm-test-in b/math/auto-libm-test-in
index ffcc40a..51c152c 100644
--- a/math/auto-libm-test-in
+++ b/math/auto-libm-test-in
@@ -1144,6 +1144,7 @@  cos 0x4.7857dp+68
 cos -0x1.02e34cp+0
 cos 0xf.f0274p+4
 cos 0x3.042d88p+0
+cos 0x1.8475e5afd4481p+0
 
 cosh 0
 cosh -0
@@ -3818,6 +3819,7 @@  sin min
 sin -min
 sin min_subnorm
 sin -min_subnorm
+sin 0x1.8475e5afd4481p+0
 
 sincos 0
 sincos -0
@@ -3852,6 +3854,7 @@  sincos min
 sincos -min
 sincos min_subnorm
 sincos -min_subnorm
+sincos 0x1.8475e5afd4481p+0
 
 sinh 0
 sinh -0
diff --git a/math/auto-libm-test-out b/math/auto-libm-test-out
index c07978e..f727cf0 100644
--- a/math/auto-libm-test-out
+++ b/math/auto-libm-test-out
@@ -103416,6 +103416,75 @@  cos 0x3.042d88p+0
 = cos tonearest ibm128 0x3.042d88p+0 : -0xf.dfe6f2169e24f276e8027d91bcp-4 : inexact-ok
 = cos towardzero ibm128 0x3.042d88p+0 : -0xf.dfe6f2169e24f276e8027d91b8p-4 : inexact-ok
 = cos upward ibm128 0x3.042d88p+0 : -0xf.dfe6f2169e24f276e8027d91b8p-4 : inexact-ok
+cos 0x1.8475e5afd4481p+0
+= cos downward binary32 0x1.8475e6p+0 : 0xd.a8263p-8 : inexact-ok
+= cos tonearest binary32 0x1.8475e6p+0 : 0xd.a8263p-8 : inexact-ok
+= cos towardzero binary32 0x1.8475e6p+0 : 0xd.a8263p-8 : inexact-ok
+= cos upward binary32 0x1.8475e6p+0 : 0xd.a8264p-8 : inexact-ok
+= cos downward binary64 0x1.8475e6p+0 : 0xd.a8263394be6dp-8 : inexact-ok
+= cos tonearest binary64 0x1.8475e6p+0 : 0xd.a8263394be6dp-8 : inexact-ok
+= cos towardzero binary64 0x1.8475e6p+0 : 0xd.a8263394be6dp-8 : inexact-ok
+= cos upward binary64 0x1.8475e6p+0 : 0xd.a8263394be6d8p-8 : inexact-ok
+= cos downward intel96 0x1.8475e6p+0 : 0xd.a8263394be6d0e5p-8 : inexact-ok
+= cos tonearest intel96 0x1.8475e6p+0 : 0xd.a8263394be6d0e6p-8 : inexact-ok
+= cos towardzero intel96 0x1.8475e6p+0 : 0xd.a8263394be6d0e5p-8 : inexact-ok
+= cos upward intel96 0x1.8475e6p+0 : 0xd.a8263394be6d0e6p-8 : inexact-ok
+= cos downward m68k96 0x1.8475e6p+0 : 0xd.a8263394be6d0e5p-8 : inexact-ok
+= cos tonearest m68k96 0x1.8475e6p+0 : 0xd.a8263394be6d0e6p-8 : inexact-ok
+= cos towardzero m68k96 0x1.8475e6p+0 : 0xd.a8263394be6d0e5p-8 : inexact-ok
+= cos upward m68k96 0x1.8475e6p+0 : 0xd.a8263394be6d0e6p-8 : inexact-ok
+= cos downward binary128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= cos tonearest binary128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= cos towardzero binary128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= cos upward binary128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3ba8p-8 : inexact-ok
+= cos downward ibm128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a38p-8 : inexact-ok
+= cos tonearest ibm128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3cp-8 : inexact-ok
+= cos towardzero ibm128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a38p-8 : inexact-ok
+= cos upward ibm128 0x1.8475e6p+0 : 0xd.a8263394be6d0e58c1c35a8a3cp-8 : inexact-ok
+= cos downward binary32 0x1.8475e4p+0 : 0xd.a8283p-8 : inexact-ok
+= cos tonearest binary32 0x1.8475e4p+0 : 0xd.a8283p-8 : inexact-ok
+= cos towardzero binary32 0x1.8475e4p+0 : 0xd.a8283p-8 : inexact-ok
+= cos upward binary32 0x1.8475e4p+0 : 0xd.a8284p-8 : inexact-ok
+= cos downward binary64 0x1.8475e4p+0 : 0xd.a82832da19f98p-8 : inexact-ok
+= cos tonearest binary64 0x1.8475e4p+0 : 0xd.a82832da19f98p-8 : inexact-ok
+= cos towardzero binary64 0x1.8475e4p+0 : 0xd.a82832da19f98p-8 : inexact-ok
+= cos upward binary64 0x1.8475e4p+0 : 0xd.a82832da19fap-8 : inexact-ok
+= cos downward intel96 0x1.8475e4p+0 : 0xd.a82832da19f9891p-8 : inexact-ok
+= cos tonearest intel96 0x1.8475e4p+0 : 0xd.a82832da19f9892p-8 : inexact-ok
+= cos towardzero intel96 0x1.8475e4p+0 : 0xd.a82832da19f9891p-8 : inexact-ok
+= cos upward intel96 0x1.8475e4p+0 : 0xd.a82832da19f9892p-8 : inexact-ok
+= cos downward m68k96 0x1.8475e4p+0 : 0xd.a82832da19f9891p-8 : inexact-ok
+= cos tonearest m68k96 0x1.8475e4p+0 : 0xd.a82832da19f9892p-8 : inexact-ok
+= cos towardzero m68k96 0x1.8475e4p+0 : 0xd.a82832da19f9891p-8 : inexact-ok
+= cos upward m68k96 0x1.8475e4p+0 : 0xd.a82832da19f9892p-8 : inexact-ok
+= cos downward binary128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= cos tonearest binary128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= cos towardzero binary128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= cos upward binary128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= cos downward ibm128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa659cp-8 : inexact-ok
+= cos tonearest ibm128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= cos towardzero ibm128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa659cp-8 : inexact-ok
+= cos upward ibm128 0x1.8475e4p+0 : 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= cos downward binary64 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbe8p-8 : inexact-ok
+= cos tonearest binary64 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbe8p-8 : inexact-ok
+= cos towardzero binary64 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbe8p-8 : inexact-ok
+= cos upward binary64 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbfp-8 : inexact-ok
+= cos downward intel96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebffp-8 : inexact-ok
+= cos tonearest intel96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbecp-8 : inexact-ok
+= cos towardzero intel96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebffp-8 : inexact-ok
+= cos upward intel96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbecp-8 : inexact-ok
+= cos downward m68k96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebffp-8 : inexact-ok
+= cos tonearest m68k96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbecp-8 : inexact-ok
+= cos towardzero m68k96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebffp-8 : inexact-ok
+= cos upward m68k96 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbecp-8 : inexact-ok
+= cos downward binary128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= cos tonearest binary128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= cos towardzero binary128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= cos upward binary128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa296688p-8 : inexact-ok
+= cos downward ibm128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= cos tonearest ibm128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= cos towardzero ibm128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= cos upward ibm128 0x1.8475e5afd4481p+0 : 0xd.a82683a33cbebfffffffa2966cp-8 : inexact-ok
 cosh 0
 = cosh downward binary32 0x0p+0 : 0x1p+0 : inexact-ok
 = cosh tonearest binary32 0x0p+0 : 0x1p+0 : inexact-ok
@@ -264628,6 +264697,75 @@  sin -min_subnorm
 = sin tonearest binary128 -0x4p-16496 : -0x4p-16496 : inexact-ok underflow errno-erange-ok
 = sin towardzero binary128 -0x4p-16496 : -0x0p+0 : inexact-ok underflow errno-erange-ok
 = sin upward binary128 -0x4p-16496 : -0x0p+0 : inexact-ok underflow errno-erange-ok
+sin 0x1.8475e5afd4481p+0
+= sin downward binary32 0x1.8475e6p+0 : 0xf.fa2adp-4 : inexact-ok
+= sin tonearest binary32 0x1.8475e6p+0 : 0xf.fa2aep-4 : inexact-ok
+= sin towardzero binary32 0x1.8475e6p+0 : 0xf.fa2adp-4 : inexact-ok
+= sin upward binary32 0x1.8475e6p+0 : 0xf.fa2aep-4 : inexact-ok
+= sin downward binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 : inexact-ok
+= sin tonearest binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 : inexact-ok
+= sin towardzero binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 : inexact-ok
+= sin upward binary64 0x1.8475e6p+0 : 0xf.fa2add3e5895p-4 : inexact-ok
+= sin downward intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin tonearest intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin towardzero intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin upward intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d2p-4 : inexact-ok
+= sin downward m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin tonearest m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin towardzero m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 : inexact-ok
+= sin upward m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d2p-4 : inexact-ok
+= sin downward binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b5618p-4 : inexact-ok
+= sin tonearest binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b562p-4 : inexact-ok
+= sin towardzero binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b5618p-4 : inexact-ok
+= sin upward binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b562p-4 : inexact-ok
+= sin downward ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b54p-4 : inexact-ok
+= sin tonearest ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b58p-4 : inexact-ok
+= sin towardzero ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b54p-4 : inexact-ok
+= sin upward ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b58p-4 : inexact-ok
+= sin downward binary32 0x1.8475e4p+0 : 0xf.fa2adp-4 : inexact-ok
+= sin tonearest binary32 0x1.8475e4p+0 : 0xf.fa2aep-4 : inexact-ok
+= sin towardzero binary32 0x1.8475e4p+0 : 0xf.fa2adp-4 : inexact-ok
+= sin upward binary32 0x1.8475e4p+0 : 0xf.fa2aep-4 : inexact-ok
+= sin downward binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 : inexact-ok
+= sin tonearest binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 : inexact-ok
+= sin towardzero binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 : inexact-ok
+= sin upward binary64 0x1.8475e4p+0 : 0xf.fa2adb8953ae8p-4 : inexact-ok
+= sin downward intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin tonearest intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin towardzero intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin upward intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae263p-4 : inexact-ok
+= sin downward m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin tonearest m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin towardzero m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 : inexact-ok
+= sin upward m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae263p-4 : inexact-ok
+= sin downward binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6b8p-4 : inexact-ok
+= sin tonearest binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6cp-4 : inexact-ok
+= sin towardzero binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6b8p-4 : inexact-ok
+= sin upward binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6cp-4 : inexact-ok
+= sin downward ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f4p-4 : inexact-ok
+= sin tonearest ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f8p-4 : inexact-ok
+= sin towardzero ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f4p-4 : inexact-ok
+= sin upward ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f8p-4 : inexact-ok
+= sin downward binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea838p-4 : inexact-ok
+= sin tonearest binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea84p-4 : inexact-ok
+= sin towardzero binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea838p-4 : inexact-ok
+= sin upward binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea84p-4 : inexact-ok
+= sin downward intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 : inexact-ok
+= sin tonearest intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 : inexact-ok
+= sin towardzero intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 : inexact-ok
+= sin upward intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 : inexact-ok
+= sin downward m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 : inexact-ok
+= sin tonearest m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 : inexact-ok
+= sin towardzero m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 : inexact-ok
+= sin upward m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 : inexact-ok
+= sin downward binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea68p-4 : inexact-ok
+= sin tonearest binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea7p-4 : inexact-ok
+= sin towardzero binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea68p-4 : inexact-ok
+= sin upward binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea7p-4 : inexact-ok
+= sin downward ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455e8p-4 : inexact-ok
+= sin tonearest ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ecp-4 : inexact-ok
+= sin towardzero ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455e8p-4 : inexact-ok
+= sin upward ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ecp-4 : inexact-ok
 sincos 0
 = sincos downward binary32 0x0p+0 : 0x0p+0 0x1p+0 : inexact-ok
 = sincos tonearest binary32 0x0p+0 : 0x0p+0 0x1p+0 : inexact-ok
@@ -266725,6 +266863,75 @@  sincos -min_subnorm
 = sincos tonearest binary128 -0x4p-16496 : -0x4p-16496 0x1p+0 : inexact-ok underflow errno-erange-ok
 = sincos towardzero binary128 -0x4p-16496 : -0x0p+0 0xf.fffffffffffffffffffffffffff8p-4 : inexact-ok underflow errno-erange-ok
 = sincos upward binary128 -0x4p-16496 : -0x0p+0 0x1p+0 : inexact-ok underflow errno-erange-ok
+sincos 0x1.8475e5afd4481p+0
+= sincos downward binary32 0x1.8475e6p+0 : 0xf.fa2adp-4 0xd.a8263p-8 : inexact-ok
+= sincos tonearest binary32 0x1.8475e6p+0 : 0xf.fa2aep-4 0xd.a8263p-8 : inexact-ok
+= sincos towardzero binary32 0x1.8475e6p+0 : 0xf.fa2adp-4 0xd.a8263p-8 : inexact-ok
+= sincos upward binary32 0x1.8475e6p+0 : 0xf.fa2aep-4 0xd.a8264p-8 : inexact-ok
+= sincos downward binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 0xd.a8263394be6dp-8 : inexact-ok
+= sincos tonearest binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 0xd.a8263394be6dp-8 : inexact-ok
+= sincos towardzero binary64 0x1.8475e6p+0 : 0xf.fa2add3e58948p-4 0xd.a8263394be6dp-8 : inexact-ok
+= sincos upward binary64 0x1.8475e6p+0 : 0xf.fa2add3e5895p-4 0xd.a8263394be6d8p-8 : inexact-ok
+= sincos downward intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e5p-8 : inexact-ok
+= sincos tonearest intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e6p-8 : inexact-ok
+= sincos towardzero intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e5p-8 : inexact-ok
+= sincos upward intel96 0x1.8475e6p+0 : 0xf.fa2add3e58948d2p-4 0xd.a8263394be6d0e6p-8 : inexact-ok
+= sincos downward m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e5p-8 : inexact-ok
+= sincos tonearest m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e6p-8 : inexact-ok
+= sincos towardzero m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d1p-4 0xd.a8263394be6d0e5p-8 : inexact-ok
+= sincos upward m68k96 0x1.8475e6p+0 : 0xf.fa2add3e58948d2p-4 0xd.a8263394be6d0e6p-8 : inexact-ok
+= sincos downward binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b5618p-4 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= sincos tonearest binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b562p-4 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= sincos towardzero binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b5618p-4 0xd.a8263394be6d0e58c1c35a8a3bap-8 : inexact-ok
+= sincos upward binary128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b562p-4 0xd.a8263394be6d0e58c1c35a8a3ba8p-8 : inexact-ok
+= sincos downward ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b54p-4 0xd.a8263394be6d0e58c1c35a8a38p-8 : inexact-ok
+= sincos tonearest ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b58p-4 0xd.a8263394be6d0e58c1c35a8a3cp-8 : inexact-ok
+= sincos towardzero ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b54p-4 0xd.a8263394be6d0e58c1c35a8a38p-8 : inexact-ok
+= sincos upward ibm128 0x1.8475e6p+0 : 0xf.fa2add3e58948d10238cc27b58p-4 0xd.a8263394be6d0e58c1c35a8a3cp-8 : inexact-ok
+= sincos downward binary32 0x1.8475e4p+0 : 0xf.fa2adp-4 0xd.a8283p-8 : inexact-ok
+= sincos tonearest binary32 0x1.8475e4p+0 : 0xf.fa2aep-4 0xd.a8283p-8 : inexact-ok
+= sincos towardzero binary32 0x1.8475e4p+0 : 0xf.fa2adp-4 0xd.a8283p-8 : inexact-ok
+= sincos upward binary32 0x1.8475e4p+0 : 0xf.fa2aep-4 0xd.a8284p-8 : inexact-ok
+= sincos downward binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 0xd.a82832da19f98p-8 : inexact-ok
+= sincos tonearest binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 0xd.a82832da19f98p-8 : inexact-ok
+= sincos towardzero binary64 0x1.8475e4p+0 : 0xf.fa2adb8953aep-4 0xd.a82832da19f98p-8 : inexact-ok
+= sincos upward binary64 0x1.8475e4p+0 : 0xf.fa2adb8953ae8p-4 0xd.a82832da19fap-8 : inexact-ok
+= sincos downward intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9891p-8 : inexact-ok
+= sincos tonearest intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9892p-8 : inexact-ok
+= sincos towardzero intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9891p-8 : inexact-ok
+= sincos upward intel96 0x1.8475e4p+0 : 0xf.fa2adb8953ae263p-4 0xd.a82832da19f9892p-8 : inexact-ok
+= sincos downward m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9891p-8 : inexact-ok
+= sincos tonearest m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9892p-8 : inexact-ok
+= sincos towardzero m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae262p-4 0xd.a82832da19f9891p-8 : inexact-ok
+= sincos upward m68k96 0x1.8475e4p+0 : 0xf.fa2adb8953ae263p-4 0xd.a82832da19f9892p-8 : inexact-ok
+= sincos downward binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6b8p-4 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= sincos tonearest binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6cp-4 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= sincos towardzero binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6b8p-4 0xd.a82832da19f9891d9762fa659ff8p-8 : inexact-ok
+= sincos upward binary128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f6cp-4 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= sincos downward ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f4p-4 0xd.a82832da19f9891d9762fa659cp-8 : inexact-ok
+= sincos tonearest ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f8p-4 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= sincos towardzero ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f4p-4 0xd.a82832da19f9891d9762fa659cp-8 : inexact-ok
+= sincos upward ibm128 0x1.8475e4p+0 : 0xf.fa2adb8953ae26229c919ec8f8p-4 0xd.a82832da19f9891d9762fa65ap-8 : inexact-ok
+= sincos downward binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea838p-4 0xd.a82683a33cbe8p-8 : inexact-ok
+= sincos tonearest binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea84p-4 0xd.a82683a33cbe8p-8 : inexact-ok
+= sincos towardzero binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea838p-4 0xd.a82683a33cbe8p-8 : inexact-ok
+= sincos upward binary64 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea84p-4 0xd.a82683a33cbfp-8 : inexact-ok
+= sincos downward intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 0xd.a82683a33cbebffp-8 : inexact-ok
+= sincos tonearest intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 0xd.a82683a33cbecp-8 : inexact-ok
+= sincos towardzero intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 0xd.a82683a33cbebffp-8 : inexact-ok
+= sincos upward intel96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 0xd.a82683a33cbecp-8 : inexact-ok
+= sincos downward m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 0xd.a82683a33cbebffp-8 : inexact-ok
+= sincos tonearest m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 0xd.a82683a33cbecp-8 : inexact-ok
+= sincos towardzero m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdp-4 0xd.a82683a33cbebffp-8 : inexact-ok
+= sincos upward m68k96 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbep-4 0xd.a82683a33cbecp-8 : inexact-ok
+= sincos downward binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea68p-4 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= sincos tonearest binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea7p-4 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= sincos towardzero binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea68p-4 0xd.a82683a33cbebfffffffa2966878p-8 : inexact-ok
+= sincos upward binary128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ea7p-4 0xd.a82683a33cbebfffffffa296688p-8 : inexact-ok
+= sincos downward ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455e8p-4 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= sincos tonearest ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ecp-4 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= sincos towardzero ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455e8p-4 0xd.a82683a33cbebfffffffa29668p-8 : inexact-ok
+= sincos upward ibm128 0x1.8475e5afd4481p+0 : 0xf.fa2adcf9ea83dbdd053ee455ecp-4 0xd.a82683a33cbebfffffffa2966cp-8 : inexact-ok
 sinh 0
 = sinh downward binary32 0x0p+0 : 0x0p+0 : inexact-ok
 = sinh tonearest binary32 0x0p+0 : 0x0p+0 : inexact-ok
diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
index ca2532f..7c9a079 100644
--- a/sysdeps/ieee754/dbl-64/s_sin.c
+++ b/sysdeps/ieee754/dbl-64/s_sin.c
@@ -803,7 +803,7 @@  sloww (double x, double dx, double orig, int k)
   a = t - y;
   da = ((t - a) - y) + da;
 
-  if (n == 2 || n == 1)
+  if (n & 2)
     {
       a = -a;
       da = -da;
@@ -817,7 +817,7 @@  sloww (double x, double dx, double orig, int k)
   if (w[0] == w[0] + cor)
     return (a > 0) ? w[0] : -w[0];
 
-  return (n & 1) ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
+  return k ? __mpcos (orig, 0, true) : __mpsin (orig, 0, true);
 }
 
 /***************************************************************************/