diff options
Diffstat (limited to 'usr/src/libm/src/C')
77 files changed, 14121 insertions, 0 deletions
diff --git a/usr/src/libm/src/C/_SVID_error.c b/usr/src/libm/src/C/_SVID_error.c new file mode 100644 index 0000000..3443657 --- /dev/null +++ b/usr/src/libm/src/C/_SVID_error.c @@ -0,0 +1,978 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_SVID_error.c 1.75 06/01/23 SMI" + +#include "libm.h" +#include "xpg6.h" /* __xpg6 */ +#include <stdio.h> +#include <float.h> /* DBL_MAX, DBL_MIN */ +#include <unistd.h> /* write */ +#if defined(__i386) || defined(i386) +#include <ieeefp.h> +#undef fp_class +#define fp_class fpclass +#define fp_quiet FP_QNAN +#endif +#include <errno.h> +#undef fflush +#include <sys/isa_defs.h> + +/* INDENT OFF */ +/* + * Report libm exception error according to System V Interface Definition + * (SVID). + * Error mapping: + * 1 -- acos(|x|>1) + * 2 -- asin(|x|>1) + * 3 -- atan2(+-0,+-0) + * 4 -- hypot overflow + * 5 -- cosh overflow + * 6 -- exp overflow + * 7 -- exp underflow + * 8 -- y0(0) + * 9 -- y0(-ve) + * 10-- y1(0) + * 11-- y1(-ve) + * 12-- yn(0) + * 13-- yn(-ve) + * 14-- lgamma(finite) overflow + * 15-- lgamma(-integer) + * 16-- log(0) + * 17-- log(x<0) + * 18-- log10(0) + * 19-- log10(x<0) + * 20-- pow(0.0,0.0) + * 21-- pow(x,y) overflow + * 22-- pow(x,y) underflow + * 23-- pow(0,negative) + * 24-- pow(neg,non-integral) + * 25-- sinh(finite) overflow + * 26-- sqrt(negative) + * 27-- fmod(x,0) + * 28-- remainder(x,0) + * 29-- acosh(x<1) + * 30-- atanh(|x|>1) + * 31-- atanh(|x|=1) + * 32-- scalb overflow + * 33-- scalb underflow + * 34-- j0(|x|>X_TLOSS) + * 35-- y0(x>X_TLOSS) + * 36-- j1(|x|>X_TLOSS) + * 37-- y1(x>X_TLOSS) + * 38-- jn(|x|>X_TLOSS, n) + * 39-- yn(x>X_TLOSS, n) + * 40-- gamma(finite) overflow + * 41-- gamma(-integer) + * 42-- pow(NaN,0.0) return NaN for SVID/XOPEN + * 43-- log1p(-1) + * 44-- log1p(x<-1) + * 45-- logb(0) + * 46-- nextafter overflow + * 47-- scalb(x,inf) + */ +/* INDENT ON */ + +static double setexception(int, double); + +static const union { + unsigned x[2]; + double d; +} C[] = { +#ifdef _LITTLE_ENDIAN + { 0xffffffff, 0x7fffffff }, + { 0x54442d18, 0x400921fb }, +#else + { 0x7fffffff, 0xffffffff }, + { 0x400921fb, 0x54442d18 }, +#endif +}; + +#define NaN C[0].d +#define PI_RZ C[1].d + +#define __HI(x) ((unsigned *)&x)[HIWORD] +#define __LO(x) ((unsigned *)&x)[LOWORD] +#undef Inf +#define Inf HUGE_VAL + +double +_SVID_libm_err(double x, double y, int type) { + struct exception exc; + double t, w, ieee_retval; + enum version lib_version = _lib_version; + int iy; + + /* force libm_ieee behavior in SUSv3 mode */ + if ((__xpg6 & _C99SUSv3_math_errexcept) != 0) + lib_version = libm_ieee; + if (lib_version == c_issue_4) { + (void) fflush(stdout); + } + exc.arg1 = x; + exc.arg2 = y; + switch (type) { + case 1: + /* acos(|x|>1) */ + exc.type = DOMAIN; + exc.name = "acos"; + ieee_retval = setexception(3, 1.0); + exc.retval = 0.0; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "acos: DOMAIN error\n", 19); + } + errno = EDOM; + } + break; + case 2: + /* asin(|x|>1) */ + exc.type = DOMAIN; + exc.name = "asin"; + exc.retval = 0.0; + ieee_retval = setexception(3, 1.0); + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "asin: DOMAIN error\n", 19); + } + errno = EDOM; + } + break; + case 3: + /* atan2(+-0,+-0) */ + exc.arg1 = y; + exc.arg2 = x; + exc.type = DOMAIN; + exc.name = "atan2"; + ieee_retval = copysign(1.0, x) == 1.0 ? y : + copysign(PI_RZ + DBL_MIN, y); + exc.retval = 0.0; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "atan2: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 4: + /* hypot(finite,finite) overflow */ + exc.type = OVERFLOW; + exc.name = "hypot"; + ieee_retval = Inf; + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 5: + /* cosh(finite) overflow */ + exc.type = OVERFLOW; + exc.name = "cosh"; + ieee_retval = setexception(2, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 6: + /* exp(finite) overflow */ + exc.type = OVERFLOW; + exc.name = "exp"; + ieee_retval = setexception(2, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 7: + /* exp(finite) underflow */ + exc.type = UNDERFLOW; + exc.name = "exp"; + ieee_retval = setexception(1, 1.0); + exc.retval = 0.0; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 8: + /* y0(0) = -inf */ + exc.type = DOMAIN; /* should be SING for IEEE */ + exc.name = "y0"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "y0: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 9: + /* y0(x<0) = NaN */ + exc.type = DOMAIN; + exc.name = "y0"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "y0: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 10: + /* y1(0) = -inf */ + exc.type = DOMAIN; /* should be SING for IEEE */ + exc.name = "y1"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "y1: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 11: + /* y1(x<0) = NaN */ + exc.type = DOMAIN; + exc.name = "y1"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "y1: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 12: + /* yn(n,0) = -inf */ + exc.type = DOMAIN; /* should be SING for IEEE */ + exc.name = "yn"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "yn: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 13: + /* yn(x<0) = NaN */ + exc.type = DOMAIN; + exc.name = "yn"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "yn: DOMAIN error\n", 17); + } + errno = EDOM; + } + break; + case 14: + /* lgamma(finite) overflow */ + exc.type = OVERFLOW; + exc.name = "lgamma"; + ieee_retval = setexception(2, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 15: + /* lgamma(-integer) or lgamma(0) */ + exc.type = SING; + exc.name = "lgamma"; + ieee_retval = setexception(0, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "lgamma: SING error\n", 19); + } + errno = EDOM; + } + break; + case 16: + /* log(0) */ + exc.type = SING; + exc.name = "log"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log: SING error\n", 16); + errno = EDOM; + } else { + errno = ERANGE; + } + } + break; + case 17: + /* log(x<0) */ + exc.type = DOMAIN; + exc.name = "log"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log: DOMAIN error\n", 18); + } + errno = EDOM; + } + break; + case 18: + /* log10(0) */ + exc.type = SING; + exc.name = "log10"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log10: SING error\n", 18); + errno = EDOM; + } else { + errno = ERANGE; + } + } + break; + case 19: + /* log10(x<0) */ + exc.type = DOMAIN; + exc.name = "log10"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log10: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 20: + /* pow(0.0,0.0) */ + /* error only if lib_version == c_issue_4 */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.retval = 0.0; + ieee_retval = 1.0; + if (lib_version != c_issue_4) { + exc.retval = 1.0; + } else if (!matherr(&exc)) { + (void) write(2, "pow(0,0): DOMAIN error\n", 23); + errno = EDOM; + } + break; + case 21: + /* pow(x,y) overflow */ + exc.type = OVERFLOW; + exc.name = "pow"; + exc.retval = (lib_version == c_issue_4)? HUGE : HUGE_VAL; + if (signbit(x)) { + t = rint(y); + if (t == y) { + w = rint(0.5 * y); + if (t != w + w) { /* y is odd */ + exc.retval = -exc.retval; + } + } + } + ieee_retval = setexception(2, exc.retval); + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 22: + /* pow(x,y) underflow */ + exc.type = UNDERFLOW; + exc.name = "pow"; + exc.retval = 0.0; + if (signbit(x)) { + t = rint(y); + if (t == y) { + w = rint(0.5 * y); + if (t != w + w) /* y is odd */ + exc.retval = -exc.retval; + } + } + ieee_retval = setexception(1, exc.retval); + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 23: + /* (+-0)**neg */ + exc.type = DOMAIN; + exc.name = "pow"; + ieee_retval = setexception(0, 1.0); + { + int ahy, k, j, yisint, ly, hx; + /* INDENT OFF */ + /* + * determine if y is an odd int when x = -0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + /* INDENT ON */ + hx = __HI(x); + ahy = __HI(y)&0x7fffffff; + ly = __LO(y); + + yisint = 0; + if (ahy >= 0x43400000) { + yisint = 2; /* even integer y */ + } else if (ahy >= 0x3ff00000) { + k = (ahy >> 20) - 0x3ff; /* exponent */ + if (k > 20) { + j = ly >> (52 - k); + if ((j << (52 - k)) == ly) + yisint = 2 - (j & 1); + } else if (ly == 0) { + j = ahy >> (20 - k); + if ((j << (20 - k)) == ahy) + yisint = 2 - (j & 1); + } + } + if (hx < 0 && yisint == 1) + ieee_retval = -ieee_retval; + } + if (lib_version == c_issue_4) + exc.retval = 0.0; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "pow(0,neg): DOMAIN error\n", + 25); + } + errno = EDOM; + } + break; + case 24: + /* neg**non-integral */ + exc.type = DOMAIN; + exc.name = "pow"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = 0.0; + else + exc.retval = ieee_retval; /* X/Open allow NaN */ + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, + "neg**non-integral: DOMAIN error\n", 32); + } + errno = EDOM; + } + break; + case 25: + /* sinh(finite) overflow */ + exc.type = OVERFLOW; + exc.name = "sinh"; + ieee_retval = copysign(Inf, x); + if (lib_version == c_issue_4) + exc.retval = x > 0.0 ? HUGE : -HUGE; + else + exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 26: + /* sqrt(x<0) */ + exc.type = DOMAIN; + exc.name = "sqrt"; + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = 0.0; + else + exc.retval = ieee_retval; /* quiet NaN */ + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "sqrt: DOMAIN error\n", 19); + } + errno = EDOM; + } + break; + case 27: + /* fmod(x,0) */ + exc.type = DOMAIN; + exc.name = "fmod"; + if (fp_class(x) == fp_quiet) + ieee_retval = NaN; + else + ieee_retval = setexception(3, 1.0); + if (lib_version == c_issue_4) + exc.retval = x; + else + exc.retval = ieee_retval; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "fmod: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 28: + /* remainder(x,0) */ + exc.type = DOMAIN; + exc.name = "remainder"; + if (fp_class(x) == fp_quiet) + ieee_retval = NaN; + else + ieee_retval = setexception(3, 1.0); + exc.retval = NaN; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "remainder: DOMAIN error\n", + 24); + } + errno = EDOM; + } + break; + case 29: + /* acosh(x<1) */ + exc.type = DOMAIN; + exc.name = "acosh"; + ieee_retval = setexception(3, 1.0); + exc.retval = NaN; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "acosh: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 30: + /* atanh(|x|>1) */ + exc.type = DOMAIN; + exc.name = "atanh"; + ieee_retval = setexception(3, 1.0); + exc.retval = NaN; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "atanh: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 31: + /* atanh(|x|=1) */ + exc.type = SING; + exc.name = "atanh"; + ieee_retval = setexception(0, x); + exc.retval = ieee_retval; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "atanh: SING error\n", 18); + errno = EDOM; + } else { + errno = ERANGE; + } + } + break; + case 32: + /* scalb overflow; SVID also returns +-HUGE_VAL */ + exc.type = OVERFLOW; + exc.name = "scalb"; + ieee_retval = setexception(2, x); + exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 33: + /* scalb underflow */ + exc.type = UNDERFLOW; + exc.name = "scalb"; + ieee_retval = setexception(1, x); + exc.retval = ieee_retval; /* +-0.0 */ + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 34: + /* j0(|x|>X_TLOSS) */ + exc.type = TLOSS; + exc.name = "j0"; + exc.retval = 0.0; + ieee_retval = y; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 35: + /* y0(x>X_TLOSS) */ + exc.type = TLOSS; + exc.name = "y0"; + exc.retval = 0.0; + ieee_retval = y; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 36: + /* j1(|x|>X_TLOSS) */ + exc.type = TLOSS; + exc.name = "j1"; + exc.retval = 0.0; + ieee_retval = y; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 37: + /* y1(x>X_TLOSS) */ + exc.type = TLOSS; + exc.name = "y1"; + exc.retval = 0.0; + ieee_retval = y; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 38: + /* jn(|x|>X_TLOSS) */ + /* incorrect ieee value: ieee should never be here */ + exc.type = TLOSS; + exc.name = "jn"; + exc.retval = 0.0; + ieee_retval = 0.0; /* shall not be used */ + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 39: + /* yn(x>X_TLOSS) */ + /* incorrect ieee value: ieee should never be here */ + exc.type = TLOSS; + exc.name = "yn"; + exc.retval = 0.0; + ieee_retval = 0.0; /* shall not be used */ + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, exc.name, 2); + (void) write(2, ": TLOSS error\n", 14); + } + errno = ERANGE; + } + break; + case 40: + /* gamma(finite) overflow */ + exc.type = OVERFLOW; + exc.name = "gamma"; + ieee_retval = setexception(2, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 41: + /* gamma(-integer) or gamma(0) */ + exc.type = SING; + exc.name = "gamma"; + ieee_retval = setexception(0, 1.0); + if (lib_version == c_issue_4) + exc.retval = HUGE; + else + exc.retval = HUGE_VAL; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "gamma: SING error\n", 18); + } + errno = EDOM; + } + break; + case 42: + /* pow(NaN,0.0) */ + /* error if lib_version == c_issue_4 or ansi_1 */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.retval = x; + ieee_retval = 1.0; + if (lib_version == strict_ansi) { + exc.retval = 1.0; + } else if (!matherr(&exc)) { + switch (lib_version) { + case c_issue_4: + case ansi_1: + errno = EDOM; + } + } + break; + case 43: + /* log1p(-1) */ + exc.type = SING; + exc.name = "log1p"; + ieee_retval = setexception(0, -1.0); + if (lib_version == c_issue_4) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) { + errno = ERANGE; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log1p: SING error\n", 18); + errno = EDOM; + } else { + errno = ERANGE; + } + } + break; + case 44: + /* log1p(x<-1) */ + exc.type = DOMAIN; + exc.name = "log1p"; + ieee_retval = setexception(3, 1.0); + exc.retval = ieee_retval; + if (lib_version == strict_ansi) { + errno = EDOM; + } else if (!matherr(&exc)) { + if (lib_version == c_issue_4) { + (void) write(2, "log1p: DOMAIN error\n", 20); + } + errno = EDOM; + } + break; + case 45: + /* logb(0) */ + exc.type = DOMAIN; + exc.name = "logb"; + ieee_retval = setexception(0, -1.0); + exc.retval = -HUGE_VAL; + if (lib_version == strict_ansi) + errno = EDOM; + else if (!matherr(&exc)) + errno = EDOM; + break; + case 46: + /* nextafter overflow */ + exc.type = OVERFLOW; + exc.name = "nextafter"; + /* + * The value as returned by setexception is +/-DBL_MAX in + * round-to-{zero,-/+Inf} mode respectively, which is not + * usable. + */ + (void) setexception(2, x); + ieee_retval = x > 0 ? Inf : -Inf; + exc.retval = x > 0 ? HUGE_VAL : -HUGE_VAL; + if (lib_version == strict_ansi) + errno = ERANGE; + else if (!matherr(&exc)) + errno = ERANGE; + break; + case 47: + /* scalb(x,inf) */ + iy = ((int *)&y)[HIWORD]; + if (lib_version == c_issue_4) + /* SVID3: ERANGE in all cases */ + errno = ERANGE; + else if ((x == 0.0 && iy > 0) || (!finite(x) && iy < 0)) + /* EDOM for scalb(0,+inf) or scalb(inf,-inf) */ + errno = EDOM; + exc.retval = ieee_retval = ((iy < 0)? x / -y : x * y); + break; + } + switch (lib_version) { + case c_issue_4: + case ansi_1: + case strict_ansi: + return (exc.retval); + /* NOTREACHED */ + default: + return (ieee_retval); + } + /* NOTREACHED */ +} + +static double +setexception(int n, double x) { + /* + * n = + * 0 division by zero + * 1 underflow + * 2 overflow + * 3 invalid + */ + volatile double one = 1.0, zero = 0.0, retv; + + switch (n) { + case 0: /* division by zero */ + retv = copysign(one / zero, x); + break; + case 1: /* underflow */ + retv = DBL_MIN * copysign(DBL_MIN, x); + break; + case 2: /* overflow */ + retv = DBL_MAX * copysign(DBL_MAX, x); + break; + case 3: /* invalid */ + retv = zero * Inf; /* for Cheetah */ + break; + } + return (retv); +} diff --git a/usr/src/libm/src/C/_TBL_atan.c b/usr/src/libm/src/C/_TBL_atan.c new file mode 100644 index 0000000..a4dbc3a --- /dev/null +++ b/usr/src/libm/src/C/_TBL_atan.c @@ -0,0 +1,137 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_atan.c 1.11 06/01/31 SMI" + +#include "libm_protos.h" + +/* + * Let y[j] = _TBL_atan[2j], atan_y[j] = _TBL_atan[2j+1], j = 0, 1, ..., 95. + * {y[j], 0 <= j < 96} is a set of break points in (-1/8, 8) chosen so that + * the high part of y[j] is very close to 0x3fc08000 + (j << 16), + * and atan_y[j] = atan(y[j]) rounded has relative error bounded by 2^-60. + * + * -- K.C. Ng, 10/17/2004 + */ + +const double _TBL_atan[] = { +1.28906287871928065814e-01, 1.28199318484201185697e-01, +1.36718905591866640714e-01, 1.35876480966603985223e-01, +1.44531257606217988787e-01, 1.43537301152401930437e-01, +1.52343679482641575218e-01, 1.51181262880709432750e-01, +1.60156177403962790562e-01, 1.58807537535115006477e-01, +1.67968772982362929413e-01, 1.66415323534856884891e-01, +1.75781211596017922227e-01, 1.74003563682464612583e-01, +1.83593807762862160082e-01, 1.81571767039387044207e-01, +1.91406205589629646591e-01, 1.89118806085245338977e-01, +1.99218440148815872925e-01, 1.96643947167121080355e-01, +2.07031180070658488157e-01, 2.04147078126891479144e-01, +2.14843557086546094181e-01, 2.11626624363759674452e-01, +2.22656308649619494311e-01, 2.19082566659412503185e-01, +2.30468759807905931858e-01, 2.26513550670145669130e-01, +2.38281413377399470255e-01, 2.33919360814280885563e-01, +2.46093763828156536499e-01, 2.41298839969374956382e-01, +2.57812599322508773092e-01, 2.52318074018685223336e-01, +2.73437443946477509726e-01, 2.66912935433335718471e-01, +2.89062532292519769328e-01, 2.81392462451501401688e-01, +3.04687577351389293767e-01, 2.95751756530947318424e-01, +3.20312405527377053183e-01, 3.09986305565206343715e-01, +3.35937715576634265968e-01, 3.24092664204967739749e-01, +3.51562621385942464247e-01, 3.38066230870244233131e-01, +3.67187719833070636000e-01, 3.51904019130060419229e-01, +3.82812538440931826589e-01, 3.65602365234580339859e-01, +3.98437724467857745658e-01, 3.79158862748537828224e-01, +4.14062683287296784407e-01, 3.92570291474021892952e-01, +4.29687654458357937148e-01, 4.05834423459965343284e-01, +4.45312642848883721847e-01, 4.18949086342842669239e-01, +4.60937644536906665493e-01, 4.31912354681638355203e-01, +4.76563149131543906112e-01, 4.44722952952162131623e-01, +4.92187842452541601812e-01, 4.57378374341803173309e-01, +5.15624825518001039804e-01, 4.76069192487019954285e-01, +5.46874516057966109095e-01, 5.00440440618262982753e-01, +5.78125566624434150675e-01, 5.24180053466007933594e-01, +6.09375102172641347487e-01, 5.47284455493244337276e-01, +6.40624936950189516338e-01, 5.69756408779493739303e-01, +6.71875248719545625775e-01, 5.91599881698465779323e-01, +7.03124988865964306584e-01, 6.12820194714659649549e-01, +7.34376295967088421612e-01, 6.33426724884753156175e-01, +7.65624929092156736310e-01, 6.53426296477277901431e-01, +7.96874196003358736817e-01, 6.72832055855442590087e-01, +8.28125565205639735389e-01, 6.91656957129326954714e-01, +8.59375453355927021448e-01, 7.09911879233846576653e-01, +8.90625694745052709500e-01, 7.27611720056701827275e-01, +9.21875110259870345075e-01, 7.44770185320721367361e-01, +9.53125042657123722201e-01, 7.61402792157321428590e-01, +9.84374765277631902372e-01, 7.77524191164056688308e-01, +1.03126494373528343473e+00, 8.00788807142382097481e-01, +1.09374968909110092952e+00, 8.30144253291031475328e-01, +1.15625019152505204012e+00, 8.57735575892430546219e-01, +1.21874985186151341132e+00, 8.83672057048812575886e-01, +1.28124876006842702836e+00, 9.08066349515326720621e-01, +1.34375006271148444981e+00, 9.31026566320014126177e-01, +1.40627222899692072566e+00, 9.52659566341466756967e-01, +1.46874957658300542285e+00, 9.73037801091363618866e-01, +1.53124999999999555911e+00, 9.92272112377190040888e-01, +1.59375089676214143353e+00, 1.01043670320979472876e+00, +1.65624949800269094524e+00, 1.02760661639661776690e+00, +1.71874946971376685312e+00, 1.04385296549501305208e+00, +1.78125111924655166185e+00, 1.05924046784549474864e+00, +1.84374921332370989013e+00, 1.07382754310190620117e+00, +1.90625055239083862624e+00, 1.08767078118685489585e+00, +1.96874992734227549640e+00, 1.10081967347672460278e+00, +2.06250046973591683042e+00, 1.11934332464931074469e+00, +2.18749905173933534286e+00, 1.14201813543610697366e+00, +2.31249933788800232648e+00, 1.16264711873167669864e+00, +2.43749855191054187742e+00, 1.18147939634549814514e+00, +2.56251104936881235474e+00, 1.19873002825057639598e+00, +2.68750036758144528193e+00, 1.21457671610223272296e+00, +2.81249907059852954916e+00, 1.22918073183895870670e+00, +2.93749583903062294610e+00, 1.24267599964591468620e+00, +3.06250108260464948273e+00, 1.25518076906426045980e+00, +3.18750016629930410517e+00, 1.26679540235591403530e+00, +3.31250071362610132297e+00, 1.27760948984166233799e+00, +3.43749999999999333866e+00, 1.28770054149540058575e+00, +3.56249877589327157423e+00, 1.29713691630583838332e+00, +3.68750696071718842006e+00, 1.30597947372626776996e+00, +3.81250023149192607264e+00, 1.31427972905173717777e+00, +3.93749827850909683846e+00, 1.32208623339324304879e+00, +4.12500187917697846984e+00, 1.33296050364557672196e+00, +4.37499759905160701123e+00, 1.34608503917096200553e+00, +4.62500066729278191957e+00, 1.35785800701782477518e+00, +4.87499852385410648026e+00, 1.36847463881194641999e+00, +5.12499918742110072145e+00, 1.37809553833018583191e+00, +5.37500000000004529710e+00, 1.38685287025772296943e+00, +5.62499999999991828759e+00, 1.39485670134236627860e+00, +5.87499417854096694924e+00, 1.40219922327269230777e+00, +6.12500000000013233858e+00, 1.40895889555647713109e+00, +6.37499999999991828759e+00, 1.41520149881786494461e+00, +6.62499933107761584949e+00, 1.42098385532083781868e+00, +6.87500431528593747288e+00, 1.42635483782722261026e+00, +7.12499228632883863099e+00, 1.43135612069194451124e+00, +7.37499257154547205317e+00, 1.43602490820671135907e+00, +7.62499911873607416624e+00, 1.44039300400460135165e+00, +7.87500000000018918200e+00, 1.44448820973165936721e+00, +}; diff --git a/usr/src/libm/src/C/_TBL_exp2.c b/usr/src/libm/src/C/_TBL_exp2.c new file mode 100644 index 0000000..7b44b96 --- /dev/null +++ b/usr/src/libm/src/C/_TBL_exp2.c @@ -0,0 +1,78 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_exp2.c 1.10 06/01/31 SMI" + +#include "libm_protos.h" + +const double _TBL_exp2_hi[] = { + 1.00000000000000000e+00, 1.01088928605170048e+00, 1.02189714865411663e+00, + 1.03302487902122841e+00, 1.04427378242741375e+00, 1.05564517836055716e+00, + 1.06714040067682370e+00, 1.07876079775711986e+00, 1.09050773266525769e+00, + 1.10238258330784089e+00, 1.11438674259589243e+00, 1.12652161860824185e+00, + 1.13878863475669156e+00, 1.15118922995298267e+00, 1.16372485877757748e+00, + 1.17639699165028122e+00, 1.18920711500272103e+00, 1.20215673145270308e+00, + 1.21524735998046896e+00, 1.22848053610687002e+00, 1.24185781207348400e+00, + 1.25538075702469110e+00, 1.26905095719173322e+00, 1.28287001607877826e+00, + 1.29683955465100964e+00, 1.31096121152476441e+00, 1.32523664315974132e+00, + 1.33966752405330292e+00, 1.35425554693689265e+00, 1.36900242297459052e+00, + 1.38390988196383202e+00, 1.39897967253831124e+00, 1.41421356237309515e+00, + 1.42961333839197002e+00, 1.44518080697704665e+00, 1.46091779418064704e+00, + 1.47682614593949935e+00, 1.49290772829126484e+00, 1.50916442759342284e+00, + 1.52559815074453820e+00, 1.54221082540794074e+00, 1.55900440023783693e+00, + 1.57598084510788650e+00, 1.59314215134226700e+00, 1.61049033194925428e+00, + 1.62802742185734783e+00, 1.64575547815396495e+00, 1.66367658032673638e+00, + 1.68179283050742900e+00, 1.70010635371852348e+00, 1.71861929812247793e+00, + 1.73733383527370622e+00, 1.75625216037329945e+00, 1.77537649252652119e+00, + 1.79470907500310717e+00, 1.81425217550039886e+00, 1.83400808640934243e+00, + 1.85397912508338547e+00, 1.87416763411029996e+00, 1.89457598158696561e+00, + 1.91520656139714740e+00, 1.93606179349229435e+00, 1.95714412417540018e+00, + 1.97845602638795093e+00, +}; +const double _TBL_exp2_lo[] = { + 0.00000000000000000e+00,-1.52347786033685772e-17, 5.10922502897344389e-17, + 7.60083887402708849e-18, 8.55188970553796366e-17, 1.75932573877209198e-18, +-7.89985396684158212e-17,-6.65666043605659260e-17,-3.04678207981247115e-17, + 5.26603687157069439e-17, 1.04102784568455710e-16, 5.16585675879545612e-17, + 8.91281267602540778e-17, 3.25071021886382721e-17, 3.82920483692409350e-17, + 5.55420325421807896e-17, 3.98201523146564611e-17, 6.64498149925230124e-17, +-7.71263069268148813e-17,-1.89878163130252995e-17, 4.65802759183693679e-17, +-6.71138982129687842e-18, 2.66793213134218610e-18, 1.71359491824356097e-17, + 2.53825027948883150e-17,-7.18153613551945386e-17,-2.85873121003886076e-17, + 8.92728259483173198e-17, 7.70094837980298946e-17, 9.59379791911884877e-17, +-6.77051165879478629e-17,-9.61421320905132307e-17,-9.66729331345291345e-17, +-1.20316424890536552e-17,-3.02375813499398732e-17,-5.60037718607521580e-17, +-3.48399455689279580e-17, 1.41929201542840358e-17,-1.01645532775429504e-16, + 1.11795187801605699e-16, 7.94983480969762086e-17, 3.78120705335752750e-17, +-1.01369164712783040e-17,-1.00944065423119625e-16, 2.47071925697978879e-17, +-6.71295508470708409e-17,-1.01256799136747726e-16, 5.89099269671309967e-17, + 8.19901002058149652e-17,-8.02371937039770025e-18,-1.85138041826311099e-17, + 3.16438929929295695e-17, 2.96014069544887331e-17, 6.42973179655657203e-17, + 1.82274584279120868e-17,-9.96953153892034882e-17, 3.28310722424562659e-17, + 9.76188749072759354e-17,-6.12276341300414256e-17, 3.40340353521652967e-17, +-1.06199460561959626e-16, 1.03323859606763257e-16, 8.96076779103666777e-17, + 4.03887531092781666e-17, +}; diff --git a/usr/src/libm/src/C/_TBL_ipio2.c b/usr/src/libm/src/C/_TBL_ipio2.c new file mode 100644 index 0000000..8419b96 --- /dev/null +++ b/usr/src/libm/src/C/_TBL_ipio2.c @@ -0,0 +1,86 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_ipio2.c 1.10 06/01/31 SMI" + +#include "libm_protos.h" + +/* + * Table of constants for 2/pi, used in __rem_pio2 (trigl) function. + */ + +/* + * 396 Hex digits (476 decimal) of 2/pi + */ +const int _TBL_ipio2_inf[] = { +0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, +0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, +0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, +0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, +0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, +0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, +0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, +0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, +0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, +0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, +0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, +}; + +#if 0 /* remove from SVR4 */ +/* + * 396 Hex digits (476 decimal) of 2/PI, PI = 66 bits of pi + */ +const int _TBL_ipio2_66[] = { +0xA2F983, 0x6E4E44, 0x152A00, 0x062BC4, 0x0DA276, 0xBED4C1, +0xFDF905, 0x5CD5BA, 0x767CEC, 0x1F80D6, 0xC26053, 0x3A0070, +0x107C2A, 0xF68EE9, 0x687B7A, 0xB990AA, 0x38DE4B, 0x96CFF3, +0x92735E, 0x8B34F6, 0x195BFC, 0x27F88E, 0xA93EC5, 0x3958A5, +0x3E5D13, 0x1C55A8, 0x5B4A8B, 0xA42E04, 0x12D105, 0x35580D, +0xF62347, 0x450900, 0xB98BCA, 0xF7E8A4, 0xA2E5D5, 0x69BC52, +0xF0381D, 0x1A0A88, 0xFE8714, 0x7F6735, 0xBB7D4D, 0xC6F642, +0xB27E80, 0x6191BF, 0xB6B750, 0x52776E, 0xD60FD0, 0x607DCC, +0x68BFAF, 0xED69FC, 0x6EB305, 0xD2557D, 0x25BDFB, 0x3E4AA1, +0x84472D, 0x8B0376, 0xF77740, 0xD290DF, 0x15EC8C, 0x45A5C3, +0x6181EF, 0xC5E7E8, 0xD8909C, 0xF62144, 0x298428, 0x6E5D9D, +}; + +/* + * 396 Hex digits (476 decimal) of 2/PI, PI = 53 bits of pi + */ +const int _TBL_ipio2_53[] = { +0xA2F983, 0x6E4E44, 0x16F3C4, 0xEA69B5, 0xD3E131, 0x60E1D2, +0xD7982A, 0xC031F5, 0xD67BCC, 0xFD1375, 0x60919B, 0x3FA0BB, +0x612ABB, 0x714F9B, 0x03DA8A, 0xC05948, 0xD023F4, 0x5AFA37, +0x51631D, 0xCD7A90, 0xC0474A, 0xF6A6F3, 0x1A52E1, 0x5C3927, +0x3ADA45, 0x4E2DB5, 0x64E8C4, 0x274A5B, 0xB74ADC, 0x1E6591, +0x2822BE, 0x4771F5, 0x12A63F, 0x83BD35, 0x2488CA, 0x1FE1BE, +0x42C21A, 0x682569, 0x2AFB91, 0x68ADE1, 0x4A42E5, 0x9BE357, +0xB79675, 0xCE998A, 0x83AF8B, 0xE645E6, 0xDF0789, 0x9E9747, +0xAA15FF, 0x358C3F, 0xAF3141, 0x72A3F7, 0x2BF1D4, 0xF3AD96, +0x7D759F, 0x257FCE, 0x29FB69, 0xB1B42C, 0xC32DE1, 0x8C0BBD, +0x31EC2F, 0x942026, 0x85DCE7, 0x653FF3, 0x136FA7, 0x0D7A5F, +}; +#endif diff --git a/usr/src/libm/src/C/_TBL_log.c b/usr/src/libm/src/C/_TBL_log.c new file mode 100644 index 0000000..12d9f73 --- /dev/null +++ b/usr/src/libm/src/C/_TBL_log.c @@ -0,0 +1,298 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_log.c 1.11 06/01/31 SMI" + +#include "libm_protos.h" + +/* + * Table of constants for log, log2, and log10 + * By K.C. Ng, November 21, 2004 + * + * Y[j], 1/Y[j], log(Y[j]) for j = 0 to 255 + * where HIWORD(Y[j]) ~ 0x3fb8400 + (j<<15) + * That is, 256 Y[j] space out logrithmically between 0.09375 and 24, and + * each is chosen so that 1/Y[j] and log(Y[j]) are very close to a IEEE + * double. In addition, each log(Y[j]) has 3 trailing zeros. + */ +const double _TBL_log[] = { +9.47265623608246343e-02, 1.05567010464380857e+01, -2.35676082856530300e+00, +9.66796869131412717e-02, 1.03434344062203838e+01, -2.33635196153499791e+00, +9.86328118117651004e-02, 1.01386139321308306e+01, -2.31635129573594156e+00, +1.00585936733578435e-01, 9.94174764856737347e+00, -2.29674282498938709e+00, +1.02539062499949152e-01, 9.75238095238578850e+00, -2.27751145544242561e+00, +1.04492186859904843e-01, 9.57009351656812157e+00, -2.25864297726331742e+00, +1.06445312294918631e-01, 9.39449543094380957e+00, -2.24012392529694537e+00, +1.08398437050250693e-01, 9.22522526350104144e+00, -2.22194160843615762e+00, +1.10351562442130582e-01, 9.06194690740703912e+00, -2.20408398741152212e+00, +1.12304686894746625e-01, 8.90434787407592943e+00, -2.18653968262558962e+00, +1.14257811990227776e-01, 8.75213679118525256e+00, -2.16929787526329321e+00, +1.16210936696872255e-01, 8.60504207627572093e+00, -2.15234831939887172e+00, +1.18164061975360682e-01, 8.46280995492959498e+00, -2.13568126444263484e+00, +1.20117187499996322e-01, 8.32520325203277523e+00, -2.11928745022706622e+00, +1.22070312499895098e-01, 8.19200000000703987e+00, -2.10315806829801133e+00, +1.24023436774175100e-01, 8.06299217317146599e+00, -2.08728472499318229e+00, +1.26953123746900931e-01, 7.87692315467275872e+00, -2.06393736501443570e+00, +1.30859374098123454e-01, 7.64179109744297769e+00, -2.03363201254049386e+00, +1.34765623780674720e-01, 7.42028992220936967e+00, -2.00421812948999545e+00, +1.38671874242985771e-01, 7.21126764500034501e+00, -1.97564475345722457e+00, +1.42578124148616536e-01, 7.01369867201821506e+00, -1.94786518986246371e+00, +1.46484374166731490e-01, 6.82666670549979404e+00, -1.92083651719164372e+00, +1.50390624434435488e-01, 6.64935067435644189e+00, -1.89451920694646070e+00, +1.54296874339723084e-01, 6.48101268596180624e+00, -1.86887677685174936e+00, +1.58203124999987427e-01, 6.32098765432149001e+00, -1.84387547036714849e+00, +1.62109374999815342e-01, 6.16867469880220742e+00, -1.81948401724404896e+00, +1.66015624243955634e-01, 6.02352943919619310e+00, -1.79567337310324682e+00, +1.69921874302298687e-01, 5.88505749542848644e+00, -1.77241651049093640e+00, +1.73828124315277527e-01, 5.75280901142480605e+00, -1.74968825924644555e+00, +1.77734374286237506e-01, 5.62637364896854919e+00, -1.72746512253855222e+00, +1.81640624146994889e-01, 5.50537636993989743e+00, -1.70572513658236602e+00, +1.85546874316304788e-01, 5.38947370406942916e+00, -1.68444773712372431e+00, +1.89453124405085355e-01, 5.27835053203882509e+00, -1.66361364967629299e+00, +1.93359374570531595e-01, 5.17171718320401652e+00, -1.64320477712600699e+00, +1.97265624263334577e-01, 5.06930694962380368e+00, -1.62320411193263148e+00, +2.01171874086291030e-01, 4.97087380898513764e+00, -1.60359564135180399e+00, +2.05078123979995308e-01, 4.87619050044336610e+00, -1.58436427985572159e+00, +2.08984373896073439e-01, 4.78504675424820736e+00, -1.56549579585994181e+00, +2.12890623963011144e-01, 4.69724772930228163e+00, -1.54697674768135762e+00, +2.16796874723889421e-01, 4.61261261848719517e+00, -1.52879442500076479e+00, +2.20703124198150608e-01, 4.53097346778917753e+00, -1.51093680996032553e+00, +2.24609374375627030e-01, 4.45217392541970725e+00, -1.49339249945607477e+00, +2.28515625000094036e-01, 4.37606837606657528e+00, -1.47615069024134016e+00, +2.32421873924349737e-01, 4.30252102831546246e+00, -1.45920113655598627e+00, +2.36328123935216378e-01, 4.23140497774241098e+00, -1.44253408394829741e+00, +2.40234375000066919e-01, 4.16260162601510064e+00, -1.42614026966681173e+00, +2.44140623863132178e-01, 4.09600001907347711e+00, -1.41001089239381727e+00, +2.48046874999894917e-01, 4.03149606299383390e+00, -1.39413753858134015e+00, +2.53906248590769879e-01, 3.93846156032078243e+00, -1.37079018013412401e+00, +2.61718748558906533e-01, 3.82089554342693294e+00, -1.34048483059486401e+00, +2.69531249159214337e-01, 3.71014493910979404e+00, -1.31107094300173976e+00, +2.77343749428383191e-01, 3.60563381024826013e+00, -1.28249756949928795e+00, +2.85156249289339359e-01, 3.50684932380819214e+00, -1.25471800582335113e+00, +2.92968749999700462e-01, 3.41333333333682321e+00, -1.22768933094427446e+00, +3.00781248554318814e-01, 3.32467534065511261e+00, -1.20137202743229921e+00, +3.08593748521894806e-01, 3.24050634463533127e+00, -1.17572959680235023e+00, +3.16406249999639899e-01, 3.16049382716409077e+00, -1.15072828980826181e+00, +3.24218749999785061e-01, 3.08433734939963511e+00, -1.12633683668362750e+00, +3.32031248841858584e-01, 3.01176471638753718e+00, -1.10252619147729547e+00, +3.39843749265406558e-01, 2.94252874199264314e+00, -1.07926932798654107e+00, +3.47656249999834799e-01, 2.87640449438338930e+00, -1.05654107474789782e+00, +3.55468749999899247e-01, 2.81318681318761055e+00, -1.03431793796299587e+00, +3.63281249999864997e-01, 2.75268817204403371e+00, -1.01257795132667816e+00, +3.71093749064121570e-01, 2.69473684890124421e+00, -9.91300555400967731e-01, +3.78906249999751032e-01, 2.63917525773369288e+00, -9.70466465976836723e-01, +3.86718748879039009e-01, 2.58585859335407608e+00, -9.50057597243619156e-01, +3.94531249999987899e-01, 2.53465346534661240e+00, -9.30056927638333697e-01, +4.02343749999485523e-01, 2.48543689320706163e+00, -9.10448456251205407e-01, +4.10156249578856991e-01, 2.43809524059864202e+00, -8.91217095348825872e-01, +4.17968749447214571e-01, 2.39252336765021800e+00, -8.72348611340208357e-01, +4.25781248601723117e-01, 2.34862386092395203e+00, -8.53829565534445223e-01, +4.33593749393073047e-01, 2.30630630953458038e+00, -8.35647244566987801e-01, +4.41406248572254134e-01, 2.26548673299152270e+00, -8.17789629001761220e-01, +4.49218749348472501e-01, 2.22608695975035964e+00, -8.00245317566669279e-01, +4.57031249277175089e-01, 2.18803419149470768e+00, -7.83003511263371976e-01, +4.64843748529596368e-01, 2.15126051100659366e+00, -7.66053954531254355e-01, +4.72656248830947701e-01, 2.11570248457175136e+00, -7.49386901356188240e-01, +4.80468748609962581e-01, 2.08130081902951236e+00, -7.32993092000230995e-01, +4.88281249241778237e-01, 2.04800000318021258e+00, -7.16863708730099525e-01, +4.96093748931098810e-01, 2.01574803583926521e+00, -7.00990360175606675e-01, +5.07812497779701388e-01, 1.96923077784079825e+00, -6.77642998396260410e-01, +5.23437498033319737e-01, 1.91044776837204044e+00, -6.47337648285891021e-01, +5.39062498006593560e-01, 1.85507247062801328e+00, -6.17923763020271188e-01, +5.54687498964024250e-01, 1.80281690477552603e+00, -5.89350388745976339e-01, +5.70312499806522322e-01, 1.75342465812909332e+00, -5.61570823110474571e-01, +5.85937497921867001e-01, 1.70666667271966777e+00, -5.34542153929987052e-01, +6.01562498226483444e-01, 1.66233766723853860e+00, -5.08224845014116688e-01, +6.17187498682654212e-01, 1.62025316801528496e+00, -4.82582413587029357e-01, +6.32812500000264566e-01, 1.58024691357958624e+00, -4.57581109246760320e-01, +6.48437499353274216e-01, 1.54216867623689291e+00, -4.33189657120379490e-01, +6.64062498728508976e-01, 1.50588235582451335e+00, -4.09379009344016609e-01, +6.79687498865382267e-01, 1.47126437027210688e+00, -3.86122146934356092e-01, +6.95312498728747119e-01, 1.43820224982050338e+00, -3.63393896015796081e-01, +7.10937499999943157e-01, 1.40659340659351906e+00, -3.41170757402847080e-01, +7.26562499999845568e-01, 1.37634408602179792e+00, -3.19430770766573779e-01, +7.42187500000120126e-01, 1.34736842105241350e+00, -2.98153372318914478e-01, +7.57812499999581890e-01, 1.31958762886670744e+00, -2.77319285416786077e-01, +7.73437498602746576e-01, 1.29292929526503420e+00, -2.56910415591577124e-01, +7.89062500000142664e-01, 1.26732673267303819e+00, -2.36909747078176913e-01, +8.04687500000259015e-01, 1.24271844660154174e+00, -2.17301275689659512e-01, +8.20312499999677036e-01, 1.21904761904809900e+00, -1.98069913762487504e-01, +8.35937499999997113e-01, 1.19626168224299478e+00, -1.79201429457714445e-01, +8.51562499999758749e-01, 1.17431192660583728e+00, -1.60682381690756770e-01, +8.67187500000204725e-01, 1.15315315315288092e+00, -1.42500062607046951e-01, +8.82812500000407896e-01, 1.13274336283133503e+00, -1.24642445206814556e-01, +8.98437499999816813e-01, 1.11304347826109651e+00, -1.07098135556570995e-01, +9.14062499999708455e-01, 1.09401709401744296e+00, -8.98563291221800009e-02, +9.29687500000063949e-01, 1.07563025210076635e+00, -7.29067708080189947e-02, +9.45312499999844014e-01, 1.05785123966959604e+00, -5.62397183230410880e-02, +9.60937500000120459e-01, 1.04065040650393459e+00, -3.98459085470743157e-02, +9.76562499999976685e-01, 1.02400000000002445e+00, -2.37165266173399170e-02, +9.92187500000169420e-01, 1.00787401574785940e+00, -7.84317746085513856e-03, +1.01562500000004907e+00, 9.84615384615337041e-01, 1.55041865360135717e-02, +1.04687500000009237e+00, 9.55223880596930641e-01, 4.58095360313824362e-02, +1.07812500000002154e+00, 9.27536231884039442e-01, 7.52234212376075018e-02, +1.10937499999982481e+00, 9.01408450704367703e-01, 1.03796793681485644e-01, +1.14062500000007416e+00, 8.76712328767066285e-01, 1.31576357788784293e-01, +1.17187500000009659e+00, 8.53333333333263000e-01, 1.58605030176721007e-01, +1.20312499999950173e+00, 8.31168831169175393e-01, 1.84922338493597849e-01, +1.23437500000022027e+00, 8.10126582278336449e-01, 2.10564769107528083e-01, +1.26562500000064615e+00, 7.90123456789720069e-01, 2.35566071313277448e-01, +1.29687500000144706e+00, 7.71084337348537208e-01, 2.59957524438041876e-01, +1.32812499999945932e+00, 7.52941176470894757e-01, 2.83768173130237500e-01, +1.35937500055846350e+00, 7.35632183605830825e-01, 3.07025035705735583e-01, +1.39062499999999467e+00, 7.19101123595508374e-01, 3.29753286372464149e-01, +1.42187500000017564e+00, 7.03296703296616421e-01, 3.51976423157301710e-01, +1.45312500161088876e+00, 6.88172042247866766e-01, 3.73716410902152685e-01, +1.48437500134602307e+00, 6.73684209915422660e-01, 3.94993809147663466e-01, +1.51562499999932343e+00, 6.59793814433284220e-01, 4.15827895143264570e-01, +1.54687500000028200e+00, 6.46464646464528614e-01, 4.36236766775100371e-01, +1.57812500000061906e+00, 6.33663366336385092e-01, 4.56237433481979870e-01, +1.60937500243255216e+00, 6.21359222361793417e-01, 4.75845906381452632e-01, +1.64062500000026312e+00, 6.09523809523711768e-01, 4.95077266798011895e-01, +1.67187500000027911e+00, 5.98130841121395473e-01, 5.13945751102401260e-01, +1.70312500224662178e+00, 5.87155962528224662e-01, 5.32464800188589216e-01, +1.73437500283893620e+00, 5.76576575632799071e-01, 5.50647119589526390e-01, +1.76562500399259092e+00, 5.66371680135198341e-01, 5.68504737613959144e-01, +1.79687500443862880e+00, 5.56521737755718449e-01, 5.86049047473771623e-01, +1.82812500114411280e+00, 5.47008546666207462e-01, 6.03290852063923744e-01, +1.85937500250667465e+00, 5.37815125325376786e-01, 6.20240411099985067e-01, +1.89062500504214515e+00, 5.28925618424108568e-01, 6.36907464903988974e-01, +1.92187500371610143e+00, 5.20325202245941476e-01, 6.53301273946326866e-01, +1.95312500494870611e+00, 5.11999998702726389e-01, 6.69430656476366792e-01, +1.98437500351688123e+00, 5.03937006980894941e-01, 6.85304004871206018e-01, +2.03125000000003997e+00, 4.92307692307682621e-01, 7.08651367095930240e-01, +2.09375000579615866e+00, 4.77611938976327366e-01, 7.38956719359554093e-01, +2.15625000000061062e+00, 4.63768115941897652e-01, 7.68370601797816022e-01, +2.21875000323311955e+00, 4.50704224695355204e-01, 7.96943975698769513e-01, +2.28125000853738547e+00, 4.38356162743050726e-01, 8.24723542091080120e-01, +2.34374999999916556e+00, 4.26666666666818573e-01, 8.51752210736227866e-01, +2.40625000438447856e+00, 4.15584414827170512e-01, 8.78069520876078258e-01, +2.46875000884389584e+00, 4.05063289688167072e-01, 9.03711953249632494e-01, +2.53124999999940403e+00, 3.95061728395154743e-01, 9.28713251872476775e-01, +2.59375000434366632e+00, 3.85542168029044230e-01, 9.53104706671537905e-01, +2.65625000734081196e+00, 3.76470587194880080e-01, 9.76915356454189698e-01, +2.71875000787161980e+00, 3.67816090889081959e-01, 1.00017221875016560e+00, +2.78125001557333462e+00, 3.59550559784484969e-01, 1.02290047253181449e+00, +2.84375001147093220e+00, 3.51648350229895601e-01, 1.04512360775085789e+00, +2.90625000771072894e+00, 3.44086020592463127e-01, 1.06686359300668343e+00, +2.96875001371853831e+00, 3.36842103706616824e-01, 1.08814099342179560e+00, +3.03125000512624965e+00, 3.29896906658595002e-01, 1.10897507739479018e+00, +3.09375001373132807e+00, 3.23232321797685962e-01, 1.12938395177327244e+00, +3.15625001204422961e+00, 3.16831681959289180e-01, 1.14938461785752644e+00, +3.21875000888250318e+00, 3.10679610793130057e-01, 1.16899308818952186e+00, +3.28125000000102052e+00, 3.04761904761809976e-01, 1.18822444735810784e+00, +3.34375001587649123e+00, 2.99065419140752298e-01, 1.20709293641028914e+00, +3.40625000791328070e+00, 2.93577980969346064e-01, 1.22561198175258212e+00, +3.46875000615970519e+00, 2.88288287776354346e-01, 1.24379430028837845e+00, +3.53125000516822674e+00, 2.83185840293502689e-01, 1.26165191737618265e+00, +3.59375001425228779e+00, 2.78260868461675415e-01, 1.27919622952937750e+00, +3.65625001719730669e+00, 2.73504272217836075e-01, 1.29643803670156643e+00, +3.71875000856489324e+00, 2.68907562405871714e-01, 1.31338759261496740e+00, +3.78125001788371806e+00, 2.64462808666557803e-01, 1.33005464752659286e+00, +3.84375001532508964e+00, 2.60162600588744020e-01, 1.34644845655970613e+00, +3.90625000429340918e+00, 2.55999999718627136e-01, 1.36257783560168733e+00, +3.96875001912740766e+00, 2.51968502722644594e-01, 1.37845118847836900e+00, +4.06250002536431332e+00, 2.46153844616978895e-01, 1.40179855389937913e+00, +4.18750001743208244e+00, 2.38805969155131859e-01, 1.43210390131407017e+00, +4.31250002253733200e+00, 2.31884056759177282e-01, 1.46151778758352613e+00, +4.43750000671406397e+00, 2.25352112335092170e-01, 1.49009115631456268e+00, +4.56250002627485340e+00, 2.19178080929562313e-01, 1.51787072466748185e+00, +4.68750001185115028e+00, 2.13333332793974317e-01, 1.54489939382477459e+00, +4.81250001682742301e+00, 2.07792207065640028e-01, 1.57121670311050998e+00, +4.93750000000042366e+00, 2.02531645569602875e-01, 1.59685913022732606e+00, +5.06249999999927613e+00, 1.97530864197559108e-01, 1.62186043243251454e+00, +5.18750002327641901e+00, 1.92771083472381588e-01, 1.64625189004383721e+00, +5.31250002381002329e+00, 1.88235293273997795e-01, 1.67006253873242194e+00, +5.43750000000577405e+00, 1.83908045976816203e-01, 1.69331939641586438e+00, +5.56250002193114934e+00, 1.79775280190080267e-01, 1.71604765143503712e+00, +5.68749999999938005e+00, 1.75824175824194989e-01, 1.73827078427695980e+00, +5.81250002749782002e+00, 1.72043009938785768e-01, 1.76001077564428243e+00, +5.93749999999874767e+00, 1.68421052631614471e-01, 1.78128816936054868e+00, +6.06250001966917473e+00, 1.64948453073088669e-01, 1.80212225950800153e+00, +6.18750003004243609e+00, 1.61616160831459688e-01, 1.82253113275015188e+00, +6.31250002448351388e+00, 1.58415840969730465e-01, 1.84253179848005466e+00, +6.43750001359968849e+00, 1.55339805497076044e-01, 1.86214026810242750e+00, +6.56250003345742350e+00, 1.52380951604072529e-01, 1.88137163301601618e+00, +6.68750002403557531e+00, 1.49532709742937614e-01, 1.90024011581622965e+00, +6.81250003423489581e+00, 1.46788990088028509e-01, 1.91875916501466826e+00, +6.93750003062940923e+00, 1.44144143507740546e-01, 1.93694148348760287e+00, +7.06250002747386052e+00, 1.41592919803171097e-01, 1.95479910036266347e+00, +7.18750003617887856e+00, 1.39130434082284093e-01, 1.97234341115705192e+00, +7.31250000000050537e+00, 1.36752136752127301e-01, 1.98958521255804399e+00, +7.43750002212249761e+00, 1.34453781112678528e-01, 2.00653477384620160e+00, +7.56250003604752941e+00, 1.32231404328381430e-01, 2.02320182812357530e+00, +7.68750005007207449e+00, 1.30081299965731312e-01, 2.03959563964607682e+00, +7.81249996125652668e+00, 1.28000000634773070e-01, 2.05572501010335529e+00, +7.93750005224239974e+00, 1.25984251139310915e-01, 2.07159837080052966e+00, +8.12500004244456164e+00, 1.23076922433975874e-01, 2.09494573343974722e+00, +8.37500006149772425e+00, 1.19402984197849338e-01, 2.12525108505414195e+00, +8.62500006593247370e+00, 1.15942028099206410e-01, 2.15466497056176820e+00, +8.87500007743793873e+00, 1.12676055354884341e-01, 2.18323834408688100e+00, +9.12500001754142609e+00, 1.09589040885222130e-01, 2.21101790139090326e+00, +9.37500007707016181e+00, 1.06666665789779500e-01, 2.23804658007729174e+00, +9.62500004426353151e+00, 1.03896103418305616e-01, 2.26436388477265638e+00, +9.87500006518495788e+00, 1.01265822116353585e-01, 2.29000631738819393e+00, +1.01250000000026539e+01, 9.87654320987395445e-02, 2.31500761299286495e+00, +1.03750000409819823e+01, 9.63855417879450060e-02, 2.33939907006683256e+00, +1.06250000362555337e+01, 9.41176467376672460e-02, 2.36320971822276604e+00, +1.08750000879032314e+01, 9.19540222452362582e-02, 2.38646658505780351e+00, +1.11250000697274576e+01, 8.98876398860551373e-02, 2.40919483431994053e+00, +1.13750000462194141e+01, 8.79120875548795450e-02, 2.43141796890025930e+00, +1.16250000714972366e+01, 8.60215048472860316e-02, 2.45315795762371991e+00, +1.18750000788855150e+01, 8.42105257563797310e-02, 2.47443535656369562e+00, +1.21250000895724916e+01, 8.24742261948517991e-02, 2.49526944421096886e+00, +1.23750000985058719e+01, 8.08080801648427965e-02, 2.51567831641482442e+00, +1.26250000894226950e+01, 7.92079202310506381e-02, 2.53567898224440924e+00, +1.28750000768594433e+01, 7.76699024489580225e-02, 2.55528745251946532e+00, +1.31250000578007420e+01, 7.61904758549435401e-02, 2.57451881288155349e+00, +1.33750000809310077e+01, 7.47663546877819496e-02, 2.59338729883298669e+00, +1.36250000915049636e+01, 7.33944949199294983e-02, 2.61190634726526838e+00, +1.38750000830616607e+01, 7.20720716406179490e-02, 2.63008866561892418e+00, +1.41249999999960103e+01, 7.07964601770111474e-02, 2.64794627703222218e+00, +1.43750000290097564e+01, 6.95652172509168693e-02, 2.66549058870148414e+00, +1.46250000868097665e+01, 6.83760679702078294e-02, 2.68273239905363070e+00, +1.48750000966053975e+01, 6.72268903196987927e-02, 2.69968195792617394e+00, +1.51250001097012756e+01, 6.61157019998031836e-02, 2.71634901116988203e+00, +1.53750000510427132e+01, 6.50406501905787804e-02, 2.73274281701243282e+00, +1.56250001080665442e+01, 6.39999995573594382e-02, 2.74887220253872400e+00, +1.58750000434989929e+01, 6.29921258116476201e-02, 2.76474554751884938e+00, +1.62500000641781739e+01, 6.15384612954199342e-02, 2.78809291272517257e+00, +1.67500001015987401e+01, 5.97014921751882754e-02, 2.81839826433667184e+00, +1.72500001048300184e+01, 5.79710141404578272e-02, 2.84781214955447126e+00, +1.77500001262529885e+01, 5.63380277682904579e-02, 2.87638552303426920e+00, +1.82500001543340602e+01, 5.47945200845665337e-02, 2.90416508848516131e+00, +1.87500001096404212e+01, 5.33333330214672482e-02, 2.93119375826390893e+00, +1.92500001680268191e+01, 5.19480514946147609e-02, 2.95751106946245912e+00, +1.97500000329124035e+01, 5.06329113080278073e-02, 2.98315349301358168e+00, +2.02500001270002485e+01, 4.93827157396732261e-02, 3.00815479982416534e+00, +2.07500001519906796e+01, 4.81927707313324349e-02, 3.03254625400155930e+00, +2.12500001425219267e+01, 4.70588232137922752e-02, 3.05635690207734001e+00, +2.17500000758314478e+01, 4.59770113339538697e-02, 3.07961376102119644e+00, +2.22500001767207358e+01, 4.49438198677525880e-02, 3.10234201655475417e+00, +2.27500001365873317e+01, 4.39560436921389575e-02, 3.12456515140079816e+00, +2.32500001697599998e+01, 4.30107523741288036e-02, 3.14630513933487066e+00, +2.37500001766865303e+01, 4.21052628446554611e-02, 3.16758253792008304e+00, +}; diff --git a/usr/src/libm/src/C/_TBL_log2.c b/usr/src/libm/src/C/_TBL_log2.c new file mode 100644 index 0000000..fe4028a --- /dev/null +++ b/usr/src/libm/src/C/_TBL_log2.c @@ -0,0 +1,120 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_log2.c 1.9 06/01/31 SMI" + +#include "libm_protos.h" + +const double _TBL_log2_hi[] = { + 0.00000000000000000e+00, 1.12272500991821289e-02, 2.23678052425384521e-02, + 3.34229767322540283e-02, 4.43941056728363037e-02, 5.52824139595031738e-02, + 6.60891532897949219e-02, 7.68155455589294434e-02, 8.74627828598022461e-02, + 9.80320572853088379e-02, 1.08524441719055176e-01, 1.18941068649291992e-01, + 1.29282951354980469e-01, 1.39551281929016113e-01, 1.49747014045715332e-01, + 1.59871220588684082e-01, 1.69924974441528320e-01, 1.79908990859985352e-01, + 1.89824461936950684e-01, 1.99672341346740723e-01, 2.09453344345092773e-01, + 2.19168424606323242e-01, 2.28818655014038086e-01, 2.38404631614685059e-01, + 2.47927427291870117e-01, 2.57387638092041016e-01, 2.66786336898803711e-01, + 2.76124238967895508e-01, 2.85402059555053711e-01, 2.94620513916015625e-01, + 3.03780555725097656e-01, 3.12882900238037109e-01, 3.21928024291992188e-01, + 3.30916643142700195e-01, 3.39849948883056641e-01, 3.48727941513061523e-01, + 3.57551813125610352e-01, 3.66322040557861328e-01, 3.75039339065551758e-01, + 3.83704185485839844e-01, 3.92317295074462891e-01, 4.00879383087158203e-01, + 4.09390926361083984e-01, 4.17852401733398438e-01, 4.26264524459838867e-01, + 4.34628009796142578e-01, 4.42943334579467773e-01, 4.51210975646972656e-01, + 4.59431409835815430e-01, 4.67605352401733398e-01, 4.75733280181884766e-01, + 4.83815670013427734e-01, 4.91852998733520508e-01, 4.99845743179321289e-01, + 5.07794380187988281e-01, 5.15699386596679688e-01, 5.23561954498291016e-01, + 5.31381130218505859e-01, 5.39158344268798828e-01, 5.46894073486328125e-01, + 5.54588794708251953e-01, 5.62242031097412109e-01, 5.69855213165283203e-01, + 5.77428817749023438e-01, 5.84962368011474609e-01, 5.92456817626953125e-01, + 5.99912643432617188e-01, 6.07329845428466797e-01, 6.14709377288818359e-01, + 6.22051715850830078e-01, 6.29356384277343750e-01, 6.36624336242675781e-01, + 6.43856048583984375e-01, 6.51051521301269531e-01, 6.58211231231689453e-01, + 6.65335655212402344e-01, 6.72425270080566406e-01, 6.79480075836181641e-01, + 6.86500072479248047e-01, 6.93486690521240234e-01, 7.00439453125000000e-01, + 7.07358837127685547e-01, 7.14245319366455078e-01, 7.21098899841308594e-01, + 7.27920055389404297e-01, 7.34709262847900391e-01, 7.41466522216796875e-01, + 7.48192787170410156e-01, 7.54887104034423828e-01, 7.61550903320312500e-01, + 7.68184185028076172e-01, 7.74786949157714844e-01, 7.81359672546386719e-01, + 7.87902355194091797e-01, 7.94415473937988281e-01, 8.00899505615234375e-01, + 8.07354450225830078e-01, 8.13780784606933594e-01, 8.20178508758544922e-01, + 8.26548099517822266e-01, 8.32889556884765625e-01, 8.39203357696533203e-01, + 8.45489978790283203e-01, 8.51748943328857422e-01, 8.57980728149414062e-01, + 8.64185810089111328e-01, 8.70364665985107422e-01, 8.76516819000244141e-01, + 8.82642745971679688e-01, 8.88742923736572266e-01, 8.94817352294921875e-01, + 9.00866508483886719e-01, 9.06890392303466797e-01, 9.12889003753662109e-01, + 9.18862819671630859e-01, 9.24812316894531250e-01, 9.30737018585205078e-01, + 9.36637878417968750e-01, 9.42514419555664062e-01, 9.48367118835449219e-01, + 9.54195976257324219e-01, 9.60001468658447266e-01, 9.65784072875976562e-01, + 9.71543312072753906e-01, 9.77279663085937500e-01, 9.82993125915527344e-01, + 9.88684654235839844e-01, 9.94353294372558594e-01, +}; +const double _TBL_log2_lo[] = { + 0.00000000000000000e+00, 5.32407199143163062e-09, 7.78591605611869461e-09, + 2.48051962506972834e-08, 1.36856171339421649e-08, 2.15416864274073636e-08, + 3.71679775110542797e-08, 5.14919014488721604e-08, 5.83905371621603131e-08, + 2.56752178779050280e-08, 1.50591138779666358e-08, 4.07421543880223335e-09, + 6.55899859865622946e-08, 7.04697774403433060e-08, 1.05458966729375492e-07, + 1.16189705334564924e-07, 2.70007840425949794e-08, 9.91549491170275978e-08, + 9.69430665462702729e-08, 3.48962367368142750e-09, 2.12838570084203029e-08, + 9.58558383294243244e-08, 3.54818427912568755e-08, 1.07710393847949145e-07, + 8.61517153766060168e-08, 2.04600610755536536e-07, 2.03796097652703831e-07, + 1.66306342048863931e-07, 1.59307194630913047e-07, 2.34975611381410033e-07, + 1.92452005268177275e-07, 5.50463182513595194e-08, 7.05953701603703195e-08, + 2.34971916784423615e-07, 5.40015680851899589e-08, 2.12718016029126278e-07, + 1.91492473341603465e-07, 1.73687954457398432e-07, 9.22813729985471341e-08, + 1.06988212380721318e-07, 1.27704297398270718e-07, 5.31950261176686284e-08, + 9.77661777174938596e-09, 1.13152499419201003e-07, 2.30242259071696645e-07, + 2.17840582054596399e-07, 1.61269260528736021e-07, 1.36185356146932601e-07, + 2.08801481826511869e-07, 1.97681264041823641e-07, 1.50784512989339287e-07, + 1.07250828689716638e-07, 9.75961542029652924e-08, 1.43903884071471071e-07, + 2.60010707986588806e-07, 4.51687362770425967e-07, 1.55872185666914818e-09, + 3.30297806270353139e-07, 4.66839232562134881e-07, 3.86401308539453419e-07, + 5.69693854190458130e-08, 3.93123660542428204e-07, 3.95165664638538863e-07, + 1.02867252517587785e-08, 1.32709681572078730e-07, 2.19641127294637299e-07, + 1.98754510492326232e-07, 4.68321143892845854e-07, 4.66826389855508924e-07, + 1.03605546188658804e-07, 2.35802265869106829e-07, 2.84300973057307715e-07, + 1.41190740320740639e-07, 1.69877659083133016e-07, 2.51520105284046651e-07, + 2.61972773884411727e-07, 7.18909291834578061e-08, 2.36692644004112907e-08, + 4.54703970334185855e-07, 2.66978085000826612e-07, 2.65016092160396791e-07, + 2.94953197203117899e-07, 1.98299667558641024e-07, 2.88865876540408914e-07, + 3.99173794882405776e-07, 3.57377937852235498e-07, 4.64184350072864601e-07, + 6.24190501305044646e-08, 3.98129044716236242e-07, 3.29124166816248113e-07, + 1.39748850186603795e-07, 1.10443458567567753e-07, 4.09782728853196823e-08, + 2.04197339771775867e-07, 3.92412117682061536e-07, 3.94305070358032831e-07, + 4.71831774029316962e-07, 4.06610103464898125e-07, 4.53656642786443564e-07, + 3.87773092718157073e-07, 4.57279976050247260e-07, 4.30400410735578705e-07, + 7.21540920170394723e-08, 9.80872001232200742e-08, 2.66978158058219765e-07, + 3.34565168908893463e-07, 5.35982971014292903e-08, 1.27564755579416119e-07, + 3.03390161571307385e-07, 3.25161686840256005e-07, 4.11013021640696012e-07, + 2.99496861839592342e-07, 2.03305051732449063e-07, 3.32476299509608735e-07, + 4.17602963653023739e-07, 1.86711249657268702e-07, 3.18977681198347184e-07, + 6.05846018127542565e-08, 8.57835758121197076e-08, 1.12749228435440334e-07, + 3.34129550990056099e-07, 4.63409633672188390e-07, 2.11786110481110945e-07, + 2.41878018084726962e-07, 2.60413978970349421e-07, 4.48778782784743522e-07, + 3.25363260095300064e-08, 1.42486299343828112e-07, +}; diff --git a/usr/src/libm/src/C/_TBL_sin.c b/usr/src/libm/src/C/_TBL_sin.c new file mode 100644 index 0000000..97f3f66 --- /dev/null +++ b/usr/src/libm/src/C/_TBL_sin.c @@ -0,0 +1,798 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_sin.c 1.10 06/01/23 SMI" + +#include "libm_protos.h" + +/* + * Table of constants for x[i],sin(x[i]),cos(x[i]), where + * x[i] ~ (i+10.5)/64 chosen to make the value of sine and + * cosine nearly representable in double (with error less + * than 2**-8 ulp) + * By K.C. Ng, May 5, 1995 + * + * For each i, _TBL_sincosx[i] := x[i], _TBL_sincos[2*i] := + * sin(x[i]), and _TBL_sincos[2*i+1] := cos(x[i]). + */ + +const double _TBL_sincos[] = { + 1.63327491736778435127e-01, 9.86571908399470176576e-01, + 1.78722113534634630128e-01, 9.83899591489758251761e-01, + 1.94073102892906523831e-01, 9.80987069605669836925e-01, + 2.09376712086097482857e-01, 9.77835053797937558961e-01, + 2.24629204957583178404e-01, 9.74444313586017130113e-01, + 2.39826857830661321902e-01, 9.70815676770349522684e-01, + 2.54965960415442560727e-01, 9.66950029230792762469e-01, + 2.70042816718758793559e-01, 9.62848314709330965755e-01, + 2.85053745940880454146e-01, 9.58511534581129587274e-01, + 2.99995083378835347698e-01, 9.53940747608846839611e-01, + 3.14863181320744367486e-01, 9.49137069684131584602e-01, + 3.29654409930721814526e-01, 9.44101673557052656349e-01, + 3.44365158144533722862e-01, 9.38835788546692695533e-01, + 3.58991834544317267586e-01, 9.33340700243220688925e-01, + 3.73530868238515501023e-01, 9.27617750192923362640e-01, + 3.87978709726743087316e-01, 9.21668335573470609567e-01, + 4.02331831777567594521e-01, 9.15493908848391546584e-01, + 4.16586730281922223984e-01, 9.09095977415485534401e-01, + 4.30739925110786514573e-01, 9.02476103237949467406e-01, + 4.44787960958008266044e-01, 8.95635902466408118094e-01, + 4.58727408216676513231e-01, 8.88577045028066558885e-01, + 4.72554863751536879946e-01, 8.81301254251215970825e-01, + 4.86266951795427115890e-01, 8.73810306411857196096e-01, + 4.99860324731856597857e-01, 8.66106030321324382726e-01, + 5.13331663943585647658e-01, 8.58190306862591900661e-01, + 5.26677680590333596733e-01, 8.50065068549453184410e-01, + 5.39895116435048061376e-01, 8.41732299041438647436e-01, + 5.52980744632255882820e-01, 8.33194032663434169805e-01, + 5.65931370507619768695e-01, 8.24452353914625679643e-01, + 5.78743832357296650315e-01, 8.15509396946711651033e-01, + 5.91415002201596706755e-01, 8.06367345054898265744e-01, + 6.03941786558566895415e-01, 7.97028430138126520177e-01, + 6.16321127179607297641e-01, 7.87494932169127248578e-01, + 6.28550001844884853597e-01, 7.77769178600434929471e-01, + 6.40625425044079821468e-01, 7.67853543839638774671e-01, + 6.52544448725672743272e-01, 7.57750448655299613243e-01, + 6.64304163044103668234e-01, 7.47462359562187539375e-01, + 6.75901697026429104653e-01, 7.36991788256011193248e-01, + 6.87334219302880855551e-01, 7.26341290975047959577e-01, + 6.98598938789923074033e-01, 7.15513467882745946014e-01, + 7.09693105361432152733e-01, 7.04510962443060329008e-01, + 7.20614010544995853280e-01, 6.93336460750663685637e-01, + 7.31358988151144640000e-01, 6.81992690906972898190e-01, + 7.41925414945620254059e-01, 6.70482422333180339002e-01, + 7.52310711296420575600e-01, 6.58808465085774175307e-01, + 7.62512341773335489137e-01, 6.46973669204044199432e-01, + 7.72527815799416095466e-01, 6.34980923978180178402e-01, + 7.82354688238184881044e-01, 6.22833157267443926486e-01, + 7.91990560000511156780e-01, 6.10533334773848967991e-01, + 8.01433078627164507957e-01, 5.98084459321745920413e-01, + 8.10679938859144910701e-01, 5.85489570130274028514e-01, + 8.19728883213368231253e-01, 5.72751742053888568407e-01, + 8.28577702516849257108e-01, 5.59874084854710574177e-01, + 8.37224236455711978699e-01, 5.46859742430497508536e-01, + 8.45666374107491569667e-01, 5.33711892039036461810e-01, + 8.53902054441761149128e-01, 5.20433743544881588505e-01, + 8.61929266833302509809e-01, 5.07028538621057900393e-01, + 8.69746051561515076678e-01, 4.93499549942200410602e-01, + 8.77350500260862697921e-01, 4.79850080433476600117e-01, + 8.84740756420631879742e-01, 4.66083462405874393575e-01, + 8.91915015812867362222e-01, 4.52203056787028545571e-01, + 8.98871526946913745881e-01, 4.38212252275223035358e-01, + 9.05608591487805036913e-01, 4.24114464529888268718e-01, + 9.12124564678846838639e-01, 4.09913135321892496687e-01, + 9.18417855741508804002e-01, 3.95611731695571844369e-01, + 9.24486928255549345046e-01, 3.81213745141251114656e-01, + 9.30330300545781363475e-01, 3.66722690716563270996e-01, + 9.35946546034209125864e-01, 3.52142106210879102246e-01, + 9.41334293596668869597e-01, 3.37475551260917883134e-01, + 9.46492227896101323559e-01, 3.22726606483374089951e-01, + 9.51419089686698082886e-01, 3.07898872650964328113e-01, + 9.56113676155394554002e-01, 2.92995969713948978264e-01, + 9.60574841181938254842e-01, 2.78021536015277237475e-01, + 9.64801495637480077683e-01, 2.62979227346346711158e-01, + 9.68792607644664016675e-01, 2.47872716072285947941e-01, + 9.72547202831614887586e-01, 2.32705690227810568782e-01, + 9.76064364566613607010e-01, 2.17481852629530458820e-01, + 9.79343234187565414572e-01, 2.02204919947659544910e-01, + 9.82383011202836109454e-01, 1.86878621837941599759e-01, + 9.85182953494231017366e-01, 1.71506699998524386741e-01, + 9.87742377497998091940e-01, 1.56092907252707135957e-01, + 9.90060658366647028394e-01, 1.40641006660935985462e-01, + 9.92137230124395808062e-01, 1.25154770588626285122e-01, + 9.93971585806359803072e-01, 1.09637979777038541140e-01, + 9.95563277581850036846e-01, 9.40944224196323536491e-02, + 9.96911916861350277941e-01, 7.85278932598362233719e-02, + 9.98017174394052908326e-01, 6.29421926414276133865e-02, + 9.98878780347215333713e-01, 4.73411255892753485286e-02, + 9.99496524372108563483e-01, 3.17285008797294557081e-02, + 9.99870255655346151791e-01, 1.61081301122361006395e-02, + 9.99999882955821872699e-01, 4.83826769160181427432e-04, + 9.99885374626887313276e-01, -1.51405946795101862407e-02, + 9.99526758624139421983e-01, -3.07613197753498594789e-02, + 9.98924122498464628350e-01, -4.63745349375326090802e-02, + 9.98077613374894423437e-01, -6.19764284214149308028e-02, + 9.96987437916807328619e-01, -7.75631912448182664344e-02, + 9.95653862273598311283e-01, -9.31310181393209396417e-02, + 9.94077212020575529117e-01, -1.08676108420387079745e-01, + 9.92257872072439317535e-01, -1.24194666996109981394e-01, + 9.90196286596708996619e-01, -1.39682905217811598186e-01, + 9.87892958898728967831e-01, -1.55137041864005509328e-01, + 9.85348451302295424981e-01, -1.70553304031812708041e-01, + 9.82563385014030843401e-01, -1.85927928052160545969e-01, + 9.79538439968065888230e-01, -2.01257160431443482551e-01, + 9.76274354660002341433e-01, -2.16537258764389006771e-01, + 9.72771925969731610095e-01, -2.31764492632368090952e-01, + 9.69032008956924317822e-01, -2.46935144556029828600e-01, + 9.65055516693764658953e-01, -2.62045510739892129060e-01, + 9.60843419958733790942e-01, -2.77091902303196746526e-01, + 9.56396747083171572257e-01, -2.92070645852553878452e-01, + 9.51716583658057113659e-01, -3.06978084543891138747e-01, + 9.46804072278775166183e-01, -3.21810578937871294425e-01, + 9.41660412264228252610e-01, -3.36564507894643705210e-01, + 9.36286859366077139910e-01, -3.51236269451786098372e-01, + 9.30684725460523609719e-01, -3.65822281708577445869e-01, + 9.24855378224429758305e-01, -3.80318983708869018390e-01, + 9.18800240811794344253e-01, -3.94722836284130795814e-01, + 9.12520791499566663596e-01, -4.09030322935848345001e-01, + 9.06018563323250702979e-01, -4.23237950701107090712e-01, + 8.99295143708603639254e-01, -4.37342250991282488481e-01, + 8.92352174084417359978e-01, -4.51339780439098559039e-01, + 8.85191349474114597129e-01, -4.65227121754735961634e-01, + 8.77814418087698666859e-01, -4.79000884547570504601e-01, + 8.70223180902864101860e-01, -4.92657706140177065190e-01, + 8.62419491209962973954e-01, -5.06194252418129098103e-01, + 8.54405254167239447405e-01, -5.19607218629047684644e-01, + 8.46182426332270809510e-01, -5.32893330195106762481e-01, + 8.37753015193838712626e-01, -5.46049343497116423940e-01, + 8.29119078677651999421e-01, -5.59072046674417011403e-01, + 8.20282724626069215113e-01, -5.71958260435175724901e-01, + 8.11246110312714763246e-01, -5.84704838788333125521e-01, + 8.02011441899084687179e-01, -5.97308669837422590021e-01, + 7.92580973890125495274e-01, -6.09766676547169317324e-01, + 7.82957008603788473522e-01, -6.22075817467780289860e-01, + 7.73141895594474215514e-01, -6.34233087497477643346e-01, + 7.63138031079152456826e-01, -6.46235518615801973752e-01, + 7.52947857359473227135e-01, -6.58080180599429964694e-01, + 7.42573862219235825144e-01, -6.69764181745192588302e-01, + 7.32018578314804879703e-01, -6.81284669577975954269e-01, + 7.21284582577006005977e-01, -6.92638831525286491342e-01, + 7.10374495555637031075e-01, -7.03823895633044149811e-01, + 6.99290980797484418297e-01, -7.14837131223114541356e-01, + 6.88036744157449198234e-01, -7.25675849597612554476e-01, + 6.76614533221899572268e-01, -7.36337404613476742554e-01, + 6.65027136549188546688e-01, -7.46819193415104276568e-01, + 6.53277383052505156158e-01, -7.57118657009633100330e-01, + 6.41368141233487065733e-01, -7.67233280958732777322e-01, + 6.29302318589868403542e-01, -7.77160595898567008177e-01, + 6.17082860810903133242e-01, -7.86898178224750721732e-01, + 6.04712751105658807838e-01, -7.96443650643424705393e-01, + 5.92195009450509846083e-01, -8.05794682770934245220e-01, + 5.79532691867931770702e-01, -8.14948991689853463605e-01, + 5.66728889706594629594e-01, -8.23904342488817387213e-01, + 5.53786728799491090314e-01, -8.32658548869558479133e-01, + 5.40709368819720759269e-01, -8.41209473597735457595e-01, + 5.27500002380493770993e-01, -8.49555029111463189118e-01, + 5.14161854409658891640e-01, -8.57693177931374672873e-01, + 5.00698181184736190730e-01, -8.65621933270118271153e-01, + 4.87112269682015319727e-01, -8.73339359427499739574e-01, + 4.73407436683839610847e-01, -8.80843572317148937323e-01, + 4.59587028080454429446e-01, -8.88132739865035936155e-01, + 4.45654417892204612883e-01, -8.95205082544307417791e-01, + 4.31613007576607476956e-01, -9.02058873738668665077e-01, + 4.17466225094956511210e-01, -9.08692440215591923369e-01, + 4.03217524247773739798e-01, -9.15104162453376668296e-01, + 3.88870383625079307777e-01, -9.21292475134407928827e-01, + 3.74428305866518040812e-01, -9.27255867474522488259e-01, + 3.59894816812003803808e-01, -9.32992883591217014860e-01, + 3.45273464602750546071e-01, -9.38502122875176647554e-01, + 3.30567818825136694461e-01, -9.43782240327286303661e-01, + 3.15781469657649860316e-01, -9.48831946880402399280e-01, + 3.00918026974915431282e-01, -9.53650009721346392233e-01, + 2.85981119468962208252e-01, -9.58235252590552089025e-01, + 2.70974393771316324209e-01, -9.62586556066657106356e-01, + 2.55901513568614069616e-01, -9.66702857838587559236e-01, + 2.40766158683884484715e-01, -9.70583152971761897732e-01, + 2.25572024178931879179e-01, -9.74226494152062860721e-01, + 2.10322819513115238932e-01, -9.77631991902911057224e-01, + 1.95022267545207572681e-01, -9.80798814824694553671e-01, + 1.79674103687683967001e-01, -9.83726189782516358129e-01, + 1.64282074965636487596e-01, -9.86413402101261493904e-01, + 1.48849939140241666058e-01, -9.88859795733422641817e-01, + 1.33381463740289751829e-01, -9.91064773428305123559e-01, + 1.17880425165185737102e-01, -9.93027796873216961338e-01, + 1.02350607771443738447e-01, -9.94748386823932517764e-01, + 8.67958029390951818494e-02, -9.96226123223115322958e-01, + 7.12198081674702832000e-02, -9.97460645301151083153e-01, + 5.56264261071372570489e-02, -9.98451651667994988237e-01, + 4.00194636390110436430e-02, -9.99198900384726140800e-01, + 2.44027309972172715136e-02, -9.99702209020204901613e-01, + 8.78004077991816241078e-03, -9.99961454699081375708e-01, + -6.84479296391702837776e-03, -9.99976574130254869388e-01, + -2.24679556394218951643e-02, -9.99747563622630175395e-01, + -3.80856331006515710924e-02, -9.99274479085362488107e-01, + -5.36940124898220294547e-02, -9.98557436015947375019e-01, + -6.92892832575160572128e-02, -9.97596609469809547655e-01, + -8.48676380386628043118e-02, -9.96392234019183087312e-01, + -1.00425273601341916163e-01, -9.94944603695148255262e-01, + -1.15958391781735684067e-01, -9.93254071914831615508e-01, + -1.31463200384306394541e-01, -9.91321051397939245753e-01, + -1.46935914119801724897e-01, -9.89146014065556578032e-01, + -1.62372755568482129984e-01, -9.86729490918913376696e-01, + -1.77769956039573850948e-01, -9.84072071918356994225e-01, + -1.93123756521520834051e-01, -9.81174405835688490107e-01, + -2.08430408606563005725e-01, -9.78037200094199477007e-01, + -2.23686175400125447643e-01, -9.74661220596605204491e-01, + -2.38887332428331961021e-01, -9.71047291539024692852e-01, + -2.54030168529570332669e-01, -9.67196295214595047618e-01, + -2.69110986809851404633e-01, -9.63109171785954898404e-01, + -2.84126105504238113397e-01, -9.58786919065437892584e-01, + -2.99071858881536201125e-01, -9.54230592270622235418e-01, + -3.13944598143160502612e-01, -9.49441303765919730751e-01, + -3.28740692363219233485e-01, -9.44420222774031481450e-01, + -3.43456529243486463621e-01, -9.39168575134420757777e-01, + -3.58088516132365641820e-01, -9.33687642958886176991e-01, + -3.72633080853157161449e-01, -9.27978764333475703019e-01, + -3.87086672547184373894e-01, -9.22043333003578990947e-01, + -4.01445762590873223008e-01, -9.15882798013933796533e-01, + -4.15706845395529489551e-01, -9.09498663380709615467e-01, + -4.29866439353555507275e-01, -9.02892487684716527063e-01, + -4.43921087571260808424e-01, -8.96065883743795366101e-01, + -4.57867358817895864220e-01, -8.89020518171051099543e-01, + -4.71701848327647499381e-01, -8.81758110982984399939e-01, + -4.85421178579811707365e-01, -8.74280435207254624785e-01, + -4.99022000232008211551e-01, -8.66589316391822128693e-01, + -5.12500992809901023683e-01, -8.58686632229048840692e-01, + -5.25854865641323332426e-01, -8.50574312027670975667e-01, + -5.39080358520030999969e-01, -8.42254336324791408330e-01, + -5.52174242663304060130e-01, -8.33728736304085060738e-01, + -5.65133321393192722404e-01, -8.24999593364201810886e-01, + -5.77954430931352902689e-01, -8.16069038603239760299e-01, + -5.90634441175508673183e-01, -8.06939252296785092256e-01, + -6.03170256463835929850e-01, -7.97612463366358381833e-01, + -6.15558816459891189332e-01, -7.88090948735295393490e-01, + -6.27797096543907584554e-01, -7.78377033044423516372e-01, + -6.39882108993420795073e-01, -7.68473087746169514212e-01, + -6.51810903392718188343e-01, -7.58381530773507561705e-01, + -6.63580567511655061708e-01, -7.48104825823834529430e-01, + -6.75188227925781481176e-01, -7.37645481834222960238e-01, + -6.86631050850229573967e-01, -7.27006052250123602221e-01, + -6.97906242654146802273e-01, -7.16189134561793783185e-01, + -7.09011050643817641870e-01, -7.05197369581700761465e-01, + -7.19942763756367454242e-01, -6.94033440775618015728e-01, + -7.30698713155769064009e-01, -6.82700073672548479742e-01, + -7.41276272975477157345e-01, -6.71200035103981407225e-01, + -7.51672860805046583188e-01, -6.59536132694151233657e-01, + -7.61885938516202787518e-01, -6.47711213961349341339e-01, + -7.71913012640803364306e-01, -6.35728165897814334606e-01, + -7.81751635309322678857e-01, -6.23589913878664137137e-01, + -7.91399404523052685256e-01, -6.11299421331770620469e-01, + -8.00853964899717496451e-01, -5.98859688829029512824e-01, + -8.10113008319712335492e-01, -5.86273753251146056975e-01, + -8.19174274236826760465e-01, -5.73544687385881157837e-01, + -8.28035550507897455397e-01, -5.60675598804766250893e-01, + -8.36694673776658404130e-01, -5.47669629314764150330e-01, + -8.45149530028187490061e-01, -5.34529954158916909002e-01, + -8.53398055161871504914e-01, -5.21259781151332757254e-01, + -8.61438235389631601358e-01, -5.07862350060326539491e-01, + -8.69268107829002323328e-01, -4.94340931656873816546e-01, + -8.76885760925650292741e-01, -4.80698827006935058836e-01, + -8.84289334936661730602e-01, -4.66939366639049280305e-01, + -8.91477022398163843064e-01, -4.53065909704210345588e-01, + -8.98447068525225711610e-01, -4.39081843234753188554e-01, + -9.05197771673453388530e-01, -4.24990581257296273776e-01, + -9.11727483791179293959e-01, -4.10795563875518132679e-01, + -9.18034610707084031134e-01, -3.96500256675695827990e-01, + -9.24117612643078456536e-01, -3.82108149615860981374e-01, + -9.29975004511545022545e-01, -3.67622756346437040698e-01, + -9.35605356329172521690e-01, -3.53047613231079804308e-01, + -9.41007293511755382731e-01, -3.38386278619096869669e-01, + -9.46179497257704227309e-01, -3.23642331855951870256e-01, + -9.51120704853153031699e-01, -3.08819372448752571536e-01, + -9.55829709968717189383e-01, -2.93921019223052470970e-01, + -9.60305362967905695726e-01, -2.78950909399985458315e-01, + -9.64546571183209522360e-01, -2.63912697721639999404e-01, + -9.68552299193694232748e-01, -2.48810055517474232323e-01, + -9.72321569045517364316e-01, -2.33646669928897571245e-01, + -9.75853460530087812863e-01, -2.18426242863471758993e-01, + -9.79147111396304836717e-01, -2.03152490125698942380e-01, + -9.82201717531947959827e-01, -1.87829140649930864670e-01, + -9.85016533205280153673e-01, -1.72459935382833828843e-01, + -9.87590871221861066331e-01, -1.57048626479970948600e-01, + -9.89924103089018792012e-01, -1.41598976420741456961e-01, + -9.92015659185421450061e-01, -1.26114756991058563074e-01, + -9.93865028889118318212e-01, -1.10599748423005059261e-01, + -9.95471760691319929037e-01, -9.50577385914659067634e-02, + -9.96835462344218936614e-01, -7.94925217425341834598e-02, + -9.97955800916290658442e-01, -6.39078979276023889655e-02, + -9.98832502892746831868e-01, -4.83076719063431220258e-02, + -9.99465354238023406808e-01, -3.26956522776712110723e-02, + -9.99854200451614993916e-01, -1.70756504784357332483e-02, + -9.99998946602528415717e-01, -1.45147987706449187358e-03, + -9.99899557352339485305e-01, 1.41730450713867285606e-02, + -9.99556056965451689145e-01, 2.97941098823021957576e-02, + -9.98968529303411734155e-01, 4.54079008695470534573e-02, + -9.98137117802025963798e-01, 6.10106061751933687054e-02, + -9.97062025438244736719e-01, 7.65984166219185330649e-02, + -9.95743514682696617690e-01, 9.21675266422526118237e-02, + -9.94181907425219280050e-01, 1.07714135322866152999e-01, + -9.92377584917212285376e-01, 1.23234447107459038628e-01, + -9.90330987653228356216e-01, 1.38724672981345553691e-01, + -9.88042615281836456020e-01, 1.54181031216647779214e-01, + -9.85513026476385278762e-01, 1.69599748364658631239e-01, + -9.82742838804682716791e-01, 1.84977060140206039929e-01, + -9.79732728555263054915e-01, 2.00309212463279484595e-01, + -9.76483430616286174342e-01, 2.15592462140605983789e-01, + -9.72995738247511954278e-01, 2.30823078032026951512e-01, + -9.69270502929450938900e-01, 2.45997341755737758406e-01, + -9.65308634114379171542e-01, 2.61111548776057855736e-01, + -9.61111099038787108917e-01, 2.76162009162112587202e-01, + -9.56678922485658334018e-01, 2.91145048509638459944e-01, + -9.52013186489632401432e-01, 3.06057008986653333871e-01, + -9.47115030121562395671e-01, 3.20894250054175877995e-01, + -9.41985649202698782645e-01, 3.35653149391108962529e-01, + -9.36626296000886870985e-01, 3.50330103815899684960e-01, + -9.31038278925287121623e-01, 3.64921530162087393023e-01, + -9.25222962204842236389e-01, 3.79423866156172462372e-01, + -9.19181765559584973424e-01, 3.93833571274420646269e-01, + -9.12916163872961705650e-01, 4.08147127564896294860e-01, + -9.06427686803489396361e-01, 4.22361040575566504263e-01, + -8.99717918410242289973e-01, 4.36471840204543548580e-01, + -8.92788496793018526709e-01, 4.50476081489419755144e-01, + -8.85641113671704172106e-01, 4.64370345494136360642e-01, + -8.78277513965914136129e-01, 4.78151240155093082418e-01, + -8.70699495405757306621e-01, 4.91815401040023969514e-01, + -8.62908908048144129843e-01, 5.05359492253939501794e-01, + -8.54907653871092576559e-01, 5.18780207171229856833e-01, + -8.46697686222891654495e-01, 5.32074269388026044325e-01, + -8.38281009508205721126e-01, 5.45238433254574883513e-01, + -8.29659678498936070667e-01, 5.58269484991829045839e-01, + -8.20835797971514846694e-01, 5.71164243250981584765e-01, + -8.11811522157973475267e-01, 5.83919559949445554636e-01, + -8.02589054191142126093e-01, 5.96532321079560556853e-01, + -7.93170645644559635379e-01, 6.08999447362468804279e-01, + -7.83558595847759331576e-01, 6.21317895181756174594e-01, + -7.73755251444074421130e-01, 6.33484657164415598807e-01, + -7.63763005819449558587e-01, 6.45496762921116018497e-01, + -7.53584298396099971917e-01, 6.57351279918779618505e-01, + -7.43221614171602262822e-01, 6.69045314031985416392e-01, + -7.32677483058112311021e-01, 6.80576010317458623966e-01, + -7.21954479231692536345e-01, 6.91940553745258979390e-01, + -7.11055220593523329420e-01, 7.03136169789818077369e-01, + -6.99982367997418419847e-01, 7.14160125246941168697e-01, + -6.88738624756222161949e-01, 7.25009728740868553132e-01, + -6.77326735865867002317e-01, 7.35682331500009611958e-01, + -6.65749487360529190738e-01, 7.46175327975397872926e-01, + -6.54009705667427665432e-01, 7.56486156444917789976e-01, + -6.42110256878597240870e-01, 7.66612299673897656938e-01, + -6.30054046069779882799e-01, 7.76551285512489308793e-01, + -6.17844016641709514737e-01, 7.86300687459981162419e-01, + -6.05483149427811451204e-01, 7.95858125396090021475e-01, + -5.92974462184078454641e-01, 8.05221265986873269149e-01, + -5.80321008740226185196e-01, 8.14387823346301220617e-01, + -5.67525878248187232167e-01, 8.23355559596596009442e-01, + -5.54592194460652221366e-01, 8.32122285390385463266e-01, + -5.41523114921985349035e-01, 8.40685860476545809838e-01, + -5.28321830279222970361e-01, 8.49044194168013799384e-01, + -5.14991563445484024086e-01, 8.57195245892075630145e-01, + -5.01535568812419785267e-01, 8.65137025687840122146e-01, + -4.87957131464199334037e-01, 8.72867594686175807261e-01, + -4.74259566375507701785e-01, 8.80385065582847903265e-01, + -4.60446217616484521074e-01, 8.87687603091691812551e-01, + -4.46520457522199765155e-01, 8.94773424400929218159e-01, + -4.32485685857187662773e-01, 9.01640799614035870491e-01, + -4.18345329015600841949e-01, 9.08288052156819181171e-01, + -4.04102839158860249746e-01, 9.14713559199681003342e-01, + -3.89761693387688290535e-01, 9.20915752046603697245e-01, + -3.75325392887144893006e-01, 9.26893116521052995438e-01, + -3.60797462091837162212e-01, 9.32644193327814230443e-01, + -3.46181447754430826613e-01, 9.38167578437160809557e-01, + -3.31480918189186846146e-01, 9.43461923384538936332e-01, + -3.16699462305234713533e-01, 9.48525935636751693636e-01, + -3.01840688808588275549e-01, 9.53358378879399670502e-01, + -2.86908225223433177575e-01, 9.57958073351407035645e-01, + -2.71905717092672694069e-01, 9.62323896103759568454e-01, + -2.56836827106365517270e-01, 9.66454781271185447977e-01, + -2.41705234084330145006e-01, 9.70349720366960877271e-01, + -2.26514632188532627488e-01, 9.74007762497041795768e-01, + -2.11268729991721526673e-01, 9.77428014601425809715e-01, + -1.95971249573089145724e-01, 9.80609641672343546048e-01, + -1.80625925602857506647e-01, 9.83551866959801457391e-01, + -1.65236504388101917984e-01, 9.86253972168224413153e-01, + -1.49806743037279310737e-01, 9.88715297616337362996e-01, + -1.34340408538235145386e-01, 9.90935242401732363504e-01, + -1.18841276732320783038e-01, 9.92913264562737096774e-01, + -1.03313131549733094872e-01, 9.94648881188425981748e-01, + -8.77597639605576101962e-02, 9.96141668554020087711e-01, + -7.21849710624100776579e-02, 9.97391262219956997725e-01, + -5.65925552406322598942e-02, 9.98397357113557260000e-01, + -4.09863231473179684405e-02, 9.99159707611782965664e-01, + -2.53700848500082870585e-02, 9.99678127596429599855e-01, + -9.74765281333290004029e-03, 9.99952490503739244154e-01, + 5.87715899658624793545e-03, 9.99982729351926780126e-01, + 2.15005359577336609134e-02, 9.99768836758543000265e-01, + 3.71186638844091532086e-02, 9.99310864942154153390e-01, + 5.27277298119544560184e-02, 9.98608925710599448777e-01, + 6.83239230305028866219e-02, 9.97663190431380964007e-01, + 8.39034359259593492952e-02, 9.96473889994022088423e-01, + 9.94624650198910192911e-02, 9.95041314746361149624e-01, + 1.14997211772979862632e-01, 9.93365814433152527485e-01, + 1.30503883601530007441e-01, 9.91447798103822663940e-01, + 1.45978694798140268274e-01, 9.89287734011208397256e-01, + 1.61417867390196478894e-01, 9.86886149506213783411e-01, + 1.76817632086965909055e-01, 9.84243630908099076393e-01, + 1.92174229316510819521e-01, 9.81360823340021615202e-01, + 2.07483909972419000578e-01, 9.78238430599900898876e-01, + 2.22742936384479617296e-01, 9.74877214981876405453e-01, + 2.37947583337762752498e-01, 9.71277997065576714775e-01, + 2.53094138761417730699e-01, 9.67441655566172231673e-01, + 2.68178904913313143066e-01, 9.63369127053330553956e-01, + 2.83198199008898365836e-01, 9.59061405791160170864e-01, + 2.98148354355895761625e-01, 9.54519543432648220893e-01, + 3.13025720984674848957e-01, 9.49744648840952665481e-01, + 3.27826666953088208256e-01, 9.44737887688658850571e-01, + 3.42547578723123691269e-01, 9.39500482336717790410e-01, + 3.57184862422095295020e-01, 9.34033711413302714099e-01, + 3.71734944552921997563e-01, 9.28338909557407276907e-01, + 3.86194272922183889918e-01, 9.22417467073399333088e-01, + 4.00559317492650446280e-01, 9.16270829596698477282e-01, + 4.14826571255144882500e-01, 9.09900497736263580428e-01, + 4.28992551069135752417e-01, 9.03308026714694345394e-01, + 4.43053798493044215245e-01, 8.96495025998965022751e-01, + 4.57006880688855809947e-01, 8.89463158879018389591e-01, + 4.70848391227359996947e-01, 8.82214142075838037016e-01, + 4.84574950851524355322e-01, 8.74749745359918784438e-01, + 4.98183208470846405902e-01, 8.67071791028685923131e-01, + 5.11669841801385194557e-01, 8.59182153557058847504e-01, + 5.25031558273095666500e-01, 8.51082759088283347104e-01, + 5.38265095838926344030e-01, 8.42775584958125989488e-01, + 5.51367223674840811753e-01, 8.34262659272904327779e-01, + 5.64334743129053073574e-01, 8.25546060312485341370e-01, + 5.77164488339731551747e-01, 8.16627916127985353789e-01, + 5.89853327114563730227e-01, 8.07510403952716560028e-01, + 6.02398161667909270989e-01, 7.98195749687458211419e-01, + 6.14795929310800737255e-01, 7.88686227407876638829e-01, + 6.27043603440996633047e-01, 7.78984158621810585110e-01, + 6.39138193783907904155e-01, 7.69091912092854990135e-01, + 6.51076747732772576072e-01, 7.59011902779999636515e-01, + 6.62856350634406732425e-01, 7.48746591594002808279e-01, + 6.74474126652610750376e-01, 7.38298484676894073431e-01, + 6.85927239488512419108e-01, 7.27670132771483846312e-01, + 6.97212893028884672653e-01, 7.16864130637244967303e-01, + 7.08328332056515685977e-01, 7.05883116391116449684e-01, + 7.19270842858181325141e-01, 6.94729770928295131682e-01, + 7.30037753982098469585e-01, 6.83406817174640912604e-01, + 7.40626436901593243611e-01, 6.71917019402284765306e-01, + 7.51034306483622016160e-01, 6.60263182742052423535e-01, + 7.61258821807797358971e-01, 6.48448152298858992992e-01, + 7.71297486713702129535e-01, 6.36474812533164180373e-01, + 7.81147850424134593261e-01, 6.24346086539952493943e-01, + 7.90807508031525441261e-01, 6.12064935477412253029e-01, + 8.00274101326324149852e-01, 5.99634357543281759639e-01, + 8.09545319236430693799e-01, 5.87057387401253572001e-01, + 8.18618898249645288168e-01, 5.74337095640301553701e-01, + 8.27492623168671781464e-01, 5.61476587758947043305e-01, + 8.36164327654276950952e-01, 5.48479003388890884452e-01, + 8.44631894603476873762e-01, 5.35347515748920921297e-01, + 8.52893256793554432882e-01, 5.22085330684634363330e-01, + 8.60946397328884449607e-01, 5.08695685971892852528e-01, + 8.68789350153792105935e-01, 4.95181850494696151888e-01, + 8.76420200509378299891e-01, 4.81547123487516159912e-01, + 8.83837085454141080376e-01, 4.67794833635354845303e-01, + 8.91038194240763248288e-01, 4.53928338401734798868e-01, + 8.98021768869999070795e-01, 4.39951022996421692302e-01, + 9.04786104293555437650e-01, 4.25866300001880193626e-01, + 9.11329549200603827863e-01, 4.11677607787725330368e-01, + 9.17650506064666360295e-01, 3.97388410398770597354e-01, + 9.23747431723077494503e-01, 3.83002196318791732210e-01, + 9.29618837697029576361e-01, 3.68522477738907783262e-01, + 9.35263290560562010612e-01, 3.53952789690701208336e-01, + 9.40679412304837647696e-01, 3.39296689146571628370e-01, + 9.45865880661811875285e-01, 3.24557754182295044032e-01, + 9.50821429431150111355e-01, 3.09739583092804637854e-01, + 9.55544848784945832776e-01, 2.94845793526980815003e-01, + 9.60034985637467253028e-01, 2.79880021352128749434e-01, + 9.64290743580318188144e-01, 2.64845920952762714506e-01, + 9.68311083831862262628e-01, 2.49747162002622591359e-01, + 9.72095024823529496594e-01, 2.34587430851146777622e-01, + 9.75641642748477533331e-01, 2.19370428579268944569e-01, + 9.78950071770562035844e-01, 2.04099870113656461923e-01, + 9.82019504170923540620e-01, 1.88779483598969205493e-01, + 9.84849190595408208182e-01, 1.73413009268535894813e-01, + 9.87438440210647860873e-01, 1.58004198660550820854e-01, + 9.89786620894844482166e-01, 1.42556813578185059832e-01, + 9.91893159367450705233e-01, 1.27074625319365142051e-01, + 9.93757541353338824663e-01, 1.11561413595234956708e-01, + 9.95379311685924861308e-01, 9.60209657713066710993e-02, + 9.96758074438687136087e-01, 8.04570757688883031467e-02, + 9.97893492999770703733e-01, 6.48735433648924275651e-02, + 9.98785290176304019205e-01, 4.92741730264058125366e-02, + 9.99433248251151762354e-01, 3.36627730609296640929e-02, + 9.99837209032161888800e-01, 1.80431547900308138221e-02, + 9.99997073896832011641e-01, 2.41913161566219324719e-03, + 9.99912803818512774257e-01, -1.32054821873487954892e-02, + 9.99584419370001642235e-01, -2.88268720595330242562e-02, + 9.99012000721555049054e-01, -4.44412242666163900817e-02, + 9.98195687620527460915e-01, -6.00447267941353959864e-02, + 9.97135679355775073063e-01, -7.56335702958476074897e-02, + 9.95832234722008102779e-01, -9.12039488650100010902e-02, + 9.94285671925894676271e-01, -1.06752061351864019345e-01, + 9.92496368545773943737e-01, -1.22274111828511194977e-01, + 9.90464761404806215417e-01, -1.37766310886661608182e-01 +}; + +const double _TBL_sincosx[] = { + 1.64062500000167837966e-01, 1.79687499999472477530e-01, + 1.95312499999996669331e-01, 2.10937500000106192832e-01, + 2.26562499999874683576e-01, 2.42187499999999750200e-01, + 2.57812499999549193941e-01, 2.73437500000180466753e-01, + 2.89062500000347444296e-01, 3.04687500000159650071e-01, + 3.20312500001052657961e-01, 3.35937499999853450561e-01, + 3.51562499998759436792e-01, 3.67187499998127386824e-01, + 3.82812499999808708573e-01, 3.98437499999694078046e-01, + 4.14062499999775512904e-01, 4.29687499999869215728e-01, + 4.45312499999981514787e-01, 4.60937499992721433362e-01, + 4.76562499999932387418e-01, 4.92187500000263733479e-01, + 5.07812500002462252624e-01, 5.23437499998664290679e-01, + 5.39062500000133337785e-01, 5.54687499999937494444e-01, + 5.70312499999814259688e-01, 5.85937500002074562744e-01, + 6.01562499999652833260e-01, 6.17187499999419131314e-01, + 6.32812500000347721851e-01, 6.48437500005533351555e-01, + 6.64062499997531863194e-01, 6.79687499999813815599e-01, + 6.95312500005013212068e-01, 7.10937499999876987289e-01, + 7.26562500001548428052e-01, 7.42187500000339617223e-01, + 7.57812499998633315457e-01, 7.73437500000337285755e-01, + 7.89062499996497468402e-01, 8.04687500000179967152e-01, + 8.20312500001350475287e-01, 8.35937499996779354028e-01, + 8.51562500000668243239e-01, 8.67187499999485522650e-01, + 8.82812500000538014078e-01, 8.98437500000525690602e-01, + 9.14062500000757727214e-01, 9.29687500002357114504e-01, + 9.45312499999430455588e-01, 9.60937500000796696042e-01, + 9.76562500001389000026e-01, 9.92187499998313238159e-01, + 1.00781250000027000624e+00, 1.02343750000073119288e+00, + 1.03906249999567279474e+00, 1.05468750000121480603e+00, + 1.07031249999813948826e+00, 1.08593749999936250994e+00, + 1.10156249999885291757e+00, 1.11718750000074029671e+00, + 1.13281249999926680871e+00, 1.14843749999650057703e+00, + 1.16406249999956079577e+00, 1.17968749999995736744e+00, + 1.19531250000235189646e+00, 1.21093750000001554312e+00, + 1.22656249999714606069e+00, 1.24218750000679789558e+00, + 1.25781249999789324079e+00, 1.27343750000030864200e+00, + 1.28906250000041366910e+00, 1.30468750000013344881e+00, + 1.32031249999823008245e+00, 1.33593749999817146268e+00, + 1.35156249999504352033e+00, 1.36718750000051336713e+00, + 1.38281250000255573340e+00, 1.39843749999889488400e+00, + 1.41406250000066702199e+00, 1.42968750000377853304e+00, + 1.44531250000268074452e+00, 1.46093749999857935862e+00, + 1.47656250000000177636e+00, 1.49218750000007549517e+00, + 1.50781249999986965982e+00, 1.52343749999979238829e+00, + 1.53906250000026356695e+00, 1.55468750000024247271e+00, + 1.57031250000686006807e+00, 1.58593749999970379250e+00, + 1.60156249999876076906e+00, 1.61718749999920530236e+00, + 1.63281249999894950697e+00, 1.64843749999433342168e+00, + 1.66406250000158717484e+00, 1.67968749999775224246e+00, + 1.69531250000185917948e+00, 1.71093749999863442568e+00, + 1.72656249999789279670e+00, 1.74218750000263478128e+00, + 1.75781250000296740410e+00, 1.77343749999920641258e+00, + 1.78906249999844191301e+00, 1.80468749999888578017e+00, + 1.82031250003296385387e+00, 1.83593749999912847493e+00, + 1.85156249999896371783e+00, 1.86718749999873900869e+00, + 1.88281249999986122212e+00, 1.89843750000025601743e+00, + 1.91406250000089750429e+00, 1.92968749999936717288e+00, + 1.94531249999502553472e+00, 1.96093749999814637164e+00, + 1.97656250000163713487e+00, 1.99218750000058819616e+00, + 2.00781250000015099033e+00, 2.02343750000025890401e+00, + 2.03906249999571986820e+00, 2.05468749999347455315e+00, + 2.07031249999880184731e+00, 2.08593749999950617280e+00, + 2.10156249999859534583e+00, 2.11718749999749178414e+00, + 2.13281250000269562150e+00, 2.14843750000770983277e+00, + 2.16406250000204325445e+00, 2.17968750000288169488e+00, + 2.19531250000207567297e+00, 2.21093749999685940111e+00, + 2.22656249999882449586e+00, 2.24218750000040500936e+00, + 2.25781249999956967756e+00, 2.27343749999970867748e+00, + 2.28906249999833111275e+00, 2.30468749999696020936e+00, + 2.32031250000405675493e+00, 2.33593750000527755617e+00, + 2.35156250000277511347e+00, 2.36718749998901101250e+00, + 2.38281250000068833828e+00, 2.39843750000151390012e+00, + 2.41406250000618571860e+00, 2.42968749999278221807e+00, + 2.44531250000394617672e+00, 2.46093750000379341003e+00, + 2.47656250000329514194e+00, 2.49218749999781508109e+00, + 2.50781249999807354101e+00, 2.52343750000954214485e+00, + 2.53906250000098099306e+00, 2.55468750001107025582e+00, + 2.57031250000341415785e+00, 2.58593750002171240965e+00, + 2.60156250000635891340e+00, 2.61718750000451771953e+00, + 2.63281250000028421709e+00, 2.64843750001994493459e+00, + 2.66406250000455235849e+00, 2.67968749999316235844e+00, + 2.69531249997396704643e+00, 2.71093749999957500663e+00, + 2.72656249999638511383e+00, 2.74218749999314947985e+00, + 2.75781249999954258811e+00, 2.77343750000063726802e+00, + 2.78906249999834177089e+00, 2.80468750000019895197e+00, + 2.82031249999983835153e+00, 2.83593749999777511306e+00, + 2.85156249999855315735e+00, 2.86718750000235678144e+00, + 2.88281249999902611236e+00, 2.89843749999328359479e+00, + 2.91406250000365130148e+00, 2.92968749999994892974e+00, + 2.94531249999847322130e+00, 2.96093749999701350006e+00, + 2.97656250000468292072e+00, 2.99218750000308997272e+00, + 3.00781249999819877416e+00, 3.02343749999709299203e+00, + 3.03906249999948618878e+00, 3.05468750000752597984e+00, + 3.07031250000433075797e+00, 3.08593749999511279825e+00, + 3.10156249999957589480e+00, 3.11718749999961186603e+00, + 3.13281249999836441944e+00, 3.14843750000262057043e+00, + 3.16406249999657873673e+00, 3.17968750000540190115e+00, + 3.19531250000325739435e+00, 3.21093750000270583556e+00, + 3.22656250000035882408e+00, 3.24218749999618305324e+00, + 3.25781250000001199041e+00, 3.27343750000431255032e+00, + 3.28906249999634914261e+00, 3.30468749999773381276e+00, + 3.32031250000108801856e+00, 3.33593750000042854609e+00, + 3.35156249999819699781e+00, 3.36718749999951061369e+00, + 3.38281250000727817806e+00, 3.39843750000385558252e+00, + 3.41406250000184297022e+00, 3.42968750000183808524e+00, + 3.44531249999830135877e+00, 3.46093749998354383024e+00, + 3.47656249999984101606e+00, 3.49218750000081934459e+00, + 3.50781249999577759979e+00, 3.52343749999866640010e+00, + 3.53906249999683852892e+00, 3.55468750000498978636e+00, + 3.57031249999826005848e+00, 3.58593750001092637092e+00, + 3.60156250000782085507e+00, 3.61718749999987299049e+00, + 3.63281250000544186918e+00, 3.64843749999226352188e+00, + 3.66406250000062438943e+00, 3.67968749999757616109e+00, + 3.69531250001872235700e+00, 3.71093750000574784664e+00, + 3.72656249999563016218e+00, 3.74218749999581179466e+00, + 3.75781250000033528735e+00, 3.77343749999415045693e+00, + 3.78906249995283994636e+00, 3.80468750000592104143e+00, + 3.82031249998920063859e+00, 3.83593750000164934733e+00, + 3.85156250000057731597e+00, 3.86718750000405053768e+00, + 3.88281249997192157153e+00, 3.89843749998371702503e+00, + 3.91406249999986277643e+00, 3.92968749999597033451e+00, + 3.94531249999519229021e+00, 3.96093749997563104870e+00, + 3.97656250000223510099e+00, 3.99218750000022870594e+00, + 4.00781250004454392410e+00, 4.02343749999355093649e+00, + 4.03906249999698196973e+00, 4.05468749999250022142e+00, + 4.07031249994990851349e+00, 4.08593749999590372113e+00, + 4.10156249999066258027e+00, 4.11718749999303490483e+00, + 4.13281249999853184107e+00, 4.14843749998088373587e+00, + 4.16406249999834177089e+00, 4.17968749999662758654e+00, + 4.19531249999891109326e+00, 4.21093749999872102308e+00, + 4.22656249999120881000e+00, 4.24218750000338129524e+00, + 4.25781250000494537744e+00, 4.27343749997698019172e+00, + 4.28906250000330668826e+00, 4.30468749999959232611e+00, + 4.32031250000562039304e+00, 4.33593749999550670537e+00, + 4.35156250000948219281e+00, 4.36718750000763922259e+00, + 4.38281249999987476684e+00, 4.39843750000314237525e+00, + 4.41406250000408473255e+00, 4.42968750000079314333e+00, + 4.44531249998868371875e+00, 4.46093750000322319949e+00, + 4.47656249999480770896e+00, 4.49218749997964028609e+00, + 4.50781250000320810045e+00, 4.52343749999724753508e+00, + 4.53906249999181721222e+00, 4.55468750000258193467e+00, + 4.57031249999976196818e+00, 4.58593750000821920310e+00, + 4.60156250004601385939e+00, 4.61718750000444977388e+00, + 4.63281249999695177166e+00, 4.64843749999638600201e+00, + 4.66406250000544897460e+00, 4.67968749999663469197e+00, + 4.69531249998381028377e+00, 4.71093749999796340688e+00, + 4.72656250000119992905e+00, 4.74218750001258992910e+00, + 4.75781250000492050845e+00, 4.77343750000340971695e+00, + 4.78906250000747402140e+00, 4.80468749998990762862e+00, + 4.82031250001256594828e+00, 4.83593750000031530334e+00, + 4.85156250000026023628e+00, 4.86718750000094679820e+00, + 4.88281250000185362836e+00, 4.89843749997600141910e+00, + 4.91406249999471889112e+00, 4.92968749998860822359e+00, + 4.94531250000475353090e+00, 4.96093749999659205940e+00, + 4.97656250000856825721e+00, 4.99218750002637179364e+00, + 5.00781249999760014191e+00, 5.02343749998691091463e+00, + 5.03906249999699618058e+00, 5.05468750000537525580e+00, + 5.07031250000353406193e+00, 5.08593749999286881547e+00, + 5.10156249998831601289e+00, 5.11718750000479172257e+00, + 5.13281250001085087575e+00, 5.14843750000346744855e+00, + 5.16406250000581845683e+00, 5.17968750000350119933e+00, + 5.19531249999482636071e+00, 5.21093750000432454073e+00, + 5.22656250000434585701e+00, 5.24218750001077093970e+00, + 5.25781249998869881779e+00, 5.27343750002139977084e+00, + 5.28906249999702104958e+00, 5.30468749998945909851e+00, + 5.32031249999385913441e+00, 5.33593749999546851370e+00, + 5.35156250001908162517e+00, 5.36718749999724487054e+00, + 5.38281249999679634044e+00, 5.39843750001770139590e+00, + 5.41406249999678212959e+00, 5.42968749999906563630e+00, + 5.44531250000517097476e+00, 5.46093749999811794993e+00, + 5.47656250001082511858e+00, 5.49218749999457500621e+00, + 5.50781250001214406353e+00, 5.52343750001415045858e+00, + 5.53906250000498356911e+00, 5.55468750000498889818e+00, + 5.57031250000316013882e+00, 5.58593750000908428888e+00, + 5.60156250002763478335e+00, 5.61718749999503863535e+00, + 5.63281250000129496414e+00, 5.64843750001081890133e+00, + 5.66406250000738609174e+00, 5.67968750000023270275e+00, + 5.69531249998335997731e+00, 5.71093749999160404940e+00, + 5.72656250000217958984e+00, 5.74218750000474997819e+00, + 5.75781250000163868918e+00, 5.77343749999750688318e+00, + 5.78906249999925304195e+00, 5.80468749999988631316e+00, + 5.82031249999487254598e+00, 5.83593749999551025809e+00, + 5.85156249999513455862e+00, 5.86718749999803179662e+00, + 5.88281250000295141689e+00, 5.89843750000985433957e+00, + 5.91406249999845634591e+00, 5.92968750000455990801e+00, + 5.94531250000243982612e+00, 5.96093750000733901828e+00, + 5.97656249999234212567e+00, 5.99218749999141753193e+00, + 6.00781250000843591863e+00, 6.02343749999880984092e+00, + 6.03906249999745359247e+00, 6.05468750000370548037e+00, + 6.07031250001220445967e+00, 6.08593750001188915633e+00, + 6.10156249999290700714e+00, 6.11718749998957456171e+00, + 6.13281249999975663911e+00, 6.14843749999015098950e+00, + 6.16406250000358646446e+00, 6.17968750000026467717e+00, + 6.19531249998414246249e+00, 6.21093749998937294521e+00, + 6.22656249999281197205e+00, 6.24218750000707967018e+00, + 6.25781250000234834374e+00, 6.27343749999462829692e+00, + 6.28906250001052136156e+00, 6.30468750000171862524e+00, + 6.32031250000594013727e+00, 6.33593750000045385917e+00, + 6.35156250000499689179e+00, 6.36718749999230215764e+00, + 6.38281249999868105505e+00, 6.39843749999853628196e+00, + 6.41406249999377564563e+00, 6.42968750000876010375e+00, + 6.44531250002396838283e+00, 6.46093750000062527761e+00, + 6.47656249999929212180e+00, 6.49218750000642064180e+00, + 6.50781249999003996720e+00, 6.52343750000912248055e+00, + 6.53906249998720845440e+00, 6.55468749999868371958e+00, + 6.57031249998638067211e+00, 6.58593750000546407364e+00, + 6.60156249994729282804e+00, 6.61718749997319211076e+00, + 6.63281249997879296387e+00, 6.64843749999244426618e+00, + 6.66406249999900524017e+00, 6.67968749999884092716e+00, + 6.69531249999227373593e+00, 6.71093749999063504674e+00, + 6.72656249999940136775e+00, 6.74218749999563193853e+00, + 6.75781249999463895506e+00, 6.77343750001427569174e+00, + 6.78906249999704858311e+00, 6.80468750000215738538e+00, + 6.82031250000341859874e+00, 6.83593749999844302323e+00, + 6.85156250001598987609e+00, 6.86718750000203925765e+00, + 6.88281250000989430760e+00, 6.89843750000604671868e+00, + 6.91406249999750777135e+00, 6.92968749999960120789e+00, + 6.94531249995244071016e+00, 6.96093750002739852789e+00, + 6.97656249999430233544e+00, 6.99218749999911892701e+00, + 7.00781250000804245559e+00, 7.02343750000080380147e+00, + 7.03906249999665778461e+00, 7.05468749999575539533e+00, + 7.07031250001700328767e+00, 7.08593750000647215614e+00, + 7.10156249997034372257e+00, 7.11718749999698641062e+00, + 7.13281250000188915550e+00, 7.14843750000192734717e+00, + 7.16406250000996358551e+00, 7.17968750005667022407e+00, + 7.19531250000950883816e+00, 7.21093749995827248966e+00, + 7.22656250000638511466e+00, 7.24218750002578115499e+00, + 7.25781249999116351290e+00, 7.27343749999614619384e+00, + 7.28906249998626343256e+00, 7.30468749998397015588e+00, + 7.32031249998488320330e+00, 7.33593749999550048813e+00, + 7.35156249998663557932e+00, 7.36718750000183675297e+00, + 7.38281249999652722238e+00, 7.39843750007829115134e+00, + 7.41406250000048494542e+00, 7.42968750000089794838e+00, + 7.44531249999165467557e+00, 7.46093749999333422096e+00, + 7.47656250000219557705e+00, 7.49218750000104360964e+00, + 7.50781249999853983468e+00, 7.52343749999573585541e+00, + 7.53906249999752819946e+00, 7.55468749999868549594e+00, + 7.57031250024692781153e+00, 7.58593750000690736357e+00, + 7.60156249999365662973e+00, 7.61718749999451283372e+00, + 7.63281249995806998498e+00, 7.64843749997276400876e+00, + 7.66406249998022381931e+00, 7.67968750000013145041e+00, + 7.69531249999808597551e+00, 7.71093750001158539931e+00, + 7.72656249999979038989e+00, 7.74218750000620037355e+00, + 7.75781249999318234245e+00, 7.77343750001715427800e+00, + 7.78906250000142730272e+00, 7.80468749997501465288e+00, + 7.82031249999300381859e+00, 7.83593750003314948316e+00, + 7.85156249999927524641e+00, 7.86718749999776001403e+00, + 7.88281249999449951105e+00, 7.89843749999351540936e+00, + 7.91406250000050803806e+00, 7.92968750004068656523e+00, + 7.94531249999952127183e+00, 7.96093750001230571200e+00, + 7.97656249999947331020e+00, 7.99218750003934363946e+00 +}; diff --git a/usr/src/libm/src/C/_TBL_tan.c b/usr/src/libm/src/C/_TBL_tan.c new file mode 100644 index 0000000..1ad97b4 --- /dev/null +++ b/usr/src/libm/src/C/_TBL_tan.c @@ -0,0 +1,84 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_TBL_tan.c 1.9 06/01/31 SMI" + +#include "libm_protos.h" + +const double _TBL_tan_hi[] = { + 1.57534107325271622e-01, 1.61539784049521462e-01, 1.65550519273933966e-01, + 1.69566445219766521e-01, 1.73587694767981526e-01, 1.77614401477446726e-01, + 1.81646699603321415e-01, 1.85684724115634414e-01, 1.89728610718059132e-01, + 1.93778495866891859e-01, 1.97834516790238668e-01, 2.01896811507417145e-01, + 2.05965518848578860e-01, 2.10040778474558987e-01, 2.14122730896958657e-01, + 2.18211517498467428e-01, 2.22307280553431325e-01, 2.26410163248673829e-01, + 2.30520309704576154e-01, 2.34637864996423667e-01, 2.38762975176025932e-01, + 2.42895787293616550e-01, 2.47036449420041271e-01, 2.51185110669240763e-01, + 2.55341921221036272e-01, 2.63680596419996804e-01, 2.72053698658770882e-01, + 2.80462470145251386e-01, 2.88908172440514699e-01, 2.97392087269024608e-01, + 3.05915517353059274e-01, 3.14479787272571532e-01, 3.23086244351745544e-01, + 3.31736259573572778e-01, 3.40431228523830398e-01, 3.49172572365910372e-01, + 3.57961738848017019e-01, 3.66800203344323394e-01, 3.75689469931754838e-01, + 3.84631072504149241e-01, 3.93626575925632771e-01, 4.02677577225140193e-01, + 4.11785706834108478e-01, 4.20952629869475847e-01, 4.30180047464230053e-01, + 4.39469698147866239e-01, 4.48823359279239720e-01, 4.58242848534432368e-01, + 4.67730025452391784e-01, 4.77286793041252266e-01, 4.86915099448406330e-01, + 4.96616939697565651e-01, 5.06394357496229852e-01, 5.16249447117175131e-01, + 5.26184355357779188e-01, 5.36201283581215993e-01, 5.46302489843790484e-01, + 5.66767065580586427e-01, 5.87597367591443209e-01, 6.08813740324380737e-01, + 6.30437673835884782e-01, 6.52491897928808018e-01, 6.75000485144242934e-01, + 6.97988963623599301e-01, 7.21484440990904474e-01, 7.45515740559391960e-01, + 7.70113551344208669e-01, 7.95310593568674173e-01, 8.21141801589894138e-01, + 8.47644526446552637e-01, 8.74858760554482306e-01, 9.02827387452673547e-01, + 9.31596459944072475e-01, 9.61215510494370373e-01, 9.91737898363268644e-01, +}; +const double _TBL_tan_lo[] = { +-1.10615392752930551e-17, 1.42255435911932711e-17, 1.02781342487141920e-17, +-1.04735896510580927e-17,-5.46679990560150911e-18, 1.50201543247778489e-18, + 1.22522327805930836e-17,-2.52772423968968903e-18, 9.78955701743985001e-19, + 4.61515122717816178e-18, 7.14813042382104539e-19,-1.25529909642919992e-17, + 1.19416304006222131e-17,-5.91325462642753544e-18, 7.53213214053688138e-18, + 4.77223821731568090e-18, 6.32882137760769522e-18, 8.33823681661647871e-18, +-1.25419320906151988e-17, 1.16585041935775587e-17,-1.19653634178542542e-17, +-7.22806346068389604e-18,-6.16674472236513534e-18, 4.26199277415660669e-18, +-5.58935834356478328e-18,-4.56998635843850688e-18, 1.78004627511465564e-18, + 1.74249040881549088e-17, 2.70817328270223006e-17,-1.80870634839170844e-17, +-1.00676145758650168e-17,-1.53577462986005684e-17,-2.38939880909534397e-17, +-1.08193046058071237e-17,-1.06856311222117164e-17,-1.96951245902998606e-17, +-2.08660034657941102e-17, 2.82596474303348100e-17, 2.34797942068937341e-18, +-1.76131026613802985e-17,-1.29729310968305823e-17, 1.87495311063417555e-17, +-2.29163073231136327e-18,-2.51936954463539765e-17,-4.11327516430776285e-18, + 1.50393242431203736e-18,-1.09029595007501330e-17,-6.87284752683418342e-19, + 1.55195027932634982e-17,-4.62284921534513474e-18,-5.45294879014110259e-18, +-2.56576334605328725e-17,-4.00960685506800741e-17, 1.35860113023765056e-17, +-4.34857062258506890e-17, 3.85791583096984630e-17, 2.90965762168371759e-17, + 1.90815918857458480e-17, 1.21159907937263400e-17,-1.52112721227855650e-17, +-1.51838757657007437e-17,-2.51352280752587451e-17,-2.66690480643161193e-17, +-4.59728584599455591e-17,-5.42439848134543255e-17, 3.56284233494755594e-17, + 3.61475127591663133e-17, 1.22197541073075113e-17,-1.61356193051149559e-17, + 1.66243632690603545e-17, 4.30578558405427098e-17,-4.43234026650131250e-17, +-1.35473813965930355e-17, 4.30118334112910435e-17, 3.62593428168003066e-17, +}; diff --git a/usr/src/libm/src/C/__cos.c b/usr/src/libm/src/C/__cos.c new file mode 100644 index 0000000..3ce23e5 --- /dev/null +++ b/usr/src/libm/src/C/__cos.c @@ -0,0 +1,126 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__cos.c 1.10 06/01/23 SMI" + +/* INDENT OFF */ +/* + * __k_cos(double x; double y) + * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * + * Accurate Table look-up algorithm by K.C. Ng, May, 1995. + * + * Algorithm: see __sincos.c + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* + * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64) + */ +/* Q1 = */ -0.5, +/* Q2 = */ 4.166666666500350703680945520860748617445e-0002, +/* Q3 = */ -1.388888596436972210694266290577848696006e-0003, +/* Q4 = */ 2.478563078858589473679519517892953492192e-0005, +}; +/* INDENT ON */ + +#define ONE sc[0] +#define NONE sc[1] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define Q1 sc[10] +#define Q2 sc[11] +#define Q3 sc[12] +#define Q4 sc[13] + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +double +__k_cos(double x, double y) { + double z, w, s, v, p, q; + int i, j, n, hx, ix; + + hx = ((int *)&x)[HIWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */ + if (ix < 0x3e400000) /* |x| < 2**-27 */ + if ((int)x == 0) + return (ONE); + z = x * x; + if (ix < 0x3f800000) /* |x| < 0.008 */ + q = z * (QQ1 + z * QQ2); + else + q = z * ((Q1 + z * Q2) + (z * z) * (Q3 + z * Q4)); + return (ONE + q); + } else { /* 0.164062500 < |x| < ~pi/4 */ + n = ix >> 20; + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + if (hx < 0) + v = -y - (_TBL_sincosx[j] + x); + else + v = y - (_TBL_sincosx[j] - x); + s = v * v; + j <<= 1; + w = _TBL_sincos[j]; + z = _TBL_sincos[j+1]; + p = s * (PP1 + s * PP2); + q = s * (QQ1 + s * QQ2); + p = v + v * p; + return (z - (w * p - z * q)); + } +} diff --git a/usr/src/libm/src/C/__lgamma.c b/usr/src/libm/src/C/__lgamma.c new file mode 100644 index 0000000..656c1cd --- /dev/null +++ b/usr/src/libm/src/C/__lgamma.c @@ -0,0 +1,268 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__lgamma.c 1.9 06/01/23 SMI" + +/* + * double __k_lgamma(double x, int *signgamp); + * + * K.C. Ng, March, 1989. + * + * Part of the algorithm is based on W. Cody's lgamma function. + */ + +#include "libm.h" + +static const double +one = 1.0, +zero = 0.0, +hln2pi = 0.9189385332046727417803297, /* log(2*pi)/2 */ +pi = 3.1415926535897932384626434, +two52 = 4503599627370496.0, /* 43300000,00000000 (used by sin_pi) */ +/* + * Numerator and denominator coefficients for rational minimax Approximation + * P/Q over (0.5,1.5). + */ +D1 = -5.772156649015328605195174e-1, +p7 = 4.945235359296727046734888e0, +p6 = 2.018112620856775083915565e2, +p5 = 2.290838373831346393026739e3, +p4 = 1.131967205903380828685045e4, +p3 = 2.855724635671635335736389e4, +p2 = 3.848496228443793359990269e4, +p1 = 2.637748787624195437963534e4, +p0 = 7.225813979700288197698961e3, +q7 = 6.748212550303777196073036e1, +q6 = 1.113332393857199323513008e3, +q5 = 7.738757056935398733233834e3, +q4 = 2.763987074403340708898585e4, +q3 = 5.499310206226157329794414e4, +q2 = 6.161122180066002127833352e4, +q1 = 3.635127591501940507276287e4, +q0 = 8.785536302431013170870835e3, +/* + * Numerator and denominator coefficients for rational minimax Approximation + * G/H over (1.5,4.0). + */ +D2 = 4.227843350984671393993777e-1, +g7 = 4.974607845568932035012064e0, +g6 = 5.424138599891070494101986e2, +g5 = 1.550693864978364947665077e4, +g4 = 1.847932904445632425417223e5, +g3 = 1.088204769468828767498470e6, +g2 = 3.338152967987029735917223e6, +g1 = 5.106661678927352456275255e6, +g0 = 3.074109054850539556250927e6, +h7 = 1.830328399370592604055942e2, +h6 = 7.765049321445005871323047e3, +h5 = 1.331903827966074194402448e5, +h4 = 1.136705821321969608938755e6, +h3 = 5.267964117437946917577538e6, +h2 = 1.346701454311101692290052e7, +h1 = 1.782736530353274213975932e7, +h0 = 9.533095591844353613395747e6, +/* + * Numerator and denominator coefficients for rational minimax Approximation + * U/V over (4.0,12.0). + */ +D4 = 1.791759469228055000094023e0, +u7 = 1.474502166059939948905062e4, +u6 = 2.426813369486704502836312e6, +u5 = 1.214755574045093227939592e8, +u4 = 2.663432449630976949898078e9, +u3 = 2.940378956634553899906876e10, +u2 = 1.702665737765398868392998e11, +u1 = 4.926125793377430887588120e11, +u0 = 5.606251856223951465078242e11, +v7 = 2.690530175870899333379843e3, +v6 = 6.393885654300092398984238e5, +v5 = 4.135599930241388052042842e7, +v4 = 1.120872109616147941376570e9, +v3 = 1.488613728678813811542398e10, +v2 = 1.016803586272438228077304e11, +v1 = 3.417476345507377132798597e11, +v0 = 4.463158187419713286462081e11, +/* + * Coefficients for minimax approximation over (12, INF). + */ +c5 = -1.910444077728e-03, +c4 = 8.4171387781295e-04, +c3 = -5.952379913043012e-04, +c2 = 7.93650793500350248e-04, +c1 = -2.777777777777681622553e-03, +c0 = 8.333333333333333331554247e-02, +c6 = 5.7083835261e-03; + +/* + * Return sin(pi*x). We assume x is finite and negative, and if it + * is an integer, then the sign of the zero returned doesn't matter. + */ +static double +sin_pi(double x) { + double y, z; + int n; + + y = -x; + if (y <= 0.25) + return (__k_sin(pi * x, 0.0)); + if (y >= two52) + return (zero); + z = floor(y); + if (y == z) + return (zero); + + /* argument reduction: set y = |x| mod 2 */ + y *= 0.5; + y = 2.0 * (y - floor(y)); + + /* now floor(y * 4) tells which octant y is in */ + n = (int)(y * 4.0); + switch (n) { + case 0: + y = __k_sin(pi * y, 0.0); + break; + case 1: + case 2: + y = __k_cos(pi * (0.5 - y), 0.0); + break; + case 3: + case 4: + y = __k_sin(pi * (1.0 - y), 0.0); + break; + case 5: + case 6: + y = -__k_cos(pi * (y - 1.5), 0.0); + break; + default: + y = __k_sin(pi * (y - 2.0), 0.0); + break; + } + return (-y); +} + +static double +neg(double z, int *signgamp) { + double t, p; + + /* + * written by K.C. Ng, Feb 2, 1989. + * + * Since + * -z*G(-z)*G(z) = pi/sin(pi*z), + * we have + * G(-z) = -pi/(sin(pi*z)*G(z)*z) + * = pi/(sin(pi*(-z))*G(z)*z) + * Algorithm + * z = |z| + * t = sin_pi(z); ...note that when z>2**52, z is an int + * and hence t=0. + * + * if(t==0.0) return 1.0/0.0; + * if(t< 0.0) *signgamp = -1; else t= -t; + * if(z+1.0==1.0) ...tiny z + * return -log(z); + * else + * return log(pi/(t*z))-__k_lgamma(z, signgamp); + */ + + t = sin_pi(z); /* t := sin(pi*z) */ + if (t == zero) /* return 1.0/0.0 = +INF */ + return (one / fabs(t)); + z = -z; + p = z + one; + if (p == one) + p = -log(z); + else + p = log(pi / (fabs(t) * z)) - __k_lgamma(z, signgamp); + if (t < zero) + *signgamp = -1; + return (p); +} + +double +__k_lgamma(double x, int *signgamp) { + double t, p, q, cr, y; + + /* purge off +-inf, NaN and negative arguments */ + if (!finite(x)) + return (x * x); + *signgamp = 1; + if (signbit(x)) + return (neg(x, signgamp)); + + /* lgamma(x) ~ log(1/x) for really tiny x */ + t = one + x; + if (t == one) { + if (x == zero) + return (one / x); + return (-log(x)); + } + + /* for tiny < x < inf */ + if (x <= 1.5) { + if (x < 0.6796875) { + cr = -log(x); + y = x; + } else { + cr = zero; + y = x - one; + } + + if (x <= 0.5 || x >= 0.6796875) { + if (x == one) + return (zero); + p = p0+y*(p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7)))))); + q = q0+y*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y* + (q7+y))))))); + return (cr+y*(D1+y*(p/q))); + } else { + y = x - one; + p = g0+y*(g1+y*(g2+y*(g3+y*(g4+y*(g5+y*(g6+y*g7)))))); + q = h0+y*(h1+y*(h2+y*(h3+y*(h4+y*(h5+y*(h6+y* + (h7+y))))))); + return (cr+y*(D2+y*(p/q))); + } + } else if (x <= 4.0) { + if (x == 2.0) + return (zero); + y = x - 2.0; + p = g0+y*(g1+y*(g2+y*(g3+y*(g4+y*(g5+y*(g6+y*g7)))))); + q = h0+y*(h1+y*(h2+y*(h3+y*(h4+y*(h5+y*(h6+y*(h7+y))))))); + return (y*(D2+y*(p/q))); + } else if (x <= 12.0) { + y = x - 4.0; + p = u0+y*(u1+y*(u2+y*(u3+y*(u4+y*(u5+y*(u6+y*u7)))))); + q = v0+y*(v1+y*(v2+y*(v3+y*(v4+y*(v5+y*(v6+y*(v7-y))))))); + return (D4+y*(p/q)); + } else if (x <= 1.0e17) { /* x ~< 2**(prec+3) */ + t = one / x; + y = t * t; + p = hln2pi+t*(c0+y*(c1+y*(c2+y*(c3+y*(c4+y*(c5+y*c6)))))); + q = log(x); + return (x*(q-one)-(0.5*q-p)); + } else { /* may overflow */ + return (x * (log(x) - 1.0)); + } +} diff --git a/usr/src/libm/src/C/__libx_errno.c b/usr/src/libm/src/C/__libx_errno.c new file mode 100644 index 0000000..41d81db --- /dev/null +++ b/usr/src/libm/src/C/__libx_errno.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__libx_errno.c 1.14 06/01/25 SMI" + +extern int *___errno(void); + +int * +__libm_errno(void) { + return (___errno()); +} diff --git a/usr/src/libm/src/C/__rem_pio2.c b/usr/src/libm/src/C/__rem_pio2.c new file mode 100644 index 0000000..2862e74 --- /dev/null +++ b/usr/src/libm/src/C/__rem_pio2.c @@ -0,0 +1,167 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__rem_pio2.c 1.13 06/01/23 SMI" + +/* + * __rem_pio2(x, y) passes back a better-than-double-precision + * approximation to x mod pi/2 in y[0]+y[1] and returns an integer + * congruent mod 8 to the integer part of x/(pi/2). + * + * This implementation tacitly assumes that x is finite and at + * least about pi/4 in magnitude. + */ + +#include "libm.h" + +extern const int _TBL_ipio2_inf[]; + +/* INDENT OFF */ +/* + * invpio2: 53 bits of 2/pi + * pio2_1: first 33 bit of pi/2 + * pio2_1t: pi/2 - pio2_1 + * pio2_2: second 33 bit of pi/2 + * pio2_2t: pi/2 - pio2_2 + * pio2_3: third 33 bit of pi/2 + * pio2_3t: pi/2 - pio2_3 + */ +static const double + half = 0.5, + invpio2 = 0.636619772367581343075535, /* 2^ -1 * 1.45F306DC9C883 */ + pio2_1 = 1.570796326734125614166, /* 2^ 0 * 1.921FB54400000 */ + pio2_1t = 6.077100506506192601475e-11, /* 2^-34 * 1.0B4611A626331 */ + pio2_2 = 6.077100506303965976596e-11, /* 2^-34 * 1.0B4611A600000 */ + pio2_2t = 2.022266248795950732400e-21, /* 2^-69 * 1.3198A2E037073 */ + pio2_3 = 2.022266248711166455796e-21, /* 2^-69 * 1.3198A2E000000 */ + pio2_3t = 8.478427660368899643959e-32; /* 2^-104 * 1.B839A252049C1 */ +/* INDENT ON */ + +int +__rem_pio2(double x, double *y) { + double w, t, r, fn; + double tx[3]; + int e0, i, j, nx, n, ix, hx, lx; + + hx = ((int *)&x)[HIWORD]; + ix = hx & 0x7fffffff; + + if (ix < 0x4002d97c) { + /* |x| < 3pi/4, special case with n=1 */ + t = fabs(x) - pio2_1; + if (ix != 0x3ff921fb) { /* 33+53 bit pi is good enough */ + y[0] = t - pio2_1t; + y[1] = (t - y[0]) - pio2_1t; + } else { /* near pi/2, use 33+33+53 bit pi */ + t -= pio2_2; + y[0] = t - pio2_2t; + y[1] = (t - y[0]) - pio2_2t; + } + if (hx < 0) { + y[0] = -y[0]; + y[1] = -y[1]; + return (-1); + } + return (1); + } + + if (ix <= 0x413921fb) { + /* |x| <= 2^19 pi */ + t = fabs(x); + n = (int)(t * invpio2 + half); + fn = (double)n; + r = t - fn * pio2_1; + j = ix >> 20; + w = fn * pio2_1t; /* 1st round good to 85 bit */ + y[0] = r - w; + i = j - ((((int *)y)[HIWORD] >> 20) & 0x7ff); + if (i > 16) { /* 2nd iteration (rare) */ + /* 2nd round good to 118 bit */ + if (i < 35) { + t = r; /* r-fn*pio2_2 may not be exact */ + w = fn * pio2_2; + r = t - w; + w = fn * pio2_2t - ((t - r) - w); + y[0] = r - w; + } else { + r -= fn * pio2_2; + w = fn * pio2_2t; + y[0] = r - w; + i = j - ((((int *)y)[HIWORD] >> 20) & 0x7ff); + if (i > 49) { + /* 3rd iteration (extremely rare) */ + if (i < 68) { + t = r; + w = fn * pio2_3; + r = t - w; + w = fn * pio2_3t - + ((t - r) - w); + y[0] = r - w; + } else { + /* + * 3rd round good to 151 bits; + * covered all possible cases + */ + r -= fn * pio2_3; + w = fn * pio2_3t; + y[0] = r - w; + } + } + } + } + y[1] = (r - y[0]) - w; + if (hx < 0) { + y[0] = -y[0]; + y[1] = -y[1]; + return (-n); + } + return (n); + } + + e0 = (ix >> 20) - 1046; /* e0 = ilogb(x)-23; */ + + /* break x into three 24 bit pieces */ + lx = ((int *)&x)[LOWORD]; + i = (lx & 0x1f) << 19; + tx[2] = (double)i; + j = (lx >> 5) & 0xffffff; + tx[1] = (double)j; + tx[0] = (double)((((ix & 0xfffff) | 0x100000) << 3) | + ((unsigned)lx >> 29)); + nx = 3; + if (i == 0) { + /* skip zero term */ + nx--; + if (j == 0) + nx--; + } + n = __rem_pio2m(tx, y, e0, nx, 2, _TBL_ipio2_inf); + if (hx < 0) { + y[0] = -y[0]; + y[1] = -y[1]; + return (-n); + } + return (n); +} diff --git a/usr/src/libm/src/C/__rem_pio2m.c b/usr/src/libm/src/C/__rem_pio2m.c new file mode 100644 index 0000000..55d7aaf --- /dev/null +++ b/usr/src/libm/src/C/__rem_pio2m.c @@ -0,0 +1,362 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__rem_pio2m.c 1.19 06/01/23 SMI" + +/* + * int __rem_pio2m(x,y,e0,nx,prec,ipio2) + * double x[],y[]; int e0,nx,prec; const int ipio2[]; + * + * __rem_pio2m return the last three digits of N with + * y = x - N*pi/2 + * so that |y| < pi/4. + * + * The method is to compute the integer (mod 8) and fraction parts of + * (2/pi)*x without doing the full multiplication. In general we + * skip the part of the product that are known to be a huge integer ( + * more accurately, = 0 mod 8 ). Thus the number of operations are + * independent of the exponent of the input. + * + * (2/PI) is represented by an array of 24-bit integers in ipio2[]. + * Here PI could as well be a machine value pi. + * + * Input parameters: + * x[] The input value (must be positive) is broken into nx + * pieces of 24-bit integers in double precision format. + * x[i] will be the i-th 24 bit of x. The scaled exponent + * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 + * match x's up to 24 bits. + * + * Example of breaking a double z into x[0]+x[1]+x[2]: + * e0 = ilogb(z)-23 + * z = scalbn(z,-e0) + * for i = 0,1,2 + * x[i] = floor(z) + * z = (z-x[i])*2**24 + * + * + * y[] ouput result in an array of double precision numbers. + * The dimension of y[] is: + * 24-bit precision 1 + * 53-bit precision 2 + * 64-bit precision 2 + * 113-bit precision 3 + * The actual value is the sum of them. Thus for 113-bit + * precsion, one may have to do something like: + * + * long double t,w,r_head, r_tail; + * t = (long double)y[2] + (long double)y[1]; + * w = (long double)y[0]; + * r_head = t+w; + * r_tail = w - (r_head - t); + * + * e0 The exponent of x[0] + * + * nx dimension of x[] + * + * prec an interger indicating the precision: + * 0 24 bits (single) + * 1 53 bits (double) + * 2 64 bits (extended) + * 3 113 bits (quad) + * + * ipio2[] + * integer array, contains the (24*i)-th to (24*i+23)-th + * bit of 2/pi or 2/PI after binary point. The corresponding + * floating value is + * + * ipio2[i] * 2^(-24(i+1)). + * + * External function: + * double scalbn( ), floor( ); + * + * + * Here is the description of some local variables: + * + * jk jk+1 is the initial number of terms of ipio2[] needed + * in the computation. The recommended value is 3,4,4, + * 6 for single, double, extended,and quad. + * + * jz local integer variable indicating the number of + * terms of ipio2[] used. + * + * jx nx - 1 + * + * jv index for pointing to the suitable ipio2[] for the + * computation. In general, we want + * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 + * is an integer. Thus + * e0-3-24*jv >= 0 or (e0-3)/24 >= jv + * Hence jv = max(0,(e0-3)/24). + * + * jp jp+1 is the number of terms in pio2[] needed, jp = jk. + * + * q[] double array with integral value, representing the + * 24-bits chunk of the product of x and 2/pi. + * + * q0 the corresponding exponent of q[0]. Note that the + * exponent for q[i] would be q0-24*i. + * + * pio2[] double precision array, obtained by cutting pi/2 + * into 24 bits chunks. + * + * f[] ipio2[] in floating point + * + * iq[] integer array by breaking up q[] in 24-bits chunk. + * + * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] + * + * ih integer. If >0 it indicats q[] is >= 0.5, hence + * it also indicates the *sign* of the result. + * + */ + +#include "libm.h" + +#if defined(__i386) && !defined(__amd64) +extern int __swapRP(int); +#endif + +static const int init_jk[] = { 3, 4, 4, 6 }; /* initial value for jk */ + +static const double pio2[] = { + 1.57079625129699707031e+00, + 7.54978941586159635335e-08, + 5.39030252995776476554e-15, + 3.28200341580791294123e-22, + 1.27065575308067607349e-29, + 1.22933308981111328932e-36, + 2.73370053816464559624e-44, + 2.16741683877804819444e-51, +}; + +static const double + zero = 0.0, + one = 1.0, + half = 0.5, + eight = 8.0, + eighth = 0.125, + two24 = 16777216.0, + twon24 = 5.960464477539062500E-8; + +int +__rem_pio2m(double *x, double *y, int e0, int nx, int prec, const int *ipio2) +{ + int jz, jx, jv, jp, jk, carry, n, iq[20]; + int i, j, k, m, q0, ih; + double z, fw, f[20], fq[20], q[20]; +#if defined(__i386) && !defined(__amd64) + int rp; + + rp = __swapRP(fp_extended); +#endif + + /* initialize jk */ + jp = jk = init_jk[prec]; + + /* determine jx,jv,q0, note that 3>q0 */ + jx = nx - 1; + jv = (e0 - 3) / 24; + if (jv < 0) + jv = 0; + q0 = e0 - 24 * (jv + 1); + + /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ + j = jv - jx; + m = jx + jk; + for (i = 0; i <= m; i++, j++) + f[i] = (j < 0)? zero : (double)ipio2[j]; + + /* compute q[0],q[1],...q[jk] */ + for (i = 0; i <= jk; i++) { + for (j = 0, fw = zero; j <= jx; j++) + fw += x[j] * f[jx+i-j]; + q[i] = fw; + } + + jz = jk; +recompute: + /* distill q[] into iq[] reversingly */ + for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) { + fw = (double)((int)(twon24 * z)); + iq[i] = (int)(z - two24 * fw); + z = q[j-1] + fw; + } + + /* compute n */ + z = scalbn(z, q0); /* actual value of z */ + z -= eight * floor(z * eighth); /* trim off integer >= 8 */ + n = (int)z; + z -= (double)n; + ih = 0; + if (q0 > 0) { /* need iq[jz-1] to determine n */ + i = (iq[jz-1] >> (24 - q0)); + n += i; + iq[jz-1] -= i << (24 - q0); + ih = iq[jz-1] >> (23 - q0); + } else if (q0 == 0) { + ih = iq[jz-1] >> 23; + } else if (z >= half) { + ih = 2; + } + + if (ih > 0) { /* q > 0.5 */ + n += 1; + carry = 0; + for (i = 0; i < jz; i++) { /* compute 1-q */ + j = iq[i]; + if (carry == 0) { + if (j != 0) { + carry = 1; + iq[i] = 0x1000000 - j; + } + } else { + iq[i] = 0xffffff - j; + } + } + if (q0 > 0) { /* rare case: chance is 1 in 12 */ + switch (q0) { + case 1: + iq[jz-1] &= 0x7fffff; + break; + case 2: + iq[jz-1] &= 0x3fffff; + break; + } + } + if (ih == 2) { + z = one - z; + if (carry != 0) + z -= scalbn(one, q0); + } + } + + /* check if recomputation is needed */ + if (z == zero) { + j = 0; + for (i = jz - 1; i >= jk; i--) + j |= iq[i]; + if (j == 0) { /* need recomputation */ + /* set k to no. of terms needed */ + for (k = 1; iq[jk-k] == 0; k++) + ; + + /* add q[jz+1] to q[jz+k] */ + for (i = jz + 1; i <= jz + k; i++) { + f[jx+i] = (double)ipio2[jv+i]; + for (j = 0, fw = zero; j <= jx; j++) + fw += x[j] * f[jx+i-j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + /* cut out zero terms */ + if (z == zero) { + jz -= 1; + q0 -= 24; + while (iq[jz] == 0) { + jz--; + q0 -= 24; + } + } else { /* break z into 24-bit if neccessary */ + z = scalbn(z, -q0); + if (z >= two24) { + fw = (double)((int)(twon24 * z)); + iq[jz] = (int)(z - two24 * fw); + jz += 1; + q0 += 24; + iq[jz] = (int)fw; + } else { + iq[jz] = (int)z; + } + } + + /* convert integer "bit" chunk to floating-point value */ + fw = scalbn(one, q0); + for (i = jz; i >= 0; i--) { + q[i] = fw * (double)iq[i]; + fw *= twon24; + } + + /* compute pio2[0,...,jp]*q[jz,...,0] */ + for (i = jz; i >= 0; i--) { + for (fw = zero, k = 0; k <= jp && k <= jz - i; k++) + fw += pio2[k] * q[i+k]; + fq[jz-i] = fw; + } + + /* compress fq[] into y[] */ + switch (prec) { + case 0: + fw = zero; + for (i = jz; i >= 0; i--) + fw += fq[i]; + y[0] = (ih == 0)? fw : -fw; + break; + + case 1: + case 2: + fw = zero; + for (i = jz; i >= 0; i--) + fw += fq[i]; + y[0] = (ih == 0)? fw : -fw; + fw = fq[0] - fw; + for (i = 1; i <= jz; i++) + fw += fq[i]; + y[1] = (ih == 0)? fw : -fw; + break; + + default: + for (i = jz; i > 0; i--) { + fw = fq[i-1] + fq[i]; + fq[i] += fq[i-1] - fw; + fq[i-1] = fw; + } + for (i = jz; i > 1; i--) { + fw = fq[i-1] + fq[i]; + fq[i] += fq[i-1] - fw; + fq[i-1] = fw; + } + for (fw = zero, i = jz; i >= 2; i--) + fw += fq[i]; + if (ih == 0) { + y[0] = fq[0]; + y[1] = fq[1]; + y[2] = fw; + } else { + y[0] = -fq[0]; + y[1] = -fq[1]; + y[2] = -fw; + } + } + +#if defined(__i386) && !defined(__amd64) + (void) __swapRP(rp); +#endif + return (n & 7); +} diff --git a/usr/src/libm/src/C/__sin.c b/usr/src/libm/src/C/__sin.c new file mode 100644 index 0000000..50fe96d --- /dev/null +++ b/usr/src/libm/src/C/__sin.c @@ -0,0 +1,128 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__sin.c 1.10 06/01/23 SMI" + +/* INDENT OFF */ +/* + * __k_sin( double x; double y ) + * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.785398164 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * + * Accurate Table look-up algorithm by K.C. Ng, May, 1995. + * + * Algorithm: see __sincos.c + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* + * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64) + */ +/* Q1 = */ -0.5, +/* Q2 = */ 4.166666666500350703680945520860748617445e-0002, +/* Q3 = */ -1.388888596436972210694266290577848696006e-0003, +/* Q4 = */ 2.478563078858589473679519517892953492192e-0005, +}; +/* INDENT ON */ + +#define ONE sc[0] +#define NONE sc[1] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define Q1 sc[10] +#define Q2 sc[11] +#define Q3 sc[12] +#define Q4 sc[13] + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +double +__k_sin(double x, double y) { + double z, w, s, v, p, q; + int i, j, n, hx, ix; + + hx = ((int *)&x)[HIWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */ + if (ix < 0x3e400000) /* |x| < 2**-27 */ + if ((int)x == 0) + return (x + y); + z = x * x; + if (ix < 0x3f800000) /* |x| < 0.008 */ + p = (x * z) * (PP1 + z * PP2) + y; + else + p = (x * z) * ((P1 + z * P2) + (z * z) * (P3 + + z * P4)) + y; + return (x + p); + } else { /* 0.164062500 < |x| < ~pi/4 */ + n = ix >> 20; + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + if (hx < 0) + v = -y - (_TBL_sincosx[j] + x); + else + v = y - (_TBL_sincosx[j] - x); + s = v * v; + j <<= 1; + w = _TBL_sincos[j]; + z = _TBL_sincos[j+1]; + p = s * (PP1 + s * PP2); + q = s * (QQ1 + s * QQ2); + p = v + v * p; + s = w * q + z * p; + return ((hx >= 0)? w + s : -(w + s)); + } +} diff --git a/usr/src/libm/src/C/__sincos.c b/usr/src/libm/src/C/__sincos.c new file mode 100644 index 0000000..d6ced7e --- /dev/null +++ b/usr/src/libm/src/C/__sincos.c @@ -0,0 +1,163 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__sincos.c 1.15 06/01/23 SMI" + +/* INDENT OFF */ +/* + * double __k_sincos(double x, double y, double *c); + * kernel sincos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * return sin(x) with *c = cos(x) + * + * Accurate Table look-up algorithm by K.C. Ng, May, 1995. + * + * 1. Reduce x to x>0 by sin(-x)=-sin(x),cos(-x)=cos(x). + * 2. For 0<= x < pi/4, let i = (64*x chopped)-10. Let d = x - a[i], where + * a[i] is a double that is close to (i+10.5)/64 and such that + * sin(a[i]) and cos(a[i]) is close to a double (with error less + * than 2**-8 ulp). Then + * cos(x) = cos(a[i]+d) = cos(a[i])cos(d) - sin(a[i])*sin(d) + * = TBL_cos_a[i]*(1+QQ1*d^2+QQ2*d^4) - + * TBL_sin_a[i]*(d+PP1*d^3+PP2*d^5) + * = TBL_cos_a[i] + (TBL_cos_a[i]*d^2*(QQ1+QQ2*d^2) - + * TBL_sin_a[i]*(d+PP1*d^3+PP2*d^5)) + * sin(x) = sin(a[i]+d) = sin(a[i])cos(d) + cos(a[i])*sin(d) + * = TBL_sin_a[i]*(1+QQ1*d^2+QQ2*d^4) + + * TBL_cos_a[i]*(d+PP1*d^3+PP2*d^5) + * = TBL_sin_a[i] + (TBL_sin_a[i]*d^2*(QQ1+QQ2*d^2) + + * TBL_cos_a[i]*(d+PP1*d^3+PP2*d^5)) + * + * For |y| less than 10.5/64 = 0.1640625, use + * sin(y) = y + y^3*(p1+y^2*(p2+y^2*(p3+y^2*p4))) + * cos(y) = 1 + y^2*(q1+y^2*(q2+y^2*(q3+y^2*q4))) + * + * For |y| less than 0.008, use + * sin(y) = y + y^3*(pp1+y^2*pp2) + * cos(y) = 1 + y^2*(qq1+y^2*qq2) + * + * Accuracy: + * TRIG(x) returns trig(x) nearly rounded (less than 1 ulp) + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* + * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64) + */ +/* Q1 = */ -0.5, +/* Q2 = */ 4.166666666500350703680945520860748617445e-0002, +/* Q3 = */ -1.388888596436972210694266290577848696006e-0003, +/* Q4 = */ 2.478563078858589473679519517892953492192e-0005, +}; +/* INDENT ON */ + +#define ONE sc[0] +#define NONE sc[1] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define Q1 sc[10] +#define Q2 sc[11] +#define Q3 sc[12] +#define Q4 sc[13] + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +double +__k_sincos(double x, double y, double *c) { + double z, w, s, v, p, q; + int i, j, n, hx, ix; + + hx = ((int *)&x)[HIWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */ + if (ix < 0x3e400000) { /* |x| < 2**-27 */ + if ((int)x == 0) + *c = ONE; + return (x + y); + } else { + z = x * x; + if (ix < 0x3f800000) { /* |x| < 0.008 */ + q = z * (QQ1 + z * QQ2); + p = (x * z) * (PP1 + z * PP2) + y; + } else { + q = z * ((Q1 + z * Q2) + (z * z) * (Q3 + + z * Q4)); + p = (x * z) * ((P1 + z * P2) + (z * z) * (P3 + + z * P4)) + y; + } + *c = ONE + q; + return (x + p); + } + } else { /* 0.164062500 < |x| < ~pi/4 */ + n = ix >> 20; + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + if (hx < 0) + v = -y - (_TBL_sincosx[j] + x); + else + v = y - (_TBL_sincosx[j] - x); + s = v * v; + j <<= 1; + w = _TBL_sincos[j]; + z = _TBL_sincos[j+1]; + p = s * (PP1 + s * PP2); + q = s * (QQ1 + s * QQ2); + p = v + v * p; + *c = z - (w * p - z * q); + s = w * q + z * p; + return ((hx >= 0)? w + s : -(w + s)); + } +} diff --git a/usr/src/libm/src/C/__tan.c b/usr/src/libm/src/C/__tan.c new file mode 100644 index 0000000..d9697e2 --- /dev/null +++ b/usr/src/libm/src/C/__tan.c @@ -0,0 +1,194 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__tan.c 1.15 06/01/31 SMI" + +/* INDENT OFF */ +/* + * __k_tan( double x; double y; int k ) + * kernel tan/cotan function on [-pi/4, pi/4], pi/4 ~ 0.785398164 + * Input x is assumed to be bounded by ~pi/4 in magnitude. + * Input y is the tail of x. + * Input k indicate -- tan if k=0; else -1/tan + * + * Table look up algorithm + * 1. by tan(-x) = -tan(x), need only to consider positive x + * 2. if x < 5/32 = [0x3fc40000, 0] = 0.15625 , then + * if x < 2^-27 (hx < 0x3e400000 0), set w=x with inexact if x!= 0 + * else + * z = x*x; + * w = x + (y+(x*z)*(t1+z*(t2+z*(t3+z*(t4+z*(t5+z*t6)))))) + * return (k==0)? w: 1/w; + * 3. else + * ht = (hx + 0x4000)&0x7fff8000 (round x to a break point t) + * lt = 0 + * i = (hy-0x3fc40000)>>15; (i<=64) + * x' = (x - t)+y (|x'| ~<= 2^-7) + * By + * tan(t+x') + * = (tan(t)+tan(x'))/(1-tan(x')tan(t)) + * We have + * sin(x')+tan(t)*(tan(t)*sin(x')) + * = tan(t) + ------------------------------- for k=0 + * cos(x') - tan(t)*sin(x') + * + * cos(x') - tan(t)*sin(x') + * = - -------------------------------------- for k=1 + * tan(t) + tan(t)*(cos(x')-1) + sin(x') + * + * + * where tan(t) is from the table, + * sin(x') = x + pp1*x^3 + pp2*x^5 + * cos(x') = 1 + qq1*x^2 + qq2*x^4 + */ + +#include "libm.h" + +extern const double _TBL_tan_hi[], _TBL_tan_lo[]; +static const double q[] = { +/* one = */ 1.0, +/* + * 2 2 -59.56 + * |sin(x) - pp1*x*(pp2+x *(pp3+x )| <= 2 for |x|<1/64 + */ +/* pp1 = */ 8.33326120969096230395312119298978359438478946686e-0003, +/* pp2 = */ 1.20001038589438965215025680596868692381425944526e+0002, +/* pp3 = */ -2.00001730975089451192161504877731204032897949219e+0001, + +/* + * 2 2 -56.19 + * |cos(x) - (1+qq1*x (qq2+x ))| <= 2 for |x|<=1/128 + */ +/* qq1 = */ 4.16665486385721928197511942926212213933467864990e-0002, +/* qq2 = */ -1.20000339921340035687080671777948737144470214844e+0001, + +/* + * |tan(x) - PF(x)| + * |--------------| <= 2^-58.57 for |x|<0.15625 + * | x | + * + * where (let z = x*x) + * PF(x) = x + (t1*x*z)(t2 + z(t3 + z))(t4 + z)(t5 + z(t6 + z)) + */ +/* t1 = */ 3.71923358986516816929168705030406272271648049355e-0003, +/* t2 = */ 6.02645120354857866118436504621058702468872070312e+0000, +/* t3 = */ 2.42627327587398156083509093150496482849121093750e+0000, +/* t4 = */ 2.44968983934252770851003333518747240304946899414e+0000, +/* t5 = */ 6.07089252571767978849948121933266520500183105469e+0000, +/* t6 = */ -2.49403756995593761658369658107403665781021118164e+0000, +}; + + +#define one q[0] +#define pp1 q[1] +#define pp2 q[2] +#define pp3 q[3] +#define qq1 q[4] +#define qq2 q[5] +#define t1 q[6] +#define t2 q[7] +#define t3 q[8] +#define t4 q[9] +#define t5 q[10] +#define t6 q[11] + +/* INDENT ON */ + + +double +__k_tan(double x, double y, int k) { + double a, t, z, w, s, c, r, rh, xh, xl; + int i, j, hx, ix; + + t = one; + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix < 0x3fc40000) { + if (ix < 0x3e400000) { + if ((i = (int) x) == 0) /* generate inexact */ + w = x; + t = y; + } else { + z = x * x; + t = y + (((t1 * x) * z) * (t2 + z * (t3 + z))) * + ((t4 + z) * (t5 + z * (t6 + z))); + w = x + t; + } + if (k == 0) + return (w); + /* + * Compute -1/(x+T) with great care + * Let r = -1/(x+T), rh = r chopped to 20 bits. + * Also let xh = x+T chopped to 20 bits, xl = (x-xh)+T. Then + * -1/(x+T) = rh + (-1/(x+T)-rh) = rh + r*(1+rh*(x+T)) + * = rh + r*((1+rh*xh)+rh*xl). + */ + rh = r = -one / w; + ((int *) &rh)[LOWORD] = 0; + xh = w; + ((int *) &xh)[LOWORD] = 0; + xl = (x - xh) + t; + return (rh + r * ((one + rh * xh) + rh * xl)); + } + j = (ix + 0x4000) & 0x7fff8000; + i = (j - 0x3fc40000) >> 15; + ((int *) &t)[HIWORD] = j; + if (hx > 0) + x = y - (t - x); + else + x = -y - (t + x); + a = _TBL_tan_hi[i]; + z = x * x; + s = (pp1 * x) * (pp2 + z * (pp3 + z)); /* sin(x) */ + t = (qq1 * z) * (qq2 + z); /* cos(x) - 1 */ + if (k == 0) { + w = a * s; + t = _TBL_tan_lo[i] + (s + a * w) / (one - (w - t)); + return (hx < 0 ? -a - t : a + t); + } else { + w = s + a * t; + c = w + _TBL_tan_lo[i]; + t = a * s - t; + /* + * Now try to compute [(1-T)/(a+c)] accurately + * + * Let r = 1/(a+c), rh = (1-T)*r chopped to 20 bits. + * Also let xh = a+c chopped to 20 bits, xl = (a-xh)+c. Then + * (1-T)/(a+c) = rh + ((1-T)/(a+c)-rh) + * = rh + r*(1-T-rh*(a+c)) + * = rh + r*((1-T-rh*xh)-rh*xl) + * = rh + r*(((1-rh*xh)-T)-rh*xl) + */ + r = one / (a + c); + rh = (one - t) * r; + ((int *) &rh)[LOWORD] = 0; + xh = a + c; + ((int *) &xh)[LOWORD] = 0; + xl = (a - xh) + c; + z = rh + r * (((one - rh * xh) - t) - rh * xl); + return (hx >= 0 ? -z : z); + } +} diff --git a/usr/src/libm/src/C/__xpg6.c b/usr/src/libm/src/C/__xpg6.c new file mode 100644 index 0000000..5cc8f69 --- /dev/null +++ b/usr/src/libm/src/C/__xpg6.c @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)__xpg6.c 1.3 06/01/31 SMI (lib/libc/port/gen/xpg6.c 1.1 02/09/24)" + +/*LINTLIBRARY*/ + +/* + * See /ws/unix200x-gate/usr/src/lib/libc/port/gen/xpg6.c for libc default. + * __xpg6 (C99/SUSv3) is first included in Solaris 10 libc and libm + * as well as the K2 (S1S8) libsunmath and libmopt. + * + * The default setting, _C99SUSv3_mode_OFF, means to retain current Solaris + * behavior which is NOT C99/SUSv3 compliant. This is normal. These libraries + * determine which standard to use based on how applications are built. These + * libraries at runtime determine which behavior to choose based on the value + * of __xpg6. By default they retain their original Solaris behavior. + * + * __xpg6 is used to control certain behaviors between the C99 standard, the + * SUSv3 standard, and Solaris. More explanation in lib/libc/inc/xpg6.h. + * The XPG6 C compiler utility (c99) will add an object file that contains + * an alternate definition for __xpg6. The symbol interposition provided + * by the linker will allow these libraries to find that symbol instead. + * + * Possible settings are available and documented in lib/libc/inc/xpg6.h. + */ + +#include "xpg6.h" + +unsigned int __xpg6 = _C99SUSv3_mode_OFF; diff --git a/usr/src/libm/src/C/_lib_version.c b/usr/src/libm/src/C/_lib_version.c new file mode 100644 index 0000000..3ee4d60 --- /dev/null +++ b/usr/src/libm/src/C/_lib_version.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)_lib_version.c 1.8 06/01/31 SMI" + +/* + * values-{X,x}?.o should define + initialize an *actual* symbol _lib_version. + */ + +#include <math.h> + +#pragma weak _lib_version = __libm_lib_version + +const enum version __libm_lib_version = libm_ieee; diff --git a/usr/src/libm/src/C/acos.c b/usr/src/libm/src/C/acos.c new file mode 100644 index 0000000..7f7d18d --- /dev/null +++ b/usr/src/libm/src/C/acos.c @@ -0,0 +1,162 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)acos.c 1.18 06/01/31 SMI" + +#pragma weak acos = __acos + +/* INDENT OFF */ +/* acos(x) + * Method : + * acos(x) = pi/2 - asin(x) + * acos(-x) = pi/2 + asin(x) + * For |x|<=0.5 + * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) + * For x>0.5 + * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) + * = 2asin(sqrt((1-x)/2)) + * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) + * = 2f + (2c + 2s*z*R(z)) + * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term + * for f so that f+c ~ sqrt(z). + * For x<-0.5 + * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) + * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) + * + * Special cases: + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. + * + * Function needed: sqrt + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __acos, __sqrt, __isnan */ +#include "libm_protos.h" /* _SVID_libm_error */ +#include <math.h> + +/* INDENT OFF */ +static const double xxx[] = { +/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ +/* pi */ 3.14159265358979311600e+00, /* 400921FB, 54442D18 */ +/* pio2_hi */ 1.57079632679489655800e+00, /* 3FF921FB, 54442D18 */ +/* pio2_lo */ 6.12323399573676603587e-17, /* 3C91A626, 33145C07 */ +/* pS0 */ 1.66666666666666657415e-01, /* 3FC55555, 55555555 */ +/* pS1 */ -3.25565818622400915405e-01, /* BFD4D612, 03EB6F7D */ +/* pS2 */ 2.01212532134862925881e-01, /* 3FC9C155, 0E884455 */ +/* pS3 */ -4.00555345006794114027e-02, /* BFA48228, B5688F3B */ +/* pS4 */ 7.91534994289814532176e-04, /* 3F49EFE0, 7501B288 */ +/* pS5 */ 3.47933107596021167570e-05, /* 3F023DE1, 0DFDF709 */ +/* qS1 */ -2.40339491173441421878e+00, /* C0033A27, 1C8A2D4B */ +/* qS2 */ 2.02094576023350569471e+00, /* 40002AE5, 9C598AC8 */ +/* qS3 */ -6.88283971605453293030e-01, /* BFE6066C, 1B8D0159 */ +/* qS4 */ 7.70381505559019352791e-02 /* 3FB3B8C5, B12E9282 */ +}; +#define one xxx[0] +#define pi xxx[1] +#define pio2_hi xxx[2] +#define pio2_lo xxx[3] +#define pS0 xxx[4] +#define pS1 xxx[5] +#define pS2 xxx[6] +#define pS3 xxx[7] +#define pS4 xxx[8] +#define pS5 xxx[9] +#define qS1 xxx[10] +#define qS2 xxx[11] +#define qS3 xxx[12] +#define qS4 xxx[13] +/* INDENT ON */ + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +acos(double x) { + double z, p, q, r, w, s, c, df; + int hx, ix; + + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix >= 0x3ff00000) { /* |x| >= 1 */ + if (((ix - 0x3ff00000) | ((int *) &x)[LOWORD]) == 0) { + /* |x| == 1 */ + if (hx > 0) /* acos(1) = 0 */ + return 0.0; + else /* acos(-1) = pi */ + return pi + 2.0 * pio2_lo; + } + else if (isnan(x)) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return ix >= 0x7ff80000 ? x : (x - x) / (x - x); + /* assumes sparc-like QNaN */ +#else + return (x - x) / (x - x); /* acos(|x|>1) is NaN */ +#endif + else + return _SVID_libm_err(x, x, 1); + } + if (ix < 0x3fe00000) { /* |x| < 0.5 */ + if (ix <= 0x3c600000) + return pio2_hi + pio2_lo; /* if |x| < 2**-57 */ + z = x * x; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + return pio2_hi - (x - (pio2_lo - x * r)); + } + else if (hx < 0) { /* x < -0.5 */ + z = (one + x) * 0.5; + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + s = sqrt(z); + r = p / q; + w = r * s - pio2_lo; + return pi - 2.0 * (s + w); + } + else { /* x > 0.5 */ + z = (one - x) * 0.5; + s = sqrt(z); + df = s; + ((int *) &df)[LOWORD] = 0; + c = (z - df * df) / (s + df); + p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + + z * (pS4 + z * pS5))))); + q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); + r = p / q; + w = r * s + c; + return 2.0 * (df + w); + } +} diff --git a/usr/src/libm/src/C/acosh.c b/usr/src/libm/src/C/acosh.c new file mode 100644 index 0000000..4e84b93 --- /dev/null +++ b/usr/src/libm/src/C/acosh.c @@ -0,0 +1,105 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)acosh.c 1.19 06/01/31 SMI" + +#pragma weak acosh = __acosh + +/* INDENT OFF */ +/* acosh(x) + * Method : + * Based on + * acosh(x) = log [ x + sqrt(x*x-1) ] + * we have + * acosh(x) := log(x)+ln2, if x is large; else + * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x > 2; else + * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t = x-1. + * + * Special cases: + * acosh(x) is NaN with signal if x < 1. + * acosh(NaN) is NaN without signal. + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __acosh, __log, __log1p */ +#include "libm_protos.h" /* _SVID_libm_error */ +#include <math.h> + +static const double + one = 1.0, + ln2 = 6.93147180559945286227e-01; /* 3FE62E42, FEFA39EF */ + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +acosh(double x) { + double t; + int hx; + + hx = ((int *) &x)[HIWORD]; + if (hx < 0x3ff00000) { /* x < 1 */ + if (isnan(x)) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return hx >= 0xfff80000 ? x : (x - x) / (x - x); + /* assumes sparc-like QNaN */ +#else + return (x - x) / (x - x); +#endif + else + return _SVID_libm_err(x, x, 29); + } + else if (hx >= 0x41b00000) { /* x > 2**28 */ + if (hx >= 0x7ff00000) { /* x is inf of NaN */ +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return hx >= 0x7ff80000 ? x : x + x; + /* assumes sparc-like QNaN */ +#else + return x + x; +#endif + } + else /* acosh(huge)=log(2x) */ + return log(x) + ln2; + } + else if (((hx - 0x3ff00000) | ((int *) &x)[LOWORD]) == 0) { + return 0.0; /* acosh(1) = 0 */ + } + else if (hx > 0x40000000) { /* 2**28 > x > 2 */ + t = x * x; + return log(2.0 * x - one / (x + sqrt(t - one))); + } + else { /* 1 < x < 2 */ + t = x - one; + return log1p(t + sqrt(2.0 * t + t * t)); + } +} diff --git a/usr/src/libm/src/C/asin.c b/usr/src/libm/src/C/asin.c new file mode 100644 index 0000000..222bf87 --- /dev/null +++ b/usr/src/libm/src/C/asin.c @@ -0,0 +1,168 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)asin.c 1.20 06/01/31 SMI" + +#pragma weak asin = __asin + +/* INDENT OFF */ +/* asin(x) + * Method : + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) + * where + * R(x^2) is a rational approximation of (asin(x)-x)/x^3 + * and its remez error is bounded by + * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75) + * + * For x in [0.5,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; + * then for x>0.98 + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) + * For x<=0.98, let pio4_hi = pio2_hi/2, then + * f = hi part of s; + * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) + * and + * asin(x) = pi/2 - 2*(s+s*z*R(z)) + * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) + * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) + * + * Special cases: + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. + * + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __asin, __sqrt, __isnan */ +#include "libm_protos.h" /* _SVID_libm_error */ +#include <math.h> + +/* INDENT OFF */ +static const double xxx[] = { +/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ +/* huge */ 1.000e+300, +/* pio2_hi */ 1.57079632679489655800e+00, /* 3FF921FB, 54442D18 */ +/* pio2_lo */ 6.12323399573676603587e-17, /* 3C91A626, 33145C07 */ +/* pio4_hi */ 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */ +/* coefficient for R(x^2) */ +/* pS0 */ 1.66666666666666657415e-01, /* 3FC55555, 55555555 */ +/* pS1 */ -3.25565818622400915405e-01, /* BFD4D612, 03EB6F7D */ +/* pS2 */ 2.01212532134862925881e-01, /* 3FC9C155, 0E884455 */ +/* pS3 */ -4.00555345006794114027e-02, /* BFA48228, B5688F3B */ +/* pS4 */ 7.91534994289814532176e-04, /* 3F49EFE0, 7501B288 */ +/* pS5 */ 3.47933107596021167570e-05, /* 3F023DE1, 0DFDF709 */ +/* qS1 */ -2.40339491173441421878e+00, /* C0033A27, 1C8A2D4B */ +/* qS2 */ 2.02094576023350569471e+00, /* 40002AE5, 9C598AC8 */ +/* qS3 */ -6.88283971605453293030e-01, /* BFE6066C, 1B8D0159 */ +/* qS4 */ 7.70381505559019352791e-02 /* 3FB3B8C5, B12E9282 */ +}; +#define one xxx[0] +#define huge xxx[1] +#define pio2_hi xxx[2] +#define pio2_lo xxx[3] +#define pio4_hi xxx[4] +#define pS0 xxx[5] +#define pS1 xxx[6] +#define pS2 xxx[7] +#define pS3 xxx[8] +#define pS4 xxx[9] +#define pS5 xxx[10] +#define qS1 xxx[11] +#define qS2 xxx[12] +#define qS3 xxx[13] +#define qS4 xxx[14] +/* INDENT ON */ + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +asin(double x) { + double t, w, p, q, c, r, s; + int hx, ix; + + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix >= 0x3ff00000) { /* |x| >= 1 */ + if (((ix - 0x3ff00000) | ((int *) &x)[LOWORD]) == 0) + /* asin(1)=+-pi/2 with inexact */ + return x * pio2_hi + x * pio2_lo; + else if (isnan(x)) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return ix >= 0x7ff80000 ? x : (x - x) / (x - x); + /* assumes sparc-like QNaN */ +#else + return (x - x) / (x - x); /* asin(|x|>1) is NaN */ +#endif + else + return _SVID_libm_err(x, x, 2); + } + else if (ix < 0x3fe00000) { /* |x| < 0.5 */ + if (ix < 0x3e400000) { /* if |x| < 2**-27 */ + if (huge + x > one) + return x; /* return x with inexact if + * x != 0 */ + } + else + t = x * x; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + w = p / q; + return x + x * w; + } + /* 1 > |x| >= 0.5 */ + w = one - fabs(x); + t = w * 0.5; + p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); + q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); + s = sqrt(t); + if (ix >= 0x3FEF3333) { /* if |x| > 0.975 */ + w = p / q; + t = pio2_hi - (2.0 * (s + s * w) - pio2_lo); + } + else { + w = s; + ((int *) &w)[LOWORD] = 0; + c = (t - w * w) / (s + w); + r = p / q; + p = 2.0 * s * r - (pio2_lo - 2.0 * c); + q = pio4_hi - 2.0 * w; + t = pio4_hi - (p - q); + } + return hx > 0 ? t : -t; +} diff --git a/usr/src/libm/src/C/asinh.c b/usr/src/libm/src/C/asinh.c new file mode 100644 index 0000000..29301ba --- /dev/null +++ b/usr/src/libm/src/C/asinh.c @@ -0,0 +1,96 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)asinh.c 1.18 06/01/31 SMI" + +#pragma weak asinh = __asinh + +/* INDENT OFF */ +/* asinh(x) + * Method : + * Based on + * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] + * we have + * asinh(x) := x if 1+x*x == 1, + * := sign(x)*(log(x)+ln2)) for large |x|, else + * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x| > 2, else + * := sign(x)*log1p(|x|+x^2/(1+sqrt(1+x^2))) + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __asinh */ +#include <math.h> + +static const double xxx[] = { +/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ +/* ln2 */ 6.93147180559945286227e-01, /* 3FE62E42, FEFA39EF */ +/* huge */ 1.00000000000000000000e+300 +}; +#define one xxx[0] +#define ln2 xxx[1] +#define huge xxx[2] + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +asinh(double x) { + double t, w; + int hx, ix; + + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix >= 0x7ff00000) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return ix >= 0x7ff80000 ? x : x + x; + /* assumes sparc-like QNaN */ +#else + return x + x; /* x is inf or NaN */ +#endif + if (ix < 0x3e300000) { /* |x|<2**-28 */ + if (huge + x > one) + return x; /* return x inexact except 0 */ + } + if (ix > 0x41b00000) { /* |x| > 2**28 */ + w = log(fabs(x)) + ln2; + } + else if (ix > 0x40000000) { /* 2**28 > |x| > 2.0 */ + t = fabs(x); + w = log(2.0 * t + one / (sqrt(x * x + one) + t)); + } + else { /* 2.0 > |x| > 2**-28 */ + t = x * x; + w = log1p(fabs(x) + t / (one + sqrt(one + t))); + } + return hx > 0 ? w : -w; +} diff --git a/usr/src/libm/src/C/atan.c b/usr/src/libm/src/C/atan.c new file mode 100644 index 0000000..a398953 --- /dev/null +++ b/usr/src/libm/src/C/atan.c @@ -0,0 +1,197 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)atan.c 1.22 06/01/31 SMI" + +#pragma weak atan = __atan + +/* INDENT OFF */ +/* + * atan(x) + * Accurate Table look-up algorithm with polynomial approximation in + * partially product form. + * + * -- K.C. Ng, October 17, 2004 + * + * Algorithm + * + * (1). Purge off Inf and NaN and 0 + * (2). Reduce x to positive by atan(x) = -atan(-x). + * (3). For x <= 1/8 and let z = x*x, return + * (2.1) if x < 2^(-prec/2), atan(x) = x with inexact flag raised + * (2.2) if x < 2^(-prec/4-1), atan(x) = x+(x/3)(x*x) + * (2.3) if x < 2^(-prec/6-2), atan(x) = x+(z-5/3)(z*x/5) + * (2.4) Otherwise + * atan(x) = poly1(x) = x + A * B, + * where + * A = (p1*x*z) * (p2+z(p3+z)) + * B = (p4+z)+z*z) * (p5+z(p6+z)) + * Note: (i) domain of poly1 is [0, 1/8], (ii) remez relative + * approximation error of poly1 is bounded by + * |(atan(x)-poly1(x))/x| <= 2^-57.61 + * (4). For x >= 8 then + * (3.1) if x >= 2^prec, atan(x) = atan(inf) - pio2lo + * (3.2) if x >= 2^(prec/3), atan(x) = atan(inf) - 1/x + * (3.3) if x <= 65, atan(x) = atan(inf) - poly1(1/x) + * (3.4) otherwise atan(x) = atan(inf) - poly2(1/x) + * where + * poly2(r) = (q1*r) * (q2+z(q3+z)) * (q4+z), + * its domain is [0, 0.0154]; and its remez absolute + * approximation error is bounded by + * |atan(x)-poly2(x)|<= 2^-59.45 + * + * (5). Now x is in (0.125, 8). + * Recall identity + * atan(x) = atan(y) + atan((x-y)/(1+x*y)). + * Let j = (ix - 0x3fc00000) >> 16, 0 <= j < 96, where ix is the high + * part of x in IEEE double format. Then + * atan(x) = atan(y[j]) + poly2((x-y[j])/(1+x*y[j])) + * where y[j] are carefully chosen so that it matches x to around 4.5 + * bits and at the same time atan(y[j]) is very close to an IEEE double + * floating point number. Calculation indicates that + * max|(x-y[j])/(1+x*y[j])| < 0.0154 + * j,x + * + * Accuracy: Maximum error observed is bounded by 0.6 ulp after testing + * more than 10 million random arguments + */ +/* INDENT ON */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" + +extern const double _TBL_atan[]; +static const double g[] = { +/* one = */ 1.0, +/* p1 = */ 8.02176624254765935351230154992663301527500152588e-0002, +/* p2 = */ 1.27223421700559402580665846471674740314483642578e+0000, +/* p3 = */ -1.20606901800503640842521235754247754812240600586e+0000, +/* p4 = */ -2.36088967922325565496066701598465442657470703125e+0000, +/* p5 = */ 1.38345799501389166152875986881554126739501953125e+0000, +/* p6 = */ 1.06742368078953453469637224770849570631980895996e+0000, +/* q1 = */ -1.42796626333911796935538518482644576579332351685e-0001, +/* q2 = */ 3.51427110447873227059810477159863497078605962912e+0000, +/* q3 = */ 5.92129112708164262457444237952586263418197631836e-0001, +/* q4 = */ -1.99272234785683144409063061175402253866195678711e+0000, +/* pio2hi */ 1.570796326794896558e+00, +/* pio2lo */ 6.123233995736765886e-17, +/* t1 = */ -0.333333333333333333333333333333333, +/* t2 = */ 0.2, +/* t3 = */ -1.666666666666666666666666666666666, +}; + +#define one g[0] +#define p1 g[1] +#define p2 g[2] +#define p3 g[3] +#define p4 g[4] +#define p5 g[5] +#define p6 g[6] +#define q1 g[7] +#define q2 g[8] +#define q3 g[9] +#define q4 g[10] +#define pio2hi g[11] +#define pio2lo g[12] +#define t1 g[13] +#define t2 g[14] +#define t3 g[15] + + +double +atan(double x) { + double y, z, r, p, s; + int ix, lx, hx, j; + + hx = ((int *) &x)[HIWORD]; + lx = ((int *) &x)[LOWORD]; + ix = hx & ~0x80000000; + j = ix >> 20; + + /* for |x| < 1/8 */ + if (j < 0x3fc) { + if (j < 0x3f5) { /* when |x| < 2**(-prec/6-2) */ + if (j < 0x3e3) { /* if |x| < 2**(-prec/2-2) */ + return ((int) x == 0 ? x : one); + } + if (j < 0x3f1) { /* if |x| < 2**(-prec/4-1) */ + return (x + (x * t1) * (x * x)); + } else { /* if |x| < 2**(-prec/6-2) */ + z = x * x; + s = t2 * x; + return (x + (t3 + z) * (s * z)); + } + } + z = x * x; s = p1 * x; + return (x + ((s * z) * (p2 + z * (p3 + z))) * + (((p4 + z) + z * z) * (p5 + z * (p6 + z)))); + } + + /* for |x| >= 8.0 */ + if (j >= 0x402) { + if (j < 0x436) { + r = one / x; + if (hx >= 0) { + y = pio2hi; p = pio2lo; + } else { + y = -pio2hi; p = -pio2lo; + } + if (ix < 0x40504000) { /* x < 65 */ + z = r * r; + s = p1 * r; + return (y + ((p - r) - ((s * z) * + (p2 + z * (p3 + z))) * + (((p4 + z) + z * z) * + (p5 + z * (p6 + z))))); + } else if (j < 0x412) { + z = r * r; + return (y + (p - ((q1 * r) * (q4 + z)) * + (q2 + z * (q3 + z)))); + } else + return (y + (p - r)); + } else { + if (j >= 0x7ff) /* x is inf or NaN */ + if (((ix - 0x7ff00000) | lx) != 0) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return (ix >= 0x7ff80000 ? x : x - x); + /* assumes sparc-like QNaN */ +#else + return (x - x); +#endif + y = -pio2lo; + return (hx >= 0 ? pio2hi - y : y - pio2hi); + } + } else { /* now x is between 1/8 and 8 */ + double *w, w0, w1, s, z; + w = (double *) _TBL_atan + (((ix - 0x3fc00000) >> 16) << 1); + w0 = (hx >= 0)? w[0] : -w[0]; + s = (x - w0) / (one + x * w0); + w1 = (hx >= 0)? w[1] : -w[1]; + z = s * s; + return (((q1 * s) * (q4 + z)) * (q2 + z * (q3 + z)) + w1); + } +} diff --git a/usr/src/libm/src/C/atan2.c b/usr/src/libm/src/C/atan2.c new file mode 100644 index 0000000..9767f3a --- /dev/null +++ b/usr/src/libm/src/C/atan2.c @@ -0,0 +1,498 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)atan2.c 1.22 06/01/23 SMI" + +#pragma weak atan2 = __atan2 + +#include "libm.h" + +/* + * Let t(0) = 1 and for i = 1, ..., 160, let t(i) be the slope of + * the line bisecting the conical hull of the set of points (x,y) + * where x and y are positive normal floating point numbers and + * the high order words hx and hy of their binary representations + * satisfy |hx - hy - i * 0x8000| <= 0x4000. Then: + * + * TBL[4*i+2] is t(i) rounded to 21 significant bits (i.e., the + * low order word is zero), and + * + * TBL[4*i] + TBL[4*i+1] form a doubled-double approximation to + * atan(TBL[4*i+2]). + * + * Finally, TBL[4*161] = TBL[4*161+1] = TBL[4*161+2] = 0. + * + * Now for any (x,y) with 0 < y <= x and any 0 < t <= 1, we have + * atan(y/x) = atan(t) + atan((y-t*x)/(x+t*y)). By choosing t = + * TBL[4*i+2], where i is the multiple of 0x8000 nearest hx - hy, + * if this multiple is less than 161, and i = 161 otherwise, we + * find that |(y-t*x)/(x+t*y)| <~ 2^-5. + */ +static const double TBL[] = { + 7.8539816339744827900e-01, +3.0616169978683830179e-17, + 1.0000000000000000000e+00, +0, + 7.7198905126506112140e-01, +2.6989956960083153652e-16, + 9.7353506088256835938e-01, +0, + 7.6068143954461309164e-01, -3.5178810518941914972e-16, + 9.5174932479858398438e-01, +0, + 7.4953661876353638860e-01, -3.2548100004524337476e-16, + 9.3073129653930664062e-01, +0, + 7.3854614984728339522e-01, -2.0775571023910406668e-16, + 9.1042709350585937500e-01, +0, + 7.2770146962041337702e-01, +3.8883249403168348802e-16, + 8.9078664779663085938e-01, +0, + 7.1699492488093774512e-01, -4.0468841511547224071e-16, + 8.7176513671875000000e-01, +0, + 7.0641813488653149022e-01, +5.6902424353981484031e-17, + 8.5331964492797851562e-01, +0, + 6.9596351101035658360e-01, +2.8245513321075021303e-16, + 8.3541154861450195312e-01, +0, + 6.8562363680534943455e-01, -4.2316970721658854064e-16, + 8.1800508499145507812e-01, +0, + 6.7539055666438230219e-01, +4.3535917281300047233e-16, + 8.0106592178344726562e-01, +0, + 6.6525763346931832132e-01, +1.1830431602404727977e-17, + 7.8456401824951171875e-01, +0, + 6.5521767574310185722e-01, -1.7435923100651044208e-16, + 7.6847028732299804688e-01, +0, + 6.4526390999481897381e-01, -1.4741927403093983947e-16, + 7.5275802612304687500e-01, +0, + 6.3538979894204850041e-01, +1.5734535069995660853e-16, + 7.3740243911743164062e-01, +0, + 6.2558914346942717799e-01, -2.8175588856316910960e-16, + 7.2238063812255859375e-01, +0, + 6.1585586476157949676e-01, -4.3056167357725226449e-16, + 7.0767116546630859375e-01, +0, + 6.0618408027576098362e-01, +1.5018013918429320289e-16, + 6.9325399398803710938e-01, +0, + 5.9656817827486730010e-01, +5.5271942033557644157e-17, + 6.7911052703857421875e-01, +0, + 5.8700289083426504533e-01, -8.2411369282676383293e-17, + 6.6522359848022460938e-01, +0, + 5.7748303053627658699e-01, +4.9400383775709159558e-17, + 6.5157699584960937500e-01, +0, + 5.6800353968303252117e-01, +2.9924431103311109543e-16, + 6.3815546035766601562e-01, +0, + 5.5855953863493823519e-01, -2.0306003403868777403e-16, + 6.2494468688964843750e-01, +0, + 5.4914706708329674711e-01, +2.8255378613779667461e-17, + 6.1193227767944335938e-01, +0, + 5.3976176660618069292e-01, +1.6370248781078747995e-16, + 5.9910583496093750000e-01, +0, + 5.3039888601412332747e-01, -7.6196097360093680134e-17, + 5.8645296096801757812e-01, +0, + 5.2105543924318808990e-01, -2.2400815668154739561e-16, + 5.7396411895751953125e-01, +0, + 5.1172778873967050828e-01, -3.6888136019899681185e-16, + 5.6162929534912109375e-01, +0, + 5.0241199666452196482e-01, -2.5412891474397011281e-16, + 5.4943847656250000000e-01, +0, + 4.9310493954293743712e-01, +4.4132186128251152229e-16, + 5.3738307952880859375e-01, +0, + 4.8380436844750995817e-01, -2.7844387907776656488e-16, + 5.2545595169067382812e-01, +0, + 4.7450670361463753721e-01, -2.0494355197368286028e-16, + 5.1364850997924804688e-01, +0, + 4.6367660027976320691e-01, +3.1709878607954760668e-16, + 5.0003623962402343750e-01, +0, + 4.5304753104003925301e-01, +3.3593436122420574865e-16, + 4.8681926727294921875e-01, +0, + 4.4423658037407065535e-01, +2.1987183192008082015e-17, + 4.7596645355224609375e-01, +0, + 4.3567016972500294258e-01, +3.0118422805369552650e-16, + 4.6550178527832031250e-01, +0, + 4.2733152672544871820e-01, -3.2667693224866479909e-16, + 4.5539522171020507812e-01, +0, + 4.1920540176693954493e-01, -2.2454273841113897647e-16, + 4.4561982154846191406e-01, +0, + 4.1127722812701872357e-01, -3.1620568973494653391e-16, + 4.3615055084228515625e-01, +0, + 4.0353384063084263289e-01, -3.5932009901481421723e-16, + 4.2696499824523925781e-01, +0, + 3.9596319345246833166e-01, -4.0281533417458698585e-16, + 4.1804289817810058594e-01, +0, + 3.8855405220339722661e-01, +1.6132231486045176674e-16, + 4.0936565399169921875e-01, +0, + 3.8129566313738116889e-01, +1.7684657060650804570e-16, + 4.0091586112976074219e-01, +0, + 3.7417884791401867517e-01, +2.6897604227426977619e-16, + 3.9267849922180175781e-01, +0, + 3.6719421967585041955e-01, -4.5886151448673745001e-17, + 3.8463878631591796875e-01, +0, + 3.6033388248727771241e-01, +1.5804115573136074946e-16, + 3.7678408622741699219e-01, +0, + 3.5358982224579182940e-01, +1.2624619863035782939e-16, + 3.6910200119018554688e-01, +0, + 3.4695498404186952968e-01, +9.3221684607372865177e-17, + 3.6158156394958496094e-01, +0, + 3.4042268308109679964e-01, +2.7697913559445449137e-16, + 3.5421252250671386719e-01, +0, + 3.3398684598563566084e-01, +3.6085337449716011085e-16, + 3.4698557853698730469e-01, +0, + 3.2764182824591436827e-01, +2.0581506352606456186e-16, + 3.3989214897155761719e-01, +0, + 3.2138200938788497041e-01, -1.9015787485430693661e-16, + 3.3292388916015625000e-01, +0, + 3.1520245348069497737e-01, +2.6961839659264087022e-16, + 3.2607340812683105469e-01, +0, + 3.0909871873117023000e-01, -1.5641891686756272625e-16, + 3.1933403015136718750e-01, +0, + 3.0306644308947827682e-01, +2.8801634211591956223e-16, + 3.1269931793212890625e-01, +0, + 2.9710135482774191473e-01, -4.3148994478973365819e-16, + 3.0616307258605957031e-01, +0, + 2.9120015759141004708e-01, -6.8539854790808585159e-17, + 2.9972028732299804688e-01, +0, + 2.8535879880370362827e-01, -1.2231638445300492682e-16, + 2.9336524009704589844e-01, +0, + 2.7957422506893880865e-01, -4.6707752931043135528e-17, + 2.8709340095520019531e-01, +0, + 2.7384352102802367313e-01, -4.1215636366229625876e-16, + 2.8090047836303710938e-01, +0, + 2.6816369484161040049e-01, -2.3700583122400495333e-16, + 2.7478218078613281250e-01, +0, + 2.6253212627627764419e-01, +2.3123213692190889610e-16, + 2.6873469352722167969e-01, +0, + 2.5694635355759309903e-01, -4.0638513814701264145e-16, + 2.6275444030761718750e-01, +0, + 2.5140385572454615470e-01, -3.4795333793554943723e-16, + 2.5683784484863281250e-01, +0, + 2.4500357070096612233e-01, +6.6542334848010259289e-17, + 2.5002646446228027344e-01, +0, + 2.3877766609573036760e-01, -2.7756633678549343650e-16, + 2.4342155456542968750e-01, +0, + 2.3365669377188336142e-01, +3.2700803838522067998e-16, + 2.3800384998321533203e-01, +0, + 2.2870810463931334766e-01, -4.4279127662219799521e-16, + 2.3278105258941650391e-01, +0, + 2.2391820542294382790e-01, +3.7558889374284208052e-16, + 2.2773718833923339844e-01, +0, + 2.1927501815429550902e-01, -1.4829838176513811186e-16, + 2.2285830974578857422e-01, +0, + 2.1476740847367459253e-01, -2.0535381496063397578e-17, + 2.1813154220581054688e-01, +0, + 2.1038568111737454558e-01, -4.2826767738736168650e-16, + 2.1354568004608154297e-01, +0, + 2.0612057974373865221e-01, +4.2108051749502232359e-16, + 2.0909011363983154297e-01, +0, + 2.0196410359405447821e-01, +3.5157118083511092869e-16, + 2.0475566387176513672e-01, +0, + 1.9790861144712756925e-01, +3.7894950972257700994e-16, + 2.0053362846374511719e-01, +0, + 1.9394752160084305359e-01, +2.8270367403478935534e-16, + 1.9641649723052978516e-01, +0, + 1.9007440763641536563e-01, -2.0842758095683676397e-16, + 1.9239699840545654297e-01, +0, + 1.8628369629742813629e-01, +3.4710917040399448932e-16, + 1.8846881389617919922e-01, +0, + 1.8256998712939509488e-01, +1.1053834120570125251e-16, + 1.8462586402893066406e-01, +0, + 1.7892875067284830237e-01, +3.0486232913366680305e-16, + 1.8086302280426025391e-01, +0, + 1.7535529778449010507e-01, -2.3810135019970148624e-16, + 1.7717504501342773438e-01, +0, + 1.7184559192514736736e-01, +5.1432582846210893916e-17, + 1.7355740070343017578e-01, +0, + 1.6839590847744290159e-01, +3.1605623296041433586e-18, + 1.7000591754913330078e-01, +0, + 1.6500283902547518977e-01, +1.5405422268770998251e-16, + 1.6651678085327148438e-01, +0, + 1.6166306303174859949e-01, +4.0042241517254928672e-16, + 1.6308629512786865234e-01, +0, + 1.5837358268281231943e-01, -2.2786616251622967291e-16, + 1.5971112251281738281e-01, +0, + 1.5513160990288810126e-01, -3.7547723514797166336e-16, + 1.5638816356658935547e-01, +0, + 1.5193468535499299321e-01, +4.3497510505554267446e-16, + 1.5311467647552490234e-01, +0, + 1.4878033155427861089e-01, -2.3102860235324261895e-16, + 1.4988791942596435547e-01, +0, + 1.4566628729590647140e-01, +9.9227592950040279415e-17, + 1.4670538902282714844e-01, +0, + 1.4259050967286590605e-01, -3.3869909683813096906e-18, + 1.4356482028961181641e-01, +0, + 1.3955105903633846509e-01, +1.5500435650773331566e-17, + 1.4046406745910644531e-01, +0, + 1.3654610022831903393e-01, +3.3965918616682805753e-16, + 1.3740110397338867188e-01, +0, + 1.3357402082462854764e-01, +2.7572431581527535421e-16, + 1.3437414169311523438e-01, +0, + 1.3063319828908959153e-01, -3.4667213797076707331e-16, + 1.3138139247894287109e-01, +0, + 1.2772200049776749609e-01, +3.1089261947725651968e-16, + 1.2842106819152832031e-01, +0, + 1.2436931430778752627e-01, -4.0654251891464630059e-16, + 1.2501454353332519531e-01, +0, + 1.2111683701666819957e-01, -3.9381654342464836012e-16, + 1.2171256542205810547e-01, +0, + 1.1844801833536511282e-01, -3.6673155595150283444e-16, + 1.1900508403778076172e-01, +0, + 1.1587365536613614125e-01, -1.5026628801318421951e-16, + 1.1639505624771118164e-01, +0, + 1.1338607085741525538e-01, +1.2886806274050538880e-16, + 1.1387449502944946289e-01, +0, + 1.1097844020819369604e-01, +2.3848343623577768044e-16, + 1.1143630743026733398e-01, +0, + 1.0864456107308662069e-01, +4.2065430313285469408e-16, + 1.0907405614852905273e-01, +0, + 1.0637891628473727934e-01, -4.6883543790348472687e-18, + 1.0678201913833618164e-01, +0, + 1.0417650062205296990e-01, +1.4774925414624453292e-16, + 1.0455501079559326172e-01, +0, + 1.0203276464730581807e-01, -1.5677032794816452332e-16, + 1.0238832235336303711e-01, +0, + 9.9943617083734892503e-02, +3.4511310907979792828e-16, + 1.0027772188186645508e-01, +0, + 9.7905249824711049200e-02, +3.4489485563461708496e-16, + 9.8219275474548339844e-02, +0, + 9.5914316649349906641e-02, -1.3214510886789011569e-17, + 9.6209526062011718750e-02, +0, + 9.3967698614664918466e-02, +1.1048427091217964090e-16, + 9.4245254993438720703e-02, +0, + 9.2062564267554769515e-02, -3.7297463814697759309e-16, + 9.2323541641235351562e-02, +0, + 9.0196252506350660383e-02, -3.5280143043576718079e-16, + 9.0441644191741943359e-02, +0, + 8.8366391663268650802e-02, -6.1140673227541621183e-17, + 8.8597118854522705078e-02, +0, + 8.6570782100201526532e-02, -2.0998844594957629702e-16, + 8.6787700653076171875e-02, +0, + 8.4807337678923566671e-02, +3.9530981588194673068e-16, + 8.5011243820190429688e-02, +0, + 8.3074323040850828193e-02, -4.3022503210464894539e-17, + 8.3265960216522216797e-02, +0, + 8.1369880712663267275e-02, -6.3063867569127169744e-18, + 8.1549942493438720703e-02, +0, + 7.9692445771216036121e-02, -5.0787623072962671502e-17, + 7.9861581325531005859e-02, +0, + 7.8040568735575632786e-02, -3.8810063021216721741e-16, + 7.8199386596679687500e-02, +0, + 7.6412797391314235540e-02, +4.1246529500495762995e-16, + 7.6561868190765380859e-02, +0, + 7.4807854772808823896e-02, -3.7025599052186724156e-16, + 7.4947714805603027344e-02, +0, + 7.3224639528778112663e-02, +4.2209138483206712401e-17, + 7.3355793952941894531e-02, +0, + 7.1661929761571485642e-02, -3.2074473649855177622e-16, + 7.1784853935241699219e-02, +0, + 7.0118738881148168218e-02, -2.5371257235753296804e-16, + 7.0233881473541259766e-02, +0, + 6.8594137996416115755e-02, +3.3796987842548399135e-16, + 6.8701922893524169922e-02, +0, + 6.7087137393172291411e-02, +5.5061492696328852397e-17, + 6.7187964916229248047e-02, +0, + 6.5596983299946565182e-02, -2.1580863111502565280e-16, + 6.5691232681274414062e-02, +0, + 6.4122802037412718335e-02, -3.1315661827469233434e-16, + 6.4210832118988037109e-02, +0, + 6.2426231582525915087e-02, -2.5758980071296622188e-16, + 6.2507450580596923828e-02, +0, + 6.0781559928021700046e-02, +1.3736899336217710591e-16, + 6.0856521129608154297e-02, +0, + 5.9432882624005145544e-02, +2.2246097394328856474e-16, + 5.9502959251403808594e-02, +0, + 5.8132551274581167888e-02, -6.2525053236379489390e-18, + 5.8198124170303344727e-02, +0, + 5.6876611930681164608e-02, -2.6589930995607417149e-16, + 5.6938022375106811523e-02, +0, + 5.5661522654748551986e-02, -4.2736362859832186197e-16, + 5.5719077587127685547e-02, +0, + 5.4484124463757943602e-02, -1.6708067365310384253e-16, + 5.4538100957870483398e-02, +0, + 5.3341582449436764080e-02, +3.3271673004611311850e-17, + 5.3392231464385986328e-02, +0, + 5.2231267345892007370e-02, -3.5593396674200571616e-16, + 5.2278816699981689453e-02, +0, + 5.1150874758829623090e-02, +1.4432815841187114832e-16, + 5.1195532083511352539e-02, +0, + 5.0098306612679444072e-02, +9.4680943793589404083e-17, + 5.0140261650085449219e-02, +0, + 4.9071641675614507960e-02, +2.1131168520301896817e-16, + 4.9111068248748779297e-02, +0, + 4.8069135772851545596e-02, +1.6035336741307516296e-16, + 4.8106193542480468750e-02, +0, + 4.7089192241088539959e-02, -2.2491738698796901479e-16, + 4.7124028205871582031e-02, +0, + 4.6130362086062248750e-02, -1.5111423469578965206e-16, + 4.6163111925125122070e-02, +0, + 4.5191314382707403752e-02, +4.1989325207399786612e-16, + 4.5222103595733642578e-02, +0, + 4.4270836390474244126e-02, -4.1432635292331004454e-16, + 4.4299781322479248047e-02, +0, + 4.3367774164955186222e-02, -3.0615383054587355892e-16, + 4.3394982814788818359e-02, +0, + 4.2481121875321825598e-02, -3.6730166956273555173e-16, + 4.2506694793701171875e-02, +0, + 4.1609902899457651415e-02, -4.4226425958068821782e-16, + 4.1633933782577514648e-02, +0, + 4.0753259129372665370e-02, +1.9801161516527046872e-16, + 4.0775835514068603516e-02, +0, + 3.9910361780060910064e-02, +8.2560620036613164573e-18, + 3.9931565523147583008e-02, +0, + 3.9080441183869218946e-02, +3.9908991939242971628e-17, + 3.9100348949432373047e-02, +0, + 3.8262816593271686827e-02, +9.5182237812195590276e-17, + 3.8281500339508056641e-02, +0, + 3.7456806948784837630e-02, +1.5213508760679563439e-16, + 3.7474334239959716797e-02, +0, + 3.6661849947035918262e-02, +7.3335516005184616486e-17, + 3.6678284406661987305e-02, +0, + 3.5877353272533163420e-02, -1.3007348019891714540e-16, + 3.5892754793167114258e-02, +0, + 3.5102754135096780885e-02, -2.9903662298950558656e-16, + 3.5117179155349731445e-02, +0, + 3.4337638360670830195e-02, +2.9656295131966114331e-16, + 3.4351140260696411133e-02, +0, + 3.3581472523789734907e-02, +3.4810947205572817820e-16, + 3.3594101667404174805e-02, +0, + 3.2833871859357266487e-02, -3.8885440174405159838e-16, + 3.2845675945281982422e-02, +0, + 3.2094421679560447558e-02, +5.8805134853032009978e-17, + 3.2105445861816406250e-02, +0, + 3.1243584858944295490e-02, +2.8737383773884313066e-17, + 3.1253755092620849609e-02, +0, + 0, 0, 0, 0 +}; + +static const double C[] = { + 0.0, + 0.125, + 1.2980742146337069071e+33, + 7.8539816339744827900e-01, + 1.5707963267948965580e+00, + 6.1232339957367658860e-17, + -3.1415926535897931160e+00, + -1.2246467991473531772e-16, + -3.33333333333327571893331786354179101074860633009e-0001, + +1.99999999942671624230086497610394721817438631379e-0001, + -1.42856965565428636896183013324727205980484158356e-0001, + +1.10894981496317081405107718475040168084164825641e-0001, +}; + +#define zero C[0] +#define twom3 C[1] +#define two110 C[2] +#define pio4 C[3] +#define pio2 C[4] +#define pio2_lo C[5] +#define mpi C[6] +#define mpi_lo C[7] +#define p1 C[8] +#define p2 C[9] +#define p3 C[10] +#define p4 C[11] + +double +atan2(double oy, double ox) { + double ah, al, t, xh, x, y, z; + int i, k, hx, hy, sx, sy; +#ifndef lint + volatile int inexact; +#endif + + hy = ((int *)&oy)[HIWORD]; + sy = hy & 0x80000000; + hy &= ~0x80000000; + + hx = ((int *)&ox)[HIWORD]; + sx = hx & 0x80000000; + hx &= ~0x80000000; + + if (hy > hx || (hy == hx && ((unsigned *)&oy)[LOWORD] > + ((unsigned *)&ox)[LOWORD])) { + i = hx; + hx = hy; + hy = i; + x = fabs(oy); + y = fabs(ox); + if (sx) { + ah = pio2; + al = pio2_lo; + } else { + ah = -pio2; + al = -pio2_lo; + sy ^= 0x80000000; + } + } else { + x = fabs(ox); + y = fabs(oy); + if (sx) { + ah = mpi; + al = mpi_lo; + sy ^= 0x80000000; + } else { + ah = al = zero; + } + } + + if (hx >= 0x7fe00000 || hx - hy >= 0x03600000) { + if (hx >= 0x7ff00000) { + if (((hx ^ 0x7ff00000) | ((int *)&x)[LOWORD]) != 0) + return (ox * oy); + if (hy >= 0x7ff00000) + ah += pio4; +#ifndef lint + inexact = (int)ah; /* inexact if ah != 0 */ +#endif + return ((sy)? -ah : ah); + } + if (hx - hy >= 0x03600000) { + if ((int)ah == 0) + ah = y / x; + return ((sy)? -ah : ah); + } + y *= twom3; + x *= twom3; + hy -= 0x00300000; + hx -= 0x00300000; + } else if (hy < 0x00100000) { + if ((hy | ((int *)&y)[LOWORD]) == 0) { + if ((hx | ((int *)&x)[LOWORD]) == 0) + return (_SVID_libm_err(ox, oy, 3)); +#ifndef lint + inexact = (int)ah; /* inexact if ah != 0 */ +#endif + return ((sy)? -ah : ah); + } + y *= two110; + x *= two110; + hy = ((int *)&y)[HIWORD]; + hx = ((int *)&x)[HIWORD]; + } + + k = (((hx - hy) + 0x00004000) >> 13) & ~0x3; + if (k > 644) + k = 644; + ah += TBL[k]; + al += TBL[k+1]; + t = TBL[k+2]; + + xh = x; + ((int *)&xh)[LOWORD] = 0; + z = ((y - t * xh) - t * (x - xh)) / (x + y * t); + x = z * z; + t = ah + (z + (al + (z * x) * (p1 + x * (p2 + x * (p3 + x * p4))))); + return ((sy)? -t : t); +} diff --git a/usr/src/libm/src/C/atan2pi.c b/usr/src/libm/src/C/atan2pi.c new file mode 100644 index 0000000..85a6171 --- /dev/null +++ b/usr/src/libm/src/C/atan2pi.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)atan2pi.c 1.6 06/01/23 SMI" + +#pragma weak atan2pi = __atan2pi + +/* + * atan2pi(x) = atan2(x)/pi + */ + +#include "libm.h" + +static const double invpi = 0.3183098861837906715377675; + +double +atan2pi(double y, double x) { + int ix, iy; + + if (x == 0.0 && y == 0.0) { + ix = ((int *)&x)[HIWORD]; + iy = ((int *)&y)[HIWORD]; + if (ix >= 0) + return (y); + return ((iy >= 0)? 1.0 : -1.0); + } + return (atan2(y, x) * invpi); +} diff --git a/usr/src/libm/src/C/atanh.c b/usr/src/libm/src/C/atanh.c new file mode 100644 index 0000000..23607cd --- /dev/null +++ b/usr/src/libm/src/C/atanh.c @@ -0,0 +1,69 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)atanh.c 1.17 06/01/31 SMI" + +#pragma weak atanh = __atanh + +/* INDENT OFF */ +/* atanh(x) + * Code originated from 4.3bsd. + * Modified by K.C. Ng for SUN 4.0 libm. + * Method : + * 1 2x x + * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) + * 2 1 - x 1 - x + * Note: to guarantee atanh(-x) = -atanh(x), we use + * sign(x) |x| + * atanh(x) = ------- * log1p(2*-------). + * 2 1 - |x| + * + * Special cases: + * atanh(x) is NaN if |x| > 1 with signal; + * atanh(NaN) is that NaN with no signal; + * atanh(+-1) is +-INF with signal. + */ +/* INDENT ON */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> + +double +atanh(double x) { + double t; + + if (isnan(x)) + return x * x; /* switched from x + x for Cheetah */ + t = fabs(x); + if (t > 1.0) + return _SVID_libm_err(x, x, 30); /* sNaN */ + if (t == 1.0) + return _SVID_libm_err(x, x, 31); /* x/0; */ + t = t / (1.0 - t); + return copysign(0.5, x) * log1p(t + t); +} diff --git a/usr/src/libm/src/C/cbrt.c b/usr/src/libm/src/C/cbrt.c new file mode 100644 index 0000000..7969a29 --- /dev/null +++ b/usr/src/libm/src/C/cbrt.c @@ -0,0 +1,283 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)cbrt.c 1.16 06/01/31 SMI" + +/* INDENT OFF */ + +/* + * cbrt: double precision cube root + * + * Algorithm: bit hacking, table lookup, and polynomial approximation + * + * For normal x, write x = s*2^(3j)*z where s = +/-1, j is an integer, + * and 1 <= z < 8. Let y := s*2^j. From a table, find u such that + * u^3 is computable exactly and |(z-u^3)/u^3| <~ 2^-8. We construct + * y, z, and the table index from x by a few integer operations. + * + * Now cbrt(x) = y*u*(1+t)^(1/3) where t = (z-u^3)/u^3. We approximate + * (1+t)^(1/3) by a polynomial 1+p(t), where p(t) := t*(p1+t*(p2+...+ + * (p5+t*p6))). By computing the result as y*(u+u*p(t)), we can bound + * the worst case error by .51 ulp. + * + * Notes: + * + * 1. For subnormal x, we scale x by 2^54, compute the cube root, and + * scale the result by 2^-18. + * + * 2. cbrt(+/-inf) = +/-inf and cbrt(NaN) is NaN. + */ + +/* + * for i = 0, ..., 385 + * form x(i) with high word 0x3ff00000 + (i << 13) and low word 0; + * then TBL[i] = cbrt(x(i)) rounded to 17 significant bits + */ +static const double __libm_TBL_cbrt[] = { + 1.00000000000000000e+00, 1.00259399414062500e+00, 1.00518798828125000e+00, + 1.00775146484375000e+00, 1.01031494140625000e+00, 1.01284790039062500e+00, + 1.01538085937500000e+00, 1.01791381835937500e+00, 1.02041625976562500e+00, + 1.02290344238281250e+00, 1.02539062500000000e+00, 1.02786254882812500e+00, + 1.03031921386718750e+00, 1.03277587890625000e+00, 1.03520202636718750e+00, + 1.03762817382812500e+00, 1.04003906250000000e+00, 1.04244995117187500e+00, + 1.04483032226562500e+00, 1.04721069335937500e+00, 1.04959106445312500e+00, + 1.05194091796875000e+00, 1.05429077148437500e+00, 1.05662536621093750e+00, + 1.05895996093750000e+00, 1.06127929687500000e+00, 1.06358337402343750e+00, + 1.06587219238281250e+00, 1.06816101074218750e+00, 1.07044982910156250e+00, + 1.07270812988281250e+00, 1.07496643066406250e+00, 1.07722473144531250e+00, + 1.07945251464843750e+00, 1.08168029785156250e+00, 1.08390808105468750e+00, + 1.08612060546875000e+00, 1.08831787109375000e+00, 1.09051513671875000e+00, + 1.09269714355468750e+00, 1.09487915039062500e+00, 1.09704589843750000e+00, + 1.09921264648437500e+00, 1.10136413574218750e+00, 1.10350036621093750e+00, + 1.10563659667968750e+00, 1.10775756835937500e+00, 1.10987854003906250e+00, + 1.11198425292968750e+00, 1.11408996582031250e+00, 1.11618041992187500e+00, + 1.11827087402343750e+00, 1.12034606933593750e+00, 1.12242126464843750e+00, + 1.12448120117187500e+00, 1.12654113769531250e+00, 1.12858581542968750e+00, + 1.13063049316406250e+00, 1.13265991210937500e+00, 1.13468933105468750e+00, + 1.13670349121093750e+00, 1.13871765136718750e+00, 1.14073181152343750e+00, + 1.14273071289062500e+00, 1.14471435546875000e+00, 1.14669799804687500e+00, + 1.14868164062500000e+00, 1.15065002441406250e+00, 1.15260314941406250e+00, + 1.15457153320312500e+00, 1.15650939941406250e+00, 1.15846252441406250e+00, + 1.16040039062500000e+00, 1.16232299804687500e+00, 1.16424560546875000e+00, + 1.16616821289062500e+00, 1.16807556152343750e+00, 1.16998291015625000e+00, + 1.17189025878906250e+00, 1.17378234863281250e+00, 1.17567443847656250e+00, + 1.17755126953125000e+00, 1.17942810058593750e+00, 1.18128967285156250e+00, + 1.18315124511718750e+00, 1.18501281738281250e+00, 1.18685913085937500e+00, + 1.18870544433593750e+00, 1.19055175781250000e+00, 1.19238281250000000e+00, + 1.19421386718750000e+00, 1.19602966308593750e+00, 1.19786071777343750e+00, + 1.19966125488281250e+00, 1.20147705078125000e+00, 1.20327758789062500e+00, + 1.20507812500000000e+00, 1.20686340332031250e+00, 1.20864868164062500e+00, + 1.21043395996093750e+00, 1.21220397949218750e+00, 1.21397399902343750e+00, + 1.21572875976562500e+00, 1.21749877929687500e+00, 1.21925354003906250e+00, + 1.22099304199218750e+00, 1.22274780273437500e+00, 1.22448730468750000e+00, + 1.22621154785156250e+00, 1.22795104980468750e+00, 1.22967529296875000e+00, + 1.23138427734375000e+00, 1.23310852050781250e+00, 1.23481750488281250e+00, + 1.23652648925781250e+00, 1.23822021484375000e+00, 1.23991394042968750e+00, + 1.24160766601562500e+00, 1.24330139160156250e+00, 1.24497985839843750e+00, + 1.24665832519531250e+00, 1.24833679199218750e+00, 1.25000000000000000e+00, + 1.25166320800781250e+00, 1.25332641601562500e+00, 1.25497436523437500e+00, + 1.25663757324218750e+00, 1.25828552246093750e+00, 1.25991821289062500e+00, + 1.26319885253906250e+00, 1.26644897460937500e+00, 1.26968383789062500e+00, + 1.27290344238281250e+00, 1.27612304687500000e+00, 1.27931213378906250e+00, + 1.28248596191406250e+00, 1.28564453125000000e+00, 1.28878784179687500e+00, + 1.29191589355468750e+00, 1.29502868652343750e+00, 1.29812622070312500e+00, + 1.30120849609375000e+00, 1.30427551269531250e+00, 1.30732727050781250e+00, + 1.31036376953125000e+00, 1.31340026855468750e+00, 1.31640625000000000e+00, + 1.31941223144531250e+00, 1.32238769531250000e+00, 1.32536315917968750e+00, + 1.32832336425781250e+00, 1.33126831054687500e+00, 1.33419799804687500e+00, + 1.33712768554687500e+00, 1.34002685546875000e+00, 1.34292602539062500e+00, + 1.34580993652343750e+00, 1.34867858886718750e+00, 1.35153198242187500e+00, + 1.35437011718750000e+00, 1.35720825195312500e+00, 1.36003112792968750e+00, + 1.36283874511718750e+00, 1.36564636230468750e+00, 1.36842346191406250e+00, + 1.37120056152343750e+00, 1.37396240234375000e+00, 1.37672424316406250e+00, + 1.37945556640625000e+00, 1.38218688964843750e+00, 1.38491821289062500e+00, + 1.38761901855468750e+00, 1.39031982421875000e+00, 1.39302062988281250e+00, + 1.39569091796875000e+00, 1.39836120605468750e+00, 1.40101623535156250e+00, + 1.40367126464843750e+00, 1.40631103515625000e+00, 1.40893554687500000e+00, + 1.41156005859375000e+00, 1.41416931152343750e+00, 1.41676330566406250e+00, + 1.41935729980468750e+00, 1.42193603515625000e+00, 1.42449951171875000e+00, + 1.42706298828125000e+00, 1.42962646484375000e+00, 1.43215942382812500e+00, + 1.43469238281250000e+00, 1.43722534179687500e+00, 1.43974304199218750e+00, + 1.44224548339843750e+00, 1.44474792480468750e+00, 1.44723510742187500e+00, + 1.44972229003906250e+00, 1.45219421386718750e+00, 1.45466613769531250e+00, + 1.45712280273437500e+00, 1.45956420898437500e+00, 1.46200561523437500e+00, + 1.46444702148437500e+00, 1.46687316894531250e+00, 1.46928405761718750e+00, + 1.47169494628906250e+00, 1.47409057617187500e+00, 1.47648620605468750e+00, + 1.47886657714843750e+00, 1.48124694824218750e+00, 1.48361206054687500e+00, + 1.48597717285156250e+00, 1.48834228515625000e+00, 1.49067687988281250e+00, + 1.49302673339843750e+00, 1.49536132812500000e+00, 1.49768066406250000e+00, + 1.50000000000000000e+00, 1.50230407714843750e+00, 1.50460815429687500e+00, + 1.50691223144531250e+00, 1.50920104980468750e+00, 1.51148986816406250e+00, + 1.51376342773437500e+00, 1.51603698730468750e+00, 1.51829528808593750e+00, + 1.52055358886718750e+00, 1.52279663085937500e+00, 1.52503967285156250e+00, + 1.52728271484375000e+00, 1.52951049804687500e+00, 1.53173828125000000e+00, + 1.53395080566406250e+00, 1.53616333007812500e+00, 1.53836059570312500e+00, + 1.54055786132812500e+00, 1.54275512695312500e+00, 1.54493713378906250e+00, + 1.54711914062500000e+00, 1.54928588867187500e+00, 1.55145263671875000e+00, + 1.55361938476562500e+00, 1.55577087402343750e+00, 1.55792236328125000e+00, + 1.56005859375000000e+00, 1.56219482421875000e+00, 1.56433105468750000e+00, + 1.56645202636718750e+00, 1.56857299804687500e+00, 1.57069396972656250e+00, + 1.57279968261718750e+00, 1.57490539550781250e+00, 1.57699584960937500e+00, + 1.57908630371093750e+00, 1.58117675781250000e+00, 1.58325195312500000e+00, + 1.58532714843750000e+00, 1.58740234375000000e+00, 1.59152221679687500e+00, + 1.59562683105468750e+00, 1.59970092773437500e+00, 1.60375976562500000e+00, + 1.60780334472656250e+00, 1.61183166503906250e+00, 1.61582946777343750e+00, + 1.61981201171875000e+00, 1.62376403808593750e+00, 1.62770080566406250e+00, + 1.63162231445312500e+00, 1.63552856445312500e+00, 1.63941955566406250e+00, + 1.64328002929687500e+00, 1.64714050292968750e+00, 1.65097045898437500e+00, + 1.65476989746093750e+00, 1.65856933593750000e+00, 1.66235351562500000e+00, + 1.66610717773437500e+00, 1.66986083984375000e+00, 1.67358398437500000e+00, + 1.67729187011718750e+00, 1.68098449707031250e+00, 1.68466186523437500e+00, + 1.68832397460937500e+00, 1.69197082519531250e+00, 1.69560241699218750e+00, + 1.69921875000000000e+00, 1.70281982421875000e+00, 1.70640563964843750e+00, + 1.70997619628906250e+00, 1.71353149414062500e+00, 1.71707153320312500e+00, + 1.72059631347656250e+00, 1.72410583496093750e+00, 1.72760009765625000e+00, + 1.73109436035156250e+00, 1.73455810546875000e+00, 1.73800659179687500e+00, + 1.74145507812500000e+00, 1.74488830566406250e+00, 1.74829101562500000e+00, + 1.75169372558593750e+00, 1.75508117675781250e+00, 1.75846862792968750e+00, + 1.76182556152343750e+00, 1.76516723632812500e+00, 1.76850891113281250e+00, + 1.77183532714843750e+00, 1.77514648437500000e+00, 1.77844238281250000e+00, + 1.78173828125000000e+00, 1.78500366210937500e+00, 1.78826904296875000e+00, + 1.79151916503906250e+00, 1.79476928710937500e+00, 1.79798889160156250e+00, + 1.80120849609375000e+00, 1.80441284179687500e+00, 1.80760192871093750e+00, + 1.81079101562500000e+00, 1.81396484375000000e+00, 1.81712341308593750e+00, + 1.82026672363281250e+00, 1.82341003417968750e+00, 1.82653808593750000e+00, + 1.82965087890625000e+00, 1.83276367187500000e+00, 1.83586120605468750e+00, + 1.83894348144531250e+00, 1.84201049804687500e+00, 1.84507751464843750e+00, + 1.84812927246093750e+00, 1.85118103027343750e+00, 1.85421752929687500e+00, + 1.85723876953125000e+00, 1.86026000976562500e+00, 1.86326599121093750e+00, + 1.86625671386718750e+00, 1.86924743652343750e+00, 1.87222290039062500e+00, + 1.87518310546875000e+00, 1.87814331054687500e+00, 1.88108825683593750e+00, + 1.88403320312500000e+00, 1.88696289062500000e+00, 1.88987731933593750e+00, + 1.89279174804687500e+00, 1.89569091796875000e+00, 1.89859008789062500e+00, + 1.90147399902343750e+00, 1.90435791015625000e+00, 1.90722656250000000e+00, + 1.91007995605468750e+00, 1.91293334960937500e+00, 1.91577148437500000e+00, + 1.91860961914062500e+00, 1.92143249511718750e+00, 1.92425537109375000e+00, + 1.92706298828125000e+00, 1.92985534667968750e+00, 1.93264770507812500e+00, + 1.93544006347656250e+00, 1.93821716308593750e+00, 1.94097900390625000e+00, + 1.94374084472656250e+00, 1.94650268554687500e+00, 1.94924926757812500e+00, + 1.95198059082031250e+00, 1.95471191406250000e+00, 1.95742797851562500e+00, + 1.96014404296875000e+00, 1.96286010742187500e+00, 1.96556091308593750e+00, + 1.96824645996093750e+00, 1.97093200683593750e+00, 1.97361755371093750e+00, + 1.97628784179687500e+00, 1.97894287109375000e+00, 1.98159790039062500e+00, + 1.98425292968750000e+00, 1.98689270019531250e+00, 1.98953247070312500e+00, + 1.99215698242187500e+00, 1.99478149414062500e+00, 1.99739074707031250e+00, + 2.00000000000000000e+00, +}; + +/* + * The polynomial p(x) := p1*x + p2*x^2 + ... + p6*x^6 satisfies + * + * |(1+x)^(1/3) - 1 - p(x)| < 2^-63 for |x| < 0.003914 + */ +static const double C[] = { + 3.33333333333333340735623180707664400321413178600e-0001, + -1.11111111111111111992797989129069515334791432304e-0001, + 6.17283950578506695710302115234720605072083379082e-0002, + -4.11522633731005164138964638666647311514892319010e-0002, + 3.01788343105268728151735586597807324859173704847e-0002, + -2.34723340038386971009665073968507263074215090751e-0002, + 18014398509481984.0 +}; + +#define p1 C[0] +#define p2 C[1] +#define p3 C[2] +#define p4 C[3] +#define p5 C[4] +#define p6 C[5] +#define two54 C[6] + +/* INDENT ON */ + +#if defined(__sparc) + +#define HIWORD 0 +#define LOWORD 1 + +#elif defined(__i386) + +#define HIWORD 1 +#define LOWORD 0 + +#else +#error Unknown architecture +#endif + +#pragma weak cbrt = __cbrt + +double __cbrt(double x) +{ + union { + unsigned int i[2]; + double d; + } xx, yy; + double t, u, w; + unsigned int hx, sx, ex, j, offset; + + xx.d = x; + hx = xx.i[HIWORD] & ~0x80000000; + sx = xx.i[HIWORD] & 0x80000000; + + /* handle special cases */ + if (hx >= 0x7ff00000) /* x is inf or nan */ +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return hx >= 0x7ff80000 ? x : x + x; + /* assumes sparc-like QNaN */ +#else + return x + x; +#endif + + if (hx < 0x00100000) { /* x is subnormal or zero */ + if ((hx | xx.i[LOWORD]) == 0) + return x; + + /* scale x to normal range */ + xx.d = x * two54; + hx = xx.i[HIWORD] & ~0x80000000; + offset = 0x29800000; + } + else + offset = 0x2aa00000; + + ex = hx & 0x7ff00000; + j = (ex >> 2) + (ex >> 4) + (ex >> 6); + j = j + (j >> 6); + j = 0x7ff00000 & (j + 0x2aa00); /* j is ex/3 */ + hx -= (j + j + j); + xx.i[HIWORD] = 0x3ff00000 + hx; + + u = __libm_TBL_cbrt[(hx + 0x1000) >> 13]; + w = u * u * u; + t = (xx.d - w) / w; + + yy.i[HIWORD] = sx | (j + offset); + yy.i[LOWORD] = 0; + + w = t * t; + return yy.d * (u + u * (t * (p1 + t * p2 + w * p3) + + (w * w) * (p4 + t * p5 + w * p6))); +} diff --git a/usr/src/libm/src/C/ceil.c b/usr/src/libm/src/C/ceil.c new file mode 100644 index 0000000..ea8d6b6 --- /dev/null +++ b/usr/src/libm/src/C/ceil.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)ceil.c 1.8 06/01/23 SMI" + +#pragma weak ceil = __ceil + +/* + * ceil(x) returns the least integral value bigger than or equal to x. + * NOTE: ceil(x) returns result with the same sign as x's, including 0. + * + * Modified 8/4/04 for performance. + */ + +#include "libm.h" + +static const double + zero = 0.0, + one = 1.0, + two52 = 4503599627370496.0; + +double +ceil(double x) { + double t, w; + int hx, lx, ix; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + ix = hx & ~0x80000000; + if (ix >= 0x43300000) /* return x if |x| >= 2^52, or x is NaN */ + return (x * one); + t = (hx >= 0)? two52 : -two52; + w = x + t; + t = w - t; + if (ix < 0x3ff00000) { + if ((ix | lx) == 0) + return (x); + else + return ((hx < 0)? -zero : one); + } + return ((t >= x)? t : t + one); +} diff --git a/usr/src/libm/src/C/copysign.c b/usr/src/libm/src/C/copysign.c new file mode 100644 index 0000000..7478fcb --- /dev/null +++ b/usr/src/libm/src/C/copysign.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)copysign.c 1.8 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak copysign = __copysign +#endif + +#include "libm.h" + +double +copysign(double x, double y) { + int hx, hy; + + hx = ((int *) &x)[HIWORD]; + hy = ((int *) &y)[HIWORD]; + return (hx ^ hy) >= 0 ? (x) : (-x); +} diff --git a/usr/src/libm/src/C/cos.c b/usr/src/libm/src/C/cos.c new file mode 100644 index 0000000..6c184ab --- /dev/null +++ b/usr/src/libm/src/C/cos.c @@ -0,0 +1,222 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)cos.c 1.13 06/01/23 SMI" + +#pragma weak cos = __cos + +/* INDENT OFF */ +/* + * cos(x) + * Accurate Table look-up algorithm by K.C. Ng, May, 1995. + * + * Algorithm: see sincos.c + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* Q1 = */ -0.5, +/* Q2 = */ 4.166666666500350703680945520860748617445e-0002, +/* Q3 = */ -1.388888596436972210694266290577848696006e-0003, +/* Q4 = */ 2.478563078858589473679519517892953492192e-0005, +/* PIO2_H = */ 1.570796326794896557999, +/* PIO2_L = */ 6.123233995736765886130e-17, +/* PIO2_L0 = */ 6.123233995727922165564e-17, +/* PIO2_L1 = */ 8.843720566135701120255e-29, +/* PI3O2_H = */ 4.712388980384689673997, +/* PI3O2_L = */ 1.836970198721029765839e-16, +/* PI3O2_L0 = */ 1.836970198720396133587e-16, +/* PI3O2_L1 = */ 6.336322524749201142226e-29, +/* PI5O2_H = */ 7.853981633974482789995, +/* PI5O2_L = */ 3.061616997868382943065e-16, +/* PI5O2_L0 = */ 3.061616997861941598865e-16, +/* PI5O2_L1 = */ 6.441344200433640781982e-28, +}; +/* INDENT ON */ + +#define ONE sc[0] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define Q1 sc[10] +#define Q2 sc[11] +#define Q3 sc[12] +#define Q4 sc[13] +#define PIO2_H sc[14] +#define PIO2_L sc[15] +#define PIO2_L0 sc[16] +#define PIO2_L1 sc[17] +#define PI3O2_H sc[18] +#define PI3O2_L sc[19] +#define PI3O2_L0 sc[20] +#define PI3O2_L1 sc[21] +#define PI5O2_H sc[22] +#define PI5O2_L sc[23] +#define PI5O2_L0 sc[24] +#define PI5O2_L1 sc[25] + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +double +cos(double x) { + double z, y[2], w, s, v, p, q; + int i, j, n, hx, ix, lx; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */ + if (ix < 0x3e400000) { /* |x| < 2**-27 */ + if ((int)x == 0) + return (ONE); + } + z = x * x; + if (ix < 0x3f800000) /* |x| < 0.008 */ + w = z * (QQ1 + z * QQ2); + else + w = z * ((Q1 + z * Q2) + (z * z) * (Q3 + z * Q4)); + return (ONE + w); + } + + /* for 0.164062500 < x < M, */ + n = ix >> 20; + if (n < 0x402) { /* x < 8 */ + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + x = fabs(x); + v = x - _TBL_sincosx[j]; + if (((j - 81) ^ (j - 101)) < 0) { + /* near pi/2, cos(pi/2-x)=sin(x) */ + p = PIO2_H - x; + i = ix - 0x3ff921fb; + x = p + PIO2_L; + if ((i | ((lx - 0x54442D00) & 0xffffff00)) == 0) { + /* very close to pi/2 */ + x = p + PIO2_L0; + return (x + PIO2_L1); + } + z = x * x; + if (((ix - 0x3ff92000) >> 12) == 0) { + /* |pi/2-x|<2**-8 */ + w = PIO2_L + (z * x) * (PP1 + z * PP2); + } else { + w = PIO2_L + (z * x) * ((P1 + z * P2) + + (z * z) * (P3 + z * P4)); + } + return (p + w); + } + s = v * v; + if (((j - 282) ^ (j - 302)) < 0) { + /* near 3/2pi, cos(x-3/2pi)=sin(x) */ + p = x - PI3O2_H; + i = ix - 0x4012D97C; + x = p - PI3O2_L; + if ((i | ((lx - 0x7f332100) & 0xffffff00)) == 0) { + /* very close to 3/2pi */ + x = p - PI3O2_L0; + return (x - PI3O2_L1); + } + z = x * x; + if (((ix - 0x4012D800) >> 9) == 0) { + /* |x-3/2pi|<2**-8 */ + w = (z * x) * (PP1 + z * PP2) - PI3O2_L; + } else { + w = (z * x) * ((P1 + z * P2) + (z * z) + * (P3 + z * P4)) - PI3O2_L; + } + return (p + w); + } + if (((j - 483) ^ (j - 503)) < 0) { + /* near 5pi/2, cos(5pi/2-x)=sin(x) */ + p = PI5O2_H - x; + i = ix - 0x401F6A7A; + x = p + PI5O2_L; + if ((i | ((lx - 0x29553800) & 0xffffff00)) == 0) { + /* very close to pi/2 */ + x = p + PI5O2_L0; + return (x + PI5O2_L1); + } + z = x * x; + if (((ix - 0x401F6A7A) >> 7) == 0) { + /* |pi/2-x|<2**-8 */ + w = PI5O2_L + (z * x) * (PP1 + z * PP2); + } else { + w = PI5O2_L + (z * x) * ((P1 + z * P2) + + (z * z) * (P3 + z * P4)); + } + return (p + w); + } + j <<= 1; + w = _TBL_sincos[j]; + z = _TBL_sincos[j+1]; + p = v + (v * s) * (PP1 + s * PP2); + q = s * (QQ1 + s * QQ2); + return (z - (w * p - z * q)); + } + + if (ix >= 0x7ff00000) /* cos(Inf or NaN) is NaN */ + return (x / x); + + /* argument reduction needed */ + n = __rem_pio2(x, y); + switch (n & 3) { + case 0: + return (__k_cos(y[0], y[1])); + case 1: + return (-__k_sin(y[0], y[1])); + case 2: + return (-__k_cos(y[0], y[1])); + default: + return (__k_sin(y[0], y[1])); + } +} diff --git a/usr/src/libm/src/C/cosh.c b/usr/src/libm/src/C/cosh.c new file mode 100644 index 0000000..f4d0532 --- /dev/null +++ b/usr/src/libm/src/C/cosh.c @@ -0,0 +1,89 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)cosh.c 1.17 06/01/23 SMI" + +#pragma weak cosh = __cosh + +/* INDENT OFF */ +/* + * cosh(x) + * Code originated from 4.3bsd. + * Modified by K.C. Ng for SUN 4.0 libm. + * Method : + * 1. Replace x by |x| (cosh(x) = cosh(-x)). + * 2. + * [ exp(x) - 1 ]^2 + * 0 <= x <= 0.3465 : cosh(x) := 1 + ------------------- + * 2*exp(x) + * + * exp(x) + 1/exp(x) + * 0.3465 <= x <= 22 : cosh(x) := ------------------- + * 2 + * 22 <= x <= lnovft : cosh(x) := exp(x)/2 + * lnovft <= x < INF : cosh(x) := scalbn(exp(x-1024*ln2),1023) + * + * Note: .3465 is a number near one half of ln2. + * + * Special cases: + * cosh(x) is |x| if x is +INF, -INF, or NaN. + * only cosh(0)=1 is exact for finite x. + */ +/* INDENT ON */ + +#include "libm.h" + +static const double + ln2 = 6.93147180559945286227e-01, + ln2hi = 6.93147180369123816490e-01, + ln2lo = 1.90821492927058770002e-10, + lnovft = 7.09782712893383973096e+02; + +double +cosh(double x) { + double t, w; + + w = fabs(x); + if (!finite(w)) + return (w * w); + if (w < 0.3465) { + t = expm1(w); + w = 1.0 + t; + if (w != 1.0) + w = 1.0 + (t * t) / (w + w); + return (w); + } else if (w < 22.0) { + t = exp(w); + return (0.5 * (t + 1.0 / t)); + } else if (w <= lnovft) { + return (0.5 * exp(w)); + } else { + w = (w - 1024 * ln2hi) - 1024 * ln2lo; + if (w >= ln2) + return (_SVID_libm_err(x, x, 5)); + else + return (scalbn(exp(w), 1023)); + } +} diff --git a/usr/src/libm/src/C/erf.c b/usr/src/libm/src/C/erf.c new file mode 100644 index 0000000..f4c680d --- /dev/null +++ b/usr/src/libm/src/C/erf.c @@ -0,0 +1,435 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)erf.c 1.17 06/01/31 SMI" + +#pragma weak erf = __erf +#pragma weak erfc = __erfc + +/* INDENT OFF */ +/* double erf(double x) + * double erfc(double x) + * x + * 2 |\ + * erf(x) = --------- | exp(-t*t)dt + * sqrt(pi) \| + * 0 + * + * erfc(x) = 1-erf(x) + * Note that + * erf(-x) = -erf(x) + * erfc(-x) = 2 - erfc(x) + * + * Method: + * 1. For |x| in [0, 0.84375] + * erf(x) = x + x*R(x^2) + * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] + * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] + * where R = P/Q where P is an odd poly of degree 8 and + * Q is an odd poly of degree 10. + * -57.90 + * | R - (erf(x)-x)/x | <= 2 + * + * + * Remark. The formula is derived by noting + * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) + * and that + * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 + * is close to one. The interval is chosen because the fix + * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is + * near 0.6174), and by some experiment, 0.84375 is chosen to + * guarantee the error is less than one ulp for erf. + * + * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and + * c = 0.84506291151 rounded to single (24 bits) + * erf(x) = sign(x) * (c + P1(s)/Q1(s)) + * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 + * 1+(c+P1(s)/Q1(s)) if x < 0 + * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06 + * Remark: here we use the taylor series expansion at x=1. + * erf(1+s) = erf(1) + s*Poly(s) + * = 0.845.. + P1(s)/Q1(s) + * That is, we use rational approximation to approximate + * erf(1+s) - (c = (single)0.84506291151) + * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] + * where + * P1(s) = degree 6 poly in s + * Q1(s) = degree 6 poly in s + * + * 3. For x in [1.25,1/0.35(~2.857143)], + * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1) + * erf(x) = 1 - erfc(x) + * where + * R1(z) = degree 7 poly in z, (z=1/x^2) + * S1(z) = degree 8 poly in z + * + * 4. For x in [1/0.35,28] + * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 + * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0 + * = 2.0 - tiny (if x <= -6) + * erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6, else + * erf(x) = sign(x)*(1.0 - tiny) + * where + * R2(z) = degree 6 poly in z, (z=1/x^2) + * S2(z) = degree 7 poly in z + * + * Note1: + * To compute exp(-x*x-0.5625+R/S), let s be a single + * precision number and s := x; then + * -x*x = -s*s + (s-x)*(s+x) + * exp(-x*x-0.5626+R/S) = + * exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S); + * Note2: + * Here 4 and 5 make use of the asymptotic series + * exp(-x*x) + * erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) ) + * x*sqrt(pi) + * We use rational approximation to approximate + * g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625 + * Here is the error bound for R1/S1 and R2/S2 + * |R1/S1 - f(x)| < 2**(-62.57) + * |R2/S2 - f(x)| < 2**(-61.52) + * + * 5. For inf > x >= 28 + * erf(x) = sign(x) *(1 - tiny) (raise inexact) + * erfc(x) = tiny*tiny (raise underflow) if x > 0 + * = 2 - tiny if x<0 + * + * 7. Special case: + * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, + * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, + * erfc/erf(NaN) is NaN + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __erf, __erfc, __exp */ +#include <math.h> + +static const double xxx[] = { +/* tiny */ 1e-300, +/* half */ 5.00000000000000000000e-01, /* 3FE00000, 00000000 */ +/* one */ 1.00000000000000000000e+00, /* 3FF00000, 00000000 */ +/* two */ 2.00000000000000000000e+00, /* 40000000, 00000000 */ +/* erx */ 8.45062911510467529297e-01, /* 3FEB0AC1, 60000000 */ +/* + * Coefficients for approximation to erf on [0,0.84375] + */ +/* efx */ 1.28379167095512586316e-01, /* 3FC06EBA, 8214DB69 */ +/* efx8 */ 1.02703333676410069053e+00, /* 3FF06EBA, 8214DB69 */ +/* pp0 */ 1.28379167095512558561e-01, /* 3FC06EBA, 8214DB68 */ +/* pp1 */ -3.25042107247001499370e-01, /* BFD4CD7D, 691CB913 */ +/* pp2 */ -2.84817495755985104766e-02, /* BF9D2A51, DBD7194F */ +/* pp3 */ -5.77027029648944159157e-03, /* BF77A291, 236668E4 */ +/* pp4 */ -2.37630166566501626084e-05, /* BEF8EAD6, 120016AC */ +/* qq1 */ 3.97917223959155352819e-01, /* 3FD97779, CDDADC09 */ +/* qq2 */ 6.50222499887672944485e-02, /* 3FB0A54C, 5536CEBA */ +/* qq3 */ 5.08130628187576562776e-03, /* 3F74D022, C4D36B0F */ +/* qq4 */ 1.32494738004321644526e-04, /* 3F215DC9, 221C1A10 */ +/* qq5 */ -3.96022827877536812320e-06, /* BED09C43, 42A26120 */ +/* + * Coefficients for approximation to erf in [0.84375,1.25] + */ +/* pa0 */ -2.36211856075265944077e-03, /* BF6359B8, BEF77538 */ +/* pa1 */ 4.14856118683748331666e-01, /* 3FDA8D00, AD92B34D */ +/* pa2 */ -3.72207876035701323847e-01, /* BFD7D240, FBB8C3F1 */ +/* pa3 */ 3.18346619901161753674e-01, /* 3FD45FCA, 805120E4 */ +/* pa4 */ -1.10894694282396677476e-01, /* BFBC6398, 3D3E28EC */ +/* pa5 */ 3.54783043256182359371e-02, /* 3FA22A36, 599795EB */ +/* pa6 */ -2.16637559486879084300e-03, /* BF61BF38, 0A96073F */ +/* qa1 */ 1.06420880400844228286e-01, /* 3FBB3E66, 18EEE323 */ +/* qa2 */ 5.40397917702171048937e-01, /* 3FE14AF0, 92EB6F33 */ +/* qa3 */ 7.18286544141962662868e-02, /* 3FB2635C, D99FE9A7 */ +/* qa4 */ 1.26171219808761642112e-01, /* 3FC02660, E763351F */ +/* qa5 */ 1.36370839120290507362e-02, /* 3F8BEDC2, 6B51DD1C */ +/* qa6 */ 1.19844998467991074170e-02, /* 3F888B54, 5735151D */ +/* + * Coefficients for approximation to erfc in [1.25,1/0.35] + */ +/* ra0 */ -9.86494403484714822705e-03, /* BF843412, 600D6435 */ +/* ra1 */ -6.93858572707181764372e-01, /* BFE63416, E4BA7360 */ +/* ra2 */ -1.05586262253232909814e+01, /* C0251E04, 41B0E726 */ +/* ra3 */ -6.23753324503260060396e+01, /* C04F300A, E4CBA38D */ +/* ra4 */ -1.62396669462573470355e+02, /* C0644CB1, 84282266 */ +/* ra5 */ -1.84605092906711035994e+02, /* C067135C, EBCCABB2 */ +/* ra6 */ -8.12874355063065934246e+01, /* C0545265, 57E4D2F2 */ +/* ra7 */ -9.81432934416914548592e+00, /* C023A0EF, C69AC25C */ +/* sa1 */ 1.96512716674392571292e+01, /* 4033A6B9, BD707687 */ +/* sa2 */ 1.37657754143519042600e+02, /* 4061350C, 526AE721 */ +/* sa3 */ 4.34565877475229228821e+02, /* 407B290D, D58A1A71 */ +/* sa4 */ 6.45387271733267880336e+02, /* 40842B19, 21EC2868 */ +/* sa5 */ 4.29008140027567833386e+02, /* 407AD021, 57700314 */ +/* sa6 */ 1.08635005541779435134e+02, /* 405B28A3, EE48AE2C */ +/* sa7 */ 6.57024977031928170135e+00, /* 401A47EF, 8E484A93 */ +/* sa8 */ -6.04244152148580987438e-02, /* BFAEEFF2, EE749A62 */ +/* + * Coefficients for approximation to erfc in [1/.35,28] + */ +/* rb0 */ -9.86494292470009928597e-03, /* BF843412, 39E86F4A */ +/* rb1 */ -7.99283237680523006574e-01, /* BFE993BA, 70C285DE */ +/* rb2 */ -1.77579549177547519889e+01, /* C031C209, 555F995A */ +/* rb3 */ -1.60636384855821916062e+02, /* C064145D, 43C5ED98 */ +/* rb4 */ -6.37566443368389627722e+02, /* C083EC88, 1375F228 */ +/* rb5 */ -1.02509513161107724954e+03, /* C0900461, 6A2E5992 */ +/* rb6 */ -4.83519191608651397019e+02, /* C07E384E, 9BDC383F */ +/* sb1 */ 3.03380607434824582924e+01, /* 403E568B, 261D5190 */ +/* sb2 */ 3.25792512996573918826e+02, /* 40745CAE, 221B9F0A */ +/* sb3 */ 1.53672958608443695994e+03, /* 409802EB, 189D5118 */ +/* sb4 */ 3.19985821950859553908e+03, /* 40A8FFB7, 688C246A */ +/* sb5 */ 2.55305040643316442583e+03, /* 40A3F219, CEDF3BE6 */ +/* sb6 */ 4.74528541206955367215e+02, /* 407DA874, E79FE763 */ +/* sb7 */ -2.24409524465858183362e+01 /* C03670E2, 42712D62 */ +}; + +#define tiny xxx[0] +#define half xxx[1] +#define one xxx[2] +#define two xxx[3] +#define erx xxx[4] +/* + * Coefficients for approximation to erf on [0,0.84375] + */ +#define efx xxx[5] +#define efx8 xxx[6] +#define pp0 xxx[7] +#define pp1 xxx[8] +#define pp2 xxx[9] +#define pp3 xxx[10] +#define pp4 xxx[11] +#define qq1 xxx[12] +#define qq2 xxx[13] +#define qq3 xxx[14] +#define qq4 xxx[15] +#define qq5 xxx[16] +/* + * Coefficients for approximation to erf in [0.84375,1.25] + */ +#define pa0 xxx[17] +#define pa1 xxx[18] +#define pa2 xxx[19] +#define pa3 xxx[20] +#define pa4 xxx[21] +#define pa5 xxx[22] +#define pa6 xxx[23] +#define qa1 xxx[24] +#define qa2 xxx[25] +#define qa3 xxx[26] +#define qa4 xxx[27] +#define qa5 xxx[28] +#define qa6 xxx[29] +/* + * Coefficients for approximation to erfc in [1.25,1/0.35] + */ +#define ra0 xxx[30] +#define ra1 xxx[31] +#define ra2 xxx[32] +#define ra3 xxx[33] +#define ra4 xxx[34] +#define ra5 xxx[35] +#define ra6 xxx[36] +#define ra7 xxx[37] +#define sa1 xxx[38] +#define sa2 xxx[39] +#define sa3 xxx[40] +#define sa4 xxx[41] +#define sa5 xxx[42] +#define sa6 xxx[43] +#define sa7 xxx[44] +#define sa8 xxx[45] +/* + * Coefficients for approximation to erfc in [1/.35,28] + */ +#define rb0 xxx[46] +#define rb1 xxx[47] +#define rb2 xxx[48] +#define rb3 xxx[49] +#define rb4 xxx[50] +#define rb5 xxx[51] +#define rb6 xxx[52] +#define sb1 xxx[53] +#define sb2 xxx[54] +#define sb3 xxx[55] +#define sb4 xxx[56] +#define sb5 xxx[57] +#define sb6 xxx[58] +#define sb7 xxx[59] + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +erf(double x) { + int hx, ix, i; + double R, S, P, Q, s, y, z, r; + + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix >= 0x7ff00000) { /* erf(nan)=nan */ +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + if (ix >= 0x7ff80000) /* assumes sparc-like QNaN */ + return x; +#endif + i = ((unsigned) hx >> 31) << 1; + return (double) (1 - i) + one / x; /* erf(+-inf)=+-1 */ + } + + if (ix < 0x3feb0000) { /* |x|<0.84375 */ + if (ix < 0x3e300000) { /* |x|<2**-28 */ + if (ix < 0x00800000) /* avoid underflow */ + return 0.125 * (8.0 * x + efx8 * x); + return x + efx * x; + } + z = x * x; + r = pp0 + z * (pp1 + z * (pp2 + z * (pp3 + z * pp4))); + s = one + z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5)))); + y = r / s; + return x + x * y; + } + if (ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */ + s = fabs(x) - one; + P = pa0 + s * (pa1 + s * (pa2 + s * (pa3 + s * (pa4 + + s * (pa5 + s * pa6))))); + Q = one + s * (qa1 + s * (qa2 + s * (qa3 + s * (qa4 + + s * (qa5 + s * qa6))))); + if (hx >= 0) + return erx + P / Q; + else + return -erx - P / Q; + } + if (ix >= 0x40180000) { /* inf > |x| >= 6 */ + if (hx >= 0) + return one - tiny; + else + return tiny - one; + } + x = fabs(x); + s = one / (x * x); + if (ix < 0x4006DB6E) { /* |x| < 1/0.35 */ + R = ra0 + s * (ra1 + s * (ra2 + s * (ra3 + s * (ra4 + + s * (ra5 + s * (ra6 + s * ra7)))))); + S = one + s * (sa1 + s * (sa2 + s * (sa3 + s * (sa4 + + s * (sa5 + s * (sa6 + s * (sa7 + s * sa8))))))); + } + else { /* |x| >= 1/0.35 */ + R = rb0 + s * (rb1 + s * (rb2 + s * (rb3 + s * (rb4 + + s * (rb5 + s * rb6))))); + S = one + s * (sb1 + s * (sb2 + s * (sb3 + s * (sb4 + + s * (sb5 + s * (sb6 + s * sb7)))))); + } + z = x; + ((int *) &z)[LOWORD] = 0; + r = exp(-z * z - 0.5625) * exp((z - x) * (z + x) + R / S); + if (hx >= 0) + return one - r / x; + else + return r / x - one; +} + +double +erfc(double x) { + int hx, ix; + double R, S, P, Q, s, y, z, r; + + hx = ((int *) &x)[HIWORD]; + ix = hx & 0x7fffffff; + if (ix >= 0x7ff00000) { /* erfc(nan)=nan */ +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + if (ix >= 0x7ff80000) /* assumes sparc-like QNaN */ + return x; +#endif + /* erfc(+-inf)=0,2 */ + return (double) (((unsigned) hx >> 31) << 1) + one / x; + } + + if (ix < 0x3feb0000) { /* |x| < 0.84375 */ + if (ix < 0x3c700000) /* |x| < 2**-56 */ + return one - x; + z = x * x; + r = pp0 + z * (pp1 + z * (pp2 + z * (pp3 + z * pp4))); + s = one + z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5)))); + y = r / s; + if (hx < 0x3fd00000) { /* x < 1/4 */ + return one - (x + x * y); + } + else { + r = x * y; + r += (x - half); + return half - r; + } + } + if (ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */ + s = fabs(x) - one; + P = pa0 + s * (pa1 + s * (pa2 + s * (pa3 + s * (pa4 + + s * (pa5 + s * pa6))))); + Q = one + s * (qa1 + s * (qa2 + s * (qa3 + s * (qa4 + + s * (qa5 + s * qa6))))); + if (hx >= 0) { + z = one - erx; + return z - P / Q; + } + else { + z = erx + P / Q; + return one + z; + } + } + if (ix < 0x403c0000) { /* |x|<28 */ + x = fabs(x); + s = one / (x * x); + if (ix < 0x4006DB6D) { /* |x| < 1/.35 ~ 2.857143 */ + R = ra0 + s * (ra1 + s * (ra2 + s * (ra3 + s * (ra4 + + s * (ra5 + s * (ra6 + s * ra7)))))); + S = one + s * (sa1 + s * (sa2 + s * (sa3 + s * (sa4 + + s * (sa5 + s * (sa6 + s * (sa7 + s * sa8))))))); + } + else { /* |x| >= 1/.35 ~ 2.857143 */ + if (hx < 0 && ix >= 0x40180000) + return two - tiny; /* x < -6 */ + R = rb0 + s * (rb1 + s * (rb2 + s * (rb3 + s * (rb4 + + s * (rb5 + s * rb6))))); + S = one + s * (sb1 + s * (sb2 + s * (sb3 + s * (sb4 + + s * (sb5 + s * (sb6 + s * sb7)))))); + } + z = x; + ((int *) &z)[LOWORD] = 0; + r = exp(-z * z - 0.5625) * exp((z - x) * (z + x) + R / S); + if (hx > 0) + return r / x; + else + return two - r / x; + } + else { + if (hx > 0) + return tiny * tiny; + else + return two - tiny; + } +} diff --git a/usr/src/libm/src/C/exp.c b/usr/src/libm/src/C/exp.c new file mode 100644 index 0000000..f090009 --- /dev/null +++ b/usr/src/libm/src/C/exp.c @@ -0,0 +1,356 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)exp.c 1.25 06/01/24 SMI" + +#pragma weak exp = __exp + +/* + * exp(x) + * Hybrid algorithm of Peter Tang's Table driven method (for large + * arguments) and an accurate table (for small arguments). + * Written by K.C. Ng, November 1988. + * Method (large arguments): + * 1. Argument Reduction: given the input x, find r and integer k + * and j such that + * x = (k+j/32)*(ln2) + r, |r| <= (1/64)*ln2 + * + * 2. exp(x) = 2^k * (2^(j/32) + 2^(j/32)*expm1(r)) + * a. expm1(r) is approximated by a polynomial: + * expm1(r) ~ r + t1*r^2 + t2*r^3 + ... + t5*r^6 + * Here t1 = 1/2 exactly. + * b. 2^(j/32) is represented to twice double precision + * as TBL[2j]+TBL[2j+1]. + * + * Note: If divide were fast enough, we could use another approximation + * in 2.a: + * expm1(r) ~ (2r)/(2-R), R = r - r^2*(t1 + t2*r^2) + * (for the same t1 and t2 as above) + * + * Special cases: + * exp(INF) is INF, exp(NaN) is NaN; + * exp(-INF)= 0; + * for finite argument, only exp(0)=1 is exact. + * + * Accuracy: + * According to an error analysis, the error is always less than + * an ulp (unit in the last place). The largest errors observed + * are less than 0.55 ulp for normal results and less than 0.75 ulp + * for subnormal results. + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then exp(x) overflow + * if x < -7.45133219101941108420e+02 then exp(x) underflow + */ + +#include "libm.h" + +static const double TBL[] = { + 1.00000000000000000000e+00, 0.00000000000000000000e+00, + 1.02189714865411662714e+00, 5.10922502897344389359e-17, + 1.04427378242741375480e+00, 8.55188970553796365958e-17, + 1.06714040067682369717e+00, -7.89985396684158212226e-17, + 1.09050773266525768967e+00, -3.04678207981247114697e-17, + 1.11438674259589243221e+00, 1.04102784568455709549e-16, + 1.13878863475669156458e+00, 8.91281267602540777782e-17, + 1.16372485877757747552e+00, 3.82920483692409349872e-17, + 1.18920711500272102690e+00, 3.98201523146564611098e-17, + 1.21524735998046895524e+00, -7.71263069268148813091e-17, + 1.24185781207348400201e+00, 4.65802759183693679123e-17, + 1.26905095719173321989e+00, 2.66793213134218609523e-18, + 1.29683955465100964055e+00, 2.53825027948883149593e-17, + 1.32523664315974132322e+00, -2.85873121003886075697e-17, + 1.35425554693689265129e+00, 7.70094837980298946162e-17, + 1.38390988196383202258e+00, -6.77051165879478628716e-17, + 1.41421356237309514547e+00, -9.66729331345291345105e-17, + 1.44518080697704665027e+00, -3.02375813499398731940e-17, + 1.47682614593949934623e+00, -3.48399455689279579579e-17, + 1.50916442759342284141e+00, -1.01645532775429503911e-16, + 1.54221082540794074411e+00, 7.94983480969762085616e-17, + 1.57598084510788649659e+00, -1.01369164712783039808e-17, + 1.61049033194925428347e+00, 2.47071925697978878522e-17, + 1.64575547815396494578e+00, -1.01256799136747726038e-16, + 1.68179283050742900407e+00, 8.19901002058149652013e-17, + 1.71861929812247793414e+00, -1.85138041826311098821e-17, + 1.75625216037329945351e+00, 2.96014069544887330703e-17, + 1.79470907500310716820e+00, 1.82274584279120867698e-17, + 1.83400808640934243066e+00, 3.28310722424562658722e-17, + 1.87416763411029996256e+00, -6.12276341300414256164e-17, + 1.91520656139714740007e+00, -1.06199460561959626376e-16, + 1.95714412417540017941e+00, 8.96076779103666776760e-17, +}; + +/* + * For i = 0, ..., 66, + * TBL2[2*i] is a double precision number near (i+1)*2^-6, and + * TBL2[2*i+1] = exp(TBL2[2*i]) to within a relative error less + * than 2^-60. + * + * For i = 67, ..., 133, + * TBL2[2*i] is a double precision number near -(i+1)*2^-6, and + * TBL2[2*i+1] = exp(TBL2[2*i]) to within a relative error less + * than 2^-60. + */ +static const double TBL2[] = { + 1.56249999999984491572e-02, 1.01574770858668417262e+00, + 3.12499999999998716305e-02, 1.03174340749910253834e+00, + 4.68750000000011102230e-02, 1.04799100201663386578e+00, + 6.24999999999990632493e-02, 1.06449445891785843266e+00, + 7.81249999999999444888e-02, 1.08125780744903954300e+00, + 9.37500000000013322676e-02, 1.09828514030782731226e+00, + 1.09375000000001346145e-01, 1.11558061464248226002e+00, + 1.24999999999999417133e-01, 1.13314845306682565607e+00, + 1.40624999999995337063e-01, 1.15099294469117108264e+00, + 1.56249999999996141975e-01, 1.16911844616949989195e+00, + 1.71874999999992894573e-01, 1.18752938276309216725e+00, + 1.87500000000000888178e-01, 1.20623024942098178158e+00, + 2.03124999999361649516e-01, 1.22522561187652545556e+00, + 2.18750000000000416334e-01, 1.24452010776609567344e+00, + 2.34375000000003524958e-01, 1.26411844775347081971e+00, + 2.50000000000006328271e-01, 1.28402541668774961003e+00, + 2.65624999999982791543e-01, 1.30424587476761533189e+00, + 2.81249999999993727240e-01, 1.32478475872885725906e+00, + 2.96875000000003275158e-01, 1.34564708304941493822e+00, + 3.12500000000002886580e-01, 1.36683794117380030819e+00, + 3.28124999999993394173e-01, 1.38836250675661765364e+00, + 3.43749999999998612221e-01, 1.41022603492570874906e+00, + 3.59374999999992450483e-01, 1.43243386356506730017e+00, + 3.74999999999991395772e-01, 1.45499141461818881638e+00, + 3.90624999999997613020e-01, 1.47790419541173490003e+00, + 4.06249999999991895372e-01, 1.50117780000011058483e+00, + 4.21874999999996613820e-01, 1.52481791053132154090e+00, + 4.37500000000004607426e-01, 1.54883029863414023453e+00, + 4.53125000000004274359e-01, 1.57322082682725961078e+00, + 4.68750000000008326673e-01, 1.59799544995064657371e+00, + 4.84374999999985456078e-01, 1.62316021661928200359e+00, + 4.99999999999997335465e-01, 1.64872127070012375327e+00, + 5.15625000000000222045e-01, 1.67468485281178436352e+00, + 5.31250000000003441691e-01, 1.70105730184840653330e+00, + 5.46874999999999111822e-01, 1.72784505652716169344e+00, + 5.62499999999999333866e-01, 1.75505465696029738787e+00, + 5.78124999999993338662e-01, 1.78269274625180318417e+00, + 5.93749999999999666933e-01, 1.81076607211938656050e+00, + 6.09375000000003441691e-01, 1.83928148854178719063e+00, + 6.24999999999995559108e-01, 1.86824595743221411048e+00, + 6.40625000000009103829e-01, 1.89766655033813602671e+00, + 6.56249999999993782751e-01, 1.92755045016753268072e+00, + 6.71875000000002109424e-01, 1.95790495294292221651e+00, + 6.87499999999992450483e-01, 1.98873746958227681780e+00, + 7.03125000000004996004e-01, 2.02005552770870666635e+00, + 7.18750000000007105427e-01, 2.05186677348799140219e+00, + 7.34375000000008770762e-01, 2.08417897349558689513e+00, + 7.49999999999983901766e-01, 2.11700001661264058939e+00, + 7.65624999999997002398e-01, 2.15033791595229351046e+00, + 7.81250000000005884182e-01, 2.18420081081563077774e+00, + 7.96874999999991451283e-01, 2.21859696867912603579e+00, + 8.12500000000000000000e-01, 2.25353478721320854561e+00, + 8.28125000000008215650e-01, 2.28902279633221983346e+00, + 8.43749999999997890576e-01, 2.32506966027711614586e+00, + 8.59374999999999444888e-01, 2.36168417973090827289e+00, + 8.75000000000003219647e-01, 2.39887529396710563745e+00, + 8.90625000000013433699e-01, 2.43665208303232461162e+00, + 9.06249999999980571097e-01, 2.47502376996297712708e+00, + 9.21874999999984456878e-01, 2.51399972303748420188e+00, + 9.37500000000001887379e-01, 2.55358945806293169412e+00, + 9.53125000000003330669e-01, 2.59380264069854327147e+00, + 9.68749999999989119814e-01, 2.63464908881560244680e+00, + 9.84374999999997890576e-01, 2.67613877489447116176e+00, + 1.00000000000001154632e+00, 2.71828182845907662113e+00, + 1.01562499999999333866e+00, 2.76108853855008318234e+00, + 1.03124999999995980993e+00, 2.80456935623711389738e+00, + 1.04687499999999933387e+00, 2.84873489717039740654e+00, + -1.56249999999999514277e-02, 9.84496437005408453480e-01, + -3.12499999999955972718e-02, 9.69233234476348348707e-01, + -4.68749999999993824384e-02, 9.54206665969188905230e-01, + -6.24999999999976130205e-02, 9.39413062813478028090e-01, + -7.81249999999989314103e-02, 9.24848813216205822840e-01, + -9.37499999999995975442e-02, 9.10510361380034494161e-01, + -1.09374999999998584466e-01, 8.96394206635151680196e-01, + -1.24999999999998556710e-01, 8.82496902584596676355e-01, + -1.40624999999999361622e-01, 8.68815056262843721235e-01, + -1.56249999999999111822e-01, 8.55345327307423297647e-01, + -1.71874999999924144012e-01, 8.42084427143446223596e-01, + -1.87499999999996752598e-01, 8.29029118180403035154e-01, + -2.03124999999988037347e-01, 8.16176213022349550386e-01, + -2.18749999999995947686e-01, 8.03522573689063990265e-01, + -2.34374999999996419531e-01, 7.91065110850298847112e-01, + -2.49999999999996280753e-01, 7.78800783071407765057e-01, + -2.65624999999999888978e-01, 7.66726596070820165529e-01, + -2.81249999999989397370e-01, 7.54839601989015340777e-01, + -2.96874999999996114219e-01, 7.43136898668761203268e-01, + -3.12499999999999555911e-01, 7.31615628946642115871e-01, + -3.28124999999993782751e-01, 7.20272979955444259126e-01, + -3.43749999999997946087e-01, 7.09106182437399867879e-01, + -3.59374999999994337863e-01, 6.98112510068129799023e-01, + -3.74999999999994615418e-01, 6.87289278790975899369e-01, + -3.90624999999999000799e-01, 6.76633846161729612945e-01, + -4.06249999999947264406e-01, 6.66143610703522903727e-01, + -4.21874999999988453681e-01, 6.55816011271509125002e-01, + -4.37499999999999111822e-01, 6.45648526427892610613e-01, + -4.53124999999999278355e-01, 6.35638673826052436056e-01, + -4.68749999999999278355e-01, 6.25784009604591573428e-01, + -4.84374999999992894573e-01, 6.16082127790682609891e-01, + -4.99999999999998168132e-01, 6.06530659712634534486e-01, + -5.15625000000000000000e-01, 5.97127273421627413619e-01, + -5.31249999999989785948e-01, 5.87869673122352498496e-01, + -5.46874999999972688514e-01, 5.78755598612500032907e-01, + -5.62500000000000000000e-01, 5.69782824730923009859e-01, + -5.78124999999992339461e-01, 5.60949160814475100700e-01, + -5.93749999999948707696e-01, 5.52252450163048691500e-01, + -6.09374999999552580121e-01, 5.43690569513243682209e-01, + -6.24999999999984789945e-01, 5.35261428518998383375e-01, + -6.40624999999983457677e-01, 5.26962969243379708573e-01, + -6.56249999999998334665e-01, 5.18793165653890220312e-01, + -6.71874999999943378626e-01, 5.10750023129039609771e-01, + -6.87499999999997002398e-01, 5.02831577970942467104e-01, + -7.03124999999991118216e-01, 4.95035896926202978463e-01, + -7.18749999999991340260e-01, 4.87361076713623331269e-01, + -7.34374999999985678123e-01, 4.79805243559684402310e-01, + -7.49999999999997335465e-01, 4.72366552741015965911e-01, + -7.65624999999993782751e-01, 4.65043188134059204408e-01, + -7.81249999999863220523e-01, 4.57833361771676883301e-01, + -7.96874999999998112621e-01, 4.50735313406363247157e-01, + -8.12499999999990119015e-01, 4.43747310081084256339e-01, + -8.28124999999996003197e-01, 4.36867645705559026759e-01, + -8.43749999999988120614e-01, 4.30094640640067360504e-01, + -8.59374999999994115818e-01, 4.23426641285265303871e-01, + -8.74999999999977129406e-01, 4.16862019678517936594e-01, + -8.90624999999983346655e-01, 4.10399173096376801428e-01, + -9.06249999999991784350e-01, 4.04036523663345414903e-01, + -9.21874999999994004796e-01, 3.97772517966614058693e-01, + -9.37499999999994337863e-01, 3.91605626676801210628e-01, + -9.53124999999999444888e-01, 3.85534344174578935682e-01, + -9.68749999999986677324e-01, 3.79557188183094640355e-01, + -9.84374999999992339461e-01, 3.73672699406045860648e-01, + -9.99999999999995892175e-01, 3.67879441171443832825e-01, + -1.01562499999994315658e+00, 3.62175999080846300338e-01, + -1.03124999999991096011e+00, 3.56560980663978732697e-01, + -1.04687499999999067413e+00, 3.51033015038813400732e-01, +}; + +static const double C[] = { + 0.5, + 4.61662413084468283841e+01, /* 0x40471547, 0x652b82fe */ + 2.16608493865351192653e-02, /* 0x3f962e42, 0xfee00000 */ + 5.96317165397058656257e-12, /* 0x3d9a39ef, 0x35793c76 */ + 1.6666666666526086527e-1, /* 3fc5555555548f7c */ + 4.1666666666226079285e-2, /* 3fa5555555545d4e */ + 8.3333679843421958056e-3, /* 3f811115b7aa905e */ + 1.3888949086377719040e-3, /* 3f56c1728d739765 */ + 1.0, + 0.0, + 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ + 7.45133219101941108420e+02, /* 0x40874910, 0xD52D3051 */ + 5.55111512312578270212e-17, /* 0x3c900000, 0x00000000 */ +}; + +#define half C[0] +#define invln2_32 C[1] +#define ln2_32hi C[2] +#define ln2_32lo C[3] +#define t2 C[4] +#define t3 C[5] +#define t4 C[6] +#define t5 C[7] +#define one C[8] +#define zero C[9] +#define threshold1 C[10] +#define threshold2 C[11] +#define twom54 C[12] + +double +exp(double x) { + double y, z, t; + int hx, ix, k, j, m; + + ix = ((int *)&x)[HIWORD]; + hx = ix & ~0x80000000; + + if (hx < 0x3ff0a2b2) { /* |x| < 3/2 ln 2 */ + if (hx < 0x3f862e42) { /* |x| < 1/64 ln 2 */ + if (hx < 0x3ed00000) { /* |x| < 2^-18 */ + volatile int dummy; + + dummy = (int)x; /* raise inexact if x != 0 */ +#ifdef lint + dummy = dummy; +#endif + if (hx < 0x3e300000) + return (one + x); + return (one + x * (one + half * x)); + } + t = x * x; + y = x + (t * (half + x * t2) + + (t * t) * (t3 + x * t4 + t * t5)); + return (one + y); + } + + /* find the multiple of 2^-6 nearest x */ + k = hx >> 20; + j = (0x00100000 | (hx & 0x000fffff)) >> (0x40c - k); + j = (j - 1) & ~1; + if (ix < 0) + j += 134; + z = x - TBL2[j]; + t = z * z; + y = z + (t * (half + z * t2) + + (t * t) * (t3 + z * t4 + t * t5)); + return (TBL2[j+1] + TBL2[j+1] * y); + } + + if (hx >= 0x40862e42) { /* x is large, infinite, or nan */ + if (hx >= 0x7ff00000) { + if (ix == 0xfff00000 && ((int *)&x)[LOWORD] == 0) + return (zero); + return (x * x); + } + if (x > threshold1) + return (_SVID_libm_err(x, x, 6)); + if (-x > threshold2) + return (_SVID_libm_err(x, x, 7)); + } + + t = invln2_32 * x; + if (ix < 0) + t -= half; + else + t += half; + k = (int)t; + j = (k & 0x1f) << 1; + m = k >> 5; + z = (x - k * ln2_32hi) - k * ln2_32lo; + + /* z is now in primary range */ + t = z * z; + y = z + (t * (half + z * t2) + (t * t) * (t3 + z * t4 + t * t5)); + y = TBL[j] + (TBL[j+1] + TBL[j] * y); + if (m < -1021) { + ((int *)&y)[HIWORD] += (m + 54) << 20; + return (twom54 * y); + } + ((int *)&y)[HIWORD] += m << 20; + return (y); +} diff --git a/usr/src/libm/src/C/exp10.c b/usr/src/libm/src/C/exp10.c new file mode 100644 index 0000000..e7fecb1 --- /dev/null +++ b/usr/src/libm/src/C/exp10.c @@ -0,0 +1,109 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)exp10.c 1.15 06/01/23 SMI" + +#pragma weak exp10 = __exp10 + +/* INDENT OFF */ +/* + * exp10(x) + * Code by K.C. Ng for SUN 4.0 libm. + * Method : + * n = nint(x*(log10/log2)); + * exp10(x) = 10**x = exp(x*ln(10)) = exp(n*ln2+(x*ln10-n*ln2)) + * = 2**n*exp(ln10*(x-n*log2/log10))) + * If x is an integer < 23 then use repeat multiplication. For + * 10**22 is the largest representable integer. + */ +/* INDENT ON */ + +#include "libm.h" + +static const double C[] = { + 3.3219280948736234787, /* log(10)/log(2) */ + 2.3025850929940456840, /* log(10) */ + 3.0102999565860955045E-1, /* log(2)/log(10) high */ + 5.3716447674669983622E-12, /* log(2)/log(10) low */ + 0.0, + 0.5, + 1.0, + 10.0, + 1.0e300, + 1.0e-300, +}; + +#define lg10 C[0] +#define ln10 C[1] +#define logt2hi C[2] +#define logt2lo C[3] +#define zero C[4] +#define half C[5] +#define one C[6] +#define ten C[7] +#define huge C[8] +#define tiny C[9] + +double +exp10(double x) { + double t, pt; + int ix, hx, k; + + ix = ((int *)&x)[HIWORD]; + hx = ix & ~0x80000000; + + if (hx >= 0x4074a000) { /* |x| >= 330 or x is nan */ + if (hx >= 0x7ff00000) { /* x is inf or nan */ + if (ix == 0xfff00000 && ((int *)&x)[LOWORD] == 0) + return (zero); + return (x * x); + } + t = (ix < 0)? tiny : huge; + return (t * t); + } + + if (hx < 0x3c000000) + return (one + x); + + k = (int)x; + if (0 <= k && k < 23 && (double)k == x) { + /* x is a small positive integer */ + t = one; + pt = ten; + if (k & 1) + t = ten; + k >>= 1; + while (k) { + pt *= pt; + if (k & 1) + t *= pt; + k >>= 1; + } + return (t); + } + t = x * lg10; + k = (int)((ix < 0)? t - half : t + half); + return (scalbn(exp(ln10 * ((x - k * logt2hi) - k * logt2lo)), k)); +} diff --git a/usr/src/libm/src/C/exp2.c b/usr/src/libm/src/C/exp2.c new file mode 100644 index 0000000..b85dbf6 --- /dev/null +++ b/usr/src/libm/src/C/exp2.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)exp2.c 1.17 06/01/23 SMI" + +#pragma weak exp2 = __exp2 + +/* INDENT OFF */ +/* + * exp2(x) + * Code by K.C. Ng for SUN 4.0 libm. + * Method : + * exp2(x) = 2**x = 2**((x-anint(x))+anint(x)) + * = 2**anint(x)*2**(x-anint(x)) + * = 2**anint(x)*exp((x-anint(x))*ln2) + */ +/* INDENT ON */ + +#include "libm.h" + +static const double C[] = { + 0.0, + 1.0, + 0.5, + 6.93147180559945286227e-01, + 1.0e300, + 1.0e-300, +}; + +#define zero C[0] +#define one C[1] +#define half C[2] +#define ln2 C[3] +#define huge C[4] +#define tiny C[5] + +double +exp2(double x) { + int ix, hx, k; + double t; + + ix = ((int *)&x)[HIWORD]; + hx = ix & ~0x80000000; + + if (hx >= 0x4090e000) { /* |x| >= 1080 or x is nan */ + if (hx >= 0x7ff00000) { /* x is inf or nan */ + if (ix == 0xfff00000 && ((int *)&x)[LOWORD] == 0) + return (zero); + return (x * x); + } + t = (ix < 0)? tiny : huge; + return (t * t); + } + + if (hx < 0x3fe00000) { /* |x| < 0.5 */ + if (hx < 0x3c000000) + return (one + x); + return (exp(ln2 * x)); + } + + k = (int)x; + if (x != (double)k) + k = (int)((ix < 0)? x - half : x + half); + return (scalbn(exp(ln2 * (x - (double)k)), k)); +} diff --git a/usr/src/libm/src/C/expm1.c b/usr/src/libm/src/C/expm1.c new file mode 100644 index 0000000..f8daddb --- /dev/null +++ b/usr/src/libm/src/C/expm1.c @@ -0,0 +1,270 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)expm1.c 2.5 06/01/31 SMI" + +#pragma weak expm1 = __expm1 + +/* INDENT OFF */ +/* expm1(x) + * Returns exp(x)-1, the exponential of x minus 1. + * + * Method + * 1. Arugment reduction: + * Given x, find r and integer k such that + * + * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 + * + * Here a correction term c will be computed to compensate + * the error in r when rounded to a floating-point number. + * + * 2. Approximating expm1(r) by a special rational function on + * the interval [0,0.34658]: + * Since + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... + * we define R1(r*r) by + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) + * That is, + * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) + * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) + * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... + * We use a special Reme algorithm on [0,0.347] to generate + * a polynomial of degree 5 in r*r to approximate R1. The + * maximum error of this polynomial approximation is bounded + * by 2**-61. In other words, + * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 + * where Q1 = -1.6666666666666567384E-2, + * Q2 = 3.9682539681370365873E-4, + * Q3 = -9.9206344733435987357E-6, + * Q4 = 2.5051361420808517002E-7, + * Q5 = -6.2843505682382617102E-9; + * (where z=r*r, and the values of Q1 to Q5 are listed below) + * with error bounded by + * | 5 | -61 + * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 + * | | + * + * expm1(r) = exp(r)-1 is then computed by the following + * specific way which minimize the accumulation rounding error: + * 2 3 + * r r [ 3 - (R1 + R1*r/2) ] + * expm1(r) = r + --- + --- * [--------------------] + * 2 2 [ 6 - r*(3 - R1*r/2) ] + * + * To compensate the error in the argument reduction, we use + * expm1(r+c) = expm1(r) + c + expm1(r)*c + * ~ expm1(r) + c + r*c + * Thus c+r*c will be added in as the correction terms for + * expm1(r+c). Now rearrange the term to avoid optimization + * screw up: + * ( 2 2 ) + * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) + * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) + * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) + * ( ) + * + * = r - E + * 3. Scale back to obtain expm1(x): + * From step 1, we have + * expm1(x) = either 2^k*[expm1(r)+1] - 1 + * = or 2^k*[expm1(r) + (1-2^-k)] + * 4. Implementation notes: + * (A). To save one multiplication, we scale the coefficient Qi + * to Qi*2^i, and replace z by (x^2)/2. + * (B). To achieve maximum accuracy, we compute expm1(x) by + * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) + * (ii) if k=0, return r-E + * (iii) if k=-1, return 0.5*(r-E)-0.5 + * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) + * else return 1.0+2.0*(r-E); + * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) + * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else + * (vii) return 2^k(1-((E+2^-k)-r)) + * + * Special cases: + * expm1(INF) is INF, expm1(NaN) is NaN; + * expm1(-INF) is -1, and + * for finite argument, only expm1(0)=0 is exact. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then expm1(x) overflow + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ +/* INDENT ON */ + +#include "libm_synonyms.h" /* __expm1 */ +#include <math.h> + +static const double xxx[] = { +/* one */ 1.0, +/* huge */ 1.0e+300, +/* tiny */ 1.0e-300, +/* o_threshold */ 7.09782712893383973096e+02, /* 40862E42 FEFA39EF */ +/* ln2_hi */ 6.93147180369123816490e-01, /* 3FE62E42 FEE00000 */ +/* ln2_lo */ 1.90821492927058770002e-10, /* 3DEA39EF 35793C76 */ +/* invln2 */ 1.44269504088896338700e+00, /* 3FF71547 652B82FE */ +/* scaled coefficients related to expm1 */ +/* Q1 */ -3.33333333333331316428e-02, /* BFA11111 111110F4 */ +/* Q2 */ 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ +/* Q3 */ -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ +/* Q4 */ 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ +/* Q5 */ -2.01099218183624371326e-07 /* BE8AFDB7 6E09C32D */ +}; +#define one xxx[0] +#define huge xxx[1] +#define tiny xxx[2] +#define o_threshold xxx[3] +#define ln2_hi xxx[4] +#define ln2_lo xxx[5] +#define invln2 xxx[6] +#define Q1 xxx[7] +#define Q2 xxx[8] +#define Q3 xxx[9] +#define Q4 xxx[10] +#define Q5 xxx[11] + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +expm1(double x) { + double y, hi, lo, c, t, e, hxs, hfx, r1; + int k, xsb; + unsigned hx; + + hx = ((unsigned *) &x)[HIWORD]; /* high word of x */ + xsb = hx & 0x80000000; /* sign bit of x */ + if (xsb == 0) + y = x; + else + y = -x; /* y = |x| */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out huge and non-finite arugment */ + if (hx >= 0x4043687A) { /* if |x|>=56*ln2 */ + if (hx >= 0x40862E42) { /* if |x|>=709.78... */ + if (hx >= 0x7ff00000) { + if (((hx & 0xfffff) | ((int *) &x)[LOWORD]) + != 0) + return x * x; /* + -> * for Cheetah */ + else + return xsb == 0 ? x : -1.0; /* exp(+-inf)={inf,-1} */ + } + if (x > o_threshold) + return huge * huge; /* overflow */ + } + if (xsb != 0) { /* x < -56*ln2, return -1.0 w/inexact */ + if (x + tiny < 0.0) /* raise inexact */ + return tiny - one; /* return -1 */ + } + } + + /* argument reduction */ + if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + if (xsb == 0) { + hi = x - ln2_hi; + lo = ln2_lo; + k = 1; + } + else { + hi = x + ln2_hi; + lo = -ln2_lo; + k = -1; + } + } + else { + k = (int) (invln2 * x + (xsb == 0 ? 0.5 : -0.5)); + t = k; + hi = x - t * ln2_hi; /* t*ln2_hi is exact here */ + lo = t * ln2_lo; + } + x = hi - lo; + c = (hi - x) - lo; + } + else if (hx < 0x3c900000) { /* when |x|<2**-54, return x */ + t = huge + x; /* return x w/inexact when x != 0 */ + return x - (t - (huge + x)); + } + else + k = 0; + + /* x is now in primary range */ + hfx = 0.5 * x; + hxs = x * hfx; + r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5)))); + t = 3.0 - r1 * hfx; + e = hxs * ((r1 - t) / (6.0 - x * t)); + if (k == 0) + return x - (x * e - hxs); /* c is 0 */ + else { + e = (x * (e - c) - c); + e -= hxs; + if (k == -1) + return 0.5 * (x - e) - 0.5; + if (k == 1) + if (x < -0.25) + return -2.0 * (e - (x + 0.5)); + else + return one + 2.0 * (x - e); + if (k <= -2 || k > 56) { /* suffice to return exp(x)-1 */ + y = one - (e - x); + ((int *) &y)[HIWORD] += k << 20; + return y - one; + } + t = one; + if (k < 20) { + ((int *) &t)[HIWORD] = 0x3ff00000 - (0x200000 >> k); + /* t = 1 - 2^-k */ + y = t - (e - x); + ((int *) &y)[HIWORD] += k << 20; + } + else { + ((int *) &t)[HIWORD] = (0x3ff - k) << 20; /* 2^-k */ + y = x - (e + t); + y += one; + ((int *) &y)[HIWORD] += k << 20; + } + } + return y; +} diff --git a/usr/src/libm/src/C/fabs.c b/usr/src/libm/src/C/fabs.c new file mode 100644 index 0000000..1c8f733 --- /dev/null +++ b/usr/src/libm/src/C/fabs.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)fabs.c 1.13 06/01/31 SMI" + +#pragma weak fabs = __fabs + +#include "libm.h" +#include "libm_synonyms.h" +#include <math.h> + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +double +fabs(double x) { + int *px = (int *) &x; + + px[HIWORD] &= ~0x80000000; + return x; +} diff --git a/usr/src/libm/src/C/floor.c b/usr/src/libm/src/C/floor.c new file mode 100644 index 0000000..b5a84e7 --- /dev/null +++ b/usr/src/libm/src/C/floor.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)floor.c 1.10 06/01/23 SMI" + +#pragma weak floor = __floor + +/* + * floor(x) returns the biggest integral value less than or equal to x. + * NOTE: floor(x) returns result with the same sign as x's, including 0. + * + * Modified 8/4/04 for performance. + */ + +#include "libm.h" + +static const double + zero = 0.0, + one = 1.0, + two52 = 4503599627370496.0; + +double +floor(double x) { + double t, w; + int hx, lx, ix; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + ix = hx & ~0x80000000; + if (ix >= 0x43300000) /* return x if |x| >= 2^52, or x is NaN */ + return (x * one); + t = (hx >= 0)? two52 : -two52; + w = x + t; + t = w - t; + if (ix < 0x3ff00000) { + if ((ix | lx) == 0) + return (x); + else + return ((hx < 0)? -one : zero); + } + return ((t <= x)? t : t - one); +} diff --git a/usr/src/libm/src/C/fmod.c b/usr/src/libm/src/C/fmod.c new file mode 100644 index 0000000..20c8702 --- /dev/null +++ b/usr/src/libm/src/C/fmod.c @@ -0,0 +1,126 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)fmod.c 1.20 06/01/24 SMI" + +#pragma weak fmod = __fmod + +#include "libm.h" + +static const double zero = 0.0; + +/* + * The following implementation assumes fast 64-bit integer arith- + * metic. This is fine for sparc because we build libm in v8plus + * mode. It's also fine for sparcv9 and amd64, although we have + * assembly code on amd64. For x86, it would be better to use + * 32-bit code, but we have assembly for x86, too. + */ +double +fmod(double x, double y) { + double w; + long long hx, ix, iy, iz; + int nd, k, ny; + + hx = *(long long *)&x; + ix = hx & ~0x8000000000000000ull; + iy = *(long long *)&y & ~0x8000000000000000ull; + + /* handle special cases */ + if (iy == 0ll) + return (_SVID_libm_err(x, y, 27)); + + if (ix >= 0x7ff0000000000000ll || iy > 0x7ff0000000000000ll) + return ((x * y) * zero); + + if (ix <= iy) + return ((ix < iy)? x : x * zero); + + /* + * Set: + * ny = true exponent of y + * nd = true exponent of x minus true exponent of y + * ix = normalized significand of x + * iy = normalized significand of y + */ + ny = iy >> 52; + k = ix >> 52; + if (ny == 0) { + /* y is subnormal, x could be normal or subnormal */ + ny = 1; + while (iy < 0x0010000000000000ll) { + ny -= 1; + iy += iy; + } + nd = k - ny; + if (k == 0) { + nd += 1; + while (ix < 0x0010000000000000ll) { + nd -= 1; + ix += ix; + } + } else { + ix = 0x0010000000000000ll | (ix & 0x000fffffffffffffll); + } + } else { + /* both x and y are normal */ + nd = k - ny; + ix = 0x0010000000000000ll | (ix & 0x000fffffffffffffll); + iy = 0x0010000000000000ll | (iy & 0x000fffffffffffffll); + } + + /* perform fixed point mod */ + while (nd--) { + iz = ix - iy; + if (iz >= 0) + ix = iz; + ix += ix; + } + iz = ix - iy; + if (iz >= 0) + ix = iz; + + /* convert back to floating point and restore the sign */ + if (ix == 0ll) + return (x * zero); + while (ix < 0x0010000000000000ll) { + ix += ix; + ny -= 1; + } + while (ix > 0x0020000000000000ll) { /* XXX can this ever happen? */ + ny += 1; + ix >>= 1; + } + if (ny <= 0) { + /* result is subnormal */ + k = -ny + 1; + ix >>= k; + *(long long *)&w = (hx & 0x8000000000000000ull) | ix; + return (w); + } + *(long long *)&w = (hx & 0x8000000000000000ull) | + ((long long)ny << 52) | (ix & 0x000fffffffffffffll); + return (w); +} diff --git a/usr/src/libm/src/C/gamma.c b/usr/src/libm/src/C/gamma.c new file mode 100644 index 0000000..b2a8b05 --- /dev/null +++ b/usr/src/libm/src/C/gamma.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)gamma.c 1.7 06/01/23 SMI" + +#pragma weak gamma = __gamma + +#include "libm.h" + +extern int signgam; + +double +gamma(double x) { + double g; + + if (!finite(x)) + return (x * x); + + g = rint(x); + if (x == g && x <= 0.0) { + signgam = 1; + return (_SVID_libm_err(x, x, 41)); + } + + g = __k_lgamma(x, &signgam); + if (!finite(g)) + g = _SVID_libm_err(x, x, 40); + return (g); +} diff --git a/usr/src/libm/src/C/gamma_r.c b/usr/src/libm/src/C/gamma_r.c new file mode 100644 index 0000000..c648635 --- /dev/null +++ b/usr/src/libm/src/C/gamma_r.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)gamma_r.c 1.6 06/01/23 SMI" + +#pragma weak gamma_r = __gamma_r + +#include "libm.h" + +double +gamma_r(double x, int *signgamp) { + return (lgamma_r(x, signgamp)); +} diff --git a/usr/src/libm/src/C/hypot.c b/usr/src/libm/src/C/hypot.c new file mode 100644 index 0000000..4f99512 --- /dev/null +++ b/usr/src/libm/src/C/hypot.c @@ -0,0 +1,211 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)hypot.c 1.31 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak hypot = __hypot +#endif + +/* INDENT OFF */ +/* + * Hypot(x, y) + * by K.C. Ng for SUN 4.0 libm, updated 3/11/2003. + * Method : + * A. When rounding is rounded-to-nearest: + * If z = x * x + y * y has error less than sqrt(2) / 2 ulp than + * sqrt(z) has error less than 1 ulp. + * So, compute sqrt(x*x+y*y) with some care as follows: + * Assume x > y > 0; + * 1. Check whether save and set rounding to round-to-nearest + * 2. if x > 2y use + * xh*xh+(y*y+((x-xh)*(x+xh))) for x*x+y*y + * where xh = x with lower 32 bits cleared; else + * 3. if x <= 2y use + * x2h*yh+((x-y)*(x-y)+(x2h*(y-yh)+(x2-x2h)*y)) + * where x2 = 2*x, x2h = 2x with lower 32 bits cleared, yh = y with + * lower 32 bits chopped. + * + * B. When rounding is not rounded-to-nearest: + * The following (magic) formula will yield an error less than 1 ulp. + * z = sqrt(x * x + y * y) + * hypot(x, y) = x + (y / ((x + z) / y)) + * + * NOTE: DO NOT remove parenthsis! + * + * Special cases: + * hypot(x, y) is INF if x or y is +INF or -INF; else + * hypot(x, y) is NAN if x or y is NAN. + * + * Accuracy: + * hypot(x, y) returns sqrt(x^2+y^2) with error less than 1 ulps + * (units in the last place) + */ + +#include "libm.h" + +static const double + zero = 0.0, + onep1u = 1.00000000000000022204e+00, /* 0x3ff00000 1 = 1+2**-52 */ + twom53 = 1.11022302462515654042e-16, /* 0x3ca00000 0 = 2**-53 */ + twom768 = 6.441148769597133308e-232, /* 2^-768 */ + two768 = 1.552518092300708935e+231; /* 2^768 */ + +/* INDENT ON */ + +double +hypot(double x, double y) { + double xh, yh, w, ax, ay; + int i, j, nx, ny, ix, iy, iscale = 0; + unsigned lx, ly; + + ix = ((int *) &x)[HIWORD] & ~0x80000000; + lx = ((int *) &x)[LOWORD]; + iy = ((int *) &y)[HIWORD] & ~0x80000000; + ly = ((int *) &y)[LOWORD]; +/* + * Force ax = |x| ~>~ ay = |y| + */ + if (iy > ix) { + ax = fabs(y); + ay = fabs(x); + i = ix; + ix = iy; + iy = i; + i = lx; + lx = ly; + ly = i; + } else { + ax = fabs(x); + ay = fabs(y); + } + nx = ix >> 20; + ny = iy >> 20; + j = nx - ny; +/* + * x >= 2^500 (x*x or y*y may overflow) + */ + if (nx >= 0x5f3) { + if (nx == 0x7ff) { /* inf or NaN, signal of sNaN */ + if (((ix - 0x7ff00000) | lx) == 0) + return (ax == ay ? ay : ax); + else if (((iy - 0x7ff00000) | ly) == 0) + return (ay == ax ? ax : ay); + else + return (ax * ay); /* + -> * for Cheetah */ + } else if (j > 32) { /* x >> y */ + if (j <= 53) + ay *= twom53; + ax += ay; + if (((int *) &ax)[HIWORD] == 0x7ff00000) + ax = _SVID_libm_err(x, y, 4); + return (ax); + } + ax *= twom768; + ay *= twom768; + iscale = 2; + ix -= 768 << 20; + iy -= 768 << 20; + } +/* + * y < 2^-450 (x*x or y*y may underflow) + */ + else if (ny < 0x23d) { + if ((ix | lx) == 0) + return (ay); + if ((iy | ly) == 0) + return (ax); + if (j > 53) /* x >> y */ + return (ax + ay); + iscale = 1; + ax *= two768; + ay *= two768; + if (nx == 0) { + if (ax == zero) /* guard subnormal flush to zero */ + return (ax); + ix = ((int *) &ax)[HIWORD]; + } else + ix += 768 << 20; + if (ny == 0) { + if (ay == zero) /* guard subnormal flush to zero */ + return (ax * twom768); + iy = ((int *) &ay)[HIWORD]; + } else + iy += 768 << 20; + j = (ix >> 20) - (iy >> 20); + if (j > 32) { /* x >> y */ + if (j <= 53) + ay *= twom53; + return ((ax + ay) * twom768); + } + } else if (j > 32) { /* x >> y */ + if (j <= 53) + ay *= twom53; + return (ax + ay); + } +/* + * Medium range ax and ay with max{|ax/ay|,|ay/ax|} bounded by 2^32 + * First check rounding mode by comparing onep1u*onep1u with onep1u+twom53. + * Make sure the computation is done at run-time. + */ + if (((lx | ly) << 5) == 0) { + ay = ay * ay; + ax += ay / (ax + sqrt(ax * ax + ay)); + } else + if (onep1u * onep1u != onep1u + twom53) { + /* round-to-zero, positive, negative mode */ + /* magic formula with less than an ulp error */ + w = sqrt(ax * ax + ay * ay); + ax += ay / ((ax + w) / ay); + } else { + /* round-to-nearest mode */ + w = ax - ay; + if (w > ay) { + ((int *) &xh)[HIWORD] = ix; + ((int *) &xh)[LOWORD] = 0; + ay = ay * ay + (ax - xh) * (ax + xh); + ax = sqrt(xh * xh + ay); + } else { + ax = ax + ax; + ((int *) &xh)[HIWORD] = ix + 0x00100000; + ((int *) &xh)[LOWORD] = 0; + ((int *) &yh)[HIWORD] = iy; + ((int *) &yh)[LOWORD] = 0; + ay = w * w + ((ax - xh) * yh + (ay - yh) * ax); + ax = sqrt(xh * yh + ay); + } + } + if (iscale > 0) { + if (iscale == 1) + ax *= twom768; + else { + ax *= two768; /* must generate side effect here */ + if (((int *) &ax)[HIWORD] == 0x7ff00000) + ax = _SVID_libm_err(x, y, 4); + } + } + return (ax); +} diff --git a/usr/src/libm/src/C/ilogb.c b/usr/src/libm/src/C/ilogb.c new file mode 100644 index 0000000..00818bc --- /dev/null +++ b/usr/src/libm/src/C/ilogb.c @@ -0,0 +1,93 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)ilogb.c 1.34 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak ilogb = __ilogb +#endif + +#include "libm.h" +#include "xpg6.h" /* __xpg6 */ + +#if defined(USE_FPSCALE) || defined(__i386) +static const double two52 = 4503599627370496.0; +#else +/* + * v: high part of a non-zero subnormal |x|; w: low part of |x| + */ +static int +ilogb_subnormal(unsigned v, unsigned w) { + int r = -1022 - 52; + + if (v) + r += 32; + else + v = w; + if (v & 0xffff0000) + r += 16, v >>= 16; + if (v & 0xff00) + r += 8, v >>= 8; + if (v & 0xf0) + r += 4, v >>= 4; + v <<= 1; + return (r + ((0xffffaa50 >> v) & 0x3)); +} +#endif /* defined(USE_FPSCALE) */ + +static int +raise_invalid(int v) { /* SUSv3 requires ilogb(0,+/-Inf,NaN) raise invalid */ +#ifndef lint + if ((__xpg6 & _C99SUSv3_ilogb_0InfNaN_raises_invalid) != 0) { + static const double zero = 0.0; + volatile double dummy; + + dummy = zero / zero; + } +#endif + return (v); +} + +int +ilogb(double x) { + int *px = (int *) &x, k = px[HIWORD] & ~0x80000000; + + if (k < 0x00100000) { + if ((px[LOWORD] | k) == 0) + return (raise_invalid(0x80000001)); + else { +#if defined(USE_FPSCALE) || defined(__i386) + x *= two52; + return (((px[HIWORD] & 0x7ff00000) >> 20) - 1075); +#else + return (ilogb_subnormal(k, px[LOWORD])); +#endif + } + } else if (k < 0x7ff00000) + return ((k >> 20) - 1023); + else + return (raise_invalid(0x7fffffff)); +} diff --git a/usr/src/libm/src/C/isnan.c b/usr/src/libm/src/C/isnan.c new file mode 100644 index 0000000..3d3954d --- /dev/null +++ b/usr/src/libm/src/C/isnan.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)isnan.c 1.10 06/01/25 SMI" + +#pragma weak isnan = __isnan +#pragma weak _isnan = __isnan +#pragma weak _isnand = __isnan +#pragma weak isnand = __isnan + +#include "libm.h" + +/* + * The following implementation assumes fast 64-bit integer arith- + * metic. This is fine for sparc because we build libm in v8plus + * mode. It's also fine for sparcv9 and amd64. For x86, it would + * be better to use 32-bit code, but we have assembly for x86. + */ +int +__isnan(double x) { + long long llx; + + llx = *(long long *)&x & ~0x8000000000000000ull; + return ((unsigned long long)(0x7ff0000000000000ll - llx) >> 63); +} diff --git a/usr/src/libm/src/C/j0.c b/usr/src/libm/src/C/j0.c new file mode 100644 index 0000000..f1f34bf --- /dev/null +++ b/usr/src/libm/src/C/j0.c @@ -0,0 +1,311 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)j0.c 1.15 06/01/31 SMI" + +/* + * Floating point Bessel's function of the first and second kinds + * of order zero: j0(x),y0(x); + * + * Special cases: + * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; + * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. + */ + +#pragma weak j0 = __j0 +#pragma weak y0 = __y0 + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> +#include <values.h> + +#define GENERIC double +static const GENERIC +zero = 0.0, +small = 1.0e-5, +tiny = 1.0e-18, +one = 1.0, +eight = 8.0, +invsqrtpi= 5.641895835477562869480794515607725858441e-0001, +tpi = 0.636619772367581343075535053490057448; + +static GENERIC pzero(GENERIC), qzero(GENERIC); +static const GENERIC r0[4] = { /* [1.e-5, 1.28] */ + -2.500000000000003622131880894830476755537e-0001, + 1.095597547334830263234433855932375353303e-0002, + -1.819734750463320921799187258987098087697e-0004, + 9.977001946806131657544212501069893930846e-0007, +}; +static const GENERIC s0[4] = { /* [1.e-5, 1.28] */ + 1.0, + 1.867609810662950169966782360588199673741e-0002, + 1.590389206181565490878430827706972074208e-0004, + 6.520867386742583632375520147714499522721e-0007, +}; +static const GENERIC r1[9] = { /* [1.28,8] */ + 9.999999999999999942156495584397047660949e-0001, + -2.389887722731319130476839836908143731281e-0001, + 1.293359476138939027791270393439493640570e-0002, + -2.770985642343140122168852400228563364082e-0004, + 2.905241575772067678086738389169625218912e-0006, + -1.636846356264052597969042009265043251279e-0008, + 5.072306160724884775085431059052611737827e-0011, + -8.187060730684066824228914775146536139112e-0014, + 5.422219326959949863954297860723723423842e-0017, +}; +static const GENERIC s1[9] = { /* [1.28,8] */ + 1.0, + 1.101122772686807702762104741932076228349e-0002, + 6.140169310641649223411427764669143978228e-0005, + 2.292035877515152097976946119293215705250e-0007, + 6.356910426504644334558832036362219583789e-0010, + 1.366626326900219555045096999553948891401e-0012, + 2.280399586866739522891837985560481180088e-0015, + 2.801559820648939665270492520004836611187e-0018, + 2.073101088320349159764410261466350732968e-0021, +}; + +GENERIC +j0(GENERIC x) { + GENERIC z, s,c,ss,cc,r,u,v,ox; + int i; + + if(isnan(x)) return x*x; /* + -> * for Cheetah */ + ox= x; + x = fabs(x); + if(x > 8.0){ + if(!finite(x)) return zero; + s = sin(x); + c = cos(x); + /* j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0)) + * where x0 = x-pi/4 + * Better formula: + * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) + * = 1/sqrt(2) * (cos(x) + sin(x)) + * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4) + * = 1/sqrt(2) * (sin(x) - cos(x)) + * To avoid cancellation, use + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) + * to compute the worse one. + */ + if(x>8.9e307) { /* x+x may overflow */ + ss = s-c; + cc = s+c; + } else if(signbit(s)!=signbit(c)) { + ss = s - c; + cc = -cos(x+x)/ss; + } else { + cc = s + c; + ss = -cos(x+x)/cc; + } + /* + * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) + * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) + */ + if(x>1.0e40) z= (invsqrtpi*cc)/sqrt(x); + else { + u = pzero(x); v = qzero(x); + z = invsqrtpi*(u*cc-v*ss)/sqrt(x); + } + /* force to pass SVR4 even the result is wrong (sign) */ + if (x > X_TLOSS) + return _SVID_libm_err(ox,z,34); + else + return z; + } + if(x<=small) { + if(x<=tiny) return one-x; + else return one-x*x*0.25; + } + z = x*x; + if(x<=1.28) { + r = r0[0]+z*(r0[1]+z*(r0[2]+z*r0[3])); + s = s0[0]+z*(s0[1]+z*(s0[2]+z*s0[3])); + return one + z*(r/s); + } else { + for(r=r1[8],s=s1[8],i=7;i>=0;i--) { + r = r*z + r1[i]; + s = s*z + s1[i]; + } + return(r/s); + } +} + +static const GENERIC u0[13] = { + -7.380429510868722526754723020704317641941e-0002, + 1.772607102684869924301459663049874294814e-0001, + -1.524370666542713828604078090970799356306e-0002, + 4.650819100693891757143771557629924591915e-0004, + -7.125768872339528975036316108718239946022e-0006, + 6.411017001656104598327565004771515257146e-0008, + -3.694275157433032553021246812379258781665e-0010, + 1.434364544206266624252820889648445263842e-0012, + -3.852064731859936455895036286874139896861e-0015, + 7.182052899726138381739945881914874579696e-0018, + -9.060556574619677567323741194079797987200e-0021, + 7.124435467408860515265552217131230511455e-0024, + -2.709726774636397615328813121715432044771e-0027, +}; +static const GENERIC v0[5] = { + 1.0, + 4.678678931512549002587702477349214886475e-0003, + 9.486828955529948534822800829497565178985e-0006, + 1.001495929158861646659010844136682454906e-0008, + 4.725338116256021660204443235685358593611e-0012, +}; + +GENERIC +y0(GENERIC x) { + GENERIC z, /* d, */ s,c,ss,cc,u,v; + int i; + + if(isnan(x)) return x*x; /* + -> * for Cheetah */ + if(x <= zero){ + if(x==zero) + /* d= -one/(x-x); */ + return _SVID_libm_err(x,x,8); + else + /* d = zero/(x-x); */ + return _SVID_libm_err(x,x,9); + } + if(x > 8.0){ + if(!finite(x)) return zero; + s = sin(x); + c = cos(x); + /* j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0)) + * where x0 = x-pi/4 + * Better formula: + * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) + * = 1/sqrt(2) * (cos(x) + sin(x)) + * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4) + * = 1/sqrt(2) * (sin(x) - cos(x)) + * To avoid cancellation, use + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) + * to compute the worse one. + */ + if(x>8.9e307) { /* x+x may overflow */ + ss = s-c; + cc = s+c; + } else if(signbit(s)!=signbit(c)) { + ss = s - c; + cc = -cos(x+x)/ss; + } else { + cc = s + c; + ss = -cos(x+x)/cc; + } + /* + * j0(x) = 1/sqrt(pi*x) * (P(0,x)*cc - Q(0,x)*ss) + * y0(x) = 1/sqrt(pi*x) * (P(0,x)*ss + Q(0,x)*cc) + */ + if(x>1.0e40) + z = (invsqrtpi*ss)/sqrt(x); + else + z = invsqrtpi*(pzero(x)*ss+qzero(x)*cc)/sqrt(x); + if (x > X_TLOSS) + return _SVID_libm_err(x,z,35); + else + return z; + + } + if(x<=tiny) { + return(u0[0] + tpi*log(x)); + } + z = x*x; + for(u=u0[12],i=11;i>=0;i--) u = u*z + u0[i]; + v = v0[0]+z*(v0[1]+z*(v0[2]+z*(v0[3]+z*v0[4]))); + return(u/v + tpi*(j0(x)*log(x))); +} + +static const GENERIC pr[7] = { /* [8 -- inf] pzero 6550 */ + .4861344183386052721391238447e5, + .1377662549407112278133438945e6, + .1222466364088289731869114004e6, + .4107070084315176135583353374e5, + .5026073801860637125889039915e4, + .1783193659125479654541542419e3, + .88010344055383421691677564e0, +}; +static const GENERIC ps[7] = { /* [8 -- inf] pzero 6550 */ + .4861344183386052721414037058e5, + .1378196632630384670477582699e6, + .1223967185341006542748936787e6, + .4120150243795353639995862617e5, + .5068271181053546392490184353e4, + .1829817905472769960535671664e3, + 1.0, +}; +static const GENERIC huge = 1.0e10; + +static GENERIC +pzero(GENERIC x) { + GENERIC s,r,t,z; + int i; + if(x>huge) return one; + t = eight/x; z = t*t; + r = pr[5]+z*pr[6]; + s = ps[5]+z; + for(i=4;i>=0;i--) { + r = r*z + pr[i]; + s = s*z + ps[i]; + } + return r/s; +} + +static const GENERIC qr[7] = { /* [8 -- inf] qzero 6950 */ + -.1731210995701068539185611951e3, + -.5522559165936166961235240613e3, + -.5604935606637346590614529613e3, + -.2200430300226009379477365011e3, + -.323869355375648849771296746e2, + -.14294979207907956223499258e1, + -.834690374102384988158918e-2, +}; +static const GENERIC qs[7] = { /* [8 -- inf] qzero 6950 */ + .1107975037248683865326709645e5, + .3544581680627082674651471873e5, + .3619118937918394132179019059e5, + .1439895563565398007471485822e5, + .2190277023344363955930226234e4, + .106695157020407986137501682e3, + 1.0, +}; + +static GENERIC +qzero(GENERIC x) { + GENERIC s,r,t,z; + int i; + if(x>huge) return -0.125/x; + t = eight/x; z = t*t; + r = qr[5]+z*qr[6]; + s = qs[5]+z; + for(i=4;i>=0;i--) { + r = r*z + qr[i]; + s = s*z + qs[i]; + } + return t*(r/s); +} diff --git a/usr/src/libm/src/C/j1.c b/usr/src/libm/src/C/j1.c new file mode 100644 index 0000000..c88914f --- /dev/null +++ b/usr/src/libm/src/C/j1.c @@ -0,0 +1,329 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)j1.c 1.17 06/01/31 SMI" + +/* + * floating point Bessel's function of the first and second kinds + * of order zero: j1(x),y1(x); + * + * Special cases: + * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; + * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. + */ + +#pragma weak j1 = __j1 +#pragma weak y1 = __y1 + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> +#include <values.h> + +#define GENERIC double +static const GENERIC +zero = 0.0, +small = 1.0e-5, +tiny = 1.0e-20, +one = 1.0, +invsqrtpi= 5.641895835477562869480794515607725858441e-0001, +tpi = 0.636619772367581343075535053490057448; + +static GENERIC pone(GENERIC), qone(GENERIC); +static const GENERIC r0[4] = { + -6.250000000000002203053200981413218949548e-0002, + 1.600998455640072901321605101981501263762e-0003, + -1.963888815948313758552511884390162864930e-0005, + 8.263917341093549759781339713418201620998e-0008, +}; +static const GENERIC s0[7] = { + 1.0e0, + 1.605069137643004242395356851797873766927e-0002, + 1.149454623251299996428500249509098499383e-0004, + 3.849701673735260970379681807910852327825e-0007, +}; +static const GENERIC r1[12] = { + 4.999999999999999995517408894340485471724e-0001, + -6.003825028120475684835384519945468075423e-0002, + 2.301719899263321828388344461995355419832e-0003, + -4.208494869238892934859525221654040304068e-0005, + 4.377745135188837783031540029700282443388e-0007, + -2.854106755678624335145364226735677754179e-0009, + 1.234002865443952024332943901323798413689e-0011, + -3.645498437039791058951273508838177134310e-0014, + 7.404320596071797459925377103787837414422e-0017, + -1.009457448277522275262808398517024439084e-0019, + 8.520158355824819796968771418801019930585e-0023, + -3.458159926081163274483854614601091361424e-0026, +}; +static const GENERIC s1[5] = { + 1.0e0, + 4.923499437590484879081138588998986303306e-0003, + 1.054389489212184156499666953501976688452e-0005, + 1.180768373106166527048240364872043816050e-0008, + 5.942665743476099355323245707680648588540e-0012, +}; + +GENERIC +j1(GENERIC x) { + GENERIC z, d, s,c,ss,cc,r; + int i, sgn; + + if(!finite(x)) return one/x; + sgn = signbit(x); + x = fabs(x); + if(x > 8.00){ + s = sin(x); + c = cos(x); + /* j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x0)-q1(x)*sin(x0)) + * where x0 = x-3pi/4 + * Better formula: + * cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4) + * = 1/sqrt(2) * (sin(x) - cos(x)) + * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) + * = -1/sqrt(2) * (cos(x) + sin(x)) + * To avoid cancellation, use + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) + * to compute the worse one. + */ + if(x>8.9e307) { /* x+x may overflow */ + ss = -s-c; + cc = s-c; + } else if(signbit(s)!=signbit(c)) { + cc = s - c; + ss = cos(x+x)/cc; + } else { + ss = -s-c; + cc = cos(x+x)/ss; + } + /* + * j1(x) = 1/sqrt(pi*x) * (P(1,x)*cc - Q(1,x)*ss) + * y1(x) = 1/sqrt(pi*x) * (P(1,x)*ss + Q(1,x)*cc) + */ + if(x>1.0e40) + d = (invsqrtpi*cc)/sqrt(x); + else + d = invsqrtpi*(pone(x)*cc-qone(x)*ss)/sqrt(x); + if (x > X_TLOSS) { + if(sgn!=0) {d = -d; x = -x;} + return _SVID_libm_err(x,d,36); + } else + if(sgn==0) return d; else return -d; + } + if(x<=small) { + if(x<=tiny) d = 0.5*x; + else d = x*(0.5-x*x*0.125); + if(sgn==0) return d; else return -d; + } + z = x*x; + if(x<1.28) { + r = r0[3]; + s = s0[3]; + for(i=2;i>=0;i--) { + r = r*z + r0[i]; + s = s*z + s0[i]; + } + d = x*0.5+x*(z*(r/s)); + } else { + r = r1[11]; + for(i=10;i>=0;i--) r = r*z + r1[i]; + s = s1[0]+z*(s1[1]+z*(s1[2]+z*(s1[3]+z*s1[4]))); + d = x*(r/s); + } + if(sgn==0) return d; else return -d; +} + +static const GENERIC u0[4] = { + -1.960570906462389461018983259589655961560e-0001, + 4.931824118350661953459180060007970291139e-0002, + -1.626975871565393656845930125424683008677e-0003, + 1.359657517926394132692884168082224258360e-0005, +}; +static const GENERIC v0[5] = { + 1.0e0, + 2.565807214838390835108224713630901653793e-0002, + 3.374175208978404268650522752520906231508e-0004, + 2.840368571306070719539936935220728843177e-0006, + 1.396387402048998277638900944415752207592e-0008, +}; +static const GENERIC u1[12] = { + -1.960570906462389473336339614647555351626e-0001, + 5.336268030335074494231369159933012844735e-0002, + -2.684137504382748094149184541866332033280e-0003, + 5.737671618979185736981543498580051903060e-0005, + -6.642696350686335339171171785557663224892e-0007, + 4.692417922568160354012347591960362101664e-0009, + -2.161728635907789319335231338621412258355e-0011, + 6.727353419738316107197644431844194668702e-0014, + -1.427502986803861372125234355906790573422e-0016, + 2.020392498726806769468143219616642940371e-0019, + -1.761371948595104156753045457888272716340e-0022, + 7.352828391941157905175042420249225115816e-0026, +}; +static const GENERIC v1[5] = { + 1.0e0, + 5.029187436727947764916247076102283399442e-0003, + 1.102693095808242775074856548927801750627e-0005, + 1.268035774543174837829534603830227216291e-0008, + 6.579416271766610825192542295821308730206e-0012, +}; + + +GENERIC +y1(GENERIC x) { + GENERIC z, d, s,c,ss,cc,u,v; + int i; + + if(isnan(x)) return x*x; /* + -> * for Cheetah */ + if(x <= zero){ + if(x==zero) + /* return -one/zero; */ + return _SVID_libm_err(x,x,10); + else + /* return zero/zero; */ + return _SVID_libm_err(x,x,11); + } + if(x > 8.0){ + if(!finite(x)) return zero; + s = sin(x); + c = cos(x); + /* j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x0)-q1(x)*sin(x0)) + * where x0 = x-3pi/4 + * Better formula: + * cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4) + * = 1/sqrt(2) * (sin(x) - cos(x)) + * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) + * = -1/sqrt(2) * (cos(x) + sin(x)) + * To avoid cancellation, use + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) + * to compute the worse one. + */ + if(x>8.9e307) { /* x+x may overflow */ + ss = -s-c; + cc = s-c; + } else if(signbit(s)!=signbit(c)) { + cc = s - c; + ss = cos(x+x)/cc; + } else { + ss = -s-c; + cc = cos(x+x)/ss; + } + /* + * j1(x) = 1/sqrt(pi*x) * (P(1,x)*cc - Q(1,x)*ss) + * y1(x) = 1/sqrt(pi*x) * (P(1,x)*ss + Q(1,x)*cc) + */ + if(x>1.0e91) + d = (invsqrtpi*ss)/sqrt(x); + else + d = invsqrtpi*(pone(x)*ss+qone(x)*cc)/sqrt(x); + if (x > X_TLOSS) + return _SVID_libm_err(x,d,37); + else + return d; + } + if(x<=tiny) { + return(-tpi/x); + } + z = x*x; + if(x<1.28) { + u = u0[3]; v = v0[3]+z*v0[4]; + for(i=2;i>=0;i--){ + u = u*z + u0[i]; + v = v*z + v0[i]; + } + } else { + for (u = u1[11], i=10;i>=0;i--) u = u*z+u1[i]; + v = v1[0]+z*(v1[1]+z*(v1[2]+z*(v1[3]+z*v1[4]))); + } + return(x*(u/v) + tpi*(j1(x)*log(x)-one/x)); +} + +static const GENERIC pr0[6] = { + -.4435757816794127857114720794e7, + -.9942246505077641195658377899e7, + -.6603373248364939109255245434e7, + -.1523529351181137383255105722e7, + -.1098240554345934672737413139e6, + -.1611616644324610116477412898e4, +}; +static const GENERIC ps0[6] = { + -.4435757816794127856828016962e7, + -.9934124389934585658967556309e7, + -.6585339479723087072826915069e7, + -.1511809506634160881644546358e7, + -.1072638599110382011903063867e6, + -.1455009440190496182453565068e4, +}; +static const GENERIC huge = 1.0e10; + +static GENERIC +pone(GENERIC x) { + GENERIC s,r,t,z; + int i; + /* assume x > 8 */ + if(x>huge) return one; + t = 8.0/x; z = t*t; + r = pr0[5]; s = ps0[5]+z; + for(i=4;i>=0;i--) { + r = z*r + pr0[i]; + s = z*s + ps0[i]; + } + return r/s; +} + + +static const GENERIC qr0[6] = { + 0.3322091340985722351859704442e5, + 0.8514516067533570196555001171e5, + 0.6617883658127083517939992166e5, + 0.1849426287322386679652009819e5, + 0.1706375429020768002061283546e4, + 0.3526513384663603218592175580e2, +}; +static const GENERIC qs0[6] = { + 0.7087128194102874357377502472e6, + 0.1819458042243997298924553839e7, + 0.1419460669603720892855755253e7, + 0.4002944358226697511708610813e6, + 0.3789022974577220264142952256e5, + 0.8638367769604990967475517183e3, +}; + +static GENERIC +qone(GENERIC x) { + GENERIC s,r,t,z; + int i; + if(x>huge) return 0.375/x; + t = 8.0/x; z = t*t; + /* assume x > 8 */ + r = qr0[5]; s = qs0[5]+z; + for(i=4;i>=0;i--) { + r = z*r + qr0[i]; + s = z*s + qs0[i]; + } + return t*(r/s); +} diff --git a/usr/src/libm/src/C/jn.c b/usr/src/libm/src/C/jn.c new file mode 100644 index 0000000..0afa31f --- /dev/null +++ b/usr/src/libm/src/C/jn.c @@ -0,0 +1,279 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)jn.c 1.23 06/01/31 SMI" + +#pragma weak jn = __jn +#pragma weak yn = __yn + +/* + * floating point Bessel's function of the 1st and 2nd kind + * of order n: jn(n,x),yn(n,x); + * + * Special cases: + * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; + * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. + * Note 2. About jn(n,x), yn(n,x) + * For n=0, j0(x) is called, + * for n=1, j1(x) is called, + * for n<x, forward recursion us used starting + * from values of j0(x) and j1(x). + * for n>x, a continued fraction approximation to + * j(n,x)/j(n-1,x) is evaluated and then backward + * recursion is used starting from a supposed value + * for j(n,x). The resulting value of j(0,x) is + * compared with the actual value to correct the + * supposed value of j(n,x). + * + * yn(n,x) is similar in all respects, except + * that forward recursion is used for all + * values of n>1. + * + */ + +#include "libm.h" +#include <float.h> /* DBL_MIN */ +#include <values.h> /* X_TLOSS */ +#include "xpg6.h" /* __xpg6 */ + +#define GENERIC double + +static const GENERIC + invsqrtpi = 5.641895835477562869480794515607725858441e-0001, + two = 2.0, + zero = 0.0, + one = 1.0; + +GENERIC +jn(int n, GENERIC x) { + int i, sgn; + GENERIC a, b, temp; + GENERIC z, w, ox, on; + + /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x) + * Thus, J(-n,x) = J(n,-x) + */ + ox = x; on = (GENERIC)n; + if(n<0){ + n = -n; + x = -x; + } + if(isnan(x)) return x*x; /* + -> * for Cheetah */ + if (!((int) _lib_version == libm_ieee || + (__xpg6 & _C99SUSv3_math_errexcept) != 0)) { + if(fabs(x) > X_TLOSS) return _SVID_libm_err(on,ox,38); + } + if(n==0) return(j0(x)); + if(n==1) return(j1(x)); + if((n&1)==0) + sgn=0; /* even n */ + else + sgn = signbit(x); /* old n */ + x = fabs(x); + if(x == zero||!finite(x)) b = zero; + else if((GENERIC)n<=x) { /* Safe to use + J(n+1,x)=2n/x *J(n,x)-J(n-1,x) + */ + if(x>1.0e91) { /* x >> n**2 + Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) + Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) + Let s=sin(x), c=cos(x), + xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then + + n sin(xn)*sqt2 cos(xn)*sqt2 + ---------------------------------- + 0 s-c c+s + 1 -s-c -c+s + 2 -s+c -c-s + 3 s+c c-s + */ + switch(n&3) { + case 0: temp = cos(x)+sin(x); break; + case 1: temp = -cos(x)+sin(x); break; + case 2: temp = -cos(x)-sin(x); break; + case 3: temp = cos(x)-sin(x); break; + } + b = invsqrtpi*temp/sqrt(x); + } else { + a = j0(x); + b = j1(x); + for(i=1;i<n;i++){ + temp = b; + b = b*((GENERIC)(i+i)/x) - a; /* avoid underflow */ + a = temp; + } + } + } else { + if(x<1e-9) { /* use J(n,x) = 1/n!*(x/2)^n */ + b = pow(0.5*x,(GENERIC) n); + if (b!=zero) { + for(a=one,i=1;i<=n;i++) a *= (GENERIC)i; + b = b/a; + } + } else { + /* use backward recurrence */ + /* x x^2 x^2 + * J(n,x)/J(n-1,x) = ---- ------ ------ ..... + * 2n - 2(n+1) - 2(n+2) + * + * 1 1 1 + * (for large x) = ---- ------ ------ ..... + * 2n 2(n+1) 2(n+2) + * -- - ------ - ------ - + * x x x + * + * Let w = 2n/x and h=2/x, then the above quotient + * is equal to the continued fraction: + * 1 + * = ----------------------- + * 1 + * w - ----------------- + * 1 + * w+h - --------- + * w+2h - ... + * + * To determine how many terms needed, let + * Q(0) = w, Q(1) = w(w+h) - 1, + * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), + * When Q(k) > 1e4 good for single + * When Q(k) > 1e9 good for double + * When Q(k) > 1e17 good for quaduple + */ + /* determin k */ + GENERIC t,v; + double q0,q1,h,tmp; int k,m; + w = (n+n)/(double)x; h = 2.0/(double)x; + q0 = w; z = w+h; q1 = w*z - 1.0; k=1; + while(q1<1.0e9) { + k += 1; z += h; + tmp = z*q1 - q0; + q0 = q1; + q1 = tmp; + } + m = n+n; + for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t); + a = t; + b = one; + /* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n) + hence, if n*(log(2n/x)) > ... + single 8.8722839355e+01 + double 7.09782712893383973096e+02 + long double 1.1356523406294143949491931077970765006170e+04 + then recurrent value may overflow and the result is + likely underflow to zero + */ + tmp = n; + v = two/x; + tmp = tmp*log(fabs(v*tmp)); + if(tmp<7.09782712893383973096e+02) { + for(i=n-1;i>0;i--){ + temp = b; + b = ((i+i)/x)*b - a; + a = temp; + } + } else { + for(i=n-1;i>0;i--){ + temp = b; + b = ((i+i)/x)*b - a; + a = temp; + if(b>1e100) { + a /= b; + t /= b; + b = 1.0; + } + } + } + b = (t*j0(x)/b); + } + } + if(sgn==1) return -b; else return b; +} + +GENERIC +yn(int n, GENERIC x) { + int i; + int sign; + GENERIC a, b, temp, ox, on; + + ox = x; on = (GENERIC)n; + if(isnan(x)) return x*x; /* + -> * for Cheetah */ + if (x <= zero) + if(x==zero) + /* return -one/zero; */ + return _SVID_libm_err((GENERIC)n,x,12); + else + /* return zero/zero; */ + return _SVID_libm_err((GENERIC)n,x,13); + if (!((int) _lib_version == libm_ieee || + (__xpg6 & _C99SUSv3_math_errexcept) != 0)) { + if(x > X_TLOSS) return _SVID_libm_err(on,ox,39); + } + sign = 1; + if(n<0){ + n = -n; + if((n&1) == 1) sign = -1; + } + if(n==0) return(y0(x)); + if(n==1) return(sign*y1(x)); + if(!finite(x)) return zero; + + if(x>1.0e91) { /* x >> n**2 + Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) + Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) + Let s=sin(x), c=cos(x), + xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then + + n sin(xn)*sqt2 cos(xn)*sqt2 + ---------------------------------- + 0 s-c c+s + 1 -s-c -c+s + 2 -s+c -c-s + 3 s+c c-s + */ + switch(n&3) { + case 0: temp = sin(x)-cos(x); break; + case 1: temp = -sin(x)-cos(x); break; + case 2: temp = -sin(x)+cos(x); break; + case 3: temp = sin(x)+cos(x); break; + } + b = invsqrtpi*temp/sqrt(x); + } else { + a = y0(x); + b = y1(x); + /* + * fix 1262058 and take care of non-default rounding + */ + for (i = 1; i < n; i++) { + temp = b; + b *= (GENERIC) (i + i) / x; + if (b <= -DBL_MAX) + break; + b -= a; + a = temp; + } + } + if(sign>0) return b; else return -b; +} diff --git a/usr/src/libm/src/C/lgamma.c b/usr/src/libm/src/C/lgamma.c new file mode 100644 index 0000000..9e61d33 --- /dev/null +++ b/usr/src/libm/src/C/lgamma.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)lgamma.c 1.25 06/01/23 SMI" + +#pragma weak lgamma = __lgamma + +#include "libm.h" + +extern int signgam; + +double +lgamma(double x) { + double g; + + if (!finite(x)) + return (x * x); + + g = rint(x); + if (x == g && x <= 0.0) { + signgam = 1; + return (_SVID_libm_err(x, x, 15)); + } + + g = __k_lgamma(x, &signgam); + if (!finite(g)) + g = _SVID_libm_err(x, x, 14); + return (g); +} diff --git a/usr/src/libm/src/C/lgamma_r.c b/usr/src/libm/src/C/lgamma_r.c new file mode 100644 index 0000000..c6e774f --- /dev/null +++ b/usr/src/libm/src/C/lgamma_r.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)lgamma_r.c 1.6 06/01/23 SMI" + +#pragma weak lgamma_r = __lgamma_r + +#include "libm.h" + +double +lgamma_r(double x, int *signgamp) { + double g; + + if (isnan(x)) + return (x * x); + + g = rint(x); + if (x == g && x <= 0.0) { + *signgamp = 1; + return (_SVID_libm_err(x, x, 15)); + } + + g = __k_lgamma(x, signgamp); + if (!finite(g)) + g = _SVID_libm_err(x, x, 14); + return (g); +} diff --git a/usr/src/libm/src/C/libm.h b/usr/src/libm/src/C/libm.h new file mode 100644 index 0000000..18e438c --- /dev/null +++ b/usr/src/libm/src/C/libm.h @@ -0,0 +1,203 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBM_H +#define _LIBM_H + +#pragma ident "@(#)libm.h 1.54 06/01/23 SMI" + +#ifdef _ASM +/* BEGIN CSTYLED */ + +/* + * Disable amd64 assembly code profiling for now. + */ +#if defined(__amd64) +#undef PROF +#endif + +#include <sys/asm_linkage.h> + +#define NAME(x) x +#define TEXT .section ".text" +#define DATA .section ".data" +#define RO_DATA .section ".rodata" +#define IDENT(x) .ident x + +#if defined(__sparc) + +#define LIBM_ANSI_PRAGMA_WEAK(sym,stype) \ + .weak sym; \ + .type sym,#stype; \ +sym = __/**/sym + +#ifndef SET_FILE +#define SET_FILE(x) \ + .file x +#endif /* !defined(SET_FILE) */ + +#ifdef PIC +/* + * One should *never* pass o7 to PIC_SETUP. + */ +#define PIC_SETUP(via) \ +9: call 8f; \ + sethi %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \ +8: or %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \ + add %via,%o7,%via +/* + * Must save/restore %o7 in leaf routines; may *not* use jmpl! + */ +#define PIC_LEAF_SETUP(via) \ + or %g0,%o7,%g1; \ +9: call 8f; \ + sethi %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \ +8: or %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \ + add %via,%o7,%via; \ + or %g0,%g1,%o7 +#ifdef __sparcv9 +#define PIC_SET(via,sym,dst) ldx [%via+sym],%dst +#else /* defined(__sparcv9) */ +#define PIC_SET(via,sym,dst) ld [%via+sym],%dst +#endif /* defined(__sparcv9) */ +#else /* defined(PIC) */ +#define PIC_SETUP(via) +#define PIC_LEAF_SETUP(via) +#ifdef __sparcv9 +/* + * g1 is used as scratch register in V9 mode + */ +#define PIC_SET(via,sym,dst) setx sym,%g1,%dst +#else /* defined(__sparcv9) */ +#define PIC_SET(via,sym,dst) set sym,%dst +#endif /* defined(__sparcv9) */ +#endif /* defined(PIC) */ + +/* + * Workaround for 4337025: MCOUNT in asm_linkage.h does not support __sparcv9 + */ +#if defined(PROF) && defined(__sparcv9) + +#undef MCOUNT_SIZE +#undef MCOUNT + +#if !defined(PIC) +#define MCOUNT_SIZE (9*4) /* 9 instructions */ +#define MCOUNT(x) \ + save %sp, -SA(MINFRAME), %sp; \ + sethi %hh(.L_/**/x/**/1), %o0; \ + sethi %lm(.L_/**/x/**/1), %o1; \ + or %o0, %hm(.L_/**/x/**/1), %o0; \ + or %o1, %lo(.L_/**/x/**/1), %o1; \ + sllx %o0, 32, %o0; \ + call _mcount; \ + or %o0, %o1, %o0; \ + restore; \ + .common .L_/**/x/**/1, 8, 8 +#elif defined(PIC32) +#define MCOUNT_SIZE (10*4) /* 10 instructions */ +#define MCOUNT(x) \ + save %sp,-SA(MINFRAME),%sp; \ +1: call .+8; \ + sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \ + sethi %hi(.L_/**/x/**/1),%o1; \ + add %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \ + add %o1,%lo(.L_/**/x/**/1),%o1; \ + add %o0,%o7,%o0; \ + call _mcount; \ + ldx [%o0+%o1],%o0; \ + restore; \ + .common .L_/**/x/**/1,8,8 +#else /* PIC13 */ +#define MCOUNT_SIZE (8*4) /* 8 instructions */ +#define MCOUNT(x) \ + save %sp,-SA(MINFRAME),%sp; \ +1: call .+8; \ + sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \ + add %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \ + add %o0,%o7,%o0; \ + call _mcount; \ + ldx [%o0+%lo(.L_/**/x/**/1)],%o0; \ + restore; \ + .common .L_/**/x/**/1,8,8 +#endif /* !defined(PIC) */ +#endif /* defined(PROF) && defined(__sparcv9) */ + +#elif defined(__i386) || defined(__amd64) + +#define LIBM_ANSI_PRAGMA_WEAK(sym,stype) \ + .weak sym; \ + .type sym,@stype; \ +sym = __/**/sym + +#ifdef PIC +#if defined(__amd64) +#define PIC_SETUP(x) +#define PIC_WRAPUP +#define PIC_F(x) x@PLT +#define PIC_G(x) x@GOTPCREL(%rip) +#define PIC_L(x) x(%rip) +#define PIC_G_LOAD(insn,sym,dst) \ + movq PIC_G(sym),%dst; \ + insn (%dst),%dst +#else +#define PIC_SETUP(label) \ + pushl %ebx; \ + call .label; \ +.label: popl %ebx; \ + addl $_GLOBAL_OFFSET_TABLE_+[.-.label],%ebx +#define PIC_WRAPUP popl %ebx +#define PIC_F(x) x@PLT +#define PIC_G(x) x@GOT(%ebx) +#define PIC_L(x) x@GOTOFF(%ebx) +#define PIC_G_LOAD(insn,sym,dst) \ + mov PIC_G(sym),%dst; \ + insn (%dst),%dst +#endif +#else /* defined(PIC) */ +#define PIC_SETUP(x) +#define PIC_WRAPUP +#define PIC_F(x) x +#define PIC_G(x) x +#define PIC_L(x) x +#define PIC_G_LOAD(insn,sym,dst) insn sym,%dst +#endif /* defined(PIC) */ + +#else +#error Unknown architecture +#endif + +/* END CSTYLED */ +#else /* defined(_ASM) */ + +#include "libm_macros.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> +#include <sunmath.h> + +#endif /* defined(_ASM) */ + +#endif /* defined(_LIBM_H) */ diff --git a/usr/src/libm/src/C/libm_macros.h b/usr/src/libm/src/C/libm_macros.h new file mode 100644 index 0000000..1061521 --- /dev/null +++ b/usr/src/libm/src/C/libm_macros.h @@ -0,0 +1,76 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBM_MACROS_H +#define _LIBM_MACROS_H + +#pragma ident "@(#)libm_macros.h 1.4 06/01/23 SMI" + +#if defined(__sparc) + +#define HIWORD 0 +#define LOWORD 1 +#define HIXWORD 0 /* index of int containing exponent */ +#define XSGNMSK 0x80000000 /* exponent bit mask within the int */ +#define XBIASED_EXP(x) ((((int *)&x)[HIXWORD] & ~0x80000000) >> 16) +#define ISZEROL(x) (((((int *)&x)[0] & ~XSGNMSK) | ((int *)&x)[1] | \ + ((int *)&x)[2] | ((int *)&x)[3]) == 0) + +#elif defined(__i386) || defined(__amd64) + +#define HIWORD 1 +#define LOWORD 0 +#define HIXWORD 2 +#define XSGNMSK 0x8000 +#define XBIASED_EXP(x) (((int *)&x)[HIXWORD] & 0x7fff) +#define ISZEROL(x) (x == 0.0L) + +#define HANDLE_UNSUPPORTED + +/* + * "convert" the high-order 32 bits of a SPARC quad precision + * value ("I") to the sign, exponent, and high-order bits of an + * x86 extended double precision value ("E"); the low-order bits + * in the 12-byte quantity are left intact + */ +#define ITOX(I, E) \ + E[2] = 0xffff & ((I) >> 16); \ + E[1] = (((I) & 0x7fff0000) == 0)? \ + (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15)) :\ + 0x80000000 | (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15)) + +/* + * "convert" the sign, exponent, and high-order bits of an x86 + * extended double precision value ("E") to the high-order 32 bits + * of a SPARC quad precision value ("I") + */ +#define XTOI(E, I) \ + I = ((E[2]<<16) | (0xffff & (E[1]>>15))) + +#else +#error Unknown architecture +#endif + +#endif /* !defined(_LIBM_MACROS_H) */ diff --git a/usr/src/libm/src/C/libm_protos.h b/usr/src/libm/src/C/libm_protos.h new file mode 100644 index 0000000..4c77e19 --- /dev/null +++ b/usr/src/libm/src/C/libm_protos.h @@ -0,0 +1,217 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)libm_protos.h 1.41 06/01/23 SMI" + +#ifndef _LIBM_PROTOS_H +#define _LIBM_PROTOS_H + +#ifdef LIBMOPT_BUILD +#define _TBL_cos __libmopt_TBL_cos +#define _TBL_exp2_512 __libmopt_TBL_exp2_512 +#define _TBL_ipio2_inf __libmopt_TBL_ipio2_inf +#define _TBL_jlog_n1 __libmopt_TBL_jlog_n1 +#define _TBL_jlog_n2 __libmopt_TBL_jlog_n2 +#define _TBL_jlog_p1 __libmopt_TBL_jlog_p1 +#define _TBL_jlog_p2 __libmopt_TBL_jlog_p2 +#define _TBL_log10 __libmopt_TBL_log10 +#define _TBL_log2_14 __libmopt_TBL_log2_14 +#define _TBL_log2_9 __libmopt_TBL_log2_9 +#define _TBL_sin __libmopt_TBL_sin +#define _TBL_sincosx __libmopt_TBL_sincosx +#define _TBL_xexp __libmopt_TBL_xexp +#define _TBL_xlog __libmopt_TBL_xlog +#define __k_cos_ __libmopt__k_cos_ +#define __k_sin_ __libmopt__k_sin_ +#define __k_sincos_ __libmopt__k_sincos_ +#define __reduction __libmopt__reduction +#define __rem_pio2 __libmopt__rem_pio2 +#define __rem_pio2m __libmopt__rem_pio2m +#else /* defined(LIBMOPT_BUILD) */ +#ifdef LIBM_BUILD +#define _SVID_libm_err __libm_SVID_libm_err /* not used by -lsunmath */ +#define _TBL_atan __libm_TBL_atan +#define _TBL_atan1 __libm_TBL_atan1 +#define _TBL_atan_hi __libm_TBL_atan_hi /* not used by -lsunmath */ +#define _TBL_atan_lo __libm_TBL_atan_lo /* not used by -lsunmath */ +#define _TBL_exp2_hi __libm_TBL_exp2_hi /* not used by -lsunmath */ +#define _TBL_exp2_lo __libm_TBL_exp2_lo /* not used by -lsunmath */ +#define _TBL_ipio2_inf __libm_TBL_ipio2_inf +#define _TBL_log __libm_TBL_log +#define _TBL_log2_hi __libm_TBL_log2_hi /* not used by -lsunmath */ +#define _TBL_log2_lo __libm_TBL_log2_lo /* not used by -lsunmath */ +#define _TBL_log_hi __libm_TBL_log_hi /* not used by -lsunmath */ +#define _TBL_log_lo __libm_TBL_log_lo /* not used by -lsunmath */ +#define _TBL_sincos __libm_TBL_sincos +#define _TBL_sincosx __libm_TBL_sincosx +#define _TBL_tan_hi __libm_TBL_tan_hi /* not used by -lsunmath */ +#define _TBL_tan_lo __libm_TBL_tan_lo /* not used by -lsunmath */ +#define __k_cexp __libm__k_cexp /* C99 libm */ +#define __k_cexpl __libm__k_cexpl /* C99 libm */ +#define __k_clog_r __libm__k_clog_r /* C99 libm */ +#define __k_clog_rl __libm__k_clog_rl /* C99 libm */ +#define __k_atan2 __libm__k_atan2 /* C99 libm */ +#define __k_atan2l __libm__k_atan2l /* C99 libm */ +#define __k_cos __libm__k_cos +#define __k_lgamma __libm__k_lgamma +#define __k_sin __libm__k_sin +#define __k_sincos __libm__k_sincos +#define __k_tan __libm__k_tan +#define __reduction __libm__reduction /* i386 only */ +#define __rem_pio2 __libm__rem_pio2 +#define __rem_pio2m __libm__rem_pio2m +#define __k_cosf __libm__k_cosf /* C99 libm */ +#define __k_cosl __libm__k_cosl /* C99 libm */ +#define __k_lgammal __libm__k_lgammal /* C99 libm */ +#define __k_sincosf __libm__k_sincosf /* C99 libm */ +#define __k_sincosl __libm__k_sincosl /* C99 libm */ +#define __k_sinf __libm__k_sinf /* C99 libm */ +#define __k_sinl __libm__k_sinl /* C99 libm */ +#define __k_tanf __libm__k_tanf /* C99 libm */ +#define __k_tanl __libm__k_tanl /* C99 libm */ +#define __poly_libmq __libm__poly_libmq /* C99 libm */ +#define __rem_pio2l __libm__rem_pio2l /* C99 libm */ +#define _TBL_atanl_hi __libm_TBL_atanl_hi /* C99 libm */ +#define _TBL_atanl_lo __libm_TBL_atanl_lo /* C99 libm */ +#define _TBL_cosl_hi __libm_TBL_cosl_hi /* C99 libm */ +#define _TBL_cosl_lo __libm_TBL_cosl_lo /* C99 libm */ +#define _TBL_expl_hi __libm_TBL_expl_hi /* C99 libm */ +#define _TBL_expl_lo __libm_TBL_expl_lo /* C99 libm */ +#define _TBL_expm1l __libm_TBL_expm1l /* C99 libm */ +#define _TBL_expm1lx __libm_TBL_expm1lx /* C99 libm */ +#define _TBL_ipio2l_inf __libm_TBL_ipio2l_inf /* C99 libm */ +#define _TBL_logl_hi __libm_TBL_logl_hi /* C99 libm */ +#define _TBL_logl_lo __libm_TBL_logl_lo /* C99 libm */ +#define _TBL_r_atan_hi __libm_TBL_r_atan_hi /* C99 libm */ +#define _TBL_r_atan_lo __libm_TBL_r_atan_lo /* C99 libm */ +#define _TBL_sinl_hi __libm_TBL_sinl_hi /* C99 libm */ +#define _TBL_sinl_lo __libm_TBL_sinl_lo /* C99 libm */ +#define _TBL_tanl_hi __libm_TBL_tanl_hi /* C99 libm */ +#define _TBL_tanl_lo __libm_TBL_tanl_lo /* C99 libm */ +#endif /* defined(LIBM_BUILD) */ +#endif /* defined(LIBMOPT_BUILD) */ + +#ifndef _ASM +#ifdef __STDC__ +#define __P(p) p +#else +#define __P(p) () +#endif + +#include <sys/ieeefp.h> + +extern double _SVID_libm_err __P((double, double, int)); +extern double __k_cos __P((double, double)); +extern double __k_cos_ __P((double *)); +extern double __k_lgamma __P((double, int *)); +extern double __k_sin __P((double, double)); +extern double __k_sin_ __P((double *)); +extern double __k_sincos __P((double, double, double *)); +extern double __k_sincos_ __P((double *, double *)); +extern double __k_tan __P((double, double, int)); +extern double __k_cexp __P((double, int *)); +extern long double __k_cexpl __P((long double, int *)); +extern double __k_clog_r __P((double, double, double *)); +extern long double __k_clog_rl __P((long double, long double, long double *)); +extern double __k_atan2 __P((double, double, double *)); +extern long double __k_atan2l __P((long double, long double, long double *)); +extern int __rem_pio2 __P((double, double *)); +extern int __rem_pio2m __P((double *, double *, int, int, int, const int *)); + +/* + * entry points that are in-lined + */ +extern double copysign __P((double, double)); +extern int finite __P((double)); +extern enum fp_class_type fp_class __P((double)); +extern double infinity __P((void)); +extern int isinf __P((double)); +extern int signbit __P((double)); + +/* + * new C99 entry points + */ +extern double fdim __P((double, double)); +extern double fma __P((double, double, double)); +extern double fmax __P((double, double)); +extern double fmin __P((double, double)); +extern double frexp __P((double, int *)); +extern double ldexp __P((double, int)); +extern double modf __P((double, double *)); +extern double nan __P((const char *)); +extern double nearbyint __P((double)); +extern double nexttoward __P((double, long double)); +extern double remquo __P((double, double, int *)); +extern double round __P((double)); +extern double scalbln __P((double, long int)); +extern double tgamma __P((double)); +extern double trunc __P((double)); +extern float fdimf __P((float, float)); +extern float fmaf __P((float, float, float)); +extern float fmaxf __P((float, float)); +extern float fminf __P((float, float)); +extern float frexpf __P((float, int *)); +extern float ldexpf __P((float, int)); +extern float modff __P((float, float *)); +extern float nanf __P((const char *)); +extern float nearbyintf __P((float)); +extern float nextafterf __P((float, float)); +extern float nexttowardf __P((float, long double)); +extern float remquof __P((float, float, int *)); +extern float roundf __P((float)); +extern float scalblnf __P((float, long int)); +extern float tgammaf __P((float)); +extern float truncf __P((float)); +extern long double frexpl(long double, int *); +extern long double fdiml __P((long double, long double)); +extern long double fmal __P((long double, long double, long double)); +extern long double fmaxl __P((long double, long double)); +extern long double fminl __P((long double, long double)); +extern long double ldexpl __P((long double, int)); +extern long double modfl __P((long double, long double *)); +extern long double nanl __P((const char *)); +extern long double nearbyintl __P((long double)); +extern long double nextafterl __P((long double, long double)); +extern long double nexttowardl __P((long double, long double)); +extern long double remquol __P((long double, long double, int *)); +extern long double roundl __P((long double)); +extern long double scalblnl __P((long double, long int)); +extern long double tgammal __P((long double)); +extern long double truncl __P((long double)); +extern long int lrint __P((double)); +extern long int lrintf __P((float)); +extern long int lrintl __P((long double)); +extern long int lround __P((double)); +extern long int lroundf __P((float)); +extern long int lroundl __P((long double)); +extern long long int llrint __P((double)); +extern long long int llrintf __P((float)); +extern long long int llrintl __P((long double)); +extern long long int llround __P((double)); +extern long long int llroundf __P((float)); +extern long long int llroundl __P((long double)); +#endif /* !defined(_ASM) */ + +#endif /* !defined(_LIBM_PROTOS_H) */ diff --git a/usr/src/libm/src/C/libm_synonyms.h b/usr/src/libm/src/C/libm_synonyms.h new file mode 100644 index 0000000..2687990 --- /dev/null +++ b/usr/src/libm/src/C/libm_synonyms.h @@ -0,0 +1,748 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBM_SYNONYMS_H +#define _LIBM_SYNONYMS_H + +#pragma ident "@(#)libm_synonyms.h 1.37 06/01/31 SMI" + +#if defined(ELFOBJ) && !defined(lint) + +#define cabs __cabs /* C99 <complex.h> */ +#define cabsf __cabsf /* C99 <complex.h> */ +#define cabsl __cabsl /* C99 <complex.h> */ +#define cacos __cacos /* C99 <complex.h> */ +#define cacosf __cacosf /* C99 <complex.h> */ +#define cacosl __cacosl /* C99 <complex.h> */ +#define cacosh __cacosh /* C99 <complex.h> */ +#define cacoshf __cacoshf /* C99 <complex.h> */ +#define cacoshl __cacoshl /* C99 <complex.h> */ +#define carg __carg /* C99 <complex.h> */ +#define cargf __cargf /* C99 <complex.h> */ +#define cargl __cargl /* C99 <complex.h> */ +#define casin __casin /* C99 <complex.h> */ +#define casinf __casinf /* C99 <complex.h> */ +#define casinl __casinl /* C99 <complex.h> */ +#define casinh __casinh /* C99 <complex.h> */ +#define casinhf __casinhf /* C99 <complex.h> */ +#define casinhl __casinhl /* C99 <complex.h> */ +#define catan __catan /* C99 <complex.h> */ +#define catanf __catanf /* C99 <complex.h> */ +#define catanl __catanl /* C99 <complex.h> */ +#define catanh __catanh /* C99 <complex.h> */ +#define catanhf __catanhf /* C99 <complex.h> */ +#define catanhl __catanhl /* C99 <complex.h> */ +#define ccos __ccos /* C99 <complex.h> */ +#define ccosf __ccosf /* C99 <complex.h> */ +#define ccosl __ccosl /* C99 <complex.h> */ +#define ccosh __ccosh /* C99 <complex.h> */ +#define ccoshf __ccoshf /* C99 <complex.h> */ +#define ccoshl __ccoshl /* C99 <complex.h> */ +#define cexp __cexp /* C99 <complex.h> */ +#define cexpf __cexpf /* C99 <complex.h> */ +#define cexpl __cexpl /* C99 <complex.h> */ +#define cimag __cimag /* C99 <complex.h> */ +#define cimagf __cimagf /* C99 <complex.h> */ +#define cimagl __cimagl /* C99 <complex.h> */ +#define clog __clog /* C99 <complex.h> */ +#define clogf __clogf /* C99 <complex.h> */ +#define clogl __clogl /* C99 <complex.h> */ +#define conj __conj /* C99 <complex.h> */ +#define conjf __conjf /* C99 <complex.h> */ +#define conjl __conjl /* C99 <complex.h> */ +#define cpow __cpow /* C99 <complex.h> */ +#define cpowf __cpowf /* C99 <complex.h> */ +#define cpowl __cpowl /* C99 <complex.h> */ +#define cproj __cproj /* C99 <complex.h> */ +#define cprojf __cprojf /* C99 <complex.h> */ +#define cprojl __cprojl /* C99 <complex.h> */ +#define creal __creal /* C99 <complex.h> */ +#define crealf __crealf /* C99 <complex.h> */ +#define creall __creall /* C99 <complex.h> */ +#define csin __csin /* C99 <complex.h> */ +#define csinf __csinf /* C99 <complex.h> */ +#define csinl __csinl /* C99 <complex.h> */ +#define csinh __csinh /* C99 <complex.h> */ +#define csinhf __csinhf /* C99 <complex.h> */ +#define csinhl __csinhl /* C99 <complex.h> */ +#define csqrt __csqrt /* C99 <complex.h> */ +#define csqrtf __csqrtf /* C99 <complex.h> */ +#define csqrtl __csqrtl /* C99 <complex.h> */ +#define ctan __ctan /* C99 <complex.h> */ +#define ctanf __ctanf /* C99 <complex.h> */ +#define ctanl __ctanl /* C99 <complex.h> */ +#define ctanh __ctanh /* C99 <complex.h> */ +#define ctanhf __ctanhf /* C99 <complex.h> */ +#define ctanhl __ctanhl /* C99 <complex.h> */ +#define abrupt_underflow_ __abrupt_underflow_ +#define acos __acos +#define acosd __acosd +#define acosdf __acosdf +#define acosdl __acosdl +#define acosf __acosf +#define acosh __acosh +#define acoshf __acoshf +#define acoshl __acoshl +#define acosl __acosl +#define acosp __acosp +#define acospf __acospf +#define acospi __acospi +#define acospif __acospif +#define acospil __acospil +#define acospl __acospl +#define aint __aint +#define aintf __aintf +#define aintl __aintl +#define anint __anint +#define anintf __anintf +#define anintl __anintl +#define annuity __annuity +#define annuityf __annuityf +#define annuityl __annuityl +#define asin __asin +#define asind __asind +#define asindf __asindf +#define asindl __asindl +#define asinf __asinf +#define asinh __asinh +#define asinhf __asinhf +#define asinhl __asinhl +#define asinl __asinl +#define asinp __asinp +#define asinpf __asinpf +#define asinpi __asinpi +#define asinpif __asinpif +#define asinpil __asinpil +#define asinpl __asinpl +#define atan __atan +#define atan2 __atan2 +#define atan2d __atan2d +#define atan2df __atan2df +#define atan2dl __atan2dl +#define atan2f __atan2f +#define atan2l __atan2l +#define atan2pi __atan2pi +#define atan2pif __atan2pif +#define atan2pil __atan2pil +#define atand __atand +#define atandf __atandf +#define atandl __atandl +#define atanf __atanf +#define atanh __atanh +#define atanhf __atanhf +#define atanhl __atanhl +#define atanl __atanl +#define atanp __atanp +#define atanpf __atanpf +#define atanpi __atanpi +#define atanpif __atanpif +#define atanpil __atanpil +#define atanpl __atanpl +#define cbrt __cbrt +#define cbrtf __cbrtf +#define cbrtl __cbrtl +#define ceil __ceil +#define ceilf __ceilf +#define ceill __ceill +#define compound __compound +#define compoundf __compoundf +#define compoundl __compoundl +#define convert_external __convert_external +#define convert_external_ __convert_external_ +#define copysign __copysign +#define copysignf __copysignf +#define copysignl __copysignl +#define cos __cos +#define cosd __cosd +#define cosdf __cosdf +#define cosdl __cosdl +#define cosf __cosf +#define cosh __cosh +#define coshf __coshf +#define coshl __coshl +#define cosl __cosl +#define cosp __cosp +#define cospf __cospf +#define cospi __cospi +#define cospif __cospif +#define cospil __cospil +#define cospl __cospl +#define d_acos_ __d_acos_ +#define d_acosd_ __d_acosd_ +#define d_acosh_ __d_acosh_ +#define d_acosp_ __d_acosp_ +#define d_acospi_ __d_acospi_ +#define d_addran_ __d_addran_ +#define d_addrans_ __d_addrans_ +#define d_aint_ __d_aint_ +#define d_anint_ __d_anint_ +#define d_annuity_ __d_annuity_ +#define d_asin_ __d_asin_ +#define d_asind_ __d_asind_ +#define d_asinh_ __d_asinh_ +#define d_asinp_ __d_asinp_ +#define d_asinpi_ __d_asinpi_ +#define d_atan2_ __d_atan2_ +#define d_atan2d_ __d_atan2d_ +#define d_atan2pi_ __d_atan2pi_ +#define d_atan_ __d_atan_ +#define d_atand_ __d_atand_ +#define d_atanh_ __d_atanh_ +#define d_atanp_ __d_atanp_ +#define d_atanpi_ __d_atanpi_ +#define d_cbrt_ __d_cbrt_ +#define d_ceil_ __d_ceil_ +#define d_compound_ __d_compound_ +#define d_copysign_ __d_copysign_ +#define d_cos_ __d_cos_ +#define d_cosd_ __d_cosd_ +#define d_cosh_ __d_cosh_ +#define d_cosp_ __d_cosp_ +#define d_cospi_ __d_cospi_ +#define d_erf_ __d_erf_ +#define d_erfc_ __d_erfc_ +#define d_exp10_ __d_exp10_ +#define d_exp2_ __d_exp2_ +#define d_exp_ __d_exp_ +#define d_expm1_ __d_expm1_ +#define d_fabs_ __d_fabs_ +#define d_floor_ __d_floor_ +#define d_fmod_ __d_fmod_ +#define d_get_addrans_ __d_get_addrans_ +#define d_hypot_ __d_hypot_ +#define d_infinity_ __d_infinity_ +#define d_init_addrans_ __d_init_addrans_ +#define d_j0_ __d_j0_ +#define d_j1_ __d_j1_ +#define d_jn_ __d_jn_ +#define d_lcran_ __d_lcran_ +#define d_lcrans_ __d_lcrans_ +#define d_lgamma_ __d_lgamma_ +#define d_lgamma_r_ __d_lgamma_r_ +#define d_log10_ __d_log10_ +#define d_log1p_ __d_log1p_ +#define d_log2_ __d_log2_ +#define d_log_ __d_log_ +#define d_logb_ __d_logb_ +#define d_max_normal_ __d_max_normal_ +#define d_max_subnormal_ __d_max_subnormal_ +#define d_min_normal_ __d_min_normal_ +#define d_min_subnormal_ __d_min_subnormal_ +#define d_mwcran_ __d_mwcran_ +#define d_mwcrans_ __d_mwcrans_ +#define d_nextafter_ __d_nextafter_ +#define d_pow_ __d_pow_ +#define d_quiet_nan_ __d_quiet_nan_ +#define d_remainder_ __d_remainder_ +#define d_rint_ __d_rint_ +#define d_scalb_ __d_scalb_ +#define d_scalbn_ __d_scalbn_ +#define d_set_addrans_ __d_set_addrans_ +#define d_shufrans_ __d_shufrans_ +#define d_signaling_nan_ __d_signaling_nan_ +#define d_significand_ __d_significand_ +#define d_sin_ __d_sin_ +#define d_sincos_ __d_sincos_ +#define d_sincosd_ __d_sincosd_ +#define d_sincosp_ __d_sincosp_ +#define d_sincospi_ __d_sincospi_ +#define d_sind_ __d_sind_ +#define d_sinh_ __d_sinh_ +#define d_sinp_ __d_sinp_ +#define d_sinpi_ __d_sinpi_ +#define d_sqrt_ __d_sqrt_ +#define d_tan_ __d_tan_ +#define d_tand_ __d_tand_ +#define d_tanh_ __d_tanh_ +#define d_tanp_ __d_tanp_ +#define d_tanpi_ __d_tanpi_ +#define d_y0_ __d_y0_ +#define d_y1_ __d_y1_ +#define d_yn_ __d_yn_ +#define drem __drem +#define erf __erf +#define erfc __erfc +#define erfcf __erfcf +#define erfcl __erfcl +#define erff __erff +#define erfl __erfl +#define exp __exp +#define exp10 __exp10 +#define exp10f __exp10f +#define exp10l __exp10l +#define exp2 __exp2 +#define exp2f __exp2f +#define exp2l __exp2l +#define expf __expf +#define expl __expl +#define expm1 __expm1 +#define expm1f __expm1f +#define expm1l __expm1l +#define fabs __fabs +#define fabsf __fabsf +#define fabsl __fabsl +#define fdim __fdim /* C99 */ +#define fdimf __fdimf /* C99 */ +#define fdiml __fdiml /* C99 */ +#define finitef __finitef +#define finitel __finitel +#define floor __floor +#define floorf __floorf +#define floorl __floorl +#define fma __fma /* C99 */ +#define fmaf __fmaf /* C99 */ +#define fmal __fmal /* C99 */ +#define fmax __fmax /* C99 */ +#define fmaxf __fmaxf /* C99 */ +#define fmaxl __fmaxl /* C99 */ +#define fmin __fmin /* C99 */ +#define fminf __fminf /* C99 */ +#define fminl __fminl /* C99 */ +#define fmod __fmod +#define fmodf __fmodf +#define fmodl __fmodl +#define fp_class __fp_class +#define fp_classf __fp_classf +#define fp_classl __fp_classl +#define frexp __frexp /* S10 */ +#define frexpf __frexpf /* S10 */ +#define frexpl __frexpl /* S10 */ +#define gamma __gamma +#define gamma_r __gamma_r +#define gammaf __gammaf +#define gammaf_r __gammaf_r +#define gammal __gammal +#define gammal_r __gammal_r +#define gradual_underflow_ __gradual_underflow_ +#define hypot __hypot +#define hypotf __hypotf +#define hypotl __hypotl +#define i_addran_ __i_addran_ +#define i_addrans_ __i_addrans_ +#define i_get_addrans_ __i_get_addrans_ +#define i_get_lcrans_ __i_get_lcrans_ +#define i_get_mwcrans_ __i_get_mwcrans_ +#define i_init_addrans_ __i_init_addrans_ +#define i_init_lcrans_ __i_init_lcrans_ +#define i_init_mwcrans_ __i_init_mwcrans_ +#define i_lcran_ __i_lcran_ +#define i_lcrans_ __i_lcrans_ +#define i_llmwcran_ __i_llmwcran_ +#define i_llmwcrans_ __i_llmwcrans_ +#define i_mwcran_ __i_mwcran_ +#define i_mwcrans_ __i_mwcrans_ +#define i_set_addrans_ __i_set_addrans_ +#define i_set_lcrans_ __i_set_lcrans_ +#define i_set_mwcrans_ __i_set_mwcrans_ +#define i_shufrans_ __i_shufrans_ +#define id_finite_ __id_finite_ +#define id_fp_class_ __id_fp_class_ +#define id_ilogb_ __id_ilogb_ +#define id_irint_ __id_irint_ +#define id_isinf_ __id_isinf_ +#define id_isnan_ __id_isnan_ +#define id_isnormal_ __id_isnormal_ +#define id_issubnormal_ __id_issubnormal_ +#define id_iszero_ __id_iszero_ +#define id_nint_ __id_nint_ +#define id_signbit_ __id_signbit_ +#define ieee_flags __ieee_flags +#define ieee_flags_ __ieee_flags_ +#define ieee_handler __ieee_handler +#define ieee_handler_ __ieee_handler_ +#define ieee_handlers __ieee_handlers +#define ieee_retrospective __ieee_retrospective +#define ieee_retrospective_ __ieee_retrospective_ +#define ilogb __ilogb +#define ilogbf __ilogbf +#define ilogbl __ilogbl +#define infinity __infinity +#define infinityf __infinityf +#define infinityl __infinityl +#define iq_finite_ __iq_finite_ +#define iq_fp_class_ __iq_fp_class_ +#define iq_ilogb_ __iq_ilogb_ +#define iq_isinf_ __iq_isinf_ +#define iq_isnan_ __iq_isnan_ +#define iq_isnormal_ __iq_isnormal_ +#define iq_issubnormal_ __iq_issubnormal_ +#define iq_iszero_ __iq_iszero_ +#define iq_signbit_ __iq_signbit_ +#define ir_finite_ __ir_finite_ +#define ir_fp_class_ __ir_fp_class_ +#define ir_ilogb_ __ir_ilogb_ +#define ir_irint_ __ir_irint_ +#define ir_isinf_ __ir_isinf_ +#define ir_isnan_ __ir_isnan_ +#define ir_isnormal_ __ir_isnormal_ +#define ir_issubnormal_ __ir_issubnormal_ +#define ir_iszero_ __ir_iszero_ +#define ir_nint_ __ir_nint_ +#define ir_signbit_ __ir_signbit_ +#define irint __irint +#define irintf __irintf +#define irintl __irintl +#define isinf __isinf +#define isinff __isinff +#define isinfl __isinfl +#define isnan __isnan +#define isnanf __isnanf +#define isnanl __isnanl +#define isnormal __isnormal +#define isnormalf __isnormalf +#define isnormall __isnormall +#define issubnormal __issubnormal +#define issubnormalf __issubnormalf +#define issubnormall __issubnormall +#define iszero __iszero +#define iszerof __iszerof +#define iszerol __iszerol +#define j0 __j0 +#define j0f __j0f +#define j0l __j0l +#define j1 __j1 +#define j1f __j1f +#define j1l __j1l +#define jn __jn +#define jnf __jnf +#define jnl __jnl +#define ldexp __ldexp /* S10 */ +#define ldexpf __ldexpf /* S10 */ +#define ldexpl __ldexpl /* S10 */ +#define lgamma __lgamma +#define lgamma_r __lgamma_r +#define lgammaf __lgammaf +#define lgammaf_r __lgammaf_r +#define lgammal __lgammal +#define lgammal_r __lgammal_r +#define llrint __llrint /* C99 */ +#define llrintf __llrintf /* C99 */ +#define llrintl __llrintl /* C99 */ +#define llround __llround /* C99 */ +#define llroundf __llroundf /* C99 */ +#define llroundl __llroundl /* C99 */ +#define lrint __lrint /* C99 */ +#define lrintf __lrintf /* C99 */ +#define lrintl __lrintl /* C99 */ +#define lround __lround /* C99 */ +#define lroundf __lroundf /* C99 */ +#define lroundl __lroundl /* C99 */ +#define log __log +#define log10 __log10 +#define log10f __log10f +#define log10l __log10l +#define log1p __log1p +#define log1pf __log1pf +#define log1pl __log1pl +#define log2 __log2 +#define log2f __log2f +#define log2l __log2l +#define logb __logb +#define logbf __logbf +#define logbl __logbl +#define logf __logf +#define logl __logl +#define max_normal __max_normal +#define max_normalf __max_normalf +#define max_normall __max_normall +#define max_subnormal __max_subnormal +#define max_subnormalf __max_subnormalf +#define max_subnormall __max_subnormall +#define min_normal __min_normal +#define min_normalf __min_normalf +#define min_normall __min_normall +#define min_subnormal __min_subnormal +#define min_subnormalf __min_subnormalf +#define min_subnormall __min_subnormall +#define modf __modf /* S10 */ +#define modff __modff /* S10 */ +#define modfl __modfl /* S10 */ +#define nan __nan /* C99 */ +#define nanf __nanf /* C99 */ +#define nanl __nanl /* C99 */ +#define nearbyint __nearbyint /* C99 */ +#define nearbyintf __nearbyintf /* C99 */ +#define nearbyintl __nearbyintl /* C99 */ +#define nextafter __nextafter +#define nextafterf __nextafterf +#define nextafterl __nextafterl +#define nexttoward __nexttoward /* C99 */ +#define nexttowardf __nexttowardf /* C99 */ +#define nexttowardl __nexttowardl /* C99 */ +#define nint __nint +#define nintf __nintf +#define nintl __nintl +#define nonstandard_arithmetic __nonstandard_arithmetic +#define nonstandard_arithmetic_ __nonstandard_arithmetic_ +#define pow __pow +#define pow_di __pow_di +#define pow_li __pow_li +#define pow_ri __pow_ri +#define powf __powf +#define powl __powl +#define q_copysign_ __q_copysign_ +#define q_fabs_ __q_fabs_ +#define q_fmod_ __q_fmod_ +#define q_infinity_ __q_infinity_ +#define q_max_normal_ __q_max_normal_ +#define q_max_subnormal_ __q_max_subnormal_ +#define q_min_normal_ __q_min_normal_ +#define q_min_subnormal_ __q_min_subnormal_ +#define q_nextafter_ __q_nextafter_ +#define q_quiet_nan_ __q_quiet_nan_ +#define q_remainder_ __q_remainder_ +#define q_scalbn_ __q_scalbn_ +#define q_signaling_nan_ __q_signaling_nan_ +#define quiet_nan __quiet_nan +#define quiet_nanf __quiet_nanf +#define quiet_nanl __quiet_nanl +#define r_acos_ __r_acos_ +#define r_acosd_ __r_acosd_ +#define r_acosh_ __r_acosh_ +#define r_acosp_ __r_acosp_ +#define r_acospi_ __r_acospi_ +#define r_addran_ __r_addran_ +#define r_addrans_ __r_addrans_ +#define r_aint_ __r_aint_ +#define r_anint_ __r_anint_ +#define r_annuity_ __r_annuity_ +#define r_asin_ __r_asin_ +#define r_asind_ __r_asind_ +#define r_asinh_ __r_asinh_ +#define r_asinp_ __r_asinp_ +#define r_asinpi_ __r_asinpi_ +#define r_atan2_ __r_atan2_ +#define r_atan2d_ __r_atan2d_ +#define r_atan2pi_ __r_atan2pi_ +#define r_atan_ __r_atan_ +#define r_atand_ __r_atand_ +#define r_atanh_ __r_atanh_ +#define r_atanp_ __r_atanp_ +#define r_atanpi_ __r_atanpi_ +#define r_cbrt_ __r_cbrt_ +#define r_ceil_ __r_ceil_ +#define r_compound_ __r_compound_ +#define r_copysign_ __r_copysign_ +#define r_cos_ __r_cos_ +#define r_cosd_ __r_cosd_ +#define r_cosh_ __r_cosh_ +#define r_cosp_ __r_cosp_ +#define r_cospi_ __r_cospi_ +#define r_erf_ __r_erf_ +#define r_erfc_ __r_erfc_ +#define r_exp10_ __r_exp10_ +#define r_exp2_ __r_exp2_ +#define r_exp_ __r_exp_ +#define r_expm1_ __r_expm1_ +#define r_fabs_ __r_fabs_ +#define r_floor_ __r_floor_ +#define r_fmod_ __r_fmod_ +#define r_get_addrans_ __r_get_addrans_ +#define r_hypot_ __r_hypot_ +#define r_infinity_ __r_infinity_ +#define r_init_addrans_ __r_init_addrans_ +#define r_j0_ __r_j0_ +#define r_j1_ __r_j1_ +#define r_jn_ __r_jn_ +#define r_lcran_ __r_lcran_ +#define r_lcrans_ __r_lcrans_ +#define r_lgamma_ __r_lgamma_ +#define r_lgamma_r_ __r_lgamma_r_ +#define r_log10_ __r_log10_ +#define r_log1p_ __r_log1p_ +#define r_log2_ __r_log2_ +#define r_log_ __r_log_ +#define r_logb_ __r_logb_ +#define r_max_normal_ __r_max_normal_ +#define r_max_subnormal_ __r_max_subnormal_ +#define r_min_normal_ __r_min_normal_ +#define r_min_subnormal_ __r_min_subnormal_ +#define r_mwcran_ __r_mwcran_ +#define r_mwcrans_ __r_mwcrans_ +#define r_nextafter_ __r_nextafter_ +#define r_pow_ __r_pow_ +#define r_quiet_nan_ __r_quiet_nan_ +#define r_remainder_ __r_remainder_ +#define r_rint_ __r_rint_ +#define r_scalb_ __r_scalb_ +#define r_scalbn_ __r_scalbn_ +#define r_set_addrans_ __r_set_addrans_ +#define r_shufrans_ __r_shufrans_ +#define r_signaling_nan_ __r_signaling_nan_ +#define r_significand_ __r_significand_ +#define r_sin_ __r_sin_ +#define r_sincos_ __r_sincos_ +#define r_sincosd_ __r_sincosd_ +#define r_sincosp_ __r_sincosp_ +#define r_sincospi_ __r_sincospi_ +#define r_sind_ __r_sind_ +#define r_sinh_ __r_sinh_ +#define r_sinp_ __r_sinp_ +#define r_sinpi_ __r_sinpi_ +#define r_sqrt_ __r_sqrt_ +#define r_tan_ __r_tan_ +#define r_tand_ __r_tand_ +#define r_tanh_ __r_tanh_ +#define r_tanp_ __r_tanp_ +#define r_tanpi_ __r_tanpi_ +#define r_y0_ __r_y0_ +#define r_y1_ __r_y1_ +#define r_yn_ __r_yn_ +#define remainder __remainder +#define remainderf __remainderf +#define remainderl __remainderl +#define remquo __remquo /* C99 */ +#define remquof __remquof /* C99 */ +#define remquol __remquol /* C99 */ +#define rint __rint +#define rintf __rintf +#define rintl __rintl +#define round __round /* C99 */ +#define roundf __roundf /* C99 */ +#define roundl __roundl /* C99 */ +#define scalb __scalb +#define scalbf __scalbf +#define scalbl __scalbl +#define scalbln __scalbln /* C99 */ +#define scalblnf __scalblnf /* C99 */ +#define scalblnl __scalblnl /* C99 */ +#define scalbn __scalbn +#define scalbnf __scalbnf +#define scalbnl __scalbnl +#define sigfpe __sigfpe +#define sigfpe_ __sigfpe_ +#define signaling_nan __signaling_nan +#define signaling_nanf __signaling_nanf +#define signaling_nanl __signaling_nanl +#define signbit __signbit +#define signbitf __signbitf +#define signbitl __signbitl +#define signgam __signgam +#define signgamf __signgamf +#define signgaml __signgaml +#define significand __significand +#define significandf __significandf +#define significandl __significandl +#define sin __sin +#define sincos __sincos +#define sincosd __sincosd +#define sincosdf __sincosdf +#define sincosdl __sincosdl +#define sincosf __sincosf +#define sincosl __sincosl +#define sincosp __sincosp +#define sincospf __sincospf +#define sincospi __sincospi +#define sincospif __sincospif +#define sincospil __sincospil +#define sincospl __sincospl +#define sind __sind +#define sindf __sindf +#define sindl __sindl +#define sinf __sinf +#define sinh __sinh +#define sinhf __sinhf +#define sinhl __sinhl +#define sinl __sinl +#define sinp __sinp +#define sinpf __sinpf +#define sinpi __sinpi +#define sinpif __sinpif +#define sinpil __sinpil +#define sinpl __sinpl +#define smwcran_ __smwcran_ +#define sqrt __sqrt +#define sqrtf __sqrtf +#define sqrtl __sqrtl +#define standard_arithmetic __standard_arithmetic +#define standard_arithmetic_ __standard_arithmetic_ +#define tan __tan +#define tand __tand +#define tandf __tandf +#define tandl __tandl +#define tanf __tanf +#define tanh __tanh +#define tanhf __tanhf +#define tanhl __tanhl +#define tanl __tanl +#define tanp __tanp +#define tanpf __tanpf +#define tanpi __tanpi +#define tanpif __tanpif +#define tanpil __tanpil +#define tanpl __tanpl +#define tgamma __tgamma /* C99 */ +#define tgammaf __tgammaf /* C99 */ +#define tgammal __tgammal /* C99 */ +#define trunc __trunc /* C99 */ +#define truncf __truncf /* C99 */ +#define truncl __truncl /* C99 */ +#define u_addrans_ __u_addrans_ +#define u_lcrans_ __u_lcrans_ +#define u_llmwcran_ __u_llmwcran_ +#define u_llmwcrans_ __u_llmwcrans_ +#define u_mwcran_ __u_mwcran_ +#define u_mwcrans_ __u_mwcrans_ +#define u_shufrans_ __u_shufrans_ +#define y0 __y0 +#define y0f __y0f +#define y0l __y0l +#define y1 __y1 +#define y1f __y1f +#define y1l __y1l +#define yn __yn +#define ynf __ynf +#define ynl __ynl + +/* + * these are libdl entry points + */ +#define dlclose _dlclose +#define dlopen _dlopen +#define dlsym _dlsym + +/* + * these are libc entry points + */ +#define finite _finite +#define fpclass _fpclass +#define isnand _isnand +#define sigaction _sigaction +#define sigemptyset _sigemptyset +#define unordered _unordered +#define write _write +#ifdef _REENTRANT +#define mutex_lock _mutex_lock +#define mutex_unlock _mutex_unlock +#define thr_getspecific _thr_getspecific +#define thr_keycreate _thr_keycreate +#define thr_main _thr_main +#define thr_setspecific _thr_setspecific +#endif + +#endif /* defined(ELFOBJ) && !defined(lint) */ + +#endif /* _LIBM_SYNONYMS_H */ diff --git a/usr/src/libm/src/C/libm_thread.h b/usr/src/libm/src/C/libm_thread.h new file mode 100644 index 0000000..ad30648 --- /dev/null +++ b/usr/src/libm/src/C/libm_thread.h @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBM_THREAD_H +#define _LIBM_THREAD_H + +#pragma ident "@(#)libm_thread.h 1.6 06/01/31 SMI" + +#include <synch.h> +#include <thread.h> + +/* + * -lthread function(s) not prototyped anywhere + */ +extern int thr_main(void); +/* + * function call(s) local to libsunmath + */ +extern void *__tsd_alloc(thread_key_t *, int, int); +#endif /* _LIBM_THREAD_H */ diff --git a/usr/src/libm/src/C/libmv1.c b/usr/src/libm/src/C/libmv1.c new file mode 100644 index 0000000..16f9fc3 --- /dev/null +++ b/usr/src/libm/src/C/libmv1.c @@ -0,0 +1,661 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)libmv1.c 1.4 06/01/31 SMI" + +#pragma weak _lib_version = __libm_lib_version +#pragma weak acos = __acos +#pragma weak acosh = __acosh +#pragma weak asin = __asin +#pragma weak asinh = __asinh +#pragma weak atan = __atan +#pragma weak atan2 = __atan2 +#pragma weak atanh = __atanh +#pragma weak cbrt = __cbrt +#pragma weak ceil = __ceil +#pragma weak copysign = __copysign +#pragma weak cos = __cos +#pragma weak cosh = __cosh +#pragma weak erf = __erf +#pragma weak erfc = __erfc +#pragma weak exp = __exp +#pragma weak expm1 = __expm1 +#pragma weak fabs = __fabs +#pragma weak floor = __floor +#pragma weak fmod = __fmod +#pragma weak gamma = __gamma +#pragma weak gamma_r = __gamma_r +#pragma weak hypot = __hypot +#pragma weak ilogb = __ilogb +#pragma weak isnan = __isnan +#pragma weak j0 = __j0 +#pragma weak j1 = __j1 +#pragma weak jn = __jn +#pragma weak lgamma = __lgamma +#pragma weak lgamma_r = __lgamma_r +#pragma weak log = __log +#pragma weak log10 = __log10 +#pragma weak log1p = __log1p +#pragma weak logb = __logb +#pragma weak nextafter = __nextafter +#pragma weak pow = __pow +#pragma weak remainder = __remainder +#pragma weak rint = __rint +#pragma weak scalb = __scalb +#pragma weak scalbn = __scalbn +#pragma weak signgam = __signgam +#pragma weak significand = __significand +#pragma weak sin = __sin +#pragma weak sinh = __sinh +#pragma weak sqrt = __sqrt +#pragma weak tan = __tan +#pragma weak tanh = __tanh +#pragma weak y0 = __y0 +#pragma weak y1 = __y1 +#pragma weak yn = __yn + +#include <math.h> + +const enum version __libm_lib_version = libm_ieee; +int __signgam = 0; + +#if !defined(__sparcv9) && !defined(__amd64) +/* ARGSUSED */ +int * +__libm_errno(void) { + return (0); +} +#endif + +/* ARGSUSED */ +int +__libm__rem_pio2(double x, double *y) { + return (0); +} + +/* ARGSUSED */ +int +__libm__rem_pio2m(double *x, double *y, int e0, int nx, int p, const int *ip) { + return (0); +} + +/* ARGSUSED */ +double +__acos(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__acosh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__asin(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__asinh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__atan(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__atan2(double y, double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__atanh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__cbrt(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__ceil(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__copysign(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__cos(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__cosh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__erf(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__erfc(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__exp(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__expm1(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__fabs(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__floor(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__fmod(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__gamma(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__gamma_r(double x, int *signgamp) { + return (0.0); +} + +/* ARGSUSED */ +double +__hypot(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +int +__ilogb(double x) { + return (0); +} + +/* ARGSUSED */ +int +__isnan(double x) { + return (0); +} + +/* ARGSUSED */ +double +__j0(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__j1(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__jn(int n, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__lgamma(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__lgamma_r(double x, int *signgamp) { + return (0.0); +} + +/* ARGSUSED */ +double +__log(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__log10(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__log1p(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__logb(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__nextafter(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__pow(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__remainder(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__rint(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__scalb(double x, double y) { + return (0.0); +} + +/* ARGSUSED */ +double +__scalbn(double x, int n) { + return (0.0); +} + +/* ARGSUSED */ +double +__significand(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__sin(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__sinh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__sqrt(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__tan(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__tanh(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__y0(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__y1(double x) { + return (0.0); +} + +/* ARGSUSED */ +double +__yn(int n, double x) { + return (0.0); +} + +/* ARGSUSED */ +int +matherr(struct exception *excep) { + return (0); +} + +/* ARGSUSED */ +float +__acosf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__asinf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__atanf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__atan2f(float y, float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__ceilf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__cosf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__coshf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__expf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__fabsf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__floorf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__fmodf(float x, float y) { + return (0.0F); +} + +/* ARGSUSED */ +float +__frexpf(float x, int *e) { + return (0.0F); +} + +/* ARGSUSED */ +float +__ldexpf(float x, int n) { + return (0.0F); +} + +/* ARGSUSED */ +float +__logf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__log10f(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__modff(float x, float *iptr) { + return (0.0F); +} + +/* ARGSUSED */ +float +__powf(float x, float y) { + return (0.0F); +} + +/* ARGSUSED */ +float +__sinf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__sinhf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__sqrtf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__tanf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +float +__tanhf(float x) { + return (0.0F); +} + +/* ARGSUSED */ +long double +__acosl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__asinl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__atanl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__atan2l(long double y, long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__ceill(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__cosl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__coshl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__expl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__fabsl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__floorl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__fmodl(long double x, long double y) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__frexpl(long double x, int *e) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__ldexpl(long double x, int n) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__logl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__log10l(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__modfl(long double x, long double *iptr) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__powl(long double x, long double y) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__sinl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__sinhl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__sqrtl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__tanl(long double x) { + return (0.0L); +} + +/* ARGSUSED */ +long double +__tanhl(long double x) { + return (0.0L); +} diff --git a/usr/src/libm/src/C/log.c b/usr/src/libm/src/C/log.c new file mode 100644 index 0000000..ddedf57 --- /dev/null +++ b/usr/src/libm/src/C/log.c @@ -0,0 +1,219 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)log.c 1.29 06/01/23 SMI" + +#pragma weak log = __log + +/* INDENT OFF */ +/* + * log(x) + * Table look-up algorithm with product polynomial approximation. + * By K.C. Ng, Oct 23, 2004. Updated Oct 18, 2005. + * + * (a). For x in [1-0.125, 1+0.1328125], using a special approximation: + * Let f = x - 1 and z = f*f. + * return f + ((a1*z) * + * ((a2 + (a3*f)*(a4+f)) + (f*z)*(a5+f))) * + * (((a6 + f*(a7+f)) + (f*z)*(a8+f)) * + * ((a9 + (a10*f)*(a11+f)) + (f*z)*(a12+f))) + * a1 -6.88821452420390473170286327331268694251775741577e-0002, + * a2 1.97493380704769294631262255279580131173133850098e+0000, + * a3 2.24963218866067560242072431719861924648284912109e+0000, + * a4 -9.02975906958474405783476868236903101205825805664e-0001, + * a5 -1.47391630715542865104339398385491222143173217773e+0000, + * a6 1.86846544648220058704168877738993614912033081055e+0000, + * a7 1.82277370459347465292410106485476717352867126465e+0000, + * a8 1.25295479915214102994980294170090928673744201660e+0000, + * a9 1.96709676945198275177517643896862864494323730469e+0000, + * a10 -4.00127989749189894030934055990655906498432159424e-0001, + * a11 3.01675528558798333733648178167641162872314453125e+0000, + * a12 -9.52325445049240770778453679668018594384193420410e-0001, + * + * with remez error |(log(1+f) - P(f))/f| <= 2**-56.81 and + * + * (b). For 0.09375 <= x < 24 + * Use an 8-bit table look-up (3-bit for exponent and 5 bit for + * significand): + * Let ix stands for the high part of x in IEEE double format. + * Since 0.09375 <= x < 24, we have + * 0x3fb80000 <= ix < 0x40380000. + * Let j = (ix - 0x3fb80000) >> 15. Then 0 <= j < 256. Choose + * a Y[j] such that HIWORD(Y[j]) ~ 0x3fb8400 + (j<<15) (the middle + * number between 0x3fb80000 + (j<<15) and 3fb80000 + ((j+1)<<15)), + * and at the same time 1/Y[j] as well as log(Y[j]) are very close + * to 53-bits floating point numbers. + * A table of Y[j], 1/Y[j], and log(Y[j]) are pre-computed and thus + * log(x) = log(Y[j]) + log(1 + (x-Y[j])*(1/Y[j])) + * = log(Y[j]) + log(1 + s) + * where + * s = (x-Y[j])*(1/Y[j]) + * We compute max (x-Y[j])*(1/Y[j]) for the chosen Y[j] and obtain + * |s| < 0.0154. By applying remez algorithm with Product Polynomial + * Approximiation, we find the following approximated of log(1+s) + * (b1*s)*(b2+s*(b3+s))*((b4+s*b5)+(s*s)*(b6+s))*(b7+s*(b8+s)) + * with remez error |log(1+s) - P(s)| <= 2**-63.5 + * + * (c). Otherwise, get "n", the exponent of x, and then normalize x to + * z in [1,2). Then similar to (b) find a Y[i] that matches z to 5.5 + * significant bits. Then + * log(x) = n*ln2 + log(Y[i]) + log(z/Y[i]). + * + * Special cases: + * log(x) is NaN with signal if x < 0 (including -INF) ; + * log(+INF) is +INF; log(0) is -INF with signal; + * log(NaN) is that NaN with no signal. + * + * Maximum error observed: less than 0.90 ulp + * + * Constants: + * The hexadecimal values are the intended ones for the following constants. + * The decimal values may be used, provided that the compiler will convert + * from decimal to binary accurately enough to produce the hexadecimal values + * shown. + */ +/* INDENT ON */ + +#include "libm.h" + +extern const double _TBL_log[]; + +static const double P[] = { +/* ONE */ 1.0, +/* TWO52 */ 4503599627370496.0, +/* LN2HI */ 6.93147180369123816490e-01, /* 3fe62e42, fee00000 */ +/* LN2LO */ 1.90821492927058770002e-10, /* 3dea39ef, 35793c76 */ +/* A1 */ -6.88821452420390473170286327331268694251775741577e-0002, +/* A2 */ 1.97493380704769294631262255279580131173133850098e+0000, +/* A3 */ 2.24963218866067560242072431719861924648284912109e+0000, +/* A4 */ -9.02975906958474405783476868236903101205825805664e-0001, +/* A5 */ -1.47391630715542865104339398385491222143173217773e+0000, +/* A6 */ 1.86846544648220058704168877738993614912033081055e+0000, +/* A7 */ 1.82277370459347465292410106485476717352867126465e+0000, +/* A8 */ 1.25295479915214102994980294170090928673744201660e+0000, +/* A9 */ 1.96709676945198275177517643896862864494323730469e+0000, +/* A10 */ -4.00127989749189894030934055990655906498432159424e-0001, +/* A11 */ 3.01675528558798333733648178167641162872314453125e+0000, +/* A12 */ -9.52325445049240770778453679668018594384193420410e-0001, +/* B1 */ -1.25041641589283658575482149899471551179885864258e-0001, +/* B2 */ 1.87161713283355151891381127914642725337613123482e+0000, +/* B3 */ -1.89082956295731507978530316904652863740921020508e+0000, +/* B4 */ -2.50562891673640253387134180229622870683670043945e+0000, +/* B5 */ 1.64822828085258366037635369139024987816810607910e+0000, +/* B6 */ -1.24409107065868340669112512841820716857910156250e+0000, +/* B7 */ 1.70534231658220414296067701798165217041969299316e+0000, +/* B8 */ 1.99196833784655646937267192697618156671524047852e+0000, +}; + +#define ONE P[0] +#define TWO52 P[1] +#define LN2HI P[2] +#define LN2LO P[3] +#define A1 P[4] +#define A2 P[5] +#define A3 P[6] +#define A4 P[7] +#define A5 P[8] +#define A6 P[9] +#define A7 P[10] +#define A8 P[11] +#define A9 P[12] +#define A10 P[13] +#define A11 P[14] +#define A12 P[15] +#define B1 P[16] +#define B2 P[17] +#define B3 P[18] +#define B4 P[19] +#define B5 P[20] +#define B6 P[21] +#define B7 P[22] +#define B8 P[23] + +double +log(double x) { + double *tb, dn, dn1, s, z, r, w; + int i, hx, ix, n, lx; + + n = 0; + hx = ((int *)&x)[HIWORD]; + ix = hx & 0x7fffffff; + lx = ((int *)&x)[LOWORD]; + + /* subnormal,0,negative,inf,nan */ + if ((hx + 0x100000) < 0x200000) { + if (ix > 0x7ff00000 || (ix == 0x7ff00000 && lx != 0)) /* nan */ + return (x * x); + if (((hx << 1) | lx) == 0) /* zero */ + return (_SVID_libm_err(x, x, 16)); + if (hx < 0) /* negative */ + return (_SVID_libm_err(x, x, 17)); + if (((hx - 0x7ff00000) | lx) == 0) /* +inf */ + return (x); + + /* x must be positive and subnormal */ + x *= TWO52; + n = -52; + ix = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + } + + i = ix >> 19; + if (i >= 0x7f7 && i <= 0x806) { + /* 0.09375 (0x3fb80000) <= x < 24 (0x40380000) */ + if (ix >= 0x3fec0000 && ix < 0x3ff22000) { + /* 0.875 <= x < 1.125 */ + s = x - ONE; + z = s * s; + if (((ix - 0x3ff00000) | lx) == 0) /* x = 1 */ + return (z); + r = (A10 * s) * (A11 + s); + w = z * s; + return (s + ((A1 * z) * + (A2 + ((A3 * s) * (A4 + s) + w * (A5 + s)))) * + ((A6 + (s * (A7 + s) + w * (A8 + s))) * + (A9 + (r + w * (A12 + s))))); + } else { + i = (ix - 0x3fb80000) >> 15; + tb = (double *)_TBL_log + (i + i + i); + s = (x - tb[0]) * tb[1]; + return (tb[2] + ((B1 * s) * (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s)))); + } + } else { + dn = (double)(n + ((ix >> 20) - 0x3ff)); + dn1 = dn * LN2HI; + i = (ix & 0x000fffff) | 0x3ff00000; /* scale x to [1,2] */ + ((int *)&x)[HIWORD] = i; + i = (i - 0x3fb80000) >> 15; + tb = (double *)_TBL_log + (i + i + i); + s = (x - tb[0]) * tb[1]; + dn = dn * LN2LO + tb[2]; + return (dn1 + (dn + ((B1 * s) * (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s))))); + } +} diff --git a/usr/src/libm/src/C/log10.c b/usr/src/libm/src/C/log10.c new file mode 100644 index 0000000..29bf07b --- /dev/null +++ b/usr/src/libm/src/C/log10.c @@ -0,0 +1,217 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)log10.c 1.23 06/01/23 SMI" + +#pragma weak log10 = __log10 + +/* INDENT OFF */ +/* + * log10(x) = log(x)/log10 + * + * Base on Table look-up algorithm with product polynomial + * approximation for log(x). + * + * By K.C. Ng, Nov 29, 2004 + * + * (a). For x in [1-0.125, 1+0.125], from log.c we have + * log(x) = f + ((a1*f^2) * + * ((a2 + (a3*f)*(a4+f)) + (f^3)*(a5+f))) * + * (((a6 + f*(a7+f)) + (f^3)*(a8+f)) * + * ((a9 + (a10*f)*(a11+f)) + (f^3)*(a12+f))) + * where f = x - 1. + * (i) modify a1 <- a1 / log10 + * (ii) 1/log10 = 0.4342944819... + * = 0.4375 - 0.003205518... (7 bit shift) + * Let lgv = 0.4375 - 1/log10, then + * lgv = 0.003205518096748172348871081083395..., + * (iii) f*0.4375 is exact because f has 3 trailing zero. + * (iv) Thus, log10(x) = f*0.4375 - (lgv*f - PPoly) + * + * (b). For 0.09375 <= x < 24 + * Let j = (ix - 0x3fb80000) >> 15. Look up Y[j], 1/Y[j], and log(Y[j]) + * from _TBL_log.c. Then + * log10(x) = log10(Y[j]) + log10(1 + (x-Y[j])*(1/Y[j])) + * = log(Y[j])(1/log10) + log10(1 + s) + * where + * s = (x-Y[j])*(1/Y[j]) + * From log.c, we have log(1+s) = + * 2 2 2 + * (b s) (b + b s + s ) [b + b s + s (b + s)] (b + b s + s ) + * 1 2 3 4 5 6 7 8 + * + * By setting b1 <- b1/log10, we have + * log10(x) = 0.4375 * T - (lgv * T - POLY(s)) + * + * (c). Otherwise, get "n", the exponent of x, and then normalize x to + * z in [1,2). Then similar to (b) find a Y[i] that matches z to 5.5 + * significant bits. Then + * log(x) = n*ln2 + log(Y[i]) + log(z/Y[i]). + * log10(x) = n*(ln2/ln10) + log10(z). + * + * Special cases: + * log10(x) is NaN with signal if x < 0 (including -INF) ; + * log10(+INF) is +INF; log10(0) is -INF with signal; + * log10(NaN) is that NaN with no signal. + * + * Maximum error observed: less than 0.89 ulp + * + * Constants: + * The hexadecimal values are the intended ones for the following constants. + * The decimal values may be used, provided that the compiler will convert + * from decimal to binary accurately enough to produce the hexadecimal values + * shown. + */ +/* INDENT ON */ + +#include "libm.h" + +extern const double _TBL_log[]; + +static const double P[] = { +/* ONE */ 1.0, +/* TWO52 */ 4503599627370496.0, +/* LNAHI */ 3.01029995607677847147e-01, /* 3FD34413 50900000 */ +/* LNALO */ 5.63033480667509769841e-11, /* 3DCEF3FD E623E256 */ +/* A1 */ -2.9142521960136582507385480707044582802184e-02, +/* A2 */ 1.99628461483039965074226529395673424005508422852e+0000, +/* A3 */ 2.26812367662950720159642514772713184356689453125e+0000, +/* A4 */ -9.05030639084976384900471657601883634924888610840e-0001, +/* A5 */ -1.48275767132434044270894446526654064655303955078e+0000, +/* A6 */ 1.88158320939722756293122074566781520843505859375e+0000, +/* A7 */ 1.83309386046986411145098827546462416648864746094e+0000, +/* A8 */ 1.24847063988317086291601754055591300129890441895e+0000, +/* A9 */ 1.98372421445537705508854742220137268304824829102e+0000, +/* A10 */ -3.94711735767898475035764249696512706577777862549e-0001, +/* A11 */ 3.07890395362954372160402272129431366920471191406e+0000, +/* A12 */ -9.60099585275022149311041630426188930869102478027e-0001, +/* B1 */ -5.4304894950350052960838096752491540286689e-02, +/* B2 */ 1.87161713283355151891381127914642725337613123482e+0000, +/* B3 */ -1.89082956295731507978530316904652863740921020508e+0000, +/* B4 */ -2.50562891673640253387134180229622870683670043945e+0000, +/* B5 */ 1.64822828085258366037635369139024987816810607910e+0000, +/* B6 */ -1.24409107065868340669112512841820716857910156250e+0000, +/* B7 */ 1.70534231658220414296067701798165217041969299316e+0000, +/* B8 */ 1.99196833784655646937267192697618156671524047852e+0000, +/* LGH */ 0.4375, +/* LGL */ 0.003205518096748172348871081083395, +/* LG10V */ 0.43429448190325182765112891891660509576226, +}; + +#define ONE P[0] +#define TWO52 P[1] +#define LNAHI P[2] +#define LNALO P[3] +#define A1 P[4] +#define A2 P[5] +#define A3 P[6] +#define A4 P[7] +#define A5 P[8] +#define A6 P[9] +#define A7 P[10] +#define A8 P[11] +#define A9 P[12] +#define A10 P[13] +#define A11 P[14] +#define A12 P[15] +#define B1 P[16] +#define B2 P[17] +#define B3 P[18] +#define B4 P[19] +#define B5 P[20] +#define B6 P[21] +#define B7 P[22] +#define B8 P[23] +#define LGH P[24] +#define LGL P[25] +#define LG10V P[26] + +double +log10(double x) { + double *tb, dn, dn1, s, z, r, w; + int i, hx, ix, n, lx; + + n = 0; + hx = ((int *)&x)[HIWORD]; + ix = hx & 0x7fffffff; + lx = ((int *)&x)[LOWORD]; + + /* subnormal,0,negative,inf,nan */ + if ((hx + 0x100000) < 0x200000) { + if (ix > 0x7ff00000 || (ix == 0x7ff00000 && lx != 0)) /* nan */ + return (x * x); + if (((hx << 1) | lx) == 0) /* zero */ + return (_SVID_libm_err(x, x, 18)); + if (hx < 0) /* negative */ + return (_SVID_libm_err(x, x, 19)); + if (((hx - 0x7ff00000) | lx) == 0) /* +inf */ + return (x); + + /* x must be positive and subnormal */ + x *= TWO52; + n = -52; + ix = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + } + + i = ix >> 19; + if (i >= 0x7f7 && i <= 0x806) { + /* 0.09375 (0x3fb80000) <= x < 24 (0x40380000) */ + if (ix >= 0x3fec0000 && ix < 0x3ff20000) { + /* 0.875 <= x < 1.125 */ + s = x - ONE; + z = s * s; + if (((ix - 0x3ff00000) | lx) == 0) /* x = 1 */ + return (z); + r = (A10 * s) * (A11 + s); + w = z * s; + return (LGH * s - (LGL * s - ((A1 * z) * + ((A2 + (A3 * s) * (A4 + s)) + w * (A5 + s))) * + (((A6 + s * (A7 + s)) + w * (A8 + s)) * + ((A9 + r) + w * (A12 + s))))); + } else { + i = (ix - 0x3fb80000) >> 15; + tb = (double *)_TBL_log + (i + i + i); + s = (x - tb[0]) * tb[1]; + return (LGH * tb[2] - (LGL * tb[2] - ((B1 * s) * + (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s))))); + } + } else { + dn = (double)(n + ((ix >> 20) - 0x3ff)); + dn1 = dn * LNAHI; + i = (ix & 0x000fffff) | 0x3ff00000; /* scale x to [1,2] */ + ((int *)&x)[HIWORD] = i; + i = (i - 0x3fb80000) >> 15; + tb = (double *)_TBL_log + (i + i + i); + s = (x - tb[0]) * tb[1]; + dn = dn * LNALO + tb[2] * LG10V; + return (dn1 + (dn + ((B1 * s) * + (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s))))); + } +} diff --git a/usr/src/libm/src/C/log1p.c b/usr/src/libm/src/C/log1p.c new file mode 100644 index 0000000..845fd0e --- /dev/null +++ b/usr/src/libm/src/C/log1p.c @@ -0,0 +1,201 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)log1p.c 1.23 06/01/23 SMI" + +#pragma weak log1p = __log1p + +/* INDENT OFF */ +/* + * Method : + * 1. Argument Reduction: find k and f such that + * 1+x = 2^k * (1+f), + * where sqrt(2)/2 < 1+f < sqrt(2) . + * + * Note. If k=0, then f=x is exact. However, if k!=0, then f + * may not be representable exactly. In that case, a correction + * term is need. Let u=1+x rounded. Let c = (1+x)-u, then + * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), + * and add back the correction term c/u. + * (Note: when x > 2**53, one can simply return log(x)) + * + * 2. Approximation of log1p(f). + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) + * = 2s + 2/3 s**3 + 2/5 s**5 + ....., + * = 2s + s*R + * We use a special Reme algorithm on [0,0.1716] to generate + * a polynomial of degree 14 to approximate R The maximum error + * of this polynomial approximation is bounded by 2**-58.45. In + * other words, + * 2 4 6 8 10 12 14 + * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s + * (the values of Lp1 to Lp7 are listed in the program) + * and + * | 2 14 | -58.45 + * | Lp1*s +...+Lp7*s - R(z) | <= 2 + * | | + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. + * In order to guarantee error in log below 1ulp, we compute log + * by + * log1p(f) = f - (hfsq - s*(hfsq+R)). + * + * 3. Finally, log1p(x) = k*ln2 + log1p(f). + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) + * Here ln2 is splitted into two floating point number: + * ln2_hi + ln2_lo, + * where n*ln2_hi is always exact for |n| < 2000. + * + * Special cases: + * log1p(x) is NaN with signal if x < -1 (including -INF) ; + * log1p(+INF) is +INF; log1p(-1) is -INF with signal; + * log1p(NaN) is that NaN with no signal. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + * + * Note: Assuming log() return accurate answer, the following + * algorithm can be used to compute log1p(x) to within a few ULP: + * + * u = 1+x; + * if(u==1.0) return x ; else + * return log(u)*(x/(u-1.0)); + * + * See HP-15C Advanced Functions Handbook, p.193. + */ +/* INDENT ON */ + +#include "libm.h" + +static const double xxx[] = { +/* ln2_hi */ 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ +/* ln2_lo */ 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ +/* two54 */ 1.80143985094819840000e+16, /* 43500000 00000000 */ +/* Lp1 */ 6.666666666666735130e-01, /* 3FE55555 55555593 */ +/* Lp2 */ 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ +/* Lp3 */ 2.857142874366239149e-01, /* 3FD24924 94229359 */ +/* Lp4 */ 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ +/* Lp5 */ 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ +/* Lp6 */ 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ +/* Lp7 */ 1.479819860511658591e-01, /* 3FC2F112 DF3E5244 */ +/* zero */ 0.0 +}; +#define ln2_hi xxx[0] +#define ln2_lo xxx[1] +#define two54 xxx[2] +#define Lp1 xxx[3] +#define Lp2 xxx[4] +#define Lp3 xxx[5] +#define Lp4 xxx[6] +#define Lp5 xxx[7] +#define Lp6 xxx[8] +#define Lp7 xxx[9] +#define zero xxx[10] + +double +log1p(double x) { + double hfsq, f, c, s, z, R, u; + int k, hx, hu, ax; + + hx = ((int *)&x)[HIWORD]; /* high word of x */ + ax = hx & 0x7fffffff; + + if (ax >= 0x7ff00000) { /* x is inf or nan */ + if (((hx - 0xfff00000) | ((int *)&x)[LOWORD]) == 0) /* -inf */ + return (_SVID_libm_err(x, x, 44)); + return (x * x); + } + + k = 1; + if (hx < 0x3FDA827A) { /* x < 0.41422 */ + if (ax >= 0x3ff00000) /* x <= -1.0 */ + return (_SVID_libm_err(x, x, x == -1.0 ? 43 : 44)); + if (ax < 0x3e200000) { /* |x| < 2**-29 */ + if (two54 + x > zero && /* raise inexact */ + ax < 0x3c900000) /* |x| < 2**-54 */ + return (x); + else + return (x - x * x * 0.5); + } + if (hx > 0 || hx <= (int)0xbfd2bec3) { /* -0.2929<x<0.41422 */ + k = 0; + f = x; + hu = 1; + } + } + if (k != 0) { + if (hx < 0x43400000) { + u = 1.0 + x; + hu = ((int *)&u)[HIWORD]; /* high word of u */ + k = (hu >> 20) - 1023; + /* + * correction term + */ + c = k > 0 ? 1.0 - (u - x) : x - (u - 1.0); + c /= u; + } else { + u = x; + hu = ((int *)&u)[HIWORD]; /* high word of u */ + k = (hu >> 20) - 1023; + c = 0; + } + hu &= 0x000fffff; + if (hu < 0x6a09e) { /* normalize u */ + ((int *)&u)[HIWORD] = hu | 0x3ff00000; + } else { /* normalize u/2 */ + k += 1; + ((int *)&u)[HIWORD] = hu | 0x3fe00000; + hu = (0x00100000 - hu) >> 2; + } + f = u - 1.0; + } + hfsq = 0.5 * f * f; + if (hu == 0) { /* |f| < 2**-20 */ + if (f == zero) { + if (k == 0) + return (zero); + c += k * ln2_lo; + return (k * ln2_hi + c); + } + R = hfsq * (1.0 - 0.66666666666666666 * f); + if (k == 0) + return (f - R); + return (k * ln2_hi - ((R - (k * ln2_lo + c)) - f)); + } + s = f / (2.0 + f); + z = s * s; + R = z * (Lp1 + z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 + + z * (Lp6 + z * Lp7)))))); + if (k == 0) + return (f - (hfsq - s * (hfsq + R))); + return (k * ln2_hi - ((hfsq - (s * (hfsq + R) + + (k * ln2_lo + c))) - f)); +} diff --git a/usr/src/libm/src/C/log2.c b/usr/src/libm/src/C/log2.c new file mode 100644 index 0000000..8bdfe82 --- /dev/null +++ b/usr/src/libm/src/C/log2.c @@ -0,0 +1,226 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)log2.c 1.16 06/01/31 SMI" + +#pragma weak log2 = __log2 + +/* INDENT OFF */ +/* + * log2(x) = log(x)/log2 + * + * Base on Table look-up algorithm with product polynomial + * approximation for log(x). + * + * By K.C. Ng, Nov 29, 2004 + * + * (a). For x in [1-0.125, 1+0.125], from log.c we have + * log(x) = f + ((a1*f^2) * + * ((a2 + (a3*f)*(a4+f)) + (f^3)*(a5+f))) * + * (((a6 + f*(a7+f)) + (f^3)*(a8+f)) * + * ((a9 + (a10*f)*(a11+f)) + (f^3)*(a12+f))) + * where f = x - 1. + * (i) modify a1 <- a1 / log2 + * (ii) 1/log2 = 1.4426950408889634... + * = 1.5 - 0.057304959... (4 bit shift) + * Let lv = 1.5 - 1/log2, then + * lv = 0.057304959111036592640075318998107956665325, + * (iii) f*1.5 is exact because f has 3 trailing zero. + * (iv) Thus, log2(x) = f*1.5 - (lv*f - PPoly) + * + * (b). For 0.09375 <= x < 24 + * Let j = (ix - 0x3fb80000) >> 15. Look up Y[j], 1/Y[j], and log(Y[j]) + * from _TBL_log.c. Then + * log2(x) = log2(Y[j]) + log2(1 + (x-Y[j])*(1/Y[j])) + * = log(Y[j])(1/log2) + log2(1 + s) + * where + * s = (x-Y[j])*(1/Y[j]) + * From log.c, we have log(1+s) = + * 2 2 2 + * (b s) (b + b s + s ) [b + b s + s (b + s)] (b + b s + s ) + * 1 2 3 4 5 6 7 8 + * + * By setting b1 <- b1/log2, we have + * log2(x) = 1.5 * T - (lv * T - POLY(s)) + * + * (c). Otherwise, get "n", the exponent of x, and then normalize x to + * z in [1,2). Then similar to (b) find a Y[i] that matches z to 5.5 + * significant bits. Then + * log2(x) = n + log2(z). + * + * Special cases: + * log2(x) is NaN with signal if x < 0 (including -INF) ; + * log2(+INF) is +INF; log2(0) is -INF with signal; + * log2(NaN) is that NaN with no signal. + * + * Maximum error observed: less than 0.84 ulp + * + * Constants: + * The hexadecimal values are the intended ones for the following constants. + * The decimal values may be used, provided that the compiler will convert + * from decimal to binary accurately enough to produce the hexadecimal values + * shown. + */ +/* INDENT ON */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" + +extern const double _TBL_log[]; + +static const double P[] = { +/* ONE */ 1.0, +/* TWO52 */ 4503599627370496.0, +/* LN10V */ 1.4426950408889634073599246810018920433347, /* 1/log10 */ +/* ZERO */ 0.0, +/* A1 */ -9.6809362455249638217841932228967194640116e-02, +/* A2 */ 1.99628461483039965074226529395673424005508422852e+0000, +/* A3 */ 2.26812367662950720159642514772713184356689453125e+0000, +/* A4 */ -9.05030639084976384900471657601883634924888610840e-0001, +/* A5 */ -1.48275767132434044270894446526654064655303955078e+0000, +/* A6 */ 1.88158320939722756293122074566781520843505859375e+0000, +/* A7 */ 1.83309386046986411145098827546462416648864746094e+0000, +/* A8 */ 1.24847063988317086291601754055591300129890441895e+0000, +/* A9 */ 1.98372421445537705508854742220137268304824829102e+0000, +/* A10 */ -3.94711735767898475035764249696512706577777862549e-0001, +/* A11 */ 3.07890395362954372160402272129431366920471191406e+0000, +/* A12 */ -9.60099585275022149311041630426188930869102478027e-0001, +/* B1 */ -1.8039695622547469514898963204616532885451e-01, +/* B2 */ 1.87161713283355151891381127914642725337613123482e+0000, +/* B3 */ -1.89082956295731507978530316904652863740921020508e+0000, +/* B4 */ -2.50562891673640253387134180229622870683670043945e+0000, +/* B5 */ 1.64822828085258366037635369139024987816810607910e+0000, +/* B6 */ -1.24409107065868340669112512841820716857910156250e+0000, +/* B7 */ 1.70534231658220414296067701798165217041969299316e+0000, +/* B8 */ 1.99196833784655646937267192697618156671524047852e+0000, +/* LGH */ 1.5, +/* LGL */ 0.057304959111036592640075318998107956665325, +}; + +#define ONE P[0] +#define TWO52 P[1] +#define LN10V P[2] +#define ZERO P[3] +#define A1 P[4] +#define A2 P[5] +#define A3 P[6] +#define A4 P[7] +#define A5 P[8] +#define A6 P[9] +#define A7 P[10] +#define A8 P[11] +#define A9 P[12] +#define A10 P[13] +#define A11 P[14] +#define A12 P[15] +#define B1 P[16] +#define B2 P[17] +#define B3 P[18] +#define B4 P[19] +#define B5 P[20] +#define B6 P[21] +#define B7 P[22] +#define B8 P[23] +#define LGH P[24] +#define LGL P[25] + +double +log2(double x) { + int i, hx, ix, n, lx; + + n = 0; + hx = ((int *) &x)[HIWORD]; ix = hx & 0x7fffffff; + lx = ((int *) &x)[LOWORD]; + + /* subnormal,0,negative,inf,nan */ + if ((hx + 0x100000) < 0x200000) { +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + if (ix >= 0x7ff80000) /* assumes sparc-like QNaN */ + return (x); /* for Cheetah when x is QNaN */ +#endif + if (((hx << 1) | lx) == 0) /* log(0.0) = -inf */ + return (A5 / fabs(x)); + if (hx < 0) { /* x < 0 */ + if (ix >= 0x7ff00000) + return (x - x); /* x is -inf or NaN */ + else + return (ZERO / (x - x)); + } + if (((hx - 0x7ff00000) | lx) == 0) /* log(inf) = inf */ + return (x); + if (ix >= 0x7ff00000) /* log(NaN) = NaN */ + return (x - x); + x *= TWO52; + n = -52; + hx = ((int *) &x)[HIWORD]; ix = hx & 0x7fffffff; + lx = ((int *) &x)[LOWORD]; + } + + /* 0.09375 (0x3fb80000) <= x < 24 (0x40380000) */ + i = ix >> 19; + if (i >= 0x7f7 && i <= 0x806) { + /* 0.875 <= x < 1.125 */ + if (ix >= 0x3fec0000 && ix < 0x3ff20000) { + double s, z, r, w; + s = x - ONE; z = s * s; r = (A10 * s) * (A11 + s); + w = z * s; + if (((ix << 12) | lx) == 0) + return (z); + else + return (LGH * s - (LGL * s - ((A1 * z) * + ((A2 + (A3 * s) * (A4 + s)) + w * (A5 + s))) * + (((A6 + s * (A7 + s)) + w * (A8 + s)) * + ((A9 + r) + w * (A12 + s))))); + } else { + double *tb, s; + i = (ix - 0x3fb80000) >> 15; + tb = (double *) _TBL_log + (i + i + i); + if (((ix << 12) | lx) == 0) /* 2's power */ + return ((double) ((ix >> 20) - 0x3ff)); + s = (x - tb[0]) * tb[1]; + return (LGH * tb[2] - (LGL * tb[2] - ((B1 * s) * + (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s))))); + } + } else { + double *tb, dn, s; + dn = (double) (n + ((ix >> 20) - 0x3ff)); + ix <<= 12; + if ((ix | lx) == 0) + return (dn); + i = ((unsigned) ix >> 12) | 0x3ff00000; /* scale x to [1,2) */ + ((int *) &x)[HIWORD] = i; + i = (i - 0x3fb80000) >> 15; + tb = (double *) _TBL_log + (i + i + i); + s = (x - tb[0]) * tb[1]; + return (dn + (tb[2] * LN10V + ((B1 * s) * + (B2 + s * (B3 + s))) * + (((B4 + s * B5) + (s * s) * (B6 + s)) * + (B7 + s * (B8 + s))))); + } +} diff --git a/usr/src/libm/src/C/logb.c b/usr/src/libm/src/C/logb.c new file mode 100644 index 0000000..83f0022 --- /dev/null +++ b/usr/src/libm/src/C/logb.c @@ -0,0 +1,84 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)logb.c 1.16 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak logb = __logb +#pragma weak _logb = __logb +#endif + +#include "libm.h" +#include "xpg6.h" /* __xpg6 */ +#define _C99SUSv3_logb _C99SUSv3_logb_subnormal_is_like_ilogb + +#if defined(USE_FPSCALE) || defined(__i386) +static const double two52 = 4503599627370496.0; +#else +/* + * v: high part of a non-zero subnormal |x|; w: low part of |x| + */ +static int +ilogb_subnormal(unsigned v, unsigned w) { + int r = -1022 - 52; + + if (v) + r += 32; + else + v = w; + if (v & 0xffff0000) + r += 16, v >>= 16; + if (v & 0xff00) + r += 8, v >>= 8; + if (v & 0xf0) + r += 4, v >>= 4; + v <<= 1; + return (r + ((0xffffaa50 >> v) & 0x3)); +} +#endif /* defined(USE_FPSCALE) */ + +double +logb(double x) { + int *px = (int *) &x, k = px[HIWORD] & ~0x80000000; + + if (k < 0x00100000) { + if ((px[LOWORD] | k) == 0) + return (_SVID_libm_err(x, x, 45)); + else if ((__xpg6 & _C99SUSv3_logb) != 0) { +#if defined(USE_FPSCALE) || defined(__i386) + x *= two52; + return ((double) (((px[HIWORD] & 0x7ff00000) >> 20) + - 1075)); +#else + return ((double) ilogb_subnormal(k, px[LOWORD])); +#endif + } else + return (-1022.0); + } else if (k < 0x7ff00000) + return ((double) ((k >> 20) - 1023)); + else + return (x * x); +} diff --git a/usr/src/libm/src/C/matherr.c b/usr/src/libm/src/C/matherr.c new file mode 100644 index 0000000..29fa363 --- /dev/null +++ b/usr/src/libm/src/C/matherr.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)matherr.c 1.13 06/01/31 SMI" + +#pragma weak matherr = __matherr + +#include "libm.h" + +/* ARGSUSED0 */ +int +__matherr(struct exception *x) { + return 0; +} diff --git a/usr/src/libm/src/C/nextafter.c b/usr/src/libm/src/C/nextafter.c new file mode 100644 index 0000000..1540f25 --- /dev/null +++ b/usr/src/libm/src/C/nextafter.c @@ -0,0 +1,85 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)nextafter.c 1.21 06/01/23 SMI" + +#pragma weak nextafter = __nextafter +#pragma weak _nextafter = __nextafter + +#include "libm.h" +#include <float.h> /* DBL_MIN */ + +double +nextafter(double x, double y) { + int hx, hy, k; + double ans; + unsigned lx; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + hy = ((int *)&y)[HIWORD]; + k = (hx & ~0x80000000) | lx; + + if (x == y) + return (y); /* C99 requirement */ + if (x != x || y != y) + return (x * y); + if (k == 0) { /* x = 0 */ + k = hy & 0x80000000; + ((int *)&ans)[HIWORD] = k; + ((int *)&ans)[LOWORD] = 1; + } else if (hx >= 0) { + if (x > y) { + ((int *)&ans)[LOWORD] = lx - 1; + k = (lx == 0)? hx - 1 : hx; + ((int *)&ans)[HIWORD] = k; + } else { + ((int *)&ans)[LOWORD] = lx + 1; + k = (lx == 0xffffffff)? hx + 1 : hx; + ((int *)&ans)[HIWORD] = k; + } + } else { + if (x < y) { + ((int *)&ans)[LOWORD] = lx - 1; + k = (lx == 0)? hx - 1 : hx; + ((int *)&ans)[HIWORD] = k; + } else { + ((int *)&ans)[LOWORD] = lx + 1; + k = (lx == 0xffffffff)? hx + 1 : hx; + ((int *)&ans)[HIWORD] = k; + } + } + k = (k >> 20) & 0x7ff; + if (k == 0x7ff) { + /* overflow */ + return (_SVID_libm_err(x, y, 46)); +#if !defined(__lint) + } else if (k == 0) { + /* underflow */ + volatile double dummy = DBL_MIN * copysign(DBL_MIN, x); +#endif + } + return (ans); +} diff --git a/usr/src/libm/src/C/pow.c b/usr/src/libm/src/C/pow.c new file mode 100644 index 0000000..208a741 --- /dev/null +++ b/usr/src/libm/src/C/pow.c @@ -0,0 +1,342 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)pow.c 1.44 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak pow = __pow +#endif + +/* + * pow(x,y) return x**y + * n + * Method: Let x = 2 * (1+f) + * 1. Compute and return log2(x) in two pieces: + * log2(x) = w1 + w2, + * where w1 has 24 bits trailing zero. + * 2. Perform y*log2(x) by simulating muti-precision arithmetic + * 3. Return x**y = exp2(y*log(x)) + * + * Special cases: + * 1. (anything) ** +-0 is 1 + * 1'. 1 ** (anything) is 1 (C99; 1 ** +-INF/NAN used to be NAN) + * 2. (anything) ** 1 is itself + * 3. (anything except 1) ** NAN is NAN ("except 1" is C99) + * 4. NAN ** (anything except 0) is NAN + * 5. +-(|x| > 1) ** +INF is +INF + * 6. +-(|x| > 1) ** -INF is +0 + * 7. +-(|x| < 1) ** +INF is +0 + * 8. +-(|x| < 1) ** -INF is +INF + * 9. -1 ** +-INF is 1 (C99; -1 ** +-INF used to be NAN) + * 10. +0 ** (+anything except 0, NAN) is +0 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 + * 12. +0 ** (-anything except 0, NAN) is +INF + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) + * 15. +INF ** (+anything except 0,NAN) is +INF + * 16. +INF ** (-anything except 0,NAN) is +0 + * 17. -INF ** (anything) = -0 ** (-anything) + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) + * 19. (-anything except 0 and inf) ** (non-integer) is NAN + * + * Accuracy: + * pow(x,y) returns x**y nearly rounded. In particular + * pow(integer,integer) + * always returns the correct integer provided it is representable. + */ + +#include "libm.h" +#include "xpg6.h" /* __xpg6 */ +#define _C99SUSv3_pow _C99SUSv3_pow_treats_Inf_as_an_even_int + +static const double zero = 0.0, one = 1.0, two = 2.0; + +extern const double _TBL_log2_hi[], _TBL_log2_lo[]; +static const double + two53 = 9007199254740992.0, + A1_hi = 2.8853900432586669921875, + A1_lo = 3.8519259825035041963606002e-8, + A1 = 2.885390081777926817222541963606002026086e+0000, + A2 = 9.617966939207270828380543979852286255862e-0001, + A3 = 5.770807680887875964868853124873696201995e-0001, + B0_hi = 2.8853900432586669921875, + B0_lo = 3.8519259822532793056374320585e-8, + B0 = 2.885390081777926814720293056374320585689e+0000, + B1 = 9.617966939259755138949202350396200257632e-0001, + B2 = 5.770780163585687000782112776448797953382e-0001, + B3 = 4.121985488948771523290174512461778354953e-0001, + B4 = 3.207590534812432970433641789022666850193e-0001; + +static double +log2_x(double x, double *w) { + double f, s, z, qn, h, t; + int *px = (int *) &x; + int *pz = (int *) &z; + int i, j, ix, n; + + n = 0; + ix = px[HIWORD]; + if (ix >= 0x3fef03f1 && ix < 0x3ff08208) { /* 65/63 > x > 63/65 */ + double f1, v; + f = x - one; + if (((ix - 0x3ff00000) | px[LOWORD]) == 0) { + *w = zero; + return (zero); /* log2(1)= +0 */ + } + qn = one / (two + f); + s = f * qn; /* |s|<2**-6 */ + v = s * s; + h = (double) ((float) s); + f1 = (double) ((float) f); + t = qn * (((f - two * h) - h * f1) - h * (f - f1)); + /* s = h+t */ + f1 = h * B0_lo + s * (v * (B1 + v * (B2 + v * (B3 + v * B4)))); + t = f1 + t * B0; + h *= B0_hi; + s = (double) ((float) (h + t)); + *w = t - (s - h); + return (s); + } + if (ix < 0x00100000) { /* subnormal x */ + x *= two53; + n = -53; + ix = px[HIWORD]; + } + /* LARGE N */ + n += ((ix + 0x1000) >> 20) - 0x3ff; + ix = (ix & 0x000fffff) | 0x3ff00000; /* scale x to [1,2] */ + px[HIWORD] = ix; + i = ix + 0x1000; + pz[HIWORD] = i & 0xffffe000; + pz[LOWORD] = 0; + qn = one / (x + z); + f = x - z; + s = f * qn; + h = (double) ((float) s); + t = qn * ((f - (h + h) * z) - h * f); + j = (i >> 13) & 0x7f; + f = s * s; + t = t * A1 + h * A1_lo; + t += (s * f) * (A2 + f * A3); + qn = h * A1_hi; + s = n + _TBL_log2_hi[j]; + h = qn + s; + t += _TBL_log2_lo[j] - ((h - s) - qn); + f = (double) ((float) (h + t)); + *w = t - (f - h); + return (f); +} + +extern const double _TBL_exp2_hi[], _TBL_exp2_lo[]; +static const double /* poly app of 2^x-1 on [-1e-10,2^-7+1e-10] */ + E1 = 6.931471805599453100674958533810346197328e-0001, + E2 = 2.402265069587779347846769151717493815979e-0001, + E3 = 5.550410866475410512631124892773937864699e-0002, + E4 = 9.618143209991026824853712740162451423355e-0003, + E5 = 1.333357676549940345096774122231849082991e-0003; + +double +pow(double x, double y) { + double z, ax; + double y1, y2, w1, w2; + int sbx, sby, j, k, yisint; + int hx, hy, ahx, ahy; + unsigned lx, ly; + int *pz = (int *) &z; + + hx = ((int *) &x)[HIWORD]; + lx = ((unsigned *) &x)[LOWORD]; + hy = ((int *) &y)[HIWORD]; + ly = ((unsigned *) &y)[LOWORD]; + ahx = hx & ~0x80000000; + ahy = hy & ~0x80000000; + if ((ahy | ly) == 0) { /* y==zero */ + if ((ahx | lx) == 0) + z = _SVID_libm_err(x, y, 20); /* +-0**+-0 */ + else if ((ahx | (((lx | -lx) >> 31) & 1)) > 0x7ff00000) + z = _SVID_libm_err(x, y, 42); /* NaN**+-0 */ + else + z = one; /* x**+-0 = 1 */ + return (z); + } else if (hx == 0x3ff00000 && lx == 0 && + (__xpg6 & _C99SUSv3_pow) != 0) + return (one); /* C99: 1**anything = 1 */ + else if (ahx > 0x7ff00000 || (ahx == 0x7ff00000 && lx != 0) || + ahy > 0x7ff00000 || (ahy == 0x7ff00000 && ly != 0)) + return (x * y); /* +-NaN return x*y; + -> * for Cheetah */ + /* includes Sun: 1**NaN = NaN */ + sbx = (unsigned) hx >> 31; + sby = (unsigned) hy >> 31; + ax = fabs(x); + + /* + * determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if (sbx) { + if (ahy >= 0x43400000) + yisint = 2; /* even integer y */ + else if (ahy >= 0x3ff00000) { + k = (ahy >> 20) - 0x3ff; /* exponent */ + if (k > 20) { + j = ly >> (52 - k); + if ((j << (52 - k)) == ly) + yisint = 2 - (j & 1); + } else if (ly == 0) { + j = ahy >> (20 - k); + if ((j << (20 - k)) == ahy) + yisint = 2 - (j & 1); + } + } + } + /* special value of y */ + if (ly == 0) { + if (ahy == 0x7ff00000) { /* y is +-inf */ + if (((ahx - 0x3ff00000) | lx) == 0) { + if ((__xpg6 & _C99SUSv3_pow) != 0) + return (one); + /* C99: (-1)**+-inf = 1 */ + else + return (y - y); + /* Sun: (+-1)**+-inf = NaN */ + } else if (ahx >= 0x3ff00000) + /* (|x|>1)**+,-inf = inf,0 */ + return (sby == 0 ? y : zero); + else /* (|x|<1)**-,+inf = inf,0 */ + return (sby != 0 ? -y : zero); + } + if (ahy == 0x3ff00000) { /* y is +-1 */ + if (sby != 0) { /* y is -1 */ + if (x == zero) /* divided by zero */ + return (_SVID_libm_err(x, y, 23)); + else if (ahx < 0x40000 || ((ahx - 0x40000) | + lx) == 0) /* overflow */ + return (_SVID_libm_err(x, y, 21)); + else + return (one / x); + } else + return (x); + } + if (hy == 0x40000000) { /* y is 2 */ + if (ahx >= 0x5ff00000 && ahx < 0x7ff00000) + return (_SVID_libm_err(x, y, 21)); + /* x*x overflow */ + else if (ahx < 0x1e56a09e && (ahx | lx) != 0 || + ahx == 0x1e56a09e && lx < 0x667f3bcd) + return (_SVID_libm_err(x, y, 22)); + /* x*x underflow */ + else + return (x * x); + } + if (hy == 0x3fe00000) { + if (!((ahx | lx) == 0 || ((ahx - 0x7ff00000) | lx) == + 0 || sbx == 1)) + return (sqrt(x)); /* y is 0.5 and x > 0 */ + } + } + /* special value of x */ + if (lx == 0) { + if (ahx == 0x7ff00000 || ahx == 0 || ahx == 0x3ff00000) { + /* x is +-0,+-inf,-1 */ + z = ax; + if (sby == 1) { + z = one / z; /* z = |x|**y */ + if (ahx == 0) + return (_SVID_libm_err(x, y, 23)); + } + if (sbx == 1) { + if (ahx == 0x3ff00000 && yisint == 0) + z = _SVID_libm_err(x, y, 24); + /* neg**non-integral is NaN + invalid */ + else if (yisint == 1) + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + return (z); + } + } + /* (x<0)**(non-int) is NaN */ + if (sbx == 1 && yisint == 0) + return (_SVID_libm_err(x, y, 24)); + /* Now ax is finite, y is finite */ + /* first compute log2(ax) = w1+w2, with 24 bits w1 */ + w1 = log2_x(ax, &w2); + + /* split up y into y1+y2 and compute (y1+y2)*(w1+w2) */ + if (((ly & 0x07ffffff) == 0) || ahy >= 0x47e00000 || + ahy <= 0x38100000) { + /* no need to split if y is short or too large or too small */ + y1 = y * w1; + y2 = y * w2; + } else { + y1 = (double) ((float) y); + y2 = (y - y1) * w1 + y * w2; + y1 *= w1; + } + z = y1 + y2; + j = pz[HIWORD]; + if (j >= 0x40900000) { /* z >= 1024 */ + if (!(j == 0x40900000 && pz[LOWORD] == 0)) /* z > 1024 */ + return (_SVID_libm_err(x, y, 21)); /* overflow */ + else { + w2 = y1 - z; + w2 += y2; + /* rounded to inf */ + if (w2 >= -8.008566259537296567160e-17) + return (_SVID_libm_err(x, y, 21)); + /* overflow */ + } + } else if ((j & ~0x80000000) >= 0x4090cc00) { /* z <= -1075 */ + if (!(j == 0xc090cc00 && pz[LOWORD] == 0)) /* z < -1075 */ + return (_SVID_libm_err(x, y, 22)); /* underflow */ + else { + w2 = y1 - z; + w2 += y2; + if (w2 <= zero) /* underflow */ + return (_SVID_libm_err(x, y, 22)); + } + } + /* + * compute 2**(k+f[j]+g) + */ + k = (int) (z * 64.0 + (((hy ^ (ahx - 0x3ff00000)) > 0) ? 0.5 : -0.5)); + j = k & 63; + w1 = y2 - ((double) k * 0.015625 - y1); + w2 = _TBL_exp2_hi[j]; + z = _TBL_exp2_lo[j] + (w2 * w1) * (E1 + w1 * (E2 + w1 * (E3 + w1 * + (E4 + w1 * E5)))); + z += w2; + k >>= 6; + if (k < -1021) + z = scalbn(z, k); + else /* subnormal output */ + pz[HIWORD] += k << 20; + if (sbx == 1 && yisint == 1) + z = -z; /* (-ve)**(odd int) */ + return (z); +} diff --git a/usr/src/libm/src/C/remainder.c b/usr/src/libm/src/C/remainder.c new file mode 100644 index 0000000..72a15c8 --- /dev/null +++ b/usr/src/libm/src/C/remainder.c @@ -0,0 +1,86 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)remainder.c 1.24 06/01/25 SMI" + +#pragma weak remainder = __remainder + +/* + * remainder(x,p) + * Code originated from 4.3bsd. + * Modified by K.C. Ng for SUN 4.0 libm. + * Return : + * returns x REM p = x - [x/p]*p as if in infinite precise arithmetic, + * where [x/p] is the (inifinite bit) integer nearest x/p (in half way + * case choose the even one). + * Method : + * Based on fmod() return x-[x/p]chopped*p exactly. + */ + +#include "libm.h" + +static const double zero = 0.0, half = 0.5; + +double +remainder(double x, double p) { + double halfp; + int ix, hx, hp; + + ix = ((int *)&x)[HIWORD]; + hx = ix & ~0x80000000; + hp = ((int *)&p)[HIWORD] & ~0x80000000; + + if (hp > 0x7ff00000 || (hp == 0x7ff00000 && ((int *)&p)[LOWORD] != 0)) + return (x * p); + if (hx > 0x7ff00000 || (hx == 0x7ff00000 && ((int *)&x)[LOWORD] != 0)) + return (x * p); + + if ((hp | ((int *)&p)[LOWORD]) == 0 || hx == 0x7ff00000) + return (_SVID_libm_err(x, p, 28)); + + p = fabs(p); + if (hp < 0x7fe00000) + x = fmod(x, p + p); + x = fabs(x); + if (hp < 0x00200000) { + if (x + x > p) { + if (x == p) /* avoid x-x=-0 in RM mode */ + return ((ix < 0)? -zero : zero); + x -= p; + if (x + x >= p) + x -= p; + } + } else { + halfp = half * p; + if (x > halfp) { + if (x == p) /* avoid x-x=-0 in RM mode */ + return ((ix < 0)? -zero : zero); + x -= p; + if (x >= halfp) + x -= p; + } + } + return ((ix < 0)? -x : x); +} diff --git a/usr/src/libm/src/C/rint.c b/usr/src/libm/src/C/rint.c new file mode 100644 index 0000000..c600c2b --- /dev/null +++ b/usr/src/libm/src/C/rint.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)rint.c 1.17 06/01/23 SMI" + +#pragma weak rint = __rint + +/* + * rint(x) return x rounded to integral according to the rounding direction + * rint(x) returns result with the same sign as x's, including 0.0. + */ + +#include "libm.h" + +#if defined(__i386) && !defined(__amd64) && (!defined(__FLT_EVAL_METHOD__) || \ + __FLT_EVAL_METHOD__ != 0) +extern enum fp_precision_type __swapRP(enum fp_precision_type); +#define DECLRP(x) enum fp_precision_type x; +#define SWAPRP(new, x) x = __swapRP(new); +#define RESTRP(x) (void) __swapRP(x); +#else +#define DECLRP(x) +#define SWAPRP(new, x) +#define RESTRP(x) +#endif + +static const double + two52 = 4503599627370496.0, + zero = 0.0, + one = 1.0; + +double +rint(double x) { + DECLRP(rp) + double t, w; + int ix, hx; + + ix = ((int *)&x)[HIWORD]; + hx = ix & ~0x80000000; + + if (hx >= 0x43300000) + return (x * one); + t = (ix < 0)? -two52 : two52; + SWAPRP(fp_double, rp) /* set precision mode to double */ + w = x + t; /* x+sign(x)*2**52 rounded */ + RESTRP(rp) /* restore precision mode */ + if (w == t) + return ((ix < 0)? -zero : zero); + return (w - t); +} diff --git a/usr/src/libm/src/C/scalb.c b/usr/src/libm/src/C/scalb.c new file mode 100644 index 0000000..8240c76 --- /dev/null +++ b/usr/src/libm/src/C/scalb.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)scalb.c 1.20 06/01/23 SMI" + +#pragma weak scalb = __scalb +#pragma weak _scalb = __scalb + +#include "libm.h" + +double +scalb(double x, double fn) { + int hn, in, n; + double z; + + if (isnan(x) || isnan(fn)) + return (x * fn); + + in = ((int *)&fn)[HIWORD]; + hn = in & ~0x80000000; + if (hn == 0x7ff00000) /* fn is inf */ + return (_SVID_libm_err(x, fn, 47)); + + /* see if fn is an integer without raising inexact */ + if (hn >= 0x43300000) { + /* |fn| >= 2^52, so it must be an integer */ + n = (in < 0)? -65000 : 65000; + } else if (hn < 0x3ff00000) { + /* |fn| < 1, so it must be zero or non-integer */ + return ((fn == 0.0)? x : (x - x) / (x - x)); + } else if (hn < 0x41400000) { + /* |fn| < 2^21 */ + if ((hn & ((1 << (0x413 - (hn >> 20))) - 1)) + | ((int *)&fn)[LOWORD]) + return ((x - x) / (x - x)); + n = (int)fn; + } else { + if (((int *)&fn)[LOWORD] & ((1 << (0x433 - (hn >> 20))) - 1)) + return ((x - x) / (x - x)); + n = (in < 0)? -65000 : 65000; + } + z = scalbn(x, n); + if (z != x) { + if (z == 0.0) + return (_SVID_libm_err(x, fn, 33)); + if (!finite(z)) + return (_SVID_libm_err(x, fn, 32)); + } + return (z); +} diff --git a/usr/src/libm/src/C/scalbn.c b/usr/src/libm/src/C/scalbn.c new file mode 100644 index 0000000..23a30a6 --- /dev/null +++ b/usr/src/libm/src/C/scalbn.c @@ -0,0 +1,119 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)scalbn.c 1.10 06/01/26 SMI" + +#pragma weak scalbn = __scalbn + +#include "libm.h" + +static const double + one = 1.0, + huge = 1.0e300, + tiny = 1.0e-300, + twom54 = 5.5511151231257827021181583404541015625e-17; + +#if defined(USE_FPSCALE) || defined(__i386) +static const double two52 = 4503599627370496.0; +#else +/* + * Normalize non-zero subnormal x and return biased exponent of x in [-51,0] + */ +static int +ilogb_biased(unsigned *px) { + int s = 52; + unsigned v = px[HIWORD] & ~0x80000000, w = px[LOWORD], t = v; + + if (t) + s -= 32; + else + t = w; + if (t & 0xffff0000) + s -= 16, t >>= 16; + if (t & 0xff00) + s -= 8, t >>= 8; + if (t & 0xf0) + s -= 4, t >>= 4; + t <<= 1; + s -= (0xffffaa50 >> t) & 0x3; + if (s < 32) { + v = (v << s) | w >> (32 - s); + w <<= s; + } else { + v = w << (s - 32); + w = 0; + } + px[HIWORD] = (px[HIWORD] & 0x80000000) | v; + px[LOWORD] = w; + return (1 - s); +} +#endif /* defined(USE_FPSCALE) */ + +double +scalbn(double x, int n) { + int *px, ix, hx, k; + + px = (int *)&x; + ix = px[HIWORD]; + hx = ix & ~0x80000000; + k = hx >> 20; + + if (k == 0x7ff) /* x is inf or NaN */ + return (x * one); + + if (k == 0) { + if ((hx | px[LOWORD]) == 0 || n == 0) + return (x); +#if defined(USE_FPSCALE) || defined(__i386) + x *= two52; + ix = px[HIWORD]; + k = ((ix & ~0x80000000) >> 20) - 52; +#else + k = ilogb_biased((unsigned *)px); + ix = px[HIWORD]; +#endif + /* now k is in the range -51..0 */ + k += n; + if (k > n) /* integer overflow occurred */ + k = -100; + } else { + /* k is in the range 1..1023 */ + k += n; + if (k < n) /* integer overflow occurred */ + k = 0x7ff; + } + + if (k > 0x7fe) + return (huge * ((ix < 0)? -huge : huge)); + if (k < 1) { + if (k <= -54) + return (tiny * ((ix < 0)? -tiny : tiny)); + k += 54; + px[HIWORD] = (ix & ~0x7ff00000) | (k << 20); + return (x * twom54); + } + px[HIWORD] = (ix & ~0x7ff00000) | (k << 20); + return (x); +} diff --git a/usr/src/libm/src/C/signgam.c b/usr/src/libm/src/C/signgam.c new file mode 100644 index 0000000..06e0711 --- /dev/null +++ b/usr/src/libm/src/C/signgam.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)signgam.c 1.8 06/01/31 SMI" + +#pragma weak signgam = __signgam + +#include "libm_synonyms.h" +#include <math.h> + +int signgam = 0; diff --git a/usr/src/libm/src/C/significand.c b/usr/src/libm/src/C/significand.c new file mode 100644 index 0000000..cc82693 --- /dev/null +++ b/usr/src/libm/src/C/significand.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)significand.c 1.12 06/01/31 SMI" + +#if defined(ELFOBJ) +#pragma weak significand = __significand +#endif + +#include "libm.h" + +double +significand(double x) { + int ix = ((int *) &x)[HIWORD] & ~0x80000000; + + /* weed out 0/+-Inf/NaN because C99 ilogb raises invalid on them */ + if ((ix | ((int *) &x)[LOWORD]) == 0 || ix >= 0x7ff00000) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return ((ix & 0x80000) != 0 ? x : x + x); + /* assumes sparc-like QNaN */ +#else + return (x + x); +#endif + else + return (scalbn(x, -ilogb(x))); +} diff --git a/usr/src/libm/src/C/sin.c b/usr/src/libm/src/C/sin.c new file mode 100644 index 0000000..c153e22 --- /dev/null +++ b/usr/src/libm/src/C/sin.c @@ -0,0 +1,188 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)sin.c 1.12 06/01/23 SMI" + +#pragma weak sin = __sin + +/* INDENT OFF */ +/* + * sin(x) + * Accurate Table look-up algorithm by K.C. Ng, May, 1995. + * + * Algorithm: see sincos.c + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* PI_H = */ 3.1415926535897931159979634685, +/* PI_L = */ 1.22464679914735317722606593227425e-16, +/* PI_L0 = */ 1.22464679914558443311283879205095e-16, +/* PI_L1 = */ 1.768744113227140223300005233735517376e-28, +/* PI2_H = */ 6.2831853071795862319959269370, +/* PI2_L = */ 2.44929359829470635445213186454850e-16, +/* PI2_L0 = */ 2.44929359829116886622567758410190e-16, +/* PI2_L1 = */ 3.537488226454280446600010467471034752e-28, +}; +/* INDENT ON */ + +#define ONEA sc +#define ONE sc[0] +#define NONE sc[1] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define PI_H sc[10] +#define PI_L sc[11] +#define PI_L0 sc[12] +#define PI_L1 sc[13] +#define PI2_H sc[14] +#define PI2_L sc[15] +#define PI2_L0 sc[16] +#define PI2_L1 sc[17] + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +double +sin(double x) { + double z, y[2], w, s, v, p, q; + int i, j, n, hx, ix, lx; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < .1640625 */ + if (ix < 0x3e400000) /* |x| < 2**-27 */ + if ((int)x == 0) + return (x); + z = x * x; + if (ix < 0x3f800000) /* |x| < 2**-8 */ + w = (z * x) * (PP1 + z * PP2); + else + w = (x * z) * ((P1 + z * P2) + (z * z) * (P3 + z * P4)); + return (x + w); + } + + /* for .1640625 < x < M, */ + n = ix >> 20; + if (n < 0x402) { /* x < 8 */ + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + x = fabs(x); + v = x - _TBL_sincosx[j]; + if (((j - 181) ^ (j - 201)) < 0) { + /* near pi, sin(x) = sin(pi-x) */ + p = PI_H - x; + i = ix - 0x400921fb; + x = p + PI_L; + if ((i | ((lx - 0x54442D00) & 0xffffff00)) == 0) { + /* very close to pi */ + x = p + PI_L0; + return ((hx >= 0)? x + PI_L1 : -(x + PI_L1)); + } + z = x * x; + if (((ix - 0x40092000) >> 11) == 0) { + /* |pi-x|<2**-8 */ + w = PI_L + (z * x) * (PP1 + z * PP2); + } else { + w = PI_L + (z * x) * ((P1 + z * P2) + + (z * z) * (P3 + z * P4)); + } + return ((hx >= 0)? p + w : -p - w); + } + s = v * v; + if (((j - 382) ^ (j - 402)) < 0) { + /* near 2pi, sin(x) = sin(x-2pi) */ + p = x - PI2_H; + i = ix - 0x401921fb; + x = p - PI2_L; + if ((i | ((lx - 0x54442D00) & 0xffffff00)) == 0) { + /* very close to 2pi */ + x = p - PI2_L0; + return ((hx >= 0)? x - PI2_L1 : -(x - PI2_L1)); + } + z = x * x; + if (((ix - 0x40192000) >> 10) == 0) { + /* |x-2pi|<2**-8 */ + w = (z * x) * (PP1 + z * PP2) - PI2_L; + } else { + w = (z * x) * ((P1 + z * P2) + + (z * z) * (P3 + z * P4)) - PI2_L; + } + return ((hx >= 0)? p + w : -p - w); + } + j <<= 1; + w = _TBL_sincos[j+1]; + z = _TBL_sincos[j]; + p = v + (v * s) * (PP1 + s * PP2); + q = s * (QQ1 + s * QQ2); + v = w * p + z * q; + return ((hx >= 0)? z + v : -z - v); + } + + if (ix >= 0x7ff00000) /* sin(Inf or NaN) is NaN */ + return (x / x); + + /* argument reduction needed */ + n = __rem_pio2(x, y); + switch (n & 3) { + case 0: + return (__k_sin(y[0], y[1])); + case 1: + return (__k_cos(y[0], y[1])); + case 2: + return (-__k_sin(y[0], y[1])); + default: + return (-__k_cos(y[0], y[1])); + } +} diff --git a/usr/src/libm/src/C/sincos.c b/usr/src/libm/src/C/sincos.c new file mode 100644 index 0000000..0143a54 --- /dev/null +++ b/usr/src/libm/src/C/sincos.c @@ -0,0 +1,367 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)sincos.c 1.13 06/01/23 SMI" + +#pragma weak sincos = __sincos + +/* INDENT OFF */ +/* + * sincos(x,s,c) + * Accurate Table look-up algorithm by K.C. Ng, 2000. + * + * 1. Reduce x to x>0 by cos(-x)=cos(x), sin(-x)=-sin(x). + * 2. For 0<= x < 8, let i = (64*x chopped)-10. Let d = x - a[i], where + * a[i] is a double that is close to (i+10.5)/64 (and hence |d|< 10.5/64) + * and such that sin(a[i]) and cos(a[i]) is close to a double (with error + * less than 2**-8 ulp). Then + * + * cos(x) = cos(a[i]+d) = cos(a[i])cos(d) - sin(a[i])*sin(d) + * = TBL_cos_a[i]*(1+QQ1*d^2+QQ2*d^4) - + * TBL_sin_a[i]*(d+PP1*d^3+PP2*d^5) + * = TBL_cos_a[i] + (TBL_cos_a[i]*d^2*(QQ1+QQ2*d^2) - + * TBL_sin_a[i]*(d+PP1*d^3+PP2*d^5)) + * + * sin(x) = sin(a[i]+d) = sin(a[i])cos(d) + cos(a[i])*sin(d) + * = TBL_sin_a[i]*(1+QQ1*d^2+QQ2*d^4) + + * TBL_cos_a[i]*(d+PP1*d^3+PP2*d^5) + * = TBL_sin_a[i] + (TBL_sin_a[i]*d^2*(QQ1+QQ2*d^2) + + * TBL_cos_a[i]*(d+PP1*d^3+PP2*d^5)) + * + * Note: for x close to n*pi/2, special treatment is need for either + * sin or cos: + * i in [81, 100] ( pi/2 +-10.5/64 => tiny cos(x) = sin(pi/2-x) + * i in [181,200] ( pi +-10.5/64 => tiny sin(x) = sin(pi-x) + * i in [282,301] ( 3pi/2+-10.5/64 => tiny cos(x) = sin(x-3pi/2) + * i in [382,401] ( 2pi +-10.5/64 => tiny sin(x) = sin(x-2pi) + * i in [483,502] ( 5pi/2+-10.5/64 => tiny cos(x) = sin(5pi/2-x) + * + * 3. For x >= 8.0, use kernel function __rem_pio2 to perform argument + * reduction and call __k_sincos_ to compute sin and cos. + * + * kernel function: + * __rem_pio2 ... argument reduction routine + * __k_sincos_ ... sine and cosine function on [-pi/4,pi/4] + * + * Method. + * Let S and C denote the sin and cos respectively on [-PI/4, +PI/4]. + * 1. Assume the argument x is reduced to y1+y2 = x-k*pi/2 in + * [-pi/2 , +pi/2], and let n = k mod 4. + * 2. Let S=S(y1+y2), C=C(y1+y2). Depending on n, we have + * + * n sin(x) cos(x) tan(x) + * ---------------------------------------------------------- + * 0 S C S/C + * 1 C -S -C/S + * 2 -S -C S/C + * 3 -C S -C/S + * ---------------------------------------------------------- + * + * Special cases: + * Let trig be any of sin, cos, or tan. + * trig(+-INF) is NaN, with signals; + * trig(NaN) is that NaN; + * + * Accuracy: + * TRIG(x) returns trig(x) nearly rounded (less than 1 ulp) + */ + +#include "libm.h" + +static const double sc[] = { +/* ONE = */ 1.0, +/* NONE = */ -1.0, +/* + * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008 + */ +/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567, +/* PP2 = */ .008333315652997472323564894248466758248475374977974017927, +/* + * |(sin(x) - (x+p1*x^3+...+p4*x^9)| + * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125 + * | x | + */ +/* P1 = */ -1.666666666666629669805215138920301589656e-0001, +/* P2 = */ 8.333333332390951295683993455280336376663e-0003, +/* P3 = */ -1.984126237997976692791551778230098403960e-0004, +/* P4 = */ 2.753403624854277237649987622848330351110e-0006, +/* + * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d) + */ +/* QQ1 = */ -0.4999999999975492381842911981948418542742729, +/* QQ2 = */ 0.041666542904352059294545209158357640398771740, +/* Q1 = */ -0.5, +/* Q2 = */ 4.166666666500350703680945520860748617445e-0002, +/* Q3 = */ -1.388888596436972210694266290577848696006e-0003, +/* Q4 = */ 2.478563078858589473679519517892953492192e-0005, +/* PIO2_H = */ 1.570796326794896557999, +/* PIO2_L = */ 6.123233995736765886130e-17, +/* PIO2_L0 = */ 6.123233995727922165564e-17, +/* PIO2_L1 = */ 8.843720566135701120255e-29, +/* PI_H = */ 3.1415926535897931159979634685, +/* PI_L = */ 1.22464679914735317722606593227425e-16, +/* PI_L0 = */ 1.22464679914558443311283879205095e-16, +/* PI_L1 = */ 1.768744113227140223300005233735517376e-28, +/* PI3O2_H = */ 4.712388980384689673997, +/* PI3O2_L = */ 1.836970198721029765839e-16, +/* PI3O2_L0 = */ 1.836970198720396133587e-16, +/* PI3O2_L1 = */ 6.336322524749201142226e-29, +/* PI2_H = */ 6.2831853071795862319959269370, +/* PI2_L = */ 2.44929359829470635445213186454850e-16, +/* PI2_L0 = */ 2.44929359829116886622567758410190e-16, +/* PI2_L1 = */ 3.537488226454280446600010467471034752e-28, +/* PI5O2_H = */ 7.853981633974482789995, +/* PI5O2_L = */ 3.061616997868382943065e-16, +/* PI5O2_L0 = */ 3.061616997861941598865e-16, +/* PI5O2_L1 = */ 6.441344200433640781982e-28, +}; +/* INDENT ON */ + +#define ONE sc[0] +#define PP1 sc[2] +#define PP2 sc[3] +#define P1 sc[4] +#define P2 sc[5] +#define P3 sc[6] +#define P4 sc[7] +#define QQ1 sc[8] +#define QQ2 sc[9] +#define Q1 sc[10] +#define Q2 sc[11] +#define Q3 sc[12] +#define Q4 sc[13] +#define PIO2_H sc[14] +#define PIO2_L sc[15] +#define PIO2_L0 sc[16] +#define PIO2_L1 sc[17] +#define PI_H sc[18] +#define PI_L sc[19] +#define PI_L0 sc[20] +#define PI_L1 sc[21] +#define PI3O2_H sc[22] +#define PI3O2_L sc[23] +#define PI3O2_L0 sc[24] +#define PI3O2_L1 sc[25] +#define PI2_H sc[26] +#define PI2_L sc[27] +#define PI2_L0 sc[28] +#define PI2_L1 sc[29] +#define PI5O2_H sc[30] +#define PI5O2_L sc[31] +#define PI5O2_L0 sc[32] +#define PI5O2_L1 sc[33] +#define PoS(x, z) ((x * z) * (PP1 + z * PP2)) +#define PoL(x, z) ((x * z) * ((P1 + z * P2) + (z * z) * (P3 + z * P4))) + +extern const double _TBL_sincos[], _TBL_sincosx[]; + +void +sincos(double x, double *s, double *c) { + double z, y[2], w, t, v, p, q; + int i, j, n, hx, ix, lx; + + hx = ((int *)&x)[HIWORD]; + lx = ((int *)&x)[LOWORD]; + ix = hx & ~0x80000000; + + if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */ + if (ix < 0x3e400000) { /* |x| < 2**-27 */ + if ((int)x == 0) + *c = ONE; + *s = x; + } else { + z = x * x; + if (ix < 0x3f800000) { /* |x| < 0.008 */ + q = z * (QQ1 + z * QQ2); + p = PoS(x, z); + } else { + q = z * ((Q1 + z * Q2) + (z * z) * + (Q3 + z * Q4)); + p = PoL(x, z); + } + *c = ONE + q; + *s = x + p; + } + return; + } + + n = ix >> 20; + i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n); + j = i - 10; + if (n < 0x402) { /* |x| < 8 */ + x = fabs(x); + v = x - _TBL_sincosx[j]; + t = v * v; + w = _TBL_sincos[(j<<1)]; + z = _TBL_sincos[(j<<1)+1]; + p = v + PoS(v, t); + q = t * (QQ1 + t * QQ2); + if ((((j - 81) ^ (j - 101)) | + ((j - 282) ^ (j - 302)) | + ((j - 483) ^ (j - 503)) | + ((j - 181) ^ (j - 201)) | + ((j - 382) ^ (j - 402))) < 0) { + if (j <= 101) { + /* near pi/2, cos(x) = sin(pi/2-x) */ + t = w * q + z * p; + *s = (hx >= 0)? w + t : -w - t; + p = PIO2_H - x; + i = ix - 0x3ff921fb; + x = p + PIO2_L; + if ((i | ((lx - 0x54442D00) & + 0xffffff00)) == 0) { + /* very close to pi/2 */ + x = p + PIO2_L0; + *c = x + PIO2_L1; + } else { + z = x * x; + if (((ix - 0x3ff92000) >> 12) == 0) { + /* |pi/2-x|<2**-8 */ + w = PIO2_L + PoS(x, z); + } else { + w = PIO2_L + PoL(x, z); + } + *c = p + w; + } + } else if (j <= 201) { + /* near pi, sin(x) = sin(pi-x) */ + *c = z - (w * p - z * q); + p = PI_H - x; + i = ix - 0x400921fb; + x = p + PI_L; + if ((i | ((lx - 0x54442D00) & + 0xffffff00)) == 0) { + /* very close to pi */ + x = p + PI_L0; + *s = (hx >= 0)? x + PI_L1 : + -(x + PI_L1); + } else { + z = x * x; + if (((ix - 0x40092000) >> 11) == 0) { + /* |pi-x|<2**-8 */ + w = PI_L + PoS(x, z); + } else { + w = PI_L + PoL(x, z); + } + *s = (hx >= 0)? p + w : -p - w; + } + } else if (j <= 302) { + /* near 3/2pi, cos(x)=sin(x-3/2pi) */ + t = w * q + z * p; + *s = (hx >= 0)? w + t : -w - t; + p = x - PI3O2_H; + i = ix - 0x4012D97C; + x = p - PI3O2_L; + if ((i | ((lx - 0x7f332100) & + 0xffffff00)) == 0) { + /* very close to 3/2pi */ + x = p - PI3O2_L0; + *c = x - PI3O2_L1; + } else { + z = x * x; + if (((ix - 0x4012D800) >> 9) == 0) { + /* |3/2pi-x|<2**-8 */ + w = PoS(x, z) - PI3O2_L; + } else { + w = PoL(x, z) - PI3O2_L; + } + *c = p + w; + } + } else if (j <= 402) { + /* near 2pi, sin(x)=sin(x-2pi) */ + *c = z - (w * p - z * q); + p = x - PI2_H; + i = ix - 0x401921fb; + x = p - PI2_L; + if ((i | ((lx - 0x54442D00) & + 0xffffff00)) == 0) { + /* very close to 2pi */ + x = p - PI2_L0; + *s = (hx >= 0)? x - PI2_L1 : + -(x - PI2_L1); + } else { + z = x * x; + if (((ix - 0x40192000) >> 10) == 0) { + /* |x-2pi|<2**-8 */ + w = PoS(x, z) - PI2_L; + } else { + w = PoL(x, z) - PI2_L; + } + *s = (hx >= 0)? p + w : -p - w; + } + } else { + /* near 5pi/2, cos(x) = sin(5pi/2-x) */ + t = w * q + z * p; + *s = (hx >= 0)? w + t : -w - t; + p = PI5O2_H - x; + i = ix - 0x401F6A7A; + x = p + PI5O2_L; + if ((i | ((lx - 0x29553800) & + 0xffffff00)) == 0) { + /* very close to pi/2 */ + x = p + PI5O2_L0; + *c = x + PI5O2_L1; + } else { + z = x * x; + if (((ix - 0x401F6A7A) >> 7) == 0) { + /* |5pi/2-x|<2**-8 */ + w = PI5O2_L + PoS(x, z); + } else { + w = PI5O2_L + PoL(x, z); + } + *c = p + w; + } + } + } else { + *c = z - (w * p - z * q); + t = w * q + z * p; + *s = (hx >= 0)? w + t : -w - t; + } + return; + } + + if (ix >= 0x7ff00000) { + *s = *c = x / x; + return; + } + + /* argument reduction needed */ + n = __rem_pio2(x, y); + switch (n & 3) { + case 0: + *s = __k_sincos(y[0], y[1], c); + break; + case 1: + *c = -__k_sincos(y[0], y[1], s); + break; + case 2: + *s = -__k_sincos(y[0], y[1], c); + *c = -*c; + break; + default: + *c = __k_sincos(y[0], y[1], s); + *s = -*s; + } +} diff --git a/usr/src/libm/src/C/sincospi.c b/usr/src/libm/src/C/sincospi.c new file mode 100644 index 0000000..c3c19ca --- /dev/null +++ b/usr/src/libm/src/C/sincospi.c @@ -0,0 +1,197 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)sincospi.c 1.17 06/01/31 SMI" + +#pragma weak sincospi = __sincospi + +/* INDENT OFF */ +/* + * void sincospi(double x, double *s, double *c) + * *s = sin(pi*x); *c = cos(pi*x); + * + * Algorithm, 10/17/2002, K.C. Ng + * ------------------------------ + * Let y = |4x|, z = floor(y), and n = (int)(z mod 8.0) (displayed in binary). + * 1. If y==z, then x is a multiple of pi/4. Return the following values: + * --------------------------------------------------- + * n x mod 2 sin(x*pi) cos(x*pi) tan(x*pi) + * --------------------------------------------------- + * 000 0.00 +0 ___ +1 ___ +0 + * 001 0.25 +\/0.5 +\/0.5 +1 + * 010 0.50 +1 ___ +0 ___ +inf + * 011 0.75 +\/0.5 -\/0.5 -1 + * 100 1.00 -0 ___ -1 ___ +0 + * 101 1.25 -\/0.5 -\/0.5 +1 + * 110 1.50 -1 ___ -0 ___ +inf + * 111 1.75 -\/0.5 +\/0.5 -1 + * --------------------------------------------------- + * 2. Otherwise, + * --------------------------------------------------- + * n t sin(x*pi) cos(x*pi) tan(x*pi) + * --------------------------------------------------- + * 000 (y-z)/4 sinpi(t) cospi(t) tanpi(t) + * 001 (z+1-y)/4 cospi(t) sinpi(t) 1/tanpi(t) + * 010 (y-z)/4 cospi(t) -sinpi(t) -1/tanpi(t) + * 011 (z+1-y)/4 sinpi(t) -cospi(t) -tanpi(t) + * 100 (y-z)/4 -sinpi(t) -cospi(t) tanpi(t) + * 101 (z+1-y)/4 -cospi(t) -sinpi(t) 1/tanpi(t) + * 110 (y-z)/4 -cospi(t) sinpi(t) -1/tanpi(t) + * 111 (z+1-y)/4 -sinpi(t) cospi(t) -tanpi(t) + * --------------------------------------------------- + * + * NOTE. This program compute sinpi/cospi(t<0.25) by __k_sin/cos(pi*t, 0.0). + * This will return a result with error slightly more than one ulp (but less + * than 2 ulp). If one wants accurate result, one may break up pi*t in + * high (tpi_h) and low (tpi_l) parts and call __k_sin/cos(tip_h, tip_lo) + * instead. + */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> +#include <sunmath.h> + +static const double + pi = 3.14159265358979323846, /* 400921FB,54442D18 */ + sqrth_h = 0.70710678118654757273731092936941422522068023681640625, + sqrth_l = -4.8336466567264565185935844299127932213411660131004e-17; +/* INDENT ON */ + +#if defined(__sparc) +#define HIWORD 0 +#define LOWORD 1 +#elif defined(__i386) +#define HIWORD 1 +#define LOWORD 0 +#else +#error Unknown architecture +#endif + +void +sincospi(double x, double *s, double *c) { + double y, z, t; + int n, ix, k; + int hx = ((int *) &x)[HIWORD]; + unsigned h, lx = ((unsigned *) &x)[LOWORD]; + + ix = hx & ~0x80000000; + n = (ix >> 20) - 0x3ff; + if (n >= 51) { /* |x| >= 2**51 */ + if (n >= 1024) +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + *s = *c = ix >= 0x7ff80000 ? x : x - x; + /* assumes sparc-like QNaN */ +#else + *s = *c = x - x; +#endif + else { + if (n >= 53) { + *s = 0.0; + *c = 1.0; + } + else if (n == 52) { + if ((lx & 1) == 0) { + *s = 0.0; + *c = 1.0; + } + else { + *s = -0.0; + *c = -1.0; + } + } + else { /* n == 51 */ + if ((lx & 1) == 0) { + *s = 0.0; + *c = 1.0; + } + else { + *s = 1.0; + *c = 0.0; + } + if ((lx & 2) != 0) { + *s = -*s; + *c = -*c; + } + } + } + } + else if (n < -2) /* |x| < 0.25 */ + *s = __k_sincos(pi * fabs(x), 0.0, c); + else { + /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */ + if (ix < 0x41C00000) { /* |x| < 2**29 */ + y = 4.0 * fabs(x); + n = (int) y; /* exact */ + z = (double) n; + k = z == y; + t = (y - z) * 0.25; + } + else { /* 2**29 <= |x| < 2**51 */ + y = fabs(x); + k = 50 - n; + n = lx >> k; + h = n << k; + ((unsigned *) &z)[LOWORD] = h; + ((int *) &z)[HIWORD] = ix; + k = h == lx; + t = y - z; + } + if (k) { /* x = N/4 */ + if ((n & 1) != 0) + *s = *c = sqrth_h + sqrth_l; + else + if ((n & 2) == 0) { + *s = 0.0; + *c = 1.0; + } + else { + *s = 1.0; + *c = 0.0; + } + y = (n & 2) == 0 ? 0.0 : 1.0; + if ((n & 4) != 0) + *s = -*s; + if (((n + 1) & 4) != 0) + *c = -*c; + } + else { + if ((n & 1) != 0) + t = 0.25 - t; + if (((n + (n & 1)) & 2) == 0) + *s = __k_sincos(pi * t, 0.0, c); + else + *c = __k_sincos(pi * t, 0.0, s); + if ((n & 4) != 0) + *s = -*s; + if (((n + 2) & 4) != 0) + *c = -*c; + } + } + if (hx < 0) + *s = -*s; +} diff --git a/usr/src/libm/src/C/sinh.c b/usr/src/libm/src/C/sinh.c new file mode 100644 index 0000000..24953a3 --- /dev/null +++ b/usr/src/libm/src/C/sinh.c @@ -0,0 +1,78 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)sinh.c 1.19 06/01/23 SMI" + +#pragma weak sinh = __sinh + +/* INDENT OFF */ +/* + * sinh(x) + * Code originated from 4.3bsd. + * Modified by K.C. Ng for SUN 4.0 libm. + * Method : + * 1. reduce x to non-negative by sinh(-x) = - sinh(x). + * 2. + * + * expm1(x) + expm1(x)/(expm1(x)+1) + * 0 <= x <= lnovft : sinh(x) := -------------------------------- + * 2 + * lnovft <= x < INF : sinh(x) := exp(x-1024*ln2)*2**1023 + * + * + * Special cases: + * sinh(x) is x if x is +INF, -INF, or NaN. + * only sinh(0)=0 is exact for finite argument. + * + */ +/* INDENT ON */ + +#include "libm.h" + +static const double + ln2hi = 6.93147180369123816490e-01, + ln2lo = 1.90821492927058770002e-10, + lnovft = 7.09782712893383973096e+02; + +double +sinh(double x) { + double ox, r, t; + + ox = x; + r = fabs(x); + if (!finite(x)) + return (x * r); + if (r < lnovft) { + t = expm1(r); + r = copysign((t + t / (1.0 + t)) * 0.5, x); + } else { + if (r < 1000.0) + x = copysign(exp((r - 1024 * ln2hi) - 1024 * ln2lo), x); + r = scalbn(x, 1023); + } + if (!finite(r)) + r = _SVID_libm_err(ox, ox, 25); + return (r); +} diff --git a/usr/src/libm/src/C/sqrt.c b/usr/src/libm/src/C/sqrt.c new file mode 100644 index 0000000..e16ee33 --- /dev/null +++ b/usr/src/libm/src/C/sqrt.c @@ -0,0 +1,149 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)sqrt.c 1.20 06/01/23 SMI" + +#pragma weak sqrt = __sqrt + +#include "libm.h" + +#ifdef __INLINE + +extern double __inline_sqrt(double); + +double +sqrt(double x) { + double z = __inline_sqrt(x); + + if (isnan(x)) + return (z); + return ((x < 0.0)? _SVID_libm_err(x, x, 26) : z); +} + +#else /* defined(__INLINE) */ + +/* + * Warning: This correctly rounded sqrt is extremely slow because it computes + * the sqrt bit by bit using integer arithmetic. + */ + +static const double big = 1.0e30, small = 1.0e-30; + +double +sqrt(double x) +{ + double z; + unsigned r, t1, s1, ix1, q1; + int ix0, s0, j, q, m, n, t; + int *px = (int *)&x, *pz = (int *)&z; + + ix0 = px[HIWORD]; + ix1 = px[LOWORD]; + if ((ix0 & 0x7ff00000) == 0x7ff00000) { /* x is inf or NaN */ + if (ix0 == 0xfff00000 && ix1 == 0) + return (_SVID_libm_err(x, x, 26)); + return (x + x); + } + if (((ix0 & 0x7fffffff) | ix1) == 0) /* x is zero */ + return (x); + + /* extract exponent and significand */ + m = ilogb(x); + z = scalbn(x, -m); + ix0 = (pz[HIWORD] & 0x000fffff) | 0x00100000; + ix1 = pz[LOWORD]; + n = m >> 1; + if (n + n != m) { + ix0 = (ix0 << 1) | (ix1 >> 31); + ix1 <<= 1; + m -= 1; + } + + /* generate sqrt(x) bit by bit */ + ix0 = (ix0 << 1) | (ix1 >> 31); + ix1 <<= 1; + q = q1 = s0 = s1 = 0; + r = 0x00200000; + + for (j = 1; j <= 22; j++) { + t = s0 + r; + if (t <= ix0) { + s0 = t + r; + ix0 -= t; + q += r; + } + ix0 = (ix0 << 1) | (ix1 >> 31); + ix1 <<= 1; + r >>= 1; + } + + r = 0x80000000; + for (j = 1; j <= 32; j++) { + t1 = s1 + r; + t = s0; + if (t < ix0 || (t == ix0 && t1 <= ix1)) { + s1 = t1 + r; + if ((t1 & 0x80000000) == 0x80000000 && + (s1 & 0x80000000) == 0) + s0 += 1; + ix0 -= t; + if (ix1 < t1) + ix0 -= 1; + ix1 -= t1; + q1 += r; + } + ix0 = (ix0 << 1) | (ix1 >> 31); + ix1 <<= 1; + r >>= 1; + } + + /* round */ + if ((ix0 | ix1) == 0) + goto done; + z = big - small; /* trigger inexact flag */ + if (z < big) + goto done; + if (q1 == 0xffffffff) { + q1 = 0; + q += 1; + goto done; + } + z = big + small; + if (z > big) { + if (q1 == 0xfffffffe) + q += 1; + q1 += 2; + goto done; + } + q1 += (q1 & 1); +done: + pz[HIWORD] = (q >> 1) + 0x3fe00000; + pz[LOWORD] = q1 >> 1; + if ((q & 1) == 1) + pz[LOWORD] |= 0x80000000; + return (scalbn(z, n)); +} + +#endif /* defined(__INLINE) */ diff --git a/usr/src/libm/src/C/tan.c b/usr/src/libm/src/C/tan.c new file mode 100644 index 0000000..568d473 --- /dev/null +++ b/usr/src/libm/src/C/tan.c @@ -0,0 +1,75 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)tan.c 1.17 06/01/31 SMI" + +#pragma weak tan = __tan + +/* INDENT OFF */ +/* + * tan(x) + * Table look-up algorithm by K.C. Ng, November, 1989. + * + * kernel function: + * __k_tan ... tangent function on [-pi/4,pi/4] + * __rem_pio2 ... argument reduction routine + */ +/* INDENT ON */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> + +double +tan(double x) { + double y[2], z = 0.0; + int n, ix; + + /* high word of x */ + ix = ((int *) &x)[HIWORD]; + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if (ix <= 0x3fe921fb) + return (__k_tan(x, z, 0)); + + /* tan(Inf or NaN) is NaN */ + else if (ix >= 0x7ff00000) { +#if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) + return (ix >= 0x7ff80000 ? x : x - x); /* NaN */ + /* assumes sparc-like QNaN */ +#else + return (x - x); /* NaN */ +#endif + } + + /* argument reduction needed */ + else { + n = __rem_pio2(x, y); + return (__k_tan(y[0], y[1], n & 1)); + } +} diff --git a/usr/src/libm/src/C/tanh.c b/usr/src/libm/src/C/tanh.c new file mode 100644 index 0000000..9d8b6ba --- /dev/null +++ b/usr/src/libm/src/C/tanh.c @@ -0,0 +1,100 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)tanh.c 1.18 06/01/31 SMI" + +#pragma weak tanh = __tanh + +/* INDENT OFF */ +/* TANH(X) + * RETURN THE HYPERBOLIC TANGENT OF X + * code based on 4.3bsd + * Modified by K.C. Ng for sun 4.0, Jan 31, 1987 + * + * Method : + * 1. reduce x to non-negative by tanh(-x) = - tanh(x). + * 2. + * 0 < x <= 1.e-10 : tanh(x) := x + * -expm1(-2x) + * 1.e-10 < x <= 1 : tanh(x) := -------------- + * expm1(-2x) + 2 + * 2 + * 1 <= x <= 22.0 : tanh(x) := 1 - --------------- + * expm1(2x) + 2 + * 22.0 < x <= INF : tanh(x) := 1. + * + * Note: 22 was chosen so that fl(1.0+2/(expm1(2*22)+2)) == 1. + * + * Special cases: + * tanh(NaN) is NaN; + * only tanh(0)=0 is exact for finite argument. + */ + +#include "libm.h" +#include "libm_synonyms.h" +#include "libm_protos.h" +#include <math.h> + +static const double + one = 1.0, + two = 2.0, + small = 1.0e-10, + big = 1.0e10; +/* INDENT ON */ + +double +tanh(double x) { + double t, y, z; + int signx; + volatile double dummy; + + if (isnan(x)) + return x * x; /* + -> * for Cheetah */ + signx = signbit(x); + t = fabs(x); + z = one; + if (t <= 22.0) { + if (t > one) + z = one - two / (expm1(t + t) + two); + else if (t > small) { + y = expm1(-t - t); + z = -y / (y + two); + } + else { /* raise the INEXACT flag for non-zero t */ + dummy = t + big; +#ifdef lint + dummy = dummy; +#endif + return x; + } + } + else if (!finite(t)) + return copysign(1.0, x); + else + return signx == 1 ? -z + small * small : z - small * small; + + return signx == 1 ? -z : z; +} diff --git a/usr/src/libm/src/C/xpg6.h b/usr/src/libm/src/C/xpg6.h new file mode 100644 index 0000000..df646ed --- /dev/null +++ b/usr/src/libm/src/C/xpg6.h @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _XPG6_H +#define _XPG6_H + +#pragma ident "@(#)xpg6.h 1.8 06/01/31 SMI" + +/* + * The bits in lib/libc/inc/xpg6.h fpgroup may use as per PSARC/2003/486. + */ + +/* + * If set, math library entry points present in SUSv2 deal with exceptional + * cases as per SUSv3 spec where math_errhandling is set to MATH_ERREXCEPT; + * otherwise they behave as per SUSv2 spec. + */ +#define _C99SUSv3_math_errexcept 0x00000400 +/* + * If set, pow(+/-1,+/-Inf) & pow(1,NaN) return 1; otherwise NaN is returned. + * Analogous comment applies to powf and powl. + */ +#define _C99SUSv3_pow_treats_Inf_as_an_even_int 0x00000080 +/* + * If set, logb(subnormal) returns (double) ilogb(subnormal); otherwise + * logb(subnormal) returns logb(DBL_MIN). Analogous comment applies to + * logbf and logbl. + */ +#define _C99SUSv3_logb_subnormal_is_like_ilogb 0x00000040 +/* + * If set, ilogb(0/+Inf/-Inf/NaN) raises FE_INVALID as per SUSv3; otherwise + * no exception is raised. Analogous comment applies to ilogbf and ilogbl. + */ +#define _C99SUSv3_ilogb_0InfNaN_raises_invalid 0x00000020 + +/* + * __xpg6 = _C99SUSv3_mode_OFF disables C99/SUSv3 standards conformance mode. + */ +#define _C99SUSv3_mode_OFF 0xFFFF0000 + +#if !defined(_ASM) +extern unsigned int __xpg6; +#endif + +#endif /* _XPG6_H */ |