Skip to content

Commit 52c901a

Browse files
committed
Import long double versions from OpenBSD.
1 parent 691b989 commit 52c901a

53 files changed

Lines changed: 9450 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ld128/e_acoshl.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* @(#)e_acosh.c 5.1 93/09/24 */
2+
/*
3+
* ====================================================
4+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5+
*
6+
* Developed at SunPro, a Sun Microsystems, Inc. business.
7+
* Permission to use, copy, modify, and distribute this
8+
* software is freely granted, provided that this notice
9+
* is preserved.
10+
* ====================================================
11+
*/
12+
13+
/* acoshl(x)
14+
* Method :
15+
* Based on
16+
* acoshl(x) = logl [ x + sqrtl(x*x-1) ]
17+
* we have
18+
* acoshl(x) := logl(x)+ln2, if x is large; else
19+
* acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else
20+
* acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1.
21+
*
22+
* Special cases:
23+
* acoshl(x) is NaN with signal if x<1.
24+
* acoshl(NaN) is NaN without signal.
25+
*/
26+
27+
#include <math.h>
28+
29+
#include "math_private.h"
30+
31+
static const long double
32+
one = 1.0,
33+
ln2 = 0.6931471805599453094172321214581766L;
34+
35+
long double
36+
acoshl(long double x)
37+
{
38+
long double t;
39+
u_int64_t lx;
40+
int64_t hx;
41+
GET_LDOUBLE_WORDS64(hx,lx,x);
42+
if(hx<0x3fff000000000000LL) { /* x < 1 */
43+
return (x-x)/(x-x);
44+
} else if(hx >=0x4035000000000000LL) { /* x > 2**54 */
45+
if(hx >=0x7fff000000000000LL) { /* x is inf of NaN */
46+
return x+x;
47+
} else
48+
return logl(x)+ln2; /* acoshl(huge)=logl(2x) */
49+
} else if(((hx-0x3fff000000000000LL)|lx)==0) {
50+
return 0.0L; /* acosh(1) = 0 */
51+
} else if (hx > 0x4000000000000000LL) { /* 2**28 > x > 2 */
52+
t=x*x;
53+
return logl(2.0L*x-one/(x+sqrtl(t-one)));
54+
} else { /* 1<x<2 */
55+
t = x-one;
56+
return log1pl(t+sqrtl(2.0L*t+t*t));
57+
}
58+
}

ld128/e_atanhl.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* @(#)e_atanh.c 5.1 93/09/24 */
2+
/*
3+
* ====================================================
4+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5+
*
6+
* Developed at SunPro, a Sun Microsystems, Inc. business.
7+
* Permission to use, copy, modify, and distribute this
8+
* software is freely granted, provided that this notice
9+
* is preserved.
10+
* ====================================================
11+
*/
12+
13+
/* atanhl(x)
14+
* Method :
15+
* 1.Reduced x to positive by atanh(-x) = -atanh(x)
16+
* 2.For x>=0.5
17+
* 1 2x x
18+
* atanhl(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
19+
* 2 1 - x 1 - x
20+
*
21+
* For x<0.5
22+
* atanhl(x) = 0.5*log1pl(2x+2x*x/(1-x))
23+
*
24+
* Special cases:
25+
* atanhl(x) is NaN if |x| > 1 with signal;
26+
* atanhl(NaN) is that NaN with no signal;
27+
* atanhl(+-1) is +-INF with signal.
28+
*
29+
*/
30+
31+
#include <math.h>
32+
33+
#include "math_private.h"
34+
35+
static const long double one = 1.0L, huge = 1e4900L;
36+
37+
static const long double zero = 0.0L;
38+
39+
long double
40+
atanhl(long double x)
41+
{
42+
long double t;
43+
u_int32_t jx, ix;
44+
ieee_quad_shape_type u;
45+
46+
u.value = x;
47+
jx = u.parts32.mswhi;
48+
ix = jx & 0x7fffffff;
49+
u.parts32.mswhi = ix;
50+
if (ix >= 0x3fff0000) /* |x| >= 1.0 or infinity or NaN */
51+
{
52+
if (u.value == one)
53+
return x/zero;
54+
else
55+
return (x-x)/(x-x);
56+
}
57+
if(ix<0x3fc60000 && (huge+x)>zero) return x; /* x < 2^-57 */
58+
59+
if(ix<0x3ffe0000) { /* x < 0.5 */
60+
t = u.value+u.value;
61+
t = 0.5*log1pl(t+t*u.value/(one-u.value));
62+
} else
63+
t = 0.5*log1pl((u.value+u.value)/(one-u.value));
64+
if(jx & 0x80000000) return -t; else return t;
65+
}

ld128/e_coshl.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* ====================================================
3+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4+
*
5+
* Developed at SunPro, a Sun Microsystems, Inc. business.
6+
* Permission to use, copy, modify, and distribute this
7+
* software is freely granted, provided that this notice
8+
* is preserved.
9+
* ====================================================
10+
*/
11+
12+
/*
13+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
14+
*
15+
* Permission to use, copy, modify, and distribute this software for any
16+
* purpose with or without fee is hereby granted, provided that the above
17+
* copyright notice and this permission notice appear in all copies.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
20+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
21+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
22+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
24+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
25+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26+
*/
27+
28+
/* coshl(x)
29+
* Method :
30+
* mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2
31+
* 1. Replace x by |x| (coshl(x) = coshl(-x)).
32+
* 2.
33+
* [ exp(x) - 1 ]^2
34+
* 0 <= x <= ln2/2 : coshl(x) := 1 + -------------------
35+
* 2*exp(x)
36+
*
37+
* exp(x) + 1/exp(x)
38+
* ln2/2 <= x <= 22 : coshl(x) := -------------------
39+
* 2
40+
* 22 <= x <= lnovft : coshl(x) := expl(x)/2
41+
* lnovft <= x <= ln2ovft: coshl(x) := expl(x/2)/2 * expl(x/2)
42+
* ln2ovft < x : coshl(x) := huge*huge (overflow)
43+
*
44+
* Special cases:
45+
* coshl(x) is |x| if x is +INF, -INF, or NaN.
46+
* only coshl(0)=1 is exact for finite x.
47+
*/
48+
49+
#include <math.h>
50+
51+
#include "math_private.h"
52+
53+
static const long double one = 1.0, half = 0.5, huge = 1.0e4900L,
54+
ovf_thresh = 1.1357216553474703894801348310092223067821E4L;
55+
56+
long double
57+
coshl(long double x)
58+
{
59+
long double t, w;
60+
int32_t ex;
61+
ieee_quad_shape_type u;
62+
63+
u.value = x;
64+
ex = u.parts32.mswhi & 0x7fffffff;
65+
66+
/* Absolute value of x. */
67+
u.parts32.mswhi = ex;
68+
69+
/* x is INF or NaN */
70+
if (ex >= 0x7fff0000)
71+
return x * x;
72+
73+
/* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */
74+
if (ex < 0x3ffd62e4) /* 0.3465728759765625 */
75+
{
76+
t = expm1l (u.value);
77+
w = one + t;
78+
if (ex < 0x3fb80000) /* |x| < 2^-116 */
79+
return w; /* cosh(tiny) = 1 */
80+
81+
return one + (t * t) / (w + w);
82+
}
83+
84+
/* |x| in [0.5*ln2,40], return (exp(|x|)+1/exp(|x|)/2; */
85+
if (ex < 0x40044000)
86+
{
87+
t = expl (u.value);
88+
return half * t + half / t;
89+
}
90+
91+
/* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
92+
if (ex <= 0x400c62e3) /* 11356.375 */
93+
return half * expl (u.value);
94+
95+
/* |x| in [log(maxdouble), overflowthresold] */
96+
if (u.value <= ovf_thresh)
97+
{
98+
w = expl (half * u.value);
99+
t = half * w;
100+
return t * w;
101+
}
102+
103+
/* |x| > overflowthresold, cosh(x) overflow */
104+
return huge * huge;
105+
}

ld128/e_expl.c

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/* $OpenBSD: e_expl.c,v 1.3 2013/11/12 20:35:18 martynas Exp $ */
2+
3+
/*
4+
* Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
/* expl.c
20+
*
21+
* Exponential function, 128-bit long double precision
22+
*
23+
*
24+
*
25+
* SYNOPSIS:
26+
*
27+
* long double x, y, expl();
28+
*
29+
* y = expl( x );
30+
*
31+
*
32+
*
33+
* DESCRIPTION:
34+
*
35+
* Returns e (2.71828...) raised to the x power.
36+
*
37+
* Range reduction is accomplished by separating the argument
38+
* into an integer k and fraction f such that
39+
*
40+
* x k f
41+
* e = 2 e.
42+
*
43+
* A Pade' form of degree 2/3 is used to approximate exp(f) - 1
44+
* in the basic range [-0.5 ln 2, 0.5 ln 2].
45+
*
46+
*
47+
* ACCURACY:
48+
*
49+
* Relative error:
50+
* arithmetic domain # trials peak rms
51+
* IEEE +-MAXLOG 100,000 2.6e-34 8.6e-35
52+
*
53+
*
54+
* Error amplification in the exponential function can be
55+
* a serious matter. The error propagation involves
56+
* exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),
57+
* which shows that a 1 lsb error in representing X produces
58+
* a relative error of X times 1 lsb in the function.
59+
* While the routine gives an accurate result for arguments
60+
* that are exactly represented by a long double precision
61+
* computer number, the result contains amplified roundoff
62+
* error for large arguments not exactly represented.
63+
*
64+
*
65+
* ERROR MESSAGES:
66+
*
67+
* message condition value returned
68+
* exp underflow x < MINLOG 0.0
69+
* exp overflow x > MAXLOG MAXNUM
70+
*
71+
*/
72+
73+
/* Exponential function */
74+
75+
#include <float.h>
76+
#include <math.h>
77+
78+
#include "math_private.h"
79+
80+
/* Pade' coefficients for exp(x) - 1
81+
Theoretical peak relative error = 2.2e-37,
82+
relative peak error spread = 9.2e-38
83+
*/
84+
static long double P[5] = {
85+
3.279723985560247033712687707263393506266E-10L,
86+
6.141506007208645008909088812338454698548E-7L,
87+
2.708775201978218837374512615596512792224E-4L,
88+
3.508710990737834361215404761139478627390E-2L,
89+
9.999999999999999999999999999999999998502E-1L
90+
};
91+
static long double Q[6] = {
92+
2.980756652081995192255342779918052538681E-12L,
93+
1.771372078166251484503904874657985291164E-8L,
94+
1.504792651814944826817779302637284053660E-5L,
95+
3.611828913847589925056132680618007270344E-3L,
96+
2.368408864814233538909747618894558968880E-1L,
97+
2.000000000000000000000000000000000000150E0L
98+
};
99+
/* C1 + C2 = ln 2 */
100+
static const long double C1 = -6.93145751953125E-1L;
101+
static const long double C2 = -1.428606820309417232121458176568075500134E-6L;
102+
103+
static const long double LOG2EL = 1.442695040888963407359924681001892137426646L;
104+
static const long double MAXLOGL = 1.1356523406294143949491931077970764891253E4L;
105+
static const long double MINLOGL = -1.143276959615573793352782661133116431383730e4L;
106+
static const long double huge = 0x1p10000L;
107+
#if 0 /* XXX Prevent gcc from erroneously constant folding this. */
108+
static const long double twom10000 = 0x1p-10000L;
109+
#else
110+
static volatile long double twom10000 = 0x1p-10000L;
111+
#endif
112+
113+
long double
114+
expl(long double x)
115+
{
116+
long double px, xx;
117+
int n;
118+
119+
if( x > MAXLOGL)
120+
return (huge*huge); /* overflow */
121+
122+
if( x < MINLOGL )
123+
return (twom10000*twom10000); /* underflow */
124+
125+
/* Express e**x = e**g 2**n
126+
* = e**g e**( n loge(2) )
127+
* = e**( g + n loge(2) )
128+
*/
129+
px = floorl( LOG2EL * x + 0.5L ); /* floor() truncates toward -infinity. */
130+
n = px;
131+
x += px * C1;
132+
x += px * C2;
133+
/* rational approximation for exponential
134+
* of the fractional part:
135+
* e**x = 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
136+
*/
137+
xx = x * x;
138+
px = x * __polevll( xx, P, 4 );
139+
xx = __polevll( xx, Q, 5 );
140+
x = px/( xx - px );
141+
x = 1.0L + x + x;
142+
143+
x = ldexpl( x, n );
144+
return(x);
145+
}

0 commit comments

Comments
 (0)