diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a05619 --- /dev/null +++ b/Makefile @@ -0,0 +1,212 @@ +# @(#)Makefile 5.1beta 93/09/24 +# $FreeBSD: src/lib/msun/Makefile,v 1.112 2011/10/21 06:27:56 das Exp $ +# +# ==================================================== +# Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +# +# Developed at SunPro, a Sun Microsystems, Inc. business. +# Permission to use, copy, modify, and distribute this +# software is freely granted, provided that this notice +# is preserved. +# ==================================================== +# +# + +.if ${MACHINE_CPUARCH} == "i386" +ARCH_SUBDIR= i387 +.else +ARCH_SUBDIR= ${MACHINE_CPUARCH} +.endif + +.include "${ARCH_SUBDIR}/Makefile.inc" + +.PATH: ${.CURDIR}/${ARCH_SUBDIR} + +# long double format +.if ${LDBL_PREC} == 64 +.PATH: ${.CURDIR}/ld80 +CFLAGS+= -I${.CURDIR}/ld80 +.elif ${LDBL_PREC} == 113 +.PATH: ${.CURDIR}/ld128 +CFLAGS+= -I${.CURDIR}/ld128 +.endif + +.PATH: ${.CURDIR}/bsdsrc +.PATH: ${.CURDIR}/src +.PATH: ${.CURDIR}/man + +LIB= m +SHLIBDIR?= /lib +SHLIB_MAJOR= 5 +WARNS?= 1 +COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \ + e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ + e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_cosh.c e_coshf.c e_exp.c \ + e_expf.c e_fmod.c e_fmodf.c e_gamma.c e_gamma_r.c e_gammaf.c \ + e_gammaf_r.c e_hypot.c e_hypotf.c e_j0.c e_j0f.c e_j1.c e_j1f.c \ + e_jn.c e_jnf.c e_lgamma.c e_lgamma_r.c e_lgammaf.c e_lgammaf_r.c \ + e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c \ + e_pow.c e_powf.c e_rem_pio2.c \ + e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c \ + e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c fenv.c \ + k_cos.c k_cosf.c k_exp.c k_expf.c k_rem_pio2.c k_sin.c k_sinf.c \ + k_tan.c k_tanf.c \ + s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_carg.c s_cargf.c s_cargl.c \ + s_cbrt.c s_cbrtf.c s_ceil.c s_ceilf.c \ + s_copysign.c s_copysignf.c s_cos.c s_cosf.c \ + s_csqrt.c s_csqrtf.c s_erf.c s_erff.c \ + s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c \ + s_finite.c s_finitef.c \ + s_floor.c s_floorf.c s_fma.c s_fmaf.c \ + s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c \ + s_fminf.c s_fminl.c s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \ + s_ilogbl.c s_isfinite.c s_isnan.c s_isnormal.c \ + s_llrint.c s_llrintf.c s_llround.c s_llroundf.c s_llroundl.c \ + s_log1p.c s_log1pf.c s_logb.c s_logbf.c s_lrint.c s_lrintf.c \ + s_lround.c s_lroundf.c s_lroundl.c s_modff.c \ + s_nan.c s_nearbyint.c s_nextafter.c s_nextafterf.c \ + s_nexttowardf.c s_remquo.c s_remquof.c \ + s_rint.c s_rintf.c s_round.c s_roundf.c s_roundl.c \ + s_scalbln.c s_scalbn.c s_scalbnf.c s_signbit.c \ + s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \ + s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \ + w_cabs.c w_cabsf.c w_drem.c w_dremf.c + +# Location of fpmath.h and _fpmath.h +LIBCDIR= ${.CURDIR}/../libc +.if exists(${LIBCDIR}/${MACHINE_ARCH}) +LIBC_ARCH=${MACHINE_ARCH} +.else +LIBC_ARCH=${MACHINE_CPUARCH} +.endif +CFLAGS+= -I${.CURDIR}/src -I${LIBCDIR}/include \ + -I${LIBCDIR}/${LIBC_ARCH} +SYM_MAPS+= ${.CURDIR}/Symbol.map + +VERSION_DEF= ${LIBCDIR}/Versions.def +SYMBOL_MAPS= ${SYM_MAPS} + +# C99 long double functions +COMMON_SRCS+= s_copysignl.c s_fabsl.c s_llrintl.c s_lrintl.c s_modfl.c +.if ${LDBL_PREC} != 53 +# If long double != double use these; otherwise, we alias the double versions. +COMMON_SRCS+= e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c \ + e_hypotl.c e_remainderl.c e_sqrtl.c \ + invtrig.c k_cosl.c k_sinl.c k_tanl.c \ + s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c s_cprojl.c \ + s_csqrtl.c s_exp2l.c s_floorl.c s_fmal.c \ + s_frexpl.c s_logbl.c s_nanl.c s_nextafterl.c s_nexttoward.c \ + s_remquol.c s_rintl.c s_scalbnl.c \ + s_sinl.c s_tanl.c s_truncl.c w_cabsl.c +.endif + +# C99 complex functions +COMMON_SRCS+= s_ccosh.c s_ccoshf.c s_cexp.c s_cexpf.c \ + s_cimag.c s_cimagf.c s_cimagl.c \ + s_conj.c s_conjf.c s_conjl.c \ + s_cproj.c s_cprojf.c s_creal.c s_crealf.c s_creall.c \ + s_csinh.c s_csinhf.c s_ctanh.c s_ctanhf.c + +# FreeBSD's C library supplies these functions: +#COMMON_SRCS+= s_fabs.c s_frexp.c s_isnan.c s_ldexp.c s_modf.c + +# Exclude the generic versions of what we provide in the MD area. +.if defined(ARCH_SRCS) +.for i in ${ARCH_SRCS} +COMMON_SRCS:= ${COMMON_SRCS:N${i:R}.c} +.endfor +.endif + +# Some files need certain gcc built-in functions to be disabled, since gcc's +# model of the functions bogusly assumes -fno-trapping-math. +XRINT_CFLAGS= -fno-builtin-rint -fno-builtin-rintf -fno-builtin-rintl +CFLAGS+= ${XRINT_CFLAGS} +XRINT_CFLAGS:= ${.IMPSRC:M*/s_nearbyint.c:C/^.+$/${XRINT_CFLAGS}/:C/^$//} + +SRCS= ${COMMON_SRCS} ${ARCH_SRCS} + +INCS= fenv.h math.h + +MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \ + ceil.3 ccos.3 ccosh.3 cexp.3 \ + cimag.3 copysign.3 cos.3 cosh.3 csqrt.3 erf.3 exp.3 fabs.3 fdim.3 \ + feclearexcept.3 feenableexcept.3 fegetenv.3 \ + fegetround.3 fenv.3 floor.3 \ + fma.3 fmax.3 fmod.3 hypot.3 ieee.3 ieee_test.3 ilogb.3 j0.3 \ + lgamma.3 log.3 lrint.3 lround.3 math.3 nan.3 \ + nextafter.3 remainder.3 rint.3 \ + round.3 scalbn.3 signbit.3 sin.3 sinh.3 sqrt.3 tan.3 tanh.3 trunc.3 \ + complex.3 + +MLINKS+=acos.3 acosf.3 acos.3 acosl.3 +MLINKS+=acosh.3 acoshf.3 +MLINKS+=asin.3 asinf.3 asin.3 asinl.3 +MLINKS+=asinh.3 asinhf.3 +MLINKS+=atan.3 atanf.3 atan.3 atanl.3 +MLINKS+=atanh.3 atanhf.3 +MLINKS+=atan2.3 atan2f.3 atan2.3 atan2l.3 \ + atan2.3 carg.3 atan2.3 cargf.3 atan2.3 cargl.3 +MLINKS+=ccos.3 ccosf.3 ccos.3 csin.3 ccos.3 csinf.3 ccos.3 ctan.3 ccos.3 ctanf.3 +MLINKS+=ccosh.3 ccoshf.3 ccosh.3 csinh.3 ccosh.3 csinhf.3 \ + ccosh.3 ctanh.3 ccosh.3 ctanhf.3 +MLINKS+=ceil.3 ceilf.3 ceil.3 ceill.3 +MLINKS+=cexp.3 cexpf.3 +MLINKS+=cimag.3 cimagf.3 cimag.3 cimagl.3 \ + cimag.3 conj.3 cimag.3 conjf.3 cimag.3 conjl.3 \ + cimag.3 cproj.3 cimag.3 cprojf.3 cimag.3 cprojl.3 \ + cimag.3 creal.3 cimag.3 crealf.3 cimag.3 creall.3 +MLINKS+=copysign.3 copysignf.3 copysign.3 copysignl.3 +MLINKS+=cos.3 cosf.3 cos.3 cosl.3 +MLINKS+=cosh.3 coshf.3 +MLINKS+=csqrt.3 csqrtf.3 csqrt.3 csqrtl.3 +MLINKS+=erf.3 erfc.3 erf.3 erff.3 erf.3 erfcf.3 +MLINKS+=exp.3 expm1.3 exp.3 expm1f.3 exp.3 pow.3 exp.3 powf.3 \ + exp.3 exp2.3 exp.3 exp2f.3 exp.3 exp2l.3 exp.3 expf.3 +MLINKS+=fabs.3 fabsf.3 fabs.3 fabsl.3 +MLINKS+=fdim.3 fdimf.3 fdim.3 fdiml.3 +MLINKS+=feclearexcept.3 fegetexceptflag.3 feclearexcept.3 feraiseexcept.3 \ + feclearexcept.3 fesetexceptflag.3 feclearexcept.3 fetestexcept.3 +MLINKS+=feenableexcept.3 fedisableexcept.3 feenableexcept.3 fegetexcept.3 +MLINKS+=fegetenv.3 feholdexcept.3 fegetenv.3 fesetenv.3 \ + fegetenv.3 feupdateenv.3 +MLINKS+=fegetround.3 fesetround.3 +MLINKS+=floor.3 floorf.3 floor.3 floorl.3 +MLINKS+=fma.3 fmaf.3 fma.3 fmal.3 +MLINKS+=fmax.3 fmaxf.3 fmax.3 fmaxl.3 \ + fmax.3 fmin.3 fmax.3 fminf.3 fmax.3 fminl.3 +MLINKS+=fmod.3 fmodf.3 fmod.3 fmodl.3 +MLINKS+=hypot.3 cabs.3 hypot.3 cabsf.3 hypot.3 cabsl.3 \ + hypot.3 hypotf.3 hypot.3 hypotl.3 +MLINKS+=ieee_test.3 scalb.3 ieee_test.3 scalbf.3 +MLINKS+=ieee_test.3 significand.3 ieee_test.3 significandf.3 +MLINKS+=ilogb.3 ilogbf.3 ilogb.3 ilogbl.3 \ + ilogb.3 logb.3 ilogb.3 logbf.3 ilogb.3 logbl.3 +MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 +MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3 +MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 \ + lgamma.3 tgamma.3 lgamma.3 tgammaf.3 +MLINKS+=log.3 log10.3 log.3 log10f.3 log.3 log1p.3 log.3 log1pf.3 log.3 logf.3 log.3 log2.3 log.3 log2f.3 +MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 llrintl.3 \ + lrint.3 lrintf.3 lrint.3 lrintl.3 +MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \ + lround.3 lroundf.3 lround.3 lroundl.3 +MLINKS+=nan.3 nanf.3 nan.3 nanl.3 +MLINKS+=nextafter.3 nextafterf.3 nextafter.3 nextafterl.3 +MLINKS+=nextafter.3 nexttoward.3 nextafter.3 nexttowardf.3 +MLINKS+=nextafter.3 nexttowardl.3 +MLINKS+=remainder.3 remainderf.3 remainder.3 remainderl.3 \ + remainder.3 remquo.3 remainder.3 remquof.3 remainder.3 remquol.3 +MLINKS+=rint.3 rintf.3 rint.3 rintl.3 \ + rint.3 nearbyint.3 rint.3 nearbyintf.3 rint.3 nearbyintl.3 +MLINKS+=round.3 roundf.3 round.3 roundl.3 +MLINKS+=scalbn.3 scalbln.3 scalbn.3 scalblnf.3 scalbn.3 scalblnl.3 +MLINKS+=scalbn.3 scalbnf.3 scalbn.3 scalbnl.3 +MLINKS+=sin.3 sinf.3 sin.3 sinl.3 +MLINKS+=sinh.3 sinhf.3 +MLINKS+=sqrt.3 cbrt.3 sqrt.3 cbrtf.3 sqrt.3 cbrtl.3 sqrt.3 sqrtf.3 \ + sqrt.3 sqrtl.3 +MLINKS+=tan.3 tanf.3 tan.3 tanl.3 +MLINKS+=tanh.3 tanhf.3 +MLINKS+=trunc.3 truncf.3 trunc.3 truncl.3 + +.include diff --git a/Symbol.map b/Symbol.map new file mode 100644 index 0000000..1a8303b --- /dev/null +++ b/Symbol.map @@ -0,0 +1,252 @@ +/* + * $FreeBSD: src/lib/msun/Symbol.map,v 1.30 2011/10/17 05:41:03 das Exp $ + */ + +/* 7.0-CURRENT */ +FBSD_1.0 { + __fe_dfl_env; + tgamma; + acos; + acosf; + acosh; + acoshf; + asin; + asinf; + atan2; + atan2f; + atanh; + atanhf; + cosh; + coshf; + exp; + expf; + fmod; + fmodf; + gamma; + gamma_r; + gammaf; + gammaf_r; + hypot; + hypotf; + j0; + y0; + j0f; + y0f; + j1; + y1; + j1f; + y1f; + jn; + yn; + jnf; + ynf; + lgamma; + lgamma_r; + lgammaf; + lgammaf_r; + log; + log10; + log10f; + logf; + pow; + powf; + remainder; + remainderf; + scalb; + scalbf; + sinh; + sinhf; + sqrt; + sqrtf; + asinh; + asinhf; + atan; + atanf; + cbrt; + cbrtf; + ceil; + ceilf; + ceill; + cimag; + cimagf; + cimagl; + conj; + conjf; + conjl; + copysign; + copysignf; + copysignl; + cos; + cosf; + creal; + crealf; + creall; + erf; + erfc; + erff; + erfcf; + exp2; + exp2f; + expm1; + expm1f; + fabs; + fabsf; + fabsl; + fdim; + fdimf; + fdiml; + finite; + finitef; + floor; + floorf; + floorl; + fma; + fmaf; + fmal; + fmax; + fmaxf; + fmaxl; + fmin; + fminf; + fminl; + frexp; + frexpf; + frexpl; + ilogb; + ilogbf; + ilogbl; + __isfinite; + __isfinitef; + __isfinitel; + isnanf; + __isnanl; + __isnormal; + __isnormalf; + __isnormall; + llrint; + llrintf; + llround; + llroundf; + llroundl; + log1p; + log1pf; + logb; + logbf; + lrint; + lrintf; + lround; + lroundf; + lroundl; + modff; + modfl; + nearbyint; + nearbyintf; + nextafter; + nexttoward; + nexttowardl; + nextafterl; + nextafterf; + nexttowardf; + remquo; + remquof; + rint; + rintf; + round; + roundf; + roundl; + scalbln; + scalblnf; + scalblnl; + scalbn; + scalbnl; + scalbnf; + ldexpf; + ldexpl; + __signbit; + __signbitf; + __signbitl; + signgam; + significand; + significandf; + sin; + sinf; + tan; + tanf; + tanh; + tanhf; + trunc; + truncf; + truncl; + cabs; + cabsf; + drem; + dremf; +}; + +/* First added in 8.0-CURRENT */ +FBSD_1.1 { + carg; + cargf; + csqrt; + csqrtf; + logbl; + nan; + nanf; + nanl; + llrintl; + lrintl; + nearbyintl; + rintl; + exp2l; + sinl; + cosl; + tanl; + tgammaf; + sqrtl; + hypotl; + cabsl; + csqrtl; + remquol; + remainderl; + fmodl; + acosl; + asinl; + atan2l; + atanl; + cargl; + cproj; + cprojf; + cprojl; +}; + +/* First added in 9.0-CURRENT */ +FBSD_1.2 { + __isnanf; + cbrtl; + cexp; + cexpf; + log2; + log2f; +}; + +/* First added in 10.0-CURRENT */ +FBSD_1.3 { + feclearexcept; + fegetexceptflag; + fetestexcept; + fegetround; + fesetround; + fesetenv; + csin; + csinf; + csinh; + csinhf; + ccos; + ccosf; + ccosh; + ccoshf; + ctan; + ctanf; + ctanh; + ctanhf; +}; diff --git a/amd64/FILES b/amd64/FILES deleted file mode 100644 index 2ec38cb..0000000 --- a/amd64/FILES +++ /dev/null @@ -1,24 +0,0 @@ - Makefile.inc - Symbol.map - e_remainder.S - e_remainderf.S - e_remainderl.S - e_sqrt.S - e_sqrtf.S - e_sqrtl.S - fenv.c - fenv.h - s_llrint.S - s_llrintf.S - s_llrintl.S - s_logbl.S - s_lrint.S - s_lrintf.S - s_lrintl.S - s_remquo.S - s_remquof.S - s_remquol.S - s_rintl.S - s_scalbn.S - s_scalbnf.S - s_scalbnl.S diff --git a/amd64/Symbol.map b/amd64/Symbol.map index 4d48690..00db005 100644 --- a/amd64/Symbol.map +++ b/amd64/Symbol.map @@ -1,5 +1,5 @@ /* - * $FreeBSD: src/lib/msun/amd64/Symbol.map,v 1.2 2007/04/29 14:05:21 deischen Exp $ + * $FreeBSD: src/lib/msun/amd64/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ */ FBSD_1.0 { fesetexceptflag; @@ -7,8 +7,6 @@ FBSD_1.0 { fegetenv; feholdexcept; feupdateenv; - __feenableexcept; - __fedisableexcept; feenableexcept; fedisableexcept; }; diff --git a/amd64/fenv.c b/amd64/fenv.c index c12ad56..069dd7a 100644 --- a/amd64/fenv.c +++ b/amd64/fenv.c @@ -23,13 +23,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/amd64/fenv.c,v 1.5 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: src/lib/msun/amd64/fenv.c,v 1.8 2011/10/21 06:25:31 das Exp $ */ #include #include #include -#include + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif const fenv_t __fe_dfl_env = { { 0xffff0000 | __INITIAL_FPUCW__, @@ -41,6 +47,9 @@ const fenv_t __fe_dfl_env = { __INITIAL_MXCSR__ }; +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { @@ -69,6 +78,10 @@ feraiseexcept(int excepts) return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { @@ -98,6 +111,8 @@ feholdexcept(fenv_t *envp) return (0); } +extern inline int fesetenv(const fenv_t *__envp); + int feupdateenv(const fenv_t *envp) { @@ -120,12 +135,12 @@ __feenableexcept(int mask) mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); - return (~omask); + return (omask); } int @@ -137,12 +152,12 @@ __fedisableexcept(int mask) mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); - return (~omask); + return (omask); } __weak_reference(__feenableexcept, feenableexcept); diff --git a/amd64/fenv.h b/amd64/fenv.h index a2afd5f..27ec50f 100644 --- a/amd64/fenv.h +++ b/amd64/fenv.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/amd64/fenv.h,v 1.7 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: src/lib/msun/amd64/fenv.h,v 1.8 2011/10/10 15:43:09 das Exp $ */ #ifndef _FENV_H_ @@ -32,6 +32,10 @@ #include #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef struct { struct { __uint32_t __control; @@ -89,7 +93,7 @@ extern const fenv_t __fe_dfl_env; #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __env; @@ -107,7 +111,7 @@ feclearexcept(int __excepts) return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { __uint32_t __mxcsr; @@ -122,7 +126,7 @@ fegetexceptflag(fexcept_t *__flagp, int __excepts) int fesetexceptflag(const fexcept_t *__flagp, int __excepts); int feraiseexcept(int __excepts); -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { __uint32_t __mxcsr; @@ -133,7 +137,7 @@ fetestexcept(int __excepts) return ((__status | __mxcsr) & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { __uint16_t __control; @@ -148,7 +152,7 @@ fegetround(void) return (__control & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { __uint32_t __mxcsr; @@ -173,7 +177,7 @@ fesetround(int __round) int fegetenv(fenv_t *__envp); int feholdexcept(fenv_t *__envp); -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { @@ -197,7 +201,8 @@ int feupdateenv(const fenv_t *__envp); int feenableexcept(int __mask); int fedisableexcept(int __mask); -static __inline int +/* We currently provide no external definition of fegetexcept(). */ +static inline int fegetexcept(void) { __uint16_t __control; diff --git a/arm/Makefile.inc b/arm/Makefile.inc new file mode 100644 index 0000000..25cccff --- /dev/null +++ b/arm/Makefile.inc @@ -0,0 +1,4 @@ +# $FreeBSD: src/lib/msun/arm/Makefile.inc,v 1.2 2006/03/27 23:59:44 deischen Exp $ + +LDBL_PREC = 53 +SYM_MAPS += ${.CURDIR}/arm/Symbol.map diff --git a/arm/Symbol.map b/arm/Symbol.map new file mode 100644 index 0000000..f922019 --- /dev/null +++ b/arm/Symbol.map @@ -0,0 +1,13 @@ +/* + * $FreeBSD: src/lib/msun/arm/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ + */ +FBSD_1.0 { +}; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; diff --git a/arm/fenv.c b/arm/fenv.c new file mode 100644 index 0000000..bf6b1f9 --- /dev/null +++ b/arm/fenv.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/arm/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $ + */ + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + +/* + * Hopefully the system ID byte is immutable, so it's valid to use + * this as a default environment. + */ +const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); diff --git a/arm/fenv.h b/arm/fenv.h new file mode 100644 index 0000000..3421b8f --- /dev/null +++ b/arm/fenv.h @@ -0,0 +1,223 @@ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.6 2011/10/10 15:43:09 das Exp $ + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include + +#ifndef __fenv_static +#define __fenv_static static +#endif + +typedef __uint32_t fenv_t; +typedef __uint32_t fexcept_t; + +/* Exception flags */ +#define FE_INVALID 0x0001 +#define FE_DIVBYZERO 0x0002 +#define FE_OVERFLOW 0x0004 +#define FE_UNDERFLOW 0x0008 +#define FE_INEXACT 0x0010 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* Rounding modes */ +#define FE_TONEAREST 0x0000 +#define FE_TOWARDZERO 0x0001 +#define FE_UPWARD 0x0002 +#define FE_DOWNWARD 0x0003 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ + FE_UPWARD | FE_TOWARDZERO) +__BEGIN_DECLS + +/* Default floating-point environment */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +/* We need to be able to map status flag positions to mask flag positions */ +#define _FPUSW_SHIFT 16 +#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) + +#ifdef ARM_HARD_FLOAT +#define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr))) +#define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr)) +#else +#define __rfs(__fpsr) +#define __wfs(__fpsr) +#endif + +__fenv_static inline int +feclearexcept(int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __fpsr &= ~__excepts; + __wfs(__fpsr); + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + *__flagp = __fpsr & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __fpsr &= ~__excepts; + __fpsr |= *__flagp & __excepts; + __wfs(__fpsr); + return (0); +} + +__fenv_static inline int +feraiseexcept(int __excepts) +{ + fexcept_t __ex = __excepts; + + fesetexceptflag(&__ex, __excepts); /* XXX */ + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + return (__fpsr & __excepts); +} + +__fenv_static inline int +fegetround(void) +{ + + /* + * Apparently, the rounding mode is specified as part of the + * instruction format on ARM, so the dynamic rounding mode is + * indeterminate. Some FPUs may differ. + */ + return (-1); +} + +__fenv_static inline int +fesetround(int __round) +{ + + return (-1); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + + __rfs(__envp); + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + fenv_t __env; + + __rfs(&__env); + *__envp = __env; + __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); + __wfs(__env); + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + + __wfs(*__envp); + return (0); +} + +__fenv_static inline int +feupdateenv(const fenv_t *__envp) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __wfs(*__envp); + feraiseexcept(__fpsr & FE_ALL_EXCEPT); + return (0); +} + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + fenv_t __old_fpsr, __new_fpsr; + + __rfs(&__old_fpsr); + __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT; + __wfs(__new_fpsr); + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fedisableexcept(int __mask) +{ + fenv_t __old_fpsr, __new_fpsr; + + __rfs(&__old_fpsr); + __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); + __wfs(__new_fpsr); + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fegetexcept(void) +{ + fenv_t __fpsr; + + __rfs(&__fpsr); + return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT); +} + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* !_FENV_H_ */ diff --git a/bsdsrc/FILES b/bsdsrc/FILES deleted file mode 100644 index 44f9758..0000000 --- a/bsdsrc/FILES +++ /dev/null @@ -1,4 +0,0 @@ -b_exp.c -b_log.c -b_tgamma.c -mathimpl.h diff --git a/bsdsrc/b_exp.c b/bsdsrc/b_exp.c index 5c0bd07..fd3ed0f 100644 --- a/bsdsrc/b_exp.c +++ b/bsdsrc/b_exp.c @@ -33,7 +33,7 @@ /* @(#)exp.c 8.1 (Berkeley) 6/4/93 */ #include -__FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.8 2008/02/22 02:26:51 das Exp $"); +__FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.9 2011/10/16 05:37:20 das Exp $"); /* EXP(X) @@ -74,16 +74,16 @@ __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.8 2008/02/22 02:26:51 das Ex #include "mathimpl.h" -const static double p1 = 0x1.555555555553ep-3; -const static double p2 = -0x1.6c16c16bebd93p-9; -const static double p3 = 0x1.1566aaf25de2cp-14; -const static double p4 = -0x1.bbd41c5d26bf1p-20; -const static double p5 = 0x1.6376972bea4d0p-25; -const static double ln2hi = 0x1.62e42fee00000p-1; -const static double ln2lo = 0x1.a39ef35793c76p-33; -const static double lnhuge = 0x1.6602b15b7ecf2p9; -const static double lntiny = -0x1.77af8ebeae354p9; -const static double invln2 = 0x1.71547652b82fep0; +static const double p1 = 0x1.555555555553ep-3; +static const double p2 = -0x1.6c16c16bebd93p-9; +static const double p3 = 0x1.1566aaf25de2cp-14; +static const double p4 = -0x1.bbd41c5d26bf1p-20; +static const double p5 = 0x1.6376972bea4d0p-25; +static const double ln2hi = 0x1.62e42fee00000p-1; +static const double ln2lo = 0x1.a39ef35793c76p-33; +static const double lnhuge = 0x1.6602b15b7ecf2p9; +static const double lntiny = -0x1.77af8ebeae354p9; +static const double invln2 = 0x1.71547652b82fep0; #if 0 double exp(x) diff --git a/i387/FILES b/i387/FILES deleted file mode 100644 index ff2e539..0000000 --- a/i387/FILES +++ /dev/null @@ -1,53 +0,0 @@ - Makefile.inc - Symbol.map - e_exp.S - e_fmod.S - e_log.S - e_log10.S - e_log10f.S - e_logf.S - e_remainder.S - e_remainderf.S - e_remainderl.S - e_sqrt.S - e_sqrtf.S - e_sqrtl.S - fenv.c - fenv.h - invtrig.c - s_ceil.S - s_ceilf.S - s_ceill.S - s_copysign.S - s_copysignf.S - s_copysignl.S - s_cos.S - s_finite.S - s_floor.S - s_floorf.S - s_floorl.S - s_llrint.S - s_llrintf.S - s_llrintl.S - s_logb.S - s_logbf.S - s_logbl.S - s_lrint.S - s_lrintf.S - s_lrintl.S - s_remquo.S - s_remquof.S - s_remquol.S - s_rint.S - s_rintf.S - s_rintl.S - s_scalbn.S - s_scalbnf.S - s_scalbnl.S - s_significand.S - s_significandf.S - s_sin.S - s_tan.S - s_trunc.S - s_truncf.S - s_truncl.S diff --git a/i387/Symbol.map b/i387/Symbol.map index 7e01ba1..e5029ad 100644 --- a/i387/Symbol.map +++ b/i387/Symbol.map @@ -1,5 +1,5 @@ /* - * $FreeBSD: src/lib/msun/i387/Symbol.map,v 1.2 2007/04/29 14:05:21 deischen Exp $ + * $FreeBSD: src/lib/msun/i387/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ */ FBSD_1.0 { __has_sse; @@ -9,8 +9,6 @@ FBSD_1.0 { fegetenv; feholdexcept; feupdateenv; - __feenableexcept; - __fedisableexcept; feenableexcept; fedisableexcept; }; diff --git a/i387/fenv.c b/i387/fenv.c index acb9a55..2c4c034 100644 --- a/i387/fenv.c +++ b/i387/fenv.c @@ -23,14 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/i387/fenv.c,v 1.4 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: src/lib/msun/i387/fenv.c,v 1.8 2011/10/21 06:25:31 das Exp $ */ #include #include #include + +#define __fenv_static #include "fenv.h" +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = { __INITIAL_NPXCW__, 0x0000, @@ -83,6 +89,9 @@ __test_sse(void) return (0); } +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { @@ -114,6 +123,10 @@ feraiseexcept(int excepts) return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { @@ -149,6 +162,8 @@ feholdexcept(fenv_t *envp) return (0); } +extern inline int fesetenv(const fenv_t *__envp); + int feupdateenv(const fenv_t *envp) { @@ -177,14 +192,14 @@ __feenableexcept(int mask) __stmxcsr(&mxcsr); else mxcsr = 0; - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); if (__HAS_SSE()) { mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); } - return (~omask); + return (omask); } int @@ -199,14 +214,14 @@ __fedisableexcept(int mask) __stmxcsr(&mxcsr); else mxcsr = 0; - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); if (__HAS_SSE()) { mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); } - return (~omask); + return (omask); } __weak_reference(__feenableexcept, feenableexcept); diff --git a/i387/fenv.h b/i387/fenv.h index 38a20ce..ed2c57e 100644 --- a/i387/fenv.h +++ b/i387/fenv.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.7 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.8 2011/10/10 15:43:09 das Exp $ */ #ifndef _FENV_H_ @@ -32,6 +32,10 @@ #include #include +#ifndef __fenv_static +#define __fenv_static static +#endif + /* * To preserve binary compatibility with FreeBSD 5.3, we pack the * mxcsr into some reserved fields, rather than changing sizeof(fenv_t). @@ -110,7 +114,7 @@ extern const fenv_t __fe_dfl_env; #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __env; @@ -131,7 +135,7 @@ feclearexcept(int __excepts) return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { __uint32_t __mxcsr; @@ -149,7 +153,7 @@ fegetexceptflag(fexcept_t *__flagp, int __excepts) int fesetexceptflag(const fexcept_t *__flagp, int __excepts); int feraiseexcept(int __excepts); -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { __uint32_t __mxcsr; @@ -163,7 +167,7 @@ fetestexcept(int __excepts) return ((__status | __mxcsr) & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { __uint16_t __control; @@ -178,7 +182,7 @@ fegetround(void) return (__control & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { __uint32_t __mxcsr; @@ -205,7 +209,7 @@ fesetround(int __round) int fegetenv(fenv_t *__envp); int feholdexcept(fenv_t *__envp); -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { fenv_t __env = *__envp; @@ -234,7 +238,8 @@ int feupdateenv(const fenv_t *__envp); int feenableexcept(int __mask); int fedisableexcept(int __mask); -static __inline int +/* We currently provide no external definition of fegetexcept(). */ +static inline int fegetexcept(void) { __uint16_t __control; diff --git a/ia64/Makefile.inc b/ia64/Makefile.inc new file mode 100644 index 0000000..1a62f25 --- /dev/null +++ b/ia64/Makefile.inc @@ -0,0 +1,5 @@ +# $FreeBSD: src/lib/msun/ia64/Makefile.inc,v 1.3 2006/03/27 23:59:45 deischen Exp $ + +ARCH_SRCS = s_fma.S s_fmaf.S s_fmal.S +LDBL_PREC = 64 +SYM_MAPS += ${.CURDIR}/ia64/Symbol.map diff --git a/ia64/Symbol.map b/ia64/Symbol.map new file mode 100644 index 0000000..3dbccac --- /dev/null +++ b/ia64/Symbol.map @@ -0,0 +1,13 @@ +/* + * $FreeBSD: src/lib/msun/ia64/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ + */ +FBSD_1.0 { + feupdateenv; +}; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; +}; diff --git a/ia64/fenv.c b/ia64/fenv.c new file mode 100644 index 0000000..b66c35d --- /dev/null +++ b/ia64/fenv.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/ia64/fenv.c,v 1.4 2011/10/16 05:37:56 das Exp $ + */ + +#include + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + +const fenv_t __fe_dfl_env = 0x0009804c8a70033fULL; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); + +/* + * It doesn't pay to inline feupdateenv() because it includes one of + * the rare uses of feraiseexcept() where the argument is not a + * constant. Thus, no dead code elimination can occur, resulting in + * significant bloat. + */ +int +feupdateenv(const fenv_t *envp) +{ + fenv_t fpsr; + + __stfpsr(&fpsr); + __ldfpsr(*envp); + feraiseexcept((fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); + return (0); +} diff --git a/ia64/fenv.h b/ia64/fenv.h new file mode 100644 index 0000000..19a3f6a --- /dev/null +++ b/ia64/fenv.h @@ -0,0 +1,248 @@ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/ia64/fenv.h,v 1.5 2011/10/10 15:43:09 das Exp $ + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include + +#ifndef __fenv_static +#define __fenv_static static +#endif + +typedef __uint64_t fenv_t; +typedef __uint16_t fexcept_t; + +/* Exception flags */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* Rounding modes */ +#define FE_TONEAREST 0x0000 +#define FE_DOWNWARD 0x0400 +#define FE_UPWARD 0x0800 +#define FE_TOWARDZERO 0x0c00 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ + FE_UPWARD | FE_TOWARDZERO) + +__BEGIN_DECLS + +/* Default floating-point environment */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +#define _FPUSW_SHIFT 13 + +#define __stfpsr(__r) __asm __volatile("mov %0=ar.fpsr" : "=r" (*(__r))) +#define __ldfpsr(__r) __asm __volatile("mov ar.fpsr=%0;;" : : "r" (__r)) + +__fenv_static inline int +feclearexcept(int __excepts) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + __fpsr &= ~((fenv_t)__excepts << _FPUSW_SHIFT); + __ldfpsr(__fpsr); + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + *__flagp = (fexcept_t)(__fpsr >> _FPUSW_SHIFT) & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + __fpsr &= ~((fenv_t)__excepts << _FPUSW_SHIFT); + __fpsr |= (fenv_t)(__excepts & *__flagp) << _FPUSW_SHIFT; + __ldfpsr(__fpsr); + return (0); +} + +/* + * It is worthwhile to use the inline version of this function iff it + * is called with arguments that are compile-time constants (due to + * dead code elimination). Unfortunately, gcc isn't smart enough to + * figure this out automatically, and there's no way to tell it. + * We assume that constant arguments will be the common case. + */ +__fenv_static inline int +feraiseexcept(int __excepts) +{ + volatile double d; + + /* + * With a compiler that supports the FENV_ACCESS pragma + * properly, simple expressions like '0.0 / 0.0' should + * be sufficient to generate traps. Unfortunately, we + * need to bring a volatile variable into the equation + * to prevent incorrect optimizations. + */ + if (__excepts & FE_INVALID) { + d = 0.0; + d = 0.0 / d; + } + if (__excepts & FE_DIVBYZERO) { + d = 0.0; + d = 1.0 / d; + } + if (__excepts & FE_OVERFLOW) { + d = 0x1.ffp1023; + d *= 2.0; + } + if (__excepts & FE_UNDERFLOW) { + d = 0x1p-1022; + d /= 0x1p1023; + } + if (__excepts & FE_INEXACT) { + d = 0x1p-1022; + d += 1.0; + } + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + return ((__fpsr >> _FPUSW_SHIFT) & __excepts); +} + + +__fenv_static inline int +fegetround(void) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + return (__fpsr & _ROUND_MASK); +} + +__fenv_static inline int +fesetround(int __round) +{ + fenv_t __fpsr; + + if (__round & ~_ROUND_MASK) + return (-1); + __stfpsr(&__fpsr); + __fpsr &= ~_ROUND_MASK; + __fpsr |= __round; + __ldfpsr(__fpsr); + return (0); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + + __stfpsr(__envp); + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + *__envp = __fpsr; + __fpsr &= ~((fenv_t)FE_ALL_EXCEPT << _FPUSW_SHIFT); + __fpsr |= FE_ALL_EXCEPT; + __ldfpsr(__fpsr); + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + + __ldfpsr(*__envp); + return (0); +} + +int feupdateenv(const fenv_t *__envp); + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + fenv_t __newfpsr, __oldfpsr; + + __stfpsr(&__oldfpsr); + __newfpsr = __oldfpsr & ~(__mask & FE_ALL_EXCEPT); + __ldfpsr(__newfpsr); + return (~__oldfpsr & FE_ALL_EXCEPT); +} + +static inline int +fedisableexcept(int __mask) +{ + fenv_t __newfpsr, __oldfpsr; + + __stfpsr(&__oldfpsr); + __newfpsr = __oldfpsr | (__mask & FE_ALL_EXCEPT); + __ldfpsr(__newfpsr); + return (~__oldfpsr & FE_ALL_EXCEPT); +} + +static inline int +fegetexcept(void) +{ + fenv_t __fpsr; + + __stfpsr(&__fpsr); + return (~__fpsr & FE_ALL_EXCEPT); +} + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* !_FENV_H_ */ diff --git a/ia64/s_fma.S b/ia64/s_fma.S new file mode 100644 index 0000000..19d16b5 --- /dev/null +++ b/ia64/s_fma.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ia64/s_fma.S,v 1.2 2009/05/25 14:37:10 attilio Exp $") + +ENTRY(fma, 3) +{ + fma.d f8 = f8, f9, f10 + br.ret.sptk b0 +} +END(fma) diff --git a/ia64/s_fmaf.S b/ia64/s_fmaf.S new file mode 100644 index 0000000..202d710 --- /dev/null +++ b/ia64/s_fmaf.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ia64/s_fmaf.S,v 1.2 2009/05/25 14:37:10 attilio Exp $") + +ENTRY(fmaf, 3) +{ + fma.s f8 = f8, f9, f10 + br.ret.sptk b0 +} +END(fmaf) diff --git a/ia64/s_fmal.S b/ia64/s_fmal.S new file mode 100644 index 0000000..f0a9680 --- /dev/null +++ b/ia64/s_fmal.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ia64/s_fmal.S,v 1.2 2009/05/25 14:37:10 attilio Exp $") + +ENTRY(fmal, 3) +{ + fma f8 = f8, f9, f10 + br.ret.sptk b0 +} +END(fmal) diff --git a/ld128/e_rem_pio2l.h b/ld128/e_rem_pio2l.h index 5fcbf3b..3e69401 100644 --- a/ld128/e_rem_pio2l.h +++ b/ld128/e_rem_pio2l.h @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/e_rem_pio2l.h,v 1.2 2011/05/30 19:41:28 kargl Exp $"); /* ld128 version of __ieee754_rem_pio2l(x,y) * @@ -24,7 +24,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #include "fpmath.h" diff --git a/ld128/invtrig.c b/ld128/invtrig.c index 945b439..f212e8d 100644 --- a/ld128/invtrig.c +++ b/ld128/invtrig.c @@ -25,7 +25,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/invtrig.c,v 1.1 2008/07/31 22:41:26 das Exp $"); #include "invtrig.h" diff --git a/ld128/k_cosl.c b/ld128/k_cosl.c index 6f424f4..1780efe 100644 --- a/ld128/k_cosl.c +++ b/ld128/k_cosl.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/k_cosl.c,v 1.1 2008/02/17 07:32:31 das Exp $"); /* * ld128 version of k_cos.c. See ../src/k_cos.c for most comments. diff --git a/ld128/k_sinl.c b/ld128/k_sinl.c index a6c4c45..02bcd18 100644 --- a/ld128/k_sinl.c +++ b/ld128/k_sinl.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/k_sinl.c,v 1.1 2008/02/17 07:32:31 das Exp $"); /* * ld128 version of k_sin.c. See ../src/k_sin.c for most comments. diff --git a/ld128/k_tanl.c b/ld128/k_tanl.c index 497cb4b..ed73904 100644 --- a/ld128/k_tanl.c +++ b/ld128/k_tanl.c @@ -12,13 +12,13 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/k_tanl.c,v 1.1 2008/02/17 07:32:31 das Exp $"); /* * ld128 version of k_tan.c. See ../src/k_tan.c for most comments. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* diff --git a/ld128/s_exp2l.c b/ld128/s_exp2l.c index 3273c1b..51e0a20 100644 --- a/ld128/s_exp2l.c +++ b/ld128/s_exp2l.c @@ -25,13 +25,13 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/ld128/s_exp2l.c,v 1.3 2008/02/13 10:44:44 bde Exp $"); #include #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #define TBLBITS 7 #define TBLSIZE (1 << TBLBITS) diff --git a/ld128/s_nanl.c b/ld128/s_nanl.c index 58f0a2a..48b5681 100644 --- a/ld128/s_nanl.c +++ b/ld128/s_nanl.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/ld128/s_nanl.c,v 1.3 2008/03/02 20:16:55 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" #include "../src/math_private.h" diff --git a/ld80/e_rem_pio2l.h b/ld80/e_rem_pio2l.h new file mode 100644 index 0000000..104eada --- /dev/null +++ b/ld80/e_rem_pio2l.h @@ -0,0 +1,149 @@ +/* From: @(#)e_rem_pio2.c 1.4 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + * Optimized by Bruce D. Evans. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/e_rem_pio2l.h,v 1.3 2011/06/18 13:56:33 benl Exp $"); + +/* ld80 version of __ieee754_rem_pio2l(x,y) + * + * return the remainder of x rem pi/2 in y[0]+y[1] + * use __kernel_rem_pio2() + */ + +#include + +#include "math.h" +#include "math_private.h" +#include "fpmath.h" + +#define BIAS (LDBL_MAX_EXP - 1) + +/* + * invpio2: 64 bits of 2/pi + * pio2_1: first 39 bits of pi/2 + * pio2_1t: pi/2 - pio2_1 + * pio2_2: second 39 bits of pi/2 + * pio2_2t: pi/2 - (pio2_1+pio2_2) + * pio2_3: third 39 bits of pi/2 + * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) + */ + +static const double +zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ +pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ +pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ +pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ + +#if defined(__amd64__) || defined(__i386__) +/* Long double constants are slow on these arches, and broken on i386. */ +static const volatile double +invpio2hi = 6.3661977236758138e-01, /* 0x145f306dc9c883.0p-53 */ +invpio2lo = -3.9356538861223811e-17, /* -0x16b00000000000.0p-107 */ +pio2_1thi = -1.0746346554971943e-12, /* -0x12e7b9676733af.0p-92 */ +pio2_1tlo = 8.8451028997905949e-29, /* 0x1c080000000000.0p-146 */ +pio2_2thi = 6.3683171635109499e-25, /* 0x18a2e03707344a.0p-133 */ +pio2_2tlo = 2.3183081793789774e-41, /* 0x10280000000000.0p-187 */ +pio2_3thi = -2.7529965190440717e-37, /* -0x176b7ed8fbbacc.0p-174 */ +pio2_3tlo = -4.2006647512740502e-54; /* -0x19c00000000000.0p-230 */ +#define invpio2 ((long double)invpio2hi + invpio2lo) +#define pio2_1t ((long double)pio2_1thi + pio2_1tlo) +#define pio2_2t ((long double)pio2_2thi + pio2_2tlo) +#define pio2_3t ((long double)pio2_3thi + pio2_3tlo) +#else +static const long double +invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 */ +pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */ +pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */ +pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ +#endif + +static inline __always_inline int +__ieee754_rem_pio2l(long double x, long double *y) +{ + union IEEEl2bits u,u1; + long double z,w,t,r,fn; + double tx[3],ty[2]; + int e0,ex,i,j,nx,n; + int16_t expsign; + + u.e = x; + expsign = u.xbits.expsign; + ex = expsign & 0x7fff; + if (ex < BIAS + 25 || (ex == BIAS + 25 && u.bits.manh < 0xc90fdaa2)) { + /* |x| ~< 2^25*(pi/2), medium size */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + fn = x*invpio2+0x1.8p63; + fn = fn-0x1.8p63; +#ifdef HAVE_EFFICIENT_IRINT + n = irint(fn); +#else + n = fn; +#endif + r = x-fn*pio2_1; + w = fn*pio2_1t; /* 1st round good to 102 bit */ + { + union IEEEl2bits u2; + int ex1; + j = ex; + y[0] = r-w; + u2.e = y[0]; + ex1 = u2.xbits.expsign & 0x7fff; + i = j-ex1; + if(i>22) { /* 2nd iteration needed, good to 141 */ + t = r; + w = fn*pio2_2; + r = t-w; + w = fn*pio2_2t-((t-r)-w); + y[0] = r-w; + u2.e = y[0]; + ex1 = u2.xbits.expsign & 0x7fff; + i = j-ex1; + if(i>61) { /* 3rd iteration need, 180 bits acc */ + t = r; /* will cover all possible cases */ + w = fn*pio2_3; + r = t-w; + w = fn*pio2_3t-((t-r)-w); + y[0] = r-w; + } + } + } + y[1] = (r-y[0])-w; + return n; + } + /* + * all other (large) arguments + */ + if(ex==0x7fff) { /* x is inf or NaN */ + y[0]=y[1]=x-x; return 0; + } + /* set z = scalbn(|x|,ilogb(x)-23) */ + u1.e = x; + e0 = ex - BIAS - 23; /* e0 = ilogb(|x|)-23; */ + u1.xbits.expsign = ex - e0; + z = u1.e; + for(i=0;i<2;i++) { + tx[i] = (double)((int32_t)(z)); + z = (z-tx[i])*two24; + } + tx[2] = z; + nx = 3; + while(tx[nx-1]==zero) nx--; /* skip zero term */ + n = __kernel_rem_pio2(tx,ty,e0,nx,2); + r = (long double)ty[0] + ty[1]; + w = ty[1] - (r - ty[0]); + if(expsign<0) {y[0] = -r; y[1] = -w; return -n;} + y[0] = r; y[1] = w; return n; +} diff --git a/ld80/invtrig.c b/ld80/invtrig.c new file mode 100644 index 0000000..aabd5d0 --- /dev/null +++ b/ld80/invtrig.c @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/invtrig.c,v 1.1 2008/07/31 22:41:26 das Exp $"); + +#include "invtrig.h" + +/* + * asinl() and acosl() + */ +const long double +pS0 = 1.66666666666666666631e-01L, +pS1 = -4.16313987993683104320e-01L, +pS2 = 3.69068046323246813704e-01L, +pS3 = -1.36213932016738603108e-01L, +pS4 = 1.78324189708471965733e-02L, +pS5 = -2.19216428382605211588e-04L, +pS6 = -7.10526623669075243183e-06L, +qS1 = -2.94788392796209867269e+00L, +qS2 = 3.27309890266528636716e+00L, +qS3 = -1.68285799854822427013e+00L, +qS4 = 3.90699412641738801874e-01L, +qS5 = -3.14365703596053263322e-02L; + +/* + * atanl() + */ +const long double atanhi[] = { + 4.63647609000806116202e-01L, + 7.85398163397448309628e-01L, + 9.82793723247329067960e-01L, + 1.57079632679489661926e+00L, +}; + +const long double atanlo[] = { + 1.18469937025062860669e-20L, + -1.25413940316708300586e-20L, + 2.55232234165405176172e-20L, + -2.50827880633416601173e-20L, +}; + +const long double aT[] = { + 3.33333333333333333017e-01L, + -1.99999999999999632011e-01L, + 1.42857142857046531280e-01L, + -1.11111111100562372733e-01L, + 9.09090902935647302252e-02L, + -7.69230552476207730353e-02L, + 6.66661718042406260546e-02L, + -5.88158892835030888692e-02L, + 5.25499891539726639379e-02L, + -4.70119845393155721494e-02L, + 4.03539201366454414072e-02L, + -2.91303858419364158725e-02L, + 1.24822046299269234080e-02L, +}; + +const long double pi_lo = -5.01655761266833202345e-20L; diff --git a/ld80/invtrig.h b/ld80/invtrig.h new file mode 100644 index 0000000..d4dfd5c --- /dev/null +++ b/ld80/invtrig.h @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/ld80/invtrig.h,v 1.2 2008/08/02 03:56:22 das Exp $ + */ + +#include + +#include "fpmath.h" + +#define BIAS (LDBL_MAX_EXP - 1) +#define MANH_SIZE LDBL_MANH_SIZE + +/* Approximation thresholds. */ +#define ASIN_LINEAR (BIAS - 32) /* 2**-32 */ +#define ACOS_CONST (BIAS - 65) /* 2**-65 */ +#define ATAN_CONST (BIAS + 65) /* 2**65 */ +#define ATAN_LINEAR (BIAS - 32) /* 2**-32 */ + +/* 0.95 */ +#define THRESH ((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT) + +/* Constants shared by the long double inverse trig functions. */ +#define pS0 _ItL_pS0 +#define pS1 _ItL_pS1 +#define pS2 _ItL_pS2 +#define pS3 _ItL_pS3 +#define pS4 _ItL_pS4 +#define pS5 _ItL_pS5 +#define pS6 _ItL_pS6 +#define qS1 _ItL_qS1 +#define qS2 _ItL_qS2 +#define qS3 _ItL_qS3 +#define qS4 _ItL_qS4 +#define qS5 _ItL_qS5 +#define atanhi _ItL_atanhi +#define atanlo _ItL_atanlo +#define aT _ItL_aT +#define pi_lo _ItL_pi_lo + +#define pio2_hi atanhi[3] +#define pio2_lo atanlo[3] +#define pio4_hi atanhi[1] + +#ifdef STRUCT_DECLS +typedef struct longdouble { + uint64_t mant; + uint16_t expsign; +} LONGDOUBLE; +#else +typedef long double LONGDOUBLE; +#endif + +extern const LONGDOUBLE pS0, pS1, pS2, pS3, pS4, pS5, pS6; +extern const LONGDOUBLE qS1, qS2, qS3, qS4, qS5; +extern const LONGDOUBLE atanhi[], atanlo[], aT[]; +extern const LONGDOUBLE pi_lo; + +#ifndef STRUCT_DECLS + +static inline long double +P(long double x) +{ + + return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \ + (pS4 + x * (pS5 + x * pS6))))))); +} + +static inline long double +Q(long double x) +{ + + return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * qS5))))); +} + +static inline long double +T_even(long double x) +{ + + return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \ + (aT[8] + x * (aT[10] + x * aT[12])))))); +} + +static inline long double +T_odd(long double x) +{ + + return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \ + (aT[9] + x * aT[11]))))); +} + +#endif diff --git a/ld80/k_cosl.c b/ld80/k_cosl.c new file mode 100644 index 0000000..10d7dff --- /dev/null +++ b/ld80/k_cosl.c @@ -0,0 +1,78 @@ +/* From: @(#)k_cos.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/k_cosl.c,v 1.1 2008/02/17 07:32:14 das Exp $"); + +/* + * ld80 version of k_cos.c. See ../src/k_cos.c for most comments. + */ + +#include "math_private.h" + +/* + * Domain [-0.7854, 0.7854], range ~[-2.43e-23, 2.425e-23]: + * |cos(x) - c(x)| < 2**-75.1 + * + * The coefficients of c(x) were generated by a pari-gp script using + * a Remez algorithm that searches for the best higher coefficients + * after rounding leading coefficients to a specified precision. + * + * Simpler methods like Chebyshev or basic Remez barely suffice for + * cos() in 64-bit precision, because we want the coefficient of x^2 + * to be precisely -0.5 so that multiplying by it is exact, and plain + * rounding of the coefficients of a good polynomial approximation only + * gives this up to about 64-bit precision. Plain rounding also gives + * a mediocre approximation for the coefficient of x^4, but a rounding + * error of 0.5 ulps for this coefficient would only contribute ~0.01 + * ulps to the final error, so this is unimportant. Rounding errors in + * higher coefficients are even less important. + * + * In fact, coefficients above the x^4 one only need to have 53-bit + * precision, and this is more efficient. We get this optimization + * almost for free from the complications needed to search for the best + * higher coefficients. + */ +static const double +one = 1.0; + +#if defined(__amd64__) || defined(__i386__) +/* Long double constants are slow on these arches, and broken on i386. */ +static const volatile double +C1hi = 0.041666666666666664, /* 0x15555555555555.0p-57 */ +C1lo = 2.2598839032744733e-18; /* 0x14d80000000000.0p-111 */ +#define C1 ((long double)C1hi + C1lo) +#else +static const long double +C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 */ +#endif + +static const double +C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */ +C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */ +C4 = -0.00000027557319215507120, /* -0x127e4fb7602f22.0p-74 */ +C5 = 0.0000000020876754400407278, /* 0x11eed8caaeccf1.0p-81 */ +C6 = -1.1470297442401303e-11, /* -0x19393412bd1529.0p-89 */ +C7 = 4.7383039476436467e-14; /* 0x1aac9d9af5c43e.0p-97 */ + +long double +__kernel_cosl(long double x, long double y) +{ + long double hz,z,r,w; + + z = x*x; + r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7)))))); + hz = 0.5*z; + w = one-hz; + return w + (((one-w)-hz) + (z*r-x*y)); +} diff --git a/ld80/k_sinl.c b/ld80/k_sinl.c new file mode 100644 index 0000000..ed49765 --- /dev/null +++ b/ld80/k_sinl.c @@ -0,0 +1,62 @@ +/* From: @(#)k_sin.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/k_sinl.c,v 1.1 2008/02/17 07:32:14 das Exp $"); + +/* + * ld80 version of k_sin.c. See ../src/k_sin.c for most comments. + */ + +#include "math_private.h" + +static const double +half = 0.5; + +/* + * Domain [-0.7854, 0.7854], range ~[-1.89e-22, 1.915e-22] + * |sin(x)/x - s(x)| < 2**-72.1 + * + * See ../ld80/k_cosl.c for more details about the polynomial. + */ +#if defined(__amd64__) || defined(__i386__) +/* Long double constants are slow on these arches, and broken on i386. */ +static const volatile double +S1hi = -0.16666666666666666, /* -0x15555555555555.0p-55 */ +S1lo = -9.2563760475949941e-18; /* -0x15580000000000.0p-109 */ +#define S1 ((long double)S1hi + S1lo) +#else +static const long double +S1 = -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 */ +#endif + +static const double +S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */ +S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */ +S4 = 0.0000027557319223597490, /* 0x171de3a55560f7.0p-71 */ +S5 = -0.000000025052108218074604, /* -0x1ae64564f16cad.0p-78 */ +S6 = 1.6059006598854211e-10, /* 0x161242b90243b5.0p-85 */ +S7 = -7.6429779983024564e-13, /* -0x1ae42ebd1b2e00.0p-93 */ +S8 = 2.6174587166648325e-15; /* 0x179372ea0b3f64.0p-101 */ + +long double +__kernel_sinl(long double x, long double y, int iy) +{ + long double z,r,v; + + z = x*x; + v = z*x; + r = S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8))))); + if(iy==0) return x+v*(S1+z*r); + else return x-((z*(half*y-v*r)-y)-v*S1); +} diff --git a/ld80/k_tanl.c b/ld80/k_tanl.c new file mode 100644 index 0000000..b4d0db9 --- /dev/null +++ b/ld80/k_tanl.c @@ -0,0 +1,124 @@ +/* From: @(#)k_tan.c 1.5 04/04/22 SMI */ + +/* + * ==================================================== + * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/k_tanl.c,v 1.3 2008/02/18 15:39:52 bde Exp $"); + +/* + * ld80 version of k_tan.c. See ../src/k_tan.c for most comments. + */ + +#include "math.h" +#include "math_private.h" + +/* + * Domain [-0.67434, 0.67434], range ~[-2.25e-22, 1.921e-22] + * |tan(x)/x - t(x)| < 2**-71.9 + * + * See k_cosl.c for more details about the polynomial. + */ +#if defined(__amd64__) || defined(__i386__) +/* Long double constants are slow on these arches, and broken on i386. */ +static const volatile double +T3hi = 0.33333333333333331, /* 0x15555555555555.0p-54 */ +T3lo = 1.8350121769317163e-17, /* 0x15280000000000.0p-108 */ +T5hi = 0.13333333333333336, /* 0x11111111111112.0p-55 */ +T5lo = 1.3051083651294260e-17, /* 0x1e180000000000.0p-109 */ +T7hi = 0.053968253968250494, /* 0x1ba1ba1ba1b827.0p-57 */ +T7lo = 3.1509625637859973e-18, /* 0x1d100000000000.0p-111 */ +pio4_hi = 0.78539816339744828, /* 0x1921fb54442d18.0p-53 */ +pio4_lo = 3.0628711372715500e-17, /* 0x11a80000000000.0p-107 */ +pio4lo_hi = -1.2541394031670831e-20, /* -0x1d9cceba3f91f2.0p-119 */ +pio4lo_lo = 6.1493048227390915e-37; /* 0x1a280000000000.0p-173 */ +#define T3 ((long double)T3hi + T3lo) +#define T5 ((long double)T5hi + T5lo) +#define T7 ((long double)T7hi + T7lo) +#define pio4 ((long double)pio4_hi + pio4_lo) +#define pio4lo ((long double)pio4lo_hi + pio4lo_lo) +#else +static const long double +T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 */ +T5 = 0.133333333333333372290L, /* 0x88888888888893c3.0p-66 */ +T7 = 0.0539682539682504975744L, /* 0xdd0dd0dd0dc13ba2.0p-68 */ +pio4 = 0.785398163397448309628L, /* 0xc90fdaa22168c235.0p-64 */ +pio4lo = -1.25413940316708300586e-20L; /* -0xece675d1fc8f8cbb.0p-130 */ +#endif + +static const double +T9 = 0.021869488536312216, /* 0x1664f4882cc1c2.0p-58 */ +T11 = 0.0088632355256619590, /* 0x1226e355c17612.0p-59 */ +T13 = 0.0035921281113786528, /* 0x1d6d3d185d7ff8.0p-61 */ +T15 = 0.0014558334756312418, /* 0x17da354aa3f96b.0p-62 */ +T17 = 0.00059003538700862256, /* 0x13559358685b83.0p-63 */ +T19 = 0.00023907843576635544, /* 0x1f56242026b5be.0p-65 */ +T21 = 0.000097154625656538905, /* 0x1977efc26806f4.0p-66 */ +T23 = 0.000038440165747303162, /* 0x14275a09b3ceac.0p-67 */ +T25 = 0.000018082171885432524, /* 0x12f5e563e5487e.0p-68 */ +T27 = 0.0000024196006108814377, /* 0x144c0d80cc6896.0p-71 */ +T29 = 0.0000078293456938132840, /* 0x106b59141a6cb3.0p-69 */ +T31 = -0.0000032609076735050182, /* -0x1b5abef3ba4b59.0p-71 */ +T33 = 0.0000023261313142559411; /* 0x13835436c0c87f.0p-71 */ + +long double +__kernel_tanl(long double x, long double y, int iy) { + long double z, r, v, w, s; + long double osign; + int i; + + iy = (iy == 1 ? -1 : 1); /* XXX recover original interface */ + osign = (x >= 0 ? 1.0 : -1.0); /* XXX slow, probably wrong for -0 */ + if (fabsl(x) >= 0.67434) { + if (x < 0) { + x = -x; + y = -y; + } + z = pio4 - x; + w = pio4lo - y; + x = z + w; + y = 0.0; + i = 1; + } else + i = 0; + z = x * x; + w = z * z; + r = T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + + w * (T25 + w * (T29 + w * T33)))))); + v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + + w * (T27 + w * T31)))))); + s = z * x; + r = y + z * (s * (r + v) + y); + r += T3 * s; + w = x + r; + if (i == 1) { + v = (long double) iy; + return osign * + (v - 2.0 * (x - (w * w / (w + v) - r))); + } + if (iy == 1) + return w; + else { + /* + * if allow error up to 2 ulp, simply return + * -1.0 / (x+r) here + */ + /* compute -1.0 / (x+r) accurately */ + long double a, t; + z = w; + z = z + 0x1p32 - 0x1p32; + v = r - (z - x); /* z+v = r+x */ + t = a = -1.0 / w; /* a = -1.0/w */ + t = t + 0x1p32 - 0x1p32; + s = 1.0 + t * z; + return t + a * (s + t * v); + } +} diff --git a/ld80/s_exp2l.c b/ld80/s_exp2l.c new file mode 100644 index 0000000..54631dc --- /dev/null +++ b/ld80/s_exp2l.c @@ -0,0 +1,294 @@ +/*- + * Copyright (c) 2005-2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/ld80/s_exp2l.c,v 1.3 2008/02/13 10:44:44 bde Exp $"); + +#include +#include + +#ifdef __i386__ +#include +#endif + +#include "fpmath.h" +#include "math.h" + +#define TBLBITS 7 +#define TBLSIZE (1 << TBLBITS) + +#define BIAS (LDBL_MAX_EXP - 1) +#define EXPMASK (BIAS + LDBL_MAX_EXP) + +static const long double huge = 0x1p10000L; +#if 0 /* XXX Prevent gcc from erroneously constant folding this. */ +static const long double twom10000 = 0x1p-10000L; +#else +static volatile long double twom10000 = 0x1p-10000L; +#endif + +static const double + redux = 0x1.8p63 / TBLSIZE, + P1 = 0x1.62e42fefa39efp-1, + P2 = 0x1.ebfbdff82c58fp-3, + P3 = 0x1.c6b08d7049fap-5, + P4 = 0x1.3b2ab6fba4da5p-7, + P5 = 0x1.5d8804780a736p-10, + P6 = 0x1.430918835e33dp-13; + +static const double tbl[TBLSIZE * 2] = { + 0x1.6a09e667f3bcdp-1, -0x1.bdd3413b2648p-55, + 0x1.6c012750bdabfp-1, -0x1.2895667ff0cp-57, + 0x1.6dfb23c651a2fp-1, -0x1.bbe3a683c88p-58, + 0x1.6ff7df9519484p-1, -0x1.83c0f25860fp-56, + 0x1.71f75e8ec5f74p-1, -0x1.16e4786887bp-56, + 0x1.73f9a48a58174p-1, -0x1.0a8d96c65d5p-55, + 0x1.75feb564267c9p-1, -0x1.0245957316ep-55, + 0x1.780694fde5d3fp-1, 0x1.866b80a0216p-55, + 0x1.7a11473eb0187p-1, -0x1.41577ee0499p-56, + 0x1.7c1ed0130c132p-1, 0x1.f124cd1164ep-55, + 0x1.7e2f336cf4e62p-1, 0x1.05d02ba157ap-57, + 0x1.80427543e1a12p-1, -0x1.27c86626d97p-55, + 0x1.82589994cce13p-1, -0x1.d4c1dd41533p-55, + 0x1.8471a4623c7adp-1, -0x1.8d684a341cep-56, + 0x1.868d99b4492edp-1, -0x1.fc6f89bd4f68p-55, + 0x1.88ac7d98a6699p-1, 0x1.994c2f37cb5p-55, + 0x1.8ace5422aa0dbp-1, 0x1.6e9f156864bp-55, + 0x1.8cf3216b5448cp-1, -0x1.0d55e32e9e4p-57, + 0x1.8f1ae99157736p-1, 0x1.5cc13a2e397p-56, + 0x1.9145b0b91ffc6p-1, -0x1.dd6792e5825p-55, + 0x1.93737b0cdc5e5p-1, -0x1.75fc781b58p-58, + 0x1.95a44cbc8520fp-1, -0x1.64b7c96a5fp-57, + 0x1.97d829fde4e5p-1, -0x1.d185b7c1b86p-55, + 0x1.9a0f170ca07bap-1, -0x1.173bd91cee6p-55, + 0x1.9c49182a3f09p-1, 0x1.c7c46b071f2p-57, + 0x1.9e86319e32323p-1, 0x1.824ca78e64cp-57, + 0x1.a0c667b5de565p-1, -0x1.359495d1cd5p-55, + 0x1.a309bec4a2d33p-1, 0x1.6305c7ddc368p-55, + 0x1.a5503b23e255dp-1, -0x1.d2f6edb8d42p-55, + 0x1.a799e1330b358p-1, 0x1.bcb7ecac564p-55, + 0x1.a9e6b5579fdbfp-1, 0x1.0fac90ef7fdp-55, + 0x1.ac36bbfd3f37ap-1, -0x1.f9234cae76dp-56, + 0x1.ae89f995ad3adp-1, 0x1.7a1cd345dcc8p-55, + 0x1.b0e07298db666p-1, -0x1.bdef54c80e4p-55, + 0x1.b33a2b84f15fbp-1, -0x1.2805e3084d8p-58, + 0x1.b59728de5593ap-1, -0x1.c71dfbbba6ep-55, + 0x1.b7f76f2fb5e47p-1, -0x1.5584f7e54acp-57, + 0x1.ba5b030a1064ap-1, -0x1.efcd30e5429p-55, + 0x1.bcc1e904bc1d2p-1, 0x1.23dd07a2d9fp-56, + 0x1.bf2c25bd71e09p-1, -0x1.efdca3f6b9c8p-55, + 0x1.c199bdd85529cp-1, 0x1.11065895049p-56, + 0x1.c40ab5fffd07ap-1, 0x1.b4537e083c6p-55, + 0x1.c67f12e57d14bp-1, 0x1.2884dff483c8p-55, + 0x1.c8f6d9406e7b5p-1, 0x1.1acbc48805cp-57, + 0x1.cb720dcef9069p-1, 0x1.503cbd1e94ap-57, + 0x1.cdf0b555dc3fap-1, -0x1.dd83b53829dp-56, + 0x1.d072d4a07897cp-1, -0x1.cbc3743797a8p-55, + 0x1.d2f87080d89f2p-1, -0x1.d487b719d858p-55, + 0x1.d5818dcfba487p-1, 0x1.2ed02d75b37p-56, + 0x1.d80e316c98398p-1, -0x1.11ec18bedep-55, + 0x1.da9e603db3285p-1, 0x1.c2300696db5p-55, + 0x1.dd321f301b46p-1, 0x1.2da5778f019p-55, + 0x1.dfc97337b9b5fp-1, -0x1.1a5cd4f184b8p-55, + 0x1.e264614f5a129p-1, -0x1.7b627817a148p-55, + 0x1.e502ee78b3ff6p-1, 0x1.39e8980a9cdp-56, + 0x1.e7a51fbc74c83p-1, 0x1.2d522ca0c8ep-55, + 0x1.ea4afa2a490dap-1, -0x1.e9c23179c288p-55, + 0x1.ecf482d8e67f1p-1, -0x1.c93f3b411ad8p-55, + 0x1.efa1bee615a27p-1, 0x1.dc7f486a4b68p-55, + 0x1.f252b376bba97p-1, 0x1.3a1a5bf0d8e8p-55, + 0x1.f50765b6e454p-1, 0x1.9d3e12dd8a18p-55, + 0x1.f7bfdad9cbe14p-1, -0x1.dbb12d00635p-55, + 0x1.fa7c1819e90d8p-1, 0x1.74853f3a593p-56, + 0x1.fd3c22b8f71f1p-1, 0x1.2eb74966578p-58, + 0x1p+0, 0x0p+0, + 0x1.0163da9fb3335p+0, 0x1.b61299ab8cd8p-54, + 0x1.02c9a3e778061p+0, -0x1.19083535b08p-56, + 0x1.04315e86e7f85p+0, -0x1.0a31c1977c98p-54, + 0x1.059b0d3158574p+0, 0x1.d73e2a475b4p-55, + 0x1.0706b29ddf6dep+0, -0x1.c91dfe2b13cp-55, + 0x1.0874518759bc8p+0, 0x1.186be4bb284p-57, + 0x1.09e3ecac6f383p+0, 0x1.14878183161p-54, + 0x1.0b5586cf9890fp+0, 0x1.8a62e4adc61p-54, + 0x1.0cc922b7247f7p+0, 0x1.01edc16e24f8p-54, + 0x1.0e3ec32d3d1a2p+0, 0x1.03a1727c58p-59, + 0x1.0fb66affed31bp+0, -0x1.b9bedc44ebcp-57, + 0x1.11301d0125b51p+0, -0x1.6c51039449bp-54, + 0x1.12abdc06c31ccp+0, -0x1.1b514b36ca8p-58, + 0x1.1429aaea92dep+0, -0x1.32fbf9af1368p-54, + 0x1.15a98c8a58e51p+0, 0x1.2406ab9eeabp-55, + 0x1.172b83c7d517bp+0, -0x1.19041b9d78ap-55, + 0x1.18af9388c8deap+0, -0x1.11023d1970f8p-54, + 0x1.1a35beb6fcb75p+0, 0x1.e5b4c7b4969p-55, + 0x1.1bbe084045cd4p+0, -0x1.95386352ef6p-54, + 0x1.1d4873168b9aap+0, 0x1.e016e00a264p-54, + 0x1.1ed5022fcd91dp+0, -0x1.1df98027bb78p-54, + 0x1.2063b88628cd6p+0, 0x1.dc775814a85p-55, + 0x1.21f49917ddc96p+0, 0x1.2a97e9494a6p-55, + 0x1.2387a6e756238p+0, 0x1.9b07eb6c7058p-54, + 0x1.251ce4fb2a63fp+0, 0x1.ac155bef4f5p-55, + 0x1.26b4565e27cddp+0, 0x1.2bd339940eap-55, + 0x1.284dfe1f56381p+0, -0x1.a4c3a8c3f0d8p-54, + 0x1.29e9df51fdee1p+0, 0x1.612e8afad12p-55, + 0x1.2b87fd0dad99p+0, -0x1.10adcd6382p-59, + 0x1.2d285a6e4030bp+0, 0x1.0024754db42p-54, + 0x1.2ecafa93e2f56p+0, 0x1.1ca0f45d524p-56, + 0x1.306fe0a31b715p+0, 0x1.6f46ad23183p-55, + 0x1.32170fc4cd831p+0, 0x1.a9ce78e1804p-55, + 0x1.33c08b26416ffp+0, 0x1.327218436598p-54, + 0x1.356c55f929ff1p+0, -0x1.b5cee5c4e46p-55, + 0x1.371a7373aa9cbp+0, -0x1.63aeabf42ebp-54, + 0x1.38cae6d05d866p+0, -0x1.e958d3c99048p-54, + 0x1.3a7db34e59ff7p+0, -0x1.5e436d661f6p-56, + 0x1.3c32dc313a8e5p+0, -0x1.efff8375d2ap-54, + 0x1.3dea64c123422p+0, 0x1.ada0911f09fp-55, + 0x1.3fa4504ac801cp+0, -0x1.7d023f956fap-54, + 0x1.4160a21f72e2ap+0, -0x1.ef3691c309p-58, + 0x1.431f5d950a897p+0, -0x1.1c7dde35f7ap-55, + 0x1.44e086061892dp+0, 0x1.89b7a04ef8p-59, + 0x1.46a41ed1d0057p+0, 0x1.c944bd1648a8p-54, + 0x1.486a2b5c13cdp+0, 0x1.3c1a3b69062p-56, + 0x1.4a32af0d7d3dep+0, 0x1.9cb62f3d1be8p-54, + 0x1.4bfdad5362a27p+0, 0x1.d4397afec42p-56, + 0x1.4dcb299fddd0dp+0, 0x1.8ecdbbc6a78p-54, + 0x1.4f9b2769d2ca7p+0, -0x1.4b309d25958p-54, + 0x1.516daa2cf6642p+0, -0x1.f768569bd94p-55, + 0x1.5342b569d4f82p+0, -0x1.07abe1db13dp-55, + 0x1.551a4ca5d920fp+0, -0x1.d689cefede6p-55, + 0x1.56f4736b527dap+0, 0x1.9bb2c011d938p-54, + 0x1.58d12d497c7fdp+0, 0x1.295e15b9a1ep-55, + 0x1.5ab07dd485429p+0, 0x1.6324c0546478p-54, + 0x1.5c9268a5946b7p+0, 0x1.c4b1b81698p-60, + 0x1.5e76f15ad2148p+0, 0x1.ba6f93080e68p-54, + 0x1.605e1b976dc09p+0, -0x1.3e2429b56de8p-54, + 0x1.6247eb03a5585p+0, -0x1.383c17e40b48p-54, + 0x1.6434634ccc32p+0, -0x1.c483c759d89p-55, + 0x1.6623882552225p+0, -0x1.bb60987591cp-54, + 0x1.68155d44ca973p+0, 0x1.038ae44f74p-57, +}; + +/* + * exp2l(x): compute the base 2 exponential of x + * + * Accuracy: Peak error < 0.511 ulp. + * + * Method: (equally-spaced tables) + * + * Reduce x: + * x = 2**k + y, for integer k and |y| <= 1/2. + * Thus we have exp2l(x) = 2**k * exp2(y). + * + * Reduce y: + * y = i/TBLSIZE + z for integer i near y * TBLSIZE. + * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z), + * with |z| <= 2**-(TBLBITS+1). + * + * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a + * degree-6 minimax polynomial with maximum error under 2**-69. + * The table entries each have 104 bits of accuracy, encoded as + * a pair of double precision values. + */ +long double +exp2l(long double x) +{ + union IEEEl2bits u, v; + long double r, twopk, twopkp10000, z; + uint32_t hx, ix, i0; + int k; + + /* Filter out exceptional cases. */ + u.e = x; + hx = u.xbits.expsign; + ix = hx & EXPMASK; + if (ix >= BIAS + 14) { /* |x| >= 16384 or x is NaN */ + if (ix == BIAS + LDBL_MAX_EXP) { + if (u.xbits.man != 1ULL << 63 || (hx & 0x8000) == 0) + return (x + x); /* x is +Inf or NaN */ + else + return (0.0); /* x is -Inf */ + } + if (x >= 16384) + return (huge * huge); /* overflow */ + if (x <= -16446) + return (twom10000 * twom10000); /* underflow */ + } else if (ix <= BIAS - 66) { /* |x| < 0x1p-66 */ + return (1.0 + x); + } + +#ifdef __i386__ + /* + * The default precision on i386 is 53 bits, so long doubles are + * broken. Call exp2() to get an accurate (double precision) result. + */ + if (fpgetprec() != FP_PE) + return (exp2(x)); +#endif + + /* + * Reduce x, computing z, i0, and k. The low bits of x + redux + * contain the 16-bit integer part of the exponent (k) followed by + * TBLBITS fractional bits (i0). We use bit tricks to extract these + * as integers, then set z to the remainder. + * + * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8. + * Then the low-order word of x + redux is 0x000abc12, + * We split this into k = 0xabc and i0 = 0x12 (adjusted to + * index into the table), then we compute z = 0x0.003456p0. + * + * XXX If the exponent is negative, the computation of k depends on + * '>>' doing sign extension. + */ + u.e = x + redux; + i0 = u.bits.manl + TBLSIZE / 2; + k = (int)i0 >> TBLBITS; + i0 = (i0 & (TBLSIZE - 1)) << 1; + u.e -= redux; + z = x - u.e; + v.xbits.man = 1ULL << 63; + if (k >= LDBL_MIN_EXP) { + v.xbits.expsign = LDBL_MAX_EXP - 1 + k; + twopk = v.e; + } else { + v.xbits.expsign = LDBL_MAX_EXP - 1 + k + 10000; + twopkp10000 = v.e; + } + + /* Compute r = exp2l(y) = exp2lt[i0] * p(z). */ + long double t_hi = tbl[i0]; + long double t_lo = tbl[i0 + 1]; + /* XXX This gives > 1 ulp errors outside of FE_TONEAREST mode */ + r = t_lo + (t_hi + t_lo) * z * (P1 + z * (P2 + z * (P3 + z * (P4 + + z * (P5 + z * P6))))) + t_hi; + + /* Scale by 2**k. */ + if (k >= LDBL_MIN_EXP) { + if (k == LDBL_MAX_EXP) + return (r * 2.0 * 0x1p16383L); + return (r * twopk); + } else { + return (r * twopkp10000 * twom10000); + } +} diff --git a/ld80/s_nanl.c b/ld80/s_nanl.c new file mode 100644 index 0000000..0fa7672 --- /dev/null +++ b/ld80/s_nanl.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2007 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/ld80/s_nanl.c,v 1.2 2007/12/18 23:46:31 das Exp $ + */ + +#include + +#include "fpmath.h" +#include "../src/math_private.h" + +long double +nanl(const char *s) +{ + union { + union IEEEl2bits ieee; + uint32_t bits[3]; + } u; + + _scan_nan(u.bits, 3, s); + u.ieee.bits.exp = 0x7fff; + u.ieee.bits.manh |= 0xc0000000; /* make it a quiet NaN */ + return (u.ieee.e); +} diff --git a/man/acos.3 b/man/acos.3 new file mode 100644 index 0000000..8533773 --- /dev/null +++ b/man/acos.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)acos.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/acos.3,v 1.15 2008/07/31 22:41:26 das Exp $ +.\" +.Dd July 31, 2008 +.Dt ACOS 3 +.Os +.Sh NAME +.Nm acos , +.Nm acosf , +.Nm acosl +.Nd arc cosine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn acos "double x" +.Ft float +.Fn acosf "float x" +.Ft long double +.Fn acosl "long double x" +.Sh DESCRIPTION +The +.Fn acos , +.Fn acosf , +and +.Fn acosl +functions compute the principal value of the arc cosine of +.Fa x . +.Sh RETURN VALUES +These functions return the arc cosine in the range +.Bq 0 , \*(Pi +radians. +If: +.Bd -unfilled -offset indent +.Pf \&| Ns Ar x Ns \&| > 1 , +.Ed +.Pp +.Fn acos x +raises an invalid exception and returns an \*(Na. +.Sh SEE ALSO +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr fenv 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn acos , +.Fn acosf , +and +.Fn acosl +functions conform to +.St -isoC-99 . diff --git a/man/acosh.3 b/man/acosh.3 new file mode 100644 index 0000000..9a77eba --- /dev/null +++ b/man/acosh.3 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)acosh.3 5.2 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/acosh.3,v 1.12 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd January 14, 2005 +.Dt ACOSH 3 +.Os +.Sh NAME +.Nm acosh , +.Nm acoshf +.Nd inverse hyperbolic cosine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn acosh "double x" +.Ft float +.Fn acoshf "float x" +.Sh DESCRIPTION +The +.Fn acosh +and the +.Fn acoshf +functions compute the inverse hyperbolic cosine +of the real +argument +.Ar x . +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn acosh +and the +.Fn acoshf +functions +return the inverse hyperbolic cosine of +.Ar x . +If the argument is less than 1, +.Fn acosh +raises an invalid exception and returns an \*(Na. +.Sh SEE ALSO +.Xr asinh 3 , +.Xr atanh 3 , +.Xr exp 3 , +.Xr fenv 3 , +.Xr math 3 +.Sh HISTORY +The +.Fn acosh +function appeared in +.Bx 4.3 . diff --git a/man/asin.3 b/man/asin.3 new file mode 100644 index 0000000..6518097 --- /dev/null +++ b/man/asin.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)asin.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/asin.3,v 1.17 2008/07/31 22:41:26 das Exp $ +.\" +.Dd July 31, 2008 +.Dt ASIN 3 +.Os +.Sh NAME +.Nm asin , +.Nm asinf , +.Nm asinl +.Nd arc sine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn asin "double x" +.Ft float +.Fn asinf "float x" +.Ft long double +.Fn asinl "long double x" +.Sh DESCRIPTION +The +.Fn asin , +.Fn asinf , +and +.Fn asinl +functions compute the principal value of the arc sine of +.Fa x . +.Sh RETURN VALUES +These functions return the arc sine in the range +.Bk -words +.Bq -\*(Pi/2 , +\*(Pi/2 +.Ek +radians. +If: +.Bd -unfilled -offset indent +.Pf \&| Ns Ar x Ns \&| > 1 +.Ed +.Pp +.Fn asin x +raises an invalid exception and returns an \*(Na. +.Sh SEE ALSO +.Xr acos 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr fenv 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn asin , +.Fn asinf , +and +.Fn asinl +functions conform to +.St -isoC-99 . diff --git a/man/asinh.3 b/man/asinh.3 new file mode 100644 index 0000000..463a468 --- /dev/null +++ b/man/asinh.3 @@ -0,0 +1,74 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)asinh.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/asinh.3,v 1.11 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd May 6, 1991 +.Dt ASINH 3 +.Os +.Sh NAME +.Nm asinh , +.Nm asinhf +.Nd inverse hyperbolic sine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn asinh "double x" +.Ft float +.Fn asinhf "float x" +.Sh DESCRIPTION +The +.Fn asinh +and the +.Fn asinhf +functions compute the inverse hyperbolic sine +of the real +argument +.Ar x . +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn asinh +and the +.Fn asinhf +functions +return the inverse hyperbolic sine of +.Ar x . +.Sh SEE ALSO +.Xr acosh 3 , +.Xr atanh 3 , +.Xr exp 3 , +.Xr math 3 +.Sh HISTORY +The +.Fn asinh +function appeared in +.Bx 4.3 . diff --git a/man/atan.3 b/man/atan.3 new file mode 100644 index 0000000..33e3b9a --- /dev/null +++ b/man/atan.3 @@ -0,0 +1,81 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)atan.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/atan.3,v 1.12 2008/07/31 22:41:26 das Exp $ +.\" +.Dd July 31, 2008 +.Dt ATAN 3 +.Os +.Sh NAME +.Nm atan , +.Nm atanf , +.Nm atanl +.Nd arc tangent functions of one variable +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn atan "double x" +.Ft float +.Fn atanf "float x" +.Ft long double +.Fn atanl "long double x" +.Sh DESCRIPTION +The +.Fn atan , +.Fn atanf , +and +.Fn atanl +functions compute the principal value of the arc tangent of +.Fa x . +.Sh RETURN VALUES +These functions return the arc tangent in the range +.Bk -words +.Bq -\*(Pi/2 , +\*(Pi/2 +.Ek +radians. +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn atan , +.Fn atanf , +and +.Fn atanl +functions conform to +.St -isoC-99 . diff --git a/man/atan2.3 b/man/atan2.3 new file mode 100644 index 0000000..4f9c32e --- /dev/null +++ b/man/atan2.3 @@ -0,0 +1,225 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/atan2.3,v 1.20 2010/06/09 07:31:32 uqs Exp $ +.\" +.Dd July 31, 2008 +.Dt ATAN2 3 +.Os +.Sh NAME +.Nm atan2 , +.Nm atan2f , +.Nm atan2l , +.Nm carg , +.Nm cargf , +.Nm cargl +.Nd arc tangent and complex phase angle functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn atan2 "double y" "double x" +.Ft float +.Fn atan2f "float y" "float x" +.Ft long double +.Fn atan2l "long double y" "long double x" +.In complex.h +.Ft double +.Fn carg "double complex z" +.Ft float +.Fn cargf "float complex z" +.Ft long double +.Fn cargl "long double complex z" +.Sh DESCRIPTION +The +.Fn atan2 , +.Fn atan2f , +and +.Fn atan2l +functions compute the principal value of the arc tangent of +.Fa y/ Ns Ar x , +using the signs of both arguments to determine the quadrant of +the return value. +.Pp +The +.Fn carg , +.Fn cargf , +and +.Fn cargl +functions compute the complex argument (or phase angle) of +.Fa z . +The complex argument is the number theta such that +.Li z = r * e^(I * theta) , +where +.Li r = cabs(z) . +The call +.Li carg(z) +is equivalent to +.Li atan2(cimag(z), creal(z)) , +and similarly for +.Fn cargf +and +.Fn cargl . +.Sh RETURN VALUES +The +.Fn atan2 , +.Fn atan2f , +and +.Fn atan2l +functions, if successful, +return the arc tangent of +.Fa y/ Ns Ar x +in the range +.Bk -words +.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi +.Ek +radians. +Here are some of the special cases: +.Bl -column atan_(y,x)_:=____ sign(y)_(Pi_atan2(Xy_xX))___ +.It Fn atan2 y x No := Ta +.Fn atan y/x Ta +if +.Ar x +> 0, +.It Ta sign( Ns Ar y Ns )*(\*(Pi - +.Fn atan "\*(Bay/x\*(Ba" ) Ta +if +.Ar x +< 0, +.It Ta +.No 0 Ta +if x = y = 0, or +.It Ta +.Pf sign( Ar y Ns )*\*(Pi/2 Ta +if +.Ar x += 0 \(!= +.Ar y . +.El +.Sh NOTES +The function +.Fn atan2 +defines "if x > 0," +.Fn atan2 0 0 += 0 despite that previously +.Fn atan2 0 0 +may have generated an error message. +The reasons for assigning a value to +.Fn atan2 0 0 +are these: +.Bl -enum -offset indent +.It +Programs that test arguments to avoid computing +.Fn atan2 0 0 +must be indifferent to its value. +Programs that require it to be invalid are vulnerable +to diverse reactions to that invalidity on diverse computer systems. +.It +The +.Fn atan2 +function is used mostly to convert from rectangular (x,y) +to polar +.if n\ +(r,theta) +.if t\ +(r,\(*h) +coordinates that must satisfy x = +.if n\ +r\(**cos theta +.if t\ +r\(**cos\(*h +and y = +.if n\ +r\(**sin theta. +.if t\ +r\(**sin\(*h. +These equations are satisfied when (x=0,y=0) +is mapped to +.if n \ +(r=0,theta=0). +.if t \ +(r=0,\(*h=0). +In general, conversions to polar coordinates +should be computed thus: +.Bd -unfilled -offset indent +.if n \{\ +r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) +theta := atan2(y,x). +.\} +.if t \{\ +r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) +\(*h := atan2(y,x). +.\} +.Ed +.It +The foregoing formulas need not be altered to cope in a +reasonable way with signed zeros and infinities +on a machine that conforms to +.Tn IEEE 754 ; +the versions of +.Xr hypot 3 +and +.Fn atan2 +provided for +such a machine are designed to handle all cases. +That is why +.Fn atan2 \(+-0 \-0 += \(+-\*(Pi +for instance. +In general the formulas above are equivalent to these: +.Bd -unfilled -offset indent +.if n \ +r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); +.if t \ +r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); +.Ed +.El +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr cabs 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn atan2 , +.Fn atan2f , +.Fn atan2l , +.Fn carg , +.Fn cargf , +and +.Fn cargl +functions conform to +.St -isoC-99 . diff --git a/man/atanh.3 b/man/atanh.3 new file mode 100644 index 0000000..d739407 --- /dev/null +++ b/man/atanh.3 @@ -0,0 +1,81 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)atanh.3 5.2 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/atanh.3,v 1.14 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd January 14, 2005 +.Dt ATANH 3 +.Os +.Sh NAME +.Nm atanh , +.Nm atanhf +.Nd inverse hyperbolic tangent functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn atanh "double x" +.Ft float +.Fn atanhf "float x" +.Sh DESCRIPTION +The +.Fn atanh +and the +.Fn atanhf +functions compute the inverse hyperbolic tangent +of the real +argument +.Ar x . +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn atanh +and the +.Fn atanhf +functions +return the inverse hyperbolic tangent of +.Ar x +if successful. +If the argument has absolute value 1, a divide-by-zero exception +is raised and an infinity is returned. +If +.Ar |x| +> 1, an invalid exception is raised and an \*(Na is returned. +.Sh SEE ALSO +.Xr acosh 3 , +.Xr asinh 3 , +.Xr exp 3 , +.Xr fenv 3 , +.Xr math 3 +.Sh HISTORY +The +.Fn atanh +function appeared in +.Bx 4.3 . diff --git a/man/ccos.3 b/man/ccos.3 new file mode 100644 index 0000000..016e429 --- /dev/null +++ b/man/ccos.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 2011 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/ccos.3,v 1.1 2011/10/17 05:41:03 das Exp $ +.\" +.Dd October 17, 2011 +.Dt CCOS 3 +.Os +.Sh NAME +.Nm ccos , +.Nm ccosf , +.Nm csin , +.Nm csinf +.Nm ctan , +.Nm ctanf +.Nd complex trigonometric functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn ccos "double complex z" +.Ft float complex +.Fn ccosf "float complex z" +.Ft double complex +.Fn csin "double complex z" +.Ft float complex +.Fn csinf "float complex z" +.Ft double complex +.Fn ctan "double complex z" +.Ft float complex +.Fn ctanf "float complex z" +.Sh DESCRIPTION +The +.Fn ccos , +.Fn csin , +and +.Fn ctan +functions compute the cosine, sine, and tangent of the complex number +.Fa z , +respectively. +The +.Fn ccosf , +.Fn csinf , +and +.Fn ctanf +functions perform the same operations in +.Fa float +precision. +.Sh SEE ALSO +.Xr ccosh 3 , +.Xr complex 3 , +.Xr cos 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr tan 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/ccosh.3 b/man/ccosh.3 new file mode 100644 index 0000000..3582650 --- /dev/null +++ b/man/ccosh.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 2011 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/ccosh.3,v 1.1 2011/10/17 05:41:03 das Exp $ +.\" +.Dd October 17, 2011 +.Dt CCOSH 3 +.Os +.Sh NAME +.Nm ccosh , +.Nm ccoshf , +.Nm csinh , +.Nm csinhf +.Nm ctanh , +.Nm ctanhf +.Nd complex hyperbolic functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn ccosh "double complex z" +.Ft float complex +.Fn ccoshf "float complex z" +.Ft double complex +.Fn csinh "double complex z" +.Ft float complex +.Fn csinhf "float complex z" +.Ft double complex +.Fn ctanh "double complex z" +.Ft float complex +.Fn ctanhf "float complex z" +.Sh DESCRIPTION +The +.Fn ccosh , +.Fn csinh , +and +.Fn ctanh +functions compute the hyperbolic cosine, sine, and tangent of the complex number +.Fa z , +respectively. +The +.Fn ccoshf , +.Fn csinhf , +and +.Fn ctanhf +functions perform the same operations in +.Fa float +precision. +.Sh SEE ALSO +.Xr ccos 3 , +.Xr complex 3 , +.Xr cosh 3 , +.Xr math 3 , +.Xr sinh 3 , +.Xr tanh 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/ceil.3 b/man/ceil.3 new file mode 100644 index 0000000..49134f1 --- /dev/null +++ b/man/ceil.3 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ceil.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/ceil.3,v 1.16 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd January 13, 2005 +.Dt CEIL 3 +.Os +.Sh NAME +.Nm ceil , +.Nm ceilf , +.Nm ceill +.Nd smallest integral value greater than or equal to x +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn ceil "double x" +.Ft float +.Fn ceilf "float x" +.Ft "long double" +.Fn ceill "long double x" +.Sh DESCRIPTION +The +.Fn ceil , +.Fn ceilf +and +.Fn ceill +functions return the smallest integral value +greater than or equal to +.Fa x , +expressed as a floating-point number. +.Sh SEE ALSO +.Xr abs 3 , +.Xr fabs 3 , +.Xr floor 3 , +.Xr ieee 3 , +.Xr math 3 , +.Xr rint 3 , +.Xr round 3 , +.Xr trunc 3 +.Sh STANDARDS +The +.Fn ceil +function conforms to +.St -isoC . +The +.Fn ceilf +and +.Fn ceill +functions conform to +.St -isoC-99 . diff --git a/man/cexp.3 b/man/cexp.3 new file mode 100644 index 0000000..e652814 --- /dev/null +++ b/man/cexp.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 2011 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/cexp.3,v 1.1 2011/03/07 03:09:24 das Exp $ +.\" +.Dd March 6, 2011 +.Dt CEXP 3 +.Os +.Sh NAME +.Nm cexp , +.Nm cexpf +.Nd complex exponential functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn cexp "double complex z" +.Ft float complex +.Fn cexpf "float complex z" +.Sh DESCRIPTION +The +.Fn cexp +and +.Fn cexpf +functions compute the complex exponential of +.Fa z , +also known as +.Em cis Ns ( Ns +.Fa z Ns ) +.Sh RETURN VALUES +For real numbers +.Fa x +and +.Fa y , +.Fn cexp +behaves according to Euler's formula: +.Bd -ragged -offset indent +.Fn cexp "x + I*y" += +.Ns ( Sy e Ns ** Ns +.Fa x * +.Em cos Ns ( Ns +.Fa y Ns )) + ( Ns +.Sy I +* +.Sy e Ns ** Ns +.Fa x +* +.Em sin Ns ( Ns +.Fa y Ns )) +.Ed +.Pp +Generally speaking, infinities, zeroes and \*(Nas are handled as would +be expected from this identity given the usual rules of floating-point +arithmetic. +However, care is taken to avoid generating \*(Nas when they are not deserved. +For example, mathematically we expect that +.Fo cimag +.Fn cexp "x + I*0" Fc += 0 regardless of the value of +.Fa x , +and +.Fn cexp +preserves this identity even if +.Fa x +is \*(If or \*(Na. +Likewise, +.Fn cexp "-\*(If + I*y" += 0 and +.Fo creal +.Fn cexp "\*(If + I*y" Fc += \*(If +for any +.Fa y +(even though the latter property is only mathematically true for +representable +.Fa y . ) +If +.Fa y +is not finite, the sign of the result is indeterminate. +.Sh SEE ALSO +.Xr complex 3 , +.Xr exp 3 , +.Xr math 3 , +.Sh STANDARDS +The +.Fn cexp +and +.Fn cexpf +functions conform to +.St -isoC-99 . diff --git a/man/cimag.3 b/man/cimag.3 new file mode 100644 index 0000000..daab9dd --- /dev/null +++ b/man/cimag.3 @@ -0,0 +1,121 @@ +.\" Copyright (c) 2004 Stefan Farfeleder +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/cimag.3,v 1.4 2010/03/12 10:01:06 uqs Exp $ +.\" +.Dd August 7, 2008 +.Dt CIMAG 3 +.Os +.Sh NAME +.Nm cimag , cimagf , cimagl , +.Nm conj , conjf , conjl , +.Nm cproj , cprojf , cprojl , +.Nm creal , crealf , creall +.Nd "functions to manipulate complex numbers" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double +.Fn cimag "double complex z" +.Ft float +.Fn cimagf "float complex z" +.Ft "long double" +.Fn cimagl "long double complex z" +.Ft "double complex" +.Fn conj "double complex z" +.Ft "float complex" +.Fn conjf "float complex z" +.Ft "long double complex" +.Fn conjl "long double complex z" +.Ft "double complex" +.Fn cproj "double complex z" +.Ft "float complex" +.Fn cprojf "float complex z" +.Ft "long double complex" +.Fn cprojl "long double complex z" +.Ft double +.Fn creal "double complex z" +.Ft float +.Fn crealf "float complex z" +.Ft "long double" +.Fn creall "long double complex z" +.Sh DESCRIPTION +Let +.Sm off +.Fa a + b * Em i +.Sm on +denote the complex number +.Fa z . +.Pp +The +.Fn creal +functions return the real part +.Fa a , +and the +.Fn cimag +functions return the imaginary part +.Fa b . +.Pp +The +.Fn conj +functions return the complex conjugate +.Sm off +.Fa a - b * Em i . +.Sm on +.Pp +The +.Fn cproj +functions return the projection onto the Riemann sphere. +If +.Fa z +contains an infinite component, then the result is +.Fa \*(If \*(Pm 0 Ns * Ns Em i , +where the (zero) imaginary part of the result has the same sign as +.Fa b . +Otherwise, the result is +.Fa z . +.Pp +These functions do not signal any floating point exceptions. +.Sh STANDARDS +The +.Fn cimag , +.Fn conj , +.Fn cproj , +and +.Fn creal +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn cimag , +.Fn conj +and +.Fn creal +functions first appeared in +.Fx 5.3 . +The +.Fn cproj +functions appeared in +.Fx 8.0 . diff --git a/man/complex.3 b/man/complex.3 new file mode 100644 index 0000000..0c946c3 --- /dev/null +++ b/man/complex.3 @@ -0,0 +1,130 @@ +.\" Copyright (c) 2011 Murray Stokely +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/complex.3,v 1.3 2011/10/17 05:41:03 das Exp $ +.\" +.Dd October 17, 2011 +.Dt COMPLEX 3 +.Os +.Sh NAME +.Nm complex +.Nd "complex arithmetic" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Sh DESCRIPTION +These functions support complex arithmetic in the C math library. +.Sh "LIST OF FUNCTIONS" +Each of the following +.Vt "double complex" +functions has a +.Vt "float complex" +counterpart with an +.Ql f +appended to the name and a +.Vt "long double complex" +counterpart with an +.Ql l +appended. +As an example, the +.Vt "float complex" +and +.Vt "long double complex" +counterparts of +.Ft double +.Fn cabs "double complex z" +are +.Ft float +.Fn cabsf "float complex z" +and +.Ft "long double" +.Fn cabsl "long double complex z" , +respectively. +.de Cl +.Bl -column "csqrt" "complex absolute value (i.e. norm, modulus, magnitude)" +.Em "Name Description" +.. +.\" Section 7.3.5 - 7.3.7 of ISO C99 standard unimplemented, see BUGS +.\" Section 7.3.8 of ISO C99 standard +.Ss Absolute-value Functions +.Cl +cabs complex absolute value (i.e. norm, modulus, magnitude) +csqrt complex square root +.El +.Ss Exponential Function +.Cl +cexp exponential base e +.El +.\" Section 7.3.9 of ISO C99 standard +.Ss Manipulation Functions +.Cl +carg compute the argument (i.e. phase angle) +cimag compute the imaginary part +conj compute the complex conjugate +cproj compute projection onto Riemann sphere +creal compute the real part +.El +.\" Section 7.3.5-6 of ISO C99 standard +.Ss Trigonometric and Hyperbolic Functions +.Cl +ccos cosine +ccosh hyperbolic cosine +csin sine +csinh hyperbolic sine +ctan tangent +ctanh hyperbolic tangent +.El +.Sh SEE ALSO +.Xr math 3 , +.Xr fenv 3 , +.Xr ieee 3 , +.Xr tgmath 3 +.Rs +.%T "ISO/IEC 9899:TC3" +.%U http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf +.Re +.Sh STANDARDS +The +.In complex.h +functions described here conform to +.St -isoC-99 . +.Sh BUGS +The inverse trigonmetric and hyperbolic functions +.Fn cacos , +.Fn cacosh , +.Fn casin , +.Fn casinh , +.Fn catan , +and +.Fn catanh +are not implemented. +.Pp +The logarithmic functions +.Fn clog +are not implemented. +.Pp +The power functions +.Fn cpow +are not implemented. diff --git a/man/copysign.3 b/man/copysign.3 new file mode 100644 index 0000000..17c72de --- /dev/null +++ b/man/copysign.3 @@ -0,0 +1,86 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/copysign.3,v 1.2 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd January 26, 2005 +.Dt COPYSIGN 3 +.Os +.Sh NAME +.Nm copysign , +.Nm copysignf , +.Nm copysignl +.Nd copy sign +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn copysign "double x" "double y" +.Ft float +.Fn copysignf "float x" "float y" +.Ft long double +.Fn copysignl "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn copysign , +.Fn copysignf +and +.Fn copysignl +functions +return +.Fa x +with its sign changed to +.Fa y Ns 's . +.Sh SEE ALSO +.Xr fabs 3 , +.Xr fdim 3 , +.Xr ieee 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn copysign , +.Fn copysignf , +and +.Fn copysignl +routines conform to +.St -isoC-99 . +They implement the Copysign function recommended by +.St -ieee754 . +.Sh HISTORY +The +.Fn copysign , +.Fn copysignf , +and +.Fn copysignl +functions appeared in +.Bx 4.3 , +.Fx 2.0 , +and +.Fx 5.3 , +respectively. diff --git a/man/cos.3 b/man/cos.3 new file mode 100644 index 0000000..742bb09 --- /dev/null +++ b/man/cos.3 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)cos.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/cos.3,v 1.15 2011/10/17 05:41:03 das Exp $ +.\" +.Dd January 24, 2008 +.Dt COS 3 +.Os +.Sh NAME +.Nm cos , +.Nm cosf , +.Nm cosl +.Nd cosine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn cos "double x" +.Ft float +.Fn cosf "float x" +.Ft long double +.Fn cosl "long double x" +.Sh DESCRIPTION +The +.Fn cos , +.Fn cosf , +and +.Fn cosl +functions compute the cosine of +.Fa x +(measured in radians). +A large magnitude argument may yield a result with little or no +significance. +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn cos , +.Fn cosf , +and +.Fn cosl +functions return the cosine value. +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr ccos 3 , +.Xr cosh 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/cosh.3 b/man/cosh.3 new file mode 100644 index 0000000..98b94a1 --- /dev/null +++ b/man/cosh.3 @@ -0,0 +1,69 @@ +.\" Copyright (c) 1989, 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)cosh.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/cosh.3,v 1.14 2011/10/17 05:41:03 das Exp $ +.\" +.Dd January 14, 2005 +.Dt COSH 3 +.Os +.Sh NAME +.Nm cosh , +.Nm coshf +.Nd hyperbolic cosine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn cosh "double x" +.Ft float +.Fn coshf "float x" +.Sh DESCRIPTION +The +.Fn cosh +and the +.Fn coshf +functions compute the hyperbolic cosine of +.Fa x . +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr ccosh 3 , +.Xr cos 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn cosh +function conforms to +.St -isoC . diff --git a/man/csqrt.3 b/man/csqrt.3 new file mode 100644 index 0000000..1775191 --- /dev/null +++ b/man/csqrt.3 @@ -0,0 +1,102 @@ +.\" Copyright (c) 2007-2008 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/csqrt.3,v 1.2 2008/03/30 20:07:15 das Exp $ +.\" +.Dd March 30, 2008 +.Dt CSQRT 3 +.Os +.Sh NAME +.Nm csqrt , +.Nm csqrtf , +.Nm csqrtl +.Nd complex square root functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn csqrt "double complex z" +.Ft float complex +.Fn csqrtf "float complex z" +.Ft long double complex +.Fn csqrtl "long double complex z" +.Sh DESCRIPTION +The +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +functions compute the square root of +.Fa z +in the complex plane, with a branch cut along the negative real axis. +In other words, +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +always return the square root whose real part is non-negative. +.Sh RETURN VALUES +These functions return the requested square root. +The square root of 0 is +.Li +0 \*(Pm 0 , +where the imaginary parts of the input and respective result have +the same sign. +For infinities and \*(Nas, the following rules apply, with the +earlier rules having precedence: +.Bl -column -offset indent "-\*(If + \*(Na*I" "\*(If \*(Pm \*(If*I " "(for all k)" +.Em Input Result +k + \*(If*I \*(If + \*(If*I (for all k) +-\*(If + \*(Na*I \*(Na \*(Pm \*(If*I +\*(If + \*(Na*I \*(If + \*(Na*I +k + \*(Na*I \*(Na + \*(Na*I +\*(Na + k*I \*(Na + \*(Na*I +-\*(If + k*I +0 + \*(If*I +\*(If + k*I \*(If + 0*I +.El +.Pp +For numbers with negative imaginary parts, the above special cases +apply given the identity: +.Dl csqrt(conj(z) = conj(sqrt(z)) +Note that the sign of \*(Na is indeterminate. +Also, if the real or imaginary part of the input is finite and +an \*(Na is generated, an invalid exception will be thrown. +.Sh SEE ALSO +.Xr cabs 3 , +.Xr fenv 3 , +.Xr math 3 , +.Sh STANDARDS +The +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +functions conform to +.St -isoC-99 . +.Sh BUGS +For +.Fn csqrt +and +.Fn csqrtl , +inexact results are not always correctly rounded. diff --git a/man/erf.3 b/man/erf.3 new file mode 100644 index 0000000..1b38e5f --- /dev/null +++ b/man/erf.3 @@ -0,0 +1,93 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)erf.3 6.4 (Berkeley) 4/20/91 +.\" $FreeBSD: src/lib/msun/man/erf.3,v 1.12 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd April 20, 1991 +.Dt ERF 3 +.Os +.Sh NAME +.Nm erf , +.Nm erff , +.Nm erfc , +.Nm erfcf +.Nd error function operators +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn erf "double x" +.Ft float +.Fn erff "float x" +.Ft double +.Fn erfc "double x" +.Ft float +.Fn erfcf "float x" +.Sh DESCRIPTION +These functions calculate the error function of +.Fa x . +.Pp +The +.Fn erf +and the +.Fn erff +functions calculate the error function of x; where +.Bd -ragged -offset indent +.if n \{\ +erf(x) = 2/sqrt(pi)\(**\|integral from 0 to x of exp(\-t\(**t) dt. +\} +.if t \{\ +erf\|(x) := +(2/\(sr\(*p)\|\(is\d\s8\z0\s10\u\u\s8x\s10\d\|exp(\-t\u\s82\s10\d)\|dt. +\} +.Ed +.Pp +The +.Fn erfc +and the +.Fn erfcf +functions calculate the complementary error function of +.Fa x ; +that is +.Fn erfc +subtracts the result of the error function +.Fn erf x +from 1.0. +This is useful, since for large +.Fa x +places disappear. +.Sh SEE ALSO +.Xr math 3 +.Sh HISTORY +The +.Fn erf +and +.Fn erfc +functions appeared in +.Bx 4.3 . diff --git a/man/exp.3 b/man/exp.3 new file mode 100644 index 0000000..3a8b9d9 --- /dev/null +++ b/man/exp.3 @@ -0,0 +1,177 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)exp.3 6.12 (Berkeley) 7/31/91 +.\" $FreeBSD: src/lib/msun/man/exp.3,v 1.24 2008/01/18 21:43:00 das Exp $ +.\" +.Dd January 17, 2008 +.Dt EXP 3 +.Os +.Sh NAME +.Nm exp , +.Nm expf , +.\" The sorting error is intentional. exp and expf should be adjacent. +.Nm exp2 , +.Nm exp2f , +.Nm exp2l , +.Nm expm1 , +.Nm expm1f , +.Nm pow , +.Nm powf +.Nd exponential and power functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn exp "double x" +.Ft float +.Fn expf "float x" +.Ft double +.Fn exp2 "double x" +.Ft float +.Fn exp2f "float x" +.Ft long double +.Fn exp2l "long double x" +.Ft double +.Fn expm1 "double x" +.Ft float +.Fn expm1f "float x" +.Ft double +.Fn pow "double x" "double y" +.Ft float +.Fn powf "float x" "float y" +.Sh DESCRIPTION +The +.Fn exp +and the +.Fn expf +functions compute the base +.Ms e +exponential value of the given argument +.Fa x . +.Pp +The +.Fn exp2 , +.Fn exp2f , +and +.Fn exp2l +functions compute the base 2 exponential of the given argument +.Fa x . +.Pp +The +.Fn expm1 +and the +.Fn expm1f +functions compute the value exp(x)\-1 accurately even for tiny argument +.Fa x . +.Pp +The +.Fn pow +and the +.Fn powf +functions compute the value +of +.Ar x +to the exponent +.Ar y . +.Sh ERROR (due to Roundoff etc.) +The values of +.Fn exp 0 , +.Fn expm1 0 , +.Fn exp2 integer , +and +.Fn pow integer integer +are exact provided that they are representable. +.\" XXX Is this really true for pow()? +Otherwise the error in these functions is generally below one +.Em ulp . +.Sh RETURN VALUES +These functions will return the appropriate computation unless an error +occurs or an argument is out of range. +The functions +.Fn pow x y +and +.Fn powf x y +raise an invalid exception and return an \*(Na if +.Fa x +< 0 and +.Fa y +is not an integer. +.Sh NOTES +The function +.Fn pow x 0 +returns x**0 = 1 for all x including x = 0, \*(If, and \*(Na . +Previous implementations of pow may +have defined x**0 to be undefined in some or all of these +cases. +Here are reasons for returning x**0 = 1 always: +.Bl -enum -width indent +.It +Any program that already tests whether x is zero (or +infinite or \*(Na) before computing x**0 cannot care +whether 0**0 = 1 or not. +Any program that depends +upon 0**0 to be invalid is dubious anyway since that +expression's meaning and, if invalid, its consequences +vary from one computer system to another. +.It +Some Algebra texts (e.g.\& Sigler's) define x**0 = 1 for +all x, including x = 0. +This is compatible with the convention that accepts a[0] +as the value of polynomial +.Bd -literal -offset indent +p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n +.Ed +.Pp +at x = 0 rather than reject a[0]\(**0**0 as invalid. +.It +Analysts will accept 0**0 = 1 despite that x**y can +approach anything or nothing as x and y approach 0 +independently. +The reason for setting 0**0 = 1 anyway is this: +.Bd -ragged -offset indent +If x(z) and y(z) are +.Em any +functions analytic (expandable +in power series) in z around z = 0, and if there +x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0. +.Ed +.It +If 0**0 = 1, then +\*(If**0 = 1/0**0 = 1 too; and +then \*(Na**0 = 1 too because x**0 = 1 for all finite +and infinite x, i.e., independently of x. +.El +.Sh SEE ALSO +.Xr fenv 3 , +.Xr ldexp 3 , +.Xr log 3 , +.Xr math 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/fabs.3 b/man/fabs.3 new file mode 100644 index 0000000..4a3937e --- /dev/null +++ b/man/fabs.3 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" @(#)fabs.3 5.1 (Berkeley) 5/2/91 +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)fabs.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/fabs.3,v 1.12 2007/01/09 01:02:05 imp Exp $ +.\" +.Dd October 25, 2003 +.Dt FABS 3 +.Os +.Sh NAME +.Nm fabs , +.Nm fabsf , +.Nm fabsl +.Nd floating-point absolute value functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fabs "double x" +.Ft float +.Fn fabsf "float x" +.Ft long double +.Fn fabsl "long double x" +.Sh DESCRIPTION +The +.Fn fabs , +.Fn fabsf +and +.Fn fabsl +functions compute the absolute value of a floating-point number +.Fa x . +.Sh RETURN VALUES +The +.Fn fabs , +.Fn fabsf +and +.Fn fabsl +functions return the absolute value of +.Fa x . +.Sh SEE ALSO +.Xr abs 3 , +.Xr ceil 3 , +.Xr floor 3 , +.Xr ieee 3 , +.Xr math 3 , +.Xr rint 3 +.Sh STANDARDS +The +.Fn fabs +function conforms to +.St -isoC . +The +.Fn fabsf +and +.Fn fabsl +functions conform to +.St -isoC-99 . diff --git a/man/fdim.3 b/man/fdim.3 new file mode 100644 index 0000000..10facbf --- /dev/null +++ b/man/fdim.3 @@ -0,0 +1,86 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fdim.3,v 1.2 2010/08/16 15:18:30 joel Exp $ +.\" +.Dd June 29, 2004 +.Dt FDIM 3 +.Os +.Sh NAME +.Nm fdim , +.Nm fdimf , +.Nm fdiml +.Nd positive difference functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fdim "double x" "double y" +.Ft float +.Fn fdimf "float x" "float y" +.Ft long double +.Fn fdiml "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn fdim , +.Fn fdimf , +and +.Fn fdiml +functions return the positive difference between +.Fa x +and +.Fa y . +That is, if +.Fa x\- Ns Fa y +is positive, then +.Fa x\- Ns Fa y +is returned. +If either +.Fa x +or +.Fa y +is an \*(Na, then an \*(Na is returned. +Otherwise, the result is +.Li +0.0 . +.Pp +Overflow or underflow may occur if the exact result is not +representable in the return type. +No other exceptions are raised. +.Sh SEE ALSO +.Xr fabs 3 , +.Xr fmax 3 , +.Xr fmin 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn fdim , +.Fn fdimf , +and +.Fn fdiml +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . diff --git a/man/feclearexcept.3 b/man/feclearexcept.3 new file mode 100644 index 0000000..073de67 --- /dev/null +++ b/man/feclearexcept.3 @@ -0,0 +1,139 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/feclearexcept.3,v 1.3 2005/01/14 09:12:05 ru Exp $ +.\" +.Dd May 8, 2004 +.Dt FECLEAREXCEPT 3 +.Os +.Sh NAME +.Nm feclearexcept , +.Nm fegetexceptflag , +.Nm feraiseexcept , +.Nm fesetexceptflag , +.Nm fetestexcept +.Nd floating-point exception flag manipulation +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In fenv.h +.Fd "#pragma STDC FENV_ACCESS ON" +.Ft int +.Fn feclearexcept "int excepts" +.Ft int +.Fn fegetexceptflag "fexcept_t *flagp" "int excepts" +.Ft int +.Fn feraiseexcept "int excepts" +.Ft int +.Fn fesetexceptflag "const fexcept_t *flagp" "int excepts" +.Ft int +.Fn fetestexcept "int excepts" +.Sh DESCRIPTION +The +.Fn feclearexcept +routine clears the floating-point exception flags specified by +.Fa excepts , +whereas +.Fn feraiseexcept +raises the specified exceptions. +Raising an exception causes the corresponding flag to be set, +and a +.Dv SIGFPE +is delivered to the process if the exception is unmasked. +.Pp +The +.Fn fetestexcept +function determines which flags are currently set, of those specified by +.Fa excepts . +.Pp +The +.Fn fegetexceptflag +function stores the state of the exception flags specified in +.Fa excepts +in the opaque object pointed to by +.Fa flagp . +Similarly, +.Fn fesetexceptflag +changes the specified exception flags to reflect the state stored in +the object pointed to by +.Fa flagp . +Note that the flags restored with +.Fn fesetexceptflag +must be a (not necessarily proper) subset of the flags recorded by +a prior call to +.Fn fegetexceptflag . +.Pp +For all of these functions, the possible types of exceptions +include those described in +.Xr fenv 3 . +Some architectures may define other types of floating-point exceptions. +.Sh IMPLEMENTATION NOTES +On some architectures, raising an overflow or underflow exception +also causes an inexact exception to be raised. +In these cases, the overflow or underflow will be raised first. +.Pp +The +.Fn fegetexceptflag +and +.Fn fesetexceptflag +routines are preferred to +.Fn fetestexcept +and +.Fn feraiseexcept , +respectively, for saving and restoring exception flags. +The latter do not re-raise exceptions and may preserve +architecture-specific information such as addresses where +exceptions occurred. +.Sh RETURN VALUES +The +.Fn feclearexcept , +.Fn fegetexceptflag , +.Fn feraiseexcept , +and +.Fn fesetexceptflag +functions return 0 upon success, and non-zero otherwise. +The +.Fn fetestexcept +function returns the bitwise OR of the values of the current exception +flags that were requested. +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr feholdexcept 3 , +.Xr fenv 3 , +.Xr feupdateenv 3 , +.Xr fpgetsticky 3 , +.Xr fpresetsticky 3 +.Sh STANDARDS +The +.Fn feclearexcept , +.Fn fegetexceptflag , +.Fn feraiseexcept , +.Fn fesetexceptflag , +and +.Fn fetestexcept +routines conform to +.St -isoC-99 . +.Sh HISTORY +These functions first appeared in +.Fx 5.3 . diff --git a/man/feenableexcept.3 b/man/feenableexcept.3 new file mode 100644 index 0000000..0b790e7 --- /dev/null +++ b/man/feenableexcept.3 @@ -0,0 +1,98 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/feenableexcept.3,v 1.1 2005/03/16 19:04:28 das Exp $ +.\" +.Dd March 16, 2005 +.Dt FEENABLEEXCEPT 3 +.Os +.Sh NAME +.Nm feenableexcept , +.Nm fedisableexcept , +.Nm fegetexcept +.Nd floating-point exception masking +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In fenv.h +.Fd "#pragma STDC FENV_ACCESS ON" +.Ft int +.Fn feenableexcept "int excepts" +.Ft int +.Fn fedisableexcept "int excepts" +.Ft int +.Fn fegetexcept "void" +.Sh DESCRIPTION +The +.Fn feenableexcept +and +.Fn fedisableexcept +functions +unmask and mask (respectively) exceptions specified in +.Fa excepts . +The +.Fn fegetexcept +function +returns the current exception mask. +All exceptions are masked by default. +.Pp +Floating-point operations that produce unmasked exceptions will trap, and a +.Dv SIGFPE +will be delivered to the process. +By installing a signal handler for +.Dv SIGFPE , +applications can take appropriate action immediately without +testing the exception flags after every operation. +Note that the trap may not be immediate, but it should occur +before the next floating-point instruction is executed. +.Pp +For all of these functions, the possible types of exceptions +include those described in +.Xr fenv 3 . +Some architectures may define other types of floating-point exceptions. +.Sh RETURN VALUES +The +.Fn feenableexcept , +.Fn fedisableexcept , +and +.Fn fegetexcept +functions return a bitmap of the exceptions that were unmasked +prior to the call. +.Sh SEE ALSO +.Xr sigaction 2 , +.Xr feclearexcept 3 , +.Xr feholdexcept 3 , +.Xr fenv 3 , +.Xr feupdateenv 3 +.Sh BUGS +Functions in the standard library may trigger exceptions multiple +times as a result of intermediate computations; +however, they generally do not trigger spurious exceptions. +.Pp +No interface is provided to permit exceptions to be handled in +nontrivial ways. +There is no uniform way for an exception handler to access +information about the exception-causing instruction, or +to determine whether that instruction should be reexecuted +after returning from the handler. diff --git a/man/fegetenv.3 b/man/fegetenv.3 new file mode 100644 index 0000000..2e386ad --- /dev/null +++ b/man/fegetenv.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fegetenv.3,v 1.1 2004/06/06 10:06:26 das Exp $ +.\" +.Dd May 8, 2004 +.Dt FEGETENV 3 +.Os +.Sh NAME +.Nm fegetenv , +.Nm feholdexcept , +.Nm fesetenv , +.Nm feupdateenv +.Nd floating-point environment save and restore +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In fenv.h +.Fd "#pragma STDC FENV_ACCESS ON" +.Ft int +.Fn fegetenv "fenv_t *envp" +.Ft int +.Fn feholdexcept "fenv_t *envp" +.Ft int +.Fn fesetenv "const fenv_t *envp" +.Ft int +.Fn feupdateenv "const fenv_t *envp" +.Sh DESCRIPTION +The floating-point environment includes exception flags and masks, the +current rounding mode, and other architecture-specific settings. +However, it does not include the floating-point register file. +.Pp +The +.Fn fegetenv +function stores the current floating-point environment in the object +pointed to by +.Fa envp , +whereas +.Fn feholdexcept +saves the current environment, then clears all exception flags +and masks all floating-point exceptions. +.Pp +The +.Fn fesetenv +function restores a previously saved environment. +The +.Fn feupdateenv +function restores a saved environment as well, but it also +raises any exceptions that were set in the environment it +replaces. +.Pp +The +.Fn feholdexcept +function is often used with +.Fn feupdateenv +or +.Fn fesetenv +to suppress spurious exceptions that occur as a result of +intermediate computations. +An example in +.Xr fenv 3 +demonstrates how to do this. +.Sh RETURN VALUES +The +.Fn fegetenv , +.Fn feholdexcept , +.Fn fesetenv , +and +.Fn feupdateenv +functions return 0 if they succeed, and non-zero otherwise. +.Sh SEE ALSO +.Xr feclearexcept 3 , +.Xr fenv 3 , +.Xr feraiseexcept 3 , +.Xr fesetenv 3 , +.Xr fetestexcept 3 , +.Xr fpgetmask 3 , +.Xr fpgetprec 3 , +.Xr fpsetmask 3 , +.Xr fpsetprec 3 +.Sh STANDARDS +The +.Fn fegetenv , +.Fn feholdexcept , +.Fn fesetenv , +and +.Fn feupdateenv +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . diff --git a/man/fegetround.3 b/man/fegetround.3 new file mode 100644 index 0000000..9384158 --- /dev/null +++ b/man/fegetround.3 @@ -0,0 +1,83 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fegetround.3,v 1.2 2005/01/14 09:12:05 ru Exp $ +.\" +.Dd May 8, 2004 +.Dt FEGETROUND 3 +.Os +.Sh NAME +.Nm fegetround , +.Nm fesetround +.Nd floating-point rounding control +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In fenv.h +.Fd "#pragma STDC FENV_ACCESS ON" +.Ft int +.Fn fegetround void +.Ft int +.Fn fesetround "int round" +.Sh DESCRIPTION +The +.Fn fegetround +function determines the current floating-point rounding mode, +and the +.Fn fesetround +function sets the current rounding mode to +.Fa round . +The rounding mode is one of +.Dv FE_TONEAREST , FE_DOWNWARD , FE_UPWARD , +or +.Dv FE_TOWARDZERO , +as described in +.Xr fenv 3 . +.Sh RETURN VALUES +The +.Fn fegetround +routine returns the current rounding mode. +The +.Fn fesetround +function returns 0 on success and non-zero otherwise; +however, the present implementation always succeeds. +.Sh SEE ALSO +.Xr fenv 3 , +.Xr fpgetround 3 , +.Xr fpsetround 3 +.Sh STANDARDS +The +.Fn fegetround +and +.Fn fesetround +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . +They supersede the non-standard +.Xr fpgetround 3 +and +.Xr fpsetround 3 +functions. diff --git a/man/fenv.3 b/man/fenv.3 new file mode 100644 index 0000000..63ee7a1 --- /dev/null +++ b/man/fenv.3 @@ -0,0 +1,293 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fenv.3,v 1.8 2011/10/21 14:23:59 das Exp $ +.\" +.Dd March 16, 2005 +.Dt FENV 3 +.Os +.Sh NAME +.Nm feclearexcept , +.Nm fegetexceptflag , +.Nm feraiseexcept , +.Nm fesetexceptflag , +.Nm fetestexcept , +.Nm fegetround , +.Nm fesetround , +.Nm fegetenv , +.Nm feholdexcept , +.Nm fesetenv , +.Nm feupdateenv , +.Nm feenableexcept , +.Nm fedisableexcept , +.Nm fegetexcept +.Nd floating-point environment control +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In fenv.h +.Fd "#pragma STDC FENV_ACCESS ON" +.Ft int +.Fn feclearexcept "int excepts" +.Ft int +.Fn fegetexceptflag "fexcept_t *flagp" "int excepts" +.Ft int +.Fn feraiseexcept "int excepts" +.Ft int +.Fn fesetexceptflag "const fexcept_t *flagp" "int excepts" +.Ft int +.Fn fetestexcept "int excepts" +.Ft int +.Fn fegetround void +.Ft int +.Fn fesetround "int round" +.Ft int +.Fn fegetenv "fenv_t *envp" +.Ft int +.Fn feholdexcept "fenv_t *envp" +.Ft int +.Fn fesetenv "const fenv_t *envp" +.Ft int +.Fn feupdateenv "const fenv_t *envp" +.Ft int +.Fn feenableexcept "int excepts" +.Ft int +.Fn fedisableexcept "int excepts" +.Ft int +.Fn fegetexcept void +.Sh DESCRIPTION +The +.In fenv.h +routines manipulate the floating-point environment, +which includes the exception flags and rounding modes defined in +.St -ieee754 . +.Ss Exceptions +Exception flags are set as side-effects of floating-point arithmetic +operations and math library routines, and they remain set until +explicitly cleared. +The following macros expand to bit flags of type +.Vt int +representing the five standard floating-point exceptions. +.Bl -tag -width ".Dv FE_DIVBYZERO" +.It Dv FE_DIVBYZERO +A divide-by-zero exception occurs when the +.Em exact +result of a computation is infinite (according to the limit definition). +For example, dividing a finite non-zero number by zero or computing +.Fn log 0 +raises a divide-by-zero exception. +.It Dv FE_INEXACT +An inexact exception is raised whenever there is a loss of accuracy +due to rounding. +.It Dv FE_INVALID +Invalid operation exceptions occur when a program attempts to +perform calculations for which there is no reasonable representable +answer. +For instance, subtraction of like-signed infinities, division of zero by zero, +ordered comparison involving \*(Nas, and taking the real square root of a +negative number are all invalid operations. +.It Dv FE_OVERFLOW +In contrast with divide-by-zero, +an overflow exception occurs when an infinity is produced because +the magnitude of the exact result is +.Em finite +but too large to fit in the destination type. +For example, computing +.Li DBL_MAX * 2 +raises an overflow exception. +.It Dv FE_UNDERFLOW +Underflow occurs when the result of a computation loses precision +because it is too close to zero. +The result is a subnormal number or zero. +.El +.Pp +Additionally, the +.Dv FE_ALL_EXCEPT +macro expands to the bitwise OR of the above flags and any +architecture-specific flags. +Combinations of these flags are passed to the +.Fn feclearexcept , +.Fn fegetexceptflag , +.Fn feraiseexcept , +.Fn fesetexceptflag , +and +.Fn fetestexcept +functions to clear, save, raise, restore, and examine the +processor's floating-point exception flags, respectively. +.Pp +Exceptions may be +.Em unmasked +with +.Fn feenableexcept +and masked with +.Fn fedisableexcept . +Unmasked exceptions cause a trap when they are produced, and +all exceptions are masked by default. +The current mask can be tested with +.Fn fegetexcept . +.Ss Rounding Modes +.St -ieee754 +specifies four rounding modes. +These modes control the direction in which results are rounded +from their exact values in order to fit them into binary +floating-point variables. +The four modes correspond with the following symbolic constants. +.Bl -tag -width ".Dv FE_TOWARDZERO" +.It Dv FE_TONEAREST +Results are rounded to the closest representable value. +If the exact result is exactly half way between two representable +values, the value whose last binary digit is even (zero) is chosen. +This is the default mode. +.It Dv FE_DOWNWARD +Results are rounded towards negative \*[If]. +.It Dv FE_UPWARD +Results are rounded towards positive \*[If]. +.It Dv FE_TOWARDZERO +Results are rounded towards zero. +.El +.Pp +The +.Fn fegetround +and +.Fn fesetround +functions query and set the rounding mode. +.Ss Environment Control +The +.Fn fegetenv +and +.Fn fesetenv +functions save and restore the floating-point environment, +which includes exception flags, the current exception mask, +the rounding mode, and possibly other implementation-specific +state. +The +.Fn feholdexcept +function behaves like +.Fn fegetenv , +but with the additional effect of clearing the exception flags and +installing a +.Em non-stop +mode. +In non-stop mode, floating-point operations will set exception flags +as usual, but no +.Dv SIGFPE +signals will be generated as a result. +Non-stop mode is the default, but it may be altered by +.Fn feenableexcept +and +.Fn fedisableexcept . +The +.Fn feupdateenv +function restores a saved environment similarly to +.Fn fesetenv , +but it also re-raises any floating-point exceptions from the old +environment. +.Pp +The macro +.Dv FE_DFL_ENV +expands to a pointer to the default environment. +.Sh EXAMPLES +The following routine computes the square root function. +It explicitly raises an invalid exception on appropriate inputs using +.Fn feraiseexcept . +It also defers inexact exceptions while it computes intermediate +values, and then it allows an inexact exception to be raised only if +the final answer is inexact. +.Bd -literal -offset indent +#pragma STDC FENV_ACCESS ON +double sqrt(double n) { + double x = 1.0; + fenv_t env; + + if (isnan(n) || n < 0.0) { + feraiseexcept(FE_INVALID); + return (NAN); + } + if (isinf(n) || n == 0.0) + return (n); + feholdexcept(&env); + while (fabs((x * x) - n) > DBL_EPSILON * 2 * x) + x = (x / 2) + (n / (2 * x)); + if (x * x == n) + feclearexcept(FE_INEXACT); + feupdateenv(&env); + return (x); +} +.Ed +.Sh SEE ALSO +.Xr cc 1 , +.Xr feclearexcept 3 , +.Xr fedisableexcept 3 , +.Xr feenableexcept 3 , +.Xr fegetenv 3 , +.Xr fegetexcept 3 , +.Xr fegetexceptflag 3 , +.Xr fegetround 3 , +.Xr feholdexcept 3 , +.Xr feraiseexcept 3 , +.Xr fesetenv 3 , +.Xr fesetexceptflag 3 , +.Xr fesetround 3 , +.Xr fetestexcept 3 , +.Xr feupdateenv 3 , +.Xr fpgetprec 3 , +.Xr fpsetprec 3 +.Sh STANDARDS +Except as noted below, +.In fenv.h +conforms to +.St -isoC-99 . +The +.Fn feenableexcept , +.Fn fedisableexcept , +and +.Fn fegetexcept +routines are extensions. +.Sh HISTORY +The +.In fenv.h +header first appeared in +.Fx 5.3 . +It supersedes the non-standard routines defined in +.In ieeefp.h +and documented in +.Xr fpgetround 3 . +.Sh CAVEATS +The FENV_ACCESS pragma can be enabled with +.Dl "#pragma STDC FENV_ACCESS ON" +and disabled with the +.Dl "#pragma STDC FENV_ACCESS OFF" +directive. +This lexically-scoped annotation tells the compiler that the program +may access the floating-point environment, so optimizations that would +violate strict IEEE-754 semantics are disabled. +If execution reaches a block of code for which +.Dv FENV_ACCESS +is off, the floating-point environment will become undefined. +.Sh BUGS +The +.Dv FENV_ACCESS +pragma is unimplemented in the system compiler. +However, non-constant expressions generally produce the correct +side-effects at low optimization levels. diff --git a/man/floor.3 b/man/floor.3 new file mode 100644 index 0000000..359a6b4 --- /dev/null +++ b/man/floor.3 @@ -0,0 +1,78 @@ +.\" Copyright (c) 1985, 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)floor.3 6.5 (Berkeley) 4/19/91 +.\" $FreeBSD: src/lib/msun/man/floor.3,v 1.18 2007/01/09 01:02:06 imp Exp $ +.\" +.Dd January 13, 2005 +.Dt FLOOR 3 +.Os +.Sh NAME +.Nm floor , +.Nm floorf , +.Nm floorl +.Nd largest integral value less than or equal to x +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn floor "double x" +.Ft float +.Fn floorf "float x" +.Ft "long double" +.Fn floorl "long double x" +.Sh DESCRIPTION +The +.Fn floor , +.Fn floorf +and +.Fn floorl +functions return the largest integral value +less than or equal to +.Fa x , +expressed as a floating-point number. +.Sh SEE ALSO +.Xr abs 3 , +.Xr ceil 3 , +.Xr fabs 3 , +.Xr ieee 3 , +.Xr math 3 , +.Xr rint 3 , +.Xr round 3 , +.Xr trunc 3 +.Sh STANDARDS +The +.Fn floor +function conforms to +.St -isoC . +The +.Fn floorf +and +.Fn floorl +functions conform to +.St -isoC-99 . diff --git a/man/fma.3 b/man/fma.3 new file mode 100644 index 0000000..078a6e2 --- /dev/null +++ b/man/fma.3 @@ -0,0 +1,116 @@ +.\" Copyright (c) 2005 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fma.3,v 1.3 2005/11/24 09:25:10 joel Exp $ +.\" +.Dd January 22, 2005 +.Dt FMA 3 +.Os +.Sh NAME +.Nm fma , +.Nm fmaf , +.Nm fmal +.Nd fused multiply-add +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fma "double x" "double y" "double z" +.Ft float +.Fn fmaf "float x" "float y" "float z" +.Ft long double +.Fn fmal "long double x" "long double y" "long double z" +.Sh DESCRIPTION +The +.Fn fma , +.Fn fmaf , +and +.Fn fmal +functions return +.No "(x * y) + z" , +computed with only one rounding error. +Using the ordinary multiplication and addition operators, by contrast, +results in two roundings: one for the intermediate product and one for +the final result. +.Pp +For instance, the expression +.No "1.2e100 * 2.0e208 - 1.4e308" +produces \*(If due to overflow in the intermediate product, whereas +.No "fma(1.2e100, 2.0e208, -1.4e308)" +returns approximately 1.0e308. +.Pp +The fused multiply-add operation is often used to improve the +accuracy of calculations such as dot products. +It may also be used to improve performance on machines that implement +it natively. +The macros +.Dv FP_FAST_FMA , +.Dv FP_FAST_FMAF +and +.Dv FP_FAST_FMAL +may be defined in +.In math.h +to indicate that +.Fn fma , +.Fn fmaf , +and +.Fn fmal +(respectively) have comparable or faster speed than a multiply +operation followed by an add operation. +.Sh IMPLEMENTATION NOTES +In general, these routines will behave as one would expect if +.No "x * y + z" +were computed with unbounded precision and range, +then rounded to the precision of the return type. +However, on some platforms, if +.Fa z +is \*(Na, these functions may not raise an exception even +when the computation of +.No "x * y" +would have otherwise generated an invalid exception. +.Sh SEE ALSO +.Xr fenv 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn fma , +.Fn fmaf , +and +.Fn fmal +functions conform to +.St -isoC-99 . +A fused multiply-add operation with virtually identical +characteristics appears in IEEE draft standard 754R. +.Sh HISTORY +The +.Fn fma +and +.Fn fmaf +routines first appeared in +.Fx 5.4 , +and +.Fn fmal +appeared in +.Fx 6.0 . diff --git a/man/fmax.3 b/man/fmax.3 new file mode 100644 index 0000000..03249a3 --- /dev/null +++ b/man/fmax.3 @@ -0,0 +1,97 @@ +.\" Copyright (c) 2004 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/fmax.3,v 1.2 2005/01/14 09:12:05 ru Exp $ +.\" +.Dd June 29, 2004 +.Dt FMAX 3 +.Os +.Sh NAME +.Nm fmax , +.Nm fmaxf , +.Nm fmaxl , +.Nm fmin , +.Nm fminf , +.Nm fminl +.Nd floating-point maximum and minimum functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fmax "double x" "double y" +.Ft float +.Fn fmaxf "float x" "float y" +.Ft "long double" +.Fn fmaxl "long double x" "long double y" +.Ft double +.Fn fmin "double x" "double y" +.Ft float +.Fn fminf "float x" "float y" +.Ft "long double" +.Fn fminl "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn fmax , +.Fn fmaxf , +and +.Fn fmaxl +functions return the larger of +.Fa x +and +.Fa y , +and likewise, the +.Fn fmin , +.Fn fminf , +and +.Fn fminl +functions return the smaller of +.Fa x +and +.Fa y . +They treat +.Li +0.0 +as being larger than +.Li -0.0 . +If one argument is an \*(Na, then the other argument is returned. +If both arguments are \*(Nas, then the result is an \*(Na. +These routines do not raise any floating-point exceptions. +.Sh SEE ALSO +.Xr fabs 3 , +.Xr fdim 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn fmax , +.Fn fmaxf , +.Fn fmaxl , +.Fn fmin , +.Fn fminf , +and +.Fn fminl +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . diff --git a/man/fmod.3 b/man/fmod.3 new file mode 100644 index 0000000..9909e26 --- /dev/null +++ b/man/fmod.3 @@ -0,0 +1,87 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)fmod.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/fmod.3,v 1.10 2008/06/19 22:39:53 das Exp $ +.\" +.Dd June 19, 2008 +.Dt FMOD 3 +.Os +.Sh NAME +.Nm fmod , +.Nm fmodf , +.Nm fmodl +.Nd floating-point remainder functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fmod "double x" "double y" +.Ft float +.Fn fmodf "float x" "float y" +.Ft long double +.Fn fmodl "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn fmod , +.Fn fmodf , +and +.Fn fmodl +functions compute the floating-point remainder of +.Fa x Ns / Fa y . +.Sh RETURN VALUES +If +.Fa y +is non-zero, the +.Fn fmod , +.Fn fmodf , +and +.Fn fmodl +functions return the value +.Sm off +.Fa x - Em i * Fa y , +.Sm on +for some integer +.Em i , +such that the result has the same sign as +.Fa x +and magnitude less than the magnitude of +.Fa y . +If +.Fa y +is zero, a \*(Na is produced. +.Sh SEE ALSO +.Xr math 3 +.Sh STANDARDS +The +.Fn fmod , +.Fn fmodf , +and +.Fn fmodl +functions conform to +.St -isoC-99 . diff --git a/man/hypot.3 b/man/hypot.3 new file mode 100644 index 0000000..74d3d44 --- /dev/null +++ b/man/hypot.3 @@ -0,0 +1,145 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)hypot.3 6.7 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/hypot.3,v 1.18 2010/05/13 12:08:11 uqs Exp $ +.\" +.Dd March 30, 2008 +.Dt HYPOT 3 +.Os +.Sh NAME +.Nm hypot , +.Nm hypotf , +.Nm hypotl , +.Nm cabs , +.Nm cabsf , +.Nm cabsl +.Nd Euclidean distance and complex absolute value functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn hypot "double x" "double y" +.Ft float +.Fn hypotf "float x" "float y" +.Ft "long double" +.Fn hypotl "long double x" "long double y" +.In complex.h +.Ft double +.Fn cabs "double complex z" +.Ft float +.Fn cabsf "float complex z" +.Ft "long double" +.Fn cabsl "long double complex z" +.Sh DESCRIPTION +The +.Fn hypot , +.Fn hypotf +and +.Fn hypotl +functions +compute the +sqrt(x*x+y*y) +in such a way that underflow will not happen, and overflow +occurs only if the final result deserves it. +The +.Fn cabs , +.Fn cabsf +and +.Fn cabsl +functions compute the complex absolute value of +.Fa z . +.Pp +.Fn hypot "\*(If" "v" += +.Fn hypot "v" "\*(If" += +\*(If for all +.Fa v , +including \*(Na. +.Sh ERROR (due to Roundoff, etc.) +Below 0.97 +.Em ulps . +Consequently +.Fn hypot "5.0" "12.0" += 13.0 +exactly; +in general, hypot and cabs return an integer whenever an +integer might be expected. +.Sh NOTES +As might be expected, +.Fn hypot "v" "\*(Na" +and +.Fn hypot "\*(Na" "v" +are \*(Na for all +.Em finite +.Fa v . +But programmers +might be surprised at first to discover that +.Fn hypot "\(+-\*(If" "\*(Na" += +\*(If. +This is intentional; it happens because +.Fn hypot "\*(If" "v" += +\*(If +for +.Em all +.Fa v , +finite or infinite. +Hence +.Fn hypot "\*(If" "v" +is independent of +.Fa v . +Unlike the reserved operand fault on a +.Tn VAX , +the +.Tn IEEE +\*(Na is designed to +disappear when it turns out to be irrelevant, as it does in +.Fn hypot "\*(If" "\*(Na" . +.Sh SEE ALSO +.Xr carg 3 , +.Xr math 3 , +.Xr sqrt 3 +.Sh STANDARDS +The +.Fn hypot , +.Fn hypotf , +.Fn hypotl , +.Fn cabs , +.Fn cabsf , +and +.Fn cabsl +functions conform to +.St -isoC-99 . +.Sh HISTORY +Both a +.Fn hypot +function and a +.Fn cabs +function +appeared in +.At v7 . diff --git a/man/ieee.3 b/man/ieee.3 new file mode 100644 index 0000000..0551a3d --- /dev/null +++ b/man/ieee.3 @@ -0,0 +1,444 @@ +.\" Copyright (c) 1985 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/ieee.3,v 1.25 2011/10/16 14:30:28 eadler Exp $ +.\" +.Dd January 26, 2005 +.Dt IEEE 3 +.Os +.Sh NAME +.Nm ieee +.Nd IEEE standard 754 for floating-point arithmetic +.Sh DESCRIPTION +The IEEE Standard 754 for Binary Floating-Point Arithmetic +defines representations of floating-point numbers and abstract +properties of arithmetic operations relating to precision, +rounding, and exceptional cases, as described below. +.Ss IEEE STANDARD 754 Floating-Point Arithmetic +Radix: Binary. +.Pp +Overflow and underflow: +.Bd -ragged -offset indent -compact +Overflow goes by default to a signed \*(If. +Underflow is +.Em gradual . +.Ed +.Pp +Zero is represented ambiguously as +0 or \-0. +.Bd -ragged -offset indent -compact +Its sign transforms correctly through multiplication or +division, and is preserved by addition of zeros +with like signs; but x\-x yields +0 for every +finite x. +The only operations that reveal zero's +sign are division by zero and +.Fn copysign x \(+-0 . +In particular, comparison (x > y, x \(>= y, etc.)\& +cannot be affected by the sign of zero; but if +finite x = y then \*(If = 1/(x\-y) \(!= \-1/(y\-x) = \-\*(If. +.Ed +.Pp +Infinity is signed. +.Bd -ragged -offset indent -compact +It persists when added to itself +or to any finite number. +Its sign transforms +correctly through multiplication and division, and +(finite)/\(+-\*(If\0=\0\(+-0 +(nonzero)/0 = \(+-\*(If. +But +\*(If\-\*(If, \*(If\(**0 and \*(If/\*(If +are, like 0/0 and sqrt(\-3), +invalid operations that produce \*(Na. ... +.Ed +.Pp +Reserved operands (\*(Nas): +.Bd -ragged -offset indent -compact +An \*(Na is +.Em ( N Ns ot Em a N Ns umber ) . +Some \*(Nas, called Signaling \*(Nas, trap any floating-point operation +performed upon them; they are used to mark missing +or uninitialized values, or nonexistent elements +of arrays. +The rest are Quiet \*(Nas; they are +the default results of Invalid Operations, and +propagate through subsequent arithmetic operations. +If x \(!= x then x is \*(Na; every other predicate +(x > y, x = y, x < y, ...) is FALSE if \*(Na is involved. +.Ed +.Pp +Rounding: +.Bd -ragged -offset indent -compact +Every algebraic operation (+, \-, \(**, /, +\(sr) +is rounded by default to within half an +.Em ulp , +and when the rounding error is exactly half an +.Em ulp +then +the rounded value's least significant bit is zero. +(An +.Em ulp +is one +.Em U Ns nit +in the +.Em L Ns ast +.Em P Ns lace . ) +This kind of rounding is usually the best kind, +sometimes provably so; for instance, for every +x = 1.0, 2.0, 3.0, 4.0, ..., 2.0**52, we find +(x/3.0)\(**3.0 == x and (x/10.0)\(**10.0 == x and ... +despite that both the quotients and the products +have been rounded. +Only rounding like IEEE 754 can do that. +But no single kind of rounding can be +proved best for every circumstance, so IEEE 754 +provides rounding towards zero or towards ++\*(If or towards \-\*(If +at the programmer's option. +.Ed +.Pp +Exceptions: +.Bd -ragged -offset indent -compact +IEEE 754 recognizes five kinds of floating-point exceptions, +listed below in declining order of probable importance. +.Bl -column -offset indent "Invalid Operation" "Gradual Underflow" +.Em "Exception Default Result" +Invalid Operation \*(Na, or FALSE +Overflow \(+-\*(If +Divide by Zero \(+-\*(If +Underflow Gradual Underflow +Inexact Rounded value +.El +.Pp +NOTE: An Exception is not an Error unless handled +badly. +What makes a class of exceptions exceptional +is that no single default response can be satisfactory +in every instance. +On the other hand, if a default +response will serve most instances satisfactorily, +the unsatisfactory instances cannot justify aborting +computation every time the exception occurs. +.Ed +.Ss Data Formats +Single-precision: +.Bd -ragged -offset indent -compact +Type name: +.Vt float +.Pp +Wordsize: 32 bits. +.Pp +Precision: 24 significant bits, +roughly like 7 significant decimals. +.Bd -ragged -offset indent -compact +If x and x' are consecutive positive single-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bd -ragged -compact +5.9e\-08 < 0.5**24 < (x'\-x)/x \(<= 0.5**23 < 1.2e\-07. +.Ed +.Ed +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**128 = 3.4e38 + Underflow threshold = 0.5**126 = 1.2e\-38 +.El +.Bd -ragged -offset indent -compact +Underflowed results round to the nearest +integer multiple of 0.5**149 = 1.4e\-45. +.Ed +.Ed +.Pp +Double-precision: +.Bd -ragged -offset indent -compact +Type name: +.Vt double +.Bd -ragged -offset indent -compact +On some architectures, +.Vt long double +is the same as +.Vt double . +.Ed +.Pp +Wordsize: 64 bits. +.Pp +Precision: 53 significant bits, +roughly like 16 significant decimals. +.Bd -ragged -offset indent -compact +If x and x' are consecutive positive double-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bd -ragged -compact +1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16. +.Ed +.Ed +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**1024 = 1.8e308 + Underflow threshold = 0.5**1022 = 2.2e\-308 +.El +.Bd -ragged -offset indent -compact +Underflowed results round to the nearest +integer multiple of 0.5**1074 = 4.9e\-324. +.Ed +.Ed +.Pp +Extended-precision: +.Bd -ragged -offset indent -compact +Type name: +.Vt long double +(when supported by the hardware) +.Pp +Wordsize: 96 bits. +.Pp +Precision: 64 significant bits, +roughly like 19 significant decimals. +.Bd -ragged -offset indent -compact +If x and x' are consecutive positive extended-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bd -ragged -compact +1.0e\-19 < 0.5**63 < (x'\-x)/x \(<= 0.5**62 < 2.2e\-19. +.Ed +.Ed +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**16384 = 1.2e4932 + Underflow threshold = 0.5**16382 = 3.4e\-4932 +.El +.Bd -ragged -offset indent -compact +Underflowed results round to the nearest +integer multiple of 0.5**16445 = 5.7e\-4953. +.Ed +.Ed +.Pp +Quad-extended-precision: +.Bd -ragged -offset indent -compact +Type name: +.Vt long double +(when supported by the hardware) +.Pp +Wordsize: 128 bits. +.Pp +Precision: 113 significant bits, +roughly like 34 significant decimals. +.Bd -ragged -offset indent -compact +If x and x' are consecutive positive quad-extended-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bd -ragged -compact +9.6e\-35 < 0.5**113 < (x'\-x)/x \(<= 0.5**112 < 2.0e\-34. +.Ed +.Ed +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**16384 = 1.2e4932 + Underflow threshold = 0.5**16382 = 3.4e\-4932 +.El +.Bd -ragged -offset indent -compact +Underflowed results round to the nearest +integer multiple of 0.5**16494 = 6.5e\-4966. +.Ed +.Ed +.Ss Additional Information Regarding Exceptions +.Pp +For each kind of floating-point exception, IEEE 754 +provides a Flag that is raised each time its exception +is signaled, and stays raised until the program resets +it. +Programs may also test, save and restore a flag. +Thus, IEEE 754 provides three ways by which programs +may cope with exceptions for which the default result +might be unsatisfactory: +.Bl -enum +.It +Test for a condition that might cause an exception +later, and branch to avoid the exception. +.It +Test a flag to see whether an exception has occurred +since the program last reset its flag. +.It +Test a result to see whether it is a value that only +an exception could have produced. +.Pp +CAUTION: The only reliable ways to discover +whether Underflow has occurred are to test whether +products or quotients lie closer to zero than the +underflow threshold, or to test the Underflow +flag. +(Sums and differences cannot underflow in +IEEE 754; if x \(!= y then x\-y is correct to +full precision and certainly nonzero regardless of +how tiny it may be.) +Products and quotients that +underflow gradually can lose accuracy gradually +without vanishing, so comparing them with zero +(as one might on a VAX) will not reveal the loss. +Fortunately, if a gradually underflowed value is +destined to be added to something bigger than the +underflow threshold, as is almost always the case, +digits lost to gradual underflow will not be missed +because they would have been rounded off anyway. +So gradual underflows are usually +.Em provably +ignorable. +The same cannot be said of underflows flushed to 0. +.El +.Pp +At the option of an implementor conforming to IEEE 754, +other ways to cope with exceptions may be provided: +.Bl -enum +.It +ABORT. +This mechanism classifies an exception in +advance as an incident to be handled by means +traditionally associated with error-handling +statements like "ON ERROR GO TO ...". +Different +languages offer different forms of this statement, +but most share the following characteristics: +.Bl -dash +.It +No means is provided to substitute a value for +the offending operation's result and resume +computation from what may be the middle of an +expression. +An exceptional result is abandoned. +.It +In a subprogram that lacks an error-handling +statement, an exception causes the subprogram to +abort within whatever program called it, and so +on back up the chain of calling subprograms until +an error-handling statement is encountered or the +whole task is aborted and memory is dumped. +.El +.It +STOP. +This mechanism, requiring an interactive +debugging environment, is more for the programmer +than the program. +It classifies an exception in +advance as a symptom of a programmer's error; the +exception suspends execution as near as it can to +the offending operation so that the programmer can +look around to see how it happened. +Quite often +the first several exceptions turn out to be quite +unexceptionable, so the programmer ought ideally +to be able to resume execution after each one as if +execution had not been stopped. +.It +\&... Other ways lie beyond the scope of this document. +.El +.Pp +Ideally, each +elementary function should act as if it were indivisible, or +atomic, in the sense that ... +.Bl -enum +.It +No exception should be signaled that is not deserved by +the data supplied to that function. +.It +Any exception signaled should be identified with that +function rather than with one of its subroutines. +.It +The internal behavior of an atomic function should not +be disrupted when a calling program changes from +one to another of the five or so ways of handling +exceptions listed above, although the definition +of the function may be correlated intentionally +with exception handling. +.El +.Pp +The functions in +.Nm libm +are only approximately atomic. +They signal no inappropriate exception except possibly ... +.Bl -tag -width indent -offset indent -compact +.It Xo +Over/Underflow +.Xc +when a result, if properly computed, might have lain barely within range, and +.It Xo +Inexact in +.Fn cabs , +.Fn cbrt , +.Fn hypot , +.Fn log10 +and +.Fn pow +.Xc +when it happens to be exact, thanks to fortuitous cancellation of errors. +.El +Otherwise, ... +.Bl -tag -width indent -offset indent -compact +.It Xo +Invalid Operation is signaled only when +.Xc +any result but \*(Na would probably be misleading. +.It Xo +Overflow is signaled only when +.Xc +the exact result would be finite but beyond the overflow threshold. +.It Xo +Divide-by-Zero is signaled only when +.Xc +a function takes exactly infinite values at finite operands. +.It Xo +Underflow is signaled only when +.Xc +the exact result would be nonzero but tinier than the underflow threshold. +.It Xo +Inexact is signaled only when +.Xc +greater range or precision would be needed to represent the exact result. +.El +.Sh SEE ALSO +.Xr fenv 3 , +.Xr ieee_test 3 , +.Xr math 3 +.Pp +An explanation of IEEE 754 and its proposed extension p854 +was published in the IEEE magazine MICRO in August 1984 under +the title "A Proposed Radix- and Word-length-independent +Standard for Floating-point Arithmetic" by +.An "W. J. Cody" +et al. +The manuals for Pascal, C and BASIC on the Apple Macintosh +document the features of IEEE 754 pretty well. +Articles in the IEEE magazine COMPUTER vol.\& 14 no.\& 3 (Mar.\& +1981), and in the ACM SIGNUM Newsletter Special Issue of +Oct.\& 1979, may be helpful although they pertain to +superseded drafts of the standard. +.Sh STANDARDS +.St -ieee754 diff --git a/man/ieee_test.3 b/man/ieee_test.3 new file mode 100644 index 0000000..a6e8dc2 --- /dev/null +++ b/man/ieee_test.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/ieee_test.3,v 1.14 2007/01/09 01:02:06 imp Exp $ +.\" +.Dd November 6, 2005 +.Dt IEEE_TEST 3 +.Os +.Sh NAME +.Nm scalb , +.Nm scalbf , +.Nm significand , +.Nm significandf +.Nd IEEE test functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn scalb "double x" "double n" +.Ft float +.Fn scalbf "float x" "float n" +.Ft double +.Fn significand "double x" +.Ft float +.Fn significandf "float x" +.Sh DESCRIPTION +These functions allow users to test conformance to +.St -ieee754 . +Their use is not otherwise recommended. +.Pp +.Fn scalb x n +and +.Fn scalbf x n +return +.Fa x Ns \(**(2** Ns Fa n ) +computed by exponent manipulation. +If +.Fa n +is not an integer, \*(Pm\*(If, or an \*(Na, the result is unspecified. +.Pp +.Fn significand x +and +.Fn significandf x +return +.Fa sig , +where +.Fa x +:= +.Fa sig No \(** 2** Ns Fa n +with 1 \(<= +.Fa sig +< 2. +.Fn significand x +and +.Fn significandf x +are not defined when +.Fa x +is 0, \*(Pm\*(If, or \*(Na. +.Sh SEE ALSO +.Xr ieee 3 , +.Xr math 3 +.Sh STANDARDS +.St -ieee754 diff --git a/man/ilogb.3 b/man/ilogb.3 new file mode 100644 index 0000000..a4c5d12 --- /dev/null +++ b/man/ilogb.3 @@ -0,0 +1,124 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/ilogb.3,v 1.5 2007/12/17 03:53:38 das Exp $ +.\" +.Dd December 16, 2007 +.Dt ILOGB 3 +.Os +.Sh NAME +.Nm ilogb , +.Nm ilogbf , +.Nm ilogbl , +.Nm logb , +.Nm logbf , +.Nm logbl +.Nd extract exponent +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft int +.Fn ilogb "double x" +.Ft int +.Fn ilogbf "float x" +.Ft int +.Fn ilogbl "long double x" +.Ft double +.Fn logb "double x" +.Ft float +.Fn logbf "float x" +.Ft long double +.Fn logbl "long double x" +.Sh DESCRIPTION +.Fn ilogb , +.Fn ilogbf +and +.Fn ilogbl +return +.Fa x Ns 's exponent +in integer format. +.Fn ilogb \*(Pm\*(If +returns +.Dv INT_MAX , +.Fn ilogb \*(Pm\*(Na +returns +.Dv FP_ILOGBNAN , +and +.Fn ilogb 0 +returns +.Dv FP_ILOGB0 . +.Pp +.Fn logb x , +.Fn logbf x , +and +.Fn logbl x +return +.Fa x Ns 's exponent +in floating\-point format with the same precision as +.Fa x . +.Fn logb \*(Pm\*(If +returns +\*(If, and +.Fn logb 0 +returns -\*(If with a division by zero exception. +.Sh SEE ALSO +.Xr frexp 3 , +.Xr ieee 3 , +.Xr math 3 , +.Xr scalbn 3 +.Sh STANDARDS +The +.Fn ilogb , +.Fn ilogbf , +.Fn ilogbl , +.Fn logb , +.Fn logbf , +and +.Fn logbl +routines conform to +.St -isoC-99 . +The latter three +implement the logb function recommended by +.St -ieee754 . +.Sh HISTORY +.Bl -tag -width "Function " -compact +.It Em Function +.Em "First Appeared In" +.It Fn logb +.Bx 4.3 +.It Fn ilogb +.Fx 1.1.5 +.It Fn ilogbf +.Fx 2.0 +.It Fn logbf +.Fx 2.0 +.It Fn ilogbl +.Fx 5.4 +.It Fn logbl +.Fx 8.0 +.El diff --git a/man/j0.3 b/man/j0.3 new file mode 100644 index 0000000..f280e7d --- /dev/null +++ b/man/j0.3 @@ -0,0 +1,169 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)j0.3 6.7 (Berkeley) 4/19/91 +.\" $FreeBSD: src/lib/msun/man/j0.3,v 1.15 2008/02/18 19:02:49 das Exp $ +.\" +.Dd February 18, 2008 +.Dt J0 3 +.Os +.Sh NAME +.Nm j0 , +.Nm j0f , +.Nm j1 , +.Nm j1f , +.Nm jn , +.Nm jnf , +.Nm y0 , +.Nm y0f , +.Nm y1 , +.Nm y1f , +.Nm yn , +.Nm ynf +.Nd Bessel functions of first and second kind +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn j0 "double x" +.Ft float +.Fn j0f "float x" +.Ft double +.Fn j1 "double x" +.Ft float +.Fn j1f "float x" +.Ft double +.Fn jn "int n" "double x" +.Ft float +.Fn jnf "int n" "float x" +.Ft double +.Fn y0 "double x" +.Ft float +.Fn y0f "float x" +.Ft double +.Fn y1 "double x" +.Ft float +.Fn y1f "float x" +.Ft double +.Fn yn "int n" "double x" +.Ft float +.Fn ynf "int n" "float x" +.Sh DESCRIPTION +The functions +.Fn j0 , +.Fn j0f , +.Fn j1 +and +.Fn j1f +compute the +.Em Bessel function of the first kind of the order +0 and the +.Em order +1, respectively, +for the +real value +.Fa x ; +the functions +.Fn jn +and +.Fn jnf +compute the +.Em Bessel function of the first kind of the integer +.Em order +.Fa n +for the real value +.Fa x . +.Pp +The functions +.Fn y0 , +.Fn y0f , +.Fn y1 , +and +.Fn y1f +compute the linearly independent +.Em Bessel function of the second kind of the order +0 and the +.Em order +1, respectively, +for the +positive +.Em real +value +.Fa x ; +the functions +.Fn yn +and +.Fn ynf +compute the +.Em Bessel function of the second kind for the integer +.Em order +.Fa n +for the positive +.Em real +value +.Fa x . +.Sh RETURN VALUES +These routines return values of their respective Bessel functions. +For large positive inputs, they may underflow and return \*(Pm0. +.Pp +The following applies to +.Fn y0 , +.Fn y0f , +.Fn y1 , +.Fn y1f , +.Fn yn , +and +.Fn ynf . +If +.Fa x +is negative, these routines will generate an invalid exception and +return \*(Na. +If +.Fa x +is 0 or a sufficiently small positive number, these routines +will generate an overflow exception and return -\*(If. +.Sh SEE ALSO +.Xr math 3 +.Sh STANDARDS +The +.Fn j0 , +.Fn j1 , +.Fn jn , +.Fn y0 , +.Fn y1 , +and +.Fn yn +functions conform to +.St -p1003.1-2001 . +The +.Ft float +versions are extensions. +.Sh HISTORY +This set of functions +appeared in +.At v7 . diff --git a/man/lgamma.3 b/man/lgamma.3 new file mode 100644 index 0000000..54677f5 --- /dev/null +++ b/man/lgamma.3 @@ -0,0 +1,189 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)lgamma.3 6.6 (Berkeley) 12/3/92 +.\" $FreeBSD: src/lib/msun/man/lgamma.3,v 1.24 2008/02/18 17:27:11 das Exp $ +.\" +.Dd January 14, 2005 +.Dt LGAMMA 3 +.Os +.Sh NAME +.Nm lgamma , +.Nm lgamma_r , +.Nm lgammaf , +.Nm lgammaf_r , +.Nm gamma , +.Nm gamma_r , +.Nm gammaf , +.Nm gammaf_r , +.Nm tgamma , +.Nm tgammaf +.Nd log gamma functions, gamma function +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft extern int +.Fa signgam ; +.sp +.Ft double +.Fn lgamma "double x" +.Ft double +.Fn lgamma_r "double x" "int *signgamp" +.Ft float +.Fn lgammaf "float x" +.Ft float +.Fn lgammaf_r "float x" "int *signgamp" +.Ft double +.Fn gamma "double x" +.Ft double +.Fn gamma_r "double x" "int *signgamp" +.Ft float +.Fn gammaf "float x" +.Ft float +.Fn gammaf_r "float x" "int *signgamp" +.Ft double +.Fn tgamma "double x" +.Ft float +.Fn tgammaf "float x" +.Sh DESCRIPTION +.Fn lgamma x +and +.Fn lgammaf x +.if t \{\ +return ln\||\(*G(x)| where +.Bd -unfilled -offset indent +\(*G(x) = \(is\d\s8\z0\s10\u\u\s8\(if\s10\d t\u\s8x\-1\s10\d e\u\s8\-t\s10\d dt for x > 0 and +\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px)) for x < 1. +.Ed +.\} +.if n \ +return ln\||\(*G(x)|. +The external integer +.Fa signgam +returns the sign of \(*G(x). +.Pp +.Fn lgamma_r x signgamp +and +.Fn lgammaf_r x signgamp +provide the same functionality as +.Fn lgamma x +and +.Fn lgammaf x +but the caller must provide an integer to store the sign of \(*G(x). +.Pp +The +.Fn tgamma x +and +.Fn tgammaf x +functions return \(*G(x), with no effect on +.Fa signgam . +.Pp +.Fn gamma , +.Fn gammaf , +.Fn gamma_r , +and +.Fn gammaf_r +are deprecated aliases for +.Fn lgamma , +.Fn lgammaf , +.Fn lgamma_r , +and +.Fn lgammaf_r , +respectively. +.Sh IDIOSYNCRASIES +Do not use the expression +.Dq Li signgam\(**exp(lgamma(x)) +to compute g := \(*G(x). +Instead use a program like this (in C): +.Bd -literal -offset indent +lg = lgamma(x); g = signgam\(**exp(lg); +.Ed +.Pp +Only after +.Fn lgamma +or +.Fn lgammaf +has returned can signgam be correct. +.Pp +For arguments in its range, +.Fn tgamma +is preferred, as for positive arguments +it is accurate to within one unit in the last place. +Exponentiation of +.Fn lgamma +will lose up to 10 significant bits. +.Sh RETURN VALUES +.Fn gamma , +.Fn gamma_r , +.Fn gammaf , +.Fn gammaf_r , +.Fn lgamma , +.Fn lgamma_r , +.Fn lgammaf , +and +.Fn lgammaf_r +return appropriate values unless an argument is out of range. +Overflow will occur for sufficiently large positive values, and +non-positive integers. +For large non-integer negative values, +.Fn tgamma +will underflow. +.Sh SEE ALSO +.Xr math 3 +.Sh STANDARDS +The +.Fn lgamma , +.Fn lgammaf , +.Fn tgamma , +and +.Fn tgammaf +functions are expected to conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn lgamma +function appeared in +.Bx 4.3 . +The +.Fn gamma +function appeared in +.Bx 4.4 +as a function which computed \(*G(x). +This version was used in +.Fx 1.1 . +The name +.Fn gamma +was originally dedicated to the +.Fn lgamma +function, +and that usage was restored by switching to Sun's fdlibm in +.Fx 1.1.5 . +The +.Fn tgamma +function appeared in +.Fx 5.0 . diff --git a/man/log.3 b/man/log.3 new file mode 100644 index 0000000..8143963 --- /dev/null +++ b/man/log.3 @@ -0,0 +1,118 @@ +.\" Copyright (c) 2008-2010 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/log.3,v 1.2 2010/12/05 22:11:22 das Exp $ +.\" +.Dd December 5, 2010 +.Dt LOG 3 +.Os +.Sh NAME +.Nm log , +.Nm logf , +.Nm logl , +.Nm log10 , +.Nm log10f , +.Nm log2 , +.Nm log2f , +.Nm log1p , +.Nm log1pf +.Nd logarithm functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn log "double x" +.Ft float +.Fn logf "float x" +.Ft double +.Fn log10 "double x" +.Ft float +.Fn log10f "float x" +.Ft double +.Fn log2 "double x" +.Ft float +.Fn log2f "float x" +.Ft double +.Fn log1p "double x" +.Ft float +.Fn log1pf "float x" +.Sh DESCRIPTION +The +.Fn log +and +.Fn logf +functions compute the natural logarithm of +.Fa x . +.Pp +The +.Fn log10 +and +.Fn log10f +functions compute the logarithm base 10 of +.Fa x , +while +.Fn log2 +and +.Fn log2f +compute the logarithm base 2 of +.Fa x . +.Pp +The +.Fn log1p +and +.Fn log1pf +functions compute the natural logarithm of +.No "1 + x" . +Computing the natural logarithm as +.Li log1p(x) +is more accurate than computing it as +.Li log(1 + x) +when +.Fa x +is close to zero. +.Sh RETURN VALUES +These functions return the requested logarithm; the logarithm of 1 is +0. +An attempt to take the logarithm of \*(Pm0 results in a divide-by-zero +exception, and -\*(If is returned. +Otherwise, attempting to take the logarithm of a negative number +results in an invalid exception and a return value of \*(Na. +.Sh SEE ALSO +.Xr exp 3 , +.Xr ilogb 3 , +.Xr math 3 , +.Xr pow 3 +.Sh STANDARDS +The +.Fn log , +.Fn logf , +.Fn log10 , +.Fn log10f , +.Fn log2 , +.Fn log2f , +.Fn log1p , +and +.Fn log1pf +functions conform to +.St -isoC-99 . diff --git a/man/lrint.3 b/man/lrint.3 new file mode 100644 index 0000000..f896d52 --- /dev/null +++ b/man/lrint.3 @@ -0,0 +1,104 @@ +.\" Copyright (c) 2005 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/lrint.3,v 1.3 2008/01/14 02:12:07 das Exp $ +.\" +.Dd January 13, 2008 +.Dt LRINT 3 +.Os +.Sh NAME +.Nm llrint , +.Nm llrintf , +.Nm llrintl , +.Nm lrint , +.Nm lrintf , +.Nm lrintl +.Nd "convert to integer" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft "long long" +.Fn llrint "double x" +.Ft "long long" +.Fn llrintf "float x" +.Ft "long long" +.Fn llrintl "long double x" +.Ft long +.Fn lrint "double x" +.Ft long +.Fn lrintf "float x" +.Ft long +.Fn lrintl "long double x" +.Sh DESCRIPTION +The +.Fn lrint +function returns the integer nearest to its argument +.Fa x +according to the current rounding mode. +If the rounded result is too large to be represented as a +.Vt long +value, an invalid exception is raised and the return value is undefined. +Otherwise, if +.Fa x +is not an integer, +.Fn lrint +raises an inexact exception. +When the rounded result is representable as a +.Vt long , +the expression +.Fn lrint x +is equivalent to +.Po Vt long Pc Ns Fn rint x +(although the former may be more efficient). +.Pp +The +.Fn llrint , +.Fn llrintf , +.Fn llrintl , +.Fn lrintf , +and +.Fn lrintl +functions differ from +.Fn lrint +only in their input and output types. +.Sh SEE ALSO +.Xr lround 3 , +.Xr math 3 , +.Xr rint 3 , +.Xr round 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn llrint , +.Fn llrintf , +.Fn lrint , +and +.Fn lrintf +routines first appeared in +.Fx 5.4 . +The long double variants were introduced in +.Fx 8.0 . diff --git a/man/lround.3 b/man/lround.3 new file mode 100644 index 0000000..d3e53c2 --- /dev/null +++ b/man/lround.3 @@ -0,0 +1,112 @@ +.\" Copyright (c) 2005 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/lround.3,v 1.4 2005/06/15 19:04:04 ru Exp $ +.\" +.Dd April 7, 2005 +.Dt LROUND 3 +.Os +.Sh NAME +.Nm llround , +.Nm llroundf , +.Nm llroundl , +.Nm lround , +.Nm lroundf , +.Nm lroundl +.Nd "convert to nearest integral value" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft "long long" +.Fn llround "double x" +.Ft "long long" +.Fn llroundf "float x" +.Ft "long long" +.Fn llroundl "long double x" +.Ft long +.Fn lround "double x" +.Ft long +.Fn lroundf "float x" +.Ft long +.Fn lroundl "long double x" +.Sh DESCRIPTION +The +.Fn lround +function returns the integer nearest to its argument +.Fa x , +rounding away from zero in halfway cases. +If the rounded result is too large to be represented as a +.Vt long +value, an invalid exception is raised and the return value is undefined. +Otherwise, if +.Fa x +is not an integer, +.Fn lround +may raise an inexact exception. +When the rounded result is representable as a +.Vt long , +the expression +.Fn lround x +is equivalent to +.Po Vt long Pc Ns Fn round x +(although the former may be more efficient). +.Pp +The +.Fn llround , +.Fn llroundf , +.Fn llroundl , +.Fn lroundf +and +.Fn lroundl +functions differ from +.Fn lround +only in their input and output types. +.Sh SEE ALSO +.Xr lrint 3 , +.Xr math 3 , +.Xr rint 3 , +.Xr round 3 +.Sh STANDARDS +The +.Fn llround , +.Fn llroundf , +.Fn llroundl , +.Fn lround , +.Fn lroundf , +and +.Fn lroundl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Vt float +and +.Vt double +versions of these routines first appeared in +.Fx 5.4 . +The +.Vt "long double" +versions appeared in +.Fx 6.0 . diff --git a/man/math.3 b/man/math.3 new file mode 100644 index 0000000..5ca2091 --- /dev/null +++ b/man/math.3 @@ -0,0 +1,254 @@ +.\" Copyright (c) 1985 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/math.3,v 1.34 2011/10/17 06:10:32 das Exp $ +.\" +.Dd December 5, 2010 +.Dt MATH 3 +.Os +.Sh NAME +.Nm math +.Nd "floating-point mathematical library" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Sh DESCRIPTION +The math library includes the following components: +.Bl -column "" "polymorphic (type-generic) versions of functions" -compact -offset indent +.In math.h Ta basic routines and real-valued functions +.In complex.h Ta complex number support +.In tgmath.h Ta polymorphic (type-generic) versions of functions +.In fenv.h Ta routines to control rounding and exceptions +.El +The rest of this manual page describes the functions provided by +.In math.h . +Please consult +.Xr complex 3 , +.Xr tgmath 3 , +and +.Xr fenv 3 +for information on the other components. +.Sh "LIST OF FUNCTIONS" +Each of the following +.Vt double +functions has a +.Vt float +counterpart with an +.Ql f +appended to the name and a +.Vt "long double" +counterpart with an +.Ql l +appended. +As an example, the +.Vt float +and +.Vt "long double" +counterparts of +.Ft double +.Fn acos "double x" +are +.Ft float +.Fn acosf "float x" +and +.Ft "long double" +.Fn acosl "long double x" , +respectively. +The classification macros and silent order predicates are type generic and +should not be suffixed with +.Ql f +or +.Ql l . +.de Cl +.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" +.Em "Name Description" +.. +.Ss Algebraic Functions +.Cl +cbrt cube root +fma fused multiply-add +hypot Euclidean distance +sqrt square root +.El +.Ss Classification Macros +.Cl +fpclassify classify a floating-point value +isfinite determine whether a value is finite +isinf determine whether a value is infinite +isnan determine whether a value is \*(Na +isnormal determine whether a value is normalized +.El +.Ss Exponent Manipulation Functions +.Cl +frexp extract exponent and mantissa +ilogb extract exponent +ldexp multiply by power of 2 +logb extract exponent +scalbln adjust exponent +scalbn adjust exponent +.El +.Ss Extremum- and Sign-Related Functions +.Cl +copysign copy sign bit +fabs absolute value +fdim positive difference +fmax maximum function +fmin minimum function +signbit extract sign bit +.El +.Ss Not a Number Functions +.Cl +nan generate a quiet \*(Na +.El +.Ss Residue and Rounding Functions +.Cl +ceil integer no less than +floor integer no greater than +fmod positive remainder +llrint round to integer in fixed-point format +llround round to nearest integer in fixed-point format +lrint round to integer in fixed-point format +lround round to nearest integer in fixed-point format +modf extract integer and fractional parts +nearbyint round to integer (silent) +nextafter next representable value +nexttoward next representable value +remainder remainder +remquo remainder with partial quotient +rint round to integer +round round to nearest integer +trunc integer no greater in magnitude than +.El +.Pp +The +.Fn ceil , +.Fn floor , +.Fn llround , +.Fn lround , +.Fn round , +and +.Fn trunc +functions round in predetermined directions, whereas +.Fn llrint , +.Fn lrint , +and +.Fn rint +round according to the current (dynamic) rounding mode. +For more information on controlling the dynamic rounding mode, see +.Xr fenv 3 +and +.Xr fesetround 3 . +.Ss Silent Order Predicates +.Cl +isgreater greater than relation +isgreaterequal greater than or equal to relation +isless less than relation +islessequal less than or equal to relation +islessgreater less than or greater than relation +isunordered unordered relation +.El +.Ss Transcendental Functions +.Cl +acos inverse cosine +acosh inverse hyperbolic cosine +asin inverse sine +asinh inverse hyperbolic sine +atan inverse tangent +atanh inverse hyperbolic tangent +atan2 atan(y/x); complex argument +cos cosine +cosh hyperbolic cosine +erf error function +erfc complementary error function +exp exponential base e +exp2 exponential base 2 +expm1 exp(x)\-1 +j0 Bessel function of the first kind of the order 0 +j1 Bessel function of the first kind of the order 1 +jn Bessel function of the first kind of the order n +lgamma log gamma function +log natural logarithm +log10 logarithm to base 10 +log1p log(1+x) +log2 base 2 logarithm +pow exponential x**y +sin trigonometric function +sinh hyperbolic function +tan trigonometric function +tanh hyperbolic function +tgamma gamma function +y0 Bessel function of the second kind of the order 0 +y1 Bessel function of the second kind of the order 1 +yn Bessel function of the second kind of the order n +.El +.Pp +The routines +in this section might not produce a result that is correctly rounded, +so reproducible results cannot be guaranteed across platforms. +For most of these functions, however, incorrect rounding occurs +rarely, and then only in very-close-to-halfway cases. +.Sh SEE ALSO +.Xr complex 3 , +.Xr fenv 3 , +.Xr ieee 3 , +.Xr tgmath 3 +.Sh HISTORY +A math library with many of the present functions appeared in +.At v7 . +The library was substantially rewritten for +.Bx 4.3 +to provide +better accuracy and speed on machines supporting either VAX +or IEEE 754 floating-point. +Most of this library was replaced with FDLIBM, developed at Sun +Microsystems, in +.Fx 1.1.5 . +Additional routines, including ones for +.Vt float +and +.Vt long double +values, were written for or imported into subsequent versions of FreeBSD. +.Sh BUGS +Some of the +.Vt "long double" +math functions in +.St -isoC-99 +are not available. +.Pp +Many of the routines to compute transcendental functions produce +inaccurate results in other than the default rounding mode. +.Pp +On the i386 platform, trigonometric argument reduction is not +performed accurately for huge arguments, resulting in +large errors +for such arguments to +.Fn cos , +.Fn sin , +and +.Fn tan . diff --git a/man/nan.3 b/man/nan.3 new file mode 100644 index 0000000..bfbc0eb --- /dev/null +++ b/man/nan.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 2007 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/nan.3,v 1.1 2007/12/16 21:19:28 das Exp $ +.\" +.Dd December 16, 2007 +.Dt NAN 3 +.Os +.Sh NAME +.Nm nan , +.Nm nanf , +.Nm nanl +.Nd quiet \*(Nas +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn nan "const char *s" +.Ft float +.Fn nanf "const char *s" +.Ft long double +.Fn nanl "const char *s" +.Sh DESCRIPTION +The +.Dv NAN +macro expands to a quiet \*(Na (Not A Number). +Similarly, each of the +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions generate a quiet \*(Na value without raising an invalid exception. +The argument +.Fa s +should point to either an empty string or a hexadecimal representation +of a non-negative integer (e.g., "0x1234".) +In the latter case, the integer is encoded in some free bits in the +representation of the \*(Na, which sometimes store +machine-specific information about why a particular \*(Na was generated. +There are 22 such bits available for +.Vt float +variables, 51 bits for +.Vt double +variables, and at least 51 bits for a +.Vt long double . +If +.Fa s +is improperly formatted or represents an integer that is too large, +then the particular encoding of the quiet \*(Na that is returned +is indeterminate. +.Sh COMPATIBILITY +Calling these functions with a non-empty string isn't portable. +Another operating system may translate the string into a different +\*(Na encoding, and furthermore, the meaning of a given \*(Na encoding +varies across machine architectures. +If you understood the innards of a particular platform well enough to +know what string to use, then you would have no need for these functions +anyway, so don't use them. +Use the +.Dv NAN +macro instead. +.Sh SEE ALSO +.Xr fenv 3 , +.Xr ieee 3 , +.Xr isnan 3 , +.Xr math 3 , +.Xr strtod 3 +.Sh STANDARDS +The +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions and the +.Dv NAN +macro conform to +.St -isoC-99 . diff --git a/man/nextafter.3 b/man/nextafter.3 new file mode 100644 index 0000000..830d8f6 --- /dev/null +++ b/man/nextafter.3 @@ -0,0 +1,96 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/nextafter.3,v 1.3 2007/01/09 01:02:06 imp Exp $ +.\" +.Dd May 4, 2005 +.Dt NEXTAFTER 3 +.Os +.Sh NAME +.Nm nextafter , +.Nm nextafterf , +.Nm nextafterl , +.Nm nexttoward , +.Nm nexttowardf , +.Nm nexttowardl +.Nd next representable value +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn nextafter "double x" "double y" +.Ft float +.Fn nextafterf "float x" "float y" +.Ft long double +.Fn nextafterl "long double x" "long double y" +.Ft double +.Fn nexttoward "double x" "long double y" +.Ft float +.Fn nexttowardf "float x" "long double y" +.Ft long double +.Fn nexttowardl "long double x" "long double y" +.Sh DESCRIPTION +These functions +return the next machine representable number from +.Fa x +in direction +.Fa y . +.Sh SEE ALSO +.Xr ieee 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn nextafter , +.Fn nextafterf , +.Fn nextafterl , +.Fn nexttoward , +.Fn nexttowardf , +and +.Fn nexttowardl +routines conform to +.St -isoC-99 . +They implement the Nextafter function recommended by +.St -ieee754 , +with the extension that +.Fn nextafter +0.0, -0.0 +returns +.Li -0.0 , +and +.Fn nextafter -0.0, +0.0 +returns +.Li +0.0 . +.Sh HISTORY +The +.Fn nextafter +function appeared in +.Bx 4.3 , +and +.Fn nextafterf +appeared in +.Fx 2.0 . diff --git a/man/remainder.3 b/man/remainder.3 new file mode 100644 index 0000000..15aa0da --- /dev/null +++ b/man/remainder.3 @@ -0,0 +1,159 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/remainder.3,v 1.7 2010/06/02 10:20:38 uqs Exp $ +.\" +.Dd March 30, 2008 +.Dt REMAINDER 3 +.Os +.Sh NAME +.Nm remainder , +.Nm remainderf , +.Nm remainderl , +.Nm remquo , +.Nm remquof , +.Nm remquol +.Nd minimal residue functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn remainder "double x" "double y" +.Ft float +.Fn remainderf "float x" "float y" +.Ft long double +.Fn remainderl "long double x" "long double y" +.Ft double +.Fn remquo "double x" "double y" "int *quo" +.Ft float +.Fn remquof "float x" "float y" "int *quo" +.Ft long double +.Fn remquol "long double x" "long double y" "int *quo" +.Sh DESCRIPTION +.Fn remainder , +.Fn remainderf , +.Fn remainderl , +.Fn remquo , +.Fn remquof , +and +.Fn remquol +return the remainder +.Fa r +:= +.Fa x +\- +.Fa n\(**y +where +.Fa n +is the integer nearest the exact value of +.Bk -words +.Fa x Ns / Ns Fa y ; +.Ek +moreover if +.Pf \*(Ba Fa n +\- +.Sm off +.Fa x No / Fa y No \*(Ba +.Sm on += +1/2 +then +.Fa n +is even. +Consequently +the remainder is computed exactly and +.Sm off +.Pf \*(Ba Fa r No \*(Ba +.Sm on +\*(Le +.Sm off +.Pf \*(Ba Fa y No \*(Ba/2 . +.Sm on +But attempting to take the remainder when +.Fa y +is 0 or +.Fa x +is \*(Pm\*(If is an invalid operation that produces a \*(Na. +.Pp +The +.Fn remquo , +.Fn remquof , +and +.Fn remquol +functions also store the last +.Va k +bits of +.Fa n +in the location pointed to by +.Fa quo , +provided that +.Fa n +exists. +The number of bits +.Va k +is platform-specific, but is guaranteed to be at least 3. +.Sh SEE ALSO +.Xr fmod 3 , +.Xr ieee 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn remainder , +.Fn remainderf , +.Fn remainderl , +.Fn remquo , +.Fn remquof , +and +.Fn remquol +routines conform to +.St -isoC-99 . +The remainder is as defined in +.St -ieee754 . +.Sh HISTORY +The +.Fn remainder +and +.Fn remainderf +functions appeared in +.Bx 4.3 +and +.Fx 2.0 , +respectively. +The +.Fn remquo +and +.Fn remquof +functions were added in +.Fx 6.0 , +and +.Fn remainderl +and +.Fn remquol +were added in +.Fx 8.0 . diff --git a/man/rint.3 b/man/rint.3 new file mode 100644 index 0000000..febff19 --- /dev/null +++ b/man/rint.3 @@ -0,0 +1,103 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)rint.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/rint.3,v 1.13 2008/01/14 02:12:07 das Exp $ +.\" +.Dd January 13, 2008 +.Dt RINT 3 +.Os +.Sh NAME +.Nm nearbyint , +.Nm nearbyintf , +.Nm nearbyintl , +.Nm rint , +.Nm rintf , +.Nm rintl +.Nd round to integral value in floating-point format +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn nearbyint "double x" +.Ft float +.Fn nearbyintf "float x" +.Ft long double +.Fn nearbyintl "long double x" +.Ft double +.Fn rint "double x" +.Ft float +.Fn rintf "float x" +.Ft long double +.Fn rintl "long double x" +.Sh DESCRIPTION +The +.Fn rint , +.Fn rintf , +and +.Fn rintl +functions return the integral value nearest to +.Fa x +according to the prevailing rounding mode. +These functions raise an inexact exception when the original argument +is not an exact integer. +.Pp +The +.Fn nearbyint , +.Fn nearbyintf , +and +.Fn nearbyintl +functions perform the same operation, except that they do not raise +an inexact exception. +.Sh SEE ALSO +.Xr abs 3 , +.Xr ceil 3 , +.Xr fabs 3 , +.Xr fenv 3 , +.Xr floor 3 , +.Xr ieee 3 , +.Xr lrint 3 , +.Xr lround 3 , +.Xr math 3 , +.Xr round 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . +.Sh HISTORY +A +.Fn rint +function appeared in +.At v6 . +The +.Fn nearbyint +and +.Fn nearbyintf +functions appeared in +.Fx 5.3 , +and the long double variants were first available in +.Fx 8.0 . diff --git a/man/round.3 b/man/round.3 new file mode 100644 index 0000000..b077d77 --- /dev/null +++ b/man/round.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 2003, Steven G. Kargl +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/round.3,v 1.6 2005/06/15 19:04:04 ru Exp $ +.\" +.Dd April 7, 2005 +.Dt ROUND 3 +.Os +.Sh NAME +.Nm round , +.Nm roundf , +.Nm roundl +.Nd round to nearest integral value +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn round "double x" +.Ft float +.Fn roundf "float x" +.Ft "long double" +.Fn roundl "long double x" +.Sh DESCRIPTION +The +.Fn round , +.Fn roundf , +and +.Fn roundl +functions return the nearest integral value to +.Fa x ; +if +.Fa x +lies halfway between two integral values, then these +functions return the integral value with the larger +absolute value (i.e., they round away from zero). +.Sh SEE ALSO +.Xr ceil 3 , +.Xr floor 3 , +.Xr ieee 3 , +.Xr lrint 3 , +.Xr lround 3 , +.Xr math 3 , +.Xr rint 3 , +.Xr trunc 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn round +and +.Fn roundf +functions appeared in +.Fx 5.3 . +The +.Fn roundl +function appeared in +.Fx 6.0 . diff --git a/man/scalbn.3 b/man/scalbn.3 new file mode 100644 index 0000000..e091da7 --- /dev/null +++ b/man/scalbn.3 @@ -0,0 +1,91 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/scalbn.3,v 1.4 2007/01/09 01:02:06 imp Exp $ +.\" +.Dd March 4, 2005 +.Dt SCALBN 3 +.Os +.Sh NAME +.Nm scalbln , +.Nm scalblnf , +.Nm scalblnl , +.Nm scalbn , +.Nm scalbnf , +.Nm scalbnl +.Nd adjust exponent +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn scalbln "double x" "long n" +.Ft float +.Fn scalblnf "float x" "long n" +.Ft long double +.Fn scalblnl "long double x" "long n" +.Ft double +.Fn scalbn "double x" "int n" +.Ft float +.Fn scalbnf "float x" "int n" +.Ft long double +.Fn scalbnl "long double x" "int n" +.Sh DESCRIPTION +These routines return +.Fa x Ns \(**(2** Ns Fa n ) +computed by exponent manipulation. +.Sh SEE ALSO +.Xr ieee 3 , +.Xr math 3 +.Sh STANDARDS +These routines conform to +.St -isoC-99 , +and they implement the Scalb function recommended by +.St -ieee754 . +.Sh HISTORY +The +.Fn scalbn +and +.Fn scalbnf +functions appeared in +.Bx 4.3 +and +.Fx 2.0 , +respectively. +The +.Fn scalbln +and +.Fn scalblnf +functions first appeared in +.Fx 5.3 , +and +.Fn scalblnl +and +.Fn scalbln +in +.Fx 6.0 . diff --git a/man/signbit.3 b/man/signbit.3 new file mode 100644 index 0000000..b749671 --- /dev/null +++ b/man/signbit.3 @@ -0,0 +1,57 @@ +.\" Copyright (c) 2003 Mike Barcroft +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/signbit.3,v 1.1 2004/07/19 08:16:10 das Exp $ +.\" +.Dd July 18, 2004 +.Dt SIGNBIT 3 +.Os +.Sh NAME +.Nm signbit +.Nd "determine whether a floating-point number's sign is negative" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft int +.Fn signbit "real-floating x" +.Sh DESCRIPTION +The +.Fn signbit +macro takes an argument of +.Fa x +and returns non-zero if the value of its sign is negative, otherwise 0. +.Sh SEE ALSO +.Xr fpclassify 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn signbit +macro conforms to +.St -isoC-99 . +.Sh HISTORY +The +.Fn signbit +macro was added in +.Fx 5.1 . diff --git a/man/sin.3 b/man/sin.3 new file mode 100644 index 0000000..ac26c30 --- /dev/null +++ b/man/sin.3 @@ -0,0 +1,82 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" @(#)sin.3 6.7 (Berkeley) 4/19/91 +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)sin.3 6.7 (Berkeley) 4/19/91 +.\" $FreeBSD: src/lib/msun/man/sin.3,v 1.12 2011/10/17 05:41:03 das Exp $ +.\" +.Dd January 24, 2008 +.Dt SIN 3 +.Os +.Sh NAME +.Nm sin , +.Nm sinf , +.Nm sinl +.Nd sine functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn sin "double x" +.Ft float +.Fn sinf "float x" +.Ft long double +.Fn sinl "long double x" +.Sh DESCRIPTION +The +.Fn sin , +.Fn sinf , +and +.Fn sinl +functions compute the sine of +.Fa x +(measured in radians). +A large magnitude argument may yield a result with little +or no significance. +.Sh RETURN VALUES +The +.Fn sin , +.Fn sinf , +and +.Fn sinl +functions return the sine value. +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr csin 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr math 3 , +.Xr sinh 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/sinh.3 b/man/sinh.3 new file mode 100644 index 0000000..21923e5 --- /dev/null +++ b/man/sinh.3 @@ -0,0 +1,68 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)sinh.3 6.6 (Berkeley) 4/19/91 +.\" $FreeBSD: src/lib/msun/man/sinh.3,v 1.14 2011/10/17 05:41:03 das Exp $ +.Dd January 14, 2005 +.Dt SINH 3 +.Os +.Sh NAME +.Nm sinh , +.Nm sinhf +.Nd hyperbolic sine function +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn sinh "double x" +.Ft float +.Fn sinhf "float x" +.Sh DESCRIPTION +The +.Fn sinh +and the +.Fn sinhf +functions compute the hyperbolic sine of +.Fa x . +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr csinh 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr tan 3 , +.Xr tanh 3 +.Sh STANDARDS +The +.Fn sinh +function conforms to +.St -isoC . diff --git a/man/sqrt.3 b/man/sqrt.3 new file mode 100644 index 0000000..2b17b76 --- /dev/null +++ b/man/sqrt.3 @@ -0,0 +1,122 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)sqrt.3 6.4 (Berkeley) 5/6/91 +.\" $FreeBSD: src/lib/msun/man/sqrt.3,v 1.16 2011/03/12 16:50:39 kargl Exp $ +.\" +.Dd March 5, 2011 +.Dt SQRT 3 +.Os +.Sh NAME +.Nm cbrt , +.Nm cbrtf , +.Nm cbrtl , +.Nm sqrt , +.Nm sqrtf , +.Nm sqrtl +.Nd cube root and square root functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn cbrt "double x" +.Ft float +.Fn cbrtf "float x" +.Ft long double +.Fn cbrtl "long double x" +.Ft double +.Fn sqrt "double x" +.Ft float +.Fn sqrtf "float x" +.Ft long double +.Fn sqrtl "long double x" +.Sh DESCRIPTION +The +.Fn cbrt , +.Fn cbrtf , +and +.Fn cbrtl +functions compute +the cube root of +.Ar x . +.Pp +The +.Fn sqrt , +.Fn sqrtf , +and +.Fn sqrtl +functions compute the +non-negative square root of +.Ar x . +.Sh RETURN VALUES +The +.Fn cbrt , +.Fn cbrtf , +and +.Fn cbrtl +functions return the requested cube root. +The +.Fn sqrt , +.Fn sqrtf , +and +.Fn sqrtl +functions return the requested square root +unless an error occurs. +An attempt to take the +.Fn sqrt +of negative +.Fa x +raises an invalid exception and causes an \*(Na to be returned +(except that the square root of -0 is valid and equal to -0.) +.Sh SEE ALSO +.Xr fenv 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn cbrt , +.Fn cbrtf , +.Fn cbrtl , +.Fn sqrt , +.Fn sqrtf , +and +.Fn sqrtl +functions conform to +.St -isoC-99 . +.Sh HISTORY +The +.Fn cbrt +function appeared in +.Bx 4.3 . +The +.Fn sqrtl +function appeared in +.Fx 8.0 . +The +.Fn cbrtl +function appeared in +.Fx 9.0 . diff --git a/man/tan.3 b/man/tan.3 new file mode 100644 index 0000000..69b02b9 --- /dev/null +++ b/man/tan.3 @@ -0,0 +1,83 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)tan.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/tan.3,v 1.12 2011/10/17 05:41:03 das Exp $ +.\" +.Dd January 24, 2008 +.Dt TAN 3 +.Os +.Sh NAME +.Nm tan , +.Nm tanf , +.Nm tanl +.Nd tangent functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn tan "double x" +.Ft float +.Fn tanf "float x" +.Ft long double +.Fn tanl "long double x" +.Sh DESCRIPTION +The +.Fn tan , +.Fn tanf , +and +.Fn tanl +functions compute the tangent of +.Fa x +(measured in radians). +A large magnitude argument may yield a result +with little or no significance. +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn tan , +.Fn tanf , +and +.Fn tanl +functions return the tangent value. +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr ctan 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tanh 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/man/tanh.3 b/man/tanh.3 new file mode 100644 index 0000000..4ee3920 --- /dev/null +++ b/man/tanh.3 @@ -0,0 +1,77 @@ +.\" Copyright (c) 1991 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)tanh.3 5.1 (Berkeley) 5/2/91 +.\" $FreeBSD: src/lib/msun/man/tanh.3,v 1.12 2011/10/17 05:41:03 das Exp $ +.\" +.Dd May 2, 1991 +.Dt TANH 3 +.Os +.Sh NAME +.Nm tanh , +.Nm tanhf +.Nd hyperbolic tangent functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn tanh "double x" +.Ft float +.Fn tanhf "float x" +.Sh DESCRIPTION +The +.Fn tanh +and the +.Fn tanhf +functions compute the hyperbolic tangent of +.Fa x . +For a discussion of error due to roundoff, see +.Xr math 3 . +.Sh RETURN VALUES +The +.Fn tanh +and the +.Fn tanhf +functions return the hyperbolic tangent value. +.Sh SEE ALSO +.Xr acos 3 , +.Xr asin 3 , +.Xr atan 3 , +.Xr atan2 3 , +.Xr cos 3 , +.Xr cosh 3 , +.Xr ctanh 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr sinh 3 , +.Xr tan 3 +.Sh STANDARDS +The +.Fn tanh +function conforms to +.St -isoC . diff --git a/man/trunc.3 b/man/trunc.3 new file mode 100644 index 0000000..cb6c26f --- /dev/null +++ b/man/trunc.3 @@ -0,0 +1,80 @@ +.\" Copyright (c) 2004, 2005 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/msun/man/trunc.3,v 1.3 2005/06/15 19:04:04 ru Exp $ +.\" +.Dd April 16, 2005 +.Dt TRUNC 3 +.Os +.Sh NAME +.Nm trunc , +.Nm truncf , +.Nm truncl +.Nd nearest integral value with magnitude less than or equal to |x| +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn trunc "double x" +.Ft float +.Fn truncf "float x" +.Ft "long double" +.Fn truncl "long double x" +.Sh DESCRIPTION +The +.Fn trunc , +.Fn truncf , +and +.Fn truncl +functions return the nearest integral value with magnitude less than +or equal to +.Pf | Fa x Ns | . +They are equivalent to +.Fn rint , +.Fn rintf , +and +.Fn rintl , +respectively, in the +.Dv FE_TOWARDZERO +rounding mode. +.Sh SEE ALSO +.Xr ceil 3 , +.Xr fesetround 3 , +.Xr floor 3 , +.Xr math 3 , +.Xr nextafter 3 , +.Xr rint 3 , +.Xr round 3 +.Sh STANDARDS +The +.Fn trunc , +.Fn truncf , +and +.Fn truncl +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . diff --git a/mips/Makefile.inc b/mips/Makefile.inc new file mode 100644 index 0000000..cf599b7 --- /dev/null +++ b/mips/Makefile.inc @@ -0,0 +1,4 @@ +# $FreeBSD: src/lib/msun/mips/Makefile.inc,v 1.1 2008/04/26 12:20:29 imp Exp $ + +LDBL_PREC = 53 +SYM_MAPS += ${.CURDIR}/mips/Symbol.map diff --git a/mips/Symbol.map b/mips/Symbol.map new file mode 100644 index 0000000..426a103 --- /dev/null +++ b/mips/Symbol.map @@ -0,0 +1,13 @@ +/* + * $FreeBSD: src/lib/msun/mips/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ + */ +FBSD_1.0 { +}; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; diff --git a/mips/fenv.c b/mips/fenv.c new file mode 100644 index 0000000..61fefdd --- /dev/null +++ b/mips/fenv.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/mips/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $ + */ + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + +/* + * Hopefully the system ID byte is immutable, so it's valid to use + * this as a default environment. + */ +const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); diff --git a/mips/fenv.h b/mips/fenv.h new file mode 100644 index 0000000..73a4f2a --- /dev/null +++ b/mips/fenv.h @@ -0,0 +1,223 @@ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/mips/fenv.h,v 1.2 2011/10/10 15:43:09 das Exp $ + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include + +#ifndef __fenv_static +#define __fenv_static static +#endif + +typedef __uint32_t fenv_t; +typedef __uint32_t fexcept_t; + +/* Exception flags */ +#define FE_INVALID 0x0001 +#define FE_DIVBYZERO 0x0002 +#define FE_OVERFLOW 0x0004 +#define FE_UNDERFLOW 0x0008 +#define FE_INEXACT 0x0010 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* Rounding modes */ +#define FE_TONEAREST 0x0000 +#define FE_TOWARDZERO 0x0001 +#define FE_UPWARD 0x0002 +#define FE_DOWNWARD 0x0003 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ + FE_UPWARD | FE_TOWARDZERO) +__BEGIN_DECLS + +/* Default floating-point environment */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +/* We need to be able to map status flag positions to mask flag positions */ +#define _FPUSW_SHIFT 16 +#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) + +#ifdef ARM_HARD_FLOAT +#define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr))) +#define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr)) +#else +#define __rfs(__fpsr) +#define __wfs(__fpsr) +#endif + +__fenv_static inline int +feclearexcept(int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __fpsr &= ~__excepts; + __wfs(__fpsr); + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + *__flagp = __fpsr & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __fpsr &= ~__excepts; + __fpsr |= *__flagp & __excepts; + __wfs(__fpsr); + return (0); +} + +__fenv_static inline int +feraiseexcept(int __excepts) +{ + fexcept_t __ex = __excepts; + + fesetexceptflag(&__ex, __excepts); /* XXX */ + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + return (__fpsr & __excepts); +} + +__fenv_static inline int +fegetround(void) +{ + + /* + * Apparently, the rounding mode is specified as part of the + * instruction format on ARM, so the dynamic rounding mode is + * indeterminate. Some FPUs may differ. + */ + return (-1); +} + +__fenv_static inline int +fesetround(int __round) +{ + + return (-1); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + + __rfs(__envp); + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + fenv_t __env; + + __rfs(&__env); + *__envp = __env; + __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); + __wfs(__env); + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + + __wfs(*__envp); + return (0); +} + +__fenv_static inline int +feupdateenv(const fenv_t *__envp) +{ + fexcept_t __fpsr; + + __rfs(&__fpsr); + __wfs(*__envp); + feraiseexcept(__fpsr & FE_ALL_EXCEPT); + return (0); +} + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + fenv_t __old_fpsr, __new_fpsr; + + __rfs(&__old_fpsr); + __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT; + __wfs(__new_fpsr); + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fedisableexcept(int __mask) +{ + fenv_t __old_fpsr, __new_fpsr; + + __rfs(&__old_fpsr); + __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); + __wfs(__new_fpsr); + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fegetexcept(void) +{ + fenv_t __fpsr; + + __rfs(&__fpsr); + return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT); +} + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* !_FENV_H_ */ diff --git a/powerpc/Makefile.inc b/powerpc/Makefile.inc new file mode 100644 index 0000000..06d8030 --- /dev/null +++ b/powerpc/Makefile.inc @@ -0,0 +1,4 @@ +# $FreeBSD: src/lib/msun/powerpc/Makefile.inc,v 1.2 2006/03/27 23:59:45 deischen Exp $ + +LDBL_PREC = 53 +SYM_MAPS += ${.CURDIR}/powerpc/Symbol.map diff --git a/powerpc/Symbol.map b/powerpc/Symbol.map new file mode 100644 index 0000000..270a408 --- /dev/null +++ b/powerpc/Symbol.map @@ -0,0 +1,13 @@ +/* + * $FreeBSD: src/lib/msun/powerpc/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ + */ +FBSD_1.0 { +}; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; diff --git a/powerpc/fenv.c b/powerpc/fenv.c new file mode 100644 index 0000000..58c399a --- /dev/null +++ b/powerpc/fenv.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/powerpc/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $ + */ + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + +const fenv_t __fe_dfl_env = 0x00000000; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); diff --git a/powerpc/fenv.h b/powerpc/fenv.h new file mode 100644 index 0000000..df8d413 --- /dev/null +++ b/powerpc/fenv.h @@ -0,0 +1,274 @@ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/powerpc/fenv.h,v 1.5 2011/10/10 15:43:09 das Exp $ + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include + +#ifndef __fenv_static +#define __fenv_static static +#endif + +typedef __uint32_t fenv_t; +typedef __uint32_t fexcept_t; + +/* Exception flags */ +#define FE_INEXACT 0x02000000 +#define FE_DIVBYZERO 0x04000000 +#define FE_UNDERFLOW 0x08000000 +#define FE_OVERFLOW 0x10000000 +#define FE_INVALID 0x20000000 /* all types of invalid FP ops */ + +/* + * The PowerPC architecture has extra invalid flags that indicate the + * specific type of invalid operation occurred. These flags may be + * tested, set, and cleared---but not masked---separately. All of + * these bits are cleared when FE_INVALID is cleared, but only + * FE_VXSOFT is set when FE_INVALID is explicitly set in software. + */ +#define FE_VXCVI 0x00000100 /* invalid integer convert */ +#define FE_VXSQRT 0x00000200 /* square root of a negative */ +#define FE_VXSOFT 0x00000400 /* software-requested exception */ +#define FE_VXVC 0x00080000 /* ordered comparison involving NaN */ +#define FE_VXIMZ 0x00100000 /* inf * 0 */ +#define FE_VXZDZ 0x00200000 /* 0 / 0 */ +#define FE_VXIDI 0x00400000 /* inf / inf */ +#define FE_VXISI 0x00800000 /* inf - inf */ +#define FE_VXSNAN 0x01000000 /* operation on a signalling NaN */ +#define FE_ALL_INVALID (FE_VXCVI | FE_VXSQRT | FE_VXSOFT | FE_VXVC | \ + FE_VXIMZ | FE_VXZDZ | FE_VXIDI | FE_VXISI | \ + FE_VXSNAN | FE_INVALID) +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ + FE_ALL_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* Rounding modes */ +#define FE_TONEAREST 0x0000 +#define FE_TOWARDZERO 0x0001 +#define FE_UPWARD 0x0002 +#define FE_DOWNWARD 0x0003 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ + FE_UPWARD | FE_TOWARDZERO) + +__BEGIN_DECLS + +/* Default floating-point environment */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +/* We need to be able to map status flag positions to mask flag positions */ +#define _FPUSW_SHIFT 22 +#define _ENABLE_MASK ((FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ + FE_OVERFLOW | FE_UNDERFLOW) >> _FPUSW_SHIFT) + +#ifndef _SOFT_FLOAT +#define __mffs(__env) __asm __volatile("mffs %0" : "=f" (*(__env))) +#define __mtfsf(__env) __asm __volatile("mtfsf 255,%0" : : "f" (__env)) +#else +#define __mffs(__env) +#define __mtfsf(__env) +#endif + +union __fpscr { + double __d; + struct { + __uint32_t __junk; + fenv_t __reg; + } __bits; +}; + +__fenv_static inline int +feclearexcept(int __excepts) +{ + union __fpscr __r; + + if (__excepts & FE_INVALID) + __excepts |= FE_ALL_INVALID; + __mffs(&__r.__d); + __r.__bits.__reg &= ~__excepts; + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + union __fpscr __r; + + __mffs(&__r.__d); + *__flagp = __r.__bits.__reg & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + union __fpscr __r; + + if (__excepts & FE_INVALID) + __excepts |= FE_ALL_EXCEPT; + __mffs(&__r.__d); + __r.__bits.__reg &= ~__excepts; + __r.__bits.__reg |= *__flagp & __excepts; + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +feraiseexcept(int __excepts) +{ + union __fpscr __r; + + if (__excepts & FE_INVALID) + __excepts |= FE_VXSOFT; + __mffs(&__r.__d); + __r.__bits.__reg |= __excepts; + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + union __fpscr __r; + + __mffs(&__r.__d); + return (__r.__bits.__reg & __excepts); +} + +__fenv_static inline int +fegetround(void) +{ + union __fpscr __r; + + __mffs(&__r.__d); + return (__r.__bits.__reg & _ROUND_MASK); +} + +__fenv_static inline int +fesetround(int __round) +{ + union __fpscr __r; + + if (__round & ~_ROUND_MASK) + return (-1); + __mffs(&__r.__d); + __r.__bits.__reg &= ~_ROUND_MASK; + __r.__bits.__reg |= __round; + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + union __fpscr __r; + + __mffs(&__r.__d); + *__envp = __r.__bits.__reg; + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + union __fpscr __r; + + __mffs(&__r.__d); + *__envp = __r.__d; + __r.__bits.__reg &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + union __fpscr __r; + + __r.__bits.__reg = *__envp; + __mtfsf(__r.__d); + return (0); +} + +__fenv_static inline int +feupdateenv(const fenv_t *__envp) +{ + union __fpscr __r; + + __mffs(&__r.__d); + __r.__bits.__reg &= FE_ALL_EXCEPT; + __r.__bits.__reg |= *__envp; + __mtfsf(__r.__d); + return (0); +} + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + union __fpscr __r; + fenv_t __oldmask; + + __mffs(&__r.__d); + __oldmask = __r.__bits.__reg; + __r.__bits.__reg |= (__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT; + __mtfsf(__r.__d); + return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); +} + +static inline int +fedisableexcept(int __mask) +{ + union __fpscr __r; + fenv_t __oldmask; + + __mffs(&__r.__d); + __oldmask = __r.__bits.__reg; + __r.__bits.__reg &= ~((__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT); + __mtfsf(__r.__d); + return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); +} + +static inline int +fegetexcept(void) +{ + union __fpscr __r; + + __mffs(&__r.__d); + return ((__r.__bits.__reg & _ENABLE_MASK) << _FPUSW_SHIFT); +} + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* !_FENV_H_ */ diff --git a/sparc64/Makefile.inc b/sparc64/Makefile.inc new file mode 100644 index 0000000..330d02b --- /dev/null +++ b/sparc64/Makefile.inc @@ -0,0 +1,5 @@ +# $FreeBSD: src/lib/msun/sparc64/Makefile.inc,v 1.3 2006/03/27 23:59:45 deischen Exp $ + +ARCH_SRCS= e_sqrt.S e_sqrtf.S +LDBL_PREC= 113 +SYM_MAPS+= ${.CURDIR}/sparc64/Symbol.map diff --git a/sparc64/Symbol.map b/sparc64/Symbol.map new file mode 100644 index 0000000..2fe510b --- /dev/null +++ b/sparc64/Symbol.map @@ -0,0 +1,13 @@ +/* + * $FreeBSD: src/lib/msun/sparc64/Symbol.map,v 1.3 2011/10/10 15:43:09 das Exp $ + */ +FBSD_1.0 { +}; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; diff --git a/sparc64/e_sqrt.S b/sparc64/e_sqrt.S new file mode 100644 index 0000000..95f79a6 --- /dev/null +++ b/sparc64/e_sqrt.S @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/sparc64/e_sqrt.S,v 1.1 2005/02/21 18:27:57 das Exp $") + +ENTRY(sqrt) + retl + fsqrtd %f0, %f0 +END(sqrt) diff --git a/sparc64/e_sqrtf.S b/sparc64/e_sqrtf.S new file mode 100644 index 0000000..e1f7cf6 --- /dev/null +++ b/sparc64/e_sqrtf.S @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/sparc64/e_sqrtf.S,v 1.1 2005/02/21 18:27:57 das Exp $") + +ENTRY(sqrtf) + retl + fsqrts %f1, %f0 +END(sqrtf) diff --git a/sparc64/fenv.c b/sparc64/fenv.c new file mode 100644 index 0000000..5a4117f --- /dev/null +++ b/sparc64/fenv.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/sparc64/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $ + */ + +#define __fenv_static +#include "fenv.h" + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + +/* + * The FSR_version field may be different on different + * implementations, but it is immutable and opaque to the + * application. Thus, 0 is valid as the default environment. + */ +const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); diff --git a/sparc64/fenv.h b/sparc64/fenv.h new file mode 100644 index 0000000..293d8e6 --- /dev/null +++ b/sparc64/fenv.h @@ -0,0 +1,260 @@ +/*- + * Copyright (c) 2004-2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/msun/sparc64/fenv.h,v 1.4 2011/10/10 15:43:09 das Exp $ + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include + +#ifndef __fenv_static +#define __fenv_static static +#endif + +typedef __uint64_t fenv_t; +typedef __uint64_t fexcept_t; + +/* Exception flags */ +#define FE_INVALID 0x00000200 +#define FE_DIVBYZERO 0x00000040 +#define FE_OVERFLOW 0x00000100 +#define FE_UNDERFLOW 0x00000080 +#define FE_INEXACT 0x00000020 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + +/* + * Rounding modes + * + * We can't just use the hardware bit values here, because that would + * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ + FE_UPWARD | FE_TOWARDZERO) +#define _ROUND_SHIFT 30 + +__BEGIN_DECLS + +/* Default floating-point environment */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +/* We need to be able to map status flag positions to mask flag positions */ +#define _FPUSW_SHIFT 18 +#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) + +#define __ldxfsr(__r) __asm __volatile("ldx %0, %%fsr" : : "m" (__r)) +#define __stxfsr(__r) __asm __volatile("stx %%fsr, %0" : "=m" (*(__r))) + +__fenv_static __inline int +feclearexcept(int __excepts) +{ + fexcept_t __r; + + __stxfsr(&__r); + __r &= ~__excepts; + __ldxfsr(__r); + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + fexcept_t __r; + + __stxfsr(&__r); + *__flagp = __r & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + fexcept_t __r; + + __stxfsr(&__r); + __r &= ~__excepts; + __r |= *__flagp & __excepts; + __ldxfsr(__r); + return (0); +} + +/* + * In contrast with the ia64 platform, it seems to be worthwhile to + * inline this function on sparc64 even when the arguments are not + * compile-time constants. Perhaps this depends on the register window. + */ +__fenv_static inline int +feraiseexcept(int __excepts) +{ + volatile double d; + + /* + * With a compiler that supports the FENV_ACCESS pragma + * properly, simple expressions like '0.0 / 0.0' should + * be sufficient to generate traps. Unfortunately, we + * need to bring a volatile variable into the equation + * to prevent incorrect optimizations. + */ + if (__excepts & FE_INVALID) { + d = 0.0; + d = 0.0 / d; + } + if (__excepts & FE_DIVBYZERO) { + d = 0.0; + d = 1.0 / d; + } + if (__excepts & FE_OVERFLOW) { + d = 0x1.ffp1023; + d *= 2.0; + } + if (__excepts & FE_UNDERFLOW) { + d = 0x1p-1022; + d /= 0x1p1023; + } + if (__excepts & FE_INEXACT) { + d = 0x1p-1022; + d += 1.0; + } + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + fexcept_t __r; + + __stxfsr(&__r); + return (__r & __excepts); +} + +__fenv_static inline int +fegetround(void) +{ + fenv_t __r; + + __stxfsr(&__r); + return ((__r >> _ROUND_SHIFT) & _ROUND_MASK); +} + +__fenv_static inline int +fesetround(int __round) +{ + fenv_t __r; + + if (__round & ~_ROUND_MASK) + return (-1); + __stxfsr(&__r); + __r &= ~(_ROUND_MASK << _ROUND_SHIFT); + __r |= __round << _ROUND_SHIFT; + __ldxfsr(__r); + return (0); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + + __stxfsr(__envp); + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + fenv_t __r; + + __stxfsr(&__r); + *__envp = __r; + __r &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); + __ldxfsr(__r); + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + + __ldxfsr(*__envp); + return (0); +} + +__fenv_static inline int +feupdateenv(const fenv_t *__envp) +{ + fexcept_t __r; + + __stxfsr(&__r); + __ldxfsr(*__envp); + feraiseexcept(__r & FE_ALL_EXCEPT); + return (0); +} + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + fenv_t __old_r, __new_r; + + __stxfsr(&__old_r); + __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); + __ldxfsr(__new_r); + return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fedisableexcept(int __mask) +{ + fenv_t __old_r, __new_r; + + __stxfsr(&__old_r); + __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); + __ldxfsr(__new_r); + return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); +} + +static inline int +fegetexcept(void) +{ + fenv_t __r; + + __stxfsr(&__r); + return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT); +} + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* !_FENV_H_ */ diff --git a/src/FILES b/src/FILES deleted file mode 100644 index e860e0b..0000000 --- a/src/FILES +++ /dev/null @@ -1,192 +0,0 @@ - e_acos.c - e_acosf.c - e_acosh.c - e_acoshf.c - e_acosl.c - e_asin.c - e_asinf.c - e_asinl.c - e_atan2.c - e_atan2f.c - e_atan2l.c - e_atanh.c - e_atanhf.c - e_cosh.c - e_coshf.c - e_exp.c - e_expf.c - e_fmod.c - e_fmodf.c - e_fmodl.c - e_gamma.c - e_gamma_r.c - e_gammaf.c - e_gammaf_r.c - e_hypot.c - e_hypotf.c - e_hypotl.c - e_j0.c - e_j0f.c - e_j1.c - e_j1f.c - e_jn.c - e_jnf.c - e_lgamma.c - e_lgamma_r.c - e_lgammaf.c - e_lgammaf_r.c - e_log.c - e_log10.c - e_log10f.c - e_logf.c - e_pow.c - e_powf.c - e_rem_pio2.c - e_rem_pio2f.c - e_remainder.c - e_remainderf.c - e_remainderl.c - e_scalb.c - e_scalbf.c - e_sinh.c - e_sinhf.c - e_sqrt.c - e_sqrtf.c - e_sqrtl.c - k_cos.c - k_cosf.c - k_rem_pio2.c - k_sin.c - k_sinf.c - k_tan.c - k_tanf.c - math.h - math_private.h - s_asinh.c - s_asinhf.c - s_atan.c - s_atanf.c - s_atanl.c - s_carg.c - s_cargf.c - s_cargl.c - s_cbrt.c - s_cbrtf.c - s_ceil.c - s_ceilf.c - s_ceill.c - s_cimag.c - s_cimagf.c - s_cimagl.c - s_conj.c - s_conjf.c - s_conjl.c - s_copysign.c - s_copysignf.c - s_copysignl.c - s_cos.c - s_cosf.c - s_cosl.c - s_cproj.c - s_cprojf.c - s_cprojl.c - s_creal.c - s_crealf.c - s_creall.c - s_csqrt.c - s_csqrtf.c - s_csqrtl.c - s_erf.c - s_erff.c - s_exp2.c - s_exp2f.c - s_expm1.c - s_expm1f.c - s_fabs.c - s_fabsf.c - s_fabsl.c - s_fdim.c - s_finite.c - s_finitef.c - s_floor.c - s_floorf.c - s_floorl.c - s_fma.c - s_fmaf.c - s_fmal.c - s_fmax.c - s_fmaxf.c - s_fmaxl.c - s_fmin.c - s_fminf.c - s_fminl.c - s_frexp.c - s_frexpf.c - s_frexpl.c - s_ilogb.c - s_ilogbf.c - s_ilogbl.c - s_isfinite.c - s_isnan.c - s_isnormal.c - s_llrint.c - s_llrintf.c - s_llrintl.c - s_llround.c - s_llroundf.c - s_llroundl.c - s_log1p.c - s_log1pf.c - s_logb.c - s_logbf.c - s_logbl.c - s_lrint.c - s_lrintf.c - s_lrintl.c - s_lround.c - s_lroundf.c - s_lroundl.c - s_modf.c - s_modff.c - s_modfl.c - s_nan.c - s_nearbyint.c - s_nextafter.c - s_nextafterf.c - s_nextafterl.c - s_nexttoward.c - s_nexttowardf.c - s_remquo.c - s_remquof.c - s_remquol.c - s_rint.c - s_rintf.c - s_rintl.c - s_round.c - s_roundf.c - s_roundl.c - s_scalbln.c - s_scalbn.c - s_scalbnf.c - s_scalbnl.c - s_signbit.c - s_signgam.c - s_significand.c - s_significandf.c - s_sin.c - s_sinf.c - s_sinl.c - s_tan.c - s_tanf.c - s_tanh.c - s_tanhf.c - s_tanl.c - s_tgammaf.c - s_trunc.c - s_truncf.c - s_truncl.c - w_cabs.c - w_cabsf.c - w_cabsl.c - w_drem.c - w_dremf.c diff --git a/src/e_acos.c b/src/e_acos.c index 4d9485e..c1ab748 100644 --- a/src/e_acos.c +++ b/src/e_acos.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_acos.c,v 1.13 2008/07/31 22:41:26 das Exp $"); /* __ieee754_acos(x) * Method : @@ -40,7 +40,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/e_acosf.c b/src/e_acosf.c index 113dfcd..4e29689 100644 --- a/src/e_acosf.c +++ b/src/e_acosf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_acosf.c,v 1.11 2008/08/03 17:39:54 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/e_acosh.c b/src/e_acosh.c index fa3406a..d3e60bb 100644 --- a/src/e_acosh.c +++ b/src/e_acosh.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_acosh.c,v 1.9 2008/02/22 02:30:34 das Exp $"); /* __ieee754_acosh(x) * Method : @@ -29,7 +29,7 @@ * acosh(NaN) is NaN without signal. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/e_acoshf.c b/src/e_acoshf.c index e4992c3..c7e590b 100644 --- a/src/e_acoshf.c +++ b/src/e_acoshf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_acoshf.c,v 1.8 2008/02/22 02:30:34 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/e_acosl.c b/src/e_acosl.c index aa38d1d..19f5b82 100644 --- a/src/e_acosl.c +++ b/src/e_acosl.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_acosl.c,v 1.2 2008/08/02 03:56:22 das Exp $"); /* * See comments in e_acos.c. @@ -23,7 +23,7 @@ #include #include "invtrig.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const long double diff --git a/src/e_asin.c b/src/e_asin.c index a0f809c..09b3f03 100644 --- a/src/e_asin.c +++ b/src/e_asin.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_asin.c,v 1.15 2011/02/10 07:37:50 das Exp $"); /* __ieee754_asin(x) * Method : @@ -46,7 +46,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/e_asinf.c b/src/e_asinf.c index 67e8ef8..f87c18c 100644 --- a/src/e_asinf.c +++ b/src/e_asinf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_asinf.c,v 1.13 2008/08/08 00:21:27 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/e_asinl.c b/src/e_asinl.c index e56081c..9e1c37f 100644 --- a/src/e_asinl.c +++ b/src/e_asinl.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_asinl.c,v 1.2 2008/08/03 17:49:05 das Exp $"); /* * See comments in e_asin.c. @@ -23,7 +23,7 @@ #include #include "invtrig.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const long double diff --git a/src/e_atan2.c b/src/e_atan2.c index f4f4ef1..54515ae 100644 --- a/src/e_atan2.c +++ b/src/e_atan2.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_atan2.c,v 1.14 2008/08/02 19:17:00 das Exp $"); /* __ieee754_atan2(y,x) * Method : @@ -44,7 +44,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static volatile double diff --git a/src/e_atan2f.c b/src/e_atan2f.c index f72de93..fc20a64 100644 --- a/src/e_atan2f.c +++ b/src/e_atan2f.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_atan2f.c,v 1.12 2008/08/03 17:39:54 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static volatile float diff --git a/src/e_atan2l.c b/src/e_atan2l.c index 4a5df65..9e0d33c 100644 --- a/src/e_atan2l.c +++ b/src/e_atan2l.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_atan2l.c,v 1.3 2008/08/02 19:17:00 das Exp $"); /* * See comments in e_atan2.c. @@ -24,7 +24,7 @@ #include #include "invtrig.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" static volatile long double diff --git a/src/e_atanh.c b/src/e_atanh.c index 25a3f71..1642b62 100644 --- a/src/e_atanh.c +++ b/src/e_atanh.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_atanh.c,v 1.8 2008/02/22 02:30:34 das Exp $"); /* __ieee754_atanh(x) * Method : @@ -33,7 +33,7 @@ * */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, huge = 1e300; diff --git a/src/e_atanhf.c b/src/e_atanhf.c index d8b37a6..b421b42 100644 --- a/src/e_atanhf.c +++ b/src/e_atanhf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_atanhf.c,v 1.7 2008/02/22 02:30:34 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0, huge = 1e30; diff --git a/src/e_cosh.c b/src/e_cosh.c index e04c7e2..5093d06 100644 --- a/src/e_cosh.c +++ b/src/e_cosh.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_cosh.c,v 1.10 2011/10/21 06:28:47 das Exp $"); /* __ieee754_cosh(x) * Method : @@ -35,7 +35,7 @@ * only cosh(0)=1 is exact for finite x. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, half=0.5, huge = 1.0e300; @@ -45,7 +45,6 @@ __ieee754_cosh(double x) { double t,w; int32_t ix; - u_int32_t lx; /* High word of |x|. */ GET_HIGH_WORD(ix,x); @@ -72,13 +71,8 @@ __ieee754_cosh(double x) if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x)); /* |x| in [log(maxdouble), overflowthresold] */ - GET_LOW_WORD(lx,x); - if (ix<0x408633CE || - ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) { - w = __ieee754_exp(half*fabs(x)); - t = half*w; - return t*w; - } + if (ix<=0x408633CE) + return __ldexp_exp(fabs(x), -1); /* |x| > overflowthresold, cosh(x) overflow */ return huge*huge; diff --git a/src/e_coshf.c b/src/e_coshf.c index dd6c682..32987a5 100644 --- a/src/e_coshf.c +++ b/src/e_coshf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_coshf.c,v 1.9 2011/10/21 06:28:47 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0, half=0.5, huge = 1.0e30; @@ -51,11 +51,8 @@ __ieee754_coshf(float x) if (ix < 0x42b17217) return half*__ieee754_expf(fabsf(x)); /* |x| in [log(maxfloat), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = __ieee754_expf(half*fabsf(x)); - t = half*w; - return t*w; - } + if (ix<=0x42b2d4fc) + return __ldexp_expf(fabsf(x), -1); /* |x| > overflowthresold, cosh(x) overflow */ return huge*huge; diff --git a/src/e_exp.c b/src/e_exp.c index 80e4a32..810cdfe 100644 --- a/src/e_exp.c +++ b/src/e_exp.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_exp.c,v 1.14 2011/10/21 06:26:38 das Exp $"); /* __ieee754_exp(x) * Returns the exponential of x. @@ -76,7 +76,9 @@ * to produce the hexadecimal values shown. */ -#include "openlibm.h" +#include + +#include "math.h" #include "math_private.h" static const double @@ -133,7 +135,7 @@ __ieee754_exp(double x) /* default IEEE double exp */ hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ lo = t*ln2LO[0]; } - x = hi - lo; + STRICT_ASSIGN(double, x, hi - lo); } else if(hx < 0x3e300000) { /* when |x|<2**-28 */ if(huge+x>one) return one+x;/* trigger inexact */ diff --git a/src/e_expf.c b/src/e_expf.c index 141504c..35e32a5 100644 --- a/src/e_expf.c +++ b/src/e_expf.c @@ -14,9 +14,11 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_expf.c,v 1.16 2011/10/21 06:26:38 das Exp $"); +#include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float @@ -40,7 +42,7 @@ P2 = -2.7667332906e-3; /* -0xb55215.0p-32 */ static volatile float twom100 = 7.8886090522e-31; /* 2**-100=0x0d800000 */ float -__ieee754_expf(float x) /* default IEEE double exp */ +__ieee754_expf(float x) { float y,hi=0.0,lo=0.0,c,t,twopk; int32_t k=0,xsb; @@ -70,7 +72,7 @@ __ieee754_expf(float x) /* default IEEE double exp */ hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ lo = t*ln2LO[0]; } - x = hi - lo; + STRICT_ASSIGN(float, x, hi - lo); } else if(hx < 0x39000000) { /* when |x|<2**-14 */ if(huge+x>one) return one+x;/* trigger inexact */ diff --git a/src/e_fmod.c b/src/e_fmod.c index 3fb307f..c52722c 100644 --- a/src/e_fmod.c +++ b/src/e_fmod.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_fmod.c,v 1.10 2008/02/22 02:30:34 das Exp $"); /* * __ieee754_fmod(x,y) @@ -20,7 +20,7 @@ * Method: shift and subtract */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, Zero[] = {0.0, -0.0,}; diff --git a/src/e_fmodf.c b/src/e_fmodf.c index 99b2150..456f85e 100644 --- a/src/e_fmodf.c +++ b/src/e_fmodf.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_fmodf.c,v 1.7 2008/02/22 02:30:34 das Exp $"); /* * __ieee754_fmodf(x,y) @@ -22,7 +22,7 @@ * Method: shift and subtract */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0, Zero[] = {0.0, -0.0,}; diff --git a/src/e_fmodl.c b/src/e_fmodl.c index b9a9d99..4f97076 100644 --- a/src/e_fmodl.c +++ b/src/e_fmodl.c @@ -11,25 +11,25 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_fmodl.c,v 1.2 2008/07/31 20:09:47 das Exp $"); #include #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" #define BIAS (LDBL_MAX_EXP - 1) #if LDBL_MANL_SIZE > 32 -typedef u_int64_t manl_t; +typedef uint64_t manl_t; #else typedef uint32_t manl_t; #endif #if LDBL_MANH_SIZE > 32 -typedef u_int64_t manh_t; +typedef uint64_t manh_t; #else typedef uint32_t manh_t; #endif diff --git a/src/e_gamma.c b/src/e_gamma.c index e6ef3d8..2d75558 100644 --- a/src/e_gamma.c +++ b/src/e_gamma.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_gamma.c,v 1.8 2008/02/22 02:30:34 das Exp $"); /* __ieee754_gamma(x) * Return the logarithm of the Gamma function of x. @@ -21,7 +21,7 @@ * Method: call __ieee754_gamma_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" extern int signgam; diff --git a/src/e_gamma_r.c b/src/e_gamma_r.c index 1335ba6..71e8172 100644 --- a/src/e_gamma_r.c +++ b/src/e_gamma_r.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_gamma_r.c,v 1.8 2008/02/22 02:30:34 das Exp $"); /* __ieee754_gamma_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function @@ -22,7 +22,7 @@ * Method: See __ieee754_lgamma_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" double diff --git a/src/e_gammaf.c b/src/e_gammaf.c index f744cec..85a8ecc 100644 --- a/src/e_gammaf.c +++ b/src/e_gammaf.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_gammaf.c,v 1.7 2008/02/22 02:30:35 das Exp $"); /* __ieee754_gammaf(x) * Return the logarithm of the Gamma function of x. @@ -22,7 +22,7 @@ * Method: call __ieee754_gammaf_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" extern int signgam; diff --git a/src/e_gammaf_r.c b/src/e_gammaf_r.c index bdd2bb4..77113fd 100644 --- a/src/e_gammaf_r.c +++ b/src/e_gammaf_r.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_gammaf_r.c,v 1.8 2008/02/22 02:30:35 das Exp $"); /* __ieee754_gammaf_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function @@ -23,7 +23,7 @@ * Method: See __ieee754_lgammaf_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" float diff --git a/src/e_hypot.c b/src/e_hypot.c index 5d5de3b..41d3b59 100644 --- a/src/e_hypot.c +++ b/src/e_hypot.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_hypot.c,v 1.14 2011/10/15 07:00:28 das Exp $"); /* __ieee754_hypot(x,y) * @@ -48,13 +48,13 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" double __ieee754_hypot(double x, double y) { - double a=x,b=y,t1,t2,y1,y2,w; + double a,b,t1,t2,y1,y2,w; int32_t j,k,ha,hb; GET_HIGH_WORD(ha,x); diff --git a/src/e_hypotf.c b/src/e_hypotf.c index 72e4b7f..face936 100644 --- a/src/e_hypotf.c +++ b/src/e_hypotf.c @@ -14,15 +14,15 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_hypotf.c,v 1.14 2011/10/15 07:00:28 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" float __ieee754_hypotf(float x, float y) { - float a=x,b=y,t1,t2,y1,y2,w; + float a,b,t1,t2,y1,y2,w; int32_t j,k,ha,hb; GET_FLOAT_WORD(ha,x); diff --git a/src/e_hypotl.c b/src/e_hypotl.c index af54d6a..a17ca19 100644 --- a/src/e_hypotl.c +++ b/src/e_hypotl.c @@ -11,23 +11,16 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_hypotl.c,v 1.3 2011/10/16 05:36:39 das Exp $"); /* long double version of hypot(). See e_hypot.c for most comments. */ #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" -#define GET_LDBL_EXPSIGN(i, v) do { \ - union IEEEl2bits uv; \ - \ - uv.e = v; \ - i = uv.xbits.expsign; \ -} while (0) - #define GET_LDBL_MAN(h, l, v) do { \ union IEEEl2bits uv; \ \ @@ -36,14 +29,6 @@ l = uv.bits.manl; \ } while (0) -#define SET_LDBL_EXPSIGN(v, i) do { \ - union IEEEl2bits uv; \ - \ - uv.e = v; \ - uv.xbits.expsign = i; \ - v = uv.e; \ -} while (0) - #undef GET_HIGH_WORD #define GET_HIGH_WORD(i, v) GET_LDBL_EXPSIGN(i, v) #undef SET_HIGH_WORD @@ -55,7 +40,7 @@ #define MAX_EXP LDBL_MAX_EXP #if LDBL_MANL_SIZE > 32 -typedef u_int64_t man_t; +typedef uint64_t man_t; #else typedef uint32_t man_t; #endif diff --git a/src/e_j0.c b/src/e_j0.c index 7b6b1fe..f9586da 100644 --- a/src/e_j0.c +++ b/src/e_j0.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_j0.c,v 1.9 2008/02/22 02:30:35 das Exp $"); /* __ieee754_j0(x), __ieee754_y0(x) * Bessel function of the first and second kinds of order zero. @@ -59,7 +59,7 @@ * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static double pzero(double), qzero(double); diff --git a/src/e_j0f.c b/src/e_j0f.c index fdcddad..840f9df 100644 --- a/src/e_j0f.c +++ b/src/e_j0f.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_j0f.c,v 1.8 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static float pzerof(float), qzerof(float); diff --git a/src/e_j1.c b/src/e_j1.c index 01b30d7..20f6c67 100644 --- a/src/e_j1.c +++ b/src/e_j1.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_j1.c,v 1.9 2008/02/22 02:30:35 das Exp $"); /* __ieee754_j1(x), __ieee754_y1(x) * Bessel function of the first and second kinds of order zero. @@ -59,7 +59,7 @@ * by method mentioned above. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static double pone(double), qone(double); diff --git a/src/e_j1f.c b/src/e_j1f.c index 5a552a0..4c1678b 100644 --- a/src/e_j1f.c +++ b/src/e_j1f.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_j1f.c,v 1.8 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static float ponef(float), qonef(float); diff --git a/src/e_jn.c b/src/e_jn.c index aefa89f..5e64cde 100644 --- a/src/e_jn.c +++ b/src/e_jn.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_jn.c,v 1.11 2010/11/13 10:54:10 uqs Exp $"); /* * __ieee754_jn(n, x), __ieee754_yn(n, x) @@ -40,7 +40,7 @@ * */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/e_jnf.c b/src/e_jnf.c index 6405a43..18165fa 100644 --- a/src/e_jnf.c +++ b/src/e_jnf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_jnf.c,v 1.11 2010/11/13 10:54:10 uqs Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/e_lgamma.c b/src/e_lgamma.c index fd80480..7b2755a 100644 --- a/src/e_lgamma.c +++ b/src/e_lgamma.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_lgamma.c,v 1.9 2008/02/22 02:30:35 das Exp $"); /* __ieee754_lgamma(x) * Return the logarithm of the Gamma function of x. @@ -21,7 +21,7 @@ * Method: call __ieee754_lgamma_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" extern int signgam; diff --git a/src/e_lgamma_r.c b/src/e_lgamma_r.c index 3d26123..6105f2b 100644 --- a/src/e_lgamma_r.c +++ b/src/e_lgamma_r.c @@ -13,7 +13,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_lgamma_r.c,v 1.11 2011/10/15 07:00:28 das Exp $"); /* __ieee754_lgamma_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function @@ -83,7 +83,7 @@ * */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double @@ -269,7 +269,6 @@ __ieee754_lgamma_r(double x, int *signgamp) } else if(ix<0x40200000) { /* x < 8.0 */ i = (int)x; - t = zero; y = x-(double)i; p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); diff --git a/src/e_lgammaf.c b/src/e_lgammaf.c index 9849622..244347a 100644 --- a/src/e_lgammaf.c +++ b/src/e_lgammaf.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_lgammaf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); /* __ieee754_lgammaf(x) * Return the logarithm of the Gamma function of x. @@ -22,7 +22,7 @@ * Method: call __ieee754_lgammaf_r */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" extern int signgam; diff --git a/src/e_lgammaf_r.c b/src/e_lgammaf_r.c index 7acb782..435d7d0 100644 --- a/src/e_lgammaf_r.c +++ b/src/e_lgammaf_r.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_lgammaf_r.c,v 1.12 2011/10/15 07:00:28 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float @@ -202,7 +202,6 @@ __ieee754_lgammaf_r(float x, int *signgamp) } else if(ix<0x41000000) { /* x < 8.0 */ i = (int)x; - t = zero; y = x-(float)i; p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); diff --git a/src/e_log.c b/src/e_log.c index 9623b0f..d0365af 100644 --- a/src/e_log.c +++ b/src/e_log.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_log.c,v 1.15 2008/03/29 16:37:59 das Exp $"); /* __ieee754_log(x) * Return the logrithm of x @@ -65,7 +65,7 @@ * to produce the hexadecimal values shown. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/e_log10.c b/src/e_log10.c index 643c5d4..1c4516f 100644 --- a/src/e_log10.c +++ b/src/e_log10.c @@ -12,13 +12,17 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_log10.c,v 1.15 2011/10/15 05:23:28 das Exp $"); /* - * Return the base 10 logarithm of x. See k_log.c for details on the algorithm. + * Return the base 10 logarithm of x. See e_log.c and k_log.h for most + * comments. + * + * log10(x) = (f - 0.5*f*f + k_log1p(f)) / ln10 + k * log10(2) + * in not-quite-routine extra precision. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" #include "k_log.h" @@ -34,31 +38,50 @@ static const double zero = 0.0; double __ieee754_log10(double x) { - double f,hi,lo,y,z; + double f,hfsq,hi,lo,r,val_hi,val_lo,w,y,y2; int32_t i,k,hx; u_int32_t lx; EXTRACT_WORDS(hx,lx,x); - k=0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 54; x *= two54; /* subnormal number, scale up x */ + k=0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; x *= two54; /* subnormal number, scale up x */ GET_HIGH_WORD(hx,x); - } + } if (hx >= 0x7ff00000) return x+x; + if (hx == 0x3ff00000 && lx == 0) + return zero; /* log(1) = +0 */ k += (hx>>20)-1023; hx &= 0x000fffff; i = (hx+0x95f64)&0x100000; SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ k += (i>>20); y = (double)k; - f = __kernel_log(x); - hi = x = x - 1; + f = x - 1.0; + hfsq = 0.5*f*f; + r = k_log1p(f); + + /* See e_log2.c for most details. */ + hi = f - hfsq; SET_LOW_WORD(hi,0); - lo = x - hi; - z = y*log10_2lo + (x+f)*ivln10lo + (lo+f)*ivln10hi + hi*ivln10hi; - return z+y*log10_2hi; + lo = (f - hi) - hfsq + r; + val_hi = hi*ivln10hi; + y2 = y*log10_2hi; + val_lo = y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi; + + /* + * Extra precision in for adding y*log10_2hi is not strictly needed + * since there is no very large cancellation near x = sqrt(2) or + * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs + * with some parallelism and it reduces the error for many args. + */ + w = y2 + val_hi; + val_lo += (y2 - w) + val_hi; + val_hi = w; + + return val_lo + val_hi; } diff --git a/src/e_log10f.c b/src/e_log10f.c index 722f6bb..c500eb6 100644 --- a/src/e_log10f.c +++ b/src/e_log10f.c @@ -10,13 +10,13 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_log10f.c,v 1.13 2011/10/16 05:36:23 das Exp $"); /* - * Return the base 10 logarithm of x. See k_log.c for details on the algorithm. + * Float version of e_log10.c. See the latter for most comments. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" #include "k_logf.h" @@ -32,31 +32,40 @@ static const float zero = 0.0; float __ieee754_log10f(float x) { - float f,hi,lo,y,z; + float f,hfsq,hi,lo,r,y; int32_t i,k,hx; GET_FLOAT_WORD(hx,x); - k=0; - if (hx < 0x00800000) { /* x < 2**-126 */ - if ((hx&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 25; x *= two25; /* subnormal number, scale up x */ + k=0; + if (hx < 0x00800000) { /* x < 2**-126 */ + if ((hx&0x7fffffff)==0) + return -two25/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 25; x *= two25; /* subnormal number, scale up x */ GET_FLOAT_WORD(hx,x); - } + } if (hx >= 0x7f800000) return x+x; + if (hx == 0x3f800000) + return zero; /* log(1) = +0 */ k += (hx>>23)-127; hx &= 0x007fffff; i = (hx+(0x4afb0d))&0x800000; SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */ k += (i>>23); y = (float)k; - f = __kernel_logf(x); - x = x - (float)1.0; - GET_FLOAT_WORD(hx,x); + f = x - (float)1.0; + hfsq = (float)0.5*f*f; + r = k_log1pf(f); + + /* See e_log2f.c and e_log2.c for details. */ + if (sizeof(float_t) > sizeof(float)) + return (r - hfsq + f) * ((float_t)ivln10lo + ivln10hi) + + y * ((float_t)log10_2lo + log10_2hi); + hi = f - hfsq; + GET_FLOAT_WORD(hx,hi); SET_FLOAT_WORD(hi,hx&0xfffff000); - lo = x - hi; - z = y*log10_2lo + (x+f)*ivln10lo + (lo+f)*ivln10hi + hi*ivln10hi; - return z+y*log10_2hi; + lo = (f - hi) - hfsq + r; + return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + + y*log10_2hi; } diff --git a/src/e_log2.c b/src/e_log2.c new file mode 100644 index 0000000..a478bd4 --- /dev/null +++ b/src/e_log2.c @@ -0,0 +1,110 @@ + +/* @(#)e_log10.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/e_log2.c,v 1.4 2011/10/15 05:23:28 das Exp $"); + +/* + * Return the base 2 logarithm of x. See e_log.c and k_log.h for most + * comments. + * + * This reduces x to {k, 1+f} exactly as in e_log.c, then calls the kernel, + * then does the combining and scaling steps + * log2(x) = (f - 0.5*f*f + k_log1p(f)) / ln2 + k + * in not-quite-routine extra precision. + */ + +#include "math.h" +#include "math_private.h" +#include "k_log.h" + +static const double +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +ivln2hi = 1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */ +ivln2lo = 1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */ + +static const double zero = 0.0; + +double +__ieee754_log2(double x) +{ + double f,hfsq,hi,lo,r,val_hi,val_lo,w,y; + int32_t i,k,hx; + u_int32_t lx; + + EXTRACT_WORDS(hx,lx,x); + + k=0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; x *= two54; /* subnormal number, scale up x */ + GET_HIGH_WORD(hx,x); + } + if (hx >= 0x7ff00000) return x+x; + if (hx == 0x3ff00000 && lx == 0) + return zero; /* log(1) = +0 */ + k += (hx>>20)-1023; + hx &= 0x000fffff; + i = (hx+0x95f64)&0x100000; + SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ + k += (i>>20); + y = (double)k; + f = x - 1.0; + hfsq = 0.5*f*f; + r = k_log1p(f); + + /* + * f-hfsq must (for args near 1) be evaluated in extra precision + * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2). + * This is fairly efficient since f-hfsq only depends on f, so can + * be evaluated in parallel with R. Not combining hfsq with R also + * keeps R small (though not as small as a true `lo' term would be), + * so that extra precision is not needed for terms involving R. + * + * Compiler bugs involving extra precision used to break Dekker's + * theorem for spitting f-hfsq as hi+lo, unless double_t was used + * or the multi-precision calculations were avoided when double_t + * has extra precision. These problems are now automatically + * avoided as a side effect of the optimization of combining the + * Dekker splitting step with the clear-low-bits step. + * + * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra + * precision to avoid a very large cancellation when x is very near + * these values. Unlike the above cancellations, this problem is + * specific to base 2. It is strange that adding +-1 is so much + * harder than adding +-ln2 or +-log10_2. + * + * This uses Dekker's theorem to normalize y+val_hi, so the + * compiler bugs are back in some configurations, sigh. And I + * don't want to used double_t to avoid them, since that gives a + * pessimization and the support for avoiding the pessimization + * is not yet available. + * + * The multi-precision calculations for the multiplications are + * routine. + */ + hi = f - hfsq; + SET_LOW_WORD(hi,0); + lo = (f - hi) - hfsq + r; + val_hi = hi*ivln2hi; + val_lo = (lo+hi)*ivln2lo + lo*ivln2hi; + + /* spadd(val_hi, val_lo, y), except for not using double_t: */ + w = y + val_hi; + val_lo += (y - w) + val_hi; + val_hi = w; + + return val_lo + val_hi; +} diff --git a/src/e_log2f.c b/src/e_log2f.c new file mode 100644 index 0000000..66bcb68 --- /dev/null +++ b/src/e_log2f.c @@ -0,0 +1,81 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/e_log2f.c,v 1.5 2011/10/15 05:23:28 das Exp $"); + +/* + * Float version of e_log2.c. See the latter for most comments. + */ + +#include "math.h" +#include "math_private.h" +#include "k_logf.h" + +static const float +two25 = 3.3554432000e+07, /* 0x4c000000 */ +ivln2hi = 1.4428710938e+00, /* 0x3fb8b000 */ +ivln2lo = -1.7605285393e-04; /* 0xb9389ad4 */ + +static const float zero = 0.0; + +float +__ieee754_log2f(float x) +{ + float f,hfsq,hi,lo,r,y; + int32_t i,k,hx; + + GET_FLOAT_WORD(hx,x); + + k=0; + if (hx < 0x00800000) { /* x < 2**-126 */ + if ((hx&0x7fffffff)==0) + return -two25/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 25; x *= two25; /* subnormal number, scale up x */ + GET_FLOAT_WORD(hx,x); + } + if (hx >= 0x7f800000) return x+x; + if (hx == 0x3f800000) + return zero; /* log(1) = +0 */ + k += (hx>>23)-127; + hx &= 0x007fffff; + i = (hx+(0x4afb0d))&0x800000; + SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */ + k += (i>>23); + y = (float)k; + f = x - (float)1.0; + hfsq = (float)0.5*f*f; + r = k_log1pf(f); + + /* + * We no longer need to avoid falling into the multi-precision + * calculations due to compiler bugs breaking Dekker's theorem. + * Keep avoiding this as an optimization. See e_log2.c for more + * details (some details are here only because the optimization + * is not yet available in double precision). + * + * Another compiler bug turned up. With gcc on i386, + * (ivln2lo + ivln2hi) would be evaluated in float precision + * despite runtime evaluations using double precision. So we + * must cast one of its terms to float_t. This makes the whole + * expression have type float_t, so return is forced to waste + * time clobbering its extra precision. + */ + if (sizeof(float_t) > sizeof(float)) + return (r - hfsq + f) * ((float_t)ivln2lo + ivln2hi) + y; + + hi = f - hfsq; + GET_FLOAT_WORD(hx,hi); + SET_FLOAT_WORD(hi,hx&0xfffff000); + lo = (f - hi) - hfsq + r; + return (lo+hi)*ivln2lo + lo*ivln2hi + hi*ivln2hi + y; +} diff --git a/src/e_logf.c b/src/e_logf.c index 92c7cad..74ade3f 100644 --- a/src/e_logf.c +++ b/src/e_logf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_logf.c,v 1.11 2008/03/29 16:37:59 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/e_pow.c b/src/e_pow.c index c9f3580..5d0f717 100644 --- a/src/e_pow.c +++ b/src/e_pow.c @@ -10,7 +10,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_pow.c,v 1.14 2011/10/21 06:26:07 das Exp $"); /* __ieee754_pow(x,y) return x**y * @@ -57,7 +57,7 @@ * to produce the hexadecimal values shown. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double @@ -109,6 +109,9 @@ __ieee754_pow(double x, double y) /* y==zero: x**0 = 1 */ if((iy|ly)==0) return one; + /* x==1: 1**y = 1, even if y is NaN */ + if (hx==0x3ff00000 && lx == 0) return one; + /* y!=zero: result is NaN if either arg is NaN */ if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) @@ -138,7 +141,7 @@ __ieee754_pow(double x, double y) if(ly==0) { if (iy==0x7ff00000) { /* y is +-inf */ if(((ix-0x3ff00000)|lx)==0) - return y - y; /* inf**+-1 is NaN */ + return one; /* (-1)**+-inf is NaN */ else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ return (hy>=0)? y: zero; else /* (|x|<1)**-,+inf = inf,0 */ diff --git a/src/e_powf.c b/src/e_powf.c index b023e83..e31b0d3 100644 --- a/src/e_powf.c +++ b/src/e_powf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_powf.c,v 1.16 2011/10/21 06:26:07 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float @@ -67,6 +67,9 @@ __ieee754_powf(float x, float y) /* y==zero: x**0 = 1 */ if(iy==0) return one; + /* x==1: 1**y = 1, even if y is NaN */ + if (hx==0x3f800000) return one; + /* y!=zero: result is NaN if either arg is NaN */ if(ix > 0x7f800000 || iy > 0x7f800000) @@ -90,7 +93,7 @@ __ieee754_powf(float x, float y) /* special value of y */ if (iy==0x7f800000) { /* y is +-inf */ if (ix==0x3f800000) - return y - y; /* inf**+-1 is NaN */ + return one; /* (-1)**+-inf is NaN */ else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */ return (hy>=0)? y: zero; else /* (|x|<1)**-,+inf = inf,0 */ diff --git a/src/e_rem_pio2.c b/src/e_rem_pio2.c index a485703..dec668a 100644 --- a/src/e_rem_pio2.c +++ b/src/e_rem_pio2.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_rem_pio2.c,v 1.22 2011/06/19 17:07:58 kargl Exp $"); /* __ieee754_rem_pio2(x,y) * @@ -24,7 +24,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* diff --git a/src/e_rem_pio2f.c b/src/e_rem_pio2f.c index a0cbe92..dd194fc 100644 --- a/src/e_rem_pio2f.c +++ b/src/e_rem_pio2f.c @@ -15,7 +15,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_rem_pio2f.c,v 1.32 2009/06/03 08:16:34 ed Exp $"); /* __ieee754_rem_pio2f(x,y) * @@ -26,7 +26,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* diff --git a/src/e_remainder.c b/src/e_remainder.c index 1e24abb..9280cb4 100644 --- a/src/e_remainder.c +++ b/src/e_remainder.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_remainder.c,v 1.12 2008/03/30 20:47:42 das Exp $"); /* __ieee754_remainder(x,p) * Return : @@ -25,7 +25,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double zero = 0.0; diff --git a/src/e_remainderf.c b/src/e_remainderf.c index 6600587..12b26c7 100644 --- a/src/e_remainderf.c +++ b/src/e_remainderf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_remainderf.c,v 1.8 2008/02/12 17:11:36 bde Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float zero = 0.0; diff --git a/src/e_remainderl.c b/src/e_remainderl.c index b72bb9f..d496276 100644 --- a/src/e_remainderl.c +++ b/src/e_remainderl.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_remainderl.c,v 1.1 2008/03/30 20:47:42 das Exp $"); - -#include "openlibm.h" +#include long double remainderl(long double x, long double y) diff --git a/src/e_scalb.c b/src/e_scalb.c index 3780146..d3231b4 100644 --- a/src/e_scalb.c +++ b/src/e_scalb.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_scalb.c,v 1.13 2008/02/22 02:30:35 das Exp $"); /* * __ieee754_scalb(x, fn) is provide for @@ -20,7 +20,7 @@ * should use scalbn() instead. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" #ifdef _SCALB_INT diff --git a/src/e_scalbf.c b/src/e_scalbf.c index 21c8f3e..72f26e5 100644 --- a/src/e_scalbf.c +++ b/src/e_scalbf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_scalbf.c,v 1.13 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" #ifdef _SCALB_INT diff --git a/src/e_sinh.c b/src/e_sinh.c index f3e2eff..a35b51c 100644 --- a/src/e_sinh.c +++ b/src/e_sinh.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_sinh.c,v 1.11 2011/10/21 06:28:47 das Exp $"); /* __ieee754_sinh(x) * Method : @@ -32,7 +32,7 @@ * only sinh(0)=0 is exact for finite x. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, shuge = 1.0e307; @@ -40,9 +40,8 @@ static const double one = 1.0, shuge = 1.0e307; double __ieee754_sinh(double x) { - double t,w,h; + double t,h; int32_t ix,jx; - u_int32_t lx; /* High word of |x|. */ GET_HIGH_WORD(jx,x); @@ -66,12 +65,8 @@ __ieee754_sinh(double x) if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); /* |x| in [log(maxdouble), overflowthresold] */ - GET_LOW_WORD(lx,x); - if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) { - w = __ieee754_exp(0.5*fabs(x)); - t = h*w; - return t*w; - } + if (ix<=0x408633CE) + return h*2.0*__ldexp_exp(fabs(x), -1); /* |x| > overflowthresold, sinh(x) overflow */ return x*shuge; diff --git a/src/e_sinhf.c b/src/e_sinhf.c index c13d35f..c00b5bf 100644 --- a/src/e_sinhf.c +++ b/src/e_sinhf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/e_sinhf.c,v 1.10 2011/10/21 06:28:47 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0, shuge = 1.0e37; @@ -24,7 +24,7 @@ static const float one = 1.0, shuge = 1.0e37; float __ieee754_sinhf(float x) { - float t,w,h; + float t,h; int32_t ix,jx; GET_FLOAT_WORD(jx,x); @@ -48,11 +48,8 @@ __ieee754_sinhf(float x) if (ix < 0x42b17217) return h*__ieee754_expf(fabsf(x)); /* |x| in [logf(maxfloat), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = __ieee754_expf((float)0.5*fabsf(x)); - t = h*w; - return t*w; - } + if (ix<=0x42b2d4fc) + return h*2.0F*__ldexp_expf(fabsf(x), -1); /* |x| > overflowthresold, sinh(x) overflow */ return x*shuge; diff --git a/src/e_sqrt.c b/src/e_sqrt.c index a15516c..83095a1 100644 --- a/src/e_sqrt.c +++ b/src/e_sqrt.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_sqrt.c,v 1.11 2008/03/02 01:47:58 das Exp $"); /* __ieee754_sqrt(x) * Return correctly rounded sqrt. @@ -86,7 +86,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, tiny=1.0e-300; diff --git a/src/e_sqrtf.c b/src/e_sqrtf.c index e48f9a8..edc9ef2 100644 --- a/src/e_sqrtf.c +++ b/src/e_sqrtf.c @@ -17,7 +17,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrtf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; #endif -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0, tiny=1.0e-30; diff --git a/src/e_sqrtl.c b/src/e_sqrtl.c index 5f5d899..d2e1e6a 100644 --- a/src/e_sqrtl.c +++ b/src/e_sqrtl.c @@ -25,13 +25,13 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/e_sqrtl.c,v 1.1 2008/03/02 01:47:58 das Exp $"); #include #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" /* Return (x + ulp) for normal positive x. Assumes no overflow. */ static inline long double diff --git a/src/k_cos.c b/src/k_cos.c index f6c3204..2e0757e 100644 --- a/src/k_cos.c +++ b/src/k_cos.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_cos.c,v 1.12 2008/02/19 12:54:14 bde Exp $"); /* * __kernel_cos( x, y ) @@ -53,7 +53,7 @@ * any extra precision in w. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/k_cosf.c b/src/k_cosf.c index 3af3db0..551b7d2 100644 --- a/src/k_cosf.c +++ b/src/k_cosf.c @@ -16,10 +16,10 @@ #ifndef INLINE_KERNEL_COSDF #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_cosf.c,v 1.18 2009/06/03 08:16:34 ed Exp $"); #endif -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */ diff --git a/src/k_exp.c b/src/k_exp.c new file mode 100644 index 0000000..71d19d3 --- /dev/null +++ b/src/k_exp.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/k_exp.c,v 1.1 2011/10/21 06:27:56 das Exp $"); + +#include + +#include "math.h" +#include "math_private.h" + +static const uint32_t k = 1799; /* constant for reduction */ +static const double kln2 = 1246.97177782734161156; /* k * ln2 */ + +/* + * Compute exp(x), scaled to avoid spurious overflow. An exponent is + * returned separately in 'expt'. + * + * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91 + * Output: 2**1023 <= y < 2**1024 + */ +static double +__frexp_exp(double x, int *expt) +{ + double exp_x; + uint32_t hx; + + /* + * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to + * minimize |exp(kln2) - 2**k|. We also scale the exponent of + * exp_x to MAX_EXP so that the result can be multiplied by + * a tiny number without losing accuracy due to denormalization. + */ + exp_x = exp(x - kln2); + GET_HIGH_WORD(hx, exp_x); + *expt = (hx >> 20) - (0x3ff + 1023) + k; + SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20)); + return (exp_x); +} + +/* + * __ldexp_exp(x, expt) and __ldexp_cexp(x, expt) compute exp(x) * 2**expt. + * They are intended for large arguments (real part >= ln(DBL_MAX)) + * where care is needed to avoid overflow. + * + * The present implementation is narrowly tailored for our hyperbolic and + * exponential functions. We assume expt is small (0 or -1), and the caller + * has filtered out very large x, for which overflow would be inevitable. + */ + +double +__ldexp_exp(double x, int expt) +{ + double exp_x, scale; + int ex_expt; + + exp_x = __frexp_exp(x, &ex_expt); + expt += ex_expt; + INSERT_WORDS(scale, (0x3ff + expt) << 20, 0); + return (exp_x * scale); +} + +double complex +__ldexp_cexp(double complex z, int expt) +{ + double x, y, exp_x, scale1, scale2; + int ex_expt, half_expt; + + x = creal(z); + y = cimag(z); + exp_x = __frexp_exp(x, &ex_expt); + expt += ex_expt; + + /* + * Arrange so that scale1 * scale2 == 2**expt. We use this to + * compensate for scalbn being horrendously slow. + */ + half_expt = expt / 2; + INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0); + half_expt = expt - half_expt; + INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0); + + return (cpack(cos(y) * exp_x * scale1 * scale2, + sin(y) * exp_x * scale1 * scale2)); +} diff --git a/src/k_expf.c b/src/k_expf.c new file mode 100644 index 0000000..c8cb5ae --- /dev/null +++ b/src/k_expf.c @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/k_expf.c,v 1.1 2011/10/21 06:27:56 das Exp $"); + +#include + +#include "math.h" +#include "math_private.h" + +static const uint32_t k = 235; /* constant for reduction */ +static const float kln2 = 162.88958740F; /* k * ln2 */ + +/* + * See k_exp.c for details. + * + * Input: ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7 + * Output: 2**127 <= y < 2**128 + */ +static float +__frexp_expf(float x, int *expt) +{ + double exp_x; + uint32_t hx; + + exp_x = expf(x - kln2); + GET_FLOAT_WORD(hx, exp_x); + *expt = (hx >> 23) - (0x7f + 127) + k; + SET_FLOAT_WORD(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23)); + return (exp_x); +} + +float +__ldexp_expf(float x, int expt) +{ + float exp_x, scale; + int ex_expt; + + exp_x = __frexp_expf(x, &ex_expt); + expt += ex_expt; + SET_FLOAT_WORD(scale, (0x7f + expt) << 23); + return (exp_x * scale); +} + +float complex +__ldexp_cexpf(float complex z, int expt) +{ + float x, y, exp_x, scale1, scale2; + int ex_expt, half_expt; + + x = crealf(z); + y = cimagf(z); + exp_x = __frexp_expf(x, &ex_expt); + expt += ex_expt; + + half_expt = expt / 2; + SET_FLOAT_WORD(scale1, (0x7f + half_expt) << 23); + half_expt = expt - half_expt; + SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23); + + return (cpackf(cosf(y) * exp_x * scale1 * scale2, + sinf(y) * exp_x * scale1 * scale2)); +} diff --git a/src/k_log.h b/src/k_log.h index 7523134..90fac98 100644 --- a/src/k_log.h +++ b/src/k_log.h @@ -12,9 +12,11 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/k_log.h,v 1.2 2011/10/15 05:23:28 das Exp $"); -/* __kernel_log(x) - * Return log(x) - (x-1) for x in ~[sqrt(2)/2, sqrt(2)]. +/* + * k_log1p(f): + * Return log(1+f) - f for 1+f in ~[sqrt(2)/2, sqrt(2)]. * * The following describes the overall strategy for computing * logarithms in base e. The argument reduction and adding the final @@ -79,37 +81,20 @@ Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ /* - * We always inline __kernel_log(), since doing so produces a + * We always inline k_log1p(), since doing so produces a * substantial performance improvement (~40% on amd64). */ static inline double -__kernel_log(double x) +k_log1p(double f) { - double hfsq,f,s,z,R,w,t1,t2; - int32_t hx,i,j; - u_int32_t lx; + double hfsq,s,z,R,w,t1,t2; - EXTRACT_WORDS(hx,lx,x); - - f = x-1.0; - if((0x000fffff&(2+hx))<3) { /* -2**-20 <= f < 2**-20 */ - if(f==0.0) return 0.0; - return f*f*(0.33333333333333333*f-0.5); - } - s = f/(2.0+f); + s = f/(2.0+f); z = s*s; - hx &= 0x000fffff; - i = hx-0x6147a; w = z*z; - j = 0x6b851-hx; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; + t1= w*(Lg2+w*(Lg4+w*Lg6)); + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); R = t2+t1; - if (i>0) { - hfsq=0.5*f*f; - return s*(hfsq+R) - hfsq; - } else { - return s*(R-f); - } + hfsq=0.5*f*f; + return s*(hfsq+R); } diff --git a/src/k_logf.h b/src/k_logf.h index ebc5e40..fffef1c 100644 --- a/src/k_logf.h +++ b/src/k_logf.h @@ -10,9 +10,10 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/k_logf.h,v 1.3 2011/10/15 05:23:28 das Exp $"); -/* __kernel_logf(x) - * Return log(x) - (x-1) for x in ~[sqrt(2)/2, sqrt(2)]. +/* + * Float version of k_log.h. See the latter for most comments. */ static const float @@ -23,32 +24,16 @@ Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ static inline float -__kernel_logf(float x) +k_log1pf(float f) { - float hfsq,f,s,z,R,w,t1,t2; - int32_t ix,i,j; + float hfsq,s,z,R,w,t1,t2; - GET_FLOAT_WORD(ix,x); - - f = x-(float)1.0; - if((0x007fffff&(0x8000+ix))<0xc000) { /* -2**-9 <= f < 2**-9 */ - if(f==0.0) return 0.0; - return f*f*((float)0.33333333333333333*f-(float)0.5); - } s = f/((float)2.0+f); z = s*s; - ix &= 0x007fffff; - i = ix-(0x6147a<<3); w = z*z; - j = (0x6b851<<3)-ix; t1= w*(Lg2+w*Lg4); t2= z*(Lg1+w*Lg3); - i |= j; R = t2+t1; - if(i>0) { - hfsq=(float)0.5*f*f; - return s*(hfsq+R) - hfsq; - } else { - return s*(R-f); - } + hfsq=(float)0.5*f*f; + return s*(hfsq+R); } diff --git a/src/k_rem_pio2.c b/src/k_rem_pio2.c index 52d27b7..1598281 100644 --- a/src/k_rem_pio2.c +++ b/src/k_rem_pio2.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_rem_pio2.c,v 1.11 2008/02/25 11:43:20 bde Exp $"); /* * __kernel_rem_pio2(x,y,e0,nx,prec) @@ -131,7 +131,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ diff --git a/src/k_sin.c b/src/k_sin.c index 70616da..172dc15 100644 --- a/src/k_sin.c +++ b/src/k_sin.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_sin.c,v 1.11 2008/02/19 12:54:14 bde Exp $"); /* __kernel_sin( x, y, iy) * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 @@ -44,7 +44,7 @@ * sin(x) = x + (S1*x + (x *(r-y/2)+y)) */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/k_sinf.c b/src/k_sinf.c index 80848be..f00d9cd 100644 --- a/src/k_sinf.c +++ b/src/k_sinf.c @@ -16,10 +16,10 @@ #ifndef INLINE_KERNEL_SINDF #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_sinf.c,v 1.16 2009/06/03 08:16:34 ed Exp $"); #endif -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */ diff --git a/src/k_tan.c b/src/k_tan.c index 7d90bc2..e267058 100644 --- a/src/k_tan.c +++ b/src/k_tan.c @@ -12,7 +12,7 @@ /* INDENT OFF */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_tan.c,v 1.13 2008/02/22 02:30:35 das Exp $"); /* __kernel_tan( x, y, k ) * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 @@ -49,7 +49,7 @@ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double xxx[] = { 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ diff --git a/src/k_tanf.c b/src/k_tanf.c index 3da90fa..08652e7 100644 --- a/src/k_tanf.c +++ b/src/k_tanf.c @@ -15,10 +15,10 @@ #ifndef INLINE_KERNEL_TANDF #include - +__FBSDID("$FreeBSD: src/lib/msun/src/k_tanf.c,v 1.23 2009/06/03 08:16:34 ed Exp $"); #endif -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ diff --git a/src/openlibm.h b/src/math.h similarity index 94% rename from src/openlibm.h rename to src/math.h index 6c94267..4b0b85e 100644 --- a/src/openlibm.h +++ b/src/math.h @@ -11,15 +11,15 @@ /* * from: @(#)fdlibm.h 5.1 93/09/24 - * $FreeBSD: src/lib/msun/src/math.h,v 1.80 2011/03/12 16:50:39 kargl Exp $ + * $FreeBSD: src/lib/msun/src/math.h,v 1.82 2011/11/12 19:55:48 theraven Exp $ */ #ifndef _MATH_H_ #define _MATH_H_ #include -#include -#include +#include +#include /* * ANSI/POSIX @@ -34,13 +34,13 @@ extern const union __nan_un { float __uf; } __nan; -//#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) #define __MATH_BUILTIN_CONSTANTS -//#endif +#endif -//#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) +#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) #define __MATH_BUILTIN_RELOPS -//#endif +#endif #ifdef __MATH_BUILTIN_CONSTANTS #define HUGE_VAL __builtin_huge_val() @@ -68,14 +68,11 @@ extern const union __nan_un { #define MATH_ERREXCEPT 2 #define math_errhandling MATH_ERREXCEPT -/* XXX We need a . */ -#if defined(__ia64__) || defined(__sparc64__) -#define FP_FAST_FMA 1 -#endif +#define FP_FAST_FMAF 1 #ifdef __ia64__ +#define FP_FAST_FMA 1 #define FP_FAST_FMAL 1 #endif -#define FP_FAST_FMAF 1 /* Symbolic constants to classify floating point numbers. */ #define FP_INFINITE 0x01 @@ -134,7 +131,7 @@ typedef __float_t float_t; /* * XOPEN/SVID */ -//#if __BSD_VISIBLE || __XSI_VISIBLE +#if __BSD_VISIBLE || __XSI_VISIBLE #define M_E 2.7182818284590452354 /* e */ #define M_LOG2E 1.4426950408889634074 /* log 2e */ #define M_LOG10E 0.43429448190325182765 /* log 10e */ @@ -151,7 +148,7 @@ typedef __float_t float_t; #define MAXFLOAT ((float)3.40282346638528860e+38) extern int signgam; -//#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ #if __BSD_VISIBLE #if 0 @@ -398,32 +395,32 @@ float significandf(float); * long double versions of ISO/POSIX math functions */ #if __ISO_C_VISIBLE >= 1999 -#if 0 +#if _DECLARE_C99_LDBL_MATH long double acoshl(long double); #endif long double acosl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double asinhl(long double); #endif long double asinl(long double); long double atan2l(long double, long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double atanhl(long double); #endif long double atanl(long double); long double cbrtl(long double); long double ceill(long double); long double copysignl(long double, long double) __pure2; -#if 0 +#if _DECLARE_C99_LDBL_MATH long double coshl(long double); #endif long double cosl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double erfcl(long double); long double erfl(long double); #endif long double exp2l(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double expl(long double); long double expm1l(long double); #endif @@ -438,18 +435,18 @@ long double frexpl(long double value, int *); /* fundamentally !__pure2 */ long double hypotl(long double, long double); int ilogbl(long double) __pure2; long double ldexpl(long double, int); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double lgammal(long double); #endif long long llrintl(long double); long long llroundl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double log10l(long double); long double log1pl(long double); long double log2l(long double); #endif long double logbl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double logl(long double); #endif long lrintl(long double); @@ -461,7 +458,7 @@ long double nextafterl(long double, long double); double nexttoward(double, long double); float nexttowardf(float, long double); long double nexttowardl(long double, long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double powl(long double, long double); #endif long double remainderl(long double, long double); @@ -470,16 +467,16 @@ long double rintl(long double); long double roundl(long double); long double scalblnl(long double, long); long double scalbnl(long double, int); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double sinhl(long double); #endif long double sinl(long double); long double sqrtl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double tanhl(long double); #endif long double tanl(long double); -#if 0 +#if _DECLARE_C99_LDBL_MATH long double tgammal(long double); #endif long double truncl(long double); diff --git a/src/math_private.h b/src/math_private.h index 6a22bad..b6f23e6 100644 --- a/src/math_private.h +++ b/src/math_private.h @@ -11,7 +11,7 @@ /* * from: @(#)fdlibm.h 5.1 93/09/24 - * $FreeBSD: src/lib/msun/src/math_private.h,v 1.31 2010/12/05 22:11:22 das Exp $ + * $FreeBSD: src/lib/msun/src/math_private.h,v 1.34 2011/10/21 06:27:56 das Exp $ */ #ifndef _MATH_PRIVATE_H_ @@ -20,10 +20,6 @@ #include #include -#ifdef __APPLE__ -#define uint32_t u_int32_t -#endif - /* * The original fdlibm code used statements like: * n0 = ((*(int*)&one)>>29)^1; * index of high word * @@ -62,6 +58,10 @@ typedef union u_int32_t msw; u_int32_t lsw; } parts; + struct + { + u_int64_t w; + } xparts; } ieee_double_shape_type; #endif @@ -76,6 +76,10 @@ typedef union u_int32_t lsw; u_int32_t msw; } parts; + struct + { + u_int64_t w; + } xparts; } ieee_double_shape_type; #endif @@ -90,6 +94,14 @@ do { \ (ix1) = ew_u.parts.lsw; \ } while (0) +/* Get a 64-bit int from a double. */ +#define EXTRACT_WORD64(ix,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix) = ew_u.xparts.w; \ +} while (0) + /* Get the more significant 32 bit int from a double. */ #define GET_HIGH_WORD(i,d) \ @@ -118,6 +130,14 @@ do { \ (d) = iw_u.value; \ } while (0) +/* Set a double from a 64-bit int. */ +#define INSERT_WORD64(d,ix) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.xparts.w = (ix); \ + (d) = iw_u.value; \ +} while (0) + /* Set the more significant 32 bits of a double from an int. */ #define SET_HIGH_WORD(d,v) \ @@ -168,6 +188,25 @@ do { \ (d) = sf_u.value; \ } while (0) +/* Get expsign as a 16 bit int from a long double. */ + +#define GET_LDBL_EXPSIGN(i,d) \ +do { \ + union IEEEl2bits ge_u; \ + ge_u.e = (d); \ + (i) = ge_u.xbits.expsign; \ +} while (0) + +/* Set expsign of a long double from a 16 bit int. */ + +#define SET_LDBL_EXPSIGN(d,v) \ +do { \ + union IEEEl2bits se_u; \ + se_u.e = (d); \ + se_u.xbits.expsign = (v); \ + (d) = se_u.e; \ +} while (0) + #ifdef FLT_EVAL_METHOD /* * Attempt to get strict C99 semantics for assignment with non-C99 compilers. @@ -358,6 +397,10 @@ int __ieee754_rem_pio2(double,double*); double __kernel_sin(double,double,int); double __kernel_cos(double,double); double __kernel_tan(double,double,int); +double __ldexp_exp(double,int); +#ifdef _COMPLEX_H +double complex __ldexp_cexp(double complex,int); +#endif /* float precision kernel functions */ #ifdef INLINE_REM_PIO2F @@ -376,6 +419,10 @@ float __kernel_cosdf(double); __inline #endif float __kernel_tandf(double,int); +float __ldexp_expf(float,int); +#ifdef _COMPLEX_H +float complex __ldexp_cexpf(float complex,int); +#endif /* long double precision kernel functions */ long double __kernel_sinl(long double, long double, int); diff --git a/src/s_asinh.c b/src/s_asinh.c index 0faa1c5..25c97bd 100644 --- a/src/s_asinh.c +++ b/src/s_asinh.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_asinh.c,v 1.9 2008/02/22 02:30:35 das Exp $"); /* asinh(x) * Method : @@ -24,7 +24,7 @@ * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_asinhf.c b/src/s_asinhf.c index 732c565..8d98378 100644 --- a/src/s_asinhf.c +++ b/src/s_asinhf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_asinhf.c,v 1.9 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_atan.c b/src/s_atan.c index 8cf6484..5f95a3d 100644 --- a/src/s_atan.c +++ b/src/s_atan.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_atan.c,v 1.13 2011/02/10 07:37:50 das Exp $"); /* atan(x) * Method @@ -35,7 +35,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double atanhi[] = { diff --git a/src/s_atanf.c b/src/s_atanf.c index e6e7e9c..ff2afb5 100644 --- a/src/s_atanf.c +++ b/src/s_atanf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_atanf.c,v 1.10 2008/08/01 01:24:25 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float atanhi[] = { diff --git a/src/s_atanl.c b/src/s_atanl.c index 7ea0b3c..280799b 100644 --- a/src/s_atanl.c +++ b/src/s_atanl.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_atanl.c,v 1.1 2008/07/31 22:41:26 das Exp $"); /* * See comments in s_atan.c. @@ -22,7 +22,7 @@ #include #include "invtrig.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const long double diff --git a/src/s_carg.c b/src/s_carg.c index 91cfb47..a9e615d 100644 --- a/src/s_carg.c +++ b/src/s_carg.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_carg.c,v 1.1 2007/12/12 23:43:51 das Exp $"); #include -#include "openlibm.h" +#include double carg(double complex z) diff --git a/src/s_cargf.c b/src/s_cargf.c index e22fabe..c63cfc1 100644 --- a/src/s_cargf.c +++ b/src/s_cargf.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cargf.c,v 1.1 2007/12/12 23:43:51 das Exp $"); #include -#include "openlibm.h" +#include float cargf(float complex z) diff --git a/src/s_cargl.c b/src/s_cargl.c index d3da1d3..c2fe612 100644 --- a/src/s_cargl.c +++ b/src/s_cargl.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cargl.c,v 1.1 2008/07/31 22:41:26 das Exp $"); #include -#include "openlibm.h" +#include long double cargl(long double complex z) diff --git a/src/s_cbrt.c b/src/s_cbrt.c index b00e912..cef02e4 100644 --- a/src/s_cbrt.c +++ b/src/s_cbrt.c @@ -13,8 +13,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_cbrt.c,v 1.17 2011/03/12 16:50:39 kargl Exp $"); -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* cbrt(x) @@ -38,7 +39,7 @@ cbrt(double x) int32_t hx; union { double value; - u_int64_t bits; + uint64_t bits; } u; double r,s,t=0.0,w; u_int32_t sign; diff --git a/src/s_cbrtf.c b/src/s_cbrtf.c index bcd2eb8..510b168 100644 --- a/src/s_cbrtf.c +++ b/src/s_cbrtf.c @@ -15,9 +15,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.18 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" /* cbrtf(x) diff --git a/src/s_cbrtl.c b/src/s_cbrtl.c new file mode 100644 index 0000000..d5c6527 --- /dev/null +++ b/src/s_cbrtl.c @@ -0,0 +1,157 @@ +/*- + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + * The argument reduction and testing for exceptional cases was + * written by Steven G. Kargl with input from Bruce D. Evans + * and David A. Schultz. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_cbrtl.c,v 1.1 2011/03/12 19:37:35 kargl Exp $"); + +#include +#include + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define BIAS (LDBL_MAX_EXP - 1) + +static const unsigned + B1 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */ + +long double +cbrtl(long double x) +{ + union IEEEl2bits u, v; + long double r, s, t, w; + double dr, dt, dx; + float ft, fx; + uint32_t hx; + uint16_t expsign; + int k; + + u.e = x; + expsign = u.xbits.expsign; + k = expsign & 0x7fff; + + /* + * If x = +-Inf, then cbrt(x) = +-Inf. + * If x = NaN, then cbrt(x) = NaN. + */ + if (k == BIAS + LDBL_MAX_EXP) + return (x + x); + +#ifdef __i386__ + fp_prec_t oprec; + + oprec = fpgetprec(); + if (oprec != FP_PE) + fpsetprec(FP_PE); +#endif + + if (k == 0) { + /* If x = +-0, then cbrt(x) = +-0. */ + if ((u.bits.manh | u.bits.manl) == 0) { +#ifdef __i386__ + if (oprec != FP_PE) + fpsetprec(oprec); +#endif + return (x); + } + /* Adjust subnormal numbers. */ + u.e *= 0x1.0p514; + k = u.bits.exp; + k -= BIAS + 514; + } else + k -= BIAS; + u.xbits.expsign = BIAS; + v.e = 1; + + x = u.e; + switch (k % 3) { + case 1: + case -2: + x = 2*x; + k--; + break; + case 2: + case -1: + x = 4*x; + k -= 2; + break; + } + v.xbits.expsign = (expsign & 0x8000) | (BIAS + k / 3); + + /* + * The following is the guts of s_cbrtf, with the handling of + * special values removed and extra care for accuracy not taken, + * but with most of the extra accuracy not discarded. + */ + + /* ~5-bit estimate: */ + fx = x; + GET_FLOAT_WORD(hx, fx); + SET_FLOAT_WORD(ft, ((hx & 0x7fffffff) / 3 + B1)); + + /* ~16-bit estimate: */ + dx = x; + dt = ft; + dr = dt * dt * dt; + dt = dt * (dx + dx + dr) / (dx + dr + dr); + + /* ~47-bit estimate: */ + dr = dt * dt * dt; + dt = dt * (dx + dx + dr) / (dx + dr + dr); + +#if LDBL_MANT_DIG == 64 + /* + * dt is cbrtl(x) to ~47 bits (after x has been reduced to 1 <= x < 8). + * Round it away from zero to 32 bits (32 so that t*t is exact, and + * away from zero for technical reasons). + */ + volatile double vd2 = 0x1.0p32; + volatile double vd1 = 0x1.0p-31; + #define vd ((long double)vd2 + vd1) + + t = dt + vd - 0x1.0p32; +#elif LDBL_MANT_DIG == 113 + /* + * Round dt away from zero to 47 bits. Since we don't trust the 47, + * add 2 47-bit ulps instead of 1 to round up. Rounding is slow and + * might be avoidable in this case, since on most machines dt will + * have been evaluated in 53-bit precision and the technical reasons + * for rounding up might not apply to either case in cbrtl() since + * dt is much more accurate than needed. + */ + t = dt + 0x2.0p-46 + 0x1.0p60L - 0x1.0p60; +#else +#error "Unsupported long double format" +#endif + + /* + * Final step Newton iteration to 64 or 113 bits with + * error < 0.667 ulps + */ + s=t*t; /* t*t is exact */ + r=x/s; /* error <= 0.5 ulps; |r| < |t| */ + w=t+t; /* t+t is exact */ + r=(r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */ + t=t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ + + t *= v.e; +#ifdef __i386__ + if (oprec != FP_PE) + fpsetprec(oprec); +#endif + return (t); +} diff --git a/src/s_ccosh.c b/src/s_ccosh.c new file mode 100644 index 0000000..bdcc6e2 --- /dev/null +++ b/src/s_ccosh.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic cosine of a complex argument z = x + i y. + * + * cosh(z) = cosh(x+iy) + * = cosh(x) cos(y) + i sinh(x) sin(y). + * + * Exceptional values are noted in the comments within the source code. + * These values and the return value were taken from n1124.pdf. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_ccosh.c,v 1.2 2011/10/21 06:29:32 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const double huge = 0x1p1023; + +double complex +ccosh(double complex z) +{ + double x, y, h; + int32_t hx, hy, ix, iy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + EXTRACT_WORDS(hy, ly, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + /* Handle the nearly-non-exceptional cases where x and y are finite. */ + if (ix < 0x7ff00000 && iy < 0x7ff00000) { + if ((iy | ly) == 0) + return (cpack(cosh(x), x * y)); + if (ix < 0x40360000) /* small x: normal case */ + return (cpack(cosh(x) * cos(y), sinh(x) * sin(y))); + + /* |x| >= 22, so cosh(x) ~= exp(|x|) */ + if (ix < 0x40862e42) { + /* x < 710: exp(|x|) won't overflow */ + h = exp(fabs(x)) * 0.5; + return (cpack(h * cos(y), copysign(h, x) * sin(y))); + } else if (ix < 0x4096bbaa) { + /* x < 1455: scale to avoid overflow */ + z = __ldexp_cexp(cpack(fabs(x), y), -1); + return (cpack(creal(z), cimag(z) * copysign(1, x))); + } else { + /* x >= 1455: the result always overflows */ + h = huge * x; + return (cpack(h * h * cos(y), h * sin(y))); + } + } + + /* + * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as dNaN. Raise the invalid floating-point exception. + * + * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as d(NaN). + */ + if ((ix | lx) == 0 && iy >= 0x7ff00000) + return (cpack(y - y, copysign(0, x * (y - y)))); + + /* + * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. + * + * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. + * The sign of 0 in the result is unspecified. + */ + if ((iy | ly) == 0 && ix >= 0x7ff00000) { + if (((hx & 0xfffff) | lx) == 0) + return (cpack(x * x, copysign(0, x) * y)); + return (cpack(x * x, copysign(0, (x + x) * y))); + } + + /* + * cosh(x +- I Inf) = dNaN + I dNaN. + * Raise the invalid floating-point exception for finite nonzero x. + * + * cosh(x + I NaN) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero x. Choice = don't raise (except for signaling NaNs). + */ + if (ix < 0x7ff00000 && iy >= 0x7ff00000) + return (cpack(y - y, x * (y - y))); + + /* + * cosh(+-Inf + I NaN) = +Inf + I d(NaN). + * + * cosh(+-Inf +- I Inf) = +Inf + I dNaN. + * The sign of Inf in the result is unspecified. Choice = always +. + * Raise the invalid floating-point exception. + * + * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) + */ + if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { + if (iy >= 0x7ff00000) + return (cpack(x * x, x * (y - y))); + return (cpack((x * x) * cos(y), x * sin(y))); + } + + /* + * cosh(NaN + I NaN) = d(NaN) + I d(NaN). + * + * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception. + * Choice = raise. + * + * cosh(NaN + I y) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero y. Choice = don't raise (except for signaling NaNs). + */ + return (cpack((x * x) * (y - y), (x + x) * (y - y))); +} + +double complex +ccos(double complex z) +{ + + /* ccos(z) = ccosh(I * z) */ + return (ccosh(cpack(-cimag(z), creal(z)))); +} diff --git a/src/s_ccoshf.c b/src/s_ccoshf.c new file mode 100644 index 0000000..87a4691 --- /dev/null +++ b/src/s_ccoshf.c @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic cosine of a complex argument. See s_ccosh.c for details. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_ccoshf.c,v 1.2 2011/10/21 06:29:32 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const float huge = 0x1p127; + +float complex +ccoshf(float complex z) +{ + float x, y, h; + int32_t hx, hy, ix, iy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hx, x); + GET_FLOAT_WORD(hy, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + if (ix < 0x7f800000 && iy < 0x7f800000) { + if (iy == 0) + return (cpackf(coshf(x), x * y)); + if (ix < 0x41100000) /* small x: normal case */ + return (cpackf(coshf(x) * cosf(y), sinhf(x) * sinf(y))); + + /* |x| >= 9, so cosh(x) ~= exp(|x|) */ + if (ix < 0x42b17218) { + /* x < 88.7: expf(|x|) won't overflow */ + h = expf(fabsf(x)) * 0.5f; + return (cpackf(h * cosf(y), copysignf(h, x) * sinf(y))); + } else if (ix < 0x4340b1e7) { + /* x < 192.7: scale to avoid overflow */ + z = __ldexp_cexpf(cpackf(fabsf(x), y), -1); + return (cpackf(crealf(z), cimagf(z) * copysignf(1, x))); + } else { + /* x >= 192.7: the result always overflows */ + h = huge * x; + return (cpackf(h * h * cosf(y), h * sinf(y))); + } + } + + if (ix == 0 && iy >= 0x7f800000) + return (cpackf(y - y, copysignf(0, x * (y - y)))); + + if (iy == 0 && ix >= 0x7f800000) { + if ((hx & 0x7fffff) == 0) + return (cpackf(x * x, copysignf(0, x) * y)); + return (cpackf(x * x, copysignf(0, (x + x) * y))); + } + + if (ix < 0x7f800000 && iy >= 0x7f800000) + return (cpackf(y - y, x * (y - y))); + + if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { + if (iy >= 0x7f800000) + return (cpackf(x * x, x * (y - y))); + return (cpackf((x * x) * cosf(y), x * sinf(y))); + } + + return (cpackf((x * x) * (y - y), (x + x) * (y - y))); +} + +float complex +ccosf(float complex z) +{ + + return (ccoshf(cpackf(-cimagf(z), crealf(z)))); +} diff --git a/src/s_ceil.c b/src/s_ceil.c index b4a0035..07ab0cb 100644 --- a/src/s_ceil.c +++ b/src/s_ceil.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_ceil.c,v 1.11 2008/02/15 07:01:40 bde Exp $"); /* * ceil(x) @@ -24,7 +24,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; diff --git a/src/s_ceilf.c b/src/s_ceilf.c index d8b26a3..e4a05bd 100644 --- a/src/s_ceilf.c +++ b/src/s_ceilf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_ceilf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float huge = 1.0e30; diff --git a/src/s_ceill.c b/src/s_ceill.c index d19bdd3..8e346a9 100644 --- a/src/s_ceill.c +++ b/src/s_ceill.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_ceill.c,v 1.9 2008/02/14 15:10:33 bde Exp $"); /* * ceill(x) @@ -24,7 +24,7 @@ */ #include -#include "openlibm.h" +#include #include #include "fpmath.h" @@ -32,7 +32,7 @@ #ifdef LDBL_IMPLICIT_NBIT #define MANH_SIZE (LDBL_MANH_SIZE + 1) #define INC_MANH(u, c) do { \ - u_int64_t o = u.bits.manh; \ + uint64_t o = u.bits.manh; \ u.bits.manh += (c); \ if (u.bits.manh < o) \ u.bits.exp++; \ @@ -40,7 +40,7 @@ #else #define MANH_SIZE LDBL_MANH_SIZE #define INC_MANH(u, c) do { \ - u_int64_t o = u.bits.manh; \ + uint64_t o = u.bits.manh; \ u.bits.manh += (c); \ if (u.bits.manh < o) { \ u.bits.exp++; \ @@ -64,7 +64,7 @@ ceill(long double x) (u.bits.manh | u.bits.manl) != 0) u.e = u.bits.sign ? -0.0 : 1.0; } else { - u_int64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); + uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); if (((u.bits.manh & m) | u.bits.manl) == 0) return (x); /* x is integral */ if (!u.bits.sign) { @@ -81,14 +81,14 @@ ceill(long double x) } } } else if (e < LDBL_MANT_DIG - 1) { - u_int64_t m = (u_int64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); + uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); if ((u.bits.manl & m) == 0) return (x); /* x is integral */ if (!u.bits.sign) { if (e == MANH_SIZE - 1) INC_MANH(u, 1); else { - u_int64_t o = u.bits.manl; + uint64_t o = u.bits.manl; u.bits.manl += 1llu << (LDBL_MANT_DIG - e - 1); if (u.bits.manl < o) /* got a carry */ INC_MANH(u, 1); diff --git a/src/s_cexp.c b/src/s_cexp.c new file mode 100644 index 0000000..a91a065 --- /dev/null +++ b/src/s_cexp.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_cexp.c,v 1.3 2011/10/21 06:27:56 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const uint32_t +exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */ +cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ + +double complex +cexp(double complex z) +{ + double x, y, exp_x; + uint32_t hx, hy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hy, ly, y); + hy &= 0x7fffffff; + + /* cexp(x + I 0) = exp(x) + I 0 */ + if ((hy | ly) == 0) + return (cpack(exp(x), y)); + EXTRACT_WORDS(hx, lx, x); + /* cexp(0 + I y) = cos(y) + I sin(y) */ + if (((hx & 0x7fffffff) | lx) == 0) + return (cpack(cos(y), sin(y))); + + if (hy >= 0x7ff00000) { + if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) { + /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ + return (cpack(y - y, y - y)); + } else if (hx & 0x80000000) { + /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ + return (cpack(0.0, 0.0)); + } else { + /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ + return (cpack(x, y - y)); + } + } + + if (hx >= exp_ovfl && hx <= cexp_ovfl) { + /* + * x is between 709.7 and 1454.3, so we must scale to avoid + * overflow in exp(x). + */ + return (__ldexp_cexp(z, 0)); + } else { + /* + * Cases covered here: + * - x < exp_ovfl and exp(x) won't overflow (common case) + * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 + * - x = +-Inf (generated by exp()) + * - x = NaN (spurious inexact exception from y) + */ + exp_x = exp(x); + return (cpack(exp_x * cos(y), exp_x * sin(y))); + } +} diff --git a/src/s_cexpf.c b/src/s_cexpf.c new file mode 100644 index 0000000..0e4253f --- /dev/null +++ b/src/s_cexpf.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_cexpf.c,v 1.3 2011/10/21 06:27:56 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const uint32_t +exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */ +cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ + +float complex +cexpf(float complex z) +{ + float x, y, exp_x; + uint32_t hx, hy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hy, y); + hy &= 0x7fffffff; + + /* cexp(x + I 0) = exp(x) + I 0 */ + if (hy == 0) + return (cpackf(expf(x), y)); + GET_FLOAT_WORD(hx, x); + /* cexp(0 + I y) = cos(y) + I sin(y) */ + if ((hx & 0x7fffffff) == 0) + return (cpackf(cosf(y), sinf(y))); + + if (hy >= 0x7f800000) { + if ((hx & 0x7fffffff) != 0x7f800000) { + /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ + return (cpackf(y - y, y - y)); + } else if (hx & 0x80000000) { + /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ + return (cpackf(0.0, 0.0)); + } else { + /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ + return (cpackf(x, y - y)); + } + } + + if (hx >= exp_ovfl && hx <= cexp_ovfl) { + /* + * x is between 88.7 and 192, so we must scale to avoid + * overflow in expf(x). + */ + return (__ldexp_cexpf(z, 0)); + } else { + /* + * Cases covered here: + * - x < exp_ovfl and exp(x) won't overflow (common case) + * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 + * - x = +-Inf (generated by exp()) + * - x = NaN (spurious inexact exception from y) + */ + exp_x = expf(x); + return (cpackf(exp_x * cosf(y), exp_x * sinf(y))); + } +} diff --git a/src/s_copysign.c b/src/s_copysign.c index 7d9db98..6be01da 100644 --- a/src/s_copysign.c +++ b/src/s_copysign.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_copysign.c,v 1.10 2008/02/22 02:30:35 das Exp $"); /* * copysign(double x, double y) @@ -19,7 +19,7 @@ * with the sign bit of y. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" double diff --git a/src/s_copysignf.c b/src/s_copysignf.c index da221a1..f7149c9 100644 --- a/src/s_copysignf.c +++ b/src/s_copysignf.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_copysignf.c,v 1.10 2008/02/22 02:30:35 das Exp $"); /* * copysignf(float x, float y) @@ -22,7 +22,7 @@ * with the sign bit of y. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" float diff --git a/src/s_copysignl.c b/src/s_copysignl.c index b994247..1bb755b 100644 --- a/src/s_copysignl.c +++ b/src/s_copysignl.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/src/s_copysignl.c,v 1.2 2007/01/07 07:54:21 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_cos.c b/src/s_cos.c index 1775a90..618d2a8 100644 --- a/src/s_cos.c +++ b/src/s_cos.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cos.c,v 1.13 2011/02/10 07:37:50 das Exp $"); /* cos(x) * Return cosine function of x. @@ -46,7 +46,7 @@ #include -#include "openlibm.h" +#include "math.h" #define INLINE_REM_PIO2 #include "math_private.h" #include "e_rem_pio2.c" diff --git a/src/s_cosf.c b/src/s_cosf.c index ce83900..e8ad14a 100644 --- a/src/s_cosf.c +++ b/src/s_cosf.c @@ -15,11 +15,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cosf.c,v 1.18 2008/02/25 22:19:17 bde Exp $"); #include -#include "openlibm.h" +#include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF #define INLINE_REM_PIO2F diff --git a/src/s_cosl.c b/src/s_cosl.c index c535226..8235188 100644 --- a/src/s_cosl.c +++ b/src/s_cosl.c @@ -25,7 +25,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cosl.c,v 1.3 2011/05/30 19:41:28 kargl Exp $"); /* * Limited testing on pseudorandom numbers drawn within [-2e8:4e8] shows @@ -34,7 +34,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #if LDBL_MANT_DIG == 64 #include "../ld80/e_rem_pio2l.h" diff --git a/src/s_cproj.c b/src/s_cproj.c index 0de8951..c0c7b87 100644 --- a/src/s_cproj.c +++ b/src/s_cproj.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cproj.c,v 1.1 2008/08/07 15:07:48 das Exp $"); #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_cprojf.c b/src/s_cprojf.c index 8663708..a3ac046 100644 --- a/src/s_cprojf.c +++ b/src/s_cprojf.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cprojf.c,v 1.1 2008/08/07 15:07:48 das Exp $"); #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_cprojl.c b/src/s_cprojl.c index b5a863b..c2db73b 100644 --- a/src/s_cprojl.c +++ b/src/s_cprojl.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_cprojl.c,v 1.1 2008/08/07 15:07:48 das Exp $"); #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_csinh.c b/src/s_csinh.c new file mode 100644 index 0000000..7d6b1e7 --- /dev/null +++ b/src/s_csinh.c @@ -0,0 +1,157 @@ +/*- + * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic sine of a complex argument z = x + i y. + * + * sinh(z) = sinh(x+iy) + * = sinh(x) cos(y) + i cosh(x) sin(y). + * + * Exceptional values are noted in the comments within the source code. + * These values and the return value were taken from n1124.pdf. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_csinh.c,v 1.2 2011/10/21 06:29:32 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const double huge = 0x1p1023; + +double complex +csinh(double complex z) +{ + double x, y, h; + int32_t hx, hy, ix, iy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + EXTRACT_WORDS(hy, ly, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + /* Handle the nearly-non-exceptional cases where x and y are finite. */ + if (ix < 0x7ff00000 && iy < 0x7ff00000) { + if ((iy | ly) == 0) + return (cpack(sinh(x), y)); + if (ix < 0x40360000) /* small x: normal case */ + return (cpack(sinh(x) * cos(y), cosh(x) * sin(y))); + + /* |x| >= 22, so cosh(x) ~= exp(|x|) */ + if (ix < 0x40862e42) { + /* x < 710: exp(|x|) won't overflow */ + h = exp(fabs(x)) * 0.5; + return (cpack(copysign(h, x) * cos(y), h * sin(y))); + } else if (ix < 0x4096bbaa) { + /* x < 1455: scale to avoid overflow */ + z = __ldexp_cexp(cpack(fabs(x), y), -1); + return (cpack(creal(z) * copysign(1, x), cimag(z))); + } else { + /* x >= 1455: the result always overflows */ + h = huge * x; + return (cpack(h * cos(y), h * h * sin(y))); + } + } + + /* + * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as dNaN. Raise the invalid floating-point exception. + * + * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN). + * The sign of 0 in the result is unspecified. Choice = normally + * the same as d(NaN). + */ + if ((ix | lx) == 0 && iy >= 0x7ff00000) + return (cpack(copysign(0, x * (y - y)), y - y)); + + /* + * sinh(+-Inf +- I 0) = +-Inf + I +-0. + * + * sinh(NaN +- I 0) = d(NaN) + I +-0. + */ + if ((iy | ly) == 0 && ix >= 0x7ff00000) { + if (((hx & 0xfffff) | lx) == 0) + return (cpack(x, y)); + return (cpack(x, copysign(0, y))); + } + + /* + * sinh(x +- I Inf) = dNaN + I dNaN. + * Raise the invalid floating-point exception for finite nonzero x. + * + * sinh(x + I NaN) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero x. Choice = don't raise (except for signaling NaNs). + */ + if (ix < 0x7ff00000 && iy >= 0x7ff00000) + return (cpack(y - y, x * (y - y))); + + /* + * sinh(+-Inf + I NaN) = +-Inf + I d(NaN). + * The sign of Inf in the result is unspecified. Choice = normally + * the same as d(NaN). + * + * sinh(+-Inf +- I Inf) = +Inf + I dNaN. + * The sign of Inf in the result is unspecified. Choice = always +. + * Raise the invalid floating-point exception. + * + * sinh(+-Inf + I y) = +-Inf cos(y) + I Inf sin(y) + */ + if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { + if (iy >= 0x7ff00000) + return (cpack(x * x, x * (y - y))); + return (cpack(x * cos(y), INFINITY * sin(y))); + } + + /* + * sinh(NaN + I NaN) = d(NaN) + I d(NaN). + * + * sinh(NaN +- I Inf) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception. + * Choice = raise. + * + * sinh(NaN + I y) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero y. Choice = don't raise (except for signaling NaNs). + */ + return (cpack((x * x) * (y - y), (x + x) * (y - y))); +} + +double complex +csin(double complex z) +{ + + /* csin(z) = -I * csinh(I * z) */ + z = csinh(cpack(-cimag(z), creal(z))); + return (cpack(cimag(z), -creal(z))); +} diff --git a/src/s_csinhf.c b/src/s_csinhf.c new file mode 100644 index 0000000..d3ed5ed --- /dev/null +++ b/src/s_csinhf.c @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic sine of a complex argument z. See s_csinh.c for details. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_csinhf.c,v 1.2 2011/10/21 06:29:32 das Exp $"); + +#include +#include + +#include "math_private.h" + +static const float huge = 0x1p127; + +float complex +csinhf(float complex z) +{ + float x, y, h; + int32_t hx, hy, ix, iy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hx, x); + GET_FLOAT_WORD(hy, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + if (ix < 0x7f800000 && iy < 0x7f800000) { + if (iy == 0) + return (cpackf(sinhf(x), y)); + if (ix < 0x41100000) /* small x: normal case */ + return (cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y))); + + /* |x| >= 9, so cosh(x) ~= exp(|x|) */ + if (ix < 0x42b17218) { + /* x < 88.7: expf(|x|) won't overflow */ + h = expf(fabsf(x)) * 0.5f; + return (cpackf(copysignf(h, x) * cosf(y), h * sinf(y))); + } else if (ix < 0x4340b1e7) { + /* x < 192.7: scale to avoid overflow */ + z = __ldexp_cexpf(cpackf(fabsf(x), y), -1); + return (cpackf(crealf(z) * copysignf(1, x), cimagf(z))); + } else { + /* x >= 192.7: the result always overflows */ + h = huge * x; + return (cpackf(h * cosf(y), h * h * sinf(y))); + } + } + + if (ix == 0 && iy >= 0x7f800000) + return (cpackf(copysignf(0, x * (y - y)), y - y)); + + if (iy == 0 && ix >= 0x7f800000) { + if ((hx & 0x7fffff) == 0) + return (cpackf(x, y)); + return (cpackf(x, copysignf(0, y))); + } + + if (ix < 0x7f800000 && iy >= 0x7f800000) + return (cpackf(y - y, x * (y - y))); + + if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { + if (iy >= 0x7f800000) + return (cpackf(x * x, x * (y - y))); + return (cpackf(x * cosf(y), INFINITY * sinf(y))); + } + + return (cpackf((x * x) * (y - y), (x + x) * (y - y))); +} + +float complex +csinf(float complex z) +{ + + z = csinhf(cpackf(-cimagf(z), crealf(z))); + return (cpackf(cimagf(z), -crealf(z))); +} diff --git a/src/s_csqrt.c b/src/s_csqrt.c index 9fca157..ddb2cb1 100644 --- a/src/s_csqrt.c +++ b/src/s_csqrt.c @@ -25,11 +25,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_csqrt.c,v 1.4 2008/08/08 00:15:16 das Exp $"); #include #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_csqrtf.c b/src/s_csqrtf.c index 9f0a947..b209de8 100644 --- a/src/s_csqrtf.c +++ b/src/s_csqrtf.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_csqrtf.c,v 1.3 2008/08/08 00:15:16 das Exp $"); #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_csqrtl.c b/src/s_csqrtl.c index 8833a2b..c441b51 100644 --- a/src/s_csqrtl.c +++ b/src/s_csqrtl.c @@ -25,11 +25,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_csqrtl.c,v 1.2 2008/08/08 00:15:16 das Exp $"); #include #include -#include "openlibm.h" +#include #include "math_private.h" diff --git a/src/s_ctanh.c b/src/s_ctanh.c new file mode 100644 index 0000000..b4115b3 --- /dev/null +++ b/src/s_ctanh.c @@ -0,0 +1,144 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic tangent of a complex argument z = x + i y. + * + * The algorithm is from: + * + * W. Kahan. Branch Cuts for Complex Elementary Functions or Much + * Ado About Nothing's Sign Bit. In The State of the Art in + * Numerical Analysis, pp. 165 ff. Iserles and Powell, eds., 1987. + * + * Method: + * + * Let t = tan(x) + * beta = 1/cos^2(y) + * s = sinh(x) + * rho = cosh(x) + * + * We have: + * + * tanh(z) = sinh(z) / cosh(z) + * + * sinh(x) cos(y) + i cosh(x) sin(y) + * = --------------------------------- + * cosh(x) cos(y) + i sinh(x) sin(y) + * + * cosh(x) sinh(x) / cos^2(y) + i tan(y) + * = ------------------------------------- + * 1 + sinh^2(x) / cos^2(y) + * + * beta rho s + i t + * = ---------------- + * 1 + beta s^2 + * + * Modifications: + * + * I omitted the original algorithm's handling of overflow in tan(x) after + * verifying with nearpi.c that this can't happen in IEEE single or double + * precision. I also handle large x differently. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_ctanh.c,v 1.2 2011/10/21 06:30:16 das Exp $"); + +#include +#include + +#include "math_private.h" + +double complex +ctanh(double complex z) +{ + double x, y; + double t, beta, s, rho, denom; + uint32_t hx, ix, lx; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + ix = hx & 0x7fffffff; + + /* + * ctanh(NaN + i 0) = NaN + i 0 + * + * ctanh(NaN + i y) = NaN + i NaN for y != 0 + * + * The imaginary part has the sign of x*sin(2*y), but there's no + * special effort to get this right. + * + * ctanh(+-Inf +- i Inf) = +-1 +- 0 + * + * ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite + * + * The imaginary part of the sign is unspecified. This special + * case is only needed to avoid a spurious invalid exception when + * y is infinite. + */ + if (ix >= 0x7ff00000) { + if ((ix & 0xfffff) | lx) /* x is NaN */ + return (cpack(x, (y == 0 ? y : x * y))); + SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */ + return (cpack(x, copysign(0, isinf(y) ? y : sin(y) * cos(y)))); + } + + /* + * ctanh(x + i NAN) = NaN + i NaN + * ctanh(x +- i Inf) = NaN + i NaN + */ + if (!isfinite(y)) + return (cpack(y - y, y - y)); + + /* + * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the + * approximation sinh^2(huge) ~= exp(2*huge) / 4. + * We use a modified formula to avoid spurious overflow. + */ + if (ix >= 0x40360000) { /* x >= 22 */ + double exp_mx = exp(-fabs(x)); + return (cpack(copysign(1, x), + 4 * sin(y) * cos(y) * exp_mx * exp_mx)); + } + + /* Kahan's algorithm */ + t = tan(y); + beta = 1.0 + t * t; /* = 1 / cos^2(y) */ + s = sinh(x); + rho = sqrt(1 + s * s); /* = cosh(x) */ + denom = 1 + beta * s * s; + return (cpack((beta * rho * s) / denom, t / denom)); +} + +double complex +ctan(double complex z) +{ + + /* ctan(z) = -I * ctanh(I * z) */ + z = ctanh(cpack(-cimag(z), creal(z))); + return (cpack(cimag(z), -creal(z))); +} diff --git a/src/s_ctanhf.c b/src/s_ctanhf.c new file mode 100644 index 0000000..ab760ba --- /dev/null +++ b/src/s_ctanhf.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Hyperbolic tangent of a complex argument z. See s_ctanh.c for details. + */ + +#include +__FBSDID("$FreeBSD: src/lib/msun/src/s_ctanhf.c,v 1.2 2011/10/21 06:30:16 das Exp $"); + +#include +#include + +#include "math_private.h" + +float complex +ctanhf(float complex z) +{ + float x, y; + float t, beta, s, rho, denom; + uint32_t hx, ix; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hx, x); + ix = hx & 0x7fffffff; + + if (ix >= 0x7f800000) { + if (ix & 0x7fffff) + return (cpackf(x, (y == 0 ? y : x * y))); + SET_FLOAT_WORD(x, hx - 0x40000000); + return (cpackf(x, + copysignf(0, isinf(y) ? y : sinf(y) * cosf(y)))); + } + + if (!isfinite(y)) + return (cpackf(y - y, y - y)); + + if (ix >= 0x41300000) { /* x >= 11 */ + float exp_mx = expf(-fabsf(x)); + return (cpackf(copysignf(1, x), + 4 * sinf(y) * cosf(y) * exp_mx * exp_mx)); + } + + t = tanf(y); + beta = 1.0 + t * t; + s = sinhf(x); + rho = sqrtf(1 + s * s); + denom = 1 + beta * s * s; + return (cpackf((beta * rho * s) / denom, t / denom)); +} + +float complex +ctanf(float complex z) +{ + + z = ctanhf(cpackf(-cimagf(z), crealf(z))); + return (cpackf(cimagf(z), -crealf(z))); +} + diff --git a/src/s_erf.c b/src/s_erf.c index f316f6b..e3e7b63 100644 --- a/src/s_erf.c +++ b/src/s_erf.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_erf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); /* double erf(double x) * double erfc(double x) @@ -108,7 +108,7 @@ */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_erff.c b/src/s_erff.c index ec280c6..6335677 100644 --- a/src/s_erff.c +++ b/src/s_erff.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_erff.c,v 1.8 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_exp2.c b/src/s_exp2.c index a9975b9..2b7dc36 100644 --- a/src/s_exp2.c +++ b/src/s_exp2.c @@ -25,11 +25,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2.c,v 1.7 2008/02/22 02:27:34 das Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #define TBLBITS 8 diff --git a/src/s_exp2f.c b/src/s_exp2f.c index 7537928..2e5a5e0 100644 --- a/src/s_exp2f.c +++ b/src/s_exp2f.c @@ -25,11 +25,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_exp2f.c,v 1.9 2008/02/22 02:27:34 das Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #define TBLBITS 4 diff --git a/src/s_expm1.c b/src/s_expm1.c index 379df28..82b6ff7 100644 --- a/src/s_expm1.c +++ b/src/s_expm1.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_expm1.c,v 1.12 2011/10/21 06:26:38 das Exp $"); /* expm1(x) * Returns exp(x)-1, the exponential of x minus 1. @@ -108,7 +108,9 @@ * to produce the hexadecimal values shown. */ -#include "openlibm.h" +#include + +#include "math.h" #include "math_private.h" static const double @@ -135,7 +137,6 @@ expm1(double x) GET_HIGH_WORD(hx,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 argument */ @@ -169,7 +170,7 @@ expm1(double x) hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ lo = t*ln2_lo; } - x = hi - lo; + STRICT_ASSIGN(double, x, hi - lo); c = (hi-x)-lo; } else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */ diff --git a/src/s_expm1f.c b/src/s_expm1f.c index 3378468..0f36a15 100644 --- a/src/s_expm1f.c +++ b/src/s_expm1f.c @@ -14,9 +14,11 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_expm1f.c,v 1.12 2011/10/21 06:26:38 das Exp $"); +#include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float @@ -44,7 +46,6 @@ expm1f(float x) GET_FLOAT_WORD(hx,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 argument */ @@ -75,7 +76,7 @@ expm1f(float x) hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ lo = t*ln2_lo; } - x = hi - lo; + STRICT_ASSIGN(float, x, hi - lo); c = (hi-x)-lo; } else if(hx < 0x33000000) { /* when |x|<2**-25, return x */ diff --git a/src/s_fabs.c b/src/s_fabs.c index 06688b0..0dfa940 100644 --- a/src/s_fabs.c +++ b/src/s_fabs.c @@ -18,7 +18,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_fabs.c,v 1.7 2002/05/28 18:1 * fabs(x) returns the absolute value of x. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" double diff --git a/src/s_fabsf.c b/src/s_fabsf.c index 4d99135..a0df12f 100644 --- a/src/s_fabsf.c +++ b/src/s_fabsf.c @@ -14,13 +14,13 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_fabsf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); /* * fabsf(x) returns the absolute value of x. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" float diff --git a/src/s_fabsl.c b/src/s_fabsl.c index 28a9c3b..200a9a5 100644 --- a/src/s_fabsl.c +++ b/src/s_fabsl.c @@ -28,7 +28,7 @@ * $FreeBSD: src/lib/msun/src/s_fabsl.c,v 1.2 2003/10/25 19:53:28 des Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fdim.c b/src/s_fdim.c index 25fbd33..6ec10df 100644 --- a/src/s_fdim.c +++ b/src/s_fdim.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #define DECL(type, fn) \ type \ diff --git a/src/s_finite.c b/src/s_finite.c index 8d96a15..fd36b02 100644 --- a/src/s_finite.c +++ b/src/s_finite.c @@ -11,14 +11,14 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_finite.c,v 1.9 2008/02/22 02:30:35 das Exp $"); /* * finite(x) returns 1 is x is finite, else 0; * no branching! */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" int finite(double x) diff --git a/src/s_finitef.c b/src/s_finitef.c index e10e436..b9c83c4 100644 --- a/src/s_finitef.c +++ b/src/s_finitef.c @@ -14,14 +14,14 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_finitef.c,v 1.7 2008/02/22 02:30:35 das Exp $"); /* * finitef(x) returns 1 is x is finite, else 0; * no branching! */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" int finitef(float x) diff --git a/src/s_floor.c b/src/s_floor.c index a0da315..deffff4 100644 --- a/src/s_floor.c +++ b/src/s_floor.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_floor.c,v 1.11 2008/02/15 07:01:40 bde Exp $"); /* * floor(x) @@ -24,7 +24,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; diff --git a/src/s_floorf.c b/src/s_floorf.c index 928d3d4..463ce00 100644 --- a/src/s_floorf.c +++ b/src/s_floorf.c @@ -14,7 +14,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_floorf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); /* * floorf(x) @@ -25,7 +25,7 @@ * Inexact flag raised if x not equal to floorf(x). */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float huge = 1.0e30; diff --git a/src/s_floorl.c b/src/s_floorl.c index 40cf69e..5cce618 100644 --- a/src/s_floorl.c +++ b/src/s_floorl.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_floorl.c,v 1.8 2008/02/14 15:10:34 bde Exp $"); /* * floorl(x) @@ -24,7 +24,7 @@ */ #include -#include "openlibm.h" +#include #include #include "fpmath.h" @@ -32,7 +32,7 @@ #ifdef LDBL_IMPLICIT_NBIT #define MANH_SIZE (LDBL_MANH_SIZE + 1) #define INC_MANH(u, c) do { \ - u_int64_t o = u.bits.manh; \ + uint64_t o = u.bits.manh; \ u.bits.manh += (c); \ if (u.bits.manh < o) \ u.bits.exp++; \ @@ -40,7 +40,7 @@ #else #define MANH_SIZE LDBL_MANH_SIZE #define INC_MANH(u, c) do { \ - u_int64_t o = u.bits.manh; \ + uint64_t o = u.bits.manh; \ u.bits.manh += (c); \ if (u.bits.manh < o) { \ u.bits.exp++; \ @@ -64,7 +64,7 @@ floorl(long double x) (u.bits.manh | u.bits.manl) != 0) u.e = u.bits.sign ? -1.0 : 0.0; } else { - u_int64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); + uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); if (((u.bits.manh & m) | u.bits.manl) == 0) return (x); /* x is integral */ if (u.bits.sign) { @@ -81,14 +81,14 @@ floorl(long double x) } } } else if (e < LDBL_MANT_DIG - 1) { - u_int64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); + uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); if ((u.bits.manl & m) == 0) return (x); /* x is integral */ if (u.bits.sign) { if (e == MANH_SIZE - 1) INC_MANH(u, 1); else { - u_int64_t o = u.bits.manl; + uint64_t o = u.bits.manl; u.bits.manl += 1llu << (LDBL_MANT_DIG - e - 1); if (u.bits.manl < o) /* got a carry */ INC_MANH(u, 1); diff --git a/src/s_fma.c b/src/s_fma.c index a98b2ee..cefd5c1 100644 --- a/src/s_fma.c +++ b/src/s_fma.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz + * Copyright (c) 2005-2011 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,11 +25,137 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_fma.c,v 1.8 2011/10/21 06:30:43 das Exp $"); #include #include -#include "openlibm.h" +#include + +#include "math_private.h" + +/* + * A struct dd represents a floating-point number with twice the precision + * of a double. We maintain the invariant that "hi" stores the 53 high-order + * bits of the result. + */ +struct dd { + double hi; + double lo; +}; + +/* + * Compute a+b exactly, returning the exact result in a struct dd. We assume + * that both a and b are finite, but make no assumptions about their relative + * magnitudes. + */ +static inline struct dd +dd_add(double a, double b) +{ + struct dd ret; + double s; + + ret.hi = a + b; + s = ret.hi - a; + ret.lo = (a - (ret.hi - s)) + (b - s); + return (ret); +} + +/* + * Compute a+b, with a small tweak: The least significant bit of the + * result is adjusted into a sticky bit summarizing all the bits that + * were lost to rounding. This adjustment negates the effects of double + * rounding when the result is added to another number with a higher + * exponent. For an explanation of round and sticky bits, see any reference + * on FPU design, e.g., + * + * J. Coonen. An Implementation Guide to a Proposed Standard for + * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. + */ +static inline double +add_adjusted(double a, double b) +{ + struct dd sum; + uint64_t hibits, lobits; + + sum = dd_add(a, b); + if (sum.lo != 0) { + EXTRACT_WORD64(hibits, sum.hi); + if ((hibits & 1) == 0) { + /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ + EXTRACT_WORD64(lobits, sum.lo); + hibits += 1 - ((hibits ^ lobits) >> 62); + INSERT_WORD64(sum.hi, hibits); + } + } + return (sum.hi); +} + +/* + * Compute ldexp(a+b, scale) with a single rounding error. It is assumed + * that the result will be subnormal, and care is taken to ensure that + * double rounding does not occur. + */ +static inline double +add_and_denormalize(double a, double b, int scale) +{ + struct dd sum; + uint64_t hibits, lobits; + int bits_lost; + + sum = dd_add(a, b); + + /* + * If we are losing at least two bits of accuracy to denormalization, + * then the first lost bit becomes a round bit, and we adjust the + * lowest bit of sum.hi to make it a sticky bit summarizing all the + * bits in sum.lo. With the sticky bit adjusted, the hardware will + * break any ties in the correct direction. + * + * If we are losing only one bit to denormalization, however, we must + * break the ties manually. + */ + if (sum.lo != 0) { + EXTRACT_WORD64(hibits, sum.hi); + bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1; + if (bits_lost != 1 ^ (int)(hibits & 1)) { + /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ + EXTRACT_WORD64(lobits, sum.lo); + hibits += 1 - (((hibits ^ lobits) >> 62) & 2); + INSERT_WORD64(sum.hi, hibits); + } + } + return (ldexp(sum.hi, scale)); +} + +/* + * Compute a*b exactly, returning the exact result in a struct dd. We assume + * that both a and b are normalized, so no underflow or overflow will occur. + * The current rounding mode must be round-to-nearest. + */ +static inline struct dd +dd_mul(double a, double b) +{ + static const double split = 0x1p27 + 1.0; + struct dd ret; + double ha, hb, la, lb, p, q; + + p = a * split; + ha = a - p; + ha += p; + la = a - ha; + + p = b * split; + hb = b - p; + hb += p; + lb = b - hb; + + p = ha * hb; + q = ha * lb + la * hb; + + ret.hi = p + q; + ret.lo = p - ret.hi + q + la * lb; + return (ret); +} /* * Fused multiply-add: Compute x * y + z with a single rounding error. @@ -48,14 +174,11 @@ * Hardware instructions should be used on architectures that support it, * since this implementation will likely be several times slower. */ -#if LDBL_MANT_DIG != 113 double fma(double x, double y, double z) { - static const double split = 0x1p27 + 1.0; - double xs, ys, zs; - double c, cc, hx, hy, p, q, tx, ty; - double r, rr, s; + double xs, ys, zs, adj; + struct dd xy, r; int oround; int ex, ey, ez; int spread; @@ -85,41 +208,6 @@ fma(double x, double y, double z) * will overflow, so we handle these cases specially. Rounding * modes other than FE_TONEAREST are painful. */ - if (spread > DBL_MANT_DIG * 2) { - fenv_t env; - feraiseexcept(FE_INEXACT); - switch(oround) { - case FE_TONEAREST: - return (x * y); - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafter(r, 0); - feupdateenv(&env); - return (r); - case FE_DOWNWARD: - if (z > 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafter(r, -INFINITY); - feupdateenv(&env); - return (r); - default: /* FE_UPWARD */ - if (z < 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafter(r, INFINITY); - feupdateenv(&env); - return (r); - } - } if (spread < -DBL_MANT_DIG) { feraiseexcept(FE_INEXACT); if (!isnormal(z)) @@ -144,63 +232,52 @@ fma(double x, double y, double z) return (z); } } + if (spread <= DBL_MANT_DIG * 2) + zs = ldexp(zs, -spread); + else + zs = copysign(DBL_MIN, zs); - /* - * Use Dekker's algorithm to perform the multiplication and - * subsequent addition in twice the machine precision. - * Arrange so that x * y = c + cc, and x * y + z = r + rr. - */ fesetround(FE_TONEAREST); - p = xs * split; - hx = xs - p; - hx += p; - tx = xs - hx; - - p = ys * split; - hy = ys - p; - hy += p; - ty = ys - hy; - - p = hx * hy; - q = hx * ty + tx * hy; - c = p + q; - cc = p - c + q + tx * ty; - - zs = ldexp(zs, -spread); - r = c + zs; - s = r - c; - rr = (c - (r - s)) + (zs - s) + cc; + /* + * Basic approach for round-to-nearest: + * + * (xy.hi, xy.lo) = x * y (exact) + * (r.hi, r.lo) = xy.hi + z (exact) + * adj = xy.lo + r.lo (inexact; low bit is sticky) + * result = r.hi + adj (correctly rounded) + */ + xy = dd_mul(xs, ys); + r = dd_add(xy.hi, zs); spread = ex + ey; - if (spread + ilogb(r) > -1023) { - fesetround(oround); - r = r + rr; - } else { + + if (r.hi == 0.0) { /* - * The result is subnormal, so we round before scaling to - * avoid double rounding. + * When the addends cancel to 0, ensure that the result has + * the correct sign. */ - p = ldexp(copysign(0x1p-1022, r), -spread); - c = r + p; - s = c - r; - cc = (r - (c - s)) + (p - s) + rr; fesetround(oround); - r = (c + cc) - p; + volatile double vzs = zs; /* XXX gcc CSE bug workaround */ + return (xy.hi + vzs + ldexp(xy.lo, spread)); } - return (ldexp(r, spread)); + + if (oround != FE_TONEAREST) { + /* + * There is no need to worry about double rounding in directed + * rounding modes. + */ + fesetround(oround); + adj = r.lo + xy.lo; + return (ldexp(r.hi + adj, spread)); + } + + adj = add_adjusted(r.lo, xy.lo); + if (spread + ilogb(r.hi) > -1023) + return (ldexp(r.hi + adj, spread)); + else + return (add_and_denormalize(r.hi, adj, spread)); } -#else /* LDBL_MANT_DIG == 113 */ -/* - * 113 bits of precision is more than twice the precision of a double, - * so it is enough to represent the intermediate product exactly. - */ -double -fma(double x, double y, double z) -{ - return ((long double)x * y + z); -} -#endif /* LDBL_MANT_DIG != 113 */ #if (LDBL_MANT_DIG == 53) __weak_reference(fma, fmal); diff --git a/src/s_fmaf.c b/src/s_fmaf.c index 9992f41..7f4f80a 100644 --- a/src/s_fmaf.c +++ b/src/s_fmaf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz + * Copyright (c) 2005-2011 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,25 +25,45 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmaf.c,v 1.3 2011/10/15 04:16:58 das Exp $"); +#include -#include "openlibm.h" +#include "math.h" +#include "math_private.h" /* * Fused multiply-add: Compute x * y + z with a single rounding error. * * A double has more than twice as much precision than a float, so - * direct double-precision arithmetic suffices. - * - * XXX We are relying on the compiler to convert from double to float - * using the current rounding mode and with the appropriate - * side-effects. But on at least one platform (gcc 3.4.2/sparc64), - * this appears to be too much to ask for. The precision - * reduction should be done manually. + * direct double-precision arithmetic suffices, except where double + * rounding occurs. */ float fmaf(float x, float y, float z) { + double xy, result; + uint32_t hr, lr; - return ((double)x * y + z); + xy = (double)x * y; + result = xy + z; + EXTRACT_WORDS(hr, lr, result); + /* Common case: The double precision result is fine. */ + if ((lr & 0x1fffffff) != 0x10000000 || /* not a halfway case */ + (hr & 0x7ff00000) == 0x7ff00000 || /* NaN */ + result - xy == z || /* exact */ + fegetround() != FE_TONEAREST) /* not round-to-nearest */ + return (result); + + /* + * If result is inexact, and exactly halfway between two float values, + * we need to adjust the low-order bit in the direction of the error. + */ + fesetround(FE_TOWARDZERO); + volatile double vxy = xy; /* XXX work around gcc CSE bug */ + double adjusted_result = vxy + z; + fesetround(FE_TONEAREST); + if (result == adjusted_result) + SET_LOW_WORD(adjusted_result, lr + 1); + return (adjusted_result); } diff --git a/src/s_fmal.c b/src/s_fmal.c index 8bd2df2..0083123 100644 --- a/src/s_fmal.c +++ b/src/s_fmal.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz + * Copyright (c) 2005-2011 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,11 +25,133 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmal.c,v 1.7 2011/10/21 06:30:43 das Exp $"); #include #include -#include "openlibm.h" +#include + +#include "fpmath.h" + +/* + * A struct dd represents a floating-point number with twice the precision + * of a long double. We maintain the invariant that "hi" stores the high-order + * bits of the result. + */ +struct dd { + long double hi; + long double lo; +}; + +/* + * Compute a+b exactly, returning the exact result in a struct dd. We assume + * that both a and b are finite, but make no assumptions about their relative + * magnitudes. + */ +static inline struct dd +dd_add(long double a, long double b) +{ + struct dd ret; + long double s; + + ret.hi = a + b; + s = ret.hi - a; + ret.lo = (a - (ret.hi - s)) + (b - s); + return (ret); +} + +/* + * Compute a+b, with a small tweak: The least significant bit of the + * result is adjusted into a sticky bit summarizing all the bits that + * were lost to rounding. This adjustment negates the effects of double + * rounding when the result is added to another number with a higher + * exponent. For an explanation of round and sticky bits, see any reference + * on FPU design, e.g., + * + * J. Coonen. An Implementation Guide to a Proposed Standard for + * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. + */ +static inline long double +add_adjusted(long double a, long double b) +{ + struct dd sum; + union IEEEl2bits u; + + sum = dd_add(a, b); + if (sum.lo != 0) { + u.e = sum.hi; + if ((u.bits.manl & 1) == 0) + sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); + } + return (sum.hi); +} + +/* + * Compute ldexp(a+b, scale) with a single rounding error. It is assumed + * that the result will be subnormal, and care is taken to ensure that + * double rounding does not occur. + */ +static inline long double +add_and_denormalize(long double a, long double b, int scale) +{ + struct dd sum; + int bits_lost; + union IEEEl2bits u; + + sum = dd_add(a, b); + + /* + * If we are losing at least two bits of accuracy to denormalization, + * then the first lost bit becomes a round bit, and we adjust the + * lowest bit of sum.hi to make it a sticky bit summarizing all the + * bits in sum.lo. With the sticky bit adjusted, the hardware will + * break any ties in the correct direction. + * + * If we are losing only one bit to denormalization, however, we must + * break the ties manually. + */ + if (sum.lo != 0) { + u.e = sum.hi; + bits_lost = -u.bits.exp - scale + 1; + if (bits_lost != 1 ^ (int)(u.bits.manl & 1)) + sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); + } + return (ldexp(sum.hi, scale)); +} + +/* + * Compute a*b exactly, returning the exact result in a struct dd. We assume + * that both a and b are normalized, so no underflow or overflow will occur. + * The current rounding mode must be round-to-nearest. + */ +static inline struct dd +dd_mul(long double a, long double b) +{ +#if LDBL_MANT_DIG == 64 + static const long double split = 0x1p32L + 1.0; +#elif LDBL_MANT_DIG == 113 + static const long double split = 0x1p57L + 1.0; +#endif + struct dd ret; + long double ha, hb, la, lb, p, q; + + p = a * split; + ha = a - p; + ha += p; + la = a - ha; + + p = b * split; + hb = b - p; + hb += p; + lb = b - hb; + + p = ha * hb; + q = ha * lb + la * hb; + + ret.hi = p + q; + ret.lo = p - ret.hi + q + la * lb; + return (ret); +} /* * Fused multiply-add: Compute x * y + z with a single rounding error. @@ -43,14 +165,8 @@ long double fmal(long double x, long double y, long double z) { -#if LDBL_MANT_DIG == 64 - static const long double split = 0x1p32L + 1.0; -#elif LDBL_MANT_DIG == 113 - static const long double split = 0x1p57L + 1.0; -#endif - long double xs, ys, zs; - long double c, cc, hx, hy, p, q, tx, ty; - long double r, rr, s; + long double xs, ys, zs, adj; + struct dd xy, r; int oround; int ex, ey, ez; int spread; @@ -80,41 +196,6 @@ fmal(long double x, long double y, long double z) * will overflow, so we handle these cases specially. Rounding * modes other than FE_TONEAREST are painful. */ - if (spread > LDBL_MANT_DIG * 2) { - fenv_t env; - feraiseexcept(FE_INEXACT); - switch(oround) { - case FE_TONEAREST: - return (x * y); - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafterl(r, 0); - feupdateenv(&env); - return (r); - case FE_DOWNWARD: - if (z > 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafterl(r, -INFINITY); - feupdateenv(&env); - return (r); - default: /* FE_UPWARD */ - if (z < 0.0) - return (x * y); - feholdexcept(&env); - r = x * y; - if (!fetestexcept(FE_INEXACT)) - r = nextafterl(r, INFINITY); - feupdateenv(&env); - return (r); - } - } if (spread < -LDBL_MANT_DIG) { feraiseexcept(FE_INEXACT); if (!isnormal(z)) @@ -139,49 +220,49 @@ fmal(long double x, long double y, long double z) return (z); } } + if (spread <= LDBL_MANT_DIG * 2) + zs = ldexpl(zs, -spread); + else + zs = copysignl(LDBL_MIN, zs); - /* - * Use Dekker's algorithm to perform the multiplication and - * subsequent addition in twice the machine precision. - * Arrange so that x * y = c + cc, and x * y + z = r + rr. - */ fesetround(FE_TONEAREST); - p = xs * split; - hx = xs - p; - hx += p; - tx = xs - hx; - - p = ys * split; - hy = ys - p; - hy += p; - ty = ys - hy; - - p = hx * hy; - q = hx * ty + tx * hy; - c = p + q; - cc = p - c + q + tx * ty; - - zs = ldexpl(zs, -spread); - r = c + zs; - s = r - c; - rr = (c - (r - s)) + (zs - s) + cc; + /* + * Basic approach for round-to-nearest: + * + * (xy.hi, xy.lo) = x * y (exact) + * (r.hi, r.lo) = xy.hi + z (exact) + * adj = xy.lo + r.lo (inexact; low bit is sticky) + * result = r.hi + adj (correctly rounded) + */ + xy = dd_mul(xs, ys); + r = dd_add(xy.hi, zs); spread = ex + ey; - if (spread + ilogbl(r) > -16383) { - fesetround(oround); - r = r + rr; - } else { + + if (r.hi == 0.0) { /* - * The result is subnormal, so we round before scaling to - * avoid double rounding. + * When the addends cancel to 0, ensure that the result has + * the correct sign. */ - p = ldexpl(copysignl(0x1p-16382L, r), -spread); - c = r + p; - s = c - r; - cc = (r - (c - s)) + (p - s) + rr; fesetround(oround); - r = (c + cc) - p; + volatile long double vzs = zs; /* XXX gcc CSE bug workaround */ + return (xy.hi + vzs + ldexpl(xy.lo, spread)); } - return (ldexpl(r, spread)); + + if (oround != FE_TONEAREST) { + /* + * There is no need to worry about double rounding in directed + * rounding modes. + */ + fesetround(oround); + adj = r.lo + xy.lo; + return (ldexpl(r.hi + adj, spread)); + } + + adj = add_adjusted(r.lo, xy.lo); + if (spread + ilogbl(r.hi) > -16383) + return (ldexpl(r.hi + adj, spread)); + else + return (add_and_denormalize(r.hi, adj, spread)); } diff --git a/src/s_fmax.c b/src/s_fmax.c index 4363375..6e619fe 100644 --- a/src/s_fmax.c +++ b/src/s_fmax.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmax.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fmaxf.c b/src/s_fmaxf.c index df5f176..a97eeb5 100644 --- a/src/s_fmaxf.c +++ b/src/s_fmaxf.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fmaxl.c b/src/s_fmaxl.c index 32c4575..5ed4ee0 100644 --- a/src/s_fmaxl.c +++ b/src/s_fmaxl.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fmin.c b/src/s_fmin.c index 2aeb914..76c1c12 100644 --- a/src/s_fmin.c +++ b/src/s_fmin.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmin.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fminf.c b/src/s_fminf.c index 5bd339b..bd1d241 100644 --- a/src/s_fminf.c +++ b/src/s_fminf.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fminf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_fminl.c b/src/s_fminl.c index 38b4aa6..63395df 100644 --- a/src/s_fminl.c +++ b/src/s_fminl.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_fminl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); - -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_frexp.c b/src/s_frexp.c index 6d7dda3..5b6e31d 100644 --- a/src/s_frexp.c +++ b/src/s_frexp.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.11 2008/02/22 02:30:35 das Exp $"); /* * for non-zero x @@ -25,7 +25,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_frexpf.c b/src/s_frexpf.c index 85ecf6f..da1b28a 100644 --- a/src/s_frexpf.c +++ b/src/s_frexpf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_frexpf.c,v 1.10 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_frexpl.c b/src/s_frexpl.c index 01ec5ff..20b3167 100644 --- a/src/s_frexpl.c +++ b/src/s_frexpl.c @@ -27,7 +27,7 @@ */ #include -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_ilogb.c b/src/s_ilogb.c index c6959ad..7d779a4 100644 --- a/src/s_ilogb.c +++ b/src/s_ilogb.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogb.c,v 1.10 2008/02/22 02:30:35 das Exp $"); /* ilogb(double x) * return the binary exponent of non-zero x @@ -22,7 +22,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" int ilogb(double x) diff --git a/src/s_ilogbf.c b/src/s_ilogbf.c index c3b931e..f4eae7e 100644 --- a/src/s_ilogbf.c +++ b/src/s_ilogbf.c @@ -14,11 +14,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogbf.c,v 1.8 2008/02/22 02:30:35 das Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" int ilogbf(float x) diff --git a/src/s_ilogbl.c b/src/s_ilogbl.c index a55cf51..484e9ab 100644 --- a/src/s_ilogbl.c +++ b/src/s_ilogbl.c @@ -11,11 +11,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.2 2008/02/22 02:30:35 das Exp $"); #include #include -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_isfinite.c b/src/s_isfinite.c index c89c9bb..394505d 100644 --- a/src/s_isfinite.c +++ b/src/s_isfinite.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/src/s_isfinite.c,v 1.1 2004/07/09 03:32:39 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_isnan.c b/src/s_isnan.c index 0f1b33b..8b6e471 100644 --- a/src/s_isnan.c +++ b/src/s_isnan.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/src/s_isnan.c,v 1.9 2010/06/12 17:32:05 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_isnormal.c b/src/s_isnormal.c index 516980f..1345dba 100644 --- a/src/s_isnormal.c +++ b/src/s_isnormal.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/src/s_isnormal.c,v 1.1 2004/07/09 03:32:39 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_llrint.c b/src/s_llrint.c index 45c4b10..fba9784 100644 --- a/src/s_llrint.c +++ b/src/s_llrint.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); #define type double #define roundit rint diff --git a/src/s_llrintf.c b/src/s_llrintf.c index 3d0b5c8..49fe58d 100644 --- a/src/s_llrintf.c +++ b/src/s_llrintf.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); #define type float #define roundit rintf diff --git a/src/s_llrintl.c b/src/s_llrintl.c index 367cda5..40d249e 100644 --- a/src/s_llrintl.c +++ b/src/s_llrintl.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llrintl.c,v 1.1 2008/01/14 02:12:06 das Exp $"); #define type long double #define roundit rintl diff --git a/src/s_llround.c b/src/s_llround.c index 593d04e..36451ca 100644 --- a/src/s_llround.c +++ b/src/s_llround.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llround.c,v 1.2 2005/04/08 00:52:27 das Exp $"); #define type double #define roundit round diff --git a/src/s_llroundf.c b/src/s_llroundf.c index 9c69c9b..3799ef0 100644 --- a/src/s_llroundf.c +++ b/src/s_llroundf.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llroundf.c,v 1.2 2005/04/08 00:52:27 das Exp $"); #define type float #define roundit roundf diff --git a/src/s_llroundl.c b/src/s_llroundl.c index 54e79ae..f0e0294 100644 --- a/src/s_llroundl.c +++ b/src/s_llroundl.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_llroundl.c,v 1.1 2005/04/08 01:24:08 das Exp $"); #define type long double #define roundit roundl diff --git a/src/s_log1p.c b/src/s_log1p.c index 5de0bd4..0dcbc44 100644 --- a/src/s_log1p.c +++ b/src/s_log1p.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_log1p.c,v 1.10 2008/03/29 16:37:59 das Exp $"); /* double log1p(double x) * @@ -80,7 +80,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_log1pf.c b/src/s_log1pf.c index 7ec555f..ae96493 100644 --- a/src/s_log1pf.c +++ b/src/s_log1pf.c @@ -14,11 +14,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_log1pf.c,v 1.12 2008/03/29 16:37:59 das Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_logb.c b/src/s_logb.c index 2596b1d..35a422f 100644 --- a/src/s_logb.c +++ b/src/s_logb.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_logb.c,v 1.12 2008/02/08 01:22:13 bde Exp $"); /* * double logb(x) @@ -21,7 +21,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_logbf.c b/src/s_logbf.c index 30e5efd..5a73dda 100644 --- a/src/s_logbf.c +++ b/src/s_logbf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_logbf.c,v 1.9 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_logbl.c b/src/s_logbl.c index 08fc9f9..4762325 100644 --- a/src/s_logbl.c +++ b/src/s_logbl.c @@ -16,7 +16,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logbl.c,v 1.1 2007/12/17 03: #include #include -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_lrint.c b/src/s_lrint.c index b0d7a75..81eabaa 100644 --- a/src/s_lrint.c +++ b/src/s_lrint.c @@ -26,10 +26,10 @@ #include #include -#include "openlibm.h" +#include #ifndef type - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); #define type double #define roundit rint #define dtype long diff --git a/src/s_lrintf.c b/src/s_lrintf.c index d4f5c59..546a099 100644 --- a/src/s_lrintf.c +++ b/src/s_lrintf.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); #define type float #define roundit rintf diff --git a/src/s_lrintl.c b/src/s_lrintl.c index b5b6502..880663f 100644 --- a/src/s_lrintl.c +++ b/src/s_lrintl.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lrintl.c,v 1.1 2008/01/14 02:12:06 das Exp $"); #define type long double #define roundit rintl diff --git a/src/s_lround.c b/src/s_lround.c index 4344ef5..bf19361 100644 --- a/src/s_lround.c +++ b/src/s_lround.c @@ -27,10 +27,10 @@ #include #include #include -#include "openlibm.h" +#include #ifndef type - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lround.c,v 1.2 2005/04/08 00:52:16 das Exp $"); #define type double #define roundit round #define dtype long diff --git a/src/s_lroundf.c b/src/s_lroundf.c index 09dafef..c78a561 100644 --- a/src/s_lroundf.c +++ b/src/s_lroundf.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lroundf.c,v 1.2 2005/04/08 00:52:27 das Exp $"); #define type float #define roundit roundf diff --git a/src/s_lroundl.c b/src/s_lroundl.c index e441804..6947ebf 100644 --- a/src/s_lroundl.c +++ b/src/s_lroundl.c @@ -1,5 +1,5 @@ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_lroundl.c,v 1.1 2005/04/08 01:24:08 das Exp $"); #define type long double #define roundit roundl diff --git a/src/s_modf.c b/src/s_modf.c index 692e025..9f4a9e8 100644 --- a/src/s_modf.c +++ b/src/s_modf.c @@ -24,7 +24,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_modf.c,v 1.8 2007/01/06 21:2 * No exception. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0; diff --git a/src/s_modff.c b/src/s_modff.c index a76b997..820fcca 100644 --- a/src/s_modff.c +++ b/src/s_modff.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_modff.c,v 1.9 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one = 1.0; diff --git a/src/s_modfl.c b/src/s_modfl.c index 1d49b31..a298f97 100644 --- a/src/s_modfl.c +++ b/src/s_modfl.c @@ -37,13 +37,13 @@ */ #include -#include "openlibm.h" +#include #include #include "fpmath.h" #if LDBL_MANL_SIZE > 32 -#define MASK ((u_int64_t)-1) +#define MASK ((uint64_t)-1) #else #define MASK ((uint32_t)-1) #endif diff --git a/src/s_nan.c b/src/s_nan.c index 227a79e..db928a5 100644 --- a/src/s_nan.c +++ b/src/s_nan.c @@ -29,7 +29,7 @@ #include #include #include -#include "openlibm.h" +#include #include #include diff --git a/src/s_nearbyint.c b/src/s_nearbyint.c index 4a4af04..abea4b3 100644 --- a/src/s_nearbyint.c +++ b/src/s_nearbyint.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_nearbyint.c,v 1.2 2008/01/14 02:12:06 das Exp $"); #include -#include "openlibm.h" +#include /* * We save and restore the floating-point environment to avoid raising diff --git a/src/s_nextafter.c b/src/s_nextafter.c index e95a7f0..3023079 100644 --- a/src/s_nextafter.c +++ b/src/s_nextafter.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.12 2008/02/22 02:30:35 das Exp $"); /* IEEE functions * nextafter(x,y) @@ -22,7 +22,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" double diff --git a/src/s_nextafterf.c b/src/s_nextafterf.c index 4f6f30e..daa8313 100644 --- a/src/s_nextafterf.c +++ b/src/s_nextafterf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_nextafterf.c,v 1.11 2008/02/22 02:30:35 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" float diff --git a/src/s_nextafterl.c b/src/s_nextafterl.c index 67655c0..d9aed06 100644 --- a/src/s_nextafterl.c +++ b/src/s_nextafterl.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.2 2008/02/22 02:30:36 das Exp $"); /* IEEE functions * nextafter(x,y) @@ -23,7 +23,7 @@ #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" #if LDBL_MAX_EXP != 0x4000 diff --git a/src/s_nexttoward.c b/src/s_nexttoward.c index 7f291a9..468c127 100644 --- a/src/s_nexttoward.c +++ b/src/s_nexttoward.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_nexttoward.c,v 1.3 2011/02/10 07:38:13 das Exp $"); /* * We assume that a long double has a 15-bit exponent. On systems @@ -22,7 +22,7 @@ #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" #if LDBL_MAX_EXP != 0x4000 diff --git a/src/s_nexttowardf.c b/src/s_nexttowardf.c index cefbcc3..18c1b81 100644 --- a/src/s_nexttowardf.c +++ b/src/s_nexttowardf.c @@ -10,12 +10,12 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.3 2011/02/10 07:38:38 das Exp $"); #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" #define LDBL_INFNAN_EXP (LDBL_MAX_EXP * 2 - 1) diff --git a/src/s_remquo.c b/src/s_remquo.c index 264232c..e2b64d5 100644 --- a/src/s_remquo.c +++ b/src/s_remquo.c @@ -11,11 +11,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_remquo.c,v 1.2 2008/03/30 20:47:26 das Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double Zero[] = {0.0, -0.0,}; diff --git a/src/s_remquof.c b/src/s_remquof.c index ccb5978..0fa74c8 100644 --- a/src/s_remquof.c +++ b/src/s_remquof.c @@ -11,9 +11,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_remquof.c,v 1.1 2005/03/25 04:40:44 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float Zero[] = {0.0, -0.0,}; diff --git a/src/s_remquol.c b/src/s_remquol.c index b8277c7..efb3afb 100644 --- a/src/s_remquol.c +++ b/src/s_remquol.c @@ -11,25 +11,25 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_remquol.c,v 1.2 2008/07/31 20:09:47 das Exp $"); #include #include #include "fpmath.h" -#include "openlibm.h" +#include "math.h" #include "math_private.h" #define BIAS (LDBL_MAX_EXP - 1) #if LDBL_MANL_SIZE > 32 -typedef u_int64_t manl_t; +typedef uint64_t manl_t; #else typedef uint32_t manl_t; #endif #if LDBL_MANH_SIZE > 32 -typedef u_int64_t manh_t; +typedef uint64_t manh_t; #else typedef uint32_t manh_t; #endif diff --git a/src/s_rint.c b/src/s_rint.c index f690bf1..3d7f69d 100644 --- a/src/s_rint.c +++ b/src/s_rint.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_rint.c,v 1.16 2008/02/22 02:30:35 das Exp $"); /* * rint(x) @@ -25,7 +25,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_rintf.c b/src/s_rintf.c index ac69753..07216dd 100644 --- a/src/s_rintf.c +++ b/src/s_rintf.c @@ -14,12 +14,12 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_rintf.c,v 1.12 2008/02/22 02:30:35 das Exp $"); #include #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_rintl.c b/src/s_rintl.c index 2704876..4b698cc 100644 --- a/src/s_rintl.c +++ b/src/s_rintl.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_rintl.c,v 1.5 2008/02/22 11:59:05 bde Exp $"); #include -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_round.c b/src/s_round.c index 178d40c..e71b087 100644 --- a/src/s_round.c +++ b/src/s_round.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); - -#include "openlibm.h" +#include double round(double x) diff --git a/src/s_roundf.c b/src/s_roundf.c index 11f00b9..6d66e52 100644 --- a/src/s_roundf.c +++ b/src/s_roundf.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); - -#include "openlibm.h" +#include float roundf(float x) diff --git a/src/s_roundl.c b/src/s_roundl.c index 88784ba..c81d1f5 100644 --- a/src/s_roundl.c +++ b/src/s_roundl.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_roundl.c,v 1.2 2005/12/02 13:45:06 bde Exp $"); - -#include "openlibm.h" +#include long double roundl(long double x) diff --git a/src/s_scalbln.c b/src/s_scalbln.c index 72165e5..81846b0 100644 --- a/src/s_scalbln.c +++ b/src/s_scalbln.c @@ -25,10 +25,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_scalbln.c,v 1.2 2005/03/07 04:57:50 das Exp $"); #include -#include "openlibm.h" +#include double scalbln (double x, long n) diff --git a/src/s_scalbn.c b/src/s_scalbn.c index 5ba3696..ed5b571 100644 --- a/src/s_scalbn.c +++ b/src/s_scalbn.c @@ -24,7 +24,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbn.c,v 1.11 2005/03/07 2 #include #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double diff --git a/src/s_scalbnf.c b/src/s_scalbnf.c index 27c0d51..46c7baf 100644 --- a/src/s_scalbnf.c +++ b/src/s_scalbnf.c @@ -19,7 +19,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnf.c,v 1.8 2005/03/07 0 #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float diff --git a/src/s_scalbnl.c b/src/s_scalbnl.c index 1c548d0..c645d00 100644 --- a/src/s_scalbnl.c +++ b/src/s_scalbnl.c @@ -29,7 +29,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnl.c,v 1.1 2005/03/07 0 #include #include -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_signbit.c b/src/s_signbit.c index fcdb036..ffc08f3 100644 --- a/src/s_signbit.c +++ b/src/s_signbit.c @@ -26,7 +26,7 @@ * $FreeBSD: src/lib/msun/src/s_signbit.c,v 1.1 2004/07/19 08:16:10 das Exp $ */ -#include "openlibm.h" +#include #include "fpmath.h" diff --git a/src/s_signgam.c b/src/s_signgam.c index b5650f6..d67d591 100644 --- a/src/s_signgam.c +++ b/src/s_signgam.c @@ -1,3 +1,3 @@ -#include "openlibm.h" +#include "math.h" #include "math_private.h" int signgam = 0; diff --git a/src/s_significand.c b/src/s_significand.c index 9ebd562..e3d7335 100644 --- a/src/s_significand.c +++ b/src/s_significand.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_significand.c,v 1.10 2008/02/22 02:30:35 das Exp $"); /* * significand(x) computes just @@ -19,7 +19,7 @@ * for exercising the fraction-part(F) IEEE 754-1985 test vector. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" double diff --git a/src/s_significandf.c b/src/s_significandf.c index 6d39315..084418b 100644 --- a/src/s_significandf.c +++ b/src/s_significandf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_significandf.c,v 1.8 2008/02/22 02:30:36 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" float diff --git a/src/s_sin.c b/src/s_sin.c index 400bad3..aa27368 100644 --- a/src/s_sin.c +++ b/src/s_sin.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_sin.c,v 1.13 2011/02/10 07:37:50 das Exp $"); /* sin(x) * Return sine function of x. @@ -46,7 +46,7 @@ #include -#include "openlibm.h" +#include "math.h" #define INLINE_REM_PIO2 #include "math_private.h" #include "e_rem_pio2.c" diff --git a/src/s_sinf.c b/src/s_sinf.c index 0e3dd4f..0e340d3 100644 --- a/src/s_sinf.c +++ b/src/s_sinf.c @@ -15,11 +15,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_sinf.c,v 1.17 2008/02/25 22:19:17 bde Exp $"); #include -#include "openlibm.h" +#include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF #define INLINE_REM_PIO2F diff --git a/src/s_sinl.c b/src/s_sinl.c index e86c206..217a888 100644 --- a/src/s_sinl.c +++ b/src/s_sinl.c @@ -25,11 +25,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_sinl.c,v 1.3 2011/05/30 19:41:28 kargl Exp $"); #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #if LDBL_MANT_DIG == 64 #include "../ld80/e_rem_pio2l.h" diff --git a/src/s_tan.c b/src/s_tan.c index 87d2d78..dcb53cb 100644 --- a/src/s_tan.c +++ b/src/s_tan.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_tan.c,v 1.13 2011/02/10 07:37:50 das Exp $"); /* tan(x) * Return tangent function of x. @@ -45,7 +45,7 @@ #include -#include "openlibm.h" +#include "math.h" #define INLINE_REM_PIO2 #include "math_private.h" #include "e_rem_pio2.c" diff --git a/src/s_tanf.c b/src/s_tanf.c index b727f2a..80962d7 100644 --- a/src/s_tanf.c +++ b/src/s_tanf.c @@ -15,11 +15,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_tanf.c,v 1.17 2008/02/25 22:19:17 bde Exp $"); #include -#include "openlibm.h" +#include "math.h" #define INLINE_KERNEL_TANDF #define INLINE_REM_PIO2F #include "math_private.h" diff --git a/src/s_tanh.c b/src/s_tanh.c index 240dafc..a63c8e6 100644 --- a/src/s_tanh.c +++ b/src/s_tanh.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_tanh.c,v 1.9 2008/02/22 02:30:36 das Exp $"); /* Tanh(x) * Return the Hyperbolic Tangent of x @@ -37,7 +37,7 @@ * only tanh(0)=0 is exact for finite argument. */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double one = 1.0, two = 2.0, tiny = 1.0e-300, huge = 1.0e300; diff --git a/src/s_tanhf.c b/src/s_tanhf.c index 844ed70..bb6d8a5 100644 --- a/src/s_tanhf.c +++ b/src/s_tanhf.c @@ -14,9 +14,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.9 2008/02/22 02:30:36 das Exp $"); - -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float one=1.0, two=2.0, tiny = 1.0e-30, huge = 1.0e30; diff --git a/src/s_tanl.c b/src/s_tanl.c index c250bcc..5946668 100644 --- a/src/s_tanl.c +++ b/src/s_tanl.c @@ -25,7 +25,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_tanl.c,v 1.3 2011/05/30 19:41:28 kargl Exp $"); /* * Limited testing on pseudorandom numbers drawn within [0:4e8] shows @@ -35,7 +35,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" #if LDBL_MANT_DIG == 64 #include "../ld80/e_rem_pio2l.h" diff --git a/src/s_tgammaf.c b/src/s_tgammaf.c index ae50c00..37b3aa4 100644 --- a/src/s_tgammaf.c +++ b/src/s_tgammaf.c @@ -25,9 +25,9 @@ */ #include +__FBSDID("$FreeBSD: src/lib/msun/src/s_tgammaf.c,v 1.1 2008/02/18 17:27:10 das Exp $"); - -#include "openlibm.h" +#include /* * We simply call tgamma() rather than bloating the math library with diff --git a/src/s_trunc.c b/src/s_trunc.c index 6ba923a..3bb079c 100644 --- a/src/s_trunc.c +++ b/src/s_trunc.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_trunc.c,v 1.4 2008/02/22 02:27:34 das Exp $"); /* * trunc(x) @@ -24,7 +24,7 @@ #include -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; diff --git a/src/s_truncf.c b/src/s_truncf.c index a3a04bf..efec266 100644 --- a/src/s_truncf.c +++ b/src/s_truncf.c @@ -11,7 +11,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_truncf.c,v 1.1 2004/06/20 09:25:43 das Exp $"); /* * truncf(x) @@ -22,7 +22,7 @@ * Inexact flag raised if x not equal to truncf(x). */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" static const float huge = 1.0e30F; diff --git a/src/s_truncl.c b/src/s_truncl.c index f428b40..6f74cde 100644 --- a/src/s_truncl.c +++ b/src/s_truncl.c @@ -12,7 +12,7 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/s_truncl.c,v 1.9 2008/02/14 15:10:34 bde Exp $"); /* * truncl(x) @@ -24,7 +24,7 @@ */ #include -#include "openlibm.h" +#include #include #include "fpmath.h" @@ -49,7 +49,7 @@ truncl(long double x) if (huge + x > 0.0) u.e = zero[u.bits.sign]; } else { - u_int64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); + uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); if (((u.bits.manh & m) | u.bits.manl) == 0) return (x); /* x is integral */ if (huge + x > 0.0) { /* raise inexact flag */ @@ -58,7 +58,7 @@ truncl(long double x) } } } else if (e < LDBL_MANT_DIG - 1) { - u_int64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); + uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1); if ((u.bits.manl & m) == 0) return (x); /* x is integral */ if (huge + x > 0.0) /* raise inexact flag */ diff --git a/src/w_cabs.c b/src/w_cabs.c index 567ad8e..33ecf71 100644 --- a/src/w_cabs.c +++ b/src/w_cabs.c @@ -6,11 +6,11 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/w_cabs.c,v 1.7 2008/03/30 20:03:06 das Exp $"); #include #include -#include "openlibm.h" +#include double cabs(double complex z) diff --git a/src/w_cabsf.c b/src/w_cabsf.c index 3c6b592..fac152f 100644 --- a/src/w_cabsf.c +++ b/src/w_cabsf.c @@ -11,7 +11,7 @@ static const char rcsid[] = #endif /* not lint */ #include -#include "openlibm.h" +#include #include "math_private.h" float diff --git a/src/w_cabsl.c b/src/w_cabsl.c index 2b37033..21bc97d 100644 --- a/src/w_cabsl.c +++ b/src/w_cabsl.c @@ -8,10 +8,10 @@ */ #include - +__FBSDID("$FreeBSD: src/lib/msun/src/w_cabsl.c,v 1.1 2008/03/30 20:02:03 das Exp $"); #include -#include "openlibm.h" +#include long double cabsl(long double complex z) diff --git a/src/w_drem.c b/src/w_drem.c index 915adfa..0f68409 100644 --- a/src/w_drem.c +++ b/src/w_drem.c @@ -5,7 +5,7 @@ * Placed into the Public Domain, 1994. */ -#include "openlibm.h" +#include double drem(x, y) diff --git a/src/w_dremf.c b/src/w_dremf.c index 37d584a..e83ac0e 100644 --- a/src/w_dremf.c +++ b/src/w_dremf.c @@ -6,7 +6,7 @@ */ /* $FreeBSD: src/lib/msun/src/w_dremf.c,v 1.3 2004/07/28 05:53:18 kan Exp $ */ -#include "openlibm.h" +#include "math.h" #include "math_private.h" float