* sysdeps/i386/fpu/s_tan.S: Set errno for ±Inf.
authorUlrich Drepper <drepper@redhat.com>
Sun, 26 Apr 2009 05:42:49 +0000 (05:42 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 26 Apr 2009 05:42:49 +0000 (05:42 +0000)
* sysdeps/i386/fpu/s_tanf.S: Likewise.
* sysdeps/i386/fpu/s_tanl.S: Likewise.
* sysdeps/ieee754/dbl-64/s_tan.c: Likewise.
* sysdeps/ieee754/flt-32/s_tanf.c: Likewise.
* sysdeps/x86_64/fpu/s_tanl.S: Likewise.
* math/libm-test.inc: Add tests for errno after tan calls with
±Inf.

ChangeLog
math/libm-test.inc
sysdeps/i386/fpu/s_tan.S
sysdeps/i386/fpu/s_tanf.S
sysdeps/i386/fpu/s_tanl.S
sysdeps/ieee754/dbl-64/s_tan.c
sysdeps/ieee754/flt-32/s_tanf.c
sysdeps/x86_64/fpu/s_tanl.S

index 3019b4b..9731ec6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-04-25  Ulrich Drepper  <drepper@redhat.com>
 
+       * sysdeps/i386/fpu/s_tan.S: Set errno for ±Inf.
+       * sysdeps/i386/fpu/s_tanf.S: Likewise.
+       * sysdeps/i386/fpu/s_tanl.S: Likewise.
+       * sysdeps/ieee754/dbl-64/s_tan.c: Likewise.
+       * sysdeps/ieee754/flt-32/s_tanf.c: Likewise.
+       * sysdeps/x86_64/fpu/s_tanl.S: Likewise.
+       * math/libm-test.inc: Add tests for errno after tan calls with
+       ±Inf.
+
        * sysdeps/ieee754/k_standard.c (__kernel_standard): Use correct
        errno value vor pow(+-0,neg).
        * math/libm-test.inc (pow_test): Add tests for errno value for
index 19025ec..8c5727c 100644 (file)
@@ -5653,9 +5653,15 @@ tan_test (void)
 
   TEST_f_f (tan, 0, 0);
   TEST_f_f (tan, minus_zero, minus_zero);
+  errno = 0;
   TEST_f_f (tan, plus_infty, nan_value, INVALID_EXCEPTION);
+  check_int ("errno for tan(Inf) == EDOM", errno, EDOM, 0, 0, 0);
+  errno = 0;
   TEST_f_f (tan, minus_infty, nan_value, INVALID_EXCEPTION);
+  check_int ("errno for tan(-Inf) == EDOM", errno, EDOM, 0, 0, 0);
+  errno = 0;
   TEST_f_f (tan, nan_value, nan_value);
+  check_int ("errno for tan(NaN) == 0", errno, 0, 0, 0, 0);
 
   TEST_f_f (tan, M_PI_4l, 1);
   TEST_f_f (tan, 0.75L, 0.931596459944072461165202756573936428L);
index 7b3547a..b35bb83 100644 (file)
@@ -1,15 +1,24 @@
 /*
  * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
  * Public domain.
  */
 
+#define __need_Emath
+#include <bits/errno.h>
 #include <machine/asm.h>
 
 RCSID("$NetBSD: s_tan.S,v 1.5 1995/05/09 00:30:00 jtc Exp $")
 
 ENTRY(__tan)
        fldl    4(%esp)
-       fptan
+       fxam
+       fstsw   %ax
+       movb    $0x45, %dh
+       andb    %ah, %dh
+       cmpb    $0x05, %dh
+       je      3f
+4:     fptan
        fnstsw  %ax
        testl   $0x400,%eax
        jnz     1f
@@ -26,5 +35,21 @@ ENTRY(__tan)
        fptan
        fstp    %st(0)
        ret
+3:
+#ifdef PIC
+       pushl   %ebx
+       cfi_adjust_cfa_offset (4)
+       cfi_rel_offset (ebx, 0)
+       LOAD_PIC_REG (bx)
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+       popl    %ebx
+       cfi_adjust_cfa_offset (-4)
+       cfi_restore (ebx)
+#else
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+#endif
+       jmp     4b
 END (__tan)
 weak_alias (__tan, tan)
index 355dff9..74bc22f 100644 (file)
@@ -1,15 +1,24 @@
 /*
  * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
  * Public domain.
  */
 
+#define __need_Emath
+#include <bits/errno.h>
 #include <machine/asm.h>
 
 RCSID("$NetBSD: s_tanf.S,v 1.3 1995/05/09 00:31:09 jtc Exp $")
 
 ENTRY(__tanf)
        flds    4(%esp)
-       fptan
+       fxam
+       fstsw   %ax
+       movb    $0x45, %dh
+       andb    %ah, %dh
+       cmpb    $0x05, %dh
+       je      3f
+4:     fptan
        fnstsw  %ax
        testl   $0x400,%eax
        jnz     1f
@@ -26,5 +35,21 @@ ENTRY(__tanf)
        fptan
        fstp    %st(0)
        ret
+3:
+#ifdef PIC
+       pushl   %ebx
+       cfi_adjust_cfa_offset (4)
+       cfi_rel_offset (ebx, 0)
+       LOAD_PIC_REG (bx)
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+       popl    %ebx
+       cfi_adjust_cfa_offset (-4)
+       cfi_restore (ebx)
+#else
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+#endif
+       jmp     4b
 END (__tanf)
 weak_alias (__tanf, tanf)
index f2bdd6a..151b771 100644 (file)
@@ -3,15 +3,22 @@
  * Public domain.
  *
  * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
+ * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
  */
 
+#define __need_Emath
+#include <bits/errno.h>
 #include <machine/asm.h>
 
-RCSID("$NetBSD: $")
-
 ENTRY(__tanl)
        fldt    4(%esp)
-       fptan
+       fxam
+       fstsw   %ax
+       movb    $0x45, %dh
+       andb    %ah, %dh
+       cmpb    $0x05, %dh
+       je      3f
+4:     fptan
        fnstsw  %ax
        testl   $0x400,%eax
        jnz     1f
@@ -28,5 +35,21 @@ ENTRY(__tanl)
        fptan
        fstp    %st(0)
        ret
+3:
+#ifdef PIC
+       pushl   %ebx
+       cfi_adjust_cfa_offset (4)
+       cfi_rel_offset (ebx, 0)
+       LOAD_PIC_REG (bx)
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+       popl    %ebx
+       cfi_adjust_cfa_offset (-4)
+       cfi_restore (ebx)
+#else
+       call    __errno_location@PLT
+       movl    $EDOM, (%eax)
+#endif
+       jmp     4b
 END (__tanl)
 weak_alias (__tanl, tanl)
index cf8d4d0..6e0f7d2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * IBM Accurate Mathematical Library
  * written by International Business Machines Corp.
- * Copyright (C) 2001 Free Software Foundation
+ * Copyright (C) 2001, 2009 Free Software Foundation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -33,6 +33,8 @@
 /* round to nearest mode of IEEE 754 standard.                       */
 /*                                                                   */
 /*********************************************************************/
+
+#include <errno.h>
 #include "endian.h"
 #include "dla.h"
 #include "mpa.h"
@@ -61,7 +63,11 @@ double tan(double x) {
 
   /* x=+-INF, x=NaN */
   num.d = x;  ux = num.i[HIGH_HALF];
-  if ((ux&0x7ff00000)==0x7ff00000) return x-x;
+  if ((ux&0x7ff00000)==0x7ff00000) {
+    if ((ux&0x7fffffff)==0x7ff00000)
+      __set_errno (EDOM);
+    return x-x;
+  }
 
   w=(x<ZERO) ? -x : x;
 
index e8f6016..4a852cb 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Developed at SunPro, a Sun Microsystems, Inc. business.
  * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
+ * software is freely granted, provided that this notice
  * is preserved.
  * ====================================================
  */
@@ -17,6 +17,7 @@
 static char rcsid[] = "$NetBSD: s_tanf.c,v 1.4 1995/05/10 20:48:20 jtc Exp $";
 #endif
 
+#include <errno.h>
 #include "math.h"
 #include "math_private.h"
 
@@ -37,7 +38,11 @@ static char rcsid[] = "$NetBSD: s_tanf.c,v 1.4 1995/05/10 20:48:20 jtc Exp $";
        if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);
 
     /* tan(Inf or NaN) is NaN */
-       else if (ix>=0x7f800000) return x-x;            /* NaN */
+       else if (ix>=0x7f800000) {
+         if (ix==0x7f800000)
+           __set_errno (EDOM);
+         return x-x;           /* NaN */
+       }
 
     /* argument reduction needed */
        else {
index 674e908..6427e3f 100644 (file)
@@ -4,15 +4,24 @@
  *
  * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
  * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>.
+ * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
  */
 
+#define __need_Emath
+#include <bits/errno.h>
 #include <machine/asm.h>
 
 RCSID("$NetBSD: $")
 
 ENTRY(__tanl)
        fldt    8(%rsp)
-       fptan
+       fxam
+       fstsw   %ax
+       movb    $0x45, %dh
+       andb    %ah, %dh
+       cmpb    $0x05, %dh
+       je      3f
+4:     fptan
        fnstsw  %ax
        testl   $0x400,%eax
        jnz     1f
@@ -29,5 +38,8 @@ ENTRY(__tanl)
        fptan
        fstp    %st(0)
        ret
+3:     call    __errno_location@PLT
+       movl    $EDOM, (%rax)
+       jmp     4b
 END (__tanl)
 weak_alias (__tanl, tanl)