diff options
author | das <das@FreeBSD.org> | 2013-06-10 06:04:58 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2013-06-10 06:04:58 +0000 |
commit | 4e8602cd3988d7feb832032e4eb9c5a560af08f0 (patch) | |
tree | 86fabb2acfe36058b468630da526ea699b62d9b8 /lib/msun/src | |
parent | dc9bd08e99b5ce900fa2f3d1c8cd7b3e36c029e2 (diff) | |
download | FreeBSD-src-4e8602cd3988d7feb832032e4eb9c5a560af08f0.zip FreeBSD-src-4e8602cd3988d7feb832032e4eb9c5a560af08f0.tar.gz |
Add implementations of acoshl(), asinhl(), and atanhl(). This is a
merge of the work done by bde and myself.
Diffstat (limited to 'lib/msun/src')
-rw-r--r-- | lib/msun/src/e_acosh.c | 6 | ||||
-rw-r--r-- | lib/msun/src/e_acoshl.c | 89 | ||||
-rw-r--r-- | lib/msun/src/e_atanh.c | 6 | ||||
-rw-r--r-- | lib/msun/src/e_atanhl.c | 74 | ||||
-rw-r--r-- | lib/msun/src/math.h | 6 | ||||
-rw-r--r-- | lib/msun/src/s_asinh.c | 6 | ||||
-rw-r--r-- | lib/msun/src/s_asinhl.c | 91 |
7 files changed, 275 insertions, 3 deletions
diff --git a/lib/msun/src/e_acosh.c b/lib/msun/src/e_acosh.c index a0cc6cb..358c8bd 100644 --- a/lib/msun/src/e_acosh.c +++ b/lib/msun/src/e_acosh.c @@ -29,6 +29,8 @@ __FBSDID("$FreeBSD$"); * acosh(NaN) is NaN without signal. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -60,3 +62,7 @@ __ieee754_acosh(double x) return log1p(t+sqrt(2.0*t+t*t)); } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(acosh, acoshl); +#endif diff --git a/lib/msun/src/e_acoshl.c b/lib/msun/src/e_acoshl.c new file mode 100644 index 0000000..b9f3aed --- /dev/null +++ b/lib/msun/src/e_acoshl.c @@ -0,0 +1,89 @@ +/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)e_acosh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See e_acosh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */ +#if LDBL_MANT_DIG == 64 +#define EXP_LARGE 34 +#elif LDBL_MANT_DIG == 113 +#define EXP_LARGE 58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double +one = 1.0; + +#if LDBL_MANT_DIG == 64 +static const union IEEEl2bits +u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); +#define ln2 u_ln2.e +#elif LDBL_MANT_DIG == 113 +static const long double +ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ +#else +#error "Unsupported long double format" +#endif + +long double +acoshl(long double x) +{ + long double t; + int16_t hx; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + if (hx < 0x3fff) { /* x < 1, or misnormal */ + RETURNI((x-x)/(x-x)); + } else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */ + if (hx >= 0x7fff) { /* x is inf, NaN or misnormal */ + RETURNI(x+x); + } else + RETURNI(logl(x)+ln2); /* acosh(huge)=log(2x), or misnormal */ + } else if (hx == 0x3fff && x == 1) { + RETURNI(0.0); /* acosh(1) = 0 */ + } else if (hx >= 0x4000) { /* LARGE > x >= 2, or misnormal */ + t=x*x; + RETURNI(logl(2.0*x-one/(x+sqrtl(t-one)))); + } else { /* 1<x<2 */ + t = x-one; + RETURNI(log1pl(t+sqrtl(2.0*t+t*t))); + } +} diff --git a/lib/msun/src/e_atanh.c b/lib/msun/src/e_atanh.c index ab8a2e1..422ff26 100644 --- a/lib/msun/src/e_atanh.c +++ b/lib/msun/src/e_atanh.c @@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$"); * */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -60,3 +62,7 @@ __ieee754_atanh(double x) t = 0.5*log1p((x+x)/(one-x)); if(hx>=0) return t; else return -t; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(atanh, atanhl); +#endif diff --git a/lib/msun/src/e_atanhl.c b/lib/msun/src/e_atanhl.c new file mode 100644 index 0000000..11d56ea --- /dev/null +++ b/lib/msun/src/e_atanhl.c @@ -0,0 +1,74 @@ +/* from: FreeBSD: head/lib/msun/src/e_atanh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)e_atanh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See e_atanh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_TINY is the threshold below which we use atanh(x) ~= x. */ +#if LDBL_MANT_DIG == 64 +#define EXP_TINY -34 +#elif LDBL_MANT_DIG == 113 +#define EXP_TINY -58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double one = 1.0, huge = 1e300; +static const double zero = 0.0; + +long double +atanhl(long double x) +{ + long double t; + uint16_t hx, ix; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + ix = hx & 0x7fff; + if (ix >= 0x3fff) /* |x| >= 1, or NaN or misnormal */ + RETURNI(fabsl(x) == 1 ? x / zero : (x - x) / (x - x)); + if (ix < BIAS + EXP_TINY && (huge + x) > zero) + RETURNI(x); /* x is tiny */ + SET_LDBL_EXPSIGN(x, ix); + if (ix < 0x3ffe) { /* |x| < 0.5, or misnormal */ + t = x+x; + t = 0.5*log1pl(t+t*x/(one-x)); + } else + t = 0.5*log1pl((x+x)/(one-x)); + RETURNI((hx & 0x8000) == 0 ? t : -t); +} diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index 8d0d478..d831f15 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -395,9 +395,12 @@ float significandf(float); * long double versions of ISO/POSIX math functions */ #if __ISO_C_VISIBLE >= 1999 +long double acoshl(long double); long double acosl(long double); +long double asinhl(long double); long double asinl(long double); long double atan2l(long double, long double); +long double atanhl(long double); long double atanl(long double); long double cbrtl(long double); long double ceill(long double); @@ -461,9 +464,6 @@ __END_DECLS */ __BEGIN_DECLS -long double acoshl(long double); -long double asinhl(long double); -long double atanhl(long double); long double coshl(long double); long double erfcl(long double); long double erfl(long double); diff --git a/lib/msun/src/s_asinh.c b/lib/msun/src/s_asinh.c index f3fdf74..cbb3d46 100644 --- a/lib/msun/src/s_asinh.c +++ b/lib/msun/src/s_asinh.c @@ -24,6 +24,8 @@ __FBSDID("$FreeBSD$"); * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -54,3 +56,7 @@ asinh(double x) } if(hx>0) return w; else return -w; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(asinh, asinhl); +#endif diff --git a/lib/msun/src/s_asinhl.c b/lib/msun/src/s_asinhl.c new file mode 100644 index 0000000..ba28f59 --- /dev/null +++ b/lib/msun/src/s_asinhl.c @@ -0,0 +1,91 @@ +/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)s_asinh.c 5.1 93/09/24 */ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See s_asinh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */ +/* EXP_TINY is the threshold below which we use asinh(x) ~= x. */ +#if LDBL_MANT_DIG == 64 +#define EXP_LARGE 34 +#define EXP_TINY -34 +#elif LDBL_MANT_DIG == 113 +#define EXP_LARGE 58 +#define EXP_TINY -58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +huge= 1.00000000000000000000e+300; + +#if LDBL_MANT_DIG == 64 +static const union IEEEl2bits +u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); +#define ln2 u_ln2.e +#elif LDBL_MANT_DIG == 113 +static const long double +ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ +#else +#error "Unsupported long double format" +#endif + +long double +asinhl(long double x) +{ + long double t, w; + uint16_t hx, ix; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + ix = hx & 0x7fff; + if (ix >= 0x7fff) RETURNI(x+x); /* x is inf, NaN or misnormal */ + if (ix < BIAS + EXP_TINY) { /* |x| < TINY, or misnormal */ + if (huge + x > one) RETURNI(x); /* return x inexact except 0 */ + } + if (ix >= BIAS + EXP_LARGE) { /* |x| >= LARGE, or misnormal */ + w = logl(fabsl(x))+ln2; + } else if (ix >= 0x4000) { /* LARGE > |x| >= 2.0, or misnormal */ + t = fabsl(x); + w = logl(2.0*t+one/(sqrtl(x*x+one)+t)); + } else { /* 2.0 > |x| >= TINY, or misnormal */ + t = x*x; + w =log1pl(fabsl(x)+t/(one+sqrtl(one+t))); + } + RETURNI((hx & 0x8000) == 0 ? w : -w); +} |