Example #1
0
#include "math.h"
#include "math_private.h"
#include "k_expl.h"

/* XXX Prevent compilers from erroneously constant folding these: */
static const volatile long double
huge = 0x1p10000L,
tiny = 0x1p-10000L;

static const long double
twom10000 = 0x1p-10000L;

static const union IEEEl2bits
/* log(2**16384 - 0.5) rounded towards zero: */
/* log(2**16384 - 0.5 + 1) rounded towards zero for expm1l() is the same: */
o_thresholdu = LD80C(0xb17217f7d1cf79ab, 13,  11356.5234062941439488L),
#define o_threshold	 (o_thresholdu.e)
/* log(2**(-16381-64-1)) rounded towards zero: */
u_thresholdu = LD80C(0xb21dfe7f09e2baa9, 13, -11399.4985314888605581L);
#define u_threshold	 (u_thresholdu.e)

long double
expl(long double x)
{
	union IEEEl2bits u;
	long double hi, lo, t, twopk;
	int k;
	uint16_t hx, ix;

	DOPRINT_START(&x);
Example #2
0
#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 long double shuge = 0x1p16383L;
#if LDBL_MANT_DIG == 64
/*
 * Domain [-1, 1], range ~[-6.6749e-22, 6.6749e-22]:
 * |sinh(x)/x - s(x)| < 2**-70.3
 */
static const union IEEEl2bits
S3u = LD80C(0xaaaaaaaaaaaaaaaa, -3,  1.66666666666666666658e-1L);
#define	S3	S3u.e
static const double
S5  =  8.3333333333333332e-3,		/*  0x11111111111111.0p-59 */
S7  =  1.9841269841270074e-4,		/*  0x1a01a01a01a070.0p-65 */
S9  =  2.7557319223873889e-6,		/*  0x171de3a5565fe6.0p-71 */
S11 =  2.5052108406704084e-8,		/*  0x1ae6456857530f.0p-78 */
S13 =  1.6059042748655297e-10,		/*  0x161245fa910697.0p-85 */
S15 =  7.6470006914396920e-13,		/*  0x1ae7ce4eff2792.0p-93 */
S17 =  2.8346142308424267e-15;		/*  0x19882ce789ffc6.0p-101 */
#elif LDBL_MANT_DIG == 113
/*
 * Domain [-1, 1], range ~[-2.9673e-36, 2.9673e-36]:
 * |sinh(x)/x - s(x)| < 2**-118.0
 */
static const long double
Example #3
0
#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 volatile double tiny = 1.0e-300;
static const double one = 1.0;
#if LDBL_MANT_DIG == 64
/*
 * Domain [-0.25, 0.25], range ~[-1.6304e-22, 1.6304e-22]:
 * |tanh(x)/x - t(x)| < 2**-72.3
 */
static const union IEEEl2bits
T3u = LD80C(0xaaaaaaaaaaaaaa9f, -2, -3.33333333333333333017e-1L);
#define	T3	T3u.e
static const double
T5  =  1.3333333333333314e-1,		/*  0x1111111111110a.0p-55 */
T7  = -5.3968253968210485e-2,		/* -0x1ba1ba1ba1a1a1.0p-57 */
T9  =  2.1869488531393817e-2,		/*  0x1664f488172022.0p-58 */
T11 = -8.8632352345964591e-3,		/* -0x1226e34bc138d5.0p-59 */
T13 =  3.5921169709993771e-3,		/*  0x1d6d371d3e400f.0p-61 */
T15 = -1.4555786415756001e-3,		/* -0x17d923aa63814d.0p-62 */
T17 =  5.8645267876296793e-4,		/*  0x13378589b85aa7.0p-63 */
T19 = -2.1121033571392224e-4;		/* -0x1baf0af80c4090.0p-65 */
#elif LDBL_MANT_DIG == 113
/*
 * Domain [-0.25, 0.25], range ~[-2.4211e-37, 2.4211e-37]:
 * |tanh(x)/x - t(x)| < 2**121.6
 */
Example #4
0
#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 volatile long double huge = 0x1p10000L, tiny = 0x1p-10000L;
#if LDBL_MANT_DIG == 64
/*
 * Domain [-1, 1], range ~[-1.8211e-21, 1.8211e-21]:
 * |cosh(x) - c(x)| < 2**-68.8
 */
static const union IEEEl2bits
C4u = LD80C(0xaaaaaaaaaaaaac78, -5,  4.16666666666666682297e-2L);
#define	C4	C4u.e
static const double
C2  =  0.5,
C6  =  1.3888888888888616e-3,		/*  0x16c16c16c16b99.0p-62 */
C8  =  2.4801587301767953e-5,		/*  0x1a01a01a027061.0p-68 */
C10 =  2.7557319163300398e-7,		/*  0x127e4fb6c9b55f.0p-74 */
C12 =  2.0876768371393075e-9,		/*  0x11eed99406a3f4.0p-81 */
C14 =  1.1469537039374480e-11,		/*  0x1938c67cd18c48.0p-89 */
C16 =  4.8473490896852041e-14;		/*  0x1b49c429701e45.0p-97 */
#elif LDBL_MANT_DIG == 113
/*
 * Domain [-1, 1], range ~[-2.3194e-37, 2.3194e-37]:
 * |cosh(x) - c(x)| < 2**-121.69
 */
static const long double
Example #5
0
#if LDBL_MAX_EXP != 0x4000
#error "Unsupported long double format"
#endif

static const long double
A_crossover =		10,
B_crossover =		0.6417,
FOUR_SQRT_MIN =		0x1p-8189L,
HALF_MAX =		0x1p16383L,
QUARTER_SQRT_MAX =	0x1p8189L,
RECIP_EPSILON =		1 / LDBL_EPSILON,
SQRT_MIN =		0x1p-8191L;

#if LDBL_MANT_DIG == 64
static const union IEEEl2bits
um_e =		LD80C(0xadf85458a2bb4a9b,  1, 2.71828182845904523536e+0L),
um_ln2 =	LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
#define		m_e	um_e.e
#define		m_ln2	um_ln2.e
static const long double
/* The next 2 literals for non-i386.  Misrounding them on i386 is harmless. */
SQRT_3_EPSILON = 5.70316273435758915310e-10,	/*  0x9cc470a0490973e8.0p-94 */
SQRT_6_EPSILON = 8.06549008734932771664e-10;	/*  0xddb3d742c265539e.0p-94 */
#elif LDBL_MANT_DIG == 113
static const long double
m_e =		2.71828182845904523536028747135266250e0L,	/* 0x15bf0a8b1457695355fb8ac404e7a.0p-111 */
m_ln2 =		6.93147180559945309417232121458176568e-1L,	/* 0x162e42fefa39ef35793c7673007e6.0p-113 */
SQRT_3_EPSILON = 2.40370335797945490975336727199878124e-17,	/*  0x1bb67ae8584caa73b25742d7078b8.0p-168 */
SQRT_6_EPSILON = 3.39934988877629587239082586223300391e-17;	/*  0x13988e1409212e7d0321914321a55.0p-167 */
#else
#error "Unsupported long double format"
Example #6
0
#include "fpmath.h"
#include "math.h"
#include "math_private.h"

#define	TBLBITS	7
#define	TBLSIZE	(1 << TBLBITS)

#define	BIAS	(LDBL_MAX_EXP - 1)

static volatile long double
    huge = 0x1p10000L,
    twom10000 = 0x1p-10000L;

static const union IEEEl2bits
P1 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309429e-1L);

static const double
redux = 0x1.8p63 / TBLSIZE,
/*
 * Domain [-0.00390625, 0.00390625], range ~[-1.7079e-23, 1.7079e-23]
 * |exp(x) - p(x)| < 2**-75.6
 */
P2 = 2.4022650695910072e-1,		/*  0x1ebfbdff82c58f.0p-55 */
P3 = 5.5504108664816879e-2,		/*  0x1c6b08d7049e1a.0p-57 */
P4 = 9.6181291055695180e-3,		/*  0x13b2ab6fa8321a.0p-59 */
P5 = 1.3333563089183052e-3,		/*  0x15d8806f67f251.0p-62 */
P6 = 1.5413361552277414e-4;		/*  0x1433ddacff3441.0p-65 */

static const double tbl[TBLSIZE * 2] = {
	0x1.6a09e667f3bcdp-1,	-0x1.bdd3413b2648p-55,
Example #7
0
#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();
Example #8
0
#include "math_private.h"

/* XXX Prevent compilers from erroneously constant folding: */
static const volatile long double tiny = 0x1p-10000L;

static const double
half= 0.5,
one = 1,
two = 2;
/*
 * In the domain [0, 2**-34], only the first term in the power series
 * expansion of erf(x) is used.  The magnitude of the first neglected
 * terms is less than 2**-102.
 */
static const union IEEEl2bits
efxu  = LD80C(0x8375d410a6db446c, -3,  1.28379167095512573902e-1L),
efx8u = LD80C(0x8375d410a6db446c,  0,  1.02703333676410059122e+0L),
/*
 * Domain [0, 0.84375], range ~[-1.423e-22, 1.423e-22]:
 * |(erf(x) - x)/x - pp(x)/qq(x)| < 2**-72.573
 */
pp0u  = LD80C(0x8375d410a6db446c, -3,   1.28379167095512573902e-1L),
pp1u  = LD80C(0xa46c7d09ec3d0cec, -2,  -3.21140201054840180596e-1L),
pp2u  = LD80C(0x9b31e66325576f86, -5,  -3.78893851760347812082e-2L),
pp3u  = LD80C(0x804ac72c9a0b97dd, -7,  -7.83032847030604679616e-3L),
pp4u  = LD80C(0x9f42bcbc3d5a601d, -12, -3.03765663857082048459e-4L),
pp5u  = LD80C(0x9ec4ad6193470693, -16, -1.89266527398167917502e-5L),
qq1u  = LD80C(0xdb4b8eb713188d6b, -2,   4.28310832832310510579e-1L),
qq2u  = LD80C(0xa5750835b2459bd1, -4,   8.07896272074540216658e-2L),
qq3u  = LD80C(0x8b85d6bd6a90b51c, -7,   8.51579638189385354266e-3L),
qq4u  = LD80C(0x87332f82cff4ff96, -11,  5.15746855583604912827e-4L),