Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libm fix ilogb*



details:   https://anonhg.NetBSD.org/src/rev/6d069a4c4761
branches:  trunk
changeset: 817541:6d069a4c4761
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 24 10:03:32 2016 +0000

description:
fix ilogb*

diffstat:

 lib/libm/Makefile       |  12 +++++++-----
 lib/libm/src/s_ilogb.c  |  37 ++++++++++++++++++++++---------------
 lib/libm/src/s_ilogbf.c |  31 +++++++++++++++++++------------
 lib/libm/src/s_ilogbl.c |  15 ++++++++++-----
 4 files changed, 58 insertions(+), 37 deletions(-)

diffs (186 lines):

diff -r 5a07ac6cd9d6 -r 6d069a4c4761 lib/libm/Makefile
--- a/lib/libm/Makefile Wed Aug 24 09:13:44 2016 +0000
+++ b/lib/libm/Makefile Wed Aug 24 10:03:32 2016 +0000
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.179 2016/08/24 09:10:57 christos Exp $
+#  $NetBSD: Makefile,v 1.180 2016/08/24 10:03:32 christos Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -113,12 +113,14 @@
            e_remainderf.S e_scalb.S e_scalbf.S e_sqrt.S e_sqrtf.S s_atan.S \
            s_atanf.S s_ceil.S s_ceilf.S s_copysign.S s_copysignf.S s_cos.S \
            s_cosf.S s_finite.S s_finitef.S s_floor.S s_floorf.S \
-           s_ilogb.S s_ilogbf.S s_ilogbl.S s_log1p.S s_log1pf.S \
-           s_logb.S s_logbf.S s_logbl.S \
+           s_log1p.S s_log1pf.S s_logb.S s_logbf.S s_logbl.S \
            s_rint.S s_rintf.S s_scalbn.S s_scalbnf.S s_significand.S \
            s_significandf.S s_sin.S s_sinf.S s_tan.S s_tanf.S lrint.S 
-# do not pick up the i387 asm version, it is incorrect
-s_modf.o s_modf.pico s_modf.po s_modf.d: s_modf.c
+# do not pick up the i387 asm version for the following functions;
+# it is incorrect
+.for f in modf ilogb ilogbl ilogbf
+s_${f}.o s_${f}.pico s_${f}.po s_${f}.d: s_${f}.c
+.endfor
 
 .if (${MACHINE_ARCH} == "i386")
 SUBDIR=arch/i387
diff -r 5a07ac6cd9d6 -r 6d069a4c4761 lib/libm/src/s_ilogb.c
--- a/lib/libm/src/s_ilogb.c    Wed Aug 24 09:13:44 2016 +0000
+++ b/lib/libm/src/s_ilogb.c    Wed Aug 24 10:03:32 2016 +0000
@@ -12,7 +12,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: s_ilogb.c,v 1.14 2013/02/09 22:56:00 matt Exp $");
+__RCSID("$NetBSD: s_ilogb.c,v 1.15 2016/08/24 10:03:32 christos Exp $");
 #endif
 
 /* ilogb(double x)
@@ -21,7 +21,8 @@
  * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
  */
 
-#include "math.h"
+#include <math.h>
+#include <fenv.h>
 #include "math_private.h"
 
 #ifndef __HAVE_LONG_DOUBLE
@@ -31,22 +32,28 @@
 int
 ilogb(double x)
 {
-       int32_t hx,lx,ix;
+       int32_t hx, lx, ix;
 
-       GET_HIGH_WORD(hx,x);
+       GET_HIGH_WORD(hx, x);
        hx &= 0x7fffffff;
-       if(hx<0x00100000) {
-           GET_LOW_WORD(lx,x);
-           if((hx|lx)==0)
-               return FP_ILOGB0;       /* ilogb(0) = 0x80000001 */
-           else                        /* subnormal x */
-               if(hx==0) {
-                   for (ix = -1043; lx>0; lx<<=1) ix -=1;
+       if (hx < 0x00100000) {
+               GET_LOW_WORD(lx, x);
+               if ((hx | lx) == 0) {
+                       feraiseexcept(FE_INVALID);
+                       return FP_ILOGB0;       /* ilogb(0) = 0x80000001 */
+               }
+               if (hx == 0) {
+                       for (ix = -1043; lx > 0; lx <<= 1) ix -= 1;
                } else {
-                   for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
+                       for (ix = -1022, hx <<= 11; hx > 0; hx <<= 1) ix -= 1;
                }
-           return ix;
+               return ix;
        }
-       else if (hx<0x7ff00000) return (hx>>20)-1023;
-       else return FP_ILOGBNAN;        /* inf too */
+
+       if (hx < 0x7ff00000) {
+               return (hx >> 20) - 1023;
+       }
+
+       feraiseexcept(FE_INVALID);
+       return isnan(x) ? FP_ILOGBNAN : INT_MAX;
 }
diff -r 5a07ac6cd9d6 -r 6d069a4c4761 lib/libm/src/s_ilogbf.c
--- a/lib/libm/src/s_ilogbf.c   Wed Aug 24 09:13:44 2016 +0000
+++ b/lib/libm/src/s_ilogbf.c   Wed Aug 24 10:03:32 2016 +0000
@@ -15,26 +15,33 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: s_ilogbf.c,v 1.8 2013/02/09 22:56:00 matt Exp $");
+__RCSID("$NetBSD: s_ilogbf.c,v 1.9 2016/08/24 10:03:32 christos Exp $");
 #endif
 
-#include "math.h"
+#include <math.h>
+#include <fenv.h>
 #include "math_private.h"
 
 int
 ilogbf(float x)
 {
-       int32_t hx,ix;
+       int32_t hx, ix;
 
-       GET_FLOAT_WORD(hx,x);
+       GET_FLOAT_WORD(hx, x);
        hx &= 0x7fffffff;
-       if(hx<0x00800000) {
-           if(hx==0)
-               return FP_ILOGB0;       /* ilogb(0) = 0x80000001 */
-           else                        /* subnormal x */
-               for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
-           return ix;
+       if (hx < 0x00800000) {
+               if (hx == 0) {
+                       feraiseexcept(FE_INVALID);
+                       return FP_ILOGB0;       /* ilogb(0) = 0x80000001 */
+               }
+               for (ix = -126, hx <<= 8; hx > 0; hx <<= 1) ix -= 1;
+               return ix;
        }
-       else if (hx<0x7f800000) return (hx>>23)-127;
-       else return FP_ILOGBNAN;        /* inf too */
+
+       if (hx < 0x7f800000) {
+               return (hx >> 23) - 127;
+       }
+
+       feraiseexcept(FE_INVALID);
+       return isnan(x) ? FP_ILOGBNAN : INT_MAX;
 }
diff -r 5a07ac6cd9d6 -r 6d069a4c4761 lib/libm/src/s_ilogbl.c
--- a/lib/libm/src/s_ilogbl.c   Wed Aug 24 09:13:44 2016 +0000
+++ b/lib/libm/src/s_ilogbl.c   Wed Aug 24 10:03:32 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: s_ilogbl.c,v 1.2 2013/02/09 22:56:00 matt Exp $        */
+/*     $NetBSD: s_ilogbl.c,v 1.3 2016/08/24 10:03:32 christos Exp $    */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: s_ilogbl.c,v 1.2 2013/02/09 22:56:00 matt Exp $");
+__RCSID("$NetBSD: s_ilogbl.c,v 1.3 2016/08/24 10:03:32 christos Exp $");
 
 #include "namespace.h"
 
 #include <float.h>
 #include <math.h>
+#include <fenv.h>
 #include <machine/ieee.h>
 
 #ifdef __HAVE_LONG_DOUBLE
@@ -53,13 +54,17 @@
 {
        union ieee_ext_u u;
 
-       if (x == 0.0L)
+       if (x == 0.0L) {
+               feraiseexcept(FE_INVALID);
                return FP_ILOGB0;       /* ilogbl(0) = 0x80000001 */
+       }
 
        u.extu_ld = x;
 
-       if (u.extu_ext.ext_exp == EXT_EXP_INFNAN)
-               return FP_ILOGBNAN;     /* inf too */
+       if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) {
+               feraiseexcept(FE_INVALID);
+               return isnan(x) ? FP_ILOGBNAN : INT_MAX;
+       }
 
        if (u.extu_ext.ext_exp == 0) {
                /*



Home | Main Index | Thread Index | Old Index