Wed Jun 5 02:11:30 1996 Ulrich Drepper <drepper@cygnus.com>
authorroland <roland>
Wed, 5 Jun 1996 01:05:06 +0000 (01:05 +0000)
committerroland <roland>
Wed, 5 Jun 1996 01:05:06 +0000 (01:05 +0000)
* sysdeps/libm-ieee754/s_ilogbl.c, sysdeps/libm-ieee754/s_logbl.c,
sysdeps/libm-ieee754/s_modfl.c:  New files.  Generic versions
of `long double' math functions.

sysdeps/libm-ieee754/s_ilogbl.c [new file with mode: 0644]
sysdeps/libm-ieee754/s_logbl.c [new file with mode: 0644]
sysdeps/libm-ieee754/s_modfl.c [new file with mode: 0644]

diff --git a/sysdeps/libm-ieee754/s_ilogbl.c b/sysdeps/libm-ieee754/s_ilogbl.c
new file mode 100644 (file)
index 0000000..11372e0
--- /dev/null
@@ -0,0 +1,56 @@
+/* s_ilogbl.c -- long double version of s_ilogb.c.
+ * Conversion to long double by Ulrich Drepper,
+ * Cygnus Support, drepper@cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(LIBM_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: $";
+#endif
+
+/* ilogbl(long double x)
+ * return the binary exponent of non-zero x
+ * ilogbl(0) = 0x80000001
+ * ilogbl(inf/NaN) = 0x7fffffff (no signal is raised)
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+#ifdef __STDC__
+       int __ilogbl(long double x)
+#else
+       int __ilogbl(x)
+       long double x;
+#endif
+{
+       int32_t es,hx,lx,ix;
+
+       GET_LDOUBLE_EXP(es,x);
+       es &= 0x7fff;
+       if(es==0) {
+           GET_LDOUBLE_WORDS(es,hx,lx,x);
+           if((hx|lx)==0)
+               return 0x80000001;      /* ilogbl(0) = 0x80000001 */
+           else                        /* subnormal x */
+               if(hx==0) {
+                   for (ix = -16415; lx>0; lx<<=1) ix -=1;
+               } else {
+                   for (ix = -16383; hx>0; hx<<=1) ix -=1;
+               }
+           return ix;
+       }
+       else if (es<0x7fff) return es-0x3fff;
+       else return 0x7fffffff;
+}
+weak_alias (__ilogbl, ilogbl)
diff --git a/sysdeps/libm-ieee754/s_logbl.c b/sysdeps/libm-ieee754/s_logbl.c
new file mode 100644 (file)
index 0000000..2cd9d10
--- /dev/null
@@ -0,0 +1,47 @@
+/* s_logbl.c -- long double version of s_logb.c.
+ * Conversion to long double by Ulrich Drepper,
+ * Cygnus Support, drepper@cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(LIBM_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: $";
+#endif
+
+/*
+ * long double logbl(x)
+ * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
+ * Use ilogb instead.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+#ifdef __STDC__
+       long double __logbl(long double x)
+#else
+       long double __logbl(x)
+       long double x;
+#endif
+{
+       int32_t es,lx,ix;
+       GET_LDOUBLE_WORDS(es,ix,lx,x);
+       es &= 0x7fff;                           /* exponent */
+       if((es|ix|lx)==0) return -1.0/fabs(x);
+       if(es==0x7fff) return x*x;
+       if(es==0)                       /* IEEE 754 logb */
+               return -16382.0;
+       else
+               return (long double) (es-0x3fff);
+}
+weak_alias (__logbl, logbl)
diff --git a/sysdeps/libm-ieee754/s_modfl.c b/sysdeps/libm-ieee754/s_modfl.c
new file mode 100644 (file)
index 0000000..433c936
--- /dev/null
@@ -0,0 +1,88 @@
+/* s_modfl.c -- long double version of s_modf.c.
+ * Conversion to long double by Ulrich Drepper,
+ * Cygnus Support, drepper@cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(LIBM_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: $";
+#endif
+
+/*
+ * modfl(long double x, long double *iptr)
+ * return fraction part of x, and return x's integral part in *iptr.
+ * Method:
+ *     Bit twiddling.
+ *
+ * Exception:
+ *     No exception.
+ */
+
+#include "math.h"
+#include "math_private.h"
+
+#ifdef __STDC__
+static const long double one = 1.0;
+#else
+static long double one = 1.0;
+#endif
+
+#ifdef __STDC__
+       long double __modfl(long double x, long double *iptr)
+#else
+       long double __modfl(x, iptr)
+       long double x,*iptr;
+#endif
+{
+       int32_t i0,i1,j0;
+       u_int32_t i,se;
+       GET_LDOUBLE_WORDS(se,i0,i1,x);
+       j0 = (se&0x7fff)-0x3fff;        /* exponent of x */
+       if(j0<32) {                     /* integer part in high x */
+           if(j0<0) {                  /* |x|<1 */
+               SET_LDOUBLE_WORDS(*iptr,se&0x8000,0,0); /* *iptr = +-0 */
+               return x;
+           } else {
+               i = (0xffffffff)>>j0;
+               if(((i0&i)|i1)==0) {            /* x is integral */
+                   u_int32_t high;
+                   *iptr = x;
+                   GET_HIGH_WORD(high,x);
+                   INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
+                   return x;
+               } else {
+                   INSERT_WORDS(*iptr,i0&(~i),0);
+                   return x - *iptr;
+               }
+           }
+       } else if (j0>63) {             /* no fraction part */
+           u_int32_t high;
+           *iptr = x*one;
+           GET_HIGH_WORD(high,x);
+           INSERT_WORDS(x,high&0x80000000,0);  /* return +-0 */
+           return x;
+       } else {                        /* fraction part in low x */
+           i = ((u_int32_t)(0xffffffff))>>(j0-20);
+           if((i1&i)==0) {             /* x is integral */
+               u_int32_t high;
+               *iptr = x;
+               GET_HIGH_WORD(high,x);
+               INSERT_WORDS(x,high&0x80000000,0);      /* return +-0 */
+               return x;
+           } else {
+               INSERT_WORDS(*iptr,i0,i1&(~i));
+               return x - *iptr;
+           }
+       }
+}
+weak_alias (__modfl, modfl)