diff options
Diffstat (limited to 'libm')
353 files changed, 12420 insertions, 11195 deletions
diff --git a/libm/Android.mk b/libm/Android.mk index 7c9a2a0..90b4906 100644 --- a/libm/Android.mk +++ b/libm/Android.mk @@ -1,231 +1,295 @@ ifneq ($(TARGET_USE_PRIVATE_LIBM),true) LOCAL_PATH:= $(call my-dir) -libm_common_src_files:= \ - isinf.c \ - fpclassify.c \ - sincos.c \ - bsdsrc/b_exp.c \ - bsdsrc/b_log.c \ - bsdsrc/b_tgamma.c \ - src/e_acos.c \ - src/e_acosf.c \ - src/e_acosh.c \ - src/e_acoshf.c \ - src/e_asin.c \ - src/e_asinf.c \ - src/e_atan2.c \ - src/e_atan2f.c \ - src/e_atanh.c \ - src/e_atanhf.c \ - src/e_cosh.c \ - src/e_coshf.c \ - src/e_exp.c \ - src/e_expf.c \ - src/e_fmod.c \ - src/e_fmodf.c \ - src/e_gamma.c \ - src/e_gamma_r.c \ - src/e_gammaf.c \ - src/e_gammaf_r.c \ - src/e_hypot.c \ - src/e_hypotf.c \ - src/e_j0.c \ - src/e_j0f.c \ - src/e_j1.c \ - src/e_j1f.c \ - src/e_jn.c \ - src/e_jnf.c \ - src/e_lgamma.c \ - src/e_lgamma_r.c \ - src/e_lgammaf.c \ - src/e_lgammaf_r.c \ - src/e_log.c \ - src/e_log10.c \ - src/e_log10f.c \ - src/e_logf.c \ - src/e_pow.c \ - src/e_powf.c \ - src/e_rem_pio2.c \ - src/e_rem_pio2f.c \ - src/e_remainder.c \ - src/e_remainderf.c \ - src/e_scalb.c \ - src/e_scalbf.c \ - src/e_sinh.c \ - src/e_sinhf.c \ - src/e_sqrt.c \ - src/k_cos.c \ - src/k_cosf.c \ - src/k_rem_pio2.c \ - src/k_sin.c \ - src/k_sinf.c \ - src/k_tan.c \ - src/k_tanf.c \ - src/s_asinh.c \ - src/s_asinhf.c \ - src/s_atan.c \ - src/s_atanf.c \ - src/s_cbrt.c \ - src/s_cbrtf.c \ - src/s_ceil.c \ - src/s_ceilf.c \ - src/s_ceill.c \ - src/s_copysign.c \ - src/s_copysignf.c \ - src/s_cos.c \ - src/s_cosf.c \ - src/s_erf.c \ - src/s_erff.c \ - src/s_exp2.c \ - src/s_exp2f.c \ - src/s_expm1.c \ - src/s_expm1f.c \ - src/s_fabsf.c \ - src/s_fdim.c \ - src/s_finite.c \ - src/s_finitef.c \ - src/s_floor.c \ - src/s_floorf.c \ - src/s_floorl.c \ - src/s_fma.c \ - src/s_fmaf.c \ - src/s_fmax.c \ - src/s_fmaxf.c \ - src/s_fmaxl.c \ - src/s_fmin.c \ - src/s_fminf.c \ - src/s_fminl.c \ - src/s_frexpf.c \ - src/s_ilogb.c \ - src/s_ilogbf.c \ - src/s_ilogbl.c \ - src/s_isfinite.c \ - src/s_isnormal.c \ - src/s_llrint.c \ - src/s_llrintf.c \ - src/s_llround.c \ - src/s_llroundf.c \ - src/s_llroundl.c \ - src/s_log1p.c \ - src/s_log1pf.c \ - src/s_logb.c \ - src/s_logbf.c \ - src/s_lrint.c \ - src/s_lrintf.c \ - src/s_lround.c \ - src/s_lroundf.c \ - src/s_lroundl.c \ - src/s_modff.c \ - src/s_nan.c \ - src/s_nearbyint.c \ - src/s_nextafter.c \ - src/s_nextafterf.c \ - src/s_nexttowardf.c \ - src/s_remquo.c \ - src/s_remquof.c \ - src/s_rint.c \ - src/s_rintf.c \ - src/s_round.c \ - src/s_roundf.c \ - src/s_roundl.c \ - src/s_signbit.c \ - src/s_signgam.c \ - src/s_significand.c \ - src/s_significandf.c \ - src/s_sin.c \ - src/s_sinf.c \ - src/s_tan.c \ - src/s_tanf.c \ - src/s_tanh.c \ - src/s_tanhf.c \ - src/s_tgammaf.c \ - src/s_trunc.c \ - src/s_truncf.c \ - src/s_truncl.c \ - src/w_drem.c \ - src/w_dremf.c \ - src/s_copysignl.c \ - src/s_fabsl.c \ - src/s_fabs.c \ - src/s_frexp.c \ - src/s_isnan.c \ - src/s_modf.c - -libm_common_cflags := - -ifeq ($(TARGET_ARCH),arm) - libm_common_src_files += \ - arm/fenv.c \ - src/e_ldexpf.c \ - src/s_scalbln.c \ - src/s_scalbn.c \ - src/s_scalbnf.c \ - src/e_sqrtf.c - - libm_common_includes = $(LOCAL_PATH)/arm -endif +# TODO: this comes from from upstream's libc, not libm, but it's an +# implementation detail that should have hidden visibility, so it needs +# to be in whatever library the math code is in. +libm_common_src_files := \ + digittoint.c \ -ifeq ($(TARGET_OS)-$(TARGET_ARCH),linux-x86) - libm_common_src_files += \ - i387/fenv.c \ - i387/s_scalbnl.S \ - i387/s_scalbn.S \ - i387/s_scalbnf.S \ - i387/e_sqrtf.S +# TODO: this is not in the BSDs. +libm_common_src_files += \ + significandl.c \ + sincos.c \ - libm_common_includes = $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387 -endif -ifeq ($(TARGET_ARCH),mips) - libm_common_src_files += \ - mips/fenv.c \ - src/e_ldexpf.c \ - src/s_scalbln.c \ - src/s_scalbn.c \ - src/s_scalbnf.c \ - src/e_sqrtf.c - - libm_common_includes = $(LOCAL_PATH)/mips - # Need to build *rint* functions - libm_common_cflags += -fno-builtin-rintf -fno-builtin-rint -endif +libm_common_src_files += \ + upstream-freebsd/lib/msun/bsdsrc/b_exp.c \ + upstream-freebsd/lib/msun/bsdsrc/b_log.c \ + upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c \ + upstream-freebsd/lib/msun/src/e_acos.c \ + upstream-freebsd/lib/msun/src/e_acosf.c \ + upstream-freebsd/lib/msun/src/e_acosh.c \ + upstream-freebsd/lib/msun/src/e_acoshf.c \ + upstream-freebsd/lib/msun/src/e_asin.c \ + upstream-freebsd/lib/msun/src/e_asinf.c \ + upstream-freebsd/lib/msun/src/e_atan2.c \ + upstream-freebsd/lib/msun/src/e_atan2f.c \ + upstream-freebsd/lib/msun/src/e_atanh.c \ + upstream-freebsd/lib/msun/src/e_atanhf.c \ + upstream-freebsd/lib/msun/src/e_cosh.c \ + upstream-freebsd/lib/msun/src/e_coshf.c \ + upstream-freebsd/lib/msun/src/e_exp.c \ + upstream-freebsd/lib/msun/src/e_expf.c \ + upstream-freebsd/lib/msun/src/e_fmod.c \ + upstream-freebsd/lib/msun/src/e_fmodf.c \ + upstream-freebsd/lib/msun/src/e_gamma.c \ + upstream-freebsd/lib/msun/src/e_gammaf.c \ + upstream-freebsd/lib/msun/src/e_gammaf_r.c \ + upstream-freebsd/lib/msun/src/e_gamma_r.c \ + upstream-freebsd/lib/msun/src/e_hypot.c \ + upstream-freebsd/lib/msun/src/e_hypotf.c \ + upstream-freebsd/lib/msun/src/e_j0.c \ + upstream-freebsd/lib/msun/src/e_j0f.c \ + upstream-freebsd/lib/msun/src/e_j1.c \ + upstream-freebsd/lib/msun/src/e_j1f.c \ + upstream-freebsd/lib/msun/src/e_jn.c \ + upstream-freebsd/lib/msun/src/e_jnf.c \ + upstream-freebsd/lib/msun/src/e_lgamma.c \ + upstream-freebsd/lib/msun/src/e_lgammaf.c \ + upstream-freebsd/lib/msun/src/e_lgammaf_r.c \ + upstream-freebsd/lib/msun/src/e_lgamma_r.c \ + upstream-freebsd/lib/msun/src/e_log10.c \ + upstream-freebsd/lib/msun/src/e_log10f.c \ + upstream-freebsd/lib/msun/src/e_log2.c \ + upstream-freebsd/lib/msun/src/e_log2f.c \ + upstream-freebsd/lib/msun/src/e_log.c \ + upstream-freebsd/lib/msun/src/e_logf.c \ + upstream-freebsd/lib/msun/src/e_pow.c \ + upstream-freebsd/lib/msun/src/e_powf.c \ + upstream-freebsd/lib/msun/src/e_remainder.c \ + upstream-freebsd/lib/msun/src/e_remainderf.c \ + upstream-freebsd/lib/msun/src/e_rem_pio2.c \ + upstream-freebsd/lib/msun/src/e_rem_pio2f.c \ + upstream-freebsd/lib/msun/src/e_scalb.c \ + upstream-freebsd/lib/msun/src/e_scalbf.c \ + upstream-freebsd/lib/msun/src/e_sinh.c \ + upstream-freebsd/lib/msun/src/e_sinhf.c \ + upstream-freebsd/lib/msun/src/e_sqrt.c \ + upstream-freebsd/lib/msun/src/e_sqrtf.c \ + upstream-freebsd/lib/msun/src/imprecise.c \ + upstream-freebsd/lib/msun/src/k_cos.c \ + upstream-freebsd/lib/msun/src/k_cosf.c \ + upstream-freebsd/lib/msun/src/k_exp.c \ + upstream-freebsd/lib/msun/src/k_expf.c \ + upstream-freebsd/lib/msun/src/k_rem_pio2.c \ + upstream-freebsd/lib/msun/src/k_sin.c \ + upstream-freebsd/lib/msun/src/k_sinf.c \ + upstream-freebsd/lib/msun/src/k_tan.c \ + upstream-freebsd/lib/msun/src/k_tanf.c \ + upstream-freebsd/lib/msun/src/s_asinh.c \ + upstream-freebsd/lib/msun/src/s_asinhf.c \ + upstream-freebsd/lib/msun/src/s_atan.c \ + upstream-freebsd/lib/msun/src/s_atanf.c \ + upstream-freebsd/lib/msun/src/s_carg.c \ + upstream-freebsd/lib/msun/src/s_cargf.c \ + upstream-freebsd/lib/msun/src/s_cbrt.c \ + upstream-freebsd/lib/msun/src/s_cbrtf.c \ + upstream-freebsd/lib/msun/src/s_ccosh.c \ + upstream-freebsd/lib/msun/src/s_ccoshf.c \ + upstream-freebsd/lib/msun/src/s_ceil.c \ + upstream-freebsd/lib/msun/src/s_ceilf.c \ + upstream-freebsd/lib/msun/src/s_cexp.c \ + upstream-freebsd/lib/msun/src/s_cexpf.c \ + upstream-freebsd/lib/msun/src/s_cimag.c \ + upstream-freebsd/lib/msun/src/s_cimagf.c \ + upstream-freebsd/lib/msun/src/s_conj.c \ + upstream-freebsd/lib/msun/src/s_conjf.c \ + upstream-freebsd/lib/msun/src/s_copysign.c \ + upstream-freebsd/lib/msun/src/s_copysignf.c \ + upstream-freebsd/lib/msun/src/s_cos.c \ + upstream-freebsd/lib/msun/src/s_cosf.c \ + upstream-freebsd/lib/msun/src/s_cproj.c \ + upstream-freebsd/lib/msun/src/s_cprojf.c \ + upstream-freebsd/lib/msun/src/s_creal.c \ + upstream-freebsd/lib/msun/src/s_crealf.c \ + upstream-freebsd/lib/msun/src/s_csinh.c \ + upstream-freebsd/lib/msun/src/s_csinhf.c \ + upstream-freebsd/lib/msun/src/s_csqrt.c \ + upstream-freebsd/lib/msun/src/s_csqrtf.c \ + upstream-freebsd/lib/msun/src/s_ctanh.c \ + upstream-freebsd/lib/msun/src/s_ctanhf.c \ + upstream-freebsd/lib/msun/src/s_erf.c \ + upstream-freebsd/lib/msun/src/s_erff.c \ + upstream-freebsd/lib/msun/src/s_exp2.c \ + upstream-freebsd/lib/msun/src/s_exp2f.c \ + upstream-freebsd/lib/msun/src/s_expm1.c \ + upstream-freebsd/lib/msun/src/s_expm1f.c \ + upstream-freebsd/lib/msun/src/s_fabs.c \ + upstream-freebsd/lib/msun/src/s_fabsf.c \ + upstream-freebsd/lib/msun/src/s_fdim.c \ + upstream-freebsd/lib/msun/src/s_finite.c \ + upstream-freebsd/lib/msun/src/s_finitef.c \ + upstream-freebsd/lib/msun/src/s_floor.c \ + upstream-freebsd/lib/msun/src/s_floorf.c \ + upstream-freebsd/lib/msun/src/s_fma.c \ + upstream-freebsd/lib/msun/src/s_fmaf.c \ + upstream-freebsd/lib/msun/src/s_fmax.c \ + upstream-freebsd/lib/msun/src/s_fmaxf.c \ + upstream-freebsd/lib/msun/src/s_fmin.c \ + upstream-freebsd/lib/msun/src/s_fminf.c \ + upstream-freebsd/lib/msun/src/s_frexp.c \ + upstream-freebsd/lib/msun/src/s_frexpf.c \ + upstream-freebsd/lib/msun/src/s_ilogb.c \ + upstream-freebsd/lib/msun/src/s_ilogbf.c \ + upstream-freebsd/lib/msun/src/s_llrint.c \ + upstream-freebsd/lib/msun/src/s_llrintf.c \ + upstream-freebsd/lib/msun/src/s_llround.c \ + upstream-freebsd/lib/msun/src/s_llroundf.c \ + upstream-freebsd/lib/msun/src/s_log1p.c \ + upstream-freebsd/lib/msun/src/s_log1pf.c \ + upstream-freebsd/lib/msun/src/s_logb.c \ + upstream-freebsd/lib/msun/src/s_logbf.c \ + upstream-freebsd/lib/msun/src/s_lrint.c \ + upstream-freebsd/lib/msun/src/s_lrintf.c \ + upstream-freebsd/lib/msun/src/s_lround.c \ + upstream-freebsd/lib/msun/src/s_lroundf.c \ + upstream-freebsd/lib/msun/src/s_modf.c \ + upstream-freebsd/lib/msun/src/s_modff.c \ + upstream-freebsd/lib/msun/src/s_nan.c \ + upstream-freebsd/lib/msun/src/s_nearbyint.c \ + upstream-freebsd/lib/msun/src/s_nextafter.c \ + upstream-freebsd/lib/msun/src/s_nextafterf.c \ + upstream-freebsd/lib/msun/src/s_remquo.c \ + upstream-freebsd/lib/msun/src/s_remquof.c \ + upstream-freebsd/lib/msun/src/s_rint.c \ + upstream-freebsd/lib/msun/src/s_rintf.c \ + upstream-freebsd/lib/msun/src/s_round.c \ + upstream-freebsd/lib/msun/src/s_roundf.c \ + upstream-freebsd/lib/msun/src/s_scalbln.c \ + upstream-freebsd/lib/msun/src/s_scalbn.c \ + upstream-freebsd/lib/msun/src/s_scalbnf.c \ + upstream-freebsd/lib/msun/src/s_signgam.c \ + upstream-freebsd/lib/msun/src/s_significand.c \ + upstream-freebsd/lib/msun/src/s_significandf.c \ + upstream-freebsd/lib/msun/src/s_sin.c \ + upstream-freebsd/lib/msun/src/s_sinf.c \ + upstream-freebsd/lib/msun/src/s_tan.c \ + upstream-freebsd/lib/msun/src/s_tanf.c \ + upstream-freebsd/lib/msun/src/s_tanh.c \ + upstream-freebsd/lib/msun/src/s_tanhf.c \ + upstream-freebsd/lib/msun/src/s_tgammaf.c \ + upstream-freebsd/lib/msun/src/s_trunc.c \ + upstream-freebsd/lib/msun/src/s_truncf.c \ + upstream-freebsd/lib/msun/src/w_cabs.c \ + upstream-freebsd/lib/msun/src/w_cabsf.c \ + upstream-freebsd/lib/msun/src/w_drem.c \ + upstream-freebsd/lib/msun/src/w_dremf.c \ -# libm.a -# ======================================================== +libm_common_src_files += \ + fake_long_double.c \ + signbit.c \ -include $(CLEAR_VARS) +libm_ld_src_files = \ + upstream-freebsd/lib/msun/src/e_acosl.c \ + upstream-freebsd/lib/msun/src/e_acoshl.c \ + upstream-freebsd/lib/msun/src/e_asinl.c \ + upstream-freebsd/lib/msun/src/e_atan2l.c \ + upstream-freebsd/lib/msun/src/e_atanhl.c \ + upstream-freebsd/lib/msun/src/e_fmodl.c \ + upstream-freebsd/lib/msun/src/e_hypotl.c \ + upstream-freebsd/lib/msun/src/e_remainderl.c \ + upstream-freebsd/lib/msun/src/e_sqrtl.c \ + upstream-freebsd/lib/msun/src/s_asinhl.c \ + upstream-freebsd/lib/msun/src/s_atanl.c \ + upstream-freebsd/lib/msun/src/s_cbrtl.c \ + upstream-freebsd/lib/msun/src/s_ceill.c \ + upstream-freebsd/lib/msun/src/s_copysignl.c \ + upstream-freebsd/lib/msun/src/s_cosl.c \ + upstream-freebsd/lib/msun/src/s_fabsl.c \ + upstream-freebsd/lib/msun/src/s_floorl.c \ + upstream-freebsd/lib/msun/src/s_fmal.c \ + upstream-freebsd/lib/msun/src/s_fmaxl.c \ + upstream-freebsd/lib/msun/src/s_fminl.c \ + upstream-freebsd/lib/msun/src/s_modfl.c \ + upstream-freebsd/lib/msun/src/s_frexpl.c \ + upstream-freebsd/lib/msun/src/s_ilogbl.c \ + upstream-freebsd/lib/msun/src/s_llrintl.c \ + upstream-freebsd/lib/msun/src/s_llroundl.c \ + upstream-freebsd/lib/msun/src/s_logbl.c \ + upstream-freebsd/lib/msun/src/s_lrintl.c \ + upstream-freebsd/lib/msun/src/s_lroundl.c \ + upstream-freebsd/lib/msun/src/s_nextafterl.c \ + upstream-freebsd/lib/msun/src/s_nexttoward.c \ + upstream-freebsd/lib/msun/src/s_nexttowardf.c \ + upstream-freebsd/lib/msun/src/s_remquol.c \ + upstream-freebsd/lib/msun/src/s_rintl.c \ + upstream-freebsd/lib/msun/src/s_roundl.c \ + upstream-freebsd/lib/msun/src/s_scalbnl.c \ + upstream-freebsd/lib/msun/src/s_sinl.c \ + upstream-freebsd/lib/msun/src/s_tanl.c \ + upstream-freebsd/lib/msun/src/s_truncl.c \ -LOCAL_SRC_FILES := \ - $(libm_common_src_files) +libm_ld_src_files += \ + upstream-freebsd/lib/msun/ld128/invtrig.c \ + upstream-freebsd/lib/msun/ld128/k_cosl.c \ + upstream-freebsd/lib/msun/ld128/k_sinl.c \ + upstream-freebsd/lib/msun/ld128/k_tanl.c \ + upstream-freebsd/lib/msun/ld128/s_exp2l.c \ + upstream-freebsd/lib/msun/ld128/s_expl.c \ + upstream-freebsd/lib/msun/ld128/s_logl.c \ + upstream-freebsd/lib/msun/ld128/s_nanl.c \ -LOCAL_ARM_MODE := arm -LOCAL_C_INCLUDES += $(libm_common_includes) -LOCAL_CFLAGS := $(libm_common_cflags) +# TODO: re-enable i387/e_sqrtf.S for x86, and maybe others. +libm_common_cflags := \ + -DFLT_EVAL_METHOD=0 \ + -std=c99 \ + -include $(LOCAL_PATH)/freebsd-compat.h \ + -Wno-missing-braces \ + -Wno-parentheses \ + -Wno-sign-compare \ + -Wno-uninitialized \ + -Wno-unknown-pragmas \ + -fvisibility=hidden \ + +# Workaround the GCC "(long)fn -> lfn" optimization bug which will result in +# self recursions for lrint, lrintf, and lrintl. +# BUG: 14225968 +libm_common_cflags += -fno-builtin-rint -fno-builtin-rintf -fno-builtin-rintl + +libm_common_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/ + +libm_ld_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/ + +# +# libm.a for target. +# +include $(CLEAR_VARS) LOCAL_MODULE:= libm LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk - +LOCAL_ARM_MODE := arm +LOCAL_CFLAGS := $(libm_common_cflags) +LOCAL_C_INCLUDES += $(libm_common_includes) +LOCAL_SRC_FILES := $(libm_common_src_files) LOCAL_SYSTEM_SHARED_LIBRARIES := libc -include $(BUILD_STATIC_LIBRARY) +# arch-specific settings +LOCAL_C_INCLUDES_arm := $(LOCAL_PATH)/arm +LOCAL_SRC_FILES_arm := arm/fenv.c -# libm.so -# ======================================================== +LOCAL_C_INCLUDES_arm64 := $(libm_ld_includes) +LOCAL_SRC_FILES_arm64 := arm64/fenv.c $(libm_ld_src_files) -include $(CLEAR_VARS) +LOCAL_C_INCLUDES_x86 := $(LOCAL_PATH)/i387 +LOCAL_SRC_FILES_x86 := i387/fenv.c -LOCAL_SRC_FILES := \ - $(libm_common_src_files) +LOCAL_C_INCLUDES_x86_64 := $(libm_ld_includes) +LOCAL_SRC_FILES_x86_64 := amd64/fenv.c $(libm_ld_src_files) -LOCAL_ARM_MODE := arm +LOCAL_SRC_FILES_mips := mips/fenv.c -LOCAL_C_INCLUDES += $(libm_common_includes) -LOCAL_CFLAGS := $(libm_common_cflags) +LOCAL_C_INCLUDES_mips64 := $(libm_ld_includes) +LOCAL_SRC_FILES_mips64 := mips/fenv.c $(libm_ld_src_files) + +include $(BUILD_STATIC_LIBRARY) +# +# libm.so for target. +# +include $(CLEAR_VARS) LOCAL_MODULE:= libm LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk - LOCAL_SYSTEM_SHARED_LIBRARIES := libc - +LOCAL_WHOLE_STATIC_LIBRARIES := libm include $(BUILD_SHARED_LIBRARY) endif diff --git a/libm/NOTICE b/libm/NOTICE index c3968cd..5be60db 100644 --- a/libm/NOTICE +++ b/libm/NOTICE @@ -1,10 +1,10 @@ - Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +==================================================== +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. - ==================================================== +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. ------------------------------------------------------------------- @@ -15,13 +15,26 @@ 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. +==================================================== + +Optimized by Bruce D. Evans. ------------------------------------------------------------------- ==================================================== Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. -Developed at SunPro, a Sun Microsystems, Inc. business. +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. + +------------------------------------------------------------------- + +==================================================== +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. @@ -33,11 +46,42 @@ Optimized by Bruce D. Evans. ==================================================== 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. + +------------------------------------------------------------------- + +==================================================== +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. + +------------------------------------------------------------------- + +==================================================== +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. ------------------------------------------------------------------- @@ -59,6 +103,84 @@ is preserved. ------------------------------------------------------------------- +==================================================== +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. + +------------------------------------------------------------------- + +Copyright (C) 2010 The Android Open Source Project +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. + +------------------------------------------------------------------- + +Copyright (C) 2013 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +------------------------------------------------------------------- + +Copyright (C) 2014 The Android Open Source Project +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. + +------------------------------------------------------------------- + Copyright (c) 1985, 1993 The Regents of the University of California. All rights reserved. @@ -190,7 +312,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 1993,94 Winning Strategies, Inc. +Copyright (c) 2001-2011 The FreeBSD Project. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -201,70 +323,34 @@ are met: 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. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - This product includes software developed by Winning Strategies, Inc. -4. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission -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. - -------------------------------------------------------------------- - -Copyright (c) 1993,94 Winning Strategies, Inc. -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. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - This product includes software developed by Winning Strategies, Inc. -4. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -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. +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. ------------------------------------------------------------------- -Copyright (c) 1994 Winning Strategies, Inc. +Copyright (c) 2003 Dag-Erling Smørgrav 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. + notice, this list of conditions and the following disclaimer + in this position and unchanged. 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. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - This product includes software developed by Winning Strategies, Inc. -4. The name of the author may not be used to endorse or promote products +3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR @@ -280,12 +366,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 1996 The NetBSD Foundation, Inc. +Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> All rights reserved. -This code is derived from software contributed to The NetBSD Foundation -by J.T. Conklin. - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -294,29 +377,23 @@ are met: 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. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: - This product includes software developed by the NetBSD - Foundation, Inc. and its contributors. -4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. +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. ------------------------------------------------------------------- -Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> +Copyright (c) 2002 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -342,20 +419,18 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003 Dag-Erling Smørgrav +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 - in this position and unchanged. + 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. -3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -370,7 +445,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -396,7 +471,33 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> +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 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. + +------------------------------------------------------------------- + +Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -422,8 +523,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> -Copyright (c) 2002 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -449,8 +549,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> -Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2004-2011 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -476,7 +575,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2003, Steven G. Kargl +Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl All rights reserved. Redistribution and use in source and binary forms, with or without @@ -502,7 +601,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -528,7 +627,59 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2004 Stefan Farfeleder +Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG> +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. + +------------------------------------------------------------------- + +Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG> +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. + +------------------------------------------------------------------- + +Copyright (c) 2007 David Schultz All rights reserved. Redistribution and use in source and binary forms, with or without @@ -554,7 +705,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -580,7 +731,7 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> +Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -604,9 +755,44 @@ 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. +Derived from s_modf.c, which has the following Copyright: +==================================================== +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. + ------------------------------------------------------------------- -Copyright (c) 2007 David Schultz +Copyright (c) 2007 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. + +------------------------------------------------------------------- + +Copyright (c) 2007-2008 David Schultz <das@FreeBSD.ORG> All rights reserved. Redistribution and use in source and binary forms, with or without @@ -618,10 +804,10 @@ are met: 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 +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 AUTHOR OR CONTRIBUTORS BE LIABLE +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) @@ -632,6 +818,32 @@ SUCH DAMAGE. ------------------------------------------------------------------- +Copyright (c) 2007-2013 Bruce D. Evans +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. + +------------------------------------------------------------------- + Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> All rights reserved. @@ -658,7 +870,113 @@ SUCH DAMAGE. ------------------------------------------------------------------- -Copyright (c) 2010 The Android Open Source Project +Copyright (c) 2009-2013 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. + +Optimized by Bruce D. Evans. + +------------------------------------------------------------------- + +Copyright (c) 2010 The NetBSD Foundation, Inc. +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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + +------------------------------------------------------------------- + +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. + +------------------------------------------------------------------- + +Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> +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. + +------------------------------------------------------------------- + +Copyright (c) 2013 David Chisnall All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/libm/amd64/fenv.c b/libm/amd64/fenv.c new file mode 100755 index 0000000..4b24ff9 --- /dev/null +++ b/libm/amd64/fenv.c @@ -0,0 +1,417 @@ +/* $OpenBSD: fenv.c,v 1.3 2012/12/05 23:20:02 deraadt Exp $ */ +/* $NetBSD: fenv.c,v 1.1 2010/07/31 21:47:53 joerg Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> + * 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 <fenv.h> +#include <machine/fpu.h> + +#define SSE_MASK_SHIFT 7 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) +#define SSE_ROUND_SHIFT 3 + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the <fenv.h> header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + * + * x87 fpu registers are 16bit wide. The upper bits, 31-16, are marked as + * RESERVED. + */ +const fenv_t __fe_dfl_env = { + { + 0xffff0000 | __INITIAL_NPXCW__, /* Control word register */ + 0xffff0000, /* Status word register */ + 0xffffffff, /* Tag word register */ + { + 0x00000000, + 0x00000000, + 0x00000000, + 0xffff0000 + } + }, + __INITIAL_MXCSR__ /* MXCSR register */ +}; + + +/* + * The feclearexcept() function clears the supported floating-point exceptions + * represented by `excepts'. + */ +int +feclearexcept(int excepts) +{ + fenv_t fenv; + unsigned int mxcsr; + + excepts &= FE_ALL_EXCEPT; + + /* Store the current x87 floating-point environment */ + __asm__ __volatile__ ("fnstenv %0" : "=m" (fenv)); + + /* Clear the requested floating-point exceptions */ + fenv.__x87.__status &= ~excepts; + + /* Load the x87 floating-point environent */ + __asm__ __volatile__ ("fldenv %0" : : "m" (fenv)); + + /* Same for SSE environment */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + mxcsr &= ~excepts; + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (0); +} + +/* + * The fegetexceptflag() function stores an implementation-defined + * representation of the states of the floating-point status flags indicated by + * the argument excepts in the object pointed to by the argument flagp. + */ +int +fegetexceptflag(fexcept_t *flagp, int excepts) +{ + unsigned short status; + unsigned int mxcsr; + + excepts &= FE_ALL_EXCEPT; + + /* Store the current x87 status register */ + __asm__ __volatile__ ("fnstsw %0" : "=am" (status)); + + /* Store the MXCSR register */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + + /* Store the results in flagp */ + *flagp = (status | mxcsr) & excepts; + + return (0); +} + +/* + * The feraiseexcept() function raises the supported floating-point exceptions + * represented by the argument `excepts'. + * + * The standard explicitly allows us to execute an instruction that has the + * exception as a side effect, but we choose to manipulate the status register + * directly. + * + * The validation of input is being deferred to fesetexceptflag(). + */ +int +feraiseexcept(int excepts) +{ + excepts &= FE_ALL_EXCEPT; + + fesetexceptflag((fexcept_t *)&excepts, excepts); + __asm__ __volatile__ ("fwait"); + + return (0); +} + +/* + * This function sets the floating-point status flags indicated by the argument + * `excepts' to the states stored in the object pointed to by `flagp'. It does + * NOT raise any floating-point exceptions, but only sets the state of the flags. + */ +int +fesetexceptflag(const fexcept_t *flagp, int excepts) +{ + fenv_t fenv; + unsigned int mxcsr; + + excepts &= FE_ALL_EXCEPT; + + /* Store the current x87 floating-point environment */ + __asm__ __volatile__ ("fnstenv %0" : "=m" (fenv)); + + /* Set the requested status flags */ + fenv.__x87.__status &= ~excepts; + fenv.__x87.__status |= *flagp & excepts; + + /* Load the x87 floating-point environent */ + __asm__ __volatile__ ("fldenv %0" : : "m" (fenv)); + + /* Same for SSE environment */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + mxcsr &= ~excepts; + mxcsr |= *flagp & excepts; + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (0); +} + +/* + * The fetestexcept() function determines which of a specified subset of the + * floating-point exception flags are currently set. The `excepts' argument + * specifies the floating-point status flags to be queried. + */ +int +fetestexcept(int excepts) +{ + unsigned short status; + unsigned int mxcsr; + + excepts &= FE_ALL_EXCEPT; + + /* Store the current x87 status register */ + __asm__ __volatile__ ("fnstsw %0" : "=am" (status)); + + /* Store the MXCSR register state */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + + return ((status | mxcsr) & excepts); +} + +/* + * The fegetround() function gets the current rounding direction. + */ +int +fegetround(void) +{ + unsigned short control; + + /* + * We assume that the x87 and the SSE unit agree on the + * rounding mode. Reading the control word on the x87 turns + * out to be about 5 times faster than reading it on the SSE + * unit on an Opteron 244. + */ + __asm__ __volatile__ ("fnstcw %0" : "=m" (control)); + + return (control & X87_ROUND_MASK); +} + +/* + * The fesetround() function establishes the rounding direction represented by + * its argument `round'. If the argument is not equal to the value of a rounding + * direction macro, the rounding direction is not changed. + */ +int +fesetround(int round) +{ + unsigned short control; + unsigned int mxcsr; + + /* Check whether requested rounding direction is supported */ + if (round & ~X87_ROUND_MASK) + return (-1); + + /* Store the current x87 control word register */ + __asm__ __volatile__ ("fnstcw %0" : "=m" (control)); + + /* Set the rounding direction */ + control &= ~X87_ROUND_MASK; + control |= round; + + /* Load the x87 control word register */ + __asm__ __volatile__ ("fldcw %0" : : "m" (control)); + + /* Same for the SSE environment */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + mxcsr &= ~(X87_ROUND_MASK << SSE_ROUND_SHIFT); + mxcsr |= round << SSE_ROUND_SHIFT; + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (0); +} + +/* + * The fegetenv() function attempts to store the current floating-point + * environment in the object pointed to by envp. + */ +int +fegetenv(fenv_t *envp) +{ + /* Store the current x87 floating-point environment */ + __asm__ __volatile__ ("fnstenv %0" : "=m" (*envp)); + + /* Store the MXCSR register state */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr)); + + /* + * When an FNSTENV instruction is executed, all pending exceptions are + * essentially lost (either the x87 FPU status register is cleared or + * all exceptions are masked). + * + * 8.6 X87 FPU EXCEPTION SYNCHRONIZATION - + * Intel(R) 64 and IA-32 Architectures Softare Developer's Manual - Vol1 + */ + __asm__ __volatile__ ("fldcw %0" : : "m" (envp->__x87.__control)); + + return (0); +} + +/* + * The feholdexcept() function saves the current floating-point environment + * in the object pointed to by envp, clears the floating-point status flags, and + * then installs a non-stop (continue on floating-point exceptions) mode, if + * available, for all floating-point exceptions. + */ +int +feholdexcept(fenv_t *envp) +{ + unsigned int mxcsr; + + /* Store the current x87 floating-point environment */ + __asm__ __volatile__ ("fnstenv %0" : "=m" (*envp)); + + /* Clear all exception flags in FPU */ + __asm__ __volatile__ ("fnclex"); + + /* Store the MXCSR register state */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (envp->__mxcsr)); + + /* Clear exception flags in MXCSR */ + mxcsr = envp->__mxcsr; + mxcsr &= ~FE_ALL_EXCEPT; + + /* Mask all exceptions */ + mxcsr |= FE_ALL_EXCEPT << SSE_MASK_SHIFT; + + /* Store the MXCSR register */ + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (0); +} + +/* + * The fesetenv() function attempts to establish the floating-point environment + * represented by the object pointed to by envp. The argument `envp' points + * to an object set by a call to fegetenv() or feholdexcept(), or equal a + * floating-point environment macro. The fesetenv() function does not raise + * floating-point exceptions, but only installs the state of the floating-point + * status flags represented through its argument. + */ +int +fesetenv(const fenv_t *envp) +{ + /* Load the x87 floating-point environent */ + __asm__ __volatile__ ("fldenv %0" : : "m" (*envp)); + + /* Store the MXCSR register */ + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (envp->__mxcsr)); + + return (0); +} + +/* + * The feupdateenv() function saves the currently raised floating-point + * exceptions in its automatic storage, installs the floating-point environment + * represented by the object pointed to by `envp', and then raises the saved + * floating-point exceptions. The argument `envp' shall point to an object set + * by a call to feholdexcept() or fegetenv(), or equal a floating-point + * environment macro. + */ +int +feupdateenv(const fenv_t *envp) +{ + unsigned short status; + unsigned int mxcsr; + + /* Store the x87 status register */ + __asm__ __volatile__ ("fnstsw %0" : "=am" (status)); + + /* Store the MXCSR register */ + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + + /* Install new floating-point environment */ + fesetenv(envp); + + /* Raise any previously accumulated exceptions */ + feraiseexcept(status | mxcsr); + + return (0); +} + +/* + * The following functions are extentions to the standard + */ +int +feenableexcept(int mask) +{ + unsigned int mxcsr, omask; + unsigned short control; + + mask &= FE_ALL_EXCEPT; + + __asm__ __volatile__ ("fnstcw %0" : "=m" (control)); + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + + omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT; + control &= ~mask; + __asm__ __volatile__ ("fldcw %0" : : "m" (control)); + + mxcsr &= ~(mask << SSE_MASK_SHIFT); + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (omask); +} + +int +fedisableexcept(int mask) +{ + unsigned int mxcsr, omask; + unsigned short control; + + mask &= FE_ALL_EXCEPT; + + __asm__ __volatile__ ("fnstcw %0" : "=m" (control)); + __asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr)); + + omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT; + control |= mask; + __asm__ __volatile__ ("fldcw %0" : : "m" (control)); + + mxcsr |= mask << SSE_MASK_SHIFT; + __asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr)); + + return (omask); +} + +int +fegetexcept(void) +{ + unsigned short control; + + /* + * We assume that the masks for the x87 and the SSE unit are + * the same. + */ + __asm__ __volatile__ ("fnstcw %0" : "=m" (control)); + + return (~control & FE_ALL_EXCEPT); +} diff --git a/libm/arm/_fpmath.h b/libm/arm/_fpmath.h deleted file mode 100644 index 79e4346..0000000 --- a/libm/arm/_fpmath.h +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> - * 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/libc/arm/_fpmath.h,v 1.4 2005/03/20 00:53:52 cognet Exp $ - */ - -union IEEEl2bits { - long double e; - struct { -#ifndef __ARMEB__ - unsigned int manl :32; - unsigned int manh :20; - unsigned int exp :11; - unsigned int sign :1; -#else - unsigned int sign :1; - unsigned int exp :11; - unsigned int manh :20; - unsigned int manl :32; -#endif - } bits; -}; - -#define LDBL_NBIT 0 -#define mask_nbit_l(u) ((void)0) - -#define LDBL_MANH_SIZE 32 -#define LDBL_MANL_SIZE 32 - -#define LDBL_TO_ARRAY32(u, a) do { \ - (a)[0] = (uint32_t)(u).bits.manl; \ - (a)[1] = (uint32_t)(u).bits.manh; \ -} while(0) diff --git a/libm/arm/fenv.c b/libm/arm/fenv.c index 469f198..2124730 100644 --- a/libm/arm/fenv.c +++ b/libm/arm/fenv.c @@ -28,8 +28,112 @@ #include <fenv.h> -/* - * Hopefully the system ID byte is immutable, so it's valid to use - * this as a default environment. - */ +#define FPSCR_ENABLE_SHIFT 8 +#define FPSCR_ENABLE_MASK (FE_ALL_EXCEPT << FPSCR_ENABLE_SHIFT) + +#define FPSCR_RMODE_SHIFT 22 + const fenv_t __fe_dfl_env = 0; + +int fegetenv(fenv_t* __envp) { + fenv_t _fpscr; + __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr)); + *__envp = _fpscr; + return 0; +} + +int fesetenv(const fenv_t* __envp) { + fenv_t _fpscr = *__envp; + __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr)); + return 0; +} + +int feclearexcept(int __excepts) { + fexcept_t __fpscr; + fegetenv(&__fpscr); + __fpscr &= ~__excepts; + fesetenv(&__fpscr); + return 0; +} + +int fegetexceptflag(fexcept_t* __flagp, int __excepts) { + fexcept_t __fpscr; + fegetenv(&__fpscr); + *__flagp = __fpscr & __excepts; + return 0; +} + +int fesetexceptflag(const fexcept_t* __flagp, int __excepts) { + fexcept_t __fpscr; + fegetenv(&__fpscr); + __fpscr &= ~__excepts; + __fpscr |= *__flagp & __excepts; + fesetenv(&__fpscr); + return 0; +} + +int feraiseexcept(int __excepts) { + fexcept_t __ex = __excepts; + fesetexceptflag(&__ex, __excepts); + return 0; +} + +int fetestexcept(int __excepts) { + fexcept_t __fpscr; + fegetenv(&__fpscr); + return (__fpscr & __excepts); +} + +int fegetround(void) { + fenv_t _fpscr; + fegetenv(&_fpscr); + return ((_fpscr >> FPSCR_RMODE_SHIFT) & 0x3); +} + +int fesetround(int __round) { + fenv_t _fpscr; + fegetenv(&_fpscr); + _fpscr &= ~(0x3 << FPSCR_RMODE_SHIFT); + _fpscr |= (__round << FPSCR_RMODE_SHIFT); + fesetenv(&_fpscr); + return 0; +} + +int feholdexcept(fenv_t* __envp) { + fenv_t __env; + fegetenv(&__env); + *__envp = __env; + __env &= ~(FE_ALL_EXCEPT | FPSCR_ENABLE_MASK); + fesetenv(&__env); + return 0; +} + +int feupdateenv(const fenv_t* __envp) { + fexcept_t __fpscr; + fegetenv(&__fpscr); + fesetenv(__envp); + feraiseexcept(__fpscr & FE_ALL_EXCEPT); + return 0; +} + +int feenableexcept(int __mask) { + fenv_t __old_fpscr, __new_fpscr; + fegetenv(&__old_fpscr); + __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT; + fesetenv(&__new_fpscr); + return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT); +} + +int fedisableexcept(int __mask) { + fenv_t __old_fpscr, __new_fpscr; + fegetenv(&__old_fpscr); + __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << FPSCR_ENABLE_SHIFT); + fesetenv(&__new_fpscr); + return ((__old_fpscr >> FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT); +} + +int fegetexcept(void) { + fenv_t __fpscr; + fegetenv(&__fpscr); + return ((__fpscr & FPSCR_ENABLE_MASK) >> FPSCR_ENABLE_SHIFT); +} diff --git a/libm/arm64/fenv.c b/libm/arm64/fenv.c new file mode 100644 index 0000000..ce560a7 --- /dev/null +++ b/libm/arm64/fenv.c @@ -0,0 +1,195 @@ +/*- + * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> + * 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: libm/aarch64/fenv.c $ + */ + +#include <fenv.h> + +#define FPCR_EXCEPT_SHIFT 8 +#define FPCR_EXCEPT_MASK (FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT) + +#define FPCR_RMODE_SHIFT 22 + +const fenv_t __fe_dfl_env = { 0 /* control */, 0 /* status */}; + +typedef __uint32_t fpu_control_t; // FPCR, Floating-point Control Register. +typedef __uint32_t fpu_status_t; // FPSR, Floating-point Status Register. + +#define __get_fpcr(__fpcr) __asm__ __volatile__("mrs %0,fpcr" : "=r" (__fpcr)) +#define __get_fpsr(__fpsr) __asm__ __volatile__("mrs %0,fpsr" : "=r" (__fpsr)) +#define __set_fpcr(__fpcr) __asm__ __volatile__("msr fpcr,%0" : :"ri" (__fpcr)) +#define __set_fpsr(__fpsr) __asm__ __volatile__("msr fpsr,%0" : :"ri" (__fpsr)) + +int fegetenv(fenv_t* envp) { + __get_fpcr(envp->__control); + __get_fpsr(envp->__status); + return 0; +} + +int fesetenv(const fenv_t* envp) { + fpu_control_t fpcr; + + __get_fpcr(fpcr); + if (envp->__control != fpcr) { + __set_fpcr(envp->__control); + } + __set_fpsr(envp->__status); + return 0; +} + +int feclearexcept(int excepts) { + fpu_status_t fpsr; + + excepts &= FE_ALL_EXCEPT; + __get_fpsr(fpsr); + fpsr &= ~excepts; + __set_fpsr(fpsr); + return 0; +} + +int fegetexceptflag(fexcept_t* flagp, int excepts) { + fpu_status_t fpsr; + + excepts &= FE_ALL_EXCEPT; + __get_fpsr(fpsr); + *flagp = fpsr & excepts; + return 0; +} + +int fesetexceptflag(const fexcept_t* flagp, int excepts) { + fpu_status_t fpsr; + + excepts &= FE_ALL_EXCEPT; + __get_fpsr(fpsr); + fpsr &= ~excepts; + fpsr |= *flagp & excepts; + __set_fpsr(fpsr); + return 0; +} + +int feraiseexcept(int excepts) { + fexcept_t ex = excepts; + + fesetexceptflag(&ex, excepts); + return 0; +} + +int fetestexcept(int excepts) { + fpu_status_t fpsr; + + excepts &= FE_ALL_EXCEPT; + __get_fpsr(fpsr); + return (fpsr & excepts); +} + +int fegetround(void) { + fpu_control_t fpcr; + + __get_fpcr(fpcr); + return ((fpcr >> FPCR_RMODE_SHIFT) & FE_TOWARDZERO); +} + +int fesetround(int round) { + fpu_control_t fpcr, new_fpcr; + + round &= FE_TOWARDZERO; + __get_fpcr(fpcr); + new_fpcr = fpcr & ~(FE_TOWARDZERO << FPCR_RMODE_SHIFT); + new_fpcr |= (round << FPCR_RMODE_SHIFT); + if (new_fpcr != fpcr) { + __set_fpcr(new_fpcr); + } + return 0; +} + +int feholdexcept(fenv_t* envp) { + fenv_t env; + fpu_status_t fpsr; + fpu_control_t fpcr, new_fpcr; + + __get_fpsr(fpsr); + __get_fpcr(fpcr); + env.__status = fpsr; + env.__control = fpcr; + *envp = env; + + // Set exceptions to untrapped. + new_fpcr = fpcr & ~(FE_ALL_EXCEPT << FPCR_EXCEPT_SHIFT); + if (new_fpcr != fpcr) { + __set_fpcr(new_fpcr); + } + + // Clear all exceptions. + fpsr &= ~FE_ALL_EXCEPT; + __set_fpsr(fpsr); + return 0; +} + +int feupdateenv(const fenv_t* envp) { + fpu_status_t fpsr; + fpu_control_t fpcr; + + // Set FPU Control register. + __get_fpcr(fpcr); + if (envp->__control != fpcr) { + __set_fpcr(envp->__control); + } + + // Set FPU Status register to status | currently raised exceptions. + __get_fpsr(fpsr); + fpsr = envp->__status | (fpsr & FE_ALL_EXCEPT); + __set_fpsr(fpsr); + return 0; +} + +int feenableexcept(int mask) { + fpu_control_t old_fpcr, new_fpcr; + + __get_fpcr(old_fpcr); + new_fpcr = old_fpcr | ((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT); + if (new_fpcr != old_fpcr) { + __set_fpcr(new_fpcr); + } + return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT); +} + +int fedisableexcept(int mask) { + fpu_control_t old_fpcr, new_fpcr; + + __get_fpcr(old_fpcr); + new_fpcr = old_fpcr & ~((mask & FE_ALL_EXCEPT) << FPCR_EXCEPT_SHIFT); + if (new_fpcr != old_fpcr) { + __set_fpcr(new_fpcr); + } + return ((old_fpcr >> FPCR_EXCEPT_SHIFT) & FE_ALL_EXCEPT); +} + +int fegetexcept(void) { + fpu_control_t fpcr; + + __get_fpcr(fpcr); + return ((fpcr & FPCR_EXCEPT_MASK) >> FPCR_EXCEPT_SHIFT); +} diff --git a/libm/digittoint.c b/libm/digittoint.c new file mode 100644 index 0000000..1824788 --- /dev/null +++ b/libm/digittoint.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$ + */ + +#include <sys/cdefs.h> + +/* digittoint is in the FreeBSD C library, but implemented in terms of locale stuff. */ +__LIBC_HIDDEN__ int digittoint(char ch) { + int d = ch - '0'; + if ((unsigned) d < 10) { + return d; + } + d = ch - 'a'; + if ((unsigned) d < 6) { + return d + 10; + } + d = ch - 'A'; + if ((unsigned) d < 6) { + return d + 10; + } + return -1; +} diff --git a/libm/fake_long_double.c b/libm/fake_long_double.c new file mode 100644 index 0000000..317a115 --- /dev/null +++ b/libm/fake_long_double.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <float.h> +#include <math.h> + +#ifndef __LP64__ +/* + * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double). + * Android works around those cases by replacing the broken functions with our own trivial stubs + * that call the regular "double" function. + */ + +long double copysignl(long double a1, long double a2) { return copysign(a1, a2); } +long double fabsl(long double a1) { return fabs(a1); } +long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); } +long double fmodl(long double a1, long double a2) { return fmod(a1, a2); } +long double fminl(long double a1, long double a2) { return fmin(a1, a2); } +int ilogbl(long double a1) { return ilogb(a1); } +long long llrintl(long double a1) { return llrint(a1); } +long lrintl(long double a1) { return lrint(a1); } +long long llroundl(long double a1) { return llround(a1); } +long lroundl(long double a1) { return lround(a1); } +long double modfl(long double a1, long double* a2) { double i; double f = modf(a1, &i); *a2 = i; return f; } +float nexttowardf(float a1, long double a2) { return nextafterf(a1, (float) a2); } +long double roundl(long double a1) { return round(a1); } + +#endif // __LP64__ diff --git a/libm/fpclassify.c b/libm/fpclassify.c deleted file mode 100644 index baf116c..0000000 --- a/libm/fpclassify.c +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> - * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> - * 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/libc/gen/fpclassify.c,v 1.2 2005/02/06 03:23:31 das Exp $ - */ - -#include <sys/endian.h> - -#include <math.h> -#include <stdint.h> - -#include "src/fpmath.h" - -int -__fpclassifyf(float f) -{ - union IEEEf2bits u; - - u.f = f; - if (u.bits.exp == 0) { - if (u.bits.man == 0) - return (FP_ZERO); - return (FP_SUBNORMAL); - } - if (u.bits.exp == 255) { - if (u.bits.man == 0) - return (FP_INFINITE); - return (FP_NAN); - } - return (FP_NORMAL); -} - -int -__fpclassifyd(double d) -{ - union IEEEd2bits u; - - u.d = d; - if (u.bits.exp == 0) { - if ((u.bits.manl | u.bits.manh) == 0) - return (FP_ZERO); - return (FP_SUBNORMAL); - } - if (u.bits.exp == 2047) { - if ((u.bits.manl | u.bits.manh) == 0) - return (FP_INFINITE); - return (FP_NAN); - } - return (FP_NORMAL); -} - -int -__fpclassifyl(long double e) -{ - union IEEEl2bits u; - - u.e = e; - if (u.bits.exp == 0) { - if ((u.bits.manl | u.bits.manh) == 0) - return (FP_ZERO); - return (FP_SUBNORMAL); - } - mask_nbit_l(u); /* Mask normalization bit if applicable. */ - if (u.bits.exp == 32767) { - if ((u.bits.manl | u.bits.manh) == 0) - return (FP_INFINITE); - return (FP_NAN); - } - return (FP_NORMAL); -} - diff --git a/libm/src/fpmath.h b/libm/fpmath.h index 879bd7b..80420e5 100644 --- a/libm/src/fpmath.h +++ b/libm/fpmath.h @@ -24,49 +24,73 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/include/fpmath.h,v 1.3 2005/02/06 03:23:31 das Exp $ + * $FreeBSD$ */ +// ANDROID changed: +// - keep only little endian variants as they're the only one supported. +// - add long double structures here instead of _fpmath.h. +// - android uses 128 bits long doubles for LP64, so the structure and macros +// were reworked for the quad precision ieee representation. + +#ifndef _FPMATH_ +#define _FPMATH_ + #include <endian.h> -#include "_fpmath.h" union IEEEf2bits { - float f; - struct { -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int man :23; - unsigned int exp :8; - unsigned int sign :1; -#else /* _BIG_ENDIAN */ - unsigned int sign :1; - unsigned int exp :8; - unsigned int man :23; -#endif - } bits; + float f; + struct { + unsigned int man :23; + unsigned int exp :8; + unsigned int sign :1; + } bits; }; -#define DBL_MANH_SIZE 20 -#define DBL_MANL_SIZE 32 +#define DBL_MANH_SIZE 20 +#define DBL_MANL_SIZE 32 union IEEEd2bits { - double d; - struct { -/* #ifdef __ARMEB__ */ -#if (__BYTE_ORDER == __BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__)) - unsigned int manh :20; - unsigned int exp :11; - unsigned int sign :1; - unsigned int manl :32; -#elif __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int manl :32; - unsigned int manh :20; - unsigned int exp :11; - unsigned int sign :1; -#elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int sign :1; - unsigned int exp :11; - unsigned int manh :20; - unsigned int manl :32; -#endif - } bits; + double d; + struct { + unsigned int manl :32; + unsigned int manh :20; + unsigned int exp :11; + unsigned int sign :1; + } bits; +}; + +#ifdef __LP64__ + +union IEEEl2bits { + long double e; + struct { + unsigned long manl :64; + unsigned long manh :48; + unsigned int exp :15; + unsigned int sign :1; + } bits; + struct { + unsigned long manl :64; + unsigned long manh :48; + unsigned int expsign :16; + } xbits; }; + +#define LDBL_NBIT 0 +#define LDBL_IMPLICIT_NBIT +#define mask_nbit_l(u) ((void)0) + +#define LDBL_MANH_SIZE 48 +#define LDBL_MANL_SIZE 64 + +#define LDBL_TO_ARRAY32(u, a) do { \ + (a)[0] = (uint32_t)(u).bits.manl; \ + (a)[1] = (uint32_t)((u).bits.manl >> 32); \ + (a)[2] = (uint32_t)(u).bits.manh; \ + (a)[3] = (uint32_t)((u).bits.manh >> 32); \ +} while(0) + +#endif // __LP64__ + +#endif // _FPMATH_ diff --git a/libm/freebsd-compat.h b/libm/freebsd-compat.h new file mode 100644 index 0000000..1481cc2 --- /dev/null +++ b/libm/freebsd-compat.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BIONIC_LIBM_FREEBSD_COMPAT_H_included +#define _BIONIC_LIBM_FREEBSD_COMPAT_H_included + +#include <float.h> + +#define __weak_reference(sym,alias) \ + __asm__(".weak " #alias); \ + __asm__(".equ " #alias ", " #sym) + +#define __strong_reference(sym,aliassym) \ + extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) + +/* digittoint is in BSD's <ctype.h>. */ +int digittoint(char ch); + +#endif diff --git a/libm/i386/_fpmath.h b/libm/i386/_fpmath.h deleted file mode 100644 index 92719d9..0000000 --- a/libm/i386/_fpmath.h +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> - * 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/libc/i386/_fpmath.h,v 1.5 2005/03/07 04:55:22 das Exp $ - */ - -union IEEEl2bits { - long double e; - struct { - unsigned int manl :32; - unsigned int manh :32; - unsigned int exp :15; - unsigned int sign :1; - unsigned int junk :16; - } bits; -}; - -#define LDBL_NBIT 0x80000000 -#define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT) - -#define LDBL_MANH_SIZE 32 -#define LDBL_MANL_SIZE 32 - -#define LDBL_TO_ARRAY32(u, a) do { \ - (a)[0] = (uint32_t)(u).bits.manl; \ - (a)[1] = (uint32_t)(u).bits.manh; \ -} while(0) diff --git a/libm/i387/e_exp.S b/libm/i387/e_exp.S deleted file mode 100644 index 008a6e1..0000000 --- a/libm/i387/e_exp.S +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_exp.S,v 1.11 2005/10/30 12:21:02 bde Exp $") - -/* e^x = 2^(x * log2(e)) */ -ENTRY(exp) - /* - * If x is +-Inf, then the subtraction would give Inf-Inf = NaN. - * Avoid this. Also avoid it if x is NaN for convenience. - */ - movl 8(%esp),%eax - andl $0x7fffffff,%eax - cmpl $0x7ff00000,%eax - jae x_Inf_or_NaN - - fldl 4(%esp) - - /* - * Extended precision is needed to reduce the maximum error from - * hundreds of ulps to less than 1 ulp. Switch to it if necessary. - * We may as well set the rounding mode to to-nearest and mask traps - * if we switch. - */ - fstcw 4(%esp) - movl 4(%esp),%eax - andl $0x0300,%eax - cmpl $0x0300,%eax /* RC == 0 && PC == 3? */ - je 1f /* jump if mode is good */ - movl $0x137f,8(%esp) - fldcw 8(%esp) -1: - fldl2e - fmulp /* x * log2(e) */ - fst %st(1) - frndint /* int(x * log2(e)) */ - fst %st(2) - fsubrp /* fract(x * log2(e)) */ - f2xm1 /* 2^(fract(x * log2(e))) - 1 */ - fld1 - faddp /* 2^(fract(x * log2(e))) */ - fscale /* e^x */ - fstp %st(1) - je 1f - fldcw 4(%esp) -1: - ret - -x_Inf_or_NaN: - /* - * Return 0 if x is -Inf. Otherwise just return x; when x is Inf - * this gives Inf, and when x is a NaN this gives the same result - * as (x + x) (x quieted). - */ - cmpl $0xfff00000,8(%esp) - jne x_not_minus_Inf - cmpl $0,4(%esp) - jne x_not_minus_Inf - fldz - ret - -x_not_minus_Inf: - fldl 4(%esp) - ret diff --git a/libm/i387/e_fmod.S b/libm/i387/e_fmod.S deleted file mode 100644 index 233476f..0000000 --- a/libm/i387/e_fmod.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_fmod.S,v 1.8 2005/02/04 14:08:32 das Exp $") - -ENTRY(fmod) - fldl 12(%esp) - fldl 4(%esp) -1: fprem - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/libm/i387/e_log.S b/libm/i387/e_log.S deleted file mode 100644 index caaac87..0000000 --- a/libm/i387/e_log.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_log.S,v 1.7 2005/02/04 14:08:32 das Exp $") - -ENTRY(log) - fldln2 - fldl 4(%esp) - fyl2x - ret diff --git a/libm/i387/e_log10.S b/libm/i387/e_log10.S deleted file mode 100644 index 7695ef6..0000000 --- a/libm/i387/e_log10.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_log10.S,v 1.7 2005/02/04 14:08:32 das Exp $") - -ENTRY(log10) - fldlg2 - fldl 4(%esp) - fyl2x - ret diff --git a/libm/i387/e_log10f.S b/libm/i387/e_log10f.S deleted file mode 100644 index 2dd6708..0000000 --- a/libm/i387/e_log10f.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/e_log10f.S,v 1.2 2005/02/04 14:08:32 das Exp $"); -/* RCSID("$NetBSD: e_log10f.S,v 1.1 1996/07/03 16:50:22 jtc Exp $") */ - -ENTRY(log10f) - fldlg2 - flds 4(%esp) - fyl2x - ret diff --git a/libm/i387/e_logf.S b/libm/i387/e_logf.S deleted file mode 100644 index 9f3bd00..0000000 --- a/libm/i387/e_logf.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/e_logf.S,v 1.2 2005/02/04 14:08:32 das Exp $"); -/* RCSID("$NetBSD: e_logf.S,v 1.2 1996/07/06 00:15:45 jtc Exp $") */ - -ENTRY(logf) - fldln2 - flds 4(%esp) - fyl2x - ret diff --git a/libm/i387/e_remainder.S b/libm/i387/e_remainder.S deleted file mode 100644 index 5f0d679..0000000 --- a/libm/i387/e_remainder.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_remainder.S,v 1.8 2005/02/04 14:08:32 das Exp $") - -ENTRY(remainder) - fldl 12(%esp) - fldl 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/libm/i387/e_remainderf.S b/libm/i387/e_remainderf.S deleted file mode 100644 index 6d1ca79..0000000 --- a/libm/i387/e_remainderf.S +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/e_remainderf.S,v 1.2 2005/02/04 14:08:32 das Exp $"); -/* RCSID("$NetBSD: e_remainderf.S,v 1.2 1995/05/08 23:49:47 jtc Exp $") */ - -ENTRY(remainderf) - flds 8(%esp) - flds 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret diff --git a/libm/i387/e_scalb.S b/libm/i387/e_scalb.S deleted file mode 100644 index dd8657f..0000000 --- a/libm/i387/e_scalb.S +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_scalb.S,v 1.8 2005/02/04 14:08:32 das Exp $") - -ENTRY(scalb) - fldl 12(%esp) - fldl 4(%esp) - fscale - fstp %st(1) - ret diff --git a/libm/i387/e_scalbf.S b/libm/i387/e_scalbf.S deleted file mode 100644 index 9de0d70..0000000 --- a/libm/i387/e_scalbf.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/e_scalbf.S,v 1.2 2005/02/04 14:08:32 das Exp $"); -/* RCSID("$NetBSD: e_scalbf.S,v 1.1 1996/07/03 16:50:24 jtc Exp $") */ - -ENTRY(scalbf) - flds 8(%esp) - flds 4(%esp) - fscale - ret diff --git a/libm/i387/e_sqrt.S b/libm/i387/e_sqrt.S deleted file mode 100644 index b7e9621..0000000 --- a/libm/i387/e_sqrt.S +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/e_sqrt.S,v 1.7 2005/02/04 14:08:32 das Exp $") - -ENTRY(sqrt) - fldl 4(%esp) - fsqrt - ret diff --git a/libm/i387/e_sqrtf.S b/libm/i387/e_sqrtf.S deleted file mode 100644 index 86c56a9..0000000 --- a/libm/i387/e_sqrtf.S +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/e_sqrtf.S,v 1.2 2005/02/04 14:08:32 das Exp $"); -/* RCSID("$NetBSD: e_sqrtf.S,v 1.2 1995/05/08 23:50:14 jtc Exp $") */ - -ENTRY(sqrtf) - flds 4(%esp) - fsqrt - ret diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c index 89ddc55..f64f8dc 100644 --- a/libm/i387/fenv.c +++ b/libm/i387/fenv.c @@ -31,29 +31,31 @@ #include "npx.h" #include "fenv.h" +#define ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO) + /* * As compared to the x87 control word, the SSE unit's control word * has the rounding control bits offset by 3 and the exception mask * bits offset by 7. */ -#define _SSE_ROUND_SHIFT 3 -#define _SSE_EMASK_SHIFT 7 +#define _SSE_ROUND_SHIFT 3 +#define _SSE_EMASK_SHIFT 7 const fenv_t __fe_dfl_env = { - __INITIAL_NPXCW__, /*__control*/ - 0x0000, /*__mxcsr_hi*/ - 0x0000, /*__status*/ - 0x1f80, /*__mxcsr_lo*/ - 0xffffffff, /*__tag*/ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/ + __INITIAL_NPXCW__, /*__control*/ + 0x0000, /*__mxcsr_hi*/ + 0x0000, /*__status*/ + 0x1f80, /*__mxcsr_lo*/ + 0xffffffff, /*__tag*/ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/ }; #define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw)) #define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env)) -#define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \ - : "st", "st(1)", "st(2)", "st(3)", "st(4)", \ - "st(5)", "st(6)", "st(7)") +#define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \ + : "st", "st(1)", "st(2)", "st(3)", "st(4)", \ + "st(5)", "st(6)", "st(7)") #define __fnclex() __asm __volatile("fnclex") #define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) #define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) @@ -68,22 +70,22 @@ enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK }; #define __HAS_SSE() 1 #else #define __HAS_SSE() (__has_sse == __SSE_YES || \ - (__has_sse == __SSE_UNK && __test_sse())) + (__has_sse == __SSE_UNK && __test_sse())) #endif enum __sse_support __has_sse = #ifdef __SSE__ - __SSE_YES; + __SSE_YES; #else - __SSE_UNK; + __SSE_UNK; #endif #ifndef __SSE__ -#define getfl(x) __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x))) -#define setfl(x) __asm __volatile("pushl %0\n\tpopfl" : : "g" (x)) -#define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t" \ - "cpuid\n\tpopl %%ebx" \ - : "=d" (*(x)) : : "eax", "ecx") +#define getfl(x) __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x))) +#define setfl(x) __asm __volatile("pushl %0\n\tpopfl" : : "g" (x)) +#define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t" \ + "cpuid\n\tpopl %%ebx" \ + : "=d" (*(x)) : : "eax", "ecx") /* * Test for SSE support on this processor. We need to do this because @@ -94,298 +96,298 @@ enum __sse_support __has_sse = int __test_sse(void) { - int flag, nflag; - int dx_features; - - /* Am I a 486? */ - getfl(&flag); - nflag = flag ^ 0x200000; - setfl(nflag); - getfl(&nflag); - if (flag != nflag) { - /* Not a 486, so CPUID should work. */ - cpuid_dx(&dx_features); - if (dx_features & 0x2000000) { - __has_sse = __SSE_YES; - return (1); - } - } - __has_sse = __SSE_NO; - return (0); + int flag, nflag; + int dx_features; + + /* Am I a 486? */ + getfl(&flag); + nflag = flag ^ 0x200000; + setfl(nflag); + getfl(&nflag); + if (flag != nflag) { + /* Not a 486, so CPUID should work. */ + cpuid_dx(&dx_features); + if (dx_features & 0x2000000) { + __has_sse = __SSE_YES; + return (1); + } + } + __has_sse = __SSE_NO; + return (0); } #endif /* __SSE__ */ int fesetexceptflag(const fexcept_t *flagp, int excepts) { - fenv_t env; - __uint32_t mxcsr; - - excepts &= FE_ALL_EXCEPT; - if (excepts) { /* Do nothing if excepts is 0 */ - __fnstenv(&env); - env.__status &= ~excepts; - env.__status |= *flagp & excepts; - __fnclex(); - __fldenv(env); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - mxcsr &= ~excepts; - mxcsr |= *flagp & excepts; - __ldmxcsr(mxcsr); - } - } - - return (0); + fenv_t env; + __uint32_t mxcsr; + + excepts &= FE_ALL_EXCEPT; + if (excepts) { /* Do nothing if excepts is 0 */ + __fnstenv(&env); + env.__status &= ~excepts; + env.__status |= *flagp & excepts; + __fnclex(); + __fldenv(env); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + mxcsr &= ~excepts; + mxcsr |= *flagp & excepts; + __ldmxcsr(mxcsr); + } + } + + return (0); } int feraiseexcept(int excepts) { - fexcept_t ex = excepts; + fexcept_t ex = excepts; - fesetexceptflag(&ex, excepts); - __fwait(); - return (0); + fesetexceptflag(&ex, excepts); + __fwait(); + return (0); } int fegetenv(fenv_t *envp) { - __uint32_t mxcsr; - - __fnstenv(envp); - /* - * fnstenv masks all exceptions, so we need to restore - * the old control word to avoid this side effect. - */ - __fldcw(envp->__control); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - envp->__mxcsr_hi = mxcsr >> 16; - envp->__mxcsr_lo = mxcsr & 0xffff; - } - return (0); + __uint32_t mxcsr; + + __fnstenv(envp); + /* + * fnstenv masks all exceptions, so we need to restore + * the old control word to avoid this side effect. + */ + __fldcw(envp->__control); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + envp->__mxcsr_hi = mxcsr >> 16; + envp->__mxcsr_lo = mxcsr & 0xffff; + } + return (0); } int feholdexcept(fenv_t *envp) { - __uint32_t mxcsr; - fenv_t env; - - __fnstenv(&env); - *envp = env; - env.__status &= ~FE_ALL_EXCEPT; - env.__control |= FE_ALL_EXCEPT; - __fnclex(); - __fldenv(env); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - envp->__mxcsr_hi = mxcsr >> 16; - envp->__mxcsr_lo = mxcsr & 0xffff; - mxcsr &= ~FE_ALL_EXCEPT; - mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT; - __ldmxcsr(mxcsr); - } - return (0); + __uint32_t mxcsr; + fenv_t env; + + __fnstenv(&env); + *envp = env; + env.__status &= ~FE_ALL_EXCEPT; + env.__control |= FE_ALL_EXCEPT; + __fnclex(); + __fldenv(env); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + envp->__mxcsr_hi = mxcsr >> 16; + envp->__mxcsr_lo = mxcsr & 0xffff; + mxcsr &= ~FE_ALL_EXCEPT; + mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT; + __ldmxcsr(mxcsr); + } + return (0); } int feupdateenv(const fenv_t *envp) { - __uint32_t mxcsr; - __uint16_t status; - - __fnstsw(&status); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - } else { - mxcsr = 0; - } - fesetenv(envp); - feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT); - return (0); + __uint32_t mxcsr; + __uint16_t status; + + __fnstsw(&status); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + } else { + mxcsr = 0; + } + fesetenv(envp); + feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT); + return (0); } int feenableexcept(int mask) { - __uint32_t mxcsr; - __uint16_t control, omask; - - mask &= FE_ALL_EXCEPT; - __fnstcw(&control); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - } else { - mxcsr = 0; - } - omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; - if (mask) { - control &= ~mask; - __fldcw(control); - if (__HAS_SSE()) { - mxcsr &= ~(mask << _SSE_EMASK_SHIFT); - __ldmxcsr(mxcsr); - } - } - return (omask); + __uint32_t mxcsr; + __uint16_t control, omask; + + mask &= FE_ALL_EXCEPT; + __fnstcw(&control); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + } else { + mxcsr = 0; + } + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + if (mask) { + control &= ~mask; + __fldcw(control); + if (__HAS_SSE()) { + mxcsr &= ~(mask << _SSE_EMASK_SHIFT); + __ldmxcsr(mxcsr); + } + } + return (omask); } int fedisableexcept(int mask) { - __uint32_t mxcsr; - __uint16_t control, omask; - - mask &= FE_ALL_EXCEPT; - __fnstcw(&control); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - } else { - mxcsr = 0; - } - omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; - if (mask) { - control |= mask; - __fldcw(control); - if (__HAS_SSE()) { - mxcsr |= mask << _SSE_EMASK_SHIFT; - __ldmxcsr(mxcsr); - } - } - return (omask); + __uint32_t mxcsr; + __uint16_t control, omask; + + mask &= FE_ALL_EXCEPT; + __fnstcw(&control); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + } else { + mxcsr = 0; + } + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + if (mask) { + control |= mask; + __fldcw(control); + if (__HAS_SSE()) { + mxcsr |= mask << _SSE_EMASK_SHIFT; + __ldmxcsr(mxcsr); + } + } + return (omask); } int feclearexcept(int excepts) { - fenv_t env; - __uint32_t mxcsr; - - excepts &= FE_ALL_EXCEPT; - if (excepts) { /* Do nothing if excepts is 0 */ - __fnstenv(&env); - env.__status &= ~excepts; - __fnclex(); - __fldenv(env); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - mxcsr &= ~excepts; - __ldmxcsr(mxcsr); - } - } - return (0); + fenv_t env; + __uint32_t mxcsr; + + excepts &= FE_ALL_EXCEPT; + if (excepts) { /* Do nothing if excepts is 0 */ + __fnstenv(&env); + env.__status &= ~excepts; + __fnclex(); + __fldenv(env); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + mxcsr &= ~excepts; + __ldmxcsr(mxcsr); + } + } + return (0); } int fegetexceptflag(fexcept_t *flagp, int excepts) { - __uint32_t mxcsr; - __uint16_t status; - - excepts &= FE_ALL_EXCEPT; - __fnstsw(&status); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - } else { - mxcsr = 0; - } - *flagp = (status | mxcsr) & excepts; - return (0); + __uint32_t mxcsr; + __uint16_t status; + + excepts &= FE_ALL_EXCEPT; + __fnstsw(&status); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + } else { + mxcsr = 0; + } + *flagp = (status | mxcsr) & excepts; + return (0); } int fetestexcept(int excepts) { - __uint32_t mxcsr; - __uint16_t status; - - excepts &= FE_ALL_EXCEPT; - if (excepts) { /* Do nothing if excepts is 0 */ - __fnstsw(&status); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - } else { - mxcsr = 0; - } - return ((status | mxcsr) & excepts); - } - return (0); + __uint32_t mxcsr; + __uint16_t status; + + excepts &= FE_ALL_EXCEPT; + if (excepts) { /* Do nothing if excepts is 0 */ + __fnstsw(&status); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + } else { + mxcsr = 0; + } + return ((status | mxcsr) & excepts); + } + return (0); } int fegetround(void) { - __uint16_t control; - - /* - * We assume that the x87 and the SSE unit agree on the - * rounding mode. Reading the control word on the x87 turns - * out to be about 5 times faster than reading it on the SSE - * unit on an Opteron 244. - */ - __fnstcw(&control); - return (control & _ROUND_MASK); + __uint16_t control; + + /* + * We assume that the x87 and the SSE unit agree on the + * rounding mode. Reading the control word on the x87 turns + * out to be about 5 times faster than reading it on the SSE + * unit on an Opteron 244. + */ + __fnstcw(&control); + return (control & ROUND_MASK); } int fesetround(int round) { - __uint32_t mxcsr; - __uint16_t control; - - if (round & ~_ROUND_MASK) { - return (-1); - } else { - __fnstcw(&control); - control &= ~_ROUND_MASK; - control |= round; - __fldcw(control); - if (__HAS_SSE()) { - __stmxcsr(&mxcsr); - mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); - mxcsr |= round << _SSE_ROUND_SHIFT; - __ldmxcsr(mxcsr); - } - return (0); - } + __uint32_t mxcsr; + __uint16_t control; + + if (round & ~ROUND_MASK) { + return (-1); + } else { + __fnstcw(&control); + control &= ~ROUND_MASK; + control |= round; + __fldcw(control); + if (__HAS_SSE()) { + __stmxcsr(&mxcsr); + mxcsr &= ~(ROUND_MASK << _SSE_ROUND_SHIFT); + mxcsr |= round << _SSE_ROUND_SHIFT; + __ldmxcsr(mxcsr); + } + return (0); + } } int fesetenv(const fenv_t *envp) { - fenv_t env = *envp; - __uint32_t mxcsr; - - mxcsr = (env.__mxcsr_hi << 16) | (env.__mxcsr_lo); - env.__mxcsr_hi = 0xffff; - env.__mxcsr_lo = 0xffff; - /* - * XXX Using fldenvx() instead of fldenv() tells the compiler that this - * instruction clobbers the i387 register stack. This happens because - * we restore the tag word from the saved environment. Normally, this - * would happen anyway and we wouldn't care, because the ABI allows - * function calls to clobber the i387 regs. However, fesetenv() is - * inlined, so we need to be more careful. - */ - __fldenvx(env); - if (__HAS_SSE()) { - __ldmxcsr(mxcsr); - } - return (0); + fenv_t env = *envp; + __uint32_t mxcsr; + + mxcsr = (env.__mxcsr_hi << 16) | (env.__mxcsr_lo); + env.__mxcsr_hi = 0xffff; + env.__mxcsr_lo = 0xffff; + /* + * XXX Using fldenvx() instead of fldenv() tells the compiler that this + * instruction clobbers the i387 register stack. This happens because + * we restore the tag word from the saved environment. Normally, this + * would happen anyway and we wouldn't care, because the ABI allows + * function calls to clobber the i387 regs. However, fesetenv() is + * inlined, so we need to be more careful. + */ + __fldenvx(env); + if (__HAS_SSE()) { + __ldmxcsr(mxcsr); + } + return (0); } int fegetexcept(void) { - __uint16_t control; - - /* - * We assume that the masks for the x87 and the SSE unit are - * the same. - */ - __fnstcw(&control); - return (~control & FE_ALL_EXCEPT); + __uint16_t control; + + /* + * We assume that the masks for the x87 and the SSE unit are + * the same. + */ + __fnstcw(&control); + return (~control & FE_ALL_EXCEPT); } diff --git a/libm/i387/s_ceil.S b/libm/i387/s_ceil.S deleted file mode 100644 index 8e73b38..0000000 --- a/libm/i387/s_ceil.S +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_ceil.S,v 1.7 1999/08/28 00:06:11 peter Exp $") - -ENTRY(ceil) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0800,%dx /* round towards +oo */ - andw $0xfbff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldl 8(%ebp); /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_ceilf.S b/libm/i387/s_ceilf.S deleted file mode 100644 index 152ca7b..0000000 --- a/libm/i387/s_ceilf.S +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_ceilf.S,v 1.2 2005/05/06 15:44:20 deischen Exp $"); -/* RCSID("$NetBSD: s_ceilf.S,v 1.3 1995/05/08 23:52:44 jtc Exp $") */ - -ENTRY(ceilf) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0800,%dx /* round towards +oo */ - andw $0xfbff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - flds 8(%ebp); /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_ceill.S b/libm/i387/s_ceill.S deleted file mode 100644 index b6c3c41..0000000 --- a/libm/i387/s_ceill.S +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_ceill.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(ceill) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0800,%dx /* round towards +oo */ - andw $0xfbff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldt 8(%ebp) /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_copysign.S b/libm/i387/s_copysign.S deleted file mode 100644 index 6ecc770..0000000 --- a/libm/i387/s_copysign.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_copysign.S,v 1.6 1999/08/28 00:06:11 peter Exp $") - -ENTRY(copysign) - movl 16(%esp),%edx - andl $0x80000000,%edx - movl 8(%esp),%eax - andl $0x7fffffff,%eax - orl %edx,%eax - movl %eax,8(%esp) - fldl 4(%esp) - ret diff --git a/libm/i387/s_copysignf.S b/libm/i387/s_copysignf.S deleted file mode 100644 index c3fc898..0000000 --- a/libm/i387/s_copysignf.S +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_copysignf.S,v 1.1 2005/01/13 18:58:25 das Exp $"); -/* RCSID("$NetBSD: s_copysignf.S,v 1.3 1995/05/08 23:53:25 jtc Exp $") */ - -ENTRY(copysignf) - movl 8(%esp),%edx - andl $0x80000000,%edx - movl 4(%esp),%eax - andl $0x7fffffff,%eax - orl %edx,%eax - movl %eax,4(%esp) - flds 4(%esp) - ret diff --git a/libm/i387/s_copysignl.S b/libm/i387/s_copysignl.S deleted file mode 100644 index 4c3a374..0000000 --- a/libm/i387/s_copysignl.S +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_copysignl.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(copysignl) - movl 24(%esp),%edx - andl $0x8000,%edx - movl 12(%esp),%eax - andl $0x7fff,%eax - orl %edx,%eax - movl %eax,12(%esp) - fldt 4(%esp) - ret diff --git a/libm/i387/s_cos.S b/libm/i387/s_cos.S deleted file mode 100644 index c38cb7b..0000000 --- a/libm/i387/s_cos.S +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_cos.S,v 1.6 1999/08/28 00:06:12 peter Exp $") - -ENTRY(cos) - fldl 4(%esp) - fcos - fnstsw %ax - andw $0x400,%ax - jnz 1f - ret -1: fldpi - fadd %st(0) - fxch %st(1) -2: fprem1 - fnstsw %ax - andw $0x400,%ax - jnz 2b - fstp %st(1) - fcos - ret diff --git a/libm/i387/s_finite.S b/libm/i387/s_finite.S deleted file mode 100644 index 4835b0e..0000000 --- a/libm/i387/s_finite.S +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_finite.S,v 1.7 1999/08/28 00:06:12 peter Exp $") - -ENTRY(finite) - movl 8(%esp),%eax - andl $0x7ff00000, %eax - cmpl $0x7ff00000, %eax - setneb %al - andl $0x000000ff, %eax - ret diff --git a/libm/i387/s_floor.S b/libm/i387/s_floor.S deleted file mode 100644 index 722f83d..0000000 --- a/libm/i387/s_floor.S +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_floor.S,v 1.7 1999/08/28 00:06:12 peter Exp $") - -ENTRY(floor) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0400,%dx /* round towards -oo */ - andw $0xf7ff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldl 8(%ebp); /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_floorf.S b/libm/i387/s_floorf.S deleted file mode 100644 index 5d39acd..0000000 --- a/libm/i387/s_floorf.S +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_floorf.S,v 1.2 2005/05/06 15:44:20 deischen Exp $"); -/* RCSID("$NetBSD: s_floorf.S,v 1.3 1995/05/09 00:04:32 jtc Exp $") */ - -ENTRY(floorf) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0400,%dx /* round towards -oo */ - andw $0xf7ff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - flds 8(%ebp); /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_floorl.S b/libm/i387/s_floorl.S deleted file mode 100644 index 3cde335..0000000 --- a/libm/i387/s_floorl.S +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_floorl.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(floorl) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0400,%dx /* round towards -oo */ - andw $0xf7ff,%dx - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldt 8(%ebp) /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_logb.S b/libm/i387/s_logb.S deleted file mode 100644 index d3f8d9d..0000000 --- a/libm/i387/s_logb.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_logb.S,v 1.7 2000/06/06 12:12:36 bde Exp $") - -ENTRY(logb) - fldl 4(%esp) - fxtract - fstp %st - ret diff --git a/libm/i387/s_logbf.S b/libm/i387/s_logbf.S deleted file mode 100644 index 26bc484..0000000 --- a/libm/i387/s_logbf.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_logbf.S,v 1.1 2005/01/13 18:58:25 das Exp $"); -/* RCSID("$NetBSD: s_logbf.S,v 1.3 1995/05/09 00:15:12 jtc Exp $") */ - -ENTRY(logbf) - flds 4(%esp) - fxtract - fstp %st - ret diff --git a/libm/i387/s_remquo.S b/libm/i387/s_remquo.S deleted file mode 100644 index f752839..0000000 --- a/libm/i387/s_remquo.S +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> - * 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. - */ - -/* - * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_remquo.S,v 1.1 2005/03/25 04:40:44 das Exp $"); - -ENTRY(remquo) - fldl 12(%esp) - fldl 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) -/* Extract the three low-order bits of the quotient from C0,C3,C1. */ - shrl $6,%eax - movl %eax,%ecx - andl $0x108,%eax - rorl $7,%eax - orl %eax,%ecx - roll $4,%eax - orl %ecx,%eax - andl $7,%eax -/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 16(%esp),%ecx - xorl 8(%esp),%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl 20(%esp),%ecx - movl %eax,(%ecx) - ret diff --git a/libm/i387/s_remquof.S b/libm/i387/s_remquof.S deleted file mode 100644 index 40d24b8..0000000 --- a/libm/i387/s_remquof.S +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> - * 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. - */ - -/* - * Based on public-domain remainder routine by J.T. Conklin <jtc@NetBSD.org>. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_remquof.S,v 1.1 2005/03/25 04:40:44 das Exp $"); - -ENTRY(remquof) - flds 8(%esp) - flds 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) -/* Extract the three low-order bits of the quotient from C0,C3,C1. */ - shrl $6,%eax - movl %eax,%ecx - andl $0x108,%eax - rorl $7,%eax - orl %eax,%ecx - roll $4,%eax - orl %ecx,%eax - andl $7,%eax -/* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 8(%esp),%ecx - xorl 4(%esp),%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl 12(%esp),%ecx - movl %eax,(%ecx) - ret diff --git a/libm/i387/s_rint.S b/libm/i387/s_rint.S deleted file mode 100644 index ccda314..0000000 --- a/libm/i387/s_rint.S +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_rint.S,v 1.6 1999/08/28 00:06:13 peter Exp $") - -ENTRY(rint) - fldl 4(%esp) - frndint - ret diff --git a/libm/i387/s_rintf.S b/libm/i387/s_rintf.S deleted file mode 100644 index ad45267..0000000 --- a/libm/i387/s_rintf.S +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_rintf.S,v 1.1 2005/01/13 18:58:25 das Exp $"); -/* RCSID("$NetBSD: s_rintf.S,v 1.3 1995/05/09 00:17:22 jtc Exp $") */ - -ENTRY(rintf) - flds 4(%esp) - frndint - ret diff --git a/libm/i387/s_scalbn.S b/libm/i387/s_scalbn.S deleted file mode 100644 index 4600603..0000000 --- a/libm/i387/s_scalbn.S +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_scalbn.S,v 1.7 1999/08/28 00:06:13 peter Exp $") - -ENTRY(scalbn) - fildl 12(%esp) - fldl 4(%esp) - fscale - fstp %st(1) - ret diff --git a/libm/i387/s_scalbnf.S b/libm/i387/s_scalbnf.S deleted file mode 100644 index 3e1ac41..0000000 --- a/libm/i387/s_scalbnf.S +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_scalbnf.S,v 1.2 2005/03/07 04:52:43 das Exp $"); -/* RCSID("$NetBSD: s_scalbnf.S,v 1.4 1999/01/02 05:15:40 kristerw Exp $") */ - -ENTRY(scalbnf) - fildl 8(%esp) - flds 4(%esp) - fscale - fstp %st(1) /* bug fix for fp stack overflow */ - ret - -.globl CNAME(ldexpf) -.set CNAME(ldexpf),CNAME(scalbnf) diff --git a/libm/i387/s_scalbnl.S b/libm/i387/s_scalbnl.S deleted file mode 100644 index 512ab61..0000000 --- a/libm/i387/s_scalbnl.S +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_scalbnl.S,v 1.1 2005/03/07 04:52:57 das Exp $"); -/* RCSID("$NetBSD: s_scalbnf.S,v 1.4 1999/01/02 05:15:40 kristerw Exp $") */ - -ENTRY(scalbnl) - fildl 16(%esp) - fldt 4(%esp) - fscale - fstp %st(1) - ret - -.globl CNAME(ldexpl) -.set CNAME(ldexpl),CNAME(scalbnl) diff --git a/libm/i387/s_significand.S b/libm/i387/s_significand.S deleted file mode 100644 index eddbc82..0000000 --- a/libm/i387/s_significand.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1993,94 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_significand.S,v 1.7 2000/06/06 12:12:36 bde Exp $") - -ENTRY(significand) - fldl 4(%esp) - fxtract - fstp %st(1) - ret diff --git a/libm/i387/s_significandf.S b/libm/i387/s_significandf.S deleted file mode 100644 index 6096ef0..0000000 --- a/libm/i387/s_significandf.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -__FBSDID("$FreeBSD: src/lib/msun/i387/s_significandf.S,v 1.1 2005/01/13 18:58:25 das Exp $"); -/* RCSID("$NetBSD: s_significandf.S,v 1.3 1995/05/09 00:24:07 jtc Exp $") */ - -ENTRY(significandf) - flds 4(%esp) - fxtract - fstp %st(1) - ret diff --git a/libm/i387/s_sin.S b/libm/i387/s_sin.S deleted file mode 100644 index c3d65fd..0000000 --- a/libm/i387/s_sin.S +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_sin.S,v 1.6 1999/08/28 00:06:14 peter Exp $") - -ENTRY(sin) - fldl 4(%esp) - fsin - fnstsw %ax - andw $0x400,%ax - jnz 1f - ret -1: fldpi - fadd %st(0) - fxch %st(1) -2: fprem1 - fnstsw %ax - andw $0x400,%ax - jnz 2b - fstp %st(1) - fsin - ret diff --git a/libm/i387/s_tan.S b/libm/i387/s_tan.S deleted file mode 100644 index 925e11a..0000000 --- a/libm/i387/s_tan.S +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 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. - */ - -/* - * Written by: - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - */ - -#include <machine/asm.h> - -RCSID("$FreeBSD: src/lib/msun/i387/s_tan.S,v 1.6 1999/08/28 00:06:14 peter Exp $") - -ENTRY(tan) - fldl 4(%esp) - fptan - fnstsw %ax - andw $0x400,%ax - jnz 1f - fstp %st(0) - ret -1: fldpi - fadd %st(0) - fxch %st(1) -2: fprem1 - fstsw %ax - andw $0x400,%ax - jnz 2b - fstp %st(1) - fptan - fstp %st(0) - ret diff --git a/libm/i387/s_trunc.S b/libm/i387/s_trunc.S deleted file mode 100644 index 1d78e1c..0000000 --- a/libm/i387/s_trunc.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_trunc.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(trunc) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0c00,%dx /* round towards -oo */ - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldl 8(%ebp) /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_truncf.S b/libm/i387/s_truncf.S deleted file mode 100644 index 8afaf3e..0000000 --- a/libm/i387/s_truncf.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_truncf.S,v 1.2 2005/05/06 15:44:20 deischen Exp $") - -ENTRY(truncf) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0c00,%dx /* round towards -oo */ - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - flds 8(%ebp) /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/i387/s_truncl.S b/libm/i387/s_truncl.S deleted file mode 100644 index cd5df1c..0000000 --- a/libm/i387/s_truncl.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Based on code written by J.T. Conklin <jtc@NetBSD.org>. - * Public domain. - */ - -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_truncl.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(truncl) - pushl %ebp - movl %esp,%ebp - subl $8,%esp - - fstcw -4(%ebp) /* store fpu control word */ - movw -4(%ebp),%dx - orw $0x0c00,%dx /* round towards -oo */ - movw %dx,-8(%ebp) - fldcw -8(%ebp) /* load modfied control word */ - - fldt 8(%ebp) /* round */ - frndint - - fldcw -4(%ebp) /* restore original control word */ - - leave - ret diff --git a/libm/include/amd64/machine/fenv.h b/libm/include/amd64/machine/fenv.h new file mode 100644 index 0000000..c2b25ed --- /dev/null +++ b/libm/include/amd64/machine/fenv.h @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> + * 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. + */ + +#ifndef _AMD64_FENV_H_ +#define _AMD64_FENV_H_ + +#include <sys/types.h> + +__BEGIN_DECLS + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + struct { + __uint32_t __control; /* Control word register */ + __uint32_t __status; /* Status word register */ + __uint32_t __tag; /* Tag word register */ + __uint32_t __others[4]; /* EIP, Pointer Selector, etc */ + } __x87; + __uint32_t __mxcsr; /* Control, status register */ +} fenv_t; + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef __uint32_t fexcept_t; + +__END_DECLS + +#endif /* !_AMD64_FENV_H_ */ diff --git a/libm/include/arm/fenv.h b/libm/include/arm/fenv.h deleted file mode 100644 index a96f99e..0000000 --- a/libm/include/arm/fenv.h +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> - * 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.5 2005/03/16 19:03:45 das Exp $ - */ - -/* - * Rewritten for Android. - * - * The ARM FPSCR is described here: - * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html - */ - -#ifndef _FENV_H_ -#define _FENV_H_ - -#include <sys/types.h> - -__BEGIN_DECLS - -typedef __uint32_t fenv_t; -typedef __uint32_t fexcept_t; - -/* Exception flags. */ -#define FE_INVALID 0x01 -#define FE_DIVBYZERO 0x02 -#define FE_OVERFLOW 0x04 -#define FE_UNDERFLOW 0x08 -#define FE_INEXACT 0x10 -#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) -#define _FPSCR_ENABLE_SHIFT 8 -#define _FPSCR_ENABLE_MASK (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT) - -/* Rounding modes. */ -#define FE_TONEAREST 0x0 -#define FE_UPWARD 0x1 -#define FE_DOWNWARD 0x2 -#define FE_TOWARDZERO 0x3 -#define _FPSCR_RMODE_SHIFT 22 - -/* Default floating-point environment. */ -extern const fenv_t __fe_dfl_env; -#define FE_DFL_ENV (&__fe_dfl_env) - -static __inline int fegetenv(fenv_t* __envp) { - fenv_t _fpscr; - __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr)); - *__envp = _fpscr; - return 0; -} - -static __inline int fesetenv(const fenv_t* __envp) { - fenv_t _fpscr = *__envp; - __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr)); - return 0; -} - -static __inline int feclearexcept(int __excepts) { - fexcept_t __fpscr; - fegetenv(&__fpscr); - __fpscr &= ~__excepts; - fesetenv(&__fpscr); - return 0; -} - -static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) { - fexcept_t __fpscr; - fegetenv(&__fpscr); - *__flagp = __fpscr & __excepts; - return 0; -} - -static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) { - fexcept_t __fpscr; - fegetenv(&__fpscr); - __fpscr &= ~__excepts; - __fpscr |= *__flagp & __excepts; - fesetenv(&__fpscr); - return 0; -} - -static __inline int feraiseexcept(int __excepts) { - fexcept_t __ex = __excepts; - fesetexceptflag(&__ex, __excepts); - return 0; -} - -static __inline int fetestexcept(int __excepts) { - fexcept_t __fpscr; - fegetenv(&__fpscr); - return (__fpscr & __excepts); -} - -static __inline int fegetround(void) { - fenv_t _fpscr; - fegetenv(&_fpscr); - return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3); -} - -static __inline int fesetround(int __round) { - fenv_t _fpscr; - fegetenv(&_fpscr); - _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT); - _fpscr |= (__round << _FPSCR_RMODE_SHIFT); - fesetenv(&_fpscr); - return 0; -} - -static __inline int feholdexcept(fenv_t* __envp) { - fenv_t __env; - fegetenv(&__env); - *__envp = __env; - __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK); - fesetenv(&__env); - return 0; -} - -static __inline int feupdateenv(const fenv_t* __envp) { - fexcept_t __fpscr; - fegetenv(&__fpscr); - fesetenv(__envp); - feraiseexcept(__fpscr & FE_ALL_EXCEPT); - return 0; -} - -#if __BSD_VISIBLE - -static __inline int feenableexcept(int __mask) { - fenv_t __old_fpscr, __new_fpscr; - fegetenv(&__old_fpscr); - __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT; - fesetenv(&__new_fpscr); - return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT); -} - -static __inline int fedisableexcept(int __mask) { - fenv_t __old_fpscr, __new_fpscr; - fegetenv(&__old_fpscr); - __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT); - fesetenv(&__new_fpscr); - return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT); -} - -static __inline int fegetexcept(void) { - fenv_t __fpscr; - fegetenv(&__fpscr); - return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT); -} - -#endif /* __BSD_VISIBLE */ - -__END_DECLS - -#endif /* !_FENV_H_ */ diff --git a/libm/isinf.c b/libm/include/arm/machine/fenv.h index 2da8f58..0e483e3 100644 --- a/libm/isinf.c +++ b/libm/include/arm/machine/fenv.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> + * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,47 +23,41 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $ */ -#include <math.h> -#include <sys/cdefs.h> -#include "src/fpmath.h" - /* - * XXX These routines belong in libm, but they must remain in libc for - * binary compat until we can bump libm's major version number. + * Rewritten for Android. + * + * The ARM FPSCR is described here: + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html */ -int -__isinf(double d) -{ - union IEEEd2bits u; +#ifndef _ARM_FENV_H_ +#define _ARM_FENV_H_ + +#include <sys/types.h> - u.d = d; - return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0); -} +__BEGIN_DECLS -int -__isinff(float f) -{ - union IEEEf2bits u; +typedef __uint32_t fenv_t; +typedef __uint32_t fexcept_t; - u.f = f; - return (u.bits.exp == 255 && u.bits.man == 0); -} +/* Exception flags. */ +#define FE_INVALID 0x01 +#define FE_DIVBYZERO 0x02 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x10 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ + FE_OVERFLOW | FE_UNDERFLOW) -int -__isinfl(long double e) -{ - union IEEEl2bits u; +/* Rounding modes. */ +#define FE_TONEAREST 0x0 +#define FE_UPWARD 0x1 +#define FE_DOWNWARD 0x2 +#define FE_TOWARDZERO 0x3 - u.e = e; - mask_nbit_l(u); -#ifndef __alpha__ - return (u.bits.exp == 32767 && u.bits.manl == 0 && u.bits.manh == 0); -#else - return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0); -#endif -} +__END_DECLS +#endif /* !_ARM_FENV_H_ */ diff --git a/libm/include/arm64/machine/fenv.h b/libm/include/arm64/machine/fenv.h new file mode 100644 index 0000000..a8568b8 --- /dev/null +++ b/libm/include/arm64/machine/fenv.h @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> + * 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.5 2005/03/16 19:03:45 das Exp $ + */ + +/* + * In ARMv8, AArch64 state, floating-point operation is controlled by: + * + * * FPCR - 32Bit Floating-Point Control Register: + * * [31:27] - Reserved, Res0; + * * [26] - AHP, Alternative half-precision control bit; + * * [25] - DN, Default NaN mode control bit; + * * [24] - FZ, Flush-to-zero mode control bit; + * * [23:22] - RMode, Rounding Mode control field: + * * 00 - Round to Nearest (RN) mode; + * * 01 - Round towards Plus Infinity (RP) mode; + * * 10 - Round towards Minus Infinity (RM) mode; + * * 11 - Round towards Zero (RZ) mode. + * * [21:20] - Stride, ignored during AArch64 execution; + * * [19] - Reserved, Res0; + * * [18:16] - Len, ignored during AArch64 execution; + * * [15] - IDE, Input Denormal exception trap; + * * [14:13] - Reserved, Res0; + * * [12] - IXE, Inexact exception trap; + * * [11] - UFE, Underflow exception trap; + * * [10] - OFE, Overflow exception trap; + * * [9] - DZE, Division by Zero exception; + * * [8] - IOE, Invalid Operation exception; + * * [7:0] - Reserved, Res0. + * + * * FPSR - 32Bit Floating-Point Status Register: + * * [31] - N, Negative condition flag for AArch32 (AArch64 sets PSTATE.N); + * * [30] - Z, Zero condition flag for AArch32 (AArch64 sets PSTATE.Z); + * * [29] - C, Carry conditon flag for AArch32 (AArch64 sets PSTATE.C); + * * [28] - V, Overflow conditon flag for AArch32 (AArch64 sets PSTATE.V); + * * [27] - QC, Cumulative saturation bit, Advanced SIMD only; + * * [26:8] - Reserved, Res0; + * * [7] - IDC, Input Denormal cumulative exception; + * * [6:5] - Reserved, Res0; + * * [4] - IXC, Inexact cumulative exception; + * * [3] - UFC, Underflow cumulative exception; + * * [2] - OFC, Overflow cumulative exception; + * * [1] - DZC, Division by Zero cumulative exception; + * * [0] - IOC, Invalid Operation cumulative exception. + */ + +#ifndef _ARM64_FENV_H_ +#define _ARM64_FENV_H_ + +#include <sys/types.h> + +__BEGIN_DECLS + +typedef struct { + __uint32_t __control; /* FPCR, Floating-point Control Register */ + __uint32_t __status; /* FPSR, Floating-point Status Register */ +} fenv_t; + +typedef __uint32_t fexcept_t; + +/* Exception flags. */ +#define FE_INVALID 0x01 +#define FE_DIVBYZERO 0x02 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x10 +#define FE_DENORMAL 0x80 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL) + +/* Rounding modes. */ +#define FE_TONEAREST 0x0 +#define FE_UPWARD 0x1 +#define FE_DOWNWARD 0x2 +#define FE_TOWARDZERO 0x3 + +__END_DECLS + +#endif /* !_ARM64_FENV_H_ */ diff --git a/libm/include/complex.h b/libm/include/complex.h new file mode 100644 index 0000000..0702541 --- /dev/null +++ b/libm/include/complex.h @@ -0,0 +1,92 @@ +/*- + * Copyright (c) 2001-2011 The FreeBSD Project. + * 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$ + */ + +#ifndef _COMPLEX_H +#define _COMPLEX_H + +#include <sys/cdefs.h> + +#ifdef __GNUC__ +#if __STDC_VERSION__ < 199901 +#define _Complex __complex__ +#endif +#define _Complex_I ((float _Complex)1.0i) +#endif + +#ifdef __generic +_Static_assert(__generic(_Complex_I, float _Complex, 1, 0), + "_Complex_I must be of type float _Complex"); +#endif + +#define complex _Complex +#define I _Complex_I + +__BEGIN_DECLS + +double cabs(double complex); +float cabsf(float complex); +long double cabsl(long double complex); +double carg(double complex); +float cargf(float complex); +long double cargl(long double complex); +double complex ccos(double complex); +float complex ccosf(float complex); +double complex ccosh(double complex); +float complex ccoshf(float complex); +double complex cexp(double complex); +float complex cexpf(float complex); +double cimag(double complex) __pure2; +float cimagf(float complex) __pure2; +long double cimagl(long double complex) __pure2; +double complex conj(double complex) __pure2; +float complex conjf(float complex) __pure2; +long double complex + conjl(long double complex) __pure2; +float complex cprojf(float complex) __pure2; +double complex cproj(double complex) __pure2; +long double complex + cprojl(long double complex) __pure2; +double creal(double complex) __pure2; +float crealf(float complex) __pure2; +long double creall(long double complex) __pure2; +double complex csin(double complex); +float complex csinf(float complex); +double complex csinh(double complex); +float complex csinhf(float complex); +double complex csqrt(double complex); +float complex csqrtf(float complex); +long double complex + csqrtl(long double complex); +double complex ctan(double complex); +float complex ctanf(float complex); +double complex ctanh(double complex); +float complex ctanhf(float complex); + +__END_DECLS + +#endif /* _COMPLEX_H */ diff --git a/libm/include/fenv.h b/libm/include/fenv.h new file mode 100644 index 0000000..73ecc80 --- /dev/null +++ b/libm/include/fenv.h @@ -0,0 +1,71 @@ +/* $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $ */ + +/* + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _FENV_H_ +#define _FENV_H_ + +#include <sys/cdefs.h> +#include <machine/fenv.h> + +__BEGIN_DECLS +#pragma GCC visibility push(default) + +int feclearexcept(int); +int fegetexceptflag(fexcept_t *, int); +int feraiseexcept(int); +int fesetexceptflag(const fexcept_t *, int); +int fetestexcept(int); + +int fegetround(void); +int fesetround(int); + +int fegetenv(fenv_t *); +int feholdexcept(fenv_t *); +int fesetenv(const fenv_t *); +int feupdateenv(const fenv_t *); + +int feenableexcept(int); +int fedisableexcept(int); +int fegetexcept(void); + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions that manage the floating-point + * environment, namely fesetenv() and feupdateenv(). + */ +extern const fenv_t __fe_dfl_env; +#define FE_DFL_ENV (&__fe_dfl_env) + +#pragma GCC visibility pop +__END_DECLS + +#endif /* ! _FENV_H_ */ diff --git a/libm/include/i387/fenv.h b/libm/include/i387/fenv.h deleted file mode 100644 index c0421c0..0000000 --- a/libm/include/i387/fenv.h +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> - * 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/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $ - */ - -#ifndef _FENV_H_ -#define _FENV_H_ - -#include <sys/types.h> - -__BEGIN_DECLS - -/* - * To preserve binary compatibility with FreeBSD 5.3, we pack the - * mxcsr into some reserved fields, rather than changing sizeof(fenv_t). - */ -typedef struct { - __uint16_t __control; - __uint16_t __mxcsr_hi; - __uint16_t __status; - __uint16_t __mxcsr_lo; - __uint32_t __tag; - char __other[16]; -} 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) - -/* Default floating-point environment */ -extern const fenv_t __fe_dfl_env; -#define FE_DFL_ENV (&__fe_dfl_env) - -/* C99 floating-point exception functions */ -int feclearexcept(int excepts); -int fegetexceptflag(fexcept_t *flagp, int excepts); -int fesetexceptflag(const fexcept_t *flagp, int excepts); -/* feraiseexcept does not set the inexact flag on overflow/underflow */ -int feraiseexcept(int excepts); -int fetestexcept(int excepts); - -/* C99 rounding control functions */ -int fegetround(void); -int fesetround(int round); - -/* C99 floating-point environment functions */ -int fegetenv(fenv_t *__envp); -int feholdexcept(fenv_t *__envp); -int fesetenv(const fenv_t *envp); -int feupdateenv(const fenv_t *__envp); - -#if __BSD_VISIBLE -/* Additional support functions to set/query floating point traps */ -int feenableexcept(int __mask); -int fedisableexcept(int __mask); -int fegetexcept(void); - -#endif /* __BSD_VISIBLE */ - -__END_DECLS - -#endif /* !_FENV_H_ */ diff --git a/libm/include/i387/machine/fenv.h b/libm/include/i387/machine/fenv.h new file mode 100644 index 0000000..de45add --- /dev/null +++ b/libm/include/i387/machine/fenv.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> + * 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/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $ + */ + +#ifndef _I387_FENV_H_ +#define _I387_FENV_H_ + +#include <sys/types.h> + +__BEGIN_DECLS + +/* + * To preserve binary compatibility with FreeBSD 5.3, we pack the + * mxcsr into some reserved fields, rather than changing sizeof(fenv_t). + */ +typedef struct { + __uint16_t __control; + __uint16_t __mxcsr_hi; + __uint16_t __status; + __uint16_t __mxcsr_lo; + __uint32_t __tag; + char __other[16]; +} 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 + +__END_DECLS + +#endif /* !I387_FENV_H_ */ diff --git a/libm/include/math.h b/libm/include/math.h index a86a16f..4faec33 100644 --- a/libm/include/math.h +++ b/libm/include/math.h @@ -11,17 +11,17 @@ /* * from: @(#)fdlibm.h 5.1 93/09/24 - * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $ + * $FreeBSD$ */ #ifndef _MATH_H_ #define _MATH_H_ #include <sys/cdefs.h> -#include <sys/types.h> #include <limits.h> -#define __pure2 +__BEGIN_DECLS +#pragma GCC visibility push(default) /* * ANSI/POSIX @@ -36,37 +36,29 @@ extern const union __nan_un { float __uf; } __nan; -/* #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) */ -#if 1 +#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) #define __MATH_BUILTIN_CONSTANTS #endif -/* #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) */ -#if 1 +#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) #define __MATH_BUILTIN_RELOPS #endif -/* #ifdef __MATH_BUILTIN_CONSTANTS */ -#if 1 +#ifdef __MATH_BUILTIN_CONSTANTS #define HUGE_VAL __builtin_huge_val() #else #define HUGE_VAL (__infinity.__ud) #endif -/* #if __ISO_C_VISIBLE >= 1999 */ -#if 0 -#define FP_ILOGB0 (-__INT_MAX) -#define FP_ILOGBNAN __INT_MAX -#else -#define FP_ILOGB0 (-INT_MAX) -#define FP_ILOGBNAN INT_MAX -#endif +#if __ISO_C_VISIBLE >= 1999 +#define FP_ILOGB0 (-INT_MAX) /* Android-changed */ +#define FP_ILOGBNAN INT_MAX /* Android-changed */ #ifdef __MATH_BUILTIN_CONSTANTS #define HUGE_VALF __builtin_huge_valf() #define HUGE_VALL __builtin_huge_vall() -#define INFINITY __builtin_inf() -#define NAN __builtin_nan("") +#define INFINITY __builtin_inff() +#define NAN __builtin_nanf("") #else #define HUGE_VALF (float)HUGE_VAL #define HUGE_VALL (long double)HUGE_VAL @@ -78,14 +70,11 @@ extern const union __nan_un { #define MATH_ERREXCEPT 2 #define math_errhandling MATH_ERREXCEPT -/* XXX We need a <machine/math.h>. */ -#if defined(__ia64__) || defined(__sparc64__) -#define FP_FAST_FMA -#endif +#define FP_FAST_FMAF 1 #ifdef __ia64__ -#define FP_FAST_FMAL +#define FP_FAST_FMA 1 +#define FP_FAST_FMAL 1 #endif -#define FP_FAST_FMAF /* Symbolic constants to classify floating point numbers. */ #define FP_INFINITE 0x01 @@ -104,10 +93,10 @@ extern const union __nan_un { : __isfinitel(x)) #define isinf(x) \ ((sizeof (x) == sizeof (float)) ? __isinff(x) \ - : (sizeof (x) == sizeof (double)) ? __isinf(x) \ + : (sizeof (x) == sizeof (double)) ? isinf(x) \ : __isinfl(x)) #define isnan(x) \ - ((sizeof (x) == sizeof (float)) ? isnanf(x) \ + ((sizeof (x) == sizeof (float)) ? __isnanf(x) \ : (sizeof (x) == sizeof (double)) ? isnan(x) \ : __isnanl(x)) #define isnormal(x) \ @@ -137,16 +126,16 @@ extern const union __nan_un { : (sizeof (x) == sizeof (double)) ? __signbit(x) \ : __signbitl(x)) -#if 0 -typedef __double_t double_t; -typedef __float_t float_t; -#endif -/* #endif */ /* __ISO_C_VISIBLE >= 1999 */ +typedef double __double_t; +typedef __double_t double_t; +typedef float __float_t; +typedef __float_t float_t; +#endif /* __ISO_C_VISIBLE >= 1999 */ /* * 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 */ @@ -163,7 +152,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 @@ -179,7 +168,7 @@ extern int signgam; * effect of raising floating-point exceptions, so they are not declared * as __pure2. In C99, FENV_ACCESS affects the purity of these functions. */ -__BEGIN_DECLS + /* * ANSI/POSIX */ @@ -190,8 +179,8 @@ int __isfinitef(float) __pure2; int __isfinite(double) __pure2; int __isfinitel(long double) __pure2; int __isinff(float) __pure2; -int __isinf(double) __pure2; int __isinfl(long double) __pure2; +int __isnanf(float) __pure2; int __isnanl(long double) __pure2; int __isnormalf(float) __pure2; int __isnormal(double) __pure2; @@ -230,7 +219,7 @@ double fmod(double, double); /* * These functions are not in C90. */ -/* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE double acosh(double); double asinh(double); double atanh(double); @@ -242,12 +231,13 @@ double expm1(double); double fma(double, double, double); double hypot(double, double); int ilogb(double) __pure2; -/* int (isinf)(double) __pure2; */ +int (isinf)(double) __pure2; int (isnan)(double) __pure2; double lgamma(double); long long llrint(double); long long llround(double); double log1p(double); +double log2(double); double logb(double); long lrint(double); long lround(double); @@ -256,23 +246,26 @@ double nextafter(double, double); double remainder(double, double); double remquo(double, double, int *); double rint(double); -/* #endif */ /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ +#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ -/* #if __BSD_VISIBLE || __XSI_VISIBLE */ +#if __BSD_VISIBLE || __XSI_VISIBLE double j0(double); double j1(double); double jn(int, double); -double scalb(double, double); double y0(double); double y1(double); double yn(int, double); -/* #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE */ +#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE double gamma(double); -/* #endif */ -/* #endif */ /* __BSD_VISIBLE || __XSI_VISIBLE */ +#endif -/* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 */ +#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE +double scalb(double, double); +#endif +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 double copysign(double, double) __pure2; double fdim(double, double); double fmax(double, double) __pure2; @@ -283,15 +276,16 @@ double scalbln(double, long); double scalbn(double, int); double tgamma(double); double trunc(double); -/* #endif */ +#endif /* * BSD math library entry points */ -/* #if __BSD_VISIBLE */ +#if __BSD_VISIBLE double drem(double, double); int finite(double) __pure2; int isnanf(float) __pure2; +long double significandl(long double); /* * Reentrant version of gamma & lgamma; passes signgam back by reference @@ -304,10 +298,10 @@ double lgamma_r(double, int *); * IEEE Test Vector */ double significand(double); -/* #endif */ /* __BSD_VISIBLE */ +#endif /* __BSD_VISIBLE */ /* float versions of ANSI/POSIX functions */ -/*#if __ISO_C_VISIBLE >= 1999 */ +#if __ISO_C_VISIBLE >= 1999 float acosf(float); float asinf(float); float atanf(float); @@ -328,6 +322,7 @@ int ilogbf(float) __pure2; float ldexpf(float, int); float log10f(float); float log1pf(float); +float log2f(float); float logf(float); float modff(float, float *); /* fundamentally !__pure2 */ @@ -370,12 +365,12 @@ float fdimf(float, float); float fmaf(float, float, float); float fmaxf(float, float) __pure2; float fminf(float, float) __pure2; -/* #endif */ +#endif /* * float versions of BSD math library entry points */ -/* #if __BSD_VISIBLE */ +#if __BSD_VISIBLE float dremf(float, float); int finitef(float) __pure2; float gammaf(float); @@ -399,13 +394,12 @@ float lgammaf_r(float, int *); * float version of IEEE Test Vector */ float significandf(float); -/* #endif */ /* __BSD_VISIBLE */ +#endif /* __BSD_VISIBLE */ /* * long double versions of ISO/POSIX math functions */ -/* #if __ISO_C_VISIBLE >= 1999 */ -#if 0 +#if __ISO_C_VISIBLE >= 1999 long double acoshl(long double); long double acosl(long double); long double asinhl(long double); @@ -414,10 +408,8 @@ long double atan2l(long double, long double); long double atanhl(long double); long double atanl(long double); long double cbrtl(long double); -#endif long double ceill(long double); long double copysignl(long double, long double) __pure2; -#if 0 long double coshl(long double); long double cosl(long double); long double erfcl(long double); @@ -425,72 +417,58 @@ long double erfl(long double); long double exp2l(long double); long double expl(long double); long double expm1l(long double); -#endif long double fabsl(long double) __pure2; long double fdiml(long double, long double); long double floorl(long double); long double fmal(long double, long double, long double); long double fmaxl(long double, long double) __pure2; long double fminl(long double, long double) __pure2; -#if 0 long double fmodl(long double, long double); -#endif long double frexpl(long double value, int *); /* fundamentally !__pure2 */ -#if 0 long double hypotl(long double, long double); -#endif int ilogbl(long double) __pure2; long double ldexpl(long double, int); -#if 0 long double lgammal(long double); long long llrintl(long double); -#endif long long llroundl(long double); -#if 0 long double log10l(long double); long double log1pl(long double); long double log2l(long double); long double logbl(long double); long double logl(long double); long lrintl(long double); -#endif long lroundl(long double); -#if 0 long double modfl(long double, long double *); /* fundamentally !__pure2 */ long double nanl(const char *) __pure2; long double nearbyintl(long double); -#endif 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 long double powl(long double, long double); long double remainderl(long double, long double); long double remquol(long double, long double, int *); long double rintl(long double); -#endif long double roundl(long double); long double scalblnl(long double, long); long double scalbnl(long double, int); -#if 0 long double sinhl(long double); long double sinl(long double); long double sqrtl(long double); long double tanhl(long double); long double tanl(long double); long double tgammal(long double); -#endif long double truncl(long double); -/* BIONIC: GLibc compatibility - required by the ARM toolchain */ -#ifdef _GNU_SOURCE -void sincos(double x, double *sin, double *cos); -void sincosf(float x, float *sin, float *cos); -void sincosl(long double x, long double *sin, long double *cos); -#endif +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#if defined(_GNU_SOURCE) +void sincos(double, double*, double*); +void sincosf(float, float*, float*); +void sincosl(long double, long double*, long double*); +#endif /* _GNU_SOURCE */ -/* #endif */ /* __ISO_C_VISIBLE >= 1999 */ +#pragma GCC visibility pop __END_DECLS #endif /* !_MATH_H_ */ diff --git a/libm/include/mips/fenv.h b/libm/include/mips/fenv.h deleted file mode 100644 index ed69cf8..0000000 --- a/libm/include/mips/fenv.h +++ /dev/null @@ -1,225 +0,0 @@ -/*- - * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> - * 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.5 2005/03/16 19:03:45 das Exp $ - */ - -/* - Rewritten for Android. -*/ - -/* MIPS FPU floating point control register bits. - * - * 31-25 -> floating point conditions code bits set by FP compare - * instructions - * 24 -> flush denormalized results to zero instead of - * causing unimplemented operation exception. - * 23 -> Condition bit - * 22 -> In conjunction with FS detects denormalized - * operands and replaces them internally with 0. - * 21 -> In conjunction with FS forces denormalized operands - * to the closest normalized value. - * 20-18 -> reserved (read as 0, write with 0) - * 17 -> cause bit for unimplemented operation - * 16 -> cause bit for invalid exception - * 15 -> cause bit for division by zero exception - * 14 -> cause bit for overflow exception - * 13 -> cause bit for underflow exception - * 12 -> cause bit for inexact exception - * 11 -> enable exception for invalid exception - * 10 -> enable exception for division by zero exception - * 9 -> enable exception for overflow exception - * 8 -> enable exception for underflow exception - * 7 -> enable exception for inexact exception - * 6 -> flag invalid exception - * 5 -> flag division by zero exception - * 4 -> flag overflow exception - * 3 -> flag underflow exception - * 2 -> flag inexact exception - * 1-0 -> rounding control - * - * - * Rounding Control: - * 00 - rounding to nearest (RN) - * 01 - rounding toward zero (RZ) - * 10 - rounding (up) toward plus infinity (RP) - * 11 - rounding (down)toward minus infinity (RM) - */ - -#ifndef _FENV_H_ -#define _FENV_H_ - -#include <sys/types.h> - -__BEGIN_DECLS - -typedef __uint32_t fenv_t; -typedef __uint32_t fexcept_t; - -/* Exception flags */ -#define FE_INVALID 0x40 -#define FE_DIVBYZERO 0x20 -#define FE_OVERFLOW 0x10 -#define FE_UNDERFLOW 0x08 -#define FE_INEXACT 0x04 -#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ - FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) -#define _FCSR_CAUSE_SHIFT 10 -#define _ENABLE_SHIFT 5 -#define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT) - -/* Rounding modes */ -#define FE_TONEAREST 0x0000 -#define FE_TOWARDZERO 0x0001 -#define FE_UPWARD 0x0002 -#define FE_DOWNWARD 0x0003 -#define _FCSR_RMODE_SHIFT 0 -#define _FCSR_RMASK 0x3 -/* Default floating-point environment */ -extern const fenv_t __fe_dfl_env; -#define FE_DFL_ENV (&__fe_dfl_env) - -static __inline int fegetenv(fenv_t* __envp) { - fenv_t _fcsr = 0; -#ifdef __mips_hard_float - __asm__ __volatile__("cfc1 %0,$31" : "=r" (_fcsr)); -#endif - *__envp = _fcsr; - return 0; -} - -static __inline int fesetenv(const fenv_t* __envp) { - fenv_t _fcsr = *__envp; -#ifdef __mips_hard_float - __asm__ __volatile__("ctc1 %0,$31" : : "r" (_fcsr)); -#endif - return 0; -} - -static __inline int feclearexcept(int __excepts) { - fexcept_t __fcsr; - fegetenv(&__fcsr); - __excepts &= FE_ALL_EXCEPT; - __fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT)); - fesetenv(&__fcsr); - return 0; -} - -static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) { - fexcept_t __fcsr; - fegetenv(&__fcsr); - *__flagp = __fcsr & __excepts & FE_ALL_EXCEPT; - return 0; -} - -static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) { - fexcept_t __fcsr; - fegetenv(&__fcsr); - /* Ensure that flags are all legal */ - __excepts &= FE_ALL_EXCEPT; - __fcsr &= ~__excepts; - __fcsr |= *__flagp & __excepts; - fesetenv(&__fcsr); - return 0; -} - -static __inline int feraiseexcept(int __excepts) { - fexcept_t __fcsr; - fegetenv(&__fcsr); - /* Ensure that flags are all legal */ - __excepts &= FE_ALL_EXCEPT; - /* Cause bit needs to be set as well for generating the exception*/ - __fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT); - fesetenv(&__fcsr); - return 0; -} - -static __inline int fetestexcept(int __excepts) { - fexcept_t __FCSR; - fegetenv(&__FCSR); - return (__FCSR & __excepts & FE_ALL_EXCEPT); -} - -static __inline int fegetround(void) { - fenv_t _fcsr; - fegetenv(&_fcsr); - return (_fcsr & _FCSR_RMASK); -} - -static __inline int fesetround(int __round) { - fenv_t _fcsr; - fegetenv(&_fcsr); - _fcsr &= ~_FCSR_RMASK; - _fcsr |= (__round & _FCSR_RMASK ) ; - fesetenv(&_fcsr); - return 0; -} - -static __inline int feholdexcept(fenv_t* __envp) { - fenv_t __env; - fegetenv(&__env); - *__envp = __env; - __env &= ~(FE_ALL_EXCEPT | _FCSR_ENABLE_MASK); - fesetenv(&__env); - return 0; -} - -static __inline int feupdateenv(const fenv_t* __envp) { - fexcept_t __fcsr; - fegetenv(&__fcsr); - fesetenv(__envp); - feraiseexcept(__fcsr & FE_ALL_EXCEPT); - return 0; -} - -#if __BSD_VISIBLE - -static __inline int feenableexcept(int __mask) { - fenv_t __old_fcsr, __new_fcsr; - fegetenv(&__old_fcsr); - __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT; - fesetenv(&__new_fcsr); - return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT); -} - -static __inline int fedisableexcept(int __mask) { - fenv_t __old_fcsr, __new_fcsr; - fegetenv(&__old_fcsr); - __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT); - fesetenv(&__new_fcsr); - return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT); -} - -static __inline int fegetexcept(void) { - fenv_t __fcsr; - fegetenv(&__fcsr); - return ((__fcsr & _FCSR_ENABLE_MASK) >> _ENABLE_SHIFT); -} - -#endif /* __BSD_VISIBLE */ - -__END_DECLS - -#endif /* !_FENV_H_ */ diff --git a/libm/include/mips/machine/fenv.h b/libm/include/mips/machine/fenv.h new file mode 100644 index 0000000..689e1cb --- /dev/null +++ b/libm/include/mips/machine/fenv.h @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> + * 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.5 2005/03/16 19:03:45 das Exp $ + */ + +/* + Rewritten for Android. +*/ + +/* MIPS FPU floating point control register bits. + * + * 31-25 -> floating point conditions code bits set by FP compare + * instructions + * 24 -> flush denormalized results to zero instead of + * causing unimplemented operation exception. + * 23 -> Condition bit + * 22 -> In conjunction with FS detects denormalized + * operands and replaces them internally with 0. + * 21 -> In conjunction with FS forces denormalized operands + * to the closest normalized value. + * 20-18 -> reserved (read as 0, write with 0) + * 17 -> cause bit for unimplemented operation + * 16 -> cause bit for invalid exception + * 15 -> cause bit for division by zero exception + * 14 -> cause bit for overflow exception + * 13 -> cause bit for underflow exception + * 12 -> cause bit for inexact exception + * 11 -> enable exception for invalid exception + * 10 -> enable exception for division by zero exception + * 9 -> enable exception for overflow exception + * 8 -> enable exception for underflow exception + * 7 -> enable exception for inexact exception + * 6 -> flag invalid exception + * 5 -> flag division by zero exception + * 4 -> flag overflow exception + * 3 -> flag underflow exception + * 2 -> flag inexact exception + * 1-0 -> rounding control + * + * + * Rounding Control: + * 00 - rounding to nearest (RN) + * 01 - rounding toward zero (RZ) + * 10 - rounding (up) toward plus infinity (RP) + * 11 - rounding (down)toward minus infinity (RM) + */ + +#ifndef _MIPS_FENV_H_ +#define _MIPS_FENV_H_ + +#include <sys/types.h> + +__BEGIN_DECLS + +typedef __uint32_t fenv_t; +typedef __uint32_t fexcept_t; + +/* Exception flags */ +#define FE_INVALID 0x40 +#define FE_DIVBYZERO 0x20 +#define FE_OVERFLOW 0x10 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x04 +#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 + +__END_DECLS + +#endif /* !_MIPS_FENV_H_ */ diff --git a/libm/man/acos.3 b/libm/man/acos.3 deleted file mode 100644 index 9f03d60..0000000 --- a/libm/man/acos.3 +++ /dev/null @@ -1,92 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.13 2005/01/14 23:28:28 das Exp $ -.\" -.Dd January 14, 2005 -.Dt ACOS 3 -.Os -.Sh NAME -.Nm acos , -.Nm acosf -.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" -.Sh DESCRIPTION -The -.Fn acos -and the -.Fn acosf -functions compute the principal value of the arc cosine of -.Fa x . -A domain error occurs for arguments not in the range -.Bq -1 , +1 . -For a discussion of error due to roundoff, see -.Xr math 3 . -.Sh RETURN VALUES -The -.Fn acos -and the -.Fn acosf -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 -function conforms to -.St -isoC . diff --git a/libm/man/acosh.3 b/libm/man/acosh.3 deleted file mode 100644 index 62534ab..0000000 --- a/libm/man/acosh.3 +++ /dev/null @@ -1,82 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.11 2005/01/14 23:28:28 das 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/libm/man/asin.3 b/libm/man/asin.3 deleted file mode 100644 index 1018990..0000000 --- a/libm/man/asin.3 +++ /dev/null @@ -1,94 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.15 2005/01/14 23:28:28 das Exp $ -.\" -.Dd January 14, 2005 -.Dt ASIN 3 -.Os -.Sh NAME -.Nm asin , -.Nm asinf -.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" -.Sh DESCRIPTION -The -.Fn asin -and the -.Fn asinf -functions compute the principal value of the arc sine of -.Fa x . -A domain error occurs for arguments not in the range -.Bq -1 , +1 . -For a discussion of error due to roundoff, see -.Xr math 3 . -.Sh RETURN VALUES -The -.Fn asin -and the -.Fn asinf -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 -function conforms to -.St -isoC . diff --git a/libm/man/asinh.3 b/libm/man/asinh.3 deleted file mode 100644 index 6a0d9a0..0000000 --- a/libm/man/asinh.3 +++ /dev/null @@ -1,78 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.10 2001/10/13 12:23:22 bde 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/libm/man/atan.3 b/libm/man/atan.3 deleted file mode 100644 index c4cefed..0000000 --- a/libm/man/atan.3 +++ /dev/null @@ -1,84 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.10 2001/10/13 12:23:22 bde Exp $ -.\" -.Dd May 2, 1991 -.Dt ATAN 3 -.Os -.Sh NAME -.Nm atan , -.Nm atanf -.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" -.Sh DESCRIPTION -The -.Fn atan -and the -.Fn atanf -functions compute the principal value of the arc tangent of -.Fa x . -For a discussion of error due to roundoff, see -.Xr math 3 . -.Sh RETURN VALUES -The -.Fn atan -and the -.Fn atanf -function returns 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 -function conforms to -.St -isoC . diff --git a/libm/man/atan2.3 b/libm/man/atan2.3 deleted file mode 100644 index 421e17d..0000000 --- a/libm/man/atan2.3 +++ /dev/null @@ -1,187 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.14 2005/01/28 21:13:34 ru Exp $ -.\" -.Dd January 14, 2005 -.Dt ATAN2 3 -.Os -.Sh NAME -.Nm atan2 , -.Nm atan2f -.Nd arc tangent functions of two variables -.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" -.Sh DESCRIPTION -The -.Fn atan2 -and the -.Fn atan2f -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. -.Sh RETURN VALUES -The -.Fn atan2 -and the -.Fn atan2f -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 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 -function conforms to -.St -isoC . diff --git a/libm/man/atanh.3 b/libm/man/atanh.3 deleted file mode 100644 index 3dcc01a..0000000 --- a/libm/man/atanh.3 +++ /dev/null @@ -1,85 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.13 2005/01/28 21:14:16 ru 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/libm/man/ceil.3 b/libm/man/ceil.3 deleted file mode 100644 index 557903e..0000000 --- a/libm/man/ceil.3 +++ /dev/null @@ -1,82 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.15 2005/01/13 20:33:42 stefanf 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/libm/man/cimag.3 b/libm/man/cimag.3 deleted file mode 100644 index 069e848..0000000 --- a/libm/man/cimag.3 +++ /dev/null @@ -1,96 +0,0 @@ -.\" 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.2 2005/01/13 10:43:01 ru Exp $ -.\" -.Dd August 7, 2004 -.Dt CIMAG 3 -.Os -.Sh NAME -.Nm cimag , cimagf , cimagl , -.Nm conj , conjf , conjl , -.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 -.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 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 creal -functions return the real part -.Fa a . -.Sh STANDARDS -The -.Fn cimag , -.Fn conj -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 . diff --git a/libm/man/copysign.3 b/libm/man/copysign.3 deleted file mode 100644 index c3ce3dc..0000000 --- a/libm/man/copysign.3 +++ /dev/null @@ -1,90 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.1 2005/01/27 05:46:16 das 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/libm/man/cos.3 b/libm/man/cos.3 deleted file mode 100644 index 8e0bd91..0000000 --- a/libm/man/cos.3 +++ /dev/null @@ -1,83 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.11 2001/10/13 12:23:23 bde Exp $ -.\" -.Dd May 2, 1991 -.Dt COS 3 -.Os -.Sh NAME -.Nm cos , -.Nm cosf -.Nd cosine functions -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft double -.Fn cos "double x" -.Ft float -.Fn cosf "float x" -.Sh DESCRIPTION -The -.Fn cos -and the -.Fn cosf -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 -and the -.Fn cosf -functions return the cosine value. -.Sh SEE ALSO -.Xr acos 3 , -.Xr asin 3 , -.Xr atan 3 , -.Xr atan2 3 , -.Xr cosh 3 , -.Xr math 3 , -.Xr sin 3 , -.Xr sinh 3 , -.Xr tan 3 , -.Xr tanh 3 -.Sh STANDARDS -The -.Fn cos -function conforms to -.St -isoC . diff --git a/libm/man/cosh.3 b/libm/man/cosh.3 deleted file mode 100644 index 947c33e..0000000 --- a/libm/man/cosh.3 +++ /dev/null @@ -1,72 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.12 2005/01/14 23:28:28 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 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/libm/man/erf.3 b/libm/man/erf.3 deleted file mode 100644 index 824787f..0000000 --- a/libm/man/erf.3 +++ /dev/null @@ -1,97 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.11 2004/07/02 23:52:20 ru 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/libm/man/exp.3 b/libm/man/exp.3 deleted file mode 100644 index f6aed8f..0000000 --- a/libm/man/exp.3 +++ /dev/null @@ -1,236 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.22 2005/04/05 02:57:28 das Exp $ -.\" -.Dd April 5, 2005 -.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 expm1 , -.Nm expm1f , -.Nm log , -.Nm logf , -.Nm log10 , -.Nm log10f , -.Nm log1p , -.Nm log1pf , -.Nm pow , -.Nm powf -.Nd exponential, logarithm, 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 double -.Fn expm1 "double x" -.Ft float -.Fn expm1f "float x" -.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 log1p "double x" -.Ft float -.Fn log1pf "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 -and the -.Fn exp2f -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 log -and the -.Fn logf -functions compute the value of the natural logarithm of argument -.Fa x . -.Pp -The -.Fn log10 -and the -.Fn log10f -functions compute the value of the logarithm of argument -.Fa x -to base 10. -.Pp -The -.Fn log1p -and the -.Fn log1pf -functions compute -the value of log(1+x) 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. -An attempt to take the logarithm of \*(Pm0 will result in -a divide-by-zero exception, and an infinity will be returned. -An attempt to take the logarithm of a negative number will -result in an invalid exception, and an \*(Na will be generated. -.Sh NOTES -The functions exp(x)\-1 and log(1+x) are called -expm1 and logp1 in -.Tn BASIC -on the Hewlett\-Packard -.Tn HP Ns \-71B -and -.Tn APPLE -Macintosh, -.Tn EXP1 -and -.Tn LN1 -in Pascal, exp1 and log1 in C -on -.Tn APPLE -Macintoshes, where they have been provided to make -sure financial calculations of ((1+x)**n\-1)/x, namely -expm1(n\(**log1p(x))/x, will be accurate when x is tiny. -They also provide accurate inverse hyperbolic functions. -.Pp -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 math 3 diff --git a/libm/man/fabs.3 b/libm/man/fabs.3 deleted file mode 100644 index 56b3a23..0000000 --- a/libm/man/fabs.3 +++ /dev/null @@ -1,87 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.11 2004/07/01 18:20:57 ru 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/libm/man/fdim.3 b/libm/man/fdim.3 deleted file mode 100644 index ca4e5ec..0000000 --- a/libm/man/fdim.3 +++ /dev/null @@ -1,86 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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.1 2004/06/30 07:04:01 das 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 iff 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/libm/man/feclearexcept.3 b/libm/man/feclearexcept.3 deleted file mode 100644 index 073de67..0000000 --- a/libm/man/feclearexcept.3 +++ /dev/null @@ -1,139 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/feenableexcept.3 b/libm/man/feenableexcept.3 deleted file mode 100644 index 0b790e7..0000000 --- a/libm/man/feenableexcept.3 +++ /dev/null @@ -1,98 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/fegetenv.3 b/libm/man/fegetenv.3 deleted file mode 100644 index 2e386ad..0000000 --- a/libm/man/fegetenv.3 +++ /dev/null @@ -1,113 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/fegetround.3 b/libm/man/fegetround.3 deleted file mode 100644 index 9384158..0000000 --- a/libm/man/fegetround.3 +++ /dev/null @@ -1,83 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/fenv.3 b/libm/man/fenv.3 deleted file mode 100644 index 33ad541..0000000 --- a/libm/man/fenv.3 +++ /dev/null @@ -1,289 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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.5 2005/06/15 19:04:04 ru 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 program attempts to -divide a finite non-zero number by zero. -.It Dv FE_INEXACT -An inexact exception is raised whenever there is a loss of precision -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 infinities, division of zero by zero, -ordered comparison involving \*(Nas, and taking the square root of a -negative number are all invalid operations. -.It Dv FE_OVERFLOW -An overflow exception occurs when the magnitude of the result of a -computation is too large to fit in the destination type. -.It Dv FE_UNDERFLOW -Underflow occurs when the result of a computation is too close to zero -to be represented as a non-zero value in the destination type. -.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 -non-standard mechanisms. -.\" XXX Mention fe[gs]etmask() here after the interface is finalized -.\" XXX and ready to be officially documented. -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 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 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 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. -.Pp -On the Alpha platform, -.Xr cc 1 -must be passed the -.Fl mieee-with-inexact mfp-rounding-mode=d -options in order to generate code that has the standard -side-effects and uses the specified rounding modes. diff --git a/libm/man/floor.3 b/libm/man/floor.3 deleted file mode 100644 index 1f02daf..0000000 --- a/libm/man/floor.3 +++ /dev/null @@ -1,82 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.17 2005/01/13 09:35:47 ru 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/libm/man/fma.3 b/libm/man/fma.3 deleted file mode 100644 index 078a6e2..0000000 --- a/libm/man/fma.3 +++ /dev/null @@ -1,116 +0,0 @@ -.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/fmax.3 b/libm/man/fmax.3 deleted file mode 100644 index 03249a3..0000000 --- a/libm/man/fmax.3 +++ /dev/null @@ -1,97 +0,0 @@ -.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/fmod.3 b/libm/man/fmod.3 deleted file mode 100644 index c0d4ed8..0000000 --- a/libm/man/fmod.3 +++ /dev/null @@ -1,87 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.8 2001/10/13 12:23:23 bde Exp $ -.\" -.Dd May 2, 1991 -.Dt FMOD 3 -.Os -.Sh NAME -.Nm fmod , -.Nm fmodf -.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" -.Sh DESCRIPTION -The -.Fn fmod -and the -.Fn fmodf -functions compute the floating-point remainder of -.Fa x Ns / Fa y . -.Sh RETURN VALUES -The -.Fn fmod -and the -.Fn fmodf -functions return the value -.Sm off -.Fa x - Em i * Fa y , -.Sm on -for some integer -.Em i -such that, if -.Fa y -is non-zero, the result has the same sign as -.Fa x -and magnitude less than the magnitude of -.Fa y . -If -.Fa y -is zero, whether a domain error occurs or the -.Fn fmod -and the -.Fn fmodf -function returns zero is implementation-defined. -.Sh SEE ALSO -.Xr math 3 -.Sh STANDARDS -The -.Fn fmod -function conforms to -.St -isoC . diff --git a/libm/man/hypot.3 b/libm/man/hypot.3 deleted file mode 100644 index a92a2a6..0000000 --- a/libm/man/hypot.3 +++ /dev/null @@ -1,134 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.13 2005/01/14 23:28:28 das Exp $ -.\" -.Dd January 14, 2005 -.Dt HYPOT 3 -.Os -.Sh NAME -.Nm hypot , -.Nm hypotf , -.Nm cabs , -.Nm cabsf -.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" -.In complex.h -.Ft double -.Fn cabs "double complex z" -.Ft float -.Fn cabsf "float complex z" -.Sh DESCRIPTION -The -.Fn hypot -and -.Fn hypotf -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 -and -.Fn cabsf -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. -.Pp -The same cannot be said for the shorter and faster version of hypot -and cabs that is provided in the comments in cabs.c; its error can -exceed 1.2 -.Em ulps . -.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 math 3 , -.Xr sqrt 3 -.Sh HISTORY -Both a -.Fn hypot -function and a -.Fn cabs -function -appeared in -.At v7 . diff --git a/libm/man/ieee.3 b/libm/man/ieee.3 deleted file mode 100644 index 3b7087d..0000000 --- a/libm/man/ieee.3 +++ /dev/null @@ -1,448 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.22 2005/06/16 21:55:45 ru 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 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 double-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 double-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/libm/man/ieee_test.3 b/libm/man/ieee_test.3 deleted file mode 100644 index debb6c8..0000000 --- a/libm/man/ieee_test.3 +++ /dev/null @@ -1,93 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.13 2005/11/17 13:00:00 ru 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/libm/man/ilogb.3 b/libm/man/ilogb.3 deleted file mode 100644 index 00ac754..0000000 --- a/libm/man/ilogb.3 +++ /dev/null @@ -1,127 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.3 2005/11/17 13:00:00 ru Exp $ -.\" -.Dd November 6, 2005 -.Dt ILOGB 3 -.Os -.Sh NAME -.Nm ilogb , -.Nm ilogbf , -.Nm ilogbl , -.Nm logb , -.Nm logbf -.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" -.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 -and -.Fn logbf 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 -and -.Fn logbf -routines conform to -.St -isoC-99 . -.Fn logb -and -.Fn logbf -implement the logb function recommended by -.St -ieee754 . -.Sh HISTORY -The -.Fn logb -function appeared in -.Bx 4.3 . -The -.Fn ilogb -function appeared in -.Fx 1.1.5 . -The -.Fn ilogbf -and -.Fn logbf -functions appeared in -.Fx 2.0 . -The -.Fn ilogbl -function appeared in -.Fx 5.4 . diff --git a/libm/man/j0.3 b/libm/man/j0.3 deleted file mode 100644 index 76cd51c..0000000 --- a/libm/man/j0.3 +++ /dev/null @@ -1,142 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.13 2005/01/14 23:28:28 das Exp $ -.\" -.Dd January 14, 2005 -.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 -If these functions are successful, -the computed value is returned. -.Sh SEE ALSO -.Xr math 3 -.Sh HISTORY -This set of functions -appeared in -.At v7 . diff --git a/libm/man/lgamma.3 b/libm/man/lgamma.3 deleted file mode 100644 index 0064a48..0000000 --- a/libm/man/lgamma.3 +++ /dev/null @@ -1,185 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.22 2005/01/16 16:46:14 ru 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 -.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" -.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)|. -.Pp -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 -.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. -.Fn tgamma x -returns \(*G(x), with no effect on -.Fa signgam . -.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 -and -.Fn tgamma -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/libm/man/lrint.3 b/libm/man/lrint.3 deleted file mode 100644 index d7de093..0000000 --- a/libm/man/lrint.3 +++ /dev/null @@ -1,94 +0,0 @@ -.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org> -.\" 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.2 2005/01/13 10:43:01 ru Exp $ -.\" -.Dd January 11, 2005 -.Dt LRINT 3 -.Os -.Sh NAME -.Nm llrint , -.Nm llrintf , -.Nm lrint , -.Nm lrintf -.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 -.Fn lrint "double x" -.Ft long -.Fn lrintf "float 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 , -and -.Fn lrintf -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 -The -.Fn llrint , -.Fn llrintf , -.Fn lrint , -and -.Fn lrintf -functions conform to -.St -isoC-99 . -.Sh HISTORY -These routines first appeared in -.Fx 5.4 . diff --git a/libm/man/lround.3 b/libm/man/lround.3 deleted file mode 100644 index d3e53c2..0000000 --- a/libm/man/lround.3 +++ /dev/null @@ -1,112 +0,0 @@ -.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org> -.\" 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/libm/man/math.3 b/libm/man/math.3 deleted file mode 100644 index 828b5e0..0000000 --- a/libm/man/math.3 +++ /dev/null @@ -1,242 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.27 2005/11/17 13:00:00 ru Exp $ -.\" -.Dd November 6, 2005 -.Dt MATH 3 -.Os -.if n \{\ -.char \[sr] "sqrt -.\} -.Sh NAME -.Nm math -.Nd "floating-point mathematical library" -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Sh DESCRIPTION -These functions constitute the C math library. -.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. -.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 Functions -.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 -.\" .Cl -.\" nan return quiet \*(Na) 0 -.\" .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 -Unlike the algebraic functions listed earlier, the routines -in this section may 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 fenv 3 , -.Xr ieee 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 -The -.Fn log2 -and -.Fn nan -functions are missing, and many functions are not available in their -.Vt "long double" -variants. -.Pp -Many of the routines to compute transcendental functions produce -inaccurate results in other than the default rounding mode. -.Pp -On some architectures, trigonometric argument reduction is not -performed accurately, resulting in errors greater than 1 -.Em ulp -for large arguments to -.Fn cos , -.Fn sin , -and -.Fn tan . diff --git a/libm/man/nextafter.3 b/libm/man/nextafter.3 deleted file mode 100644 index 1c94fb7..0000000 --- a/libm/man/nextafter.3 +++ /dev/null @@ -1,100 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.2 2005/03/07 05:00:29 das 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/libm/man/remainder.3 b/libm/man/remainder.3 deleted file mode 100644 index 9b621e3..0000000 --- a/libm/man/remainder.3 +++ /dev/null @@ -1,146 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.4 2005/11/24 09:25:10 joel Exp $ -.\" -.Dd March 24, 2005 -.Dt REMAINDER 3 -.Os -.Sh NAME -.Nm remainder , -.Nm remainderf , -.Nm remquo , -.Nm remquof -.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 double -.Fn remquo "double x" "double y" "int *quo" -.Ft float -.Fn remquof "float x" "float y" "int *quo" -.Sh DESCRIPTION -.Fn remainder , -.Fn remainderf , -.Fn remquo , -and -.Fn remquof -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 -and -.Fn remquof -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 remquo , -and -.Fn remquof -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 . diff --git a/libm/man/rint.3 b/libm/man/rint.3 deleted file mode 100644 index ee55fea..0000000 --- a/libm/man/rint.3 +++ /dev/null @@ -1,103 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.11 2005/01/11 23:12:17 das Exp $ -.\" -.Dd July 5, 2004 -.Dt RINT 3 -.Os -.Sh NAME -.Nm nearbyint , -.Nm nearbyintf , -.Nm rint , -.Nm rintf -.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 double -.Fn rint "double x" -.Ft float -.Fn rintf "float x" -.Sh DESCRIPTION -The -.Fn rint -and the -.Fn rintf -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 -and -.Fn nearbyintf -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 -The -.Fn nearbyint , -.Fn nearbyintf , -.Fn rint , -and -.Fn rintf -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 . diff --git a/libm/man/round.3 b/libm/man/round.3 deleted file mode 100644 index b077d77..0000000 --- a/libm/man/round.3 +++ /dev/null @@ -1,80 +0,0 @@ -.\" 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/libm/man/scalbn.3 b/libm/man/scalbn.3 deleted file mode 100644 index 923caab..0000000 --- a/libm/man/scalbn.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.3 2005/11/24 09:25:10 joel 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/libm/man/signbit.3 b/libm/man/signbit.3 deleted file mode 100644 index b749671..0000000 --- a/libm/man/signbit.3 +++ /dev/null @@ -1,57 +0,0 @@ -.\" Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> -.\" 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/libm/man/sin.3 b/libm/man/sin.3 deleted file mode 100644 index 3a408a7..0000000 --- a/libm/man/sin.3 +++ /dev/null @@ -1,82 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.9 2001/10/13 12:23:23 bde Exp $ -.\" -.Dd April 19, 1991 -.Dt SIN 3 -.Os -.Sh NAME -.Nm sin , -.Nm sinf -.Nd sine functions -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft double -.Fn sin "double x" -.Ft float -.Fn sinf "float x" -.Sh DESCRIPTION -The -.Fn sin -and the -.Fn sinf -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 -and the -.Fn sinf -functions return the sine value. -.Sh SEE ALSO -.Xr acos 3 , -.Xr asin 3 , -.Xr atan 3 , -.Xr atan2 3 , -.Xr cos 3 , -.Xr cosh 3 , -.Xr math 3 , -.Xr sinh 3 , -.Xr tan 3 , -.Xr tanh 3 -.Sh STANDARDS -The -.Fn sin -function conforms to -.St -isoC . diff --git a/libm/man/sinh.3 b/libm/man/sinh.3 deleted file mode 100644 index 8347862..0000000 --- a/libm/man/sinh.3 +++ /dev/null @@ -1,71 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.12 2005/01/14 23:28:28 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 math 3 , -.Xr sin 3 , -.Xr tan 3 , -.Xr tanh 3 -.Sh STANDARDS -The -.Fn sinh -function conforms to -.St -isoC . diff --git a/libm/man/sqrt.3 b/libm/man/sqrt.3 deleted file mode 100644 index 22f8b7b..0000000 --- a/libm/man/sqrt.3 +++ /dev/null @@ -1,100 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.12 2005/01/14 23:28:28 das Exp $ -.\" -.Dd May 6, 1991 -.Dt SQRT 3 -.Os -.Sh NAME -.Nm cbrt , -.Nm cbrtf , -.Nm sqrt , -.Nm sqrtf -.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 double -.Fn sqrt "double x" -.Ft float -.Fn sqrtf "float x" -.Sh DESCRIPTION -The -.Fn cbrt -and the -.Fn cbrtf -functions compute -the cube root of -.Ar x . -.Pp -The -.Fn sqrt -and the -.Fn sqrtf -functions compute the -non-negative square root of x. -.Sh RETURN VALUES -The -.Fn cbrt -and the -.Fn cbrtf -functions return the requested cube root. -The -.Fn sqrt -and the -.Fn sqrtf -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. -.Sh SEE ALSO -.Xr fenv 3 , -.Xr math 3 -.Sh STANDARDS -The -.Fn sqrt -function conforms to -.St -isoC . -.Sh HISTORY -The -.Fn cbrt -function appeared in -.Bx 4.3 . diff --git a/libm/man/tan.3 b/libm/man/tan.3 deleted file mode 100644 index 5995a3b..0000000 --- a/libm/man/tan.3 +++ /dev/null @@ -1,81 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.9 2001/10/13 12:23:23 bde Exp $ -.\" -.Dd May 2, 1991 -.Dt TAN 3 -.Os -.Sh NAME -.Nm tan , -.Nm tanf -.Nd tangent functions -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft double -.Fn tan "double x" -.Ft float -.Fn tanf "float x" -.Sh DESCRIPTION -The -.Fn tan -and the -.Fn tanf -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 -function returns 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 math 3 , -.Xr sin 3 , -.Xr sinh 3 , -.Xr tanh 3 -.Sh STANDARDS -The -.Fn tan -function conforms to -.St -isoC . diff --git a/libm/man/tanh.3 b/libm/man/tanh.3 deleted file mode 100644 index 391bc15..0000000 --- a/libm/man/tanh.3 +++ /dev/null @@ -1,80 +0,0 @@ -.\" 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. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 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.10 2001/10/13 12:23:23 bde 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 math 3 , -.Xr sin 3 , -.Xr sinh 3 , -.Xr tan 3 -.Sh STANDARDS -The -.Fn tanh -function conforms to -.St -isoC . diff --git a/libm/man/trunc.3 b/libm/man/trunc.3 deleted file mode 100644 index cb6c26f..0000000 --- a/libm/man/trunc.3 +++ /dev/null @@ -1,80 +0,0 @@ -.\" Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.org> -.\" 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/libm/mips/_fpmath.h b/libm/mips/_fpmath.h deleted file mode 100644 index cb6e8c0..0000000 --- a/libm/mips/_fpmath.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG> - * 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/libc/mips/_fpmath.h,v 1.1 2008/04/26 12:07:59 imp Exp $ - */ - -union IEEEl2bits { - long double e; - struct { -#ifndef __MIPSEB__ - unsigned int manl :32; - unsigned int manh :20; - unsigned int exp :11; - unsigned int sign :1; -#else - unsigned int sign :1; - unsigned int exp :11; - unsigned int manh :20; - unsigned int manl :32; -#endif - } bits; -}; - -#define LDBL_NBIT 0 -#define mask_nbit_l(u) ((void)0) -#define LDBL_IMPLICIT_NBIT - -#define LDBL_MANH_SIZE 20 -#define LDBL_MANL_SIZE 32 - -#define LDBL_TO_ARRAY32(u, a) do { \ - (a)[0] = (uint32_t)(u).bits.manl; \ - (a)[1] = (uint32_t)(u).bits.manh; \ -} while(0) diff --git a/libm/mips/fenv.c b/libm/mips/fenv.c index b5f52da..aacd526 100644 --- a/libm/mips/fenv.c +++ b/libm/mips/fenv.c @@ -28,8 +28,129 @@ #include <fenv.h> +#define FCSR_CAUSE_SHIFT 10 +#define FCSR_ENABLE_SHIFT 5 +#define FCSR_ENABLE_MASK (FE_ALL_EXCEPT << FCSR_ENABLE_SHIFT) + +#define FCSR_RMASK 0x3 + /* * 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; + +int fegetenv(fenv_t* __envp) { + fenv_t _fcsr = 0; +#ifdef __mips_hard_float + __asm__ __volatile__("cfc1 %0,$31" : "=r" (_fcsr)); +#endif + *__envp = _fcsr; + return 0; +} + +int fesetenv(const fenv_t* __envp) { + fenv_t _fcsr = *__envp; +#ifdef __mips_hard_float + __asm__ __volatile__("ctc1 %0,$31" : : "r" (_fcsr)); +#endif + return 0; +} + +int feclearexcept(int __excepts) { + fexcept_t __fcsr; + fegetenv(&__fcsr); + __excepts &= FE_ALL_EXCEPT; + __fcsr &= ~(__excepts | (__excepts << FCSR_CAUSE_SHIFT)); + fesetenv(&__fcsr); + return 0; +} + +int fegetexceptflag(fexcept_t* __flagp, int __excepts) { + fexcept_t __fcsr; + fegetenv(&__fcsr); + *__flagp = __fcsr & __excepts & FE_ALL_EXCEPT; + return 0; +} + +int fesetexceptflag(const fexcept_t* __flagp, int __excepts) { + fexcept_t __fcsr; + fegetenv(&__fcsr); + /* Ensure that flags are all legal */ + __excepts &= FE_ALL_EXCEPT; + __fcsr &= ~__excepts; + __fcsr |= *__flagp & __excepts; + fesetenv(&__fcsr); + return 0; +} + +int feraiseexcept(int __excepts) { + fexcept_t __fcsr; + fegetenv(&__fcsr); + /* Ensure that flags are all legal */ + __excepts &= FE_ALL_EXCEPT; + /* Cause bit needs to be set as well for generating the exception*/ + __fcsr |= __excepts | (__excepts << FCSR_CAUSE_SHIFT); + fesetenv(&__fcsr); + return 0; +} + +int fetestexcept(int __excepts) { + fexcept_t __FCSR; + fegetenv(&__FCSR); + return (__FCSR & __excepts & FE_ALL_EXCEPT); +} + +int fegetround(void) { + fenv_t _fcsr; + fegetenv(&_fcsr); + return (_fcsr & FCSR_RMASK); +} + +int fesetround(int __round) { + fenv_t _fcsr; + fegetenv(&_fcsr); + _fcsr &= ~FCSR_RMASK; + _fcsr |= (__round & FCSR_RMASK); + fesetenv(&_fcsr); + return 0; +} + +int feholdexcept(fenv_t* __envp) { + fenv_t __env; + fegetenv(&__env); + *__envp = __env; + __env &= ~(FE_ALL_EXCEPT | FCSR_ENABLE_MASK); + fesetenv(&__env); + return 0; +} + +int feupdateenv(const fenv_t* __envp) { + fexcept_t __fcsr; + fegetenv(&__fcsr); + fesetenv(__envp); + feraiseexcept(__fcsr & FE_ALL_EXCEPT); + return 0; +} + +int feenableexcept(int __mask) { + fenv_t __old_fcsr, __new_fcsr; + fegetenv(&__old_fcsr); + __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT; + fesetenv(&__new_fcsr); + return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT); +} + +int fedisableexcept(int __mask) { + fenv_t __old_fcsr, __new_fcsr; + fegetenv(&__old_fcsr); + __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << FCSR_ENABLE_SHIFT); + fesetenv(&__new_fcsr); + return ((__old_fcsr >> FCSR_ENABLE_SHIFT) & FE_ALL_EXCEPT); +} + +int fegetexcept(void) { + fenv_t __fcsr; + fegetenv(&__fcsr); + return ((__fcsr & FCSR_ENABLE_MASK) >> FCSR_ENABLE_SHIFT); +} diff --git a/libm/src/s_signbit.c b/libm/signbit.c index ffc08f3..b98bf45 100644 --- a/libm/src/s_signbit.c +++ b/libm/signbit.c @@ -23,36 +23,37 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_signbit.c,v 1.1 2004/07/19 08:16:10 das Exp $ + * $FreeBSD$ */ #include <math.h> #include "fpmath.h" -int -__signbit(double d) +int __signbit(double d) { - union IEEEd2bits u; + union IEEEd2bits u; - u.d = d; - return (u.bits.sign); + u.d = d; + return (u.bits.sign); } -int -__signbitf(float f) +int __signbitf(float f) { - union IEEEf2bits u; + union IEEEf2bits u; - u.f = f; - return (u.bits.sign); + u.f = f; + return (u.bits.sign); } -int -__signbitl(long double e) +#ifdef __LP64__ +int __signbitl(long double e) { - union IEEEl2bits u; + union IEEEl2bits u; - u.e = e; - return (u.bits.sign); + u.e = e; + return (u.bits.sign); } +#else // __LP32__ +__weak_reference(__signbit, __signbitl); +#endif // __LP64__ diff --git a/libm/significandl.c b/libm/significandl.c new file mode 100644 index 0000000..c5d7dd4 --- /dev/null +++ b/libm/significandl.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * 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 <math.h> + +long double significandl(long double x) { + return scalbnl(x, -ilogbl(x)); +} diff --git a/libm/sincos.c b/libm/sincos.c index e9f6dcc..ad75549 100644 --- a/libm/sincos.c +++ b/libm/sincos.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2010 The Android Open Source Project + * Copyright (C) 2010 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,20 +35,17 @@ // Thus we just enforce -O0 when compiling this file. #pragma GCC optimize ("O0") -void sincos(double x, double *psin, double *pcos) -{ - *psin = sin(x); - *pcos = cos(x); +void sincos(double x, double* p_sin, double* p_cos) { + *p_sin = sin(x); + *p_cos = cos(x); } -void sincosf(float x, float *psin, float *pcos) -{ - *psin = sinf(x); - *pcos = cosf(x); +void sincosf(float x, float* p_sinf, float* p_cosf) { + *p_sinf = sinf(x); + *p_cosf = cosf(x); } -void sincosl(long double x, long double *psin, long double *pcos) -{ - *psin = sin(x); - *pcos = cos(x); +void sincosl(long double x, long double* p_sinl, long double* p_cosl) { + *p_sinl = sinl(x); + *p_cosl = cosl(x); } diff --git a/libm/src/e_asinf.c b/libm/src/e_asinf.c deleted file mode 100644 index 1405faf..0000000 --- a/libm/src/e_asinf.c +++ /dev/null @@ -1,84 +0,0 @@ -/* e_asinf.c -- float version of e_asin.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_asinf.c,v 1.9 2005/12/04 13:52:46 bde Exp $"; -#endif - -#include "math.h" -#include "math_private.h" - -static const float -one = 1.0000000000e+00, /* 0x3F800000 */ -huge = 1.000e+30, -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pio4_hi = 7.8539812565e-01, /* 0x3f490fda */ - /* coefficient for R(x^2) */ -pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ -pS1 = -3.2556581497e-01, /* 0xbea6b090 */ -pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ -pS3 = -4.0055535734e-02, /* 0xbd241146 */ -pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ -pS5 = 3.4793309169e-05, /* 0x3811ef08 */ -qS1 = -2.4033949375e+00, /* 0xc019d139 */ -qS2 = 2.0209457874e+00, /* 0x4001572d */ -qS3 = -6.8828397989e-01, /* 0xbf303361 */ -qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ - -float -__ieee754_asinf(float x) -{ - float t=0.0,w,p,q,c,r,s; - int32_t hx,ix; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix==0x3f800000) { - /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - } else if(ix> 0x3f800000) { /* |x|>= 1 */ - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ - } else if (ix<0x3f000000) { /* |x|<0.5 */ - if(ix<0x32000000) { /* if |x| < 2**-27 */ - if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else - t = x*x; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - w = p/q; - return x+x*w; - } - /* 1> |x|>= 0.5 */ - w = one-fabsf(x); - t = w*(float)0.5; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - s = __ieee754_sqrtf(t); - if(ix>=0x3F79999A) { /* if |x| > 0.975 */ - w = p/q; - t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo); - } else { - int32_t iw; - w = s; - GET_FLOAT_WORD(iw,w); - SET_FLOAT_WORD(w,iw&0xfffff000); - c = (t-w*w)/(s+w); - r = p/q; - p = (float)2.0*s*r-(pio2_lo-(float)2.0*c); - q = pio4_hi-(float)2.0*w; - t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; -} diff --git a/libm/src/e_ldexpf.c b/libm/src/e_ldexpf.c deleted file mode 100644 index 86297fc..0000000 --- a/libm/src/e_ldexpf.c +++ /dev/null @@ -1,22 +0,0 @@ -/* e_scalbf.c -- float version of e_scalb.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * 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 "math.h" -#include "math_private.h" - -float -__ieee754_ldexpf(float x, int fn) -{ - return __ieee754_scalbf(x,fn); -} diff --git a/libm/src/e_log10.c b/libm/src/e_log10.c deleted file mode 100644 index e84c0c7..0000000 --- a/libm/src/e_log10.c +++ /dev/null @@ -1,87 +0,0 @@ - -/* @(#)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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log10.c,v 1.11 2005/02/04 18:26:06 das Exp $"; -#endif - -/* __ieee754_log10(x) - * Return the base 10 logarithm of x - * - * Method : - * Let log10_2hi = leading 40 bits of log10(2) and - * log10_2lo = log10(2) - log10_2hi, - * ivln10 = 1/log(10) rounded. - * Then - * n = ilogb(x), - * if(n<0) n = n+1; - * x = scalbn(x,-n); - * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x)) - * - * Note 1: - * To guarantee log10(10**n)=n, where 10**n is normal, the rounding - * mode must set to Round-to-Nearest. - * Note 2: - * [1/log(10)] rounded to 53 bits has error .198 ulps; - * log10 is monotonic at all binary break points. - * - * Special cases: - * log10(x) is NaN with signal if x < 0; - * log10(+INF) is +INF with no signal; log10(0) is -INF with signal; - * log10(NaN) is that NaN with no signal; - * log10(10**N) = N for N=0,1,...,22. - * - * Constants: - * The hexadecimal values are the intended ones for the following constants. - * The decimal values may be used, provided that the compiler will convert - * from decimal to binary accurately enough to produce the hexadecimal values - * shown. - */ - -#include "math.h" -#include "math_private.h" - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ -log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ -log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ - -static const double zero = 0.0; - -double -__ieee754_log10(double x) -{ - double y,z; - 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; - k += (hx>>20)-1023; - i = ((u_int32_t)k&0x80000000)>>31; - hx = (hx&0x000fffff)|((0x3ff-i)<<20); - y = (double)(k+i); - SET_HIGH_WORD(x,hx); - z = y*log10_2lo + ivln10*__ieee754_log(x); - return z+y*log10_2hi; -} diff --git a/libm/src/e_log10f.c b/libm/src/e_log10f.c deleted file mode 100644 index 3473088..0000000 --- a/libm/src/e_log10f.c +++ /dev/null @@ -1,55 +0,0 @@ -/* e_log10f.c -- float version of e_log10.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log10f.c,v 1.8 2002/05/28 18:15:04 alfred Exp $"; -#endif - -#include "math.h" -#include "math_private.h" - -static const float -two25 = 3.3554432000e+07, /* 0x4c000000 */ -ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */ -log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ -log10_2lo = 7.9034151668e-07; /* 0x355427db */ - -static const float zero = 0.0; - -float -__ieee754_log10f(float x) -{ - float y,z; - 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; - k += (hx>>23)-127; - i = ((u_int32_t)k&0x80000000)>>31; - hx = (hx&0x007fffff)|((0x7f-i)<<23); - y = (float)(k+i); - SET_FLOAT_WORD(x,hx); - z = y*log10_2lo + ivln10*__ieee754_logf(x); - return z+y*log10_2hi; -} diff --git a/libm/src/e_rem_pio2f.c b/libm/src/e_rem_pio2f.c deleted file mode 100644 index 5231cd4..0000000 --- a/libm/src/e_rem_pio2f.c +++ /dev/null @@ -1,98 +0,0 @@ -/* e_rem_pio2f.c -- float version of e_rem_pio2.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Debugged and optimized by Bruce D. Evans. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_rem_pio2f.c,v 1.19 2005/11/23 03:03:09 bde Exp $"; -#endif - -/* __ieee754_rem_pio2f(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use double precision internally - * use __kernel_rem_pio2() for large x - */ - -#include "math.h" -#include "math_private.h" - -/* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ -static const int32_t two_over_pi[] = { -0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, -0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, -0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, -0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, -0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, -0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, -0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, -0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, -0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, -0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, -0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, -}; - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - */ - -static const double -zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ -pio2_1t = 6.07710050650619224932e-11; /* 0x3DD0B461, 0x1A626331 */ - - int32_t __ieee754_rem_pio2f(float x, float *y) -{ - double w,t,r,fn; - double tx[1],ty[2]; - float z; - int32_t e0,n,ix,hx; - - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - /* 33+53 bit pi is good enough for medium size */ - if(ix<=0x49490f80) { /* |x| ~<= 2^19*(pi/2), medium size */ - t = fabsf(x); - n = (int32_t) (t*invpio2+half); - fn = (double)n; - r = t-fn*pio2_1; - w = fn*pio2_1t; - y[0] = r-w; - y[1] = (r-y[0])-w; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - else return n; - } - /* - * all other (large) arguments - */ - if(ix>=0x7f800000) { /* x is inf or NaN */ - y[0]=y[1]=x-x; return 0; - } - /* set z = scalbn(|x|,ilogb(|x|)-23) */ - e0 = (ix>>23)-150; /* e0 = ilogb(|x|)-23; */ - SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23))); - tx[0] = z; - n = __kernel_rem_pio2(tx,ty,e0,1,1,two_over_pi); - y[0] = ty[0]; - y[1] = ty[0] - y[0]; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - return n; -} diff --git a/libm/src/k_rem_pio2.c b/libm/src/k_rem_pio2.c deleted file mode 100644 index 7116f31..0000000 --- a/libm/src/k_rem_pio2.c +++ /dev/null @@ -1,304 +0,0 @@ - -/* @(#)k_rem_pio2.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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_rem_pio2.c,v 1.7 2005/02/04 18:26:06 das Exp $"; -#endif - -/* - * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2) - * double x[],y[]; int e0,nx,prec; int ipio2[]; - * - * __kernel_rem_pio2 return the last three digits of N with - * y = x - N*pi/2 - * so that |y| < pi/2. - * - * The method is to compute the integer (mod 8) and fraction parts of - * (2/pi)*x without doing the full multiplication. In general we - * skip the part of the product that are known to be a huge integer ( - * more accurately, = 0 mod 8 ). Thus the number of operations are - * independent of the exponent of the input. - * - * (2/pi) is represented by an array of 24-bit integers in ipio2[]. - * - * Input parameters: - * x[] The input value (must be positive) is broken into nx - * pieces of 24-bit integers in double precision format. - * x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 - * match x's up to 24 bits. - * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: - * e0 = ilogb(z)-23 - * z = scalbn(z,-e0) - * for i = 0,1,2 - * x[i] = floor(z) - * z = (z-x[i])*2**24 - * - * - * y[] ouput result in an array of double precision numbers. - * The dimension of y[] is: - * 24-bit precision 1 - * 53-bit precision 2 - * 64-bit precision 2 - * 113-bit precision 3 - * The actual value is the sum of them. Thus for 113-bit - * precison, one may have to do something like: - * - * long double t,w,r_head, r_tail; - * t = (long double)y[2] + (long double)y[1]; - * w = (long double)y[0]; - * r_head = t+w; - * r_tail = w - (r_head - t); - * - * e0 The exponent of x[0] - * - * nx dimension of x[] - * - * prec an integer indicating the precision: - * 0 24 bits (single) - * 1 53 bits (double) - * 2 64 bits (extended) - * 3 113 bits (quad) - * - * ipio2[] - * integer array, contains the (24*i)-th to (24*i+23)-th - * bit of 2/pi after binary point. The corresponding - * floating value is - * - * ipio2[i] * 2^(-24(i+1)). - * - * External function: - * double scalbn(), floor(); - * - * - * Here is the description of some local variables: - * - * jk jk+1 is the initial number of terms of ipio2[] needed - * in the computation. The recommended value is 2,3,4, - * 6 for single, double, extended,and quad. - * - * jz local integer variable indicating the number of - * terms of ipio2[] used. - * - * jx nx - 1 - * - * jv index for pointing to the suitable ipio2[] for the - * computation. In general, we want - * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 - * is an integer. Thus - * e0-3-24*jv >= 0 or (e0-3)/24 >= jv - * Hence jv = max(0,(e0-3)/24). - * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. - * - * q[] double array with integral value, representing the - * 24-bits chunk of the product of x and 2/pi. - * - * q0 the corresponding exponent of q[0]. Note that the - * exponent for q[i] would be q0-24*i. - * - * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. - * - * f[] ipio2[] in floating point - * - * iq[] integer array by breaking up q[] in 24-bits chunk. - * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] - * - * ih integer. If >0 it indicates q[] is >= 0.5, hence - * it also indicates the *sign* of the result. - * - */ - - -/* - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "math.h" -#include "math_private.h" - -static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ - -static const double PIo2[] = { - 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ - 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ - 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ - 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ - 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ - 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ - 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ - 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ -}; - -static const double -zero = 0.0, -one = 1.0, -two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ -twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ - - int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2) -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - double z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/24; if(jv<0) jv=0; - q0 = e0-24*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0;i<=jk;i++) { - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for(i=0,j=jz,z=q[jz];j>0;i++,j--) { - fw = (double)((int32_t)(twon24* z)); - iq[i] = (int32_t)(z-two24*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbn(z,q0); /* actual value of z */ - z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ - n = (int32_t) z; - z -= (double)n; - ih = 0; - if(q0>0) { /* need iq[jz-1] to determine n */ - i = (iq[jz-1]>>(24-q0)); n += i; - iq[jz-1] -= i<<(24-q0); - ih = iq[jz-1]>>(23-q0); - } - else if(q0==0) ih = iq[jz-1]>>23; - else if(z>=0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i<jz ;i++) { /* compute 1-q */ - j = iq[i]; - if(carry==0) { - if(j!=0) { - carry = 1; iq[i] = 0x1000000- j; - } - } else iq[i] = 0xffffff - j; - } - if(q0>0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7fffff; break; - case 2: - iq[jz-1] &= 0x3fffff; break; - } - } - if(ih==2) { - z = one - z; - if(carry!=0) z -= scalbn(one,q0); - } - } - - /* check if recomputation is needed */ - if(z==zero) { - j = 0; - for (i=jz-1;i>=jk;i--) j |= iq[i]; - if(j==0) { /* need recomputation */ - for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ - - for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (double) ipio2[jv+i]; - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if(z==0.0) { - jz -= 1; q0 -= 24; - while(iq[jz]==0) { jz--; q0-=24;} - } else { /* break z into 24-bit if necessary */ - z = scalbn(z,-q0); - if(z>=two24) { - fw = (double)((int32_t)(twon24*z)); - iq[jz] = (int32_t)(z-two24*fw); - jz += 1; q0 += 24; - iq[jz] = (int32_t) fw; - } else iq[jz] = (int32_t) z ; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbn(one,q0); - for(i=jz;i>=0;i--) { - q[i] = fw*(double)iq[i]; fw*=twon24; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz;i>=0;i--) { - for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - fw = fq[0]-fw; - for (i=1;i<=jz;i++) fw += fq[i]; - y[1] = (ih==0)? fw: -fw; - break; - case 3: /* painful */ - for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz;i>1;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; - if(ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} diff --git a/libm/src/k_rem_pio2f.c b/libm/src/k_rem_pio2f.c deleted file mode 100644 index 35c28f5..0000000 --- a/libm/src/k_rem_pio2f.c +++ /dev/null @@ -1,197 +0,0 @@ -/* k_rem_pio2f.c -- float version of k_rem_pio2.c - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_rem_pio2f.c,v 1.8 2005/10/11 07:56:05 bde Exp $"; -#endif - -#include "math.h" -#include "math_private.h" - -/* In the float version, the input parameter x contains 8 bit - integers, not 24 bit integers. 113 bit precision is not supported. */ - -static const int init_jk[] = {4,7,9}; /* initial value for jk */ - -static const float PIo2[] = { - 1.5703125000e+00, /* 0x3fc90000 */ - 4.5776367188e-04, /* 0x39f00000 */ - 2.5987625122e-05, /* 0x37da0000 */ - 7.5437128544e-08, /* 0x33a20000 */ - 6.0026650317e-11, /* 0x2e840000 */ - 7.3896444519e-13, /* 0x2b500000 */ - 5.3845816694e-15, /* 0x27c20000 */ - 5.6378512969e-18, /* 0x22d00000 */ - 8.3009228831e-20, /* 0x1fc40000 */ - 3.2756352257e-22, /* 0x1bc60000 */ - 6.3331015649e-25, /* 0x17440000 */ -}; - -static const float -zero = 0.0, -one = 1.0, -two8 = 2.5600000000e+02, /* 0x43800000 */ -twon8 = 3.9062500000e-03; /* 0x3b800000 */ - - int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const int32_t *ipio2) -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - float z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/8; if(jv<0) jv=0; - q0 = e0-8*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0;i<=jk;i++) { - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for(i=0,j=jz,z=q[jz];j>0;i++,j--) { - fw = (float)((int32_t)(twon8* z)); - iq[i] = (int32_t)(z-two8*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbnf(z,q0); /* actual value of z */ - z -= (float)8.0*floorf(z*(float)0.125); /* trim off integer >= 8 */ - n = (int32_t) z; - z -= (float)n; - ih = 0; - if(q0>0) { /* need iq[jz-1] to determine n */ - i = (iq[jz-1]>>(8-q0)); n += i; - iq[jz-1] -= i<<(8-q0); - ih = iq[jz-1]>>(7-q0); - } - else if(q0==0) ih = iq[jz-1]>>7; - else if(z>=(float)0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i<jz ;i++) { /* compute 1-q */ - j = iq[i]; - if(carry==0) { - if(j!=0) { - carry = 1; iq[i] = 0x100- j; - } - } else iq[i] = 0xff - j; - } - if(q0>0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7f; break; - case 2: - iq[jz-1] &= 0x3f; break; - } - } - if(ih==2) { - z = one - z; - if(carry!=0) z -= scalbnf(one,q0); - } - } - - /* check if recomputation is needed */ - if(z==zero) { - j = 0; - for (i=jz-1;i>=jk;i--) j |= iq[i]; - if(j==0) { /* need recomputation */ - for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ - - for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (float) ipio2[jv+i]; - for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if(z==(float)0.0) { - jz -= 1; q0 -= 8; - while(iq[jz]==0) { jz--; q0-=8;} - } else { /* break z into 8-bit if necessary */ - z = scalbnf(z,-q0); - if(z>=two8) { - fw = (float)((int32_t)(twon8*z)); - iq[jz] = (int32_t)(z-two8*fw); - jz += 1; q0 += 8; - iq[jz] = (int32_t) fw; - } else iq[jz] = (int32_t) z ; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbnf(one,q0); - for(i=jz;i>=0;i--) { - q[i] = fw*(float)iq[i]; fw*=twon8; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz;i>=0;i--) { - for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; - fw = *(volatile float *)&fw; /* clip any extra precision */ - y[0] = (ih==0)? fw: -fw; - fw = fq[0]-fw; - for (i=1;i<=jz;i++) fw += fq[i]; - y[1] = (ih==0)? fw: -fw; - break; - case 3: /* painful */ - for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz;i>1;i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; - if(ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} diff --git a/libm/src/math_private.h b/libm/src/math_private.h deleted file mode 100644 index 5f6e088..0000000 --- a/libm/src/math_private.h +++ /dev/null @@ -1,273 +0,0 @@ -/* - * ==================================================== - * 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. - * ==================================================== - */ - -/* - * from: @(#)fdlibm.h 5.1 93/09/24 - * $FreeBSD: src/lib/msun/src/math_private.h,v 1.20 2005/11/28 04:58:57 bde Exp $ - */ - -#ifndef _MATH_PRIVATE_H_ -#define _MATH_PRIVATE_H_ - -#include <sys/types.h> -#include <endian.h> - -/* - * The original fdlibm code used statements like: - * n0 = ((*(int*)&one)>>29)^1; * index of high word * - * ix0 = *(n0+(int*)&x); * high word of x * - * ix1 = *((1-n0)+(int*)&x); * low word of x * - * to dig two 32 bit words out of the 64 bit IEEE floating point - * value. That is non-ANSI, and, moreover, the gcc instruction - * scheduler gets it wrong. We instead use the following macros. - * Unlike the original code, we determine the endianness at compile - * time, not at run time; I don't see much benefit to selecting - * endianness at run time. - */ - -/* - * A union which permits us to convert between a double and two 32 bit - * ints. - */ - -#if (__BYTE_ORDER == __BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__)) - -typedef union -{ - double value; - struct - { - u_int32_t msw; - u_int32_t lsw; - } parts; -} ieee_double_shape_type; - -#endif - -#if __BYTE_ORDER == __LITTLE_ENDIAN && !(defined(__arm__) && !defined(__VFP_FP__)) - -typedef union -{ - double value; - struct - { - u_int32_t lsw; - u_int32_t msw; - } parts; -} ieee_double_shape_type; - -#endif - -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(ix0,ix1,d) \ -do { \ - ieee_double_shape_type ew_u; \ - ew_u.value = (d); \ - (ix0) = ew_u.parts.msw; \ - (ix1) = ew_u.parts.lsw; \ -} while (0) - -/* Get the more significant 32 bit int from a double. */ - -#define GET_HIGH_WORD(i,d) \ -do { \ - ieee_double_shape_type gh_u; \ - gh_u.value = (d); \ - (i) = gh_u.parts.msw; \ -} while (0) - -/* Get the less significant 32 bit int from a double. */ - -#define GET_LOW_WORD(i,d) \ -do { \ - ieee_double_shape_type gl_u; \ - gl_u.value = (d); \ - (i) = gl_u.parts.lsw; \ -} while (0) - -/* Set a double from two 32 bit ints. */ - -#define INSERT_WORDS(d,ix0,ix1) \ -do { \ - ieee_double_shape_type iw_u; \ - iw_u.parts.msw = (ix0); \ - iw_u.parts.lsw = (ix1); \ - (d) = iw_u.value; \ -} while (0) - -/* Set the more significant 32 bits of a double from an int. */ - -#define SET_HIGH_WORD(d,v) \ -do { \ - ieee_double_shape_type sh_u; \ - sh_u.value = (d); \ - sh_u.parts.msw = (v); \ - (d) = sh_u.value; \ -} while (0) - -/* Set the less significant 32 bits of a double from an int. */ - -#define SET_LOW_WORD(d,v) \ -do { \ - ieee_double_shape_type sl_u; \ - sl_u.value = (d); \ - sl_u.parts.lsw = (v); \ - (d) = sl_u.value; \ -} while (0) - -/* - * A union which permits us to convert between a float and a 32 bit - * int. - */ - -typedef union -{ - float value; - /* FIXME: Assumes 32 bit int. */ - unsigned int word; -} ieee_float_shape_type; - -/* Get a 32 bit int from a float. */ - -#define GET_FLOAT_WORD(i,d) \ -do { \ - ieee_float_shape_type gf_u; \ - gf_u.value = (d); \ - (i) = gf_u.word; \ -} while (0) - -/* Set a float from a 32 bit int. */ - -#define SET_FLOAT_WORD(d,i) \ -do { \ - ieee_float_shape_type sf_u; \ - sf_u.word = (i); \ - (d) = sf_u.value; \ -} while (0) - -#ifdef _COMPLEX_H -/* - * Inline functions that can be used to construct complex values. - * - * The C99 standard intends x+I*y to be used for this, but x+I*y is - * currently unusable in general since gcc introduces many overflow, - * underflow, sign and efficiency bugs by rewriting I*y as - * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product. - * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted - * to -0.0+I*0.0. - */ -static __inline float complex -cpackf(float x, float y) -{ - float complex z; - - __real__ z = x; - __imag__ z = y; - return (z); -} - -static __inline double complex -cpack(double x, double y) -{ - double complex z; - - __real__ z = x; - __imag__ z = y; - return (z); -} - -static __inline long double complex -cpackl(long double x, long double y) -{ - long double complex z; - - __real__ z = x; - __imag__ z = y; - return (z); -} -#endif /* _COMPLEX_H */ - -/* - * ieee style elementary functions - * - * We rename functions here to improve other sources' diffability - * against fdlibm. - */ -#define __ieee754_sqrt sqrt -#define __ieee754_acos acos -#define __ieee754_acosh acosh -#define __ieee754_log log -#define __ieee754_atanh atanh -#define __ieee754_asin asin -#define __ieee754_atan2 atan2 -#define __ieee754_exp exp -#define __ieee754_cosh cosh -#define __ieee754_fmod fmod -#define __ieee754_pow pow -#define __ieee754_lgamma lgamma -#define __ieee754_gamma gamma -#define __ieee754_lgamma_r lgamma_r -#define __ieee754_gamma_r gamma_r -#define __ieee754_log10 log10 -#define __ieee754_sinh sinh -#define __ieee754_hypot hypot -#define __ieee754_j0 j0 -#define __ieee754_j1 j1 -#define __ieee754_y0 y0 -#define __ieee754_y1 y1 -#define __ieee754_jn jn -#define __ieee754_yn yn -#define __ieee754_remainder remainder -#define __ieee754_scalb scalb -#define __ieee754_sqrtf sqrtf -#define __ieee754_acosf acosf -#define __ieee754_acoshf acoshf -#define __ieee754_logf logf -#define __ieee754_atanhf atanhf -#define __ieee754_asinf asinf -#define __ieee754_atan2f atan2f -#define __ieee754_expf expf -#define __ieee754_coshf coshf -#define __ieee754_fmodf fmodf -#define __ieee754_powf powf -#define __ieee754_lgammaf lgammaf -#define __ieee754_gammaf gammaf -#define __ieee754_lgammaf_r lgammaf_r -#define __ieee754_gammaf_r gammaf_r -#define __ieee754_log10f log10f -#define __ieee754_sinhf sinhf -#define __ieee754_hypotf hypotf -#define __ieee754_j0f j0f -#define __ieee754_j1f j1f -#define __ieee754_y0f y0f -#define __ieee754_y1f y1f -#define __ieee754_jnf jnf -#define __ieee754_ynf ynf -#define __ieee754_remainderf remainderf -#define __ieee754_scalbf scalbf -#define __ieee754_ldexpf ldexpf - -/* fdlibm kernel function */ -int __ieee754_rem_pio2(double,double*); -double __kernel_sin(double,double,int); -double __kernel_cos(double,double); -double __kernel_tan(double,double,int); -int __kernel_rem_pio2(double*,double*,int,int,int,const int*); - -/* float versions of fdlibm kernel functions */ -int __ieee754_rem_pio2f(float,float*); -float __kernel_sindf(double); -float __kernel_cosdf(double); -float __kernel_tandf(double,int); -int __kernel_rem_pio2f(float*,float*,int,int,int,const int*); - -#endif /* !_MATH_PRIVATE_H_ */ diff --git a/libm/src/s_cbrt.c b/libm/src/s_cbrt.c deleted file mode 100644 index b600677..0000000 --- a/libm/src/s_cbrt.c +++ /dev/null @@ -1,92 +0,0 @@ -/* @(#)s_cbrt.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cbrt.c,v 1.10 2005/12/13 20:17:23 bde Exp $"; -#endif - -#include "math.h" -#include "math_private.h" - -/* cbrt(x) - * Return cube root of x - */ -static const u_int32_t - B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */ - B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */ - -static const double -C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */ -D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */ -E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */ -F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */ -G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */ - -double -cbrt(double x) -{ - int32_t hx; - double r,s,t=0.0,w; - u_int32_t sign; - u_int32_t high,low; - - GET_HIGH_WORD(hx,x); - sign=hx&0x80000000; /* sign= sign(x) */ - hx ^=sign; - if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ - GET_LOW_WORD(low,x); - if((hx|low)==0) - return(x); /* cbrt(0) is itself */ - - /* - * Rough cbrt to 5 bits: - * cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3) - * where e is integral and >= 0, m is real and in [0, 1), and "/" and - * "%" are integer division and modulus with rounding towards minus - * infinity. The RHS is always >= the LHS and has a maximum relative - * error of about 1 in 16. Adding a bias of -0.03306235651 to the - * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE - * floating point representation, for finite positive normal values, - * ordinary integer divison of the value in bits magically gives - * almost exactly the RHS of the above provided we first subtract the - * exponent bias (1023 for doubles) and later add it back. We do the - * subtraction virtually to keep e >= 0 so that ordinary integer - * division rounds towards minus infinity; this is also efficient. - */ - if(hx<0x00100000) { /* subnormal number */ - SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */ - t*=x; - GET_HIGH_WORD(high,t); - SET_HIGH_WORD(t,sign|((high&0x7fffffff)/3+B2)); - } else - SET_HIGH_WORD(t,sign|(hx/3+B1)); - - /* new cbrt to 23 bits; may be implemented in single precision */ - r=t*t/x; - s=C+r*t; - t*=G+F/(s+E+D/s); - - /* chop t to 20 bits and make it larger in magnitude than cbrt(x) */ - GET_HIGH_WORD(high,t); - INSERT_WORDS(t,high+0x00000001,0); - - /* one step Newton iteration to 53 bits with error less than 0.667 ulps */ - s=t*t; /* t*t is exact */ - r=x/s; - w=t+t; - r=(r-t)/(w+r); /* r-t is exact */ - t=t+t*r; - - return(t); -} diff --git a/libm/src/s_erff.c b/libm/src/s_erff.c deleted file mode 100644 index 24e053c..0000000 --- a/libm/src/s_erff.c +++ /dev/null @@ -1,211 +0,0 @@ -/* s_erff.c -- float version of s_erf.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - -/* - * ==================================================== - * 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. - * ==================================================== - */ - -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_erff.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif - -#include "math.h" -#include "math_private.h" - -static const float -tiny = 1e-30, -half= 5.0000000000e-01, /* 0x3F000000 */ -one = 1.0000000000e+00, /* 0x3F800000 */ -two = 2.0000000000e+00, /* 0x40000000 */ - /* c = (subfloat)0.84506291151 */ -erx = 8.4506291151e-01, /* 0x3f58560b */ -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -efx = 1.2837916613e-01, /* 0x3e0375d4 */ -efx8= 1.0270333290e+00, /* 0x3f8375d4 */ -pp0 = 1.2837916613e-01, /* 0x3e0375d4 */ -pp1 = -3.2504209876e-01, /* 0xbea66beb */ -pp2 = -2.8481749818e-02, /* 0xbce9528f */ -pp3 = -5.7702702470e-03, /* 0xbbbd1489 */ -pp4 = -2.3763017452e-05, /* 0xb7c756b1 */ -qq1 = 3.9791721106e-01, /* 0x3ecbbbce */ -qq2 = 6.5022252500e-02, /* 0x3d852a63 */ -qq3 = 5.0813062117e-03, /* 0x3ba68116 */ -qq4 = 1.3249473704e-04, /* 0x390aee49 */ -qq5 = -3.9602282413e-06, /* 0xb684e21a */ -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */ -pa1 = 4.1485610604e-01, /* 0x3ed46805 */ -pa2 = -3.7220788002e-01, /* 0xbebe9208 */ -pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */ -pa4 = -1.1089469492e-01, /* 0xbde31cc2 */ -pa5 = 3.5478305072e-02, /* 0x3d1151b3 */ -pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */ -qa1 = 1.0642088205e-01, /* 0x3dd9f331 */ -qa2 = 5.4039794207e-01, /* 0x3f0a5785 */ -qa3 = 7.1828655899e-02, /* 0x3d931ae7 */ -qa4 = 1.2617121637e-01, /* 0x3e013307 */ -qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */ -qa6 = 1.1984500103e-02, /* 0x3c445aa3 */ -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -ra0 = -9.8649440333e-03, /* 0xbc21a093 */ -ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */ -ra2 = -1.0558626175e+01, /* 0xc128f022 */ -ra3 = -6.2375331879e+01, /* 0xc2798057 */ -ra4 = -1.6239666748e+02, /* 0xc322658c */ -ra5 = -1.8460508728e+02, /* 0xc3389ae7 */ -ra6 = -8.1287437439e+01, /* 0xc2a2932b */ -ra7 = -9.8143291473e+00, /* 0xc11d077e */ -sa1 = 1.9651271820e+01, /* 0x419d35ce */ -sa2 = 1.3765776062e+02, /* 0x4309a863 */ -sa3 = 4.3456588745e+02, /* 0x43d9486f */ -sa4 = 6.4538726807e+02, /* 0x442158c9 */ -sa5 = 4.2900814819e+02, /* 0x43d6810b */ -sa6 = 1.0863500214e+02, /* 0x42d9451f */ -sa7 = 6.5702495575e+00, /* 0x40d23f7c */ -sa8 = -6.0424413532e-02, /* 0xbd777f97 */ -/* - * Coefficients for approximation to erfc in [1/.35,28] - */ -rb0 = -9.8649431020e-03, /* 0xbc21a092 */ -rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */ -rb2 = -1.7757955551e+01, /* 0xc18e104b */ -rb3 = -1.6063638306e+02, /* 0xc320a2ea */ -rb4 = -6.3756646729e+02, /* 0xc41f6441 */ -rb5 = -1.0250950928e+03, /* 0xc480230b */ -rb6 = -4.8351919556e+02, /* 0xc3f1c275 */ -sb1 = 3.0338060379e+01, /* 0x41f2b459 */ -sb2 = 3.2579251099e+02, /* 0x43a2e571 */ -sb3 = 1.5367296143e+03, /* 0x44c01759 */ -sb4 = 3.1998581543e+03, /* 0x4547fdbb */ -sb5 = 2.5530502930e+03, /* 0x451f90ce */ -sb6 = 4.7452853394e+02, /* 0x43ed43a7 */ -sb7 = -2.2440952301e+01; /* 0xc1b38712 */ - -float -erff(float x) -{ - int32_t hx,ix,i; - float R,S,P,Q,s,y,z,r; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7f800000) { /* erf(nan)=nan */ - i = ((u_int32_t)hx>>31)<<1; - return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */ - } - - if(ix < 0x3f580000) { /* |x|<0.84375 */ - if(ix < 0x31800000) { /* |x|<2**-28 */ - if (ix < 0x04000000) - /*avoid underflow */ - return (float)0.125*((float)8.0*x+efx8*x); - return x + efx*x; - } - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - return x + x*y; - } - if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ - s = fabsf(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) return erx + P/Q; else return -erx - P/Q; - } - if (ix >= 0x40c00000) { /* inf>|x|>=6 */ - if(hx>=0) return one-tiny; else return tiny-one; - } - x = fabsf(x); - s = one/(x*x); - if(ix< 0x4036DB6E) { /* |x| < 1/0.35 */ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/0.35 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(z,ix&0xfffff000); - r = __ieee754_expf(-z*z-(float)0.5625)*__ieee754_expf((z-x)*(z+x)+R/S); - if(hx>=0) return one-r/x; else return r/x-one; -} - -float -erfcf(float x) -{ - int32_t hx,ix; - float R,S,P,Q,s,y,z,r; - GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; - if(ix>=0x7f800000) { /* erfc(nan)=nan */ - /* erfc(+-inf)=0,2 */ - return (float)(((u_int32_t)hx>>31)<<1)+one/x; - } - - if(ix < 0x3f580000) { /* |x|<0.84375 */ - if(ix < 0x23800000) /* |x|<2**-56 */ - return one-x; - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - if(hx < 0x3e800000) { /* x<1/4 */ - return one-(x+x*y); - } else { - r = x*y; - r += (x-half); - return half - r ; - } - } - if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ - s = fabsf(x)-one; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - if(hx>=0) { - z = one-erx; return z - P/Q; - } else { - z = erx+P/Q; return one+z; - } - } - if (ix < 0x41e00000) { /* |x|<28 */ - x = fabsf(x); - s = one/(x*x); - if(ix< 0x4036DB6D) { /* |x| < 1/.35 ~ 2.857143*/ - R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/.35 ~ 2.857143 */ - if(hx<0&&ix>=0x40c00000) return two-tiny;/* x < -6 */ - R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(z,ix&0xfffff000); - r = __ieee754_expf(-z*z-(float)0.5625)* - __ieee754_expf((z-x)*(z+x)+R/S); - if(hx>0) return r/x; else return two-r/x; - } else { - if(hx>0) return tiny*tiny; else return two-tiny; - } -} diff --git a/libm/src/s_fma.c b/libm/src/s_fma.c deleted file mode 100644 index 1fcc26c..0000000 --- a/libm/src/s_fma.c +++ /dev/null @@ -1,202 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> - * 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 <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fma.c,v 1.4 2005/03/18 02:27:59 das Exp $"); */ - -#include <fenv.h> -#include <float.h> -#include <math.h> - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * We use scaling to avoid overflow/underflow, along with the - * canonical precision-doubling technique adapted from: - * - * Dekker, T. A Floating-Point Technique for Extending the - * Available Precision. Numer. Math. 18, 224-242 (1971). - * - * This algorithm is sensitive to the rounding precision. FPUs such - * as the i387 must be set in double-precision mode if variables are - * to be stored in FP registers in order to avoid incorrect results. - * This is the default on FreeBSD, but not on many other systems. - * - * 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; - int oround; - int ex, ey, ez; - int spread; - - if (z == 0.0) - return (x * y); - if (x == 0.0 || y == 0.0) - return (x * y + z); - - /* Results of frexp() are undefined for these cases. */ - if (!isfinite(x) || !isfinite(y) || !isfinite(z)) - return (x * y + z); - - xs = frexp(x, &ex); - ys = frexp(y, &ey); - zs = frexp(z, &ez); - oround = fegetround(); - spread = ex + ey - ez; - - /* - * If x * y and z are many orders of magnitude apart, the scaling - * 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)) - feraiseexcept(FE_UNDERFLOW); - switch (oround) { - case FE_TONEAREST: - return (z); - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (z); - else - return (nextafter(z, 0)); - case FE_DOWNWARD: - if (x > 0.0 ^ y < 0.0) - return (z); - else - return (nextafter(z, -INFINITY)); - default: /* FE_UPWARD */ - if (x > 0.0 ^ y < 0.0) - return (nextafter(z, INFINITY)); - else - return (z); - } - } - - /* - * 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; - - spread = ex + ey; - if (spread + ilogb(r) > -1023) { - fesetround(oround); - r = r + rr; - } else { - /* - * The result is subnormal, so we round before scaling to - * avoid double rounding. - */ - 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; - } - return (ldexp(r, 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); -#endif diff --git a/libm/src/s_fmal.c b/libm/src/s_fmal.c deleted file mode 100644 index f1736fa..0000000 --- a/libm/src/s_fmal.c +++ /dev/null @@ -1,182 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> - * 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 <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmal.c,v 1.2 2005/03/18 02:27:59 das Exp $"); */ - -#include <fenv.h> -#include <float.h> -#include <math.h> - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * We use scaling to avoid overflow/underflow, along with the - * canonical precision-doubling technique adapted from: - * - * Dekker, T. A Floating-Point Technique for Extending the - * Available Precision. Numer. Math. 18, 224-242 (1971). - */ -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; - int oround; - int ex, ey, ez; - int spread; - - if (z == 0.0) - return (x * y); - if (x == 0.0 || y == 0.0) - return (x * y + z); - - /* Results of frexp() are undefined for these cases. */ - if (!isfinite(x) || !isfinite(y) || !isfinite(z)) - return (x * y + z); - - xs = frexpl(x, &ex); - ys = frexpl(y, &ey); - zs = frexpl(z, &ez); - oround = fegetround(); - spread = ex + ey - ez; - - /* - * If x * y and z are many orders of magnitude apart, the scaling - * 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)) - feraiseexcept(FE_UNDERFLOW); - switch (oround) { - case FE_TONEAREST: - return (z); - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (z); - else - return (nextafterl(z, 0)); - case FE_DOWNWARD: - if (x > 0.0 ^ y < 0.0) - return (z); - else - return (nextafterl(z, -INFINITY)); - default: /* FE_UPWARD */ - if (x > 0.0 ^ y < 0.0) - return (nextafterl(z, INFINITY)); - else - return (z); - } - } - - /* - * 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; - - spread = ex + ey; - if (spread + ilogbl(r) > -16383) { - fesetround(oround); - r = r + rr; - } else { - /* - * The result is subnormal, so we round before scaling to - * avoid double rounding. - */ - 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; - } - return (ldexpl(r, spread)); -} diff --git a/libm/src/s_isnan.c b/libm/src/s_isnan.c deleted file mode 100644 index f76352d..0000000 --- a/libm/src/s_isnan.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> - * 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/src/s_isnan.c,v 1.8 2004/08/05 01:46:11 das Exp $ - */ - -#include <math.h> - -#include "fpmath.h" - -/* Provided by libc */ -#if 1 -int -(isnan)(double d) -{ - union IEEEd2bits u; - - u.d = d; - return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); -} -#endif - -int -isnanf(float f) -{ - union IEEEf2bits u; - - u.f = f; - return (u.bits.exp == 255 && u.bits.man != 0); -} - -int -__isnanl(long double e) -{ - union IEEEl2bits u; - - u.e = e; - mask_nbit_l(u); - return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0)); -} diff --git a/libm/src/s_isnormal.c b/libm/src/s_isnormal.c deleted file mode 100644 index 1345dba..0000000 --- a/libm/src/s_isnormal.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> - * 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/src/s_isnormal.c,v 1.1 2004/07/09 03:32:39 das Exp $ - */ - -#include <math.h> - -#include "fpmath.h" - -int -__isnormal(double d) -{ - union IEEEd2bits u; - - u.d = d; - return (u.bits.exp != 0 && u.bits.exp != 2047); -} - -int -__isnormalf(float f) -{ - union IEEEf2bits u; - - u.f = f; - return (u.bits.exp != 0 && u.bits.exp != 255); -} - -int -__isnormall(long double e) -{ - union IEEEl2bits u; - - u.e = e; - return (u.bits.exp != 0 && u.bits.exp != 32767); -} diff --git a/libm/src/s_llround.c b/libm/src/s_llround.c deleted file mode 100644 index 28ab13e..0000000 --- a/libm/src/s_llround.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <sys/cdefs.h> -/* __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 -#define dtype long long -#define DTYPE_MIN LONGLONG_MIN -#define DTYPE_MAX LONGLONG_MAX -#define fn llround - -#include "s_lround.c" diff --git a/libm/src/s_llroundf.c b/libm/src/s_llroundf.c deleted file mode 100644 index 3dd6905..0000000 --- a/libm/src/s_llroundf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <sys/cdefs.h> -/* __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 -#define dtype long long -#define DTYPE_MIN LONGLONG_MIN -#define DTYPE_MAX LONGLONG_MAX -#define fn llroundf - -#include "s_lround.c" diff --git a/libm/src/s_llroundl.c b/libm/src/s_llroundl.c deleted file mode 100644 index 89bae54..0000000 --- a/libm/src/s_llroundl.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <sys/cdefs.h> -/* __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 -#define dtype long long -#define DTYPE_MIN LONGLONG_MIN -#define DTYPE_MAX LONGLONG_MAX -#define fn llroundl - -#include "s_lround.c" diff --git a/libm/src/w_cabs.c b/libm/src/w_cabs.c deleted file mode 100644 index 577e5e0..0000000 --- a/libm/src/w_cabs.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * cabs() wrapper for hypot(). - * - * Written by J.T. Conklin, <jtc@wimsey.com> - * Placed into the Public Domain, 1994. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD: src/lib/msun/src/w_cabs.c,v 1.4 2001/06/13 15:16:30 ru Exp $"; -#endif /* not lint */ - -#include <complex.h> -#include <math.h> - -double -cabs(z) - double complex z; -{ - return hypot(creal(z), cimag(z)); -} - -double -z_abs(z) - double complex *z; -{ - return hypot(creal(*z), cimag(*z)); -} diff --git a/libm/bsdsrc/b_exp.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c index 107bc89..4400992 100644 --- a/libm/bsdsrc/b_exp.c +++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c @@ -31,11 +31,9 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)exp.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ +/* @(#)exp.c 8.1 (Berkeley) 6/4/93 */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.7 2004/12/16 20:40:37 das Exp $"); */ +__FBSDID("$FreeBSD$"); /* EXP(X) diff --git a/libm/bsdsrc/b_log.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c index d4e5f65..5a4b964 100644 --- a/libm/bsdsrc/b_log.c +++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c @@ -31,11 +31,9 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)log.c 8.2 (Berkeley) 11/30/93"; -#endif /* not lint */ +/* @(#)log.c 8.2 (Berkeley) 11/30/93 */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_log.c,v 1.8 2005/09/19 11:28:19 bde Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> #include <errno.h> diff --git a/libm/bsdsrc/b_tgamma.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c index ff6c5ac..1d0af44 100644 --- a/libm/bsdsrc/b_tgamma.c +++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c @@ -31,11 +31,9 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)gamma.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ +/* @(#)gamma.c 8.1 (Berkeley) 6/4/93 */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_tgamma.c,v 1.7 2005/09/19 11:28:19 bde Exp $"); */ +__FBSDID("$FreeBSD$"); /* * This code by P. McIlroy, Oct 1992; @@ -44,14 +42,12 @@ static char sccsid[] = "@(#)gamma.c 8.1 (Berkeley) 6/4/93"; * acknowledged. */ -//#include <math.h> -#include "../include/math.h" +#include <math.h> #include "mathimpl.h" -#include <errno.h> /* METHOD: * x < 0: Use reflection formula, G(x) = pi/(sin(pi*x)*x*G(x)) - * At negative integers, return +Inf, and set errno. + * At negative integers, return NaN and raise invalid. * * x < 6.5: * Use argument reduction G(x+1) = xG(x) to reach the @@ -68,11 +64,15 @@ static char sccsid[] = "@(#)gamma.c 8.1 (Berkeley) 6/4/93"; * avoid premature round-off. * * Special values: - * non-positive integer: Set overflow trap; return +Inf; - * x > 171.63: Set overflow trap; return +Inf; - * NaN: Set invalid trap; return NaN + * -Inf: return NaN and raise invalid; + * negative integer: return NaN and raise invalid; + * other x ~< 177.79: return +-0 and raise underflow; + * +-0: return +-Inf and raise divide-by-zero; + * finite x ~> 171.63: return +Inf and raise overflow; + * +Inf: return +Inf; + * NaN: return NaN. * - * Accuracy: Gamma(x) is accurate to within + * Accuracy: tgamma(x) is accurate to within * x > 0: error provably < 0.9ulp. * Maximum observed in 1,000,000 trials was .87ulp. * x < 0: @@ -133,7 +133,7 @@ tgamma(x) if (x >= 6) { if(x > 171.63) - return(one/zero); + return (x / zero); u = large_gam(x); return(__exp__D(u.a, u.b)); } else if (x >= 1.0 + LEFT + x0) @@ -141,12 +141,11 @@ tgamma(x) else if (x > 1.e-17) return (smaller_gam(x)); else if (x > -1.e-17) { - if (x == 0.0) - return (one/x); - one+1e-20; /* Raise inexact flag. */ + if (x != 0.0) + u.a = one - tiny; /* raise inexact */ return (one/x); } else if (!finite(x)) - return (x*x); /* x = NaN, -Inf */ + return (x - x); /* x is NaN or -Inf */ else return (neg_gam(x)); } @@ -280,11 +279,13 @@ neg_gam(x) struct Double lg, lsine; double y, z; - y = floor(x + .5); + y = ceil(x); if (y == x) /* Negative integer. */ - return (one/zero); - z = fabs(x - y); - y = .5*ceil(x); + return ((x - x) / zero); + z = y - x; + if (z > 0.5) + z = one - z; + y = 0.5 * y; if (y == ceil(y)) sgn = -1; if (z < .25) diff --git a/libm/bsdsrc/mathimpl.h b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h index 2a3b246..04a4b6e 100644 --- a/libm/bsdsrc/mathimpl.h +++ b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)mathimpl.h 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/msun/bsdsrc/mathimpl.h,v 1.7 2005/11/18 05:03:12 bde Exp $ + * $FreeBSD$ */ #ifndef _MATHIMPL_H_ diff --git a/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h b/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h new file mode 100644 index 0000000..078d0c3 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/e_rem_pio2l.h @@ -0,0 +1,140 @@ +/* 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* ld128 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 <float.h> + +#include "math.h" +#include "math_private.h" +#include "fpmath.h" + +#define BIAS (LDBL_MAX_EXP - 1) + +/* + * XXX need to verify that nonzero integer multiples of pi/2 within the + * range get no closer to a long double than 2**-140, or that + * ilogb(x) + ilogb(min_delta) < 45 - -140. + */ +/* + * invpio2: 113 bits of 2/pi + * pio2_1: first 68 bits of pi/2 + * pio2_1t: pi/2 - pio2_1 + * pio2_2: second 68 bits of pi/2 + * pio2_2t: pi/2 - (pio2_1+pio2_2) + * pio2_3: third 68 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 */ + +static const long double +invpio2 = 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 */ +pio2_1 = 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 */ +pio2_1t = 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 */ +pio2_2 = 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 */ +pio2_2t = 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 */ +pio2_3 = 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 */ +pio2_3t = -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */ + +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[5],ty[3]; + int64_t n; + int e0,ex,i,j,nx; + int16_t expsign; + + u.e = x; + expsign = u.xbits.expsign; + ex = expsign & 0x7fff; + if (ex < BIAS + 45 || ex == BIAS + 45 && + u.bits.manh < 0x921fb54442d1LL) { + /* |x| ~< 2^45*(pi/2), medium size */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + fn = x*invpio2+0x1.8p112; + fn = fn-0x1.8p112; +#ifdef HAVE_EFFICIENT_I64RINT + n = i64rint(fn); +#else + n = fn; +#endif + r = x-fn*pio2_1; + w = fn*pio2_1t; /* 1st round good to 180 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>51) { /* 2nd iteration needed, good to 248 */ + 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>119) { /* 3rd iteration need, 316 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<4;i++) { + tx[i] = (double)((int32_t)(z)); + z = (z-tx[i])*two24; + } + tx[4] = z; + nx = 5; + while(tx[nx-1]==zero) nx--; /* skip zero term */ + n = __kernel_rem_pio2(tx,ty,e0,nx,3); + t = (long double)ty[2] + ty[1]; + r = t + ty[0]; + w = ty[0] - (r - t); + if(expsign<0) {y[0] = -r; y[1] = -w; return -n;} + y[0] = r; y[1] = w; return n; +} diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.c b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c new file mode 100644 index 0000000..df67d16 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.c @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "invtrig.h" + +/* + * asinl() and acosl() + */ +const long double +pS0 = 1.66666666666666666666666666666700314e-01L, +pS1 = -7.32816946414566252574527475428622708e-01L, +pS2 = 1.34215708714992334609030036562143589e+00L, +pS3 = -1.32483151677116409805070261790752040e+00L, +pS4 = 7.61206183613632558824485341162121989e-01L, +pS5 = -2.56165783329023486777386833928147375e-01L, +pS6 = 4.80718586374448793411019434585413855e-02L, +pS7 = -4.42523267167024279410230886239774718e-03L, +pS8 = 1.44551535183911458253205638280410064e-04L, +pS9 = -2.10558957916600254061591040482706179e-07L, +qS1 = -4.84690167848739751544716485245697428e+00L, +qS2 = 9.96619113536172610135016921140206980e+00L, +qS3 = -1.13177895428973036660836798461641458e+01L, +qS4 = 7.74004374389488266169304117714658761e+00L, +qS5 = -3.25871986053534084709023539900339905e+00L, +qS6 = 8.27830318881232209752469022352928864e-01L, +qS7 = -1.18768052702942805423330715206348004e-01L, +qS8 = 8.32600764660522313269101537926539470e-03L, +qS9 = -1.99407384882605586705979504567947007e-04L; + +/* + * atanl() + */ +const long double atanhi[] = { + 4.63647609000806116214256231461214397e-01L, + 7.85398163397448309615660845819875699e-01L, + 9.82793723247329067985710611014666038e-01L, + 1.57079632679489661923132169163975140e+00L, +}; + +const long double atanlo[] = { + 4.89509642257333492668618435220297706e-36L, + 2.16795253253094525619926100651083806e-35L, + -2.31288434538183565909319952098066272e-35L, + 4.33590506506189051239852201302167613e-35L, +}; + +const long double aT[] = { + 3.33333333333333333333333333333333125e-01L, + -1.99999999999999999999999999999180430e-01L, + 1.42857142857142857142857142125269827e-01L, + -1.11111111111111111111110834490810169e-01L, + 9.09090909090909090908522355708623681e-02L, + -7.69230769230769230696553844935357021e-02L, + 6.66666666666666660390096773046256096e-02L, + -5.88235294117646671706582985209643694e-02L, + 5.26315789473666478515847092020327506e-02L, + -4.76190476189855517021024424991436144e-02L, + 4.34782608678695085948531993458097026e-02L, + -3.99999999632663469330634215991142368e-02L, + 3.70370363987423702891250829918659723e-02L, + -3.44827496515048090726669907612335954e-02L, + 3.22579620681420149871973710852268528e-02L, + -3.03020767654269261041647570626778067e-02L, + 2.85641979882534783223403715930946138e-02L, + -2.69824879726738568189929461383741323e-02L, + 2.54194698498808542954187110873675769e-02L, + -2.35083879708189059926183138130183215e-02L, + 2.04832358998165364349957325067131428e-02L, + -1.54489555488544397858507248612362957e-02L, + 8.64492360989278761493037861575248038e-03L, + -2.58521121597609872727919154569765469e-03L, +}; + +const long double pi_lo = 8.67181013012378102479704402604335225e-35L; diff --git a/libm/upstream-freebsd/lib/msun/ld128/invtrig.h b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h new file mode 100644 index 0000000..12f598b --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/invtrig.h @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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$ + */ + +#include <float.h> + +#include "fpmath.h" + +#define BIAS (LDBL_MAX_EXP - 1) +#define MANH_SIZE (LDBL_MANH_SIZE + 1) + +/* Approximation thresholds. */ +#define ASIN_LINEAR (BIAS - 56) /* 2**-56 */ +#define ACOS_CONST (BIAS - 113) /* 2**-113 */ +#define ATAN_CONST (BIAS + 113) /* 2**113 */ +#define ATAN_LINEAR (BIAS - 56) /* 2**-56 */ + +/* 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 pS7 _ItL_pS7 +#define pS8 _ItL_pS8 +#define pS9 _ItL_pS9 +#define qS1 _ItL_qS1 +#define qS2 _ItL_qS2 +#define qS3 _ItL_qS3 +#define qS4 _ItL_qS4 +#define qS5 _ItL_qS5 +#define qS6 _ItL_qS6 +#define qS7 _ItL_qS7 +#define qS8 _ItL_qS8 +#define qS9 _ItL_qS9 +#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] + +/* Constants shared by the long double inverse trig functions. */ +extern const long double pS0, pS1, pS2, pS3, pS4, pS5, pS6, pS7, pS8, pS9; +extern const long double qS1, qS2, qS3, qS4, qS5, qS6, qS7, qS8, qS9; +extern const long double atanhi[], atanlo[], aT[]; +extern const long double pi_lo; + +static inline long double +P(long double x) +{ + + return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \ + (pS4 + x * (pS5 + x * (pS6 + x * (pS7 + x * (pS8 + x * \ + pS9)))))))))); +} + +static inline long double +Q(long double x) +{ + + return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * \ + (qS5 + x * (qS6 + x * (qS7 + x * (qS8 + x * qS9))))))))); +} + +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] + x * (aT[14] + x * \ + (aT[16] + x * (aT[18] + x * (aT[20] + x * aT[22]))))))))))); +} + +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] + x * (aT[13] + x * (aT[15] + x * \ + (aT[17] + x * (aT[19] + x * (aT[21] + x * aT[23]))))))))))); +} diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c b/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c new file mode 100644 index 0000000..5f4aa37 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/k_cosl.c @@ -0,0 +1,61 @@ +/* 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * ld128 version of k_cos.c. See ../src/k_cos.c for most comments. + */ + +#include "math_private.h" + +/* + * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]: + * |cos(x) - c(x))| < 2**-122.0 + * + * 113-bit precision requires more care than 64-bit precision, since + * simple methods give a minimax polynomial with coefficient for x^2 + * that is 1 ulp below 0.5, but we want it to be precisely 0.5. See + * ../ld80/k_cosl.c for more details. + */ +static const double +one = 1.0; + +static const long double +C1 = 0.04166666666666666666666666666666658424671L, +C2 = -0.001388888888888888888888888888863490893732L, +C3 = 0.00002480158730158730158730158600795304914210L, +C4 = -0.2755731922398589065255474947078934284324e-6L, +C5 = 0.2087675698786809897659225313136400793948e-8L, +C6 = -0.1147074559772972315817149986812031204775e-10L, +C7 = 0.4779477332386808976875457937252120293400e-13L; + +static const double +C8 = -0.1561920696721507929516718307820958119868e-15, +C9 = 0.4110317413744594971475941557607804508039e-18, +C10 = -0.8896592467191938803288521958313920156409e-21, +C11 = 0.1601061435794535138244346256065192782581e-23; + +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+ + z*(C8+z*(C9+z*(C10+z*C11)))))))))); + hz = 0.5*z; + w = one-hz; + return w + (((one-w)-hz) + (z*r-x*y)); +} diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c b/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c new file mode 100644 index 0000000..bd415c0 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/k_sinl.c @@ -0,0 +1,59 @@ +/* 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * ld128 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.53e-37, 1.659e-37] + * |sin(x)/x - s(x)| < 2**-122.1 + * + * See ../ld80/k_cosl.c for more details about the polynomial. + */ +static const long double +S1 = -0.16666666666666666666666666666666666606732416116558L, +S2 = 0.0083333333333333333333333333333331135404851288270047L, +S3 = -0.00019841269841269841269841269839935785325638310428717L, +S4 = 0.27557319223985890652557316053039946268333231205686e-5L, +S5 = -0.25052108385441718775048214826384312253862930064745e-7L, +S6 = 0.16059043836821614596571832194524392581082444805729e-9L, +S7 = -0.76471637318198151807063387954939213287488216303768e-12L, +S8 = 0.28114572543451292625024967174638477283187397621303e-14L; + +static const double +S9 = -0.82206352458348947812512122163446202498005154296863e-17, +S10 = 0.19572940011906109418080609928334380560135358385256e-19, +S11 = -0.38680813379701966970673724299207480965452616911420e-22, +S12 = 0.64038150078671872796678569586315881020659912139412e-25; + +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+ + z*(S9+z*(S10+z*(S11+z*S12))))))))); + if(iy==0) return x+v*(S1+z*r); + else return x-((z*(half*y-v*r)-y)-v*S1); +} diff --git a/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c b/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c new file mode 100644 index 0000000..d7ec0b9 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/k_tanl.c @@ -0,0 +1,119 @@ +/* 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * ld128 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 ~[-3.37e-36, 1.982e-37] + * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37) + * + * See ../ld80/k_cosl.c for more details about the polynomial. + */ +static const long double +T3 = 0x1.5555555555555555555555555553p-2L, +T5 = 0x1.1111111111111111111111111eb5p-3L, +T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L, +T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L, +T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L, +T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L, +T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L, +T17 = 0x1.355824803674477dfcf726649efep-11L, +T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L, +T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L, +T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L, +T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L, +T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L, +T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L, +T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L, +T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L, +T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L, +T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L, +pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, +pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L; + +static const double +T39 = 0.000000028443389121318352, /* 0x1e8a7592977938.0p-78 */ +T41 = 0.000000011981013102001973, /* 0x19baa1b1223219.0p-79 */ +T43 = 0.0000000038303578044958070, /* 0x107385dfb24529.0p-80 */ +T45 = 0.0000000034664378216909893, /* 0x1dc6c702a05262.0p-81 */ +T47 = -0.0000000015090641701997785, /* -0x19ecef3569ebb6.0p-82 */ +T49 = 0.0000000029449552300483952, /* 0x194c0668da786a.0p-81 */ +T51 = -0.0000000022006995706097711, /* -0x12e763b8845268.0p-81 */ +T53 = 0.0000000015468200913196612, /* 0x1a92fc98c29554.0p-82 */ +T55 = -0.00000000061311613386849674, /* -0x151106cbc779a9.0p-83 */ +T57 = 1.4912469681508012e-10; /* 0x147edbdba6f43a.0p-85 */ + +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 + + w * (T37 + w * (T41 + w * (T45 + w * (T49 + w * (T53 + + w * T57)))))))))))); + v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + + w * (T27 + w * (T31 + w * (T35 + + w * (T39 + w * (T43 + w * (T47 + w * (T51 + w * T55)))))))))))); + 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/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c new file mode 100644 index 0000000..5ed514c --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/s_exp2l.c @@ -0,0 +1,427 @@ +/*- + * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <stdint.h> + +#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 volatile long double + huge = 0x1p10000L, + twom10000 = 0x1p-10000L; + +static const long double + P1 = 0x1.62e42fefa39ef35793c7673007e6p-1L, + P2 = 0x1.ebfbdff82c58ea86f16b06ec9736p-3L, + P3 = 0x1.c6b08d704a0bf8b33a762bad3459p-5L, + P4 = 0x1.3b2ab6fba4e7729ccbbe0b4f3fc2p-7L, + P5 = 0x1.5d87fe78a67311071dee13fd11d9p-10L, + P6 = 0x1.430912f86c7876f4b663b23c5fe5p-13L; + +static const double + P7 = 0x1.ffcbfc588b041p-17, + P8 = 0x1.62c0223a5c7c7p-20, + P9 = 0x1.b52541ff59713p-24, + P10 = 0x1.e4cf56a391e22p-28, + redux = 0x1.8p112 / TBLSIZE; + +static const long double tbl[TBLSIZE] = { + 0x1.6a09e667f3bcc908b2fb1366dfeap-1L, + 0x1.6c012750bdabeed76a99800f4edep-1L, + 0x1.6dfb23c651a2ef220e2cbe1bc0d4p-1L, + 0x1.6ff7df9519483cf87e1b4f3e1e98p-1L, + 0x1.71f75e8ec5f73dd2370f2ef0b148p-1L, + 0x1.73f9a48a58173bd5c9a4e68ab074p-1L, + 0x1.75feb564267c8bf6e9aa33a489a8p-1L, + 0x1.780694fde5d3f619ae02808592a4p-1L, + 0x1.7a11473eb0186d7d51023f6ccb1ap-1L, + 0x1.7c1ed0130c1327c49334459378dep-1L, + 0x1.7e2f336cf4e62105d02ba1579756p-1L, + 0x1.80427543e1a11b60de67649a3842p-1L, + 0x1.82589994cce128acf88afab34928p-1L, + 0x1.8471a4623c7acce52f6b97c6444cp-1L, + 0x1.868d99b4492ec80e41d90ac2556ap-1L, + 0x1.88ac7d98a669966530bcdf2d4cc0p-1L, + 0x1.8ace5422aa0db5ba7c55a192c648p-1L, + 0x1.8cf3216b5448bef2aa1cd161c57ap-1L, + 0x1.8f1ae991577362b982745c72eddap-1L, + 0x1.9145b0b91ffc588a61b469f6b6a0p-1L, + 0x1.93737b0cdc5e4f4501c3f2540ae8p-1L, + 0x1.95a44cbc8520ee9b483695a0e7fep-1L, + 0x1.97d829fde4e4f8b9e920f91e8eb6p-1L, + 0x1.9a0f170ca07b9ba3109b8c467844p-1L, + 0x1.9c49182a3f0901c7c46b071f28dep-1L, + 0x1.9e86319e323231824ca78e64c462p-1L, + 0x1.a0c667b5de564b29ada8b8cabbacp-1L, + 0x1.a309bec4a2d3358c171f770db1f4p-1L, + 0x1.a5503b23e255c8b424491caf88ccp-1L, + 0x1.a799e1330b3586f2dfb2b158f31ep-1L, + 0x1.a9e6b5579fdbf43eb243bdff53a2p-1L, + 0x1.ac36bbfd3f379c0db966a3126988p-1L, + 0x1.ae89f995ad3ad5e8734d17731c80p-1L, + 0x1.b0e07298db66590842acdfc6fb4ep-1L, + 0x1.b33a2b84f15faf6bfd0e7bd941b0p-1L, + 0x1.b59728de559398e3881111648738p-1L, + 0x1.b7f76f2fb5e46eaa7b081ab53ff6p-1L, + 0x1.ba5b030a10649840cb3c6af5b74cp-1L, + 0x1.bcc1e904bc1d2247ba0f45b3d06cp-1L, + 0x1.bf2c25bd71e088408d7025190cd0p-1L, + 0x1.c199bdd85529c2220cb12a0916bap-1L, + 0x1.c40ab5fffd07a6d14df820f17deap-1L, + 0x1.c67f12e57d14b4a2137fd20f2a26p-1L, + 0x1.c8f6d9406e7b511acbc48805c3f6p-1L, + 0x1.cb720dcef90691503cbd1e949d0ap-1L, + 0x1.cdf0b555dc3f9c44f8958fac4f12p-1L, + 0x1.d072d4a07897b8d0f22f21a13792p-1L, + 0x1.d2f87080d89f18ade123989ea50ep-1L, + 0x1.d5818dcfba48725da05aeb66dff8p-1L, + 0x1.d80e316c98397bb84f9d048807a0p-1L, + 0x1.da9e603db3285708c01a5b6d480cp-1L, + 0x1.dd321f301b4604b695de3c0630c0p-1L, + 0x1.dfc97337b9b5eb968cac39ed284cp-1L, + 0x1.e264614f5a128a12761fa17adc74p-1L, + 0x1.e502ee78b3ff6273d130153992d0p-1L, + 0x1.e7a51fbc74c834b548b2832378a4p-1L, + 0x1.ea4afa2a490d9858f73a18f5dab4p-1L, + 0x1.ecf482d8e67f08db0312fb949d50p-1L, + 0x1.efa1bee615a27771fd21a92dabb6p-1L, + 0x1.f252b376bba974e8696fc3638f24p-1L, + 0x1.f50765b6e4540674f84b762861a6p-1L, + 0x1.f7bfdad9cbe138913b4bfe72bd78p-1L, + 0x1.fa7c1819e90d82e90a7e74b26360p-1L, + 0x1.fd3c22b8f71f10975ba4b32bd006p-1L, + 0x1.0000000000000000000000000000p+0L, + 0x1.0163da9fb33356d84a66ae336e98p+0L, + 0x1.02c9a3e778060ee6f7caca4f7a18p+0L, + 0x1.04315e86e7f84bd738f9a20da442p+0L, + 0x1.059b0d31585743ae7c548eb68c6ap+0L, + 0x1.0706b29ddf6ddc6dc403a9d87b1ep+0L, + 0x1.0874518759bc808c35f25d942856p+0L, + 0x1.09e3ecac6f3834521e060c584d5cp+0L, + 0x1.0b5586cf9890f6298b92b7184200p+0L, + 0x1.0cc922b7247f7407b705b893dbdep+0L, + 0x1.0e3ec32d3d1a2020742e4f8af794p+0L, + 0x1.0fb66affed31af232091dd8a169ep+0L, + 0x1.11301d0125b50a4ebbf1aed9321cp+0L, + 0x1.12abdc06c31cbfb92bad324d6f84p+0L, + 0x1.1429aaea92ddfb34101943b2588ep+0L, + 0x1.15a98c8a58e512480d573dd562aep+0L, + 0x1.172b83c7d517adcdf7c8c50eb162p+0L, + 0x1.18af9388c8de9bbbf70b9a3c269cp+0L, + 0x1.1a35beb6fcb753cb698f692d2038p+0L, + 0x1.1bbe084045cd39ab1e72b442810ep+0L, + 0x1.1d4873168b9aa7805b8028990be8p+0L, + 0x1.1ed5022fcd91cb8819ff61121fbep+0L, + 0x1.2063b88628cd63b8eeb0295093f6p+0L, + 0x1.21f49917ddc962552fd29294bc20p+0L, + 0x1.2387a6e75623866c1fadb1c159c0p+0L, + 0x1.251ce4fb2a63f3582ab7de9e9562p+0L, + 0x1.26b4565e27cdd257a673281d3068p+0L, + 0x1.284dfe1f5638096cf15cf03c9fa0p+0L, + 0x1.29e9df51fdee12c25d15f5a25022p+0L, + 0x1.2b87fd0dad98ffddea46538fca24p+0L, + 0x1.2d285a6e4030b40091d536d0733ep+0L, + 0x1.2ecafa93e2f5611ca0f45d5239a4p+0L, + 0x1.306fe0a31b7152de8d5a463063bep+0L, + 0x1.32170fc4cd8313539cf1c3009330p+0L, + 0x1.33c08b26416ff4c9c8610d96680ep+0L, + 0x1.356c55f929ff0c94623476373be4p+0L, + 0x1.371a7373aa9caa7145502f45452ap+0L, + 0x1.38cae6d05d86585a9cb0d9bed530p+0L, + 0x1.3a7db34e59ff6ea1bc9299e0a1fep+0L, + 0x1.3c32dc313a8e484001f228b58cf0p+0L, + 0x1.3dea64c12342235b41223e13d7eep+0L, + 0x1.3fa4504ac801ba0bf701aa417b9cp+0L, + 0x1.4160a21f72e29f84325b8f3dbacap+0L, + 0x1.431f5d950a896dc704439410b628p+0L, + 0x1.44e086061892d03136f409df0724p+0L, + 0x1.46a41ed1d005772512f459229f0ap+0L, + 0x1.486a2b5c13cd013c1a3b69062f26p+0L, + 0x1.4a32af0d7d3de672d8bcf46f99b4p+0L, + 0x1.4bfdad5362a271d4397afec42e36p+0L, + 0x1.4dcb299fddd0d63b36ef1a9e19dep+0L, + 0x1.4f9b2769d2ca6ad33d8b69aa0b8cp+0L, + 0x1.516daa2cf6641c112f52c84d6066p+0L, + 0x1.5342b569d4f81df0a83c49d86bf4p+0L, + 0x1.551a4ca5d920ec52ec620243540cp+0L, + 0x1.56f4736b527da66ecb004764e61ep+0L, + 0x1.58d12d497c7fd252bc2b7343d554p+0L, + 0x1.5ab07dd48542958c93015191e9a8p+0L, + 0x1.5c9268a5946b701c4b1b81697ed4p+0L, + 0x1.5e76f15ad21486e9be4c20399d12p+0L, + 0x1.605e1b976dc08b076f592a487066p+0L, + 0x1.6247eb03a5584b1f0fa06fd2d9eap+0L, + 0x1.6434634ccc31fc76f8714c4ee122p+0L, + 0x1.66238825522249127d9e29b92ea2p+0L, + 0x1.68155d44ca973081c57227b9f69ep+0L, +}; + +static const float eps[TBLSIZE] = { + -0x1.5c50p-101, + -0x1.5d00p-106, + 0x1.8e90p-102, + -0x1.5340p-103, + 0x1.1bd0p-102, + -0x1.4600p-105, + -0x1.7a40p-104, + 0x1.d590p-102, + -0x1.d590p-101, + 0x1.b100p-103, + -0x1.0d80p-105, + 0x1.6b00p-103, + -0x1.9f00p-105, + 0x1.c400p-103, + 0x1.e120p-103, + -0x1.c100p-104, + -0x1.9d20p-103, + 0x1.a800p-108, + 0x1.4c00p-106, + -0x1.9500p-106, + 0x1.6900p-105, + -0x1.29d0p-100, + 0x1.4c60p-103, + 0x1.13a0p-102, + -0x1.5b60p-103, + -0x1.1c40p-103, + 0x1.db80p-102, + 0x1.91a0p-102, + 0x1.dc00p-105, + 0x1.44c0p-104, + 0x1.9710p-102, + 0x1.8760p-103, + -0x1.a720p-103, + 0x1.ed20p-103, + -0x1.49c0p-102, + -0x1.e000p-111, + 0x1.86a0p-103, + 0x1.2b40p-103, + -0x1.b400p-108, + 0x1.1280p-99, + -0x1.02d8p-102, + -0x1.e3d0p-103, + -0x1.b080p-105, + -0x1.f100p-107, + -0x1.16c0p-105, + -0x1.1190p-103, + -0x1.a7d2p-100, + 0x1.3450p-103, + -0x1.67c0p-105, + 0x1.4b80p-104, + -0x1.c4e0p-103, + 0x1.6000p-108, + -0x1.3f60p-105, + 0x1.93f0p-104, + 0x1.5fe0p-105, + 0x1.6f80p-107, + -0x1.7600p-106, + 0x1.21e0p-106, + -0x1.3a40p-106, + -0x1.40c0p-104, + -0x1.9860p-105, + -0x1.5d40p-108, + -0x1.1d70p-106, + 0x1.2760p-105, + 0x0.0000p+0, + 0x1.21e2p-104, + -0x1.9520p-108, + -0x1.5720p-106, + -0x1.4810p-106, + -0x1.be00p-109, + 0x1.0080p-105, + -0x1.5780p-108, + -0x1.d460p-105, + -0x1.6140p-105, + 0x1.4630p-104, + 0x1.ad50p-103, + 0x1.82e0p-105, + 0x1.1d3cp-101, + 0x1.6100p-107, + 0x1.ec30p-104, + 0x1.f200p-108, + 0x1.0b40p-103, + 0x1.3660p-102, + 0x1.d9d0p-103, + -0x1.02d0p-102, + 0x1.b070p-103, + 0x1.b9c0p-104, + -0x1.01c0p-103, + -0x1.dfe0p-103, + 0x1.1b60p-104, + -0x1.ae94p-101, + -0x1.3340p-104, + 0x1.b3d8p-102, + -0x1.6e40p-105, + -0x1.3670p-103, + 0x1.c140p-104, + 0x1.1840p-101, + 0x1.1ab0p-102, + -0x1.a400p-104, + 0x1.1f00p-104, + -0x1.7180p-103, + 0x1.4ce0p-102, + 0x1.9200p-107, + -0x1.54c0p-103, + 0x1.1b80p-105, + -0x1.1828p-101, + 0x1.5720p-102, + -0x1.a060p-100, + 0x1.9160p-102, + 0x1.a280p-104, + 0x1.3400p-107, + 0x1.2b20p-102, + 0x1.7800p-108, + 0x1.cfd0p-101, + 0x1.2ef0p-102, + -0x1.2760p-99, + 0x1.b380p-104, + 0x1.0048p-101, + -0x1.60b0p-102, + 0x1.a1ccp-100, + -0x1.a640p-104, + -0x1.08a0p-101, + 0x1.7e60p-102, + 0x1.22c0p-103, + -0x1.7200p-106, + 0x1.f0f0p-102, + 0x1.eb4ep-99, + 0x1.c6e0p-103, +}; + +/* + * exp2l(x): compute the base 2 exponential of x + * + * Accuracy: Peak error < 0.502 ulp. + * + * Method: (accurate tables) + * + * Reduce x: + * x = 2**k + y, for integer k and |y| <= 1/2. + * Thus we have exp2(x) = 2**k * exp2(y). + * + * Reduce y: + * y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE. + * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]), + * with |z - eps[i]| <= 2**-8 + 2**-98 for the table used. + * + * We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via + * a degree-10 minimax polynomial with maximum error under 2**-120. + * The values in exp2t[] and eps[] are chosen such that + * exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such + * that exp2t[i] is accurate to 2**-122. + * + * Note that the range of i is +-TBLSIZE/2, so we actually index the tables + * by i0 = i + TBLSIZE/2. + * + * This method is due to Gal, with many details due to Gal and Bachelis: + * + * Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library + * for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). + */ +long double +exp2l(long double x) +{ + union IEEEl2bits u, v; + long double r, t, twopk, twopkp10000, z; + uint32_t hx, ix, i0; + int k; + + u.e = x; + + /* Filter out exceptional cases. */ + hx = u.xbits.expsign; + ix = hx & EXPMASK; + if (ix >= BIAS + 14) { /* |x| >= 16384 */ + if (ix == BIAS + LDBL_MAX_EXP) { + if (u.xbits.manh != 0 + || u.xbits.manl != 0 + || (hx & 0x8000) == 0) + return (x + x); /* x is NaN or +Inf */ + else + return (0.0); /* x is -Inf */ + } + if (x >= 16384) + return (huge * huge); /* overflow */ + if (x <= -16495) + return (twom10000 * twom10000); /* underflow */ + } else if (ix <= BIAS - 115) { /* |x| < 0x1p-115 */ + return (1.0 + x); + } + + /* + * 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 & 0xffffffff) + TBLSIZE / 2; + k = (int)i0 >> TBLBITS; + i0 = i0 & (TBLSIZE - 1); + u.e -= redux; + z = x - u.e; + v.xbits.manh = 0; + v.xbits.manl = 0; + 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 = exp2(y) = exp2t[i0] * p(z - eps[i]). */ + t = tbl[i0]; /* exp2t[i0] */ + z -= eps[i0]; /* eps[i0] */ + r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * (P5 + z * (P6 + + z * (P7 + z * (P8 + z * (P9 + z * P10))))))))); + + /* 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/libm/upstream-freebsd/lib/msun/ld128/s_expl.c b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c new file mode 100644 index 0000000..176c932 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/s_expl.c @@ -0,0 +1,494 @@ +/*- + * Copyright (c) 2009-2013 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. + * + * Optimized by Bruce D. Evans. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * ld128 version of s_expl.c. See ../ld80/s_expl.c for most comments. + */ + +#include <float.h> + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define INTERVALS 128 +#define LOG2_INTERVALS 7 +#define BIAS (LDBL_MAX_EXP - 1) + +static const long double +huge = 0x1p10000L, +twom10000 = 0x1p-10000L; +/* XXX Prevent gcc from erroneously constant folding this: */ +static volatile const long double tiny = 0x1p-10000L; + +static const long double +/* log(2**16384 - 0.5) rounded towards zero: */ +/* log(2**16384 - 0.5 + 1) rounded towards zero for expm1l() is the same: */ +o_threshold = 11356.523406294143949491931077970763428L, +/* log(2**(-16381-64-1)) rounded towards zero: */ +u_threshold = -11433.462743336297878837243843452621503L; + +static const double +/* + * ln2/INTERVALS = L1+L2 (hi+lo decomposition for multiplication). L1 must + * have at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(INTERVALS)) lowest + * bits zero so that multiplication of it by n is exact. + */ +INV_L = 1.8466496523378731e+2, /* 0x171547652b82fe.0p-45 */ +L2 = -1.0253670638894731e-29; /* -0x1.9ff0342542fc3p-97 */ +static const long double +/* 0x1.62e42fefa39ef35793c768000000p-8 */ +L1 = 5.41521234812457272982212595914567508e-3L; + +static const long double +/* + * Domain [-0.002708, 0.002708], range ~[-2.4021e-38, 2.4234e-38]: + * |exp(x) - p(x)| < 2**-124.9 + * (0.002708 is ln2/(2*INTERVALS) rounded up a little). + */ +A2 = 0.5, +A3 = 1.66666666666666666666666666651085500e-1L, +A4 = 4.16666666666666666666666666425885320e-2L, +A5 = 8.33333333333333333334522877160175842e-3L, +A6 = 1.38888888888888888889971139751596836e-3L; + +static const double +A7 = 1.9841269841269471e-4, +A8 = 2.4801587301585284e-5, +A9 = 2.7557324277411234e-6, +A10 = 2.7557333722375072e-7; + +static const struct { + /* + * hi must be rounded to at most 106 bits so that multiplication + * by r1 in expm1l() is exact, but it is rounded to 88 bits due to + * historical accidents. + */ + long double hi; + long double lo; +} tbl[INTERVALS] = { + 0x1p0L, 0x0p0L, + 0x1.0163da9fb33356d84a66aep0L, 0x3.36dcdfa4003ec04c360be2404078p-92L, + 0x1.02c9a3e778060ee6f7cacap0L, 0x4.f7a29bde93d70a2cabc5cb89ba10p-92L, + 0x1.04315e86e7f84bd738f9a2p0L, 0xd.a47e6ed040bb4bfc05af6455e9b8p-96L, + 0x1.059b0d31585743ae7c548ep0L, 0xb.68ca417fe53e3495f7df4baf84a0p-92L, + 0x1.0706b29ddf6ddc6dc403a8p0L, 0x1.d87b27ed07cb8b092ac75e311753p-88L, + 0x1.0874518759bc808c35f25cp0L, 0x1.9427fa2b041b2d6829d8993a0d01p-88L, + 0x1.09e3ecac6f3834521e060cp0L, 0x5.84d6b74ba2e023da730e7fccb758p-92L, + 0x1.0b5586cf9890f6298b92b6p0L, 0x1.1842a98364291408b3ceb0a2a2bbp-88L, + 0x1.0cc922b7247f7407b705b8p0L, 0x9.3dc5e8aac564e6fe2ef1d431fd98p-92L, + 0x1.0e3ec32d3d1a2020742e4ep0L, 0x1.8af6a552ac4b358b1129e9f966a4p-88L, + 0x1.0fb66affed31af232091dcp0L, 0x1.8a1426514e0b627bda694a400a27p-88L, + 0x1.11301d0125b50a4ebbf1aep0L, 0xd.9318ceac5cc47ab166ee57427178p-92L, + 0x1.12abdc06c31cbfb92bad32p0L, 0x4.d68e2f7270bdf7cedf94eb1cb818p-92L, + 0x1.1429aaea92ddfb34101942p0L, 0x1.b2586d01844b389bea7aedd221d4p-88L, + 0x1.15a98c8a58e512480d573cp0L, 0x1.d5613bf92a2b618ee31b376c2689p-88L, + 0x1.172b83c7d517adcdf7c8c4p0L, 0x1.0eb14a792035509ff7d758693f24p-88L, + 0x1.18af9388c8de9bbbf70b9ap0L, 0x3.c2505c97c0102e5f1211941d2840p-92L, + 0x1.1a35beb6fcb753cb698f68p0L, 0x1.2d1c835a6c30724d5cfae31b84e5p-88L, + 0x1.1bbe084045cd39ab1e72b4p0L, 0x4.27e35f9acb57e473915519a1b448p-92L, + 0x1.1d4873168b9aa7805b8028p0L, 0x9.90f07a98b42206e46166cf051d70p-92L, + 0x1.1ed5022fcd91cb8819ff60p0L, 0x1.121d1e504d36c47474c9b7de6067p-88L, + 0x1.2063b88628cd63b8eeb028p0L, 0x1.50929d0fc487d21c2b84004264dep-88L, + 0x1.21f49917ddc962552fd292p0L, 0x9.4bdb4b61ea62477caa1dce823ba0p-92L, + 0x1.2387a6e75623866c1fadb0p0L, 0x1.c15cb593b0328566902df69e4de2p-88L, + 0x1.251ce4fb2a63f3582ab7dep0L, 0x9.e94811a9c8afdcf796934bc652d0p-92L, + 0x1.26b4565e27cdd257a67328p0L, 0x1.d3b249dce4e9186ddd5ff44e6b08p-92L, + 0x1.284dfe1f5638096cf15cf0p0L, 0x3.ca0967fdaa2e52d7c8106f2e262cp-92L, + 0x1.29e9df51fdee12c25d15f4p0L, 0x1.a24aa3bca890ac08d203fed80a07p-88L, + 0x1.2b87fd0dad98ffddea4652p0L, 0x1.8fcab88442fdc3cb6de4519165edp-88L, + 0x1.2d285a6e4030b40091d536p0L, 0xd.075384589c1cd1b3e4018a6b1348p-92L, + 0x1.2ecafa93e2f5611ca0f45cp0L, 0x1.523833af611bdcda253c554cf278p-88L, + 0x1.306fe0a31b7152de8d5a46p0L, 0x3.05c85edecbc27343629f502f1af2p-92L, + 0x1.32170fc4cd8313539cf1c2p0L, 0x1.008f86dde3220ae17a005b6412bep-88L, + 0x1.33c08b26416ff4c9c8610cp0L, 0x1.96696bf95d1593039539d94d662bp-88L, + 0x1.356c55f929ff0c94623476p0L, 0x3.73af38d6d8d6f9506c9bbc93cbc0p-92L, + 0x1.371a7373aa9caa7145502ep0L, 0x1.4547987e3e12516bf9c699be432fp-88L, + 0x1.38cae6d05d86585a9cb0d8p0L, 0x1.bed0c853bd30a02790931eb2e8f0p-88L, + 0x1.3a7db34e59ff6ea1bc9298p0L, 0x1.e0a1d336163fe2f852ceeb134067p-88L, + 0x1.3c32dc313a8e484001f228p0L, 0xb.58f3775e06ab66353001fae9fca0p-92L, + 0x1.3dea64c12342235b41223ep0L, 0x1.3d773fba2cb82b8244267c54443fp-92L, + 0x1.3fa4504ac801ba0bf701aap0L, 0x4.1832fb8c1c8dbdff2c49909e6c60p-92L, + 0x1.4160a21f72e29f84325b8ep0L, 0x1.3db61fb352f0540e6ba05634413ep-88L, + 0x1.431f5d950a896dc7044394p0L, 0x1.0ccec81e24b0caff7581ef4127f7p-92L, + 0x1.44e086061892d03136f408p0L, 0x1.df019fbd4f3b48709b78591d5cb5p-88L, + 0x1.46a41ed1d005772512f458p0L, 0x1.229d97df404ff21f39c1b594d3a8p-88L, + 0x1.486a2b5c13cd013c1a3b68p0L, 0x1.062f03c3dd75ce8757f780e6ec99p-88L, + 0x1.4a32af0d7d3de672d8bcf4p0L, 0x6.f9586461db1d878b1d148bd3ccb8p-92L, + 0x1.4bfdad5362a271d4397afep0L, 0xc.42e20e0363ba2e159c579f82e4b0p-92L, + 0x1.4dcb299fddd0d63b36ef1ap0L, 0x9.e0cc484b25a5566d0bd5f58ad238p-92L, + 0x1.4f9b2769d2ca6ad33d8b68p0L, 0x1.aa073ee55e028497a329a7333dbap-88L, + 0x1.516daa2cf6641c112f52c8p0L, 0x4.d822190e718226177d7608d20038p-92L, + 0x1.5342b569d4f81df0a83c48p0L, 0x1.d86a63f4e672a3e429805b049465p-88L, + 0x1.551a4ca5d920ec52ec6202p0L, 0x4.34ca672645dc6c124d6619a87574p-92L, + 0x1.56f4736b527da66ecb0046p0L, 0x1.64eb3c00f2f5ab3d801d7cc7272dp-88L, + 0x1.58d12d497c7fd252bc2b72p0L, 0x1.43bcf2ec936a970d9cc266f0072fp-88L, + 0x1.5ab07dd48542958c930150p0L, 0x1.91eb345d88d7c81280e069fbdb63p-88L, + 0x1.5c9268a5946b701c4b1b80p0L, 0x1.6986a203d84e6a4a92f179e71889p-88L, + 0x1.5e76f15ad21486e9be4c20p0L, 0x3.99766a06548a05829e853bdb2b52p-92L, + 0x1.605e1b976dc08b076f592ap0L, 0x4.86e3b34ead1b4769df867b9c89ccp-92L, + 0x1.6247eb03a5584b1f0fa06ep0L, 0x1.d2da42bb1ceaf9f732275b8aef30p-88L, + 0x1.6434634ccc31fc76f8714cp0L, 0x4.ed9a4e41000307103a18cf7a6e08p-92L, + 0x1.66238825522249127d9e28p0L, 0x1.b8f314a337f4dc0a3adf1787ff74p-88L, + 0x1.68155d44ca973081c57226p0L, 0x1.b9f32706bfe4e627d809a85dcc66p-88L, + 0x1.6a09e667f3bcc908b2fb12p0L, 0x1.66ea957d3e3adec17512775099dap-88L, + 0x1.6c012750bdabeed76a9980p0L, 0xf.4f33fdeb8b0ecd831106f57b3d00p-96L, + 0x1.6dfb23c651a2ef220e2cbep0L, 0x1.bbaa834b3f11577ceefbe6c1c411p-92L, + 0x1.6ff7df9519483cf87e1b4ep0L, 0x1.3e213bff9b702d5aa477c12523cep-88L, + 0x1.71f75e8ec5f73dd2370f2ep0L, 0xf.0acd6cb434b562d9e8a20adda648p-92L, + 0x1.73f9a48a58173bd5c9a4e6p0L, 0x8.ab1182ae217f3a7681759553e840p-92L, + 0x1.75feb564267c8bf6e9aa32p0L, 0x1.a48b27071805e61a17b954a2dad8p-88L, + 0x1.780694fde5d3f619ae0280p0L, 0x8.58b2bb2bdcf86cd08e35fb04c0f0p-92L, + 0x1.7a11473eb0186d7d51023ep0L, 0x1.6cda1f5ef42b66977960531e821bp-88L, + 0x1.7c1ed0130c1327c4933444p0L, 0x1.937562b2dc933d44fc828efd4c9cp-88L, + 0x1.7e2f336cf4e62105d02ba0p0L, 0x1.5797e170a1427f8fcdf5f3906108p-88L, + 0x1.80427543e1a11b60de6764p0L, 0x9.a354ea706b8e4d8b718a672bf7c8p-92L, + 0x1.82589994cce128acf88afap0L, 0xb.34a010f6ad65cbbac0f532d39be0p-92L, + 0x1.8471a4623c7acce52f6b96p0L, 0x1.c64095370f51f48817914dd78665p-88L, + 0x1.868d99b4492ec80e41d90ap0L, 0xc.251707484d73f136fb5779656b70p-92L, + 0x1.88ac7d98a669966530bcdep0L, 0x1.2d4e9d61283ef385de170ab20f96p-88L, + 0x1.8ace5422aa0db5ba7c55a0p0L, 0x1.92c9bb3e6ed61f2733304a346d8fp-88L, + 0x1.8cf3216b5448bef2aa1cd0p0L, 0x1.61c55d84a9848f8c453b3ca8c946p-88L, + 0x1.8f1ae991577362b982745cp0L, 0x7.2ed804efc9b4ae1458ae946099d4p-92L, + 0x1.9145b0b91ffc588a61b468p0L, 0x1.f6b70e01c2a90229a4c4309ea719p-88L, + 0x1.93737b0cdc5e4f4501c3f2p0L, 0x5.40a22d2fc4af581b63e8326efe9cp-92L, + 0x1.95a44cbc8520ee9b483694p0L, 0x1.a0fc6f7c7d61b2b3a22a0eab2cadp-88L, + 0x1.97d829fde4e4f8b9e920f8p0L, 0x1.1e8bd7edb9d7144b6f6818084cc7p-88L, + 0x1.9a0f170ca07b9ba3109b8cp0L, 0x4.6737beb19e1eada6825d3c557428p-92L, + 0x1.9c49182a3f0901c7c46b06p0L, 0x1.1f2be58ddade50c217186c90b457p-88L, + 0x1.9e86319e323231824ca78ep0L, 0x6.4c6e010f92c082bbadfaf605cfd4p-92L, + 0x1.a0c667b5de564b29ada8b8p0L, 0xc.ab349aa0422a8da7d4512edac548p-92L, + 0x1.a309bec4a2d3358c171f76p0L, 0x1.0daad547fa22c26d168ea762d854p-88L, + 0x1.a5503b23e255c8b424491cp0L, 0xa.f87bc8050a405381703ef7caff50p-92L, + 0x1.a799e1330b3586f2dfb2b0p0L, 0x1.58f1a98796ce8908ae852236ca94p-88L, + 0x1.a9e6b5579fdbf43eb243bcp0L, 0x1.ff4c4c58b571cf465caf07b4b9f5p-88L, + 0x1.ac36bbfd3f379c0db966a2p0L, 0x1.1265fc73e480712d20f8597a8e7bp-88L, + 0x1.ae89f995ad3ad5e8734d16p0L, 0x1.73205a7fbc3ae675ea440b162d6cp-88L, + 0x1.b0e07298db66590842acdep0L, 0x1.c6f6ca0e5dcae2aafffa7a0554cbp-88L, + 0x1.b33a2b84f15faf6bfd0e7ap0L, 0x1.d947c2575781dbb49b1237c87b6ep-88L, + 0x1.b59728de559398e3881110p0L, 0x1.64873c7171fefc410416be0a6525p-88L, + 0x1.b7f76f2fb5e46eaa7b081ap0L, 0xb.53c5354c8903c356e4b625aacc28p-92L, + 0x1.ba5b030a10649840cb3c6ap0L, 0xf.5b47f297203757e1cc6eadc8bad0p-92L, + 0x1.bcc1e904bc1d2247ba0f44p0L, 0x1.b3d08cd0b20287092bd59be4ad98p-88L, + 0x1.bf2c25bd71e088408d7024p0L, 0x1.18e3449fa073b356766dfb568ff4p-88L, + 0x1.c199bdd85529c2220cb12ap0L, 0x9.1ba6679444964a36661240043970p-96L, + 0x1.c40ab5fffd07a6d14df820p0L, 0xf.1828a5366fd387a7bdd54cdf7300p-92L, + 0x1.c67f12e57d14b4a2137fd2p0L, 0xf.2b301dd9e6b151a6d1f9d5d5f520p-96L, + 0x1.c8f6d9406e7b511acbc488p0L, 0x5.c442ddb55820171f319d9e5076a8p-96L, + 0x1.cb720dcef90691503cbd1ep0L, 0x9.49db761d9559ac0cb6dd3ed599e0p-92L, + 0x1.cdf0b555dc3f9c44f8958ep0L, 0x1.ac51be515f8c58bdfb6f5740a3a4p-88L, + 0x1.d072d4a07897b8d0f22f20p0L, 0x1.a158e18fbbfc625f09f4cca40874p-88L, + 0x1.d2f87080d89f18ade12398p0L, 0x9.ea2025b4c56553f5cdee4c924728p-92L, + 0x1.d5818dcfba48725da05aeap0L, 0x1.66e0dca9f589f559c0876ff23830p-88L, + 0x1.d80e316c98397bb84f9d04p0L, 0x8.805f84bec614de269900ddf98d28p-92L, + 0x1.da9e603db3285708c01a5ap0L, 0x1.6d4c97f6246f0ec614ec95c99392p-88L, + 0x1.dd321f301b4604b695de3cp0L, 0x6.30a393215299e30d4fb73503c348p-96L, + 0x1.dfc97337b9b5eb968cac38p0L, 0x1.ed291b7225a944efd5bb5524b927p-88L, + 0x1.e264614f5a128a12761fa0p0L, 0x1.7ada6467e77f73bf65e04c95e29dp-88L, + 0x1.e502ee78b3ff6273d13014p0L, 0x1.3991e8f49659e1693be17ae1d2f9p-88L, + 0x1.e7a51fbc74c834b548b282p0L, 0x1.23786758a84f4956354634a416cep-88L, + 0x1.ea4afa2a490d9858f73a18p0L, 0xf.5db301f86dea20610ceee13eb7b8p-92L, + 0x1.ecf482d8e67f08db0312fap0L, 0x1.949cef462010bb4bc4ce72a900dfp-88L, + 0x1.efa1bee615a27771fd21a8p0L, 0x1.2dac1f6dd5d229ff68e46f27e3dfp-88L, + 0x1.f252b376bba974e8696fc2p0L, 0x1.6390d4c6ad5476b5162f40e1d9a9p-88L, + 0x1.f50765b6e4540674f84b76p0L, 0x2.862baff99000dfc4352ba29b8908p-92L, + 0x1.f7bfdad9cbe138913b4bfep0L, 0x7.2bd95c5ce7280fa4d2344a3f5618p-92L, + 0x1.fa7c1819e90d82e90a7e74p0L, 0xb.263c1dc060c36f7650b4c0f233a8p-92L, + 0x1.fd3c22b8f71f10975ba4b2p0L, 0x1.2bcf3a5e12d269d8ad7c1a4a8875p-88L +}; + +long double +expl(long double x) +{ + union IEEEl2bits u, v; + long double q, r, r1, t, twopk, twopkp10000; + double dr, fn, r2; + int k, n, n2; + uint16_t hx, ix; + + /* Filter out exceptional cases. */ + u.e = x; + hx = u.xbits.expsign; + ix = hx & 0x7fff; + if (ix >= BIAS + 13) { /* |x| >= 8192 or x is NaN */ + if (ix == BIAS + LDBL_MAX_EXP) { + if (hx & 0x8000) /* x is -Inf or -NaN */ + return (-1 / x); + return (x + x); /* x is +Inf or +NaN */ + } + if (x > o_threshold) + return (huge * huge); + if (x < u_threshold) + return (tiny * tiny); + } else if (ix < BIAS - 114) { /* |x| < 0x1p-114 */ + return (1 + x); /* 1 with inexact iff x != 0 */ + } + + ENTERI(); + + /* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + /* XXX assume no extra precision for the additions, as for trig fns. */ + /* XXX this set of comments is now quadruplicated. */ + fn = (double)x * INV_L + 0x1.8p52 - 0x1.8p52; +#if defined(HAVE_EFFICIENT_IRINT) + n = irint(fn); +#else + n = (int)fn; +#endif + n2 = (unsigned)n % INTERVALS; + k = n >> LOG2_INTERVALS; + r1 = x - fn * L1; + r2 = fn * -L2; + r = r1 + r2; + + /* Prepare scale factors. */ + /* XXX sparc64 multiplication is so slow that scalbnl() is faster. */ + v.e = 1; + if (k >= LDBL_MIN_EXP) { + v.xbits.expsign = BIAS + k; + twopk = v.e; + } else { + v.xbits.expsign = BIAS + k + 10000; + twopkp10000 = v.e; + } + + /* Evaluate expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2). */ + dr = r; + q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 + + dr * (A7 + dr * (A8 + dr * (A9 + dr * A10)))))))); + t = tbl[n2].lo + tbl[n2].hi; + t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi; + + /* Scale by 2**k. */ + if (k >= LDBL_MIN_EXP) { + if (k == LDBL_MAX_EXP) + RETURNI(t * 2 * 0x1p16383L); + RETURNI(t * twopk); + } else { + RETURNI(t * twopkp10000 * twom10000); + } +} + +/* + * Our T1 and T2 are chosen to be approximately the points where method + * A and method B have the same accuracy. Tang's T1 and T2 are the + * points where method A's accuracy changes by a full bit. For Tang, + * this drop in accuracy makes method A immediately less accurate than + * method B, but our larger INTERVALS makes method A 2 bits more + * accurate so it remains the most accurate method significantly + * closer to the origin despite losing the full bit in our extended + * range for it. + * + * Split the interval [T1, T2] into two intervals [T1, T3] and [T3, T2]. + * Setting T3 to 0 would require the |x| < 0x1p-113 condition to appear + * in both subintervals, so set T3 = 2**-5, which places the condition + * into the [T1, T3] interval. + */ +static const double +T1 = -0.1659, /* ~-30.625/128 * log(2) */ +T2 = 0.1659, /* ~30.625/128 * log(2) */ +T3 = 0.03125; + +/* + * Domain [-0.1659, 0.03125], range ~[2.9134e-44, 1.8404e-37]: + * |(exp(x)-1-x-x**2/2)/x - p(x)| < 2**-122.03 + */ +static const long double +C3 = 1.66666666666666666666666666666666667e-1L, +C4 = 4.16666666666666666666666666666666645e-2L, +C5 = 8.33333333333333333333333333333371638e-3L, +C6 = 1.38888888888888888888888888891188658e-3L, +C7 = 1.98412698412698412698412697235950394e-4L, +C8 = 2.48015873015873015873015112487849040e-5L, +C9 = 2.75573192239858906525606685484412005e-6L, +C10 = 2.75573192239858906612966093057020362e-7L, +C11 = 2.50521083854417203619031960151253944e-8L, +C12 = 2.08767569878679576457272282566520649e-9L, +C13 = 1.60590438367252471783548748824255707e-10L; + +static const double +C14 = 1.1470745580491932e-11, /* 0x1.93974a81dae30p-37 */ +C15 = 7.6471620181090468e-13, /* 0x1.ae7f3820adab1p-41 */ +C16 = 4.7793721460260450e-14, /* 0x1.ae7cd18a18eacp-45 */ +C17 = 2.8074757356658877e-15, /* 0x1.949992a1937d9p-49 */ +C18 = 1.4760610323699476e-16; /* 0x1.545b43aabfbcdp-53 */ + +/* + * Domain [0.03125, 0.1659], range ~[-2.7676e-37, -1.0367e-38]: + * |(exp(x)-1-x-x**2/2)/x - p(x)| < 2**-121.44 + */ +static const long double +D3 = 1.66666666666666666666666666666682245e-1L, +D4 = 4.16666666666666666666666666634228324e-2L, +D5 = 8.33333333333333333333333364022244481e-3L, +D6 = 1.38888888888888888888887138722762072e-3L, +D7 = 1.98412698412698412699085805424661471e-4L, +D8 = 2.48015873015873015687993712101479612e-5L, +D9 = 2.75573192239858944101036288338208042e-6L, +D10 = 2.75573192239853161148064676533754048e-7L, +D11 = 2.50521083855084570046480450935267433e-8L, +D12 = 2.08767569819738524488686318024854942e-9L, +D13 = 1.60590442297008495301927448122499313e-10L; + +static const double +D14 = 1.1470726176204336e-11, /* 0x1.93971dc395d9ep-37 */ +D15 = 7.6478532249581686e-13, /* 0x1.ae892e3D16fcep-41 */ +D16 = 4.7628892832607741e-14, /* 0x1.ad00Dfe41feccp-45 */ +D17 = 3.0524857220358650e-15; /* 0x1.D7e8d886Df921p-49 */ + +long double +expm1l(long double x) +{ + union IEEEl2bits u, v; + long double hx2_hi, hx2_lo, q, r, r1, t, twomk, twopk, x_hi; + long double x_lo, x2; + double dr, dx, fn, r2; + int k, n, n2; + uint16_t hx, ix; + + /* Filter out exceptional cases. */ + u.e = x; + hx = u.xbits.expsign; + ix = hx & 0x7fff; + if (ix >= BIAS + 7) { /* |x| >= 128 or x is NaN */ + if (ix == BIAS + LDBL_MAX_EXP) { + if (hx & 0x8000) /* x is -Inf or -NaN */ + return (-1 / x - 1); + return (x + x); /* x is +Inf or +NaN */ + } + if (x > o_threshold) + return (huge * huge); + /* + * expm1l() never underflows, but it must avoid + * unrepresentable large negative exponents. We used a + * much smaller threshold for large |x| above than in + * expl() so as to handle not so large negative exponents + * in the same way as large ones here. + */ + if (hx & 0x8000) /* x <= -128 */ + return (tiny - 1); /* good for x < -114ln2 - eps */ + } + + ENTERI(); + + if (T1 < x && x < T2) { + x2 = x * x; + dx = x; + + if (x < T3) { + if (ix < BIAS - 113) { /* |x| < 0x1p-113 */ + /* x (rounded) with inexact if x != 0: */ + RETURNI(x == 0 ? x : + (0x1p200 * x + fabsl(x)) * 0x1p-200); + } + q = x * x2 * C3 + x2 * x2 * (C4 + x * (C5 + x * (C6 + + x * (C7 + x * (C8 + x * (C9 + x * (C10 + + x * (C11 + x * (C12 + x * (C13 + + dx * (C14 + dx * (C15 + dx * (C16 + + dx * (C17 + dx * C18)))))))))))))); + } else { + q = x * x2 * D3 + x2 * x2 * (D4 + x * (D5 + x * (D6 + + x * (D7 + x * (D8 + x * (D9 + x * (D10 + + x * (D11 + x * (D12 + x * (D13 + + dx * (D14 + dx * (D15 + dx * (D16 + + dx * D17))))))))))))); + } + + x_hi = (float)x; + x_lo = x - x_hi; + hx2_hi = x_hi * x_hi / 2; + hx2_lo = x_lo * (x + x_hi) / 2; + if (ix >= BIAS - 7) + RETURNI(hx2_lo + x_lo + q + (hx2_hi + x_hi)); + else + RETURNI(hx2_lo + q + hx2_hi + x); + } + + /* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + fn = (double)x * INV_L + 0x1.8p52 - 0x1.8p52; +#if defined(HAVE_EFFICIENT_IRINT) + n = irint(fn); +#else + n = (int)fn; +#endif + n2 = (unsigned)n % INTERVALS; + k = n >> LOG2_INTERVALS; + r1 = x - fn * L1; + r2 = fn * -L2; + r = r1 + r2; + + /* Prepare scale factor. */ + v.e = 1; + v.xbits.expsign = BIAS + k; + twopk = v.e; + + /* + * Evaluate lower terms of + * expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2). + */ + dr = r; + q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 + + dr * (A7 + dr * (A8 + dr * (A9 + dr * A10)))))))); + + t = tbl[n2].lo + tbl[n2].hi; + + if (k == 0) { + t = tbl[n2].lo * (r1 + 1) + t * q + tbl[n2].hi * r1 + + (tbl[n2].hi - 1); + RETURNI(t); + } + if (k == -1) { + t = tbl[n2].lo * (r1 + 1) + t * q + tbl[n2].hi * r1 + + (tbl[n2].hi - 2); + RETURNI(t / 2); + } + if (k < -7) { + t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi; + RETURNI(t * twopk - 1); + } + if (k > 2 * LDBL_MANT_DIG - 1) { + t = tbl[n2].lo + t * (q + r1) + tbl[n2].hi; + if (k == LDBL_MAX_EXP) + RETURNI(t * 2 * 0x1p16383L - 1); + RETURNI(t * twopk - 1); + } + + v.xbits.expsign = BIAS - k; + twomk = v.e; + + if (k > LDBL_MANT_DIG - 1) + t = tbl[n2].lo - twomk + t * (q + r1) + tbl[n2].hi; + else + t = tbl[n2].lo + t * (q + r1) + (tbl[n2].hi - twomk); + RETURNI(t * twopk); +} diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_logl.c b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c new file mode 100644 index 0000000..391d623 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/s_logl.c @@ -0,0 +1,737 @@ +/*- + * Copyright (c) 2007-2013 Bruce D. Evans + * 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/** + * Implementation of the natural logarithm of x for 128-bit format. + * + * First decompose x into its base 2 representation: + * + * log(x) = log(X * 2**k), where X is in [1, 2) + * = log(X) + k * log(2). + * + * Let X = X_i + e, where X_i is the center of one of the intervals + * [-1.0/256, 1.0/256), [1.0/256, 3.0/256), .... [2.0-1.0/256, 2.0+1.0/256) + * and X is in this interval. Then + * + * log(X) = log(X_i + e) + * = log(X_i * (1 + e / X_i)) + * = log(X_i) + log(1 + e / X_i). + * + * The values log(X_i) are tabulated below. Let d = e / X_i and use + * + * log(1 + d) = p(d) + * + * where p(d) = d - 0.5*d*d + ... is a special minimax polynomial of + * suitably high degree. + * + * To get sufficiently small roundoff errors, k * log(2), log(X_i), and + * sometimes (if |k| is not large) the first term in p(d) must be evaluated + * and added up in extra precision. Extra precision is not needed for the + * rest of p(d). In the worst case when k = 0 and log(X_i) is 0, the final + * error is controlled mainly by the error in the second term in p(d). The + * error in this term itself is at most 0.5 ulps from the d*d operation in + * it. The error in this term relative to the first term is thus at most + * 0.5 * |-0.5| * |d| < 1.0/1024 ulps. We aim for an accumulated error of + * at most twice this at the point of the final rounding step. Thus the + * final error should be at most 0.5 + 1.0/512 = 0.5020 ulps. Exhaustive + * testing of a float variant of this function showed a maximum final error + * of 0.5008 ulps. Non-exhaustive testing of a double variant of this + * function showed a maximum final error of 0.5078 ulps (near 1+1.0/256). + * + * We made the maximum of |d| (and thus the total relative error and the + * degree of p(d)) small by using a large number of intervals. Using + * centers of intervals instead of endpoints reduces this maximum by a + * factor of 2 for a given number of intervals. p(d) is special only + * in beginning with the Taylor coefficients 0 + 1*d, which tends to happen + * naturally. The most accurate minimax polynomial of a given degree might + * be different, but then we wouldn't want it since we would have to do + * extra work to avoid roundoff error (especially for P0*d instead of d). + */ + +#ifdef DEBUG +#include <assert.h> +#include <fenv.h> +#endif + +#include "fpmath.h" +#include "math.h" +#ifndef NO_STRUCT_RETURN +#define STRUCT_RETURN +#endif +#include "math_private.h" + +#if !defined(NO_UTAB) && !defined(NO_UTABL) +#define USE_UTAB +#endif + +/* + * Domain [-0.005280, 0.004838], range ~[-1.1577e-37, 1.1582e-37]: + * |log(1 + d)/d - p(d)| < 2**-122.7 + */ +static const long double +P2 = -0.5L, +P3 = 3.33333333333333333333333333333233795e-1L, /* 0x15555555555555555555555554d42.0p-114L */ +P4 = -2.49999999999999999999999999941139296e-1L, /* -0x1ffffffffffffffffffffffdab14e.0p-115L */ +P5 = 2.00000000000000000000000085468039943e-1L, /* 0x19999999999999999999a6d3567f4.0p-115L */ +P6 = -1.66666666666666666666696142372698408e-1L, /* -0x15555555555555555567267a58e13.0p-115L */ +P7 = 1.42857142857142857119522943477166120e-1L, /* 0x1249249249249248ed79a0ae434de.0p-115L */ +P8 = -1.24999999999999994863289015033581301e-1L; /* -0x1fffffffffffffa13e91765e46140.0p-116L */ +/* Double precision gives ~ 53 + log2(P9 * max(|d|)**8) ~= 120 bits. */ +static const double +P9 = 1.1111111111111401e-1, /* 0x1c71c71c71c7ed.0p-56 */ +P10 = -1.0000000000040135e-1, /* -0x199999999a0a92.0p-56 */ +P11 = 9.0909090728136258e-2, /* 0x1745d173962111.0p-56 */ +P12 = -8.3333318851855284e-2, /* -0x1555551722c7a3.0p-56 */ +P13 = 7.6928634666404178e-2, /* 0x13b1985204a4ae.0p-56 */ +P14 = -7.1626810078462499e-2; /* -0x12562276cdc5d0.0p-56 */ + +static volatile const double zero = 0; + +#define INTERVALS 128 +#define LOG2_INTERVALS 7 +#define TSIZE (INTERVALS + 1) +#define G(i) (T[(i)].G) +#define F_hi(i) (T[(i)].F_hi) +#define F_lo(i) (T[(i)].F_lo) +#define ln2_hi F_hi(TSIZE - 1) +#define ln2_lo F_lo(TSIZE - 1) +#define E(i) (U[(i)].E) +#define H(i) (U[(i)].H) + +static const struct { + float G; /* 1/(1 + i/128) rounded to 8/9 bits */ + float F_hi; /* log(1 / G_i) rounded (see below) */ + /* The compiler will insert 8 bytes of padding here. */ + long double F_lo; /* next 113 bits for log(1 / G_i) */ +} T[TSIZE] = { + /* + * ln2_hi and each F_hi(i) are rounded to a number of bits that + * makes F_hi(i) + dk*ln2_hi exact for all i and all dk. + * + * The last entry (for X just below 2) is used to define ln2_hi + * and ln2_lo, to ensure that F_hi(i) and F_lo(i) cancel exactly + * with dk*ln2_hi and dk*ln2_lo, respectively, when dk = -1. + * This is needed for accuracy when x is just below 1. (To avoid + * special cases, such x are "reduced" strangely to X just below + * 2 and dk = -1, and then the exact cancellation is needed + * because any the error from any non-exactness would be too + * large). + * + * The relevant range of dk is [-16445, 16383]. The maximum number + * of bits in F_hi(i) that works is very dependent on i but has + * a minimum of 93. We only need about 12 bits in F_hi(i) for + * it to provide enough extra precision. + * + * We round F_hi(i) to 24 bits so that it can have type float, + * mainly to minimize the size of the table. Using all 24 bits + * in a float for it automatically satisfies the above constraints. + */ + 0x800000.0p-23, 0, 0, + 0xfe0000.0p-24, 0x8080ac.0p-30, -0x14ee431dae6674afa0c4bfe16e8fd.0p-144L, + 0xfc0000.0p-24, 0x8102b3.0p-29, -0x1db29ee2d83717be918e1119642ab.0p-144L, + 0xfa0000.0p-24, 0xc24929.0p-29, 0x1191957d173697cf302cc9476f561.0p-143L, + 0xf80000.0p-24, 0x820aec.0p-28, 0x13ce8888e02e78eba9b1113bc1c18.0p-142L, + 0xf60000.0p-24, 0xa33577.0p-28, -0x17a4382ce6eb7bfa509bec8da5f22.0p-142L, + 0xf48000.0p-24, 0xbc42cb.0p-28, -0x172a21161a107674986dcdca6709c.0p-143L, + 0xf30000.0p-24, 0xd57797.0p-28, -0x1e09de07cb958897a3ea46e84abb3.0p-142L, + 0xf10000.0p-24, 0xf7518e.0p-28, 0x1ae1eec1b036c484993c549c4bf40.0p-151L, + 0xef0000.0p-24, 0x8cb9df.0p-27, -0x1d7355325d560d9e9ab3d6ebab580.0p-141L, + 0xed8000.0p-24, 0x999ec0.0p-27, -0x1f9f02d256d5037108f4ec21e48cd.0p-142L, + 0xec0000.0p-24, 0xa6988b.0p-27, -0x16fc0a9d12c17a70f7a684c596b12.0p-143L, + 0xea0000.0p-24, 0xb80698.0p-27, 0x15d581c1e8da99ded322fb08b8462.0p-141L, + 0xe80000.0p-24, 0xc99af3.0p-27, -0x1535b3ba8f150ae09996d7bb4653e.0p-143L, + 0xe70000.0p-24, 0xd273b2.0p-27, 0x163786f5251aefe0ded34c8318f52.0p-145L, + 0xe50000.0p-24, 0xe442c0.0p-27, 0x1bc4b2368e32d56699c1799a244d4.0p-144L, + 0xe38000.0p-24, 0xf1b83f.0p-27, 0x1c6090f684e6766abceccab1d7174.0p-141L, + 0xe20000.0p-24, 0xff448a.0p-27, -0x1890aa69ac9f4215f93936b709efb.0p-142L, + 0xe08000.0p-24, 0x8673f6.0p-26, 0x1b9985194b6affd511b534b72a28e.0p-140L, + 0xdf0000.0p-24, 0x8d515c.0p-26, -0x1dc08d61c6ef1d9b2ef7e68680598.0p-143L, + 0xdd8000.0p-24, 0x943a9e.0p-26, -0x1f72a2dac729b3f46662238a9425a.0p-142L, + 0xdc0000.0p-24, 0x9b2fe6.0p-26, -0x1fd4dfd3a0afb9691aed4d5e3df94.0p-140L, + 0xda8000.0p-24, 0xa2315d.0p-26, -0x11b26121629c46c186384993e1c93.0p-142L, + 0xd90000.0p-24, 0xa93f2f.0p-26, 0x1286d633e8e5697dc6a402a56fce1.0p-141L, + 0xd78000.0p-24, 0xb05988.0p-26, 0x16128eba9367707ebfa540e45350c.0p-144L, + 0xd60000.0p-24, 0xb78094.0p-26, 0x16ead577390d31ef0f4c9d43f79b2.0p-140L, + 0xd50000.0p-24, 0xbc4c6c.0p-26, 0x151131ccf7c7b75e7d900b521c48d.0p-141L, + 0xd38000.0p-24, 0xc3890a.0p-26, -0x115e2cd714bd06508aeb00d2ae3e9.0p-140L, + 0xd20000.0p-24, 0xcad2d7.0p-26, -0x1847f406ebd3af80485c2f409633c.0p-142L, + 0xd10000.0p-24, 0xcfb620.0p-26, 0x1c2259904d686581799fbce0b5f19.0p-141L, + 0xcf8000.0p-24, 0xd71653.0p-26, 0x1ece57a8d5ae54f550444ecf8b995.0p-140L, + 0xce0000.0p-24, 0xde843a.0p-26, -0x1f109d4bc4595412b5d2517aaac13.0p-141L, + 0xcd0000.0p-24, 0xe37fde.0p-26, 0x1bc03dc271a74d3a85b5b43c0e727.0p-141L, + 0xcb8000.0p-24, 0xeb050c.0p-26, -0x1bf2badc0df841a71b79dd5645b46.0p-145L, + 0xca0000.0p-24, 0xf29878.0p-26, -0x18efededd89fbe0bcfbe6d6db9f66.0p-147L, + 0xc90000.0p-24, 0xf7ad6f.0p-26, 0x1373ff977baa6911c7bafcb4d84fb.0p-141L, + 0xc80000.0p-24, 0xfcc8e3.0p-26, 0x196766f2fb328337cc050c6d83b22.0p-140L, + 0xc68000.0p-24, 0x823f30.0p-25, 0x19bd076f7c434e5fcf1a212e2a91e.0p-139L, + 0xc58000.0p-24, 0x84d52c.0p-25, -0x1a327257af0f465e5ecab5f2a6f81.0p-139L, + 0xc40000.0p-24, 0x88bc74.0p-25, 0x113f23def19c5a0fe396f40f1dda9.0p-141L, + 0xc30000.0p-24, 0x8b5ae6.0p-25, 0x1759f6e6b37de945a049a962e66c6.0p-139L, + 0xc20000.0p-24, 0x8dfccb.0p-25, 0x1ad35ca6ed5147bdb6ddcaf59c425.0p-141L, + 0xc10000.0p-24, 0x90a22b.0p-25, 0x1a1d71a87deba46bae9827221dc98.0p-139L, + 0xbf8000.0p-24, 0x94a0d8.0p-25, -0x139e5210c2b730e28aba001a9b5e0.0p-140L, + 0xbe8000.0p-24, 0x974f16.0p-25, -0x18f6ebcff3ed72e23e13431adc4a5.0p-141L, + 0xbd8000.0p-24, 0x9a00f1.0p-25, -0x1aa268be39aab7148e8d80caa10b7.0p-139L, + 0xbc8000.0p-24, 0x9cb672.0p-25, -0x14c8815839c5663663d15faed7771.0p-139L, + 0xbb0000.0p-24, 0xa0cda1.0p-25, 0x1eaf46390dbb2438273918db7df5c.0p-141L, + 0xba0000.0p-24, 0xa38c6e.0p-25, 0x138e20d831f698298adddd7f32686.0p-141L, + 0xb90000.0p-24, 0xa64f05.0p-25, -0x1e8d3c41123615b147a5d47bc208f.0p-142L, + 0xb80000.0p-24, 0xa91570.0p-25, 0x1ce28f5f3840b263acb4351104631.0p-140L, + 0xb70000.0p-24, 0xabdfbb.0p-25, -0x186e5c0a42423457e22d8c650b355.0p-139L, + 0xb60000.0p-24, 0xaeadef.0p-25, -0x14d41a0b2a08a465dc513b13f567d.0p-143L, + 0xb50000.0p-24, 0xb18018.0p-25, 0x16755892770633947ffe651e7352f.0p-139L, + 0xb40000.0p-24, 0xb45642.0p-25, -0x16395ebe59b15228bfe8798d10ff0.0p-142L, + 0xb30000.0p-24, 0xb73077.0p-25, 0x1abc65c8595f088b61a335f5b688c.0p-140L, + 0xb20000.0p-24, 0xba0ec4.0p-25, -0x1273089d3dad88e7d353e9967d548.0p-139L, + 0xb10000.0p-24, 0xbcf133.0p-25, 0x10f9f67b1f4bbf45de06ecebfaf6d.0p-139L, + 0xb00000.0p-24, 0xbfd7d2.0p-25, -0x109fab904864092b34edda19a831e.0p-140L, + 0xaf0000.0p-24, 0xc2c2ac.0p-25, -0x1124680aa43333221d8a9b475a6ba.0p-139L, + 0xae8000.0p-24, 0xc439b3.0p-25, -0x1f360cc4710fbfe24b633f4e8d84d.0p-140L, + 0xad8000.0p-24, 0xc72afd.0p-25, -0x132d91f21d89c89c45003fc5d7807.0p-140L, + 0xac8000.0p-24, 0xca20a2.0p-25, -0x16bf9b4d1f8da8002f2449e174504.0p-139L, + 0xab8000.0p-24, 0xcd1aae.0p-25, 0x19deb5ce6a6a8717d5626e16acc7d.0p-141L, + 0xaa8000.0p-24, 0xd0192f.0p-25, 0x1a29fb48f7d3ca87dabf351aa41f4.0p-139L, + 0xaa0000.0p-24, 0xd19a20.0p-25, 0x1127d3c6457f9d79f51dcc73014c9.0p-141L, + 0xa90000.0p-24, 0xd49f6a.0p-25, -0x1ba930e486a0ac42d1bf9199188e7.0p-141L, + 0xa80000.0p-24, 0xd7a94b.0p-25, -0x1b6e645f31549dd1160bcc45c7e2c.0p-139L, + 0xa70000.0p-24, 0xdab7d0.0p-25, 0x1118a425494b610665377f15625b6.0p-140L, + 0xa68000.0p-24, 0xdc40d5.0p-25, 0x1966f24d29d3a2d1b2176010478be.0p-140L, + 0xa58000.0p-24, 0xdf566d.0p-25, -0x1d8e52eb2248f0c95dd83626d7333.0p-142L, + 0xa48000.0p-24, 0xe270ce.0p-25, -0x1ee370f96e6b67ccb006a5b9890ea.0p-140L, + 0xa40000.0p-24, 0xe3ffce.0p-25, 0x1d155324911f56db28da4d629d00a.0p-140L, + 0xa30000.0p-24, 0xe72179.0p-25, -0x1fe6e2f2f867d8f4d60c713346641.0p-140L, + 0xa20000.0p-24, 0xea4812.0p-25, 0x1b7be9add7f4d3b3d406b6cbf3ce5.0p-140L, + 0xa18000.0p-24, 0xebdd3d.0p-25, 0x1b3cfb3f7511dd73692609040ccc2.0p-139L, + 0xa08000.0p-24, 0xef0b5b.0p-25, -0x1220de1f7301901b8ad85c25afd09.0p-139L, + 0xa00000.0p-24, 0xf0a451.0p-25, -0x176364c9ac81cc8a4dfb804de6867.0p-140L, + 0x9f0000.0p-24, 0xf3da16.0p-25, 0x1eed6b9aafac8d42f78d3e65d3727.0p-141L, + 0x9e8000.0p-24, 0xf576e9.0p-25, 0x1d593218675af269647b783d88999.0p-139L, + 0x9d8000.0p-24, 0xf8b47c.0p-25, -0x13e8eb7da053e063714615f7cc91d.0p-144L, + 0x9d0000.0p-24, 0xfa553f.0p-25, 0x1c063259bcade02951686d5373aec.0p-139L, + 0x9c0000.0p-24, 0xfd9ac5.0p-25, 0x1ef491085fa3c1649349630531502.0p-139L, + 0x9b8000.0p-24, 0xff3f8c.0p-25, 0x1d607a7c2b8c5320619fb9433d841.0p-139L, + 0x9a8000.0p-24, 0x814697.0p-24, -0x12ad3817004f3f0bdff99f932b273.0p-138L, + 0x9a0000.0p-24, 0x821b06.0p-24, -0x189fc53117f9e54e78103a2bc1767.0p-141L, + 0x990000.0p-24, 0x83c5f8.0p-24, 0x14cf15a048907b7d7f47ddb45c5a3.0p-139L, + 0x988000.0p-24, 0x849c7d.0p-24, 0x1cbb1d35fb82873b04a9af1dd692c.0p-138L, + 0x978000.0p-24, 0x864ba6.0p-24, 0x1128639b814f9b9770d8cb6573540.0p-138L, + 0x970000.0p-24, 0x87244c.0p-24, 0x184733853300f002e836dfd47bd41.0p-139L, + 0x968000.0p-24, 0x87fdaa.0p-24, 0x109d23aef77dd5cd7cc94306fb3ff.0p-140L, + 0x958000.0p-24, 0x89b293.0p-24, -0x1a81ef367a59de2b41eeebd550702.0p-138L, + 0x950000.0p-24, 0x8a8e20.0p-24, -0x121ad3dbb2f45275c917a30df4ac9.0p-138L, + 0x948000.0p-24, 0x8b6a6a.0p-24, -0x1cfb981628af71a89df4e6df2e93b.0p-139L, + 0x938000.0p-24, 0x8d253a.0p-24, -0x1d21730ea76cfdec367828734cae5.0p-139L, + 0x930000.0p-24, 0x8e03c2.0p-24, 0x135cc00e566f76b87333891e0dec4.0p-138L, + 0x928000.0p-24, 0x8ee30d.0p-24, -0x10fcb5df257a263e3bf446c6e3f69.0p-140L, + 0x918000.0p-24, 0x90a3ee.0p-24, -0x16e171b15433d723a4c7380a448d8.0p-139L, + 0x910000.0p-24, 0x918587.0p-24, -0x1d050da07f3236f330972da2a7a87.0p-139L, + 0x908000.0p-24, 0x9267e7.0p-24, 0x1be03669a5268d21148c6002becd3.0p-139L, + 0x8f8000.0p-24, 0x942f04.0p-24, 0x10b28e0e26c336af90e00533323ba.0p-139L, + 0x8f0000.0p-24, 0x9513c3.0p-24, 0x1a1d820da57cf2f105a89060046aa.0p-138L, + 0x8e8000.0p-24, 0x95f950.0p-24, -0x19ef8f13ae3cf162409d8ea99d4c0.0p-139L, + 0x8e0000.0p-24, 0x96dfab.0p-24, -0x109e417a6e507b9dc10dac743ad7a.0p-138L, + 0x8d0000.0p-24, 0x98aed2.0p-24, 0x10d01a2c5b0e97c4990b23d9ac1f5.0p-139L, + 0x8c8000.0p-24, 0x9997a2.0p-24, -0x1d6a50d4b61ea74540bdd2aa99a42.0p-138L, + 0x8c0000.0p-24, 0x9a8145.0p-24, 0x1b3b190b83f9527e6aba8f2d783c1.0p-138L, + 0x8b8000.0p-24, 0x9b6bbf.0p-24, 0x13a69fad7e7abe7ba81c664c107e0.0p-138L, + 0x8b0000.0p-24, 0x9c5711.0p-24, -0x11cd12316f576aad348ae79867223.0p-138L, + 0x8a8000.0p-24, 0x9d433b.0p-24, 0x1c95c444b807a246726b304ccae56.0p-139L, + 0x898000.0p-24, 0x9f1e22.0p-24, -0x1b9c224ea698c2f9b47466d6123fe.0p-139L, + 0x890000.0p-24, 0xa00ce1.0p-24, 0x125ca93186cf0f38b4619a2483399.0p-141L, + 0x888000.0p-24, 0xa0fc80.0p-24, -0x1ee38a7bc228b3597043be78eaf49.0p-139L, + 0x880000.0p-24, 0xa1ed00.0p-24, -0x1a0db876613d204147dc69a07a649.0p-138L, + 0x878000.0p-24, 0xa2de62.0p-24, 0x193224e8516c008d3602a7b41c6e8.0p-139L, + 0x870000.0p-24, 0xa3d0a9.0p-24, 0x1fa28b4d2541aca7d5844606b2421.0p-139L, + 0x868000.0p-24, 0xa4c3d6.0p-24, 0x1c1b5760fb4571acbcfb03f16daf4.0p-138L, + 0x858000.0p-24, 0xa6acea.0p-24, 0x1fed5d0f65949c0a345ad743ae1ae.0p-140L, + 0x850000.0p-24, 0xa7a2d4.0p-24, 0x1ad270c9d749362382a7688479e24.0p-140L, + 0x848000.0p-24, 0xa899ab.0p-24, 0x199ff15ce532661ea9643a3a2d378.0p-139L, + 0x840000.0p-24, 0xa99171.0p-24, 0x1a19e15ccc45d257530a682b80490.0p-139L, + 0x838000.0p-24, 0xaa8a28.0p-24, -0x121a14ec532b35ba3e1f868fd0b5e.0p-140L, + 0x830000.0p-24, 0xab83d1.0p-24, 0x1aee319980bff3303dd481779df69.0p-139L, + 0x828000.0p-24, 0xac7e6f.0p-24, -0x18ffd9e3900345a85d2d86161742e.0p-140L, + 0x820000.0p-24, 0xad7a03.0p-24, -0x1e4db102ce29f79b026b64b42caa1.0p-140L, + 0x818000.0p-24, 0xae768f.0p-24, 0x17c35c55a04a82ab19f77652d977a.0p-141L, + 0x810000.0p-24, 0xaf7415.0p-24, 0x1448324047019b48d7b98c1cf7234.0p-138L, + 0x808000.0p-24, 0xb07298.0p-24, -0x1750ee3915a197e9c7359dd94152f.0p-138L, + 0x800000.0p-24, 0xb17218.0p-24, -0x105c610ca86c3898cff81a12a17e2.0p-141L, +}; + +#ifdef USE_UTAB +static const struct { + float H; /* 1 + i/INTERVALS (exact) */ + float E; /* H(i) * G(i) - 1 (exact) */ +} U[TSIZE] = { + 0x800000.0p-23, 0, + 0x810000.0p-23, -0x800000.0p-37, + 0x820000.0p-23, -0x800000.0p-35, + 0x830000.0p-23, -0x900000.0p-34, + 0x840000.0p-23, -0x800000.0p-33, + 0x850000.0p-23, -0xc80000.0p-33, + 0x860000.0p-23, -0xa00000.0p-36, + 0x870000.0p-23, 0x940000.0p-33, + 0x880000.0p-23, 0x800000.0p-35, + 0x890000.0p-23, -0xc80000.0p-34, + 0x8a0000.0p-23, 0xe00000.0p-36, + 0x8b0000.0p-23, 0x900000.0p-33, + 0x8c0000.0p-23, -0x800000.0p-35, + 0x8d0000.0p-23, -0xe00000.0p-33, + 0x8e0000.0p-23, 0x880000.0p-33, + 0x8f0000.0p-23, -0xa80000.0p-34, + 0x900000.0p-23, -0x800000.0p-35, + 0x910000.0p-23, 0x800000.0p-37, + 0x920000.0p-23, 0x900000.0p-35, + 0x930000.0p-23, 0xd00000.0p-35, + 0x940000.0p-23, 0xe00000.0p-35, + 0x950000.0p-23, 0xc00000.0p-35, + 0x960000.0p-23, 0xe00000.0p-36, + 0x970000.0p-23, -0x800000.0p-38, + 0x980000.0p-23, -0xc00000.0p-35, + 0x990000.0p-23, -0xd00000.0p-34, + 0x9a0000.0p-23, 0x880000.0p-33, + 0x9b0000.0p-23, 0xe80000.0p-35, + 0x9c0000.0p-23, -0x800000.0p-35, + 0x9d0000.0p-23, 0xb40000.0p-33, + 0x9e0000.0p-23, 0x880000.0p-34, + 0x9f0000.0p-23, -0xe00000.0p-35, + 0xa00000.0p-23, 0x800000.0p-33, + 0xa10000.0p-23, -0x900000.0p-36, + 0xa20000.0p-23, -0xb00000.0p-33, + 0xa30000.0p-23, -0xa00000.0p-36, + 0xa40000.0p-23, 0x800000.0p-33, + 0xa50000.0p-23, -0xf80000.0p-35, + 0xa60000.0p-23, 0x880000.0p-34, + 0xa70000.0p-23, -0x900000.0p-33, + 0xa80000.0p-23, -0x800000.0p-35, + 0xa90000.0p-23, 0x900000.0p-34, + 0xaa0000.0p-23, 0xa80000.0p-33, + 0xab0000.0p-23, -0xac0000.0p-34, + 0xac0000.0p-23, -0x800000.0p-37, + 0xad0000.0p-23, 0xf80000.0p-35, + 0xae0000.0p-23, 0xf80000.0p-34, + 0xaf0000.0p-23, -0xac0000.0p-33, + 0xb00000.0p-23, -0x800000.0p-33, + 0xb10000.0p-23, -0xb80000.0p-34, + 0xb20000.0p-23, -0x800000.0p-34, + 0xb30000.0p-23, -0xb00000.0p-35, + 0xb40000.0p-23, -0x800000.0p-35, + 0xb50000.0p-23, -0xe00000.0p-36, + 0xb60000.0p-23, -0x800000.0p-35, + 0xb70000.0p-23, -0xb00000.0p-35, + 0xb80000.0p-23, -0x800000.0p-34, + 0xb90000.0p-23, -0xb80000.0p-34, + 0xba0000.0p-23, -0x800000.0p-33, + 0xbb0000.0p-23, -0xac0000.0p-33, + 0xbc0000.0p-23, 0x980000.0p-33, + 0xbd0000.0p-23, 0xbc0000.0p-34, + 0xbe0000.0p-23, 0xe00000.0p-36, + 0xbf0000.0p-23, -0xb80000.0p-35, + 0xc00000.0p-23, -0x800000.0p-33, + 0xc10000.0p-23, 0xa80000.0p-33, + 0xc20000.0p-23, 0x900000.0p-34, + 0xc30000.0p-23, -0x800000.0p-35, + 0xc40000.0p-23, -0x900000.0p-33, + 0xc50000.0p-23, 0x820000.0p-33, + 0xc60000.0p-23, 0x800000.0p-38, + 0xc70000.0p-23, -0x820000.0p-33, + 0xc80000.0p-23, 0x800000.0p-33, + 0xc90000.0p-23, -0xa00000.0p-36, + 0xca0000.0p-23, -0xb00000.0p-33, + 0xcb0000.0p-23, 0x840000.0p-34, + 0xcc0000.0p-23, -0xd00000.0p-34, + 0xcd0000.0p-23, 0x800000.0p-33, + 0xce0000.0p-23, -0xe00000.0p-35, + 0xcf0000.0p-23, 0xa60000.0p-33, + 0xd00000.0p-23, -0x800000.0p-35, + 0xd10000.0p-23, 0xb40000.0p-33, + 0xd20000.0p-23, -0x800000.0p-35, + 0xd30000.0p-23, 0xaa0000.0p-33, + 0xd40000.0p-23, -0xe00000.0p-35, + 0xd50000.0p-23, 0x880000.0p-33, + 0xd60000.0p-23, -0xd00000.0p-34, + 0xd70000.0p-23, 0x9c0000.0p-34, + 0xd80000.0p-23, -0xb00000.0p-33, + 0xd90000.0p-23, -0x800000.0p-38, + 0xda0000.0p-23, 0xa40000.0p-33, + 0xdb0000.0p-23, -0xdc0000.0p-34, + 0xdc0000.0p-23, 0xc00000.0p-35, + 0xdd0000.0p-23, 0xca0000.0p-33, + 0xde0000.0p-23, -0xb80000.0p-34, + 0xdf0000.0p-23, 0xd00000.0p-35, + 0xe00000.0p-23, 0xc00000.0p-33, + 0xe10000.0p-23, -0xf40000.0p-34, + 0xe20000.0p-23, 0x800000.0p-37, + 0xe30000.0p-23, 0x860000.0p-33, + 0xe40000.0p-23, -0xc80000.0p-33, + 0xe50000.0p-23, -0xa80000.0p-34, + 0xe60000.0p-23, 0xe00000.0p-36, + 0xe70000.0p-23, 0x880000.0p-33, + 0xe80000.0p-23, -0xe00000.0p-33, + 0xe90000.0p-23, -0xfc0000.0p-34, + 0xea0000.0p-23, -0x800000.0p-35, + 0xeb0000.0p-23, 0xe80000.0p-35, + 0xec0000.0p-23, 0x900000.0p-33, + 0xed0000.0p-23, 0xe20000.0p-33, + 0xee0000.0p-23, -0xac0000.0p-33, + 0xef0000.0p-23, -0xc80000.0p-34, + 0xf00000.0p-23, -0x800000.0p-35, + 0xf10000.0p-23, 0x800000.0p-35, + 0xf20000.0p-23, 0xb80000.0p-34, + 0xf30000.0p-23, 0x940000.0p-33, + 0xf40000.0p-23, 0xc80000.0p-33, + 0xf50000.0p-23, -0xf20000.0p-33, + 0xf60000.0p-23, -0xc80000.0p-33, + 0xf70000.0p-23, -0xa20000.0p-33, + 0xf80000.0p-23, -0x800000.0p-33, + 0xf90000.0p-23, -0xc40000.0p-34, + 0xfa0000.0p-23, -0x900000.0p-34, + 0xfb0000.0p-23, -0xc80000.0p-35, + 0xfc0000.0p-23, -0x800000.0p-35, + 0xfd0000.0p-23, -0x900000.0p-36, + 0xfe0000.0p-23, -0x800000.0p-37, + 0xff0000.0p-23, -0x800000.0p-39, + 0x800000.0p-22, 0, +}; +#endif /* USE_UTAB */ + +#ifdef STRUCT_RETURN +#define RETURN1(rp, v) do { \ + (rp)->hi = (v); \ + (rp)->lo_set = 0; \ + return; \ +} while (0) + +#define RETURN2(rp, h, l) do { \ + (rp)->hi = (h); \ + (rp)->lo = (l); \ + (rp)->lo_set = 1; \ + return; \ +} while (0) + +struct ld { + long double hi; + long double lo; + int lo_set; +}; +#else +#define RETURN1(rp, v) RETURNF(v) +#define RETURN2(rp, h, l) RETURNI((h) + (l)) +#endif + +#ifdef STRUCT_RETURN +static inline __always_inline void +k_logl(long double x, struct ld *rp) +#else +long double +logl(long double x) +#endif +{ + long double d, val_hi, val_lo; + double dd, dk; + uint64_t lx, llx; + int i, k; + uint16_t hx; + + EXTRACT_LDBL128_WORDS(hx, lx, llx, x); + k = -16383; +#if 0 /* Hard to do efficiently. Don't do it until we support all modes. */ + if (x == 1) + RETURN1(rp, 0); /* log(1) = +0 in all rounding modes */ +#endif + if (hx == 0 || hx >= 0x8000) { /* zero, negative or subnormal? */ + if (((hx & 0x7fff) | lx | llx) == 0) + RETURN1(rp, -1 / zero); /* log(+-0) = -Inf */ + if (hx != 0) + /* log(neg or NaN) = qNaN: */ + RETURN1(rp, (x - x) / zero); + x *= 0x1.0p113; /* subnormal; scale up x */ + EXTRACT_LDBL128_WORDS(hx, lx, llx, x); + k = -16383 - 113; + } else if (hx >= 0x7fff) + RETURN1(rp, x + x); /* log(Inf or NaN) = Inf or qNaN */ +#ifndef STRUCT_RETURN + ENTERI(); +#endif + k += hx; + dk = k; + + /* Scale x to be in [1, 2). */ + SET_LDBL_EXPSIGN(x, 0x3fff); + + /* 0 <= i <= INTERVALS: */ +#define L2I (49 - LOG2_INTERVALS) + i = (lx + (1LL << (L2I - 2))) >> (L2I - 1); + + /* + * -0.005280 < d < 0.004838. In particular, the infinite- + * precision |d| is <= 2**-7. Rounding of G(i) to 8 bits + * ensures that d is representable without extra precision for + * this bound on |d| (since when this calculation is expressed + * as x*G(i)-1, the multiplication needs as many extra bits as + * G(i) has and the subtraction cancels 8 bits). But for + * most i (107 cases out of 129), the infinite-precision |d| + * is <= 2**-8. G(i) is rounded to 9 bits for such i to give + * better accuracy (this works by improving the bound on |d|, + * which in turn allows rounding to 9 bits in more cases). + * This is only important when the original x is near 1 -- it + * lets us avoid using a special method to give the desired + * accuracy for such x. + */ + if (0) + d = x * G(i) - 1; + else { +#ifdef USE_UTAB + d = (x - H(i)) * G(i) + E(i); +#else + long double x_hi; + double x_lo; + + /* + * Split x into x_hi + x_lo to calculate x*G(i)-1 exactly. + * G(i) has at most 9 bits, so the splitting point is not + * critical. + */ + INSERT_LDBL128_WORDS(x_hi, 0x3fff, lx, + llx & 0xffffffffff000000ULL); + x_lo = x - x_hi; + d = x_hi * G(i) - 1 + x_lo * G(i); +#endif + } + + /* + * Our algorithm depends on exact cancellation of F_lo(i) and + * F_hi(i) with dk*ln_2_lo and dk*ln2_hi when k is -1 and i is + * at the end of the table. This and other technical complications + * make it difficult to avoid the double scaling in (dk*ln2) * + * log(base) for base != e without losing more accuracy and/or + * efficiency than is gained. + */ + /* + * Use double precision operations wherever possible, since long + * double operations are emulated and are very slow on the only + * known machines that support ld128 (sparc64). Also, don't try + * to improve parallelism by increasing the number of operations, + * since any parallelism on such machines is needed for the + * emulation. Horner's method is good for this, and is also good + * for accuracy. Horner's method doesn't handle the `lo' term + * well, either for efficiency or accuracy. However, for accuracy + * we evaluate d * d * P2 separately to take advantage of + * by P2 being exact, and this gives a good place to sum the 'lo' + * term too. + */ + dd = (double)d; + val_lo = d * d * d * (P3 + + d * (P4 + d * (P5 + d * (P6 + d * (P7 + d * (P8 + + dd * (P9 + dd * (P10 + dd * (P11 + dd * (P12 + dd * (P13 + + dd * P14))))))))))) + (F_lo(i) + dk * ln2_lo) + d * d * P2; + val_hi = d; +#ifdef DEBUG + if (fetestexcept(FE_UNDERFLOW)) + breakpoint(); +#endif + + _3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi); + RETURN2(rp, val_hi, val_lo); +} + +long double +log1pl(long double x) +{ + long double d, d_hi, f_lo, val_hi, val_lo; + long double f_hi, twopminusk; + double d_lo, dd, dk; + uint64_t lx, llx; + int i, k; + int16_t ax, hx; + + DOPRINT_START(&x); + EXTRACT_LDBL128_WORDS(hx, lx, llx, x); + if (hx < 0x3fff) { /* x < 1, or x neg NaN */ + ax = hx & 0x7fff; + if (ax >= 0x3fff) { /* x <= -1, or x neg NaN */ + if (ax == 0x3fff && (lx | llx) == 0) + RETURNP(-1 / zero); /* log1p(-1) = -Inf */ + /* log1p(x < 1, or x NaN) = qNaN: */ + RETURNP((x - x) / (x - x)); + } + if (ax <= 0x3f8d) { /* |x| < 2**-113 */ + if ((int)x == 0) + RETURNP(x); /* x with inexact if x != 0 */ + } + f_hi = 1; + f_lo = x; + } else if (hx >= 0x7fff) { /* x +Inf or non-neg NaN */ + RETURNP(x + x); /* log1p(Inf or NaN) = Inf or qNaN */ + } else if (hx < 0x40e1) { /* 1 <= x < 2**226 */ + f_hi = x; + f_lo = 1; + } else { /* 2**226 <= x < +Inf */ + f_hi = x; + f_lo = 0; /* avoid underflow of the P3 term */ + } + ENTERI(); + x = f_hi + f_lo; + f_lo = (f_hi - x) + f_lo; + + EXTRACT_LDBL128_WORDS(hx, lx, llx, x); + k = -16383; + + k += hx; + dk = k; + + SET_LDBL_EXPSIGN(x, 0x3fff); + twopminusk = 1; + SET_LDBL_EXPSIGN(twopminusk, 0x7ffe - (hx & 0x7fff)); + f_lo *= twopminusk; + + i = (lx + (1LL << (L2I - 2))) >> (L2I - 1); + + /* + * x*G(i)-1 (with a reduced x) can be represented exactly, as + * above, but now we need to evaluate the polynomial on d = + * (x+f_lo)*G(i)-1 and extra precision is needed for that. + * Since x+x_lo is a hi+lo decomposition and subtracting 1 + * doesn't lose too many bits, an inexact calculation for + * f_lo*G(i) is good enough. + */ + if (0) + d_hi = x * G(i) - 1; + else { +#ifdef USE_UTAB + d_hi = (x - H(i)) * G(i) + E(i); +#else + long double x_hi; + double x_lo; + + INSERT_LDBL128_WORDS(x_hi, 0x3fff, lx, + llx & 0xffffffffff000000ULL); + x_lo = x - x_hi; + d_hi = x_hi * G(i) - 1 + x_lo * G(i); +#endif + } + d_lo = f_lo * G(i); + + /* + * This is _2sumF(d_hi, d_lo) inlined. The condition + * (d_hi == 0 || |d_hi| >= |d_lo|) for using _2sumF() is not + * always satisifed, so it is not clear that this works, but + * it works in practice. It works even if it gives a wrong + * normalized d_lo, since |d_lo| > |d_hi| implies that i is + * nonzero and d is tiny, so the F(i) term dominates d_lo. + * In float precision: + * (By exhaustive testing, the worst case is d_hi = 0x1.bp-25. + * And if d is only a little tinier than that, we would have + * another underflow problem for the P3 term; this is also ruled + * out by exhaustive testing.) + */ + d = d_hi + d_lo; + d_lo = d_hi - d + d_lo; + d_hi = d; + + dd = (double)d; + val_lo = d * d * d * (P3 + + d * (P4 + d * (P5 + d * (P6 + d * (P7 + d * (P8 + + dd * (P9 + dd * (P10 + dd * (P11 + dd * (P12 + dd * (P13 + + dd * P14))))))))))) + (F_lo(i) + dk * ln2_lo + d_lo) + d * d * P2; + val_hi = d_hi; +#ifdef DEBUG + if (fetestexcept(FE_UNDERFLOW)) + breakpoint(); +#endif + + _3sumF(val_hi, val_lo, F_hi(i) + dk * ln2_hi); + RETURN2PI(val_hi, val_lo); +} + +#ifdef STRUCT_RETURN + +long double +logl(long double x) +{ + struct ld r; + + ENTERI(); + DOPRINT_START(&x); + k_logl(x, &r); + RETURNSPI(&r); +} + +/* + * 29+113 bit decompositions. The bits are distributed so that the products + * of the hi terms are exact in double precision. The types are chosen so + * that the products of the hi terms are done in at least double precision, + * without any explicit conversions. More natural choices would require a + * slow long double precision multiplication. + */ +static const double +invln10_hi = 4.3429448176175356e-1, /* 0x1bcb7b15000000.0p-54 */ +invln2_hi = 1.4426950402557850e0; /* 0x17154765000000.0p-52 */ +static const long double +invln10_lo = 1.41498268538580090791605082294397000e-10L, /* 0x137287195355baaafad33dc323ee3.0p-145L */ +invln2_lo = 6.33178418956604368501892137426645911e-10L; /* 0x15c17f0bbbe87fed0691d3e88eb57.0p-143L */ + +long double +log10l(long double x) +{ + struct ld r; + long double lo; + float hi; + + ENTERI(); + DOPRINT_START(&x); + k_logl(x, &r); + if (!r.lo_set) + RETURNPI(r.hi); + _2sumF(r.hi, r.lo); + hi = r.hi; + lo = r.lo + (r.hi - hi); + RETURN2PI(invln10_hi * hi, + (invln10_lo + invln10_hi) * lo + invln10_lo * hi); +} + +long double +log2l(long double x) +{ + struct ld r; + long double lo; + float hi; + + ENTERI(); + DOPRINT_START(&x); + k_logl(x, &r); + if (!r.lo_set) + RETURNPI(r.hi); + _2sumF(r.hi, r.lo); + hi = r.hi; + lo = r.lo + (r.hi - hi); + RETURN2PI(invln2_hi * hi, + (invln2_lo + invln2_hi) * lo + invln2_lo * hi); +} + +#endif /* STRUCT_RETURN */ diff --git a/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c b/libm/upstream-freebsd/lib/msun/ld128/s_nanl.c new file mode 100644 index 0000000..0f74a13 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/ld128/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$ + */ + +#include <math.h> + +#include "fpmath.h" +#include "../src/math_private.h" + +long double +nanl(const char *s) +{ + union { + union IEEEl2bits ieee; + uint32_t bits[4]; + } u; + + _scan_nan(u.bits, 4, s); + u.ieee.bits.exp = 0x7fff; + u.ieee.bits.manh |= 1ULL << 47; /* make it a quiet NaN */ + return (u.ieee.e); +} diff --git a/libm/src/e_acos.c b/libm/upstream-freebsd/lib/msun/src/e_acos.c index 8ba672a..1f6dca5 100644 --- a/libm/src/e_acos.c +++ b/libm/upstream-freebsd/lib/msun/src/e_acos.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acos.c,v 1.10 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_acos(x) * Method : @@ -39,14 +38,18 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acos.c,v 1.10 2005/02/04 18: * Function needed: sqrt */ +#include <float.h> + #include "math.h" #include "math_private.h" static const double one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ +pio2_hi = 1.57079632679489655800e+00; /* 0x3FF921FB, 0x54442D18 */ +static volatile double +pio2_lo = 6.12323399573676603587e-17; /* 0x3C91A626, 0x33145C07 */ +static const double pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ @@ -102,3 +105,7 @@ __ieee754_acos(double x) return 2.0*(df+w); } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(acos, acosl); +#endif diff --git a/libm/src/e_acosf.c b/libm/upstream-freebsd/lib/msun/src/e_acosf.c index a11f48e..c9f62cc 100644 --- a/libm/src/e_acosf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_acosf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosf.c,v 1.7 2002/05/28 17:03:12 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -23,18 +22,14 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosf.c,v 1.7 2002/05/28 17: static const float one = 1.0000000000e+00, /* 0x3F800000 */ pi = 3.1415925026e+00, /* 0x40490fda */ -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ -pS1 = -3.2556581497e-01, /* 0xbea6b090 */ -pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ -pS3 = -4.0055535734e-02, /* 0xbd241146 */ -pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ -pS5 = 3.4793309169e-05, /* 0x3811ef08 */ -qS1 = -2.4033949375e+00, /* 0xc019d139 */ -qS2 = 2.0209457874e+00, /* 0x4001572d */ -qS3 = -6.8828397989e-01, /* 0xbf303361 */ -qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ +pio2_hi = 1.5707962513e+00; /* 0x3fc90fda */ +static volatile float +pio2_lo = 7.5497894159e-08; /* 0x33a22168 */ +static const float +pS0 = 1.6666586697e-01, +pS1 = -4.2743422091e-02, +pS2 = -8.6563630030e-03, +qS1 = -7.0662963390e-01; float __ieee754_acosf(float x) @@ -43,37 +38,38 @@ __ieee754_acosf(float x) int32_t hx,ix; GET_FLOAT_WORD(hx,x); ix = hx&0x7fffffff; - if(ix==0x3f800000) { /* |x|==1 */ - if(hx>0) return 0.0; /* acos(1) = 0 */ - else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ - } else if(ix>0x3f800000) { /* |x| >= 1 */ + if(ix>=0x3f800000) { /* |x| >= 1 */ + if(ix==0x3f800000) { /* |x| == 1 */ + if(hx>0) return 0.0; /* acos(1) = 0 */ + else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ + } return (x-x)/(x-x); /* acos(|x|>1) is NaN */ } if(ix<0x3f000000) { /* |x| < 0.5 */ - if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ + if(ix<=0x32800000) return pio2_hi+pio2_lo;/*if|x|<2**-26*/ z = x*x; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + p = z*(pS0+z*(pS1+z*pS2)); + q = one+z*qS1; r = p/q; return pio2_hi - (x - (pio2_lo-x*r)); } else if (hx<0) { /* x < -0.5 */ z = (one+x)*(float)0.5; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - s = __ieee754_sqrtf(z); + p = z*(pS0+z*(pS1+z*pS2)); + q = one+z*qS1; + s = sqrtf(z); r = p/q; w = r*s-pio2_lo; return pi - (float)2.0*(s+w); } else { /* x > 0.5 */ int32_t idf; z = (one-x)*(float)0.5; - s = __ieee754_sqrtf(z); + s = sqrtf(z); df = s; GET_FLOAT_WORD(idf,df); SET_FLOAT_WORD(df,idf&0xfffff000); c = (z-df*df)/(s+df); - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + p = z*(pS0+z*(pS1+z*pS2)); + q = one+z*qS1; r = p/q; w = r*s+c; return (float)2.0*(df+w); diff --git a/libm/src/e_acosh.c b/libm/upstream-freebsd/lib/msun/src/e_acosh.c index ccb1521..358c8bd 100644 --- a/libm/src/e_acosh.c +++ b/libm/upstream-freebsd/lib/msun/src/e_acosh.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosh.c,v 1.8 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_acosh(x) * Method : @@ -30,6 +29,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosh.c,v 1.8 2005/02/04 18: * acosh(NaN) is NaN without signal. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -61,3 +62,7 @@ __ieee754_acosh(double x) return log1p(t+sqrt(2.0*t+t*t)); } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(acosh, acoshl); +#endif diff --git a/libm/src/e_acoshf.c b/libm/upstream-freebsd/lib/msun/src/e_acoshf.c index 5257914..f529b20 100644 --- a/libm/src/e_acoshf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_acoshf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acoshf.c,v 1.7 2002/05/28 17:03:12 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/upstream-freebsd/lib/msun/src/e_acoshl.c b/libm/upstream-freebsd/lib/msun/src/e_acoshl.c new file mode 100644 index 0000000..59faeb0 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_acoshl.c @@ -0,0 +1,89 @@ +/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)e_acosh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See e_acosh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */ +#if LDBL_MANT_DIG == 64 +#define EXP_LARGE 34 +#elif LDBL_MANT_DIG == 113 +#define EXP_LARGE 58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double +one = 1.0; + +#if LDBL_MANT_DIG == 64 +static const union IEEEl2bits +u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); +#define ln2 u_ln2.e +#elif LDBL_MANT_DIG == 113 +static const long double +ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ +#else +#error "Unsupported long double format" +#endif + +long double +acoshl(long double x) +{ + long double t; + int16_t hx; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + if (hx < 0x3fff) { /* x < 1, or misnormal */ + RETURNI((x-x)/(x-x)); + } else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */ + if (hx >= 0x7fff) { /* x is inf, NaN or misnormal */ + RETURNI(x+x); + } else + RETURNI(logl(x)+ln2); /* acosh(huge)=log(2x), or misnormal */ + } else if (hx == 0x3fff && x == 1) { + RETURNI(0.0); /* acosh(1) = 0 */ + } else if (hx >= 0x4000) { /* LARGE > x >= 2, or misnormal */ + t=x*x; + RETURNI(logl(2.0*x-one/(x+sqrtl(t-one)))); + } else { /* 1<x<2 */ + t = x-one; + RETURNI(log1pl(t+sqrtl(2.0*t+t*t))); + } +} diff --git a/libm/upstream-freebsd/lib/msun/src/e_acosl.c b/libm/upstream-freebsd/lib/msun/src/e_acosl.c new file mode 100644 index 0000000..d33c8fe --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_acosl.c @@ -0,0 +1,87 @@ + +/* @(#)e_acos.c 1.3 95/01/18 */ +/* FreeBSD: head/lib/msun/src/e_acos.c 176451 2008-02-22 02:30:36Z das */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See comments in e_acos.c. + * Converted to long double by David Schultz <das@FreeBSD.ORG>. + */ + +#include <float.h> + +#include "invtrig.h" +#include "math.h" +#include "math_private.h" + +static const long double +one= 1.00000000000000000000e+00; + +#ifdef __i386__ +/* XXX Work around the fact that gcc truncates long double constants on i386 */ +static volatile double +pi1 = 3.14159265358979311600e+00, /* 0x1.921fb54442d18p+1 */ +pi2 = 1.22514845490862001043e-16; /* 0x1.1a80000000000p-53 */ +#define pi ((long double)pi1 + pi2) +#else +static const long double +pi = 3.14159265358979323846264338327950280e+00L; +#endif + +long double +acosl(long double x) +{ + union IEEEl2bits u; + long double z,p,q,r,w,s,c,df; + int16_t expsign, expt; + u.e = x; + expsign = u.xbits.expsign; + expt = expsign & 0x7fff; + if(expt >= BIAS) { /* |x| >= 1 */ + if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0) { + if (expsign>0) return 0.0; /* acos(1) = 0 */ + else return pi+2.0*pio2_lo; /* acos(-1)= pi */ + } + return (x-x)/(x-x); /* acos(|x|>1) is NaN */ + } + if(expt<BIAS-1) { /* |x| < 0.5 */ + if(expt<ACOS_CONST) return pio2_hi+pio2_lo;/*x tiny: acosl=pi/2*/ + z = x*x; + p = P(z); + q = Q(z); + r = p/q; + return pio2_hi - (x - (pio2_lo-x*r)); + } else if (expsign<0) { /* x < -0.5 */ + z = (one+x)*0.5; + p = P(z); + q = Q(z); + s = sqrtl(z); + r = p/q; + w = r*s-pio2_lo; + return pi - 2.0*(s+w); + } else { /* x > 0.5 */ + z = (one-x)*0.5; + s = sqrtl(z); + u.e = s; + u.bits.manl = 0; + df = u.e; + c = (z-df*df)/(s+df); + p = P(z); + q = Q(z); + r = p/q; + w = r*s+c; + return 2.0*(df+w); + } +} diff --git a/libm/src/e_asin.c b/libm/upstream-freebsd/lib/msun/src/e_asin.c index 1ba7026..27de207 100644 --- a/libm/src/e_asin.c +++ b/libm/upstream-freebsd/lib/msun/src/e_asin.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_asin.c,v 1.11 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_asin(x) * Method : @@ -45,6 +44,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_asin.c,v 1.11 2005/02/04 18: * */ +#include <float.h> #include "math.h" #include "math_private.h" @@ -82,14 +82,14 @@ __ieee754_asin(double x) return x*pio2_hi+x*pio2_lo; return (x-x)/(x-x); /* asin(|x|>1) is NaN */ } else if (ix<0x3fe00000) { /* |x|<0.5 */ - if(ix<0x3e400000) { /* if |x| < 2**-27 */ + if(ix<0x3e500000) { /* if |x| < 2**-26 */ if(huge+x>one) return x;/* return x with inexact if x!=0*/ - } else - t = x*x; - p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - w = p/q; - return x+x*w; + } + t = x*x; + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); + w = p/q; + return x+x*w; } /* 1> |x|>= 0.5 */ w = one-fabs(x); @@ -111,3 +111,7 @@ __ieee754_asin(double x) } if(hx>0) return t; else return -t; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(asin, asinl); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/e_asinf.c b/libm/upstream-freebsd/lib/msun/src/e_asinf.c new file mode 100644 index 0000000..deaabb6 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_asinf.c @@ -0,0 +1,65 @@ +/* e_asinf.c -- float version of e_asin.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "math.h" +#include "math_private.h" + +static const float +one = 1.0000000000e+00, /* 0x3F800000 */ +huge = 1.000e+30, + /* coefficient for R(x^2) */ +pS0 = 1.6666586697e-01, +pS1 = -4.2743422091e-02, +pS2 = -8.6563630030e-03, +qS1 = -7.0662963390e-01; + +static const double +pio2 = 1.570796326794896558e+00; + +float +__ieee754_asinf(float x) +{ + double s; + float t,w,p,q; + int32_t hx,ix; + GET_FLOAT_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>=0x3f800000) { /* |x| >= 1 */ + if(ix==0x3f800000) /* |x| == 1 */ + return x*pio2; /* asin(+-1) = +-pi/2 with inexact */ + return (x-x)/(x-x); /* asin(|x|>1) is NaN */ + } else if (ix<0x3f000000) { /* |x|<0.5 */ + if(ix<0x39800000) { /* |x| < 2**-12 */ + if(huge+x>one) return x;/* return x with inexact if x!=0*/ + } + t = x*x; + p = t*(pS0+t*(pS1+t*pS2)); + q = one+t*qS1; + w = p/q; + return x+x*w; + } + /* 1> |x|>= 0.5 */ + w = one-fabsf(x); + t = w*(float)0.5; + p = t*(pS0+t*(pS1+t*pS2)); + q = one+t*qS1; + s = sqrt(t); + w = p/q; + t = pio2-2.0*(s+s*w); + if(hx>0) return t; else return -t; +} diff --git a/libm/upstream-freebsd/lib/msun/src/e_asinl.c b/libm/upstream-freebsd/lib/msun/src/e_asinl.c new file mode 100644 index 0000000..a85765f --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_asinl.c @@ -0,0 +1,77 @@ + +/* @(#)e_asin.c 1.3 95/01/18 */ +/* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See comments in e_asin.c. + * Converted to long double by David Schultz <das@FreeBSD.ORG>. + */ + +#include <float.h> + +#include "invtrig.h" +#include "math.h" +#include "math_private.h" + +static const long double +one = 1.00000000000000000000e+00, +huge = 1.000e+300; + +long double +asinl(long double x) +{ + union IEEEl2bits u; + long double t=0.0,w,p,q,c,r,s; + int16_t expsign, expt; + u.e = x; + expsign = u.xbits.expsign; + expt = expsign & 0x7fff; + if(expt >= BIAS) { /* |x|>= 1 */ + if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0) + /* asin(1)=+-pi/2 with inexact */ + return x*pio2_hi+x*pio2_lo; + return (x-x)/(x-x); /* asin(|x|>1) is NaN */ + } else if (expt<BIAS-1) { /* |x|<0.5 */ + if(expt<ASIN_LINEAR) { /* if |x| is small, asinl(x)=x */ + if(huge+x>one) return x;/* return x with inexact if x!=0*/ + } + t = x*x; + p = P(t); + q = Q(t); + w = p/q; + return x+x*w; + } + /* 1> |x|>= 0.5 */ + w = one-fabsl(x); + t = w*0.5; + p = P(t); + q = Q(t); + s = sqrtl(t); + if(u.bits.manh>=THRESH) { /* if |x| is close to 1 */ + w = p/q; + t = pio2_hi-(2.0*(s+s*w)-pio2_lo); + } else { + u.e = s; + u.bits.manl = 0; + w = u.e; + c = (t-w*w)/(s+w); + r = p/q; + p = 2.0*s*r-(pio2_lo-2.0*c); + q = pio4_hi-2.0*w; + t = pio4_hi-(p-q); + } + if(expsign>0) return t; else return -t; +} diff --git a/libm/src/e_atan2.c b/libm/upstream-freebsd/lib/msun/src/e_atan2.c index 56c05a5..a4a985b 100644 --- a/libm/src/e_atan2.c +++ b/libm/upstream-freebsd/lib/msun/src/e_atan2.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atan2.c,v 1.10 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_atan2(y,x) * Method : @@ -43,15 +42,19 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atan2.c,v 1.10 2005/02/04 18 * to produce the hexadecimal values shown. */ +#include <float.h> + #include "math.h" #include "math_private.h" +static volatile double +tiny = 1.0e-300; static const double -tiny = 1.0e-300, zero = 0.0, pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ -pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ +pi = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */ +static volatile double pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ double @@ -68,7 +71,7 @@ __ieee754_atan2(double y, double x) if(((ix|((lx|-lx)>>31))>0x7ff00000)|| ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */ return x+y; - if(((hx-0x3ff00000) | lx)==0) return atan(y); /* x=1.0 */ + if((hx-0x3ff00000|lx)==0) return atan(y); /* x=1.0 */ m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ /* when y = 0 */ @@ -106,19 +109,21 @@ __ieee754_atan2(double y, double x) /* compute y/x */ k = (iy-ix)>>20; - if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ + if(k > 60) { /* |y/x| > 2**60 */ + z=pi_o_2+0.5*pi_lo; + m&=1; + } + else if(hx<0&&k<-60) z=0.0; /* 0 > |y|/x > -2**-60 */ else z=atan(fabs(y/x)); /* safe to do y/x */ switch (m) { case 0: return z ; /* atan(+,+) */ - case 1: { - u_int32_t zh; - GET_HIGH_WORD(zh,z); - SET_HIGH_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ + case 1: return -z ; /* atan(-,+) */ case 2: return pi-(z-pi_lo);/* atan(+,-) */ default: /* case 3 */ return (z-pi_lo)-pi;/* atan(-,-) */ } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(atan2, atan2l); +#endif diff --git a/libm/src/e_atan2f.c b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c index 466d5d4..fc77bff 100644 --- a/libm/src/e_atan2f.c +++ b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c @@ -13,19 +13,20 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atan2f.c,v 1.7 2004/06/02 17:09:05 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" +static volatile float +tiny = 1.0e-30; static const float -tiny = 1.0e-30, zero = 0.0, pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ -pi = 3.1415927410e+00, /* 0x40490fdb */ +pi = 3.1415927410e+00; /* 0x40490fdb */ +static volatile float pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ float @@ -79,17 +80,15 @@ __ieee754_atan2f(float y, float x) /* compute y/x */ k = (iy-ix)>>23; - if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ + if(k > 26) { /* |y/x| > 2**26 */ + z=pi_o_2+(float)0.5*pi_lo; + m&=1; + } + else if(k<-26&&hx<0) z=0.0; /* 0 > |y|/x > -2**-26 */ else z=atanf(fabsf(y/x)); /* safe to do y/x */ switch (m) { case 0: return z ; /* atan(+,+) */ - case 1: { - u_int32_t zh; - GET_FLOAT_WORD(zh,z); - SET_FLOAT_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ + case 1: return -z ; /* atan(-,+) */ case 2: return pi-(z-pi_lo);/* atan(+,-) */ default: /* case 3 */ return (z-pi_lo)-pi;/* atan(-,-) */ diff --git a/libm/upstream-freebsd/lib/msun/src/e_atan2l.c b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c new file mode 100644 index 0000000..0326482 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c @@ -0,0 +1,120 @@ + +/* @(#)e_atan2.c 1.3 95/01/18 */ +/* FreeBSD: head/lib/msun/src/e_atan2.c 176451 2008-02-22 02:30:36Z das */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See comments in e_atan2.c. + * Converted to long double by David Schultz <das@FreeBSD.ORG>. + */ + +#include <float.h> + +#include "invtrig.h" +#include "math.h" +#include "math_private.h" + +static volatile long double +tiny = 1.0e-300; +static const long double +zero = 0.0; + +#ifdef __i386__ +/* XXX Work around the fact that gcc truncates long double constants on i386 */ +static volatile double +pi1 = 3.14159265358979311600e+00, /* 0x1.921fb54442d18p+1 */ +pi2 = 1.22514845490862001043e-16; /* 0x1.1a80000000000p-53 */ +#define pi ((long double)pi1 + pi2) +#else +static const long double +pi = 3.14159265358979323846264338327950280e+00L; +#endif + +long double +atan2l(long double y, long double x) +{ + union IEEEl2bits ux, uy; + long double z; + int32_t k,m; + int16_t exptx, expsignx, expty, expsigny; + + uy.e = y; + expsigny = uy.xbits.expsign; + expty = expsigny & 0x7fff; + ux.e = x; + expsignx = ux.xbits.expsign; + exptx = expsignx & 0x7fff; + + if ((exptx==BIAS+LDBL_MAX_EXP && + ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)!=0) || /* x is NaN */ + (expty==BIAS+LDBL_MAX_EXP && + ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* y is NaN */ + return x+y; + if (expsignx==BIAS && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0) + return atanl(y); /* x=1.0 */ + m = ((expsigny>>15)&1)|((expsignx>>14)&2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if(expty==0 && ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)==0) { + switch(m) { + case 0: + case 1: return y; /* atan(+-0,+anything)=+-0 */ + case 2: return pi+tiny;/* atan(+0,-anything) = pi */ + case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ + } + } + /* when x = 0 */ + if(exptx==0 && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0) + return (expsigny<0)? -pio2_hi-tiny: pio2_hi+tiny; + + /* when x is INF */ + if(exptx==BIAS+LDBL_MAX_EXP) { + if(expty==BIAS+LDBL_MAX_EXP) { + switch(m) { + case 0: return pio2_hi*0.5+tiny;/* atan(+INF,+INF) */ + case 1: return -pio2_hi*0.5-tiny;/* atan(-INF,+INF) */ + case 2: return 1.5*pio2_hi+tiny;/*atan(+INF,-INF)*/ + case 3: return -1.5*pio2_hi-tiny;/*atan(-INF,-INF)*/ + } + } else { + switch(m) { + case 0: return zero ; /* atan(+...,+INF) */ + case 1: return -zero ; /* atan(-...,+INF) */ + case 2: return pi+tiny ; /* atan(+...,-INF) */ + case 3: return -pi-tiny ; /* atan(-...,-INF) */ + } + } + } + /* when y is INF */ + if(expty==BIAS+LDBL_MAX_EXP) + return (expsigny<0)? -pio2_hi-tiny: pio2_hi+tiny; + + /* compute y/x */ + k = expty-exptx; + if(k > LDBL_MANT_DIG+2) { /* |y/x| huge */ + z=pio2_hi+pio2_lo; + m&=1; + } + else if(expsignx<0&&k<-LDBL_MANT_DIG-2) z=0.0; /* |y/x| tiny, x<0 */ + else z=atanl(fabsl(y/x)); /* safe to do y/x */ + switch (m) { + case 0: return z ; /* atan(+,+) */ + case 1: return -z ; /* atan(-,+) */ + case 2: return pi-(z-pi_lo);/* atan(+,-) */ + default: /* case 3 */ + return (z-pi_lo)-pi;/* atan(-,-) */ + } +} diff --git a/libm/src/e_atanh.c b/libm/upstream-freebsd/lib/msun/src/e_atanh.c index 604875c..422ff26 100644 --- a/libm/src/e_atanh.c +++ b/libm/upstream-freebsd/lib/msun/src/e_atanh.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atanh.c,v 1.7 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_atanh(x) * Method : @@ -34,6 +33,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atanh.c,v 1.7 2005/02/04 18: * */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -61,3 +62,7 @@ __ieee754_atanh(double x) t = 0.5*log1p((x+x)/(one-x)); if(hx>=0) return t; else return -t; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(atanh, atanhl); +#endif diff --git a/libm/src/e_atanhf.c b/libm/upstream-freebsd/lib/msun/src/e_atanhf.c index 64ebd3d..4bd6a8f 100644 --- a/libm/src/e_atanhf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_atanhf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atanhf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/upstream-freebsd/lib/msun/src/e_atanhl.c b/libm/upstream-freebsd/lib/msun/src/e_atanhl.c new file mode 100644 index 0000000..a888426 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_atanhl.c @@ -0,0 +1,74 @@ +/* from: FreeBSD: head/lib/msun/src/e_atanh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)e_atanh.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See e_atanh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_TINY is the threshold below which we use atanh(x) ~= x. */ +#if LDBL_MANT_DIG == 64 +#define EXP_TINY -34 +#elif LDBL_MANT_DIG == 113 +#define EXP_TINY -58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double one = 1.0, huge = 1e300; +static const double zero = 0.0; + +long double +atanhl(long double x) +{ + long double t; + uint16_t hx, ix; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + ix = hx & 0x7fff; + if (ix >= 0x3fff) /* |x| >= 1, or NaN or misnormal */ + RETURNI(fabsl(x) == 1 ? x / zero : (x - x) / (x - x)); + if (ix < BIAS + EXP_TINY && (huge + x) > zero) + RETURNI(x); /* x is tiny */ + SET_LDBL_EXPSIGN(x, ix); + if (ix < 0x3ffe) { /* |x| < 0.5, or misnormal */ + t = x+x; + t = 0.5*log1pl(t+t*x/(one-x)); + } else + t = 0.5*log1pl((x+x)/(one-x)); + RETURNI((hx & 0x8000) == 0 ? t : -t); +} diff --git a/libm/src/e_cosh.c b/libm/upstream-freebsd/lib/msun/src/e_cosh.c index 40a943a..a363695 100644 --- a/libm/src/e_cosh.c +++ b/libm/upstream-freebsd/lib/msun/src/e_cosh.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_cosh.c,v 1.8 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_cosh(x) * Method : @@ -46,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); @@ -73,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/libm/src/e_coshf.c b/libm/upstream-freebsd/lib/msun/src/e_coshf.c index f9df9b0..95a0d6e 100644 --- a/libm/src/e_coshf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_coshf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_coshf.c,v 1.7 2005/11/13 00:08:23 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -52,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/libm/src/e_exp.c b/libm/upstream-freebsd/lib/msun/src/e_exp.c index e261895..94c9769 100644 --- a/libm/src/e_exp.c +++ b/libm/upstream-freebsd/lib/msun/src/e_exp.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_exp.c,v 1.10 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_exp(x) * Returns the exponential of x. @@ -77,14 +76,14 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_exp.c,v 1.10 2005/02/04 18:2 * to produce the hexadecimal values shown. */ +#include <float.h> + #include "math.h" #include "math_private.h" static const double one = 1.0, halF[2] = {0.5,-0.5,}, -huge = 1.0e+300, -twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ @@ -98,11 +97,14 @@ P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ +static volatile double +huge = 1.0e+300, +twom1000= 9.33263618503218878990e-302; /* 2**-1000=0x01700000,0*/ double __ieee754_exp(double x) /* default IEEE double exp */ { - double y,hi=0.0,lo=0.0,c,t; + double y,hi=0.0,lo=0.0,c,t,twopk; int32_t k=0,xsb; u_int32_t hx; @@ -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 */ @@ -142,18 +144,21 @@ __ieee754_exp(double x) /* default IEEE double exp */ /* x is now in primary range */ t = x*x; + if(k >= -1021) + INSERT_WORDS(twopk,0x3ff00000+(k<<20), 0); + else + INSERT_WORDS(twopk,0x3ff00000+((k+1000)<<20), 0); c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); if(k==0) return one-((x*c)/(c-2.0)-x); else y = one-((lo-(x*c)/(2.0-c))-hi); if(k >= -1021) { - u_int32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */ - return y; + if (k==1024) return y*2.0*0x1p1023; + return y*twopk; } else { - u_int32_t hy; - GET_HIGH_WORD(hy,y); - SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */ - return y*twom1000; + return y*twopk*twom1000; } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(exp, expl); +#endif diff --git a/libm/src/e_expf.c b/libm/upstream-freebsd/lib/msun/src/e_expf.c index 4e06556..b1fe2c5 100644 --- a/libm/src/e_expf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_expf.c @@ -13,9 +13,10 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_expf.c,v 1.10 2005/11/30 04:56:49 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" @@ -23,8 +24,6 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_expf.c,v 1.10 2005/11/30 04: static const float one = 1.0, halF[2] = {0.5,-0.5,}, -huge = 1.0e+30, -twom100 = 7.8886090522e-31, /* 2**-100=0x0d800000 */ o_threshold= 8.8721679688e+01, /* 0x42b17180 */ u_threshold= -1.0397208405e+02, /* 0xc2cff1b5 */ ln2HI[2] ={ 6.9314575195e-01, /* 0x3f317200 */ @@ -32,16 +31,21 @@ ln2HI[2] ={ 6.9314575195e-01, /* 0x3f317200 */ ln2LO[2] ={ 1.4286067653e-06, /* 0x35bfbe8e */ -1.4286067653e-06,}, /* 0xb5bfbe8e */ invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */ -P1 = 1.6666667163e-01, /* 0x3e2aaaab */ -P2 = -2.7777778450e-03, /* 0xbb360b61 */ -P3 = 6.6137559770e-05, /* 0x388ab355 */ -P4 = -1.6533901999e-06, /* 0xb5ddea0e */ -P5 = 4.1381369442e-08; /* 0x3331bb4c */ +/* + * Domain [-0.34568, 0.34568], range ~[-4.278e-9, 4.447e-9]: + * |x*(exp(x)+1)/(exp(x)-1) - p(x)| < 2**-27.74 + */ +P1 = 1.6666625440e-1, /* 0xaaaa8f.0p-26 */ +P2 = -2.7667332906e-3; /* -0xb55215.0p-32 */ + +static volatile float +huge = 1.0e+30, +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; + float y,hi=0.0,lo=0.0,c,t,twopk; int32_t k=0,xsb; u_int32_t hx; @@ -69,27 +73,26 @@ __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 < 0x31800000) { /* when |x|<2**-28 */ + else if(hx < 0x39000000) { /* when |x|<2**-14 */ if(huge+x>one) return one+x;/* trigger inexact */ } else k = 0; /* x is now in primary range */ t = x*x; - c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + if(k >= -125) + SET_FLOAT_WORD(twopk,0x3f800000+(k<<23)); + else + SET_FLOAT_WORD(twopk,0x3f800000+((k+100)<<23)); + c = x - t*(P1+t*P2); if(k==0) return one-((x*c)/(c-(float)2.0)-x); else y = one-((lo-(x*c)/((float)2.0-c))-hi); if(k >= -125) { - u_int32_t hy; - GET_FLOAT_WORD(hy,y); - SET_FLOAT_WORD(y,hy+(k<<23)); /* add k to y's exponent */ - return y; + if(k==128) return y*2.0F*0x1p127F; + return y*twopk; } else { - u_int32_t hy; - GET_FLOAT_WORD(hy,y); - SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */ - return y*twom100; + return y*twopk*twom100; } } diff --git a/libm/src/e_fmod.c b/libm/upstream-freebsd/lib/msun/src/e_fmod.c index 3b3c169..720aa03 100644 --- a/libm/src/e_fmod.c +++ b/libm/upstream-freebsd/lib/msun/src/e_fmod.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_fmod.c,v 1.9 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * __ieee754_fmod(x,y) diff --git a/libm/src/e_fmodf.c b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c index 8b487ac..52ce373 100644 --- a/libm/src/e_fmodf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_fmodf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * __ieee754_fmodf(x,y) diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmodl.c b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c new file mode 100644 index 0000000..e315f76 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c @@ -0,0 +1,149 @@ +/* @(#)e_fmod.c 1.3 95/01/18 */ +/*- + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <stdint.h> + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define BIAS (LDBL_MAX_EXP - 1) + +#if LDBL_MANL_SIZE > 32 +typedef uint64_t manl_t; +#else +typedef uint32_t manl_t; +#endif + +#if LDBL_MANH_SIZE > 32 +typedef uint64_t manh_t; +#else +typedef uint32_t manh_t; +#endif + +/* + * These macros add and remove an explicit integer bit in front of the + * fractional mantissa, if the architecture doesn't have such a bit by + * default already. + */ +#ifdef LDBL_IMPLICIT_NBIT +#define SET_NBIT(hx) ((hx) | (1ULL << LDBL_MANH_SIZE)) +#define HFRAC_BITS LDBL_MANH_SIZE +#else +#define SET_NBIT(hx) (hx) +#define HFRAC_BITS (LDBL_MANH_SIZE - 1) +#endif + +#define MANL_SHIFT (LDBL_MANL_SIZE - 1) + +static const long double one = 1.0, Zero[] = {0.0, -0.0,}; + +/* + * fmodl(x,y) + * Return x mod y in exact arithmetic + * Method: shift and subtract + * + * Assumptions: + * - The low part of the mantissa fits in a manl_t exactly. + * - The high part of the mantissa fits in an int64_t with enough room + * for an explicit integer bit in front of the fractional bits. + */ +long double +fmodl(long double x, long double y) +{ + union IEEEl2bits ux, uy; + int64_t hx,hz; /* We need a carry bit even if LDBL_MANH_SIZE is 32. */ + manh_t hy; + manl_t lx,ly,lz; + int ix,iy,n,sx; + + ux.e = x; + uy.e = y; + sx = ux.bits.sign; + + /* purge off exception values */ + if((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */ + (ux.bits.exp == BIAS + LDBL_MAX_EXP) || /* or x not finite */ + (uy.bits.exp == BIAS + LDBL_MAX_EXP && + ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */ + return (x*y)/(x*y); + if(ux.bits.exp<=uy.bits.exp) { + if((ux.bits.exp<uy.bits.exp) || + (ux.bits.manh<=uy.bits.manh && + (ux.bits.manh<uy.bits.manh || + ux.bits.manl<uy.bits.manl))) { + return x; /* |x|<|y| return x or x-y */ + } + if(ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl) { + return Zero[sx]; /* |x|=|y| return x*0*/ + } + } + + /* determine ix = ilogb(x) */ + if(ux.bits.exp == 0) { /* subnormal x */ + ux.e *= 0x1.0p512; + ix = ux.bits.exp - (BIAS + 512); + } else { + ix = ux.bits.exp - BIAS; + } + + /* determine iy = ilogb(y) */ + if(uy.bits.exp == 0) { /* subnormal y */ + uy.e *= 0x1.0p512; + iy = uy.bits.exp - (BIAS + 512); + } else { + iy = uy.bits.exp - BIAS; + } + + /* set up {hx,lx}, {hy,ly} and align y to x */ + hx = SET_NBIT(ux.bits.manh); + hy = SET_NBIT(uy.bits.manh); + lx = ux.bits.manl; + ly = uy.bits.manl; + + /* fix point fmod */ + n = ix - iy; + + while(n--) { + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; + if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;} + else { + if ((hz|lz)==0) /* return sign(x)*0 */ + return Zero[sx]; + hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz; + } + } + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; + if(hz>=0) {hx=hz;lx=lz;} + + /* convert back to floating value and restore the sign */ + if((hx|lx)==0) /* return sign(x)*0 */ + return Zero[sx]; + while(hx<(1ULL<<HFRAC_BITS)) { /* normalize x */ + hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx; + iy -= 1; + } + ux.bits.manh = hx; /* The mantissa is truncated here if needed. */ + ux.bits.manl = lx; + if (iy < LDBL_MIN_EXP) { + ux.bits.exp = iy + (BIAS + 512); + ux.e *= 0x1p-512; + } else { + ux.bits.exp = iy + BIAS; + } + x = ux.e * one; /* create necessary signal */ + return x; /* exact output */ +} diff --git a/libm/src/e_gamma.c b/libm/upstream-freebsd/lib/msun/src/e_gamma.c index f52ff17..28fb5cc 100644 --- a/libm/src/e_gamma.c +++ b/libm/upstream-freebsd/lib/msun/src/e_gamma.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gamma.c,v 1.7 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_gamma(x) * Return the logarithm of the Gamma function of x. diff --git a/libm/src/e_gamma_r.c b/libm/upstream-freebsd/lib/msun/src/e_gamma_r.c index be8339d..2c423dc 100644 --- a/libm/src/e_gamma_r.c +++ b/libm/upstream-freebsd/lib/msun/src/e_gamma_r.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gamma_r.c,v 1.7 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_gamma_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function diff --git a/libm/src/e_gammaf.c b/libm/upstream-freebsd/lib/msun/src/e_gammaf.c index b5c2ec1..c1b1668 100644 --- a/libm/src/e_gammaf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_gammaf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gammaf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_gammaf(x) * Return the logarithm of the Gamma function of x. diff --git a/libm/src/e_gammaf_r.c b/libm/upstream-freebsd/lib/msun/src/e_gammaf_r.c index d4300c3..9d7831b 100644 --- a/libm/src/e_gammaf_r.c +++ b/libm/upstream-freebsd/lib/msun/src/e_gammaf_r.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gammaf_r.c,v 1.7 2002/05/28 18:15:03 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_gammaf_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function diff --git a/libm/src/e_hypot.c b/libm/upstream-freebsd/lib/msun/src/e_hypot.c index 11385f5..2398e98 100644 --- a/libm/src/e_hypot.c +++ b/libm/upstream-freebsd/lib/msun/src/e_hypot.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypot.c,v 1.9 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_hypot(x,y) * @@ -47,13 +46,15 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypot.c,v 1.9 2005/02/04 18: * than 1 ulps (units in the last place) */ +#include <float.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); @@ -61,14 +62,15 @@ __ieee754_hypot(double x, double y) GET_HIGH_WORD(hb,y); hb &= 0x7fffffff; if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} - SET_HIGH_WORD(a,ha); /* a <- |a| */ - SET_HIGH_WORD(b,hb); /* b <- |b| */ + a = fabs(a); + b = fabs(b); if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */ k=0; if(ha > 0x5f300000) { /* a>2**500 */ if(ha >= 0x7ff00000) { /* Inf or NaN */ u_int32_t low; - w = a+b; /* for sNaN */ + /* Use original arg order iff result is NaN; quieten sNaNs. */ + w = fabs(x+0.0)-fabs(y+0.0); GET_LOW_WORD(low,a); if(((ha&0xfffff)|low)==0) w = a; GET_LOW_WORD(low,b); @@ -123,3 +125,7 @@ __ieee754_hypot(double x, double y) return t1*w; } else return w; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(hypot, hypotl); +#endif diff --git a/libm/src/e_hypotf.c b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c index 354075a..6d083e4 100644 --- a/libm/src/e_hypotf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypotf.c,v 1.9 2002/05/28 18:15:03 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -23,7 +22,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypotf.c,v 1.9 2002/05/28 18 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); @@ -31,13 +30,14 @@ __ieee754_hypotf(float x, float y) GET_FLOAT_WORD(hb,y); hb &= 0x7fffffff; if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} - SET_FLOAT_WORD(a,ha); /* a <- |a| */ - SET_FLOAT_WORD(b,hb); /* b <- |b| */ + a = fabsf(a); + b = fabsf(b); if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */ k=0; if(ha > 0x58800000) { /* a>2**50 */ if(ha >= 0x7f800000) { /* Inf or NaN */ - w = a+b; /* for sNaN */ + /* Use original arg order iff result is NaN; quieten sNaNs. */ + w = fabsf(x+0.0F)-fabsf(y+0.0F); if(ha == 0x7f800000) w = a; if(hb == 0x7f800000) w = b; return w; @@ -72,7 +72,7 @@ __ieee754_hypotf(float x, float y) a = a+a; SET_FLOAT_WORD(y1,hb&0xfffff000); y2 = b - y1; - SET_FLOAT_WORD(t1,ha+0x00800000); + SET_FLOAT_WORD(t1,(ha+0x00800000)&0xfffff000); t2 = a - t1; w = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b))); } diff --git a/libm/upstream-freebsd/lib/msun/src/e_hypotl.c b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c new file mode 100644 index 0000000..7b5ab89 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c @@ -0,0 +1,124 @@ +/* From: @(#)e_hypot.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* long double version of hypot(). See e_hypot.c for most comments. */ + +#include <float.h> + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define GET_LDBL_MAN(h, l, v) do { \ + union IEEEl2bits uv; \ + \ + uv.e = v; \ + h = uv.bits.manh; \ + l = uv.bits.manl; \ +} while (0) + +#undef GET_HIGH_WORD +#define GET_HIGH_WORD(i, v) GET_LDBL_EXPSIGN(i, v) +#undef SET_HIGH_WORD +#define SET_HIGH_WORD(v, i) SET_LDBL_EXPSIGN(v, i) + +#define DESW(exp) (exp) /* delta expsign word */ +#define ESW(exp) (MAX_EXP - 1 + (exp)) /* expsign word */ +#define MANT_DIG LDBL_MANT_DIG +#define MAX_EXP LDBL_MAX_EXP + +#if LDBL_MANL_SIZE > 32 +typedef uint64_t man_t; +#else +typedef uint32_t man_t; +#endif + +long double +hypotl(long double x, long double y) +{ + long double a=x,b=y,t1,t2,y1,y2,w; + int32_t j,k,ha,hb; + + GET_HIGH_WORD(ha,x); + ha &= 0x7fff; + GET_HIGH_WORD(hb,y); + hb &= 0x7fff; + if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} + a = fabsl(a); + b = fabsl(b); + if((ha-hb)>DESW(MANT_DIG+7)) {return a+b;} /* x/y > 2**(MANT_DIG+7) */ + k=0; + if(ha > ESW(MAX_EXP/2-12)) { /* a>2**(MAX_EXP/2-12) */ + if(ha >= ESW(MAX_EXP)) { /* Inf or NaN */ + man_t manh, manl; + /* Use original arg order iff result is NaN; quieten sNaNs. */ + w = fabsl(x+0.0)-fabsl(y+0.0); + GET_LDBL_MAN(manh,manl,a); + if (manh == LDBL_NBIT && manl == 0) w = a; + GET_LDBL_MAN(manh,manl,b); + if (hb >= ESW(MAX_EXP) && manh == LDBL_NBIT && manl == 0) w = b; + return w; + } + /* scale a and b by 2**-(MAX_EXP/2+88) */ + ha -= DESW(MAX_EXP/2+88); hb -= DESW(MAX_EXP/2+88); + k += MAX_EXP/2+88; + SET_HIGH_WORD(a,ha); + SET_HIGH_WORD(b,hb); + } + if(hb < ESW(-(MAX_EXP/2-12))) { /* b < 2**-(MAX_EXP/2-12) */ + if(hb <= 0) { /* subnormal b or 0 */ + man_t manh, manl; + GET_LDBL_MAN(manh,manl,b); + if((manh|manl)==0) return a; + t1=0; + SET_HIGH_WORD(t1,ESW(MAX_EXP-2)); /* t1=2^(MAX_EXP-2) */ + b *= t1; + a *= t1; + k -= MAX_EXP-2; + } else { /* scale a and b by 2^(MAX_EXP/2+88) */ + ha += DESW(MAX_EXP/2+88); + hb += DESW(MAX_EXP/2+88); + k -= MAX_EXP/2+88; + SET_HIGH_WORD(a,ha); + SET_HIGH_WORD(b,hb); + } + } + /* medium size a and b */ + w = a-b; + if (w>b) { + t1 = a; + union IEEEl2bits uv; + uv.e = t1; uv.bits.manl = 0; t1 = uv.e; + t2 = a-t1; + w = sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); + } else { + a = a+a; + y1 = b; + union IEEEl2bits uv; + uv.e = y1; uv.bits.manl = 0; y1 = uv.e; + y2 = b - y1; + t1 = a; + uv.e = t1; uv.bits.manl = 0; t1 = uv.e; + t2 = a - t1; + w = sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b))); + } + if(k!=0) { + u_int32_t high; + t1 = 1.0; + GET_HIGH_WORD(high,t1); + SET_HIGH_WORD(t1,high+DESW(k)); + return t1*w; + } else return w; +} diff --git a/libm/src/e_j0.c b/libm/upstream-freebsd/lib/msun/src/e_j0.c index d99bf11..8320f25 100644 --- a/libm/src/e_j0.c +++ b/libm/upstream-freebsd/lib/msun/src/e_j0.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j0.c,v 1.8 2005/02/04 18:26:05 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_j0(x), __ieee754_y0(x) * Bessel function of the first and second kinds of order zero. diff --git a/libm/src/e_j0f.c b/libm/upstream-freebsd/lib/msun/src/e_j0f.c index 6b566bf..c45faf3 100644 --- a/libm/src/e_j0f.c +++ b/libm/upstream-freebsd/lib/msun/src/e_j0f.c @@ -1,6 +1,5 @@ /* e_j0f.c -- float version of e_j0.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Bugs in __ieee754_j0f and __ieee754_y0f fixed by Scott Turner 01/16/2010 */ /* @@ -14,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j0f.c,v 1.7 2002/05/28 18:15:03 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -64,7 +62,7 @@ __ieee754_j0f(float x) * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) */ - if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*cc)/sqrtf(x); + if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x); else { u = pzerof(x); v = qzerof(x); z = invsqrtpi*(u*cc-v*ss)/sqrtf(x); @@ -108,7 +106,7 @@ __ieee754_y0f(float x) int32_t hx,ix; GET_FLOAT_WORD(hx,x); - ix = hx&0x7fffffff; + ix = 0x7fffffff&hx; /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */ if(ix>=0x7f800000) return one/(x+x*x); if(ix==0) return -one/zero; @@ -138,7 +136,7 @@ __ieee754_y0f(float x) if ((s*c)<zero) cc = z/ss; else ss = z/cc; } - if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*ss)/sqrtf(x); + if(ix>0x80000000) z = (invsqrtpi*ss)/sqrtf(x); else { u = pzerof(x); v = qzerof(x); z = invsqrtpi*(u*ss+v*cc)/sqrtf(x); diff --git a/libm/src/e_j1.c b/libm/upstream-freebsd/lib/msun/src/e_j1.c index 4dbf222..63800ad 100644 --- a/libm/src/e_j1.c +++ b/libm/upstream-freebsd/lib/msun/src/e_j1.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j1.c,v 1.8 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_j1(x), __ieee754_y1(x) * Bessel function of the first and second kinds of order zero. diff --git a/libm/src/e_j1f.c b/libm/upstream-freebsd/lib/msun/src/e_j1f.c index ea05774..88e2d83 100644 --- a/libm/src/e_j1f.c +++ b/libm/upstream-freebsd/lib/msun/src/e_j1f.c @@ -1,6 +1,5 @@ /* e_j1f.c -- float version of e_j1.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Bug in __ieee754_j1f fixed by Scott Turner 1/16/2010 */ /* @@ -14,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j1f.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -65,7 +63,7 @@ __ieee754_j1f(float x) * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x) * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x) */ - if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*cc)/sqrtf(y); + if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y); else { u = ponef(y); v = qonef(y); z = invsqrtpi*(u*cc-v*ss)/sqrtf(y); diff --git a/libm/src/e_jn.c b/libm/upstream-freebsd/lib/msun/src/e_jn.c index 413b22d..8b0bc62 100644 --- a/libm/src/e_jn.c +++ b/libm/upstream-freebsd/lib/msun/src/e_jn.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_jn.c,v 1.9 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * __ieee754_jn(n, x), __ieee754_yn(n, x) @@ -201,7 +200,12 @@ __ieee754_jn(int n, double x) } } } - b = (t*__ieee754_j0(x)/b); + z = __ieee754_j0(x); + w = __ieee754_j1(x); + if (fabs(z) >= fabs(w)) + b = (t*z/b); + else + b = (t*w/a); } } if(sgn==1) return -b; else return b; diff --git a/libm/src/e_jnf.c b/libm/upstream-freebsd/lib/msun/src/e_jnf.c index a61fb68..f564aec 100644 --- a/libm/src/e_jnf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_jnf.c @@ -13,15 +13,13 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_jnf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" static const float -invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */ two = 2.0000000000e+00, /* 0x40000000 */ one = 1.0000000000e+00; /* 0x3F800000 */ @@ -154,7 +152,12 @@ __ieee754_jnf(int n, float x) } } } - b = (t*__ieee754_j0f(x)/b); + z = __ieee754_j0f(x); + w = __ieee754_j1f(x); + if (fabsf(z) >= fabsf(w)) + b = (t*z/b); + else + b = (t*w/a); } } if(sgn==1) return -b; else return b; @@ -186,7 +189,7 @@ __ieee754_ynf(int n, float x) b = __ieee754_y1f(x); /* quit if b is -inf */ GET_FLOAT_WORD(ib,b); - for(i=1; i<n && (((uint32_t)ib) != 0xff800000); i++){ + for(i=1;i<n&&ib!=0xff800000;i++){ temp = b; b = ((float)(i+i)/x)*b - a; GET_FLOAT_WORD(ib,b); diff --git a/libm/src/e_lgamma.c b/libm/upstream-freebsd/lib/msun/src/e_lgamma.c index 87ad41a..4674d9b 100644 --- a/libm/src/e_lgamma.c +++ b/libm/upstream-freebsd/lib/msun/src/e_lgamma.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgamma.c,v 1.8 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_lgamma(x) * Return the logarithm of the Gamma function of x. diff --git a/libm/src/e_lgamma_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c index 68dbfd0..1cff592 100644 --- a/libm/src/e_lgamma_r.c +++ b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c @@ -12,9 +12,8 @@ * */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgamma_r.c,v 1.8 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_lgamma_r(x, signgamp) * Reentrant version of the logarithm of the Gamma function @@ -76,10 +75,11 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgamma_r.c,v 1.8 2005/02/04 * * 5. Special Cases * lgamma(2+s) ~ s*(1-Euler) for tiny s - * lgamma(1)=lgamma(2)=0 - * lgamma(x) ~ -log(x) for tiny x - * lgamma(0) = lgamma(inf) = inf - * lgamma(-integer) = +-inf + * lgamma(1) = lgamma(2) = 0 + * lgamma(x) ~ -log(|x|) for tiny x + * lgamma(0) = lgamma(neg.integer) = inf and raise divide-by-zero + * lgamma(inf) = inf + * lgamma(-inf) = inf (bug for bug compatible with C99!?) * */ @@ -205,11 +205,12 @@ double __ieee754_lgamma_r(double x, int *signgamp) { double t,y,z,nadj,p,p1,p2,p3,q,r,w; - int i,hx,lx,ix; + int32_t hx; + int i,lx,ix; EXTRACT_WORDS(hx,lx,x); - /* purge off +-inf, NaN, +-0, and negative arguments */ + /* purge off +-inf, NaN, +-0, tiny and negative arguments */ *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7ff00000) return x*x; @@ -268,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/libm/src/e_lgammaf.c b/libm/upstream-freebsd/lib/msun/src/e_lgammaf.c index b1f48d5..1e2c552 100644 --- a/libm/src/e_lgammaf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_lgammaf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgammaf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_lgammaf(x) * Return the logarithm of the Gamma function of x. diff --git a/libm/src/e_lgammaf_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c index 3b55208..e2d90ef 100644 --- a/libm/src/e_lgammaf_r.c +++ b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgammaf_r.c,v 1.9 2005/11/28 08:32:15 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -139,11 +138,12 @@ float __ieee754_lgammaf_r(float x, int *signgamp) { float t,y,z,nadj,p,p1,p2,p3,q,r,w; - int i,hx,ix; + int32_t hx; + int i,ix; GET_FLOAT_WORD(hx,x); - /* purge off +-inf, NaN, +-0, and negative arguments */ + /* purge off +-inf, NaN, +-0, tiny and negative arguments */ *signgamp = 1; ix = hx&0x7fffffff; if(ix>=0x7f800000) return x*x; @@ -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/libm/src/e_log.c b/libm/upstream-freebsd/lib/msun/src/e_log.c index 2dbf057..68bc107 100644 --- a/libm/src/e_log.c +++ b/libm/upstream-freebsd/lib/msun/src/e_log.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log.c,v 1.10 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_log(x) * Return the logrithm of x @@ -66,6 +65,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log.c,v 1.10 2005/02/04 18:2 * to produce the hexadecimal values shown. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -82,6 +83,7 @@ Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ static const double zero = 0.0; +static volatile double vzero = 0.0; double __ieee754_log(double x) @@ -95,7 +97,7 @@ __ieee754_log(double x) k=0; if (hx < 0x00100000) { /* x < 2**-1022 */ if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ + return -two54/vzero; /* 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); @@ -107,9 +109,15 @@ __ieee754_log(double x) SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ k += (i>>20); f = x-1.0; - if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ - if(f==zero) if(k==0) return zero; else {dk=(double)k; - return dk*ln2_hi+dk*ln2_lo;} + if((0x000fffff&(2+hx))<3) { /* -2**-20 <= f < 2**-20 */ + if(f==zero) { + if(k==0) { + return zero; + } else { + dk=(double)k; + return dk*ln2_hi+dk*ln2_lo; + } + } R = f*f*(0.5-0.33333333333333333*f); if(k==0) return f-R; else {dk=(double)k; return dk*ln2_hi-((R-dk*ln2_lo)-f);} @@ -133,3 +141,7 @@ __ieee754_log(double x) return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(log, logl); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/e_log10.c b/libm/upstream-freebsd/lib/msun/src/e_log10.c new file mode 100644 index 0000000..3c89ed2 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_log10.c @@ -0,0 +1,94 @@ + +/* @(#)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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * 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 <float.h> + +#include "math.h" +#include "math_private.h" +#include "k_log.h" + +static const double +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */ +ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */ +log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ +log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ + +static const double zero = 0.0; +static volatile double vzero = 0.0; + +double +__ieee754_log10(double x) +{ + 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/vzero; /* 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); + + /* See e_log2.c for most details. */ + hi = f - hfsq; + SET_LOW_WORD(hi,0); + 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; +} + +#if (LDBL_MANT_DIG == 53) +__weak_reference(log10, log10l); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/e_log10f.c b/libm/upstream-freebsd/lib/msun/src/e_log10f.c new file mode 100644 index 0000000..9856df2 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_log10f.c @@ -0,0 +1,72 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * Float version of e_log10.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 */ +ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ +ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ +log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ +log10_2lo = 7.9034151668e-07; /* 0x355427db */ + +static const float zero = 0.0; +static volatile float vzero = 0.0; + +float +__ieee754_log10f(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/vzero; /* 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); + + /* 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 = (f - hi) - hfsq + r; + return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + + y*log10_2hi; +} diff --git a/libm/upstream-freebsd/lib/msun/src/e_log2.c b/libm/upstream-freebsd/lib/msun/src/e_log2.c new file mode 100644 index 0000000..4766cdb --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_log2.c @@ -0,0 +1,117 @@ + +/* @(#)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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * 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 <float.h> + +#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; +static volatile double vzero = 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/vzero; /* 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; +} + +#if (LDBL_MANT_DIG == 53) +__weak_reference(log2, log2l); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/e_log2f.c b/libm/upstream-freebsd/lib/msun/src/e_log2f.c new file mode 100644 index 0000000..1794484 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_log2f.c @@ -0,0 +1,82 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * 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; +static volatile float vzero = 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/vzero; /* 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/libm/src/e_logf.c b/libm/upstream-freebsd/lib/msun/src/e_logf.c index 7cee2ab..ec3985f 100644 --- a/libm/src/e_logf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_logf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_logf.c,v 1.8 2005/11/12 18:20:09 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -31,6 +30,7 @@ Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ static const float zero = 0.0; +static volatile float vzero = 0.0; float __ieee754_logf(float x) @@ -43,7 +43,7 @@ __ieee754_logf(float x) k=0; if (ix < 0x00800000) { /* x < 2**-126 */ if ((ix&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ + return -two25/vzero; /* log(+-0)=-inf */ if (ix<0) return (x-x)/zero; /* log(-#) = NaN */ k -= 25; x *= two25; /* subnormal number, scale up x */ GET_FLOAT_WORD(ix,x); @@ -55,9 +55,15 @@ __ieee754_logf(float x) SET_FLOAT_WORD(x,ix|(i^0x3f800000)); /* normalize x or x/2 */ k += (i>>23); f = x-(float)1.0; - if((0x007fffff&(15+ix))<16) { /* |f| < 2**-20 */ - if(f==zero) if(k==0) return zero; else {dk=(float)k; - return dk*ln2_hi+dk*ln2_lo;} + if((0x007fffff&(0x8000+ix))<0xc000) { /* -2**-9 <= f < 2**-9 */ + if(f==zero) { + if(k==0) { + return zero; + } else { + dk=(float)k; + return dk*ln2_hi+dk*ln2_lo; + } + } R = f*f*((float)0.5-(float)0.33333333333333333*f); if(k==0) return f-R; else {dk=(float)k; return dk*ln2_hi-((R-dk*ln2_lo)-f);} diff --git a/libm/src/e_pow.c b/libm/upstream-freebsd/lib/msun/src/e_pow.c index d213132..7607a4a 100644 --- a/libm/src/e_pow.c +++ b/libm/upstream-freebsd/lib/msun/src/e_pow.c @@ -9,9 +9,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_pow.c,v 1.11 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_pow(x,y) return x**y * @@ -110,10 +109,13 @@ __ieee754_pow(double x, double y) /* y==zero: x**0 = 1 */ if((iy|ly)==0) return one; - /* +-NaN return x+y */ + /* 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))) - return x+y; + return (x+0.0)+(y+0.0); /* determine if y is an odd int when x < 0 * yisint = 0 ... y is not an integer @@ -139,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/libm/src/e_powf.c b/libm/upstream-freebsd/lib/msun/src/e_powf.c index 41f08dd..5c46478 100644 --- a/libm/src/e_powf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_powf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_powf.c,v 1.12 2004/06/01 19:33:30 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -47,8 +46,8 @@ lg2_h = 6.93145752e-01, /* 0x3f317200 */ lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ -cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */ -cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */ +cp_h = 9.6191406250e-01, /* 0x3f764000 =12b cp */ +cp_l = -1.1736857402e-04, /* 0xb8f623c6 =tail of cp_h */ ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ @@ -68,10 +67,13 @@ __ieee754_powf(float x, float y) /* y==zero: x**0 = 1 */ if(iy==0) return one; - /* +-NaN return x+y */ + /* 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) - return x+y; + return (x+0.0F)+(y+0.0F); /* determine if y is an odd int when x < 0 * yisint = 0 ... y is not an integer @@ -91,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/libm/src/e_rem_pio2.c b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2.c index 121ba29..be2630b 100644 --- a/libm/src/e_rem_pio2.c +++ b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2.c @@ -10,11 +10,11 @@ * is preserved. * ==================================================== * + * Optimized by Bruce D. Evans. */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_rem_pio2.c,v 1.8 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_rem_pio2(x,y) * @@ -22,36 +22,12 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_rem_pio2.c,v 1.8 2005/02/04 * use __kernel_rem_pio2() */ +#include <float.h> + #include "math.h" #include "math_private.h" /* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ -static const int32_t two_over_pi[] = { -0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, -0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, -0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, -0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, -0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, -0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, -0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, -0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, -0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, -0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, -0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, -}; - -static const int32_t npio2_hw[] = { -0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, -0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, -0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, -0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, -0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, -0x404858EB, 0x404921FB, -}; - -/* * invpio2: 53 bits of 2/pi * pio2_1: first 33 bit of pi/2 * pio2_1t: pi/2 - pio2_1 @@ -63,7 +39,6 @@ static const int32_t npio2_hw[] = { static const double zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ -half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ @@ -73,51 +48,96 @@ pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ - int32_t __ieee754_rem_pio2(double x, double *y) +#ifdef INLINE_REM_PIO2 +static __inline __always_inline +#endif +int +__ieee754_rem_pio2(double x, double *y) { double z,w,t,r,fn; - double tx[3]; + double tx[3],ty[2]; int32_t e0,i,j,nx,n,ix,hx; u_int32_t low; GET_HIGH_WORD(hx,x); /* high word of x */ ix = hx&0x7fffffff; +#if 0 /* Must be handled in caller. */ if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ {y[0] = x; y[1] = 0; return 0;} - if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */ - if(hx>0) { - z = x - pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ +#endif + if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ + if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ + goto medium; /* cancellation -- use medium case */ + if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ + if (hx > 0) { + z = x - pio2_1; /* one round good to 85 bits */ y[0] = z - pio2_1t; y[1] = (z-y[0])-pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z -= pio2_2; - y[0] = z - pio2_2t; - y[1] = (z-y[0])-pio2_2t; - } - return 1; - } else { /* negative x */ - z = x + pio2_1; - if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ + return 1; + } else { + z = x + pio2_1; y[0] = z + pio2_1t; y[1] = (z-y[0])+pio2_1t; - } else { /* near pi/2, use 33+33+53 bit pi */ - z += pio2_2; - y[0] = z + pio2_2t; - y[1] = (z-y[0])+pio2_2t; + return -1; + } + } else { + if (hx > 0) { + z = x - 2*pio2_1; + y[0] = z - 2*pio2_1t; + y[1] = (z-y[0])-2*pio2_1t; + return 2; + } else { + z = x + 2*pio2_1; + y[0] = z + 2*pio2_1t; + y[1] = (z-y[0])+2*pio2_1t; + return -2; } - return -1; } } - if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */ - t = fabs(x); - n = (int32_t) (t*invpio2+half); - fn = (double)n; - r = t-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 85 bit */ - if(n<32&&ix!=npio2_hw[n-1]) { - y[0] = r-w; /* quick check no cancellation */ + if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ + if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ + if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ + goto medium; + if (hx > 0) { + z = x - 3*pio2_1; + y[0] = z - 3*pio2_1t; + y[1] = (z-y[0])-3*pio2_1t; + return 3; + } else { + z = x + 3*pio2_1; + y[0] = z + 3*pio2_1t; + y[1] = (z-y[0])+3*pio2_1t; + return -3; + } } else { + if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ + goto medium; + if (hx > 0) { + z = x - 4*pio2_1; + y[0] = z - 4*pio2_1t; + y[1] = (z-y[0])-4*pio2_1t; + return 4; + } else { + z = x + 4*pio2_1; + y[0] = z + 4*pio2_1t; + y[1] = (z-y[0])+4*pio2_1t; + return -4; + } + } + } + if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ +medium: + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + STRICT_ASSIGN(double,fn,x*invpio2+0x1.8p52); + fn = fn-0x1.8p52; +#ifdef HAVE_EFFICIENT_IRINT + n = irint(fn); +#else + n = (int32_t)fn; +#endif + r = x-fn*pio2_1; + w = fn*pio2_1t; /* 1st round good to 85 bit */ + { u_int32_t high; j = ix>>20; y[0] = r-w; @@ -141,8 +161,7 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ } } y[1] = (r-y[0])-w; - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - else return n; + return n; } /* * all other (large) arguments @@ -152,9 +171,8 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ } /* set z = scalbn(|x|,ilogb(x)-23) */ GET_LOW_WORD(low,x); - SET_LOW_WORD(z,low); e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */ - SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20))); + INSERT_WORDS(z, ix - ((int32_t)(e0<<20)), low); for(i=0;i<2;i++) { tx[i] = (double)((int32_t)(z)); z = (z-tx[i])*two24; @@ -162,7 +180,7 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ tx[2] = z; nx = 3; while(tx[nx-1]==zero) nx--; /* skip zero term */ - n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi); - if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} - return n; + n = __kernel_rem_pio2(tx,ty,e0,nx,1); + if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;} + y[0] = ty[0]; y[1] = ty[1]; return n; } diff --git a/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c new file mode 100644 index 0000000..f1ee7a0 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c @@ -0,0 +1,84 @@ +/* e_rem_pio2f.c -- float version of e_rem_pio2.c + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + * Debugged and optimized by Bruce D. Evans. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* __ieee754_rem_pio2f(x,y) + * + * return the remainder of x rem pi/2 in *y + * use double precision for everything except passing x + * use __kernel_rem_pio2() for large x + */ + +#include <float.h> + +#include "math.h" +#include "math_private.h" + +/* + * invpio2: 53 bits of 2/pi + * pio2_1: first 25 bits of pi/2 + * pio2_1t: pi/2 - pio2_1 + */ + +static const double +invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ +pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */ +pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ + +#ifdef INLINE_REM_PIO2F +static __inline __always_inline +#endif +int +__ieee754_rem_pio2f(float x, double *y) +{ + double w,r,fn; + double tx[1],ty[1]; + float z; + int32_t e0,n,ix,hx; + + GET_FLOAT_WORD(hx,x); + ix = hx&0x7fffffff; + /* 33+53 bit pi is good enough for medium size */ + if(ix<0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + STRICT_ASSIGN(double,fn,x*invpio2+0x1.8p52); + fn = fn-0x1.8p52; +#ifdef HAVE_EFFICIENT_IRINT + n = irint(fn); +#else + n = (int32_t)fn; +#endif + r = x-fn*pio2_1; + w = fn*pio2_1t; + *y = r-w; + return n; + } + /* + * all other (large) arguments + */ + if(ix>=0x7f800000) { /* x is inf or NaN */ + *y=x-x; return 0; + } + /* set z = scalbn(|x|,ilogb(|x|)-23) */ + e0 = (ix>>23)-150; /* e0 = ilogb(|x|)-23; */ + SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23))); + tx[0] = z; + n = __kernel_rem_pio2(tx,ty,e0,1,0); + if(hx<0) {*y = -ty[0]; return -n;} + *y = ty[0]; return n; +} diff --git a/libm/src/e_remainder.c b/libm/upstream-freebsd/lib/msun/src/e_remainder.c index 46932a2..9be513b 100644 --- a/libm/src/e_remainder.c +++ b/libm/upstream-freebsd/lib/msun/src/e_remainder.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_remainder.c,v 1.10 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_remainder(x,p) * Return : @@ -24,6 +23,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_remainder.c,v 1.10 2005/02/0 * Based on fmod() return x-[x/p]chopped*p exactlp. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -48,7 +49,7 @@ __ieee754_remainder(double x, double p) if((hx>=0x7ff00000)|| /* x not finite */ ((hp>=0x7ff00000)&& /* p is NaN */ (((hp-0x7ff00000)|lp)!=0))) - return (x*p)/(x*p); + return ((long double)x*p)/((long double)x*p); if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */ @@ -68,6 +69,11 @@ __ieee754_remainder(double x, double p) } } GET_HIGH_WORD(hx,x); + if ((hx&0x7fffffff)==0) hx = 0; SET_HIGH_WORD(x,hx^sx); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(remainder, remainderl); +#endif diff --git a/libm/src/e_remainderf.c b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c index 4045088..b0014ae 100644 --- a/libm/src/e_remainderf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_remainderf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -40,7 +39,7 @@ __ieee754_remainderf(float x, float p) if(hp==0) return (x*p)/(x*p); /* p = 0 */ if((hx>=0x7f800000)|| /* x not finite */ ((hp>0x7f800000))) /* p is NaN */ - return (x*p)/(x*p); + return ((long double)x*p)/((long double)x*p); if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p); /* now x < 2p */ @@ -60,6 +59,7 @@ __ieee754_remainderf(float x, float p) } } GET_FLOAT_WORD(hx,x); + if ((hx&0x7fffffff)==0) hx = 0; SET_FLOAT_WORD(x,hx^sx); return x; } diff --git a/libm/i387/s_llrint.S b/libm/upstream-freebsd/lib/msun/src/e_remainderl.c index b266e5c..03327b8 100644 --- a/libm/i387/s_llrint.S +++ b/libm/upstream-freebsd/lib/msun/src/e_remainderl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,13 +24,15 @@ * SUCH DAMAGE. */ -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_llrint.S,v 1.1 2005/01/11 23:10:53 das Exp $"); - -ENTRY(llrint) - fldl 4(%esp) - subl $8,%esp - fistpll (%esp) - popl %eax - popl %edx - ret +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <math.h> + +long double +remainderl(long double x, long double y) +{ + int quo; + + return (remquol(x, y, &quo)); +} diff --git a/libm/src/e_scalb.c b/libm/upstream-freebsd/lib/msun/src/e_scalb.c index b81666e..c0a7b5b 100644 --- a/libm/src/e_scalb.c +++ b/libm/upstream-freebsd/lib/msun/src/e_scalb.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_scalb.c,v 1.12 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * __ieee754_scalb(x, fn) is provide for diff --git a/libm/src/e_scalbf.c b/libm/upstream-freebsd/lib/msun/src/e_scalbf.c index 07ac1f4..d49e904 100644 --- a/libm/src/e_scalbf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_scalbf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_scalbf.c,v 1.10 2005/12/06 20:12:38 obrien Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -42,5 +41,3 @@ __ieee754_scalbf(float x, float fn) return scalbnf(x,(int)fn); #endif } - -__weak_reference(scalbf, ldexpf); diff --git a/libm/src/e_sinh.c b/libm/upstream-freebsd/lib/msun/src/e_sinh.c index 7584b27..17442d0 100644 --- a/libm/src/e_sinh.c +++ b/libm/upstream-freebsd/lib/msun/src/e_sinh.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sinh.c,v 1.9 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_sinh(x) * Method : @@ -41,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); @@ -67,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/libm/src/e_sinhf.c b/libm/upstream-freebsd/lib/msun/src/e_sinhf.c index 02e753f..1be2dc3 100644 --- a/libm/src/e_sinhf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_sinhf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sinhf.c,v 1.8 2005/11/13 00:41:46 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -25,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); @@ -49,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/libm/src/e_sqrt.c b/libm/upstream-freebsd/lib/msun/src/e_sqrt.c index d75cb10..12fb56e 100644 --- a/libm/src/e_sqrt.c +++ b/libm/upstream-freebsd/lib/msun/src/e_sqrt.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrt.c,v 1.10 2005/02/04 18:26:06 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __ieee754_sqrt(x) * Return correctly rounded sqrt. @@ -85,6 +84,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrt.c,v 1.10 2005/02/04 18: *--------------- */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -187,6 +188,10 @@ __ieee754_sqrt(double x) return z; } +#if (LDBL_MANT_DIG == 53) +__weak_reference(sqrt, sqrtl); +#endif + /* Other methods (use floating-point arithmetic) ------------- diff --git a/libm/src/e_sqrtf.c b/libm/upstream-freebsd/lib/msun/src/e_sqrtf.c index edc9ef2..7eba4d0 100644 --- a/libm/src/e_sqrtf.c +++ b/libm/upstream-freebsd/lib/msun/src/e_sqrtf.c @@ -14,7 +14,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrtf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif #include "math.h" diff --git a/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c b/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c new file mode 100644 index 0000000..92b84de --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c @@ -0,0 +1,159 @@ +/*- + * Copyright (c) 2007 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <fenv.h> +#include <float.h> + +#include "fpmath.h" +#include "math.h" + +/* Return (x + ulp) for normal positive x. Assumes no overflow. */ +static inline long double +inc(long double x) +{ + union IEEEl2bits u; + + u.e = x; + if (++u.bits.manl == 0) { + if (++u.bits.manh == 0) { + u.bits.exp++; + u.bits.manh |= LDBL_NBIT; + } + } + return (u.e); +} + +/* Return (x - ulp) for normal positive x. Assumes no underflow. */ +static inline long double +dec(long double x) +{ + union IEEEl2bits u; + + u.e = x; + if (u.bits.manl-- == 0) { + if (u.bits.manh-- == LDBL_NBIT) { + u.bits.exp--; + u.bits.manh |= LDBL_NBIT; + } + } + return (u.e); +} + +#pragma STDC FENV_ACCESS ON + +/* + * This is slow, but simple and portable. You should use hardware sqrt + * if possible. + */ + +long double +sqrtl(long double x) +{ + union IEEEl2bits u; + int k, r; + long double lo, xn; + fenv_t env; + + u.e = x; + + /* If x = NaN, then sqrt(x) = NaN. */ + /* If x = Inf, then sqrt(x) = Inf. */ + /* If x = -Inf, then sqrt(x) = NaN. */ + if (u.bits.exp == LDBL_MAX_EXP * 2 - 1) + return (x * x + x); + + /* If x = +-0, then sqrt(x) = +-0. */ + if ((u.bits.manh | u.bits.manl | u.bits.exp) == 0) + return (x); + + /* If x < 0, then raise invalid and return NaN */ + if (u.bits.sign) + return ((x - x) / (x - x)); + + feholdexcept(&env); + + if (u.bits.exp == 0) { + /* Adjust subnormal numbers. */ + u.e *= 0x1.0p514; + k = -514; + } else { + k = 0; + } + /* + * u.e is a normal number, so break it into u.e = e*2^n where + * u.e = (2*e)*2^2k for odd n and u.e = (4*e)*2^2k for even n. + */ + if ((u.bits.exp - 0x3ffe) & 1) { /* n is odd. */ + k += u.bits.exp - 0x3fff; /* 2k = n - 1. */ + u.bits.exp = 0x3fff; /* u.e in [1,2). */ + } else { + k += u.bits.exp - 0x4000; /* 2k = n - 2. */ + u.bits.exp = 0x4000; /* u.e in [2,4). */ + } + + /* + * Newton's iteration. + * Split u.e into a high and low part to achieve additional precision. + */ + xn = sqrt(u.e); /* 53-bit estimate of sqrtl(x). */ +#if LDBL_MANT_DIG > 100 + xn = (xn + (u.e / xn)) * 0.5; /* 106-bit estimate. */ +#endif + lo = u.e; + u.bits.manl = 0; /* Zero out lower bits. */ + lo = (lo - u.e) / xn; /* Low bits divided by xn. */ + xn = xn + (u.e / xn); /* High portion of estimate. */ + u.e = xn + lo; /* Combine everything. */ + u.bits.exp += (k >> 1) - 1; + + feclearexcept(FE_INEXACT); + r = fegetround(); + fesetround(FE_TOWARDZERO); /* Set to round-toward-zero. */ + xn = x / u.e; /* Chopped quotient (inexact?). */ + + if (!fetestexcept(FE_INEXACT)) { /* Quotient is exact. */ + if (xn == u.e) { + fesetenv(&env); + return (u.e); + } + /* Round correctly for inputs like x = y**2 - ulp. */ + xn = dec(xn); /* xn = xn - ulp. */ + } + + if (r == FE_TONEAREST) { + xn = inc(xn); /* xn = xn + ulp. */ + } else if (r == FE_UPWARD) { + u.e = inc(u.e); /* u.e = u.e + ulp. */ + xn = inc(xn); /* xn = xn + ulp. */ + } + u.e = u.e + xn; /* Chopped sum. */ + feupdateenv(&env); /* Restore env and raise inexact */ + u.bits.exp--; + return (u.e); +} diff --git a/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h b/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h new file mode 100644 index 0000000..02d2a2c --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h @@ -0,0 +1,184 @@ +/*- + * Copyright (c) 2004-2011 David Schultz <das@FreeBSD.ORG> + * 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$ + */ + +#ifndef _FENV_H_ +#error "This file is meant to be included only by <fenv.h>." +#endif + +/* + * This file implements the functionality of <fenv.h> on platforms that + * lack an FPU and use softfloat in libc for floating point. To use it, + * you must write an <fenv.h> that provides the following: + * + * - a typedef for fenv_t, which may be an integer or struct type + * - a typedef for fexcept_t (XXX This file assumes fexcept_t is a + * simple integer type containing the exception mask.) + * - definitions of FE_* constants for the five exceptions and four + * rounding modes in IEEE 754, as described in fenv(3) + * - a definition, and the corresponding external symbol, for FE_DFL_ENV + * - a macro __set_env(env, flags, mask, rnd), which sets the given fenv_t + * from the exception flags, mask, and rounding mode + * - macros __env_flags(env), __env_mask(env), and __env_round(env), which + * extract fields from an fenv_t + * - a definition of __fenv_static + * + * If the architecture supports an optional FPU, it's recommended that you + * define fenv_t and fexcept_t to match the hardware ABI. Otherwise, it + * doesn't matter how you define them. + */ + +extern int __softfloat_float_exception_flags; +extern int __softfloat_float_exception_mask; +extern int __softfloat_float_rounding_mode; +void __softfloat_float_raise(int); + +__fenv_static inline int +feclearexcept(int __excepts) +{ + + __softfloat_float_exception_flags &= ~__excepts; + return (0); +} + +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) +{ + + *__flagp = __softfloat_float_exception_flags & __excepts; + return (0); +} + +__fenv_static inline int +fesetexceptflag(const fexcept_t *__flagp, int __excepts) +{ + + __softfloat_float_exception_flags &= ~__excepts; + __softfloat_float_exception_flags |= *__flagp & __excepts; + return (0); +} + +__fenv_static inline int +feraiseexcept(int __excepts) +{ + + __softfloat_float_raise(__excepts); + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + + return (__softfloat_float_exception_flags & __excepts); +} + +__fenv_static inline int +fegetround(void) +{ + + return (__softfloat_float_rounding_mode); +} + +__fenv_static inline int +fesetround(int __round) +{ + + __softfloat_float_rounding_mode = __round; + return (0); +} + +__fenv_static inline int +fegetenv(fenv_t *__envp) +{ + + __set_env(*__envp, __softfloat_float_exception_flags, + __softfloat_float_exception_mask, __softfloat_float_rounding_mode); + return (0); +} + +__fenv_static inline int +feholdexcept(fenv_t *__envp) +{ + fenv_t __env; + + fegetenv(__envp); + __softfloat_float_exception_flags = 0; + __softfloat_float_exception_mask = 0; + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + + __softfloat_float_exception_flags = __env_flags(*__envp); + __softfloat_float_exception_mask = __env_mask(*__envp); + __softfloat_float_rounding_mode = __env_round(*__envp); + return (0); +} + +__fenv_static inline int +feupdateenv(const fenv_t *__envp) +{ + int __oflags = __softfloat_float_exception_flags; + + fesetenv(__envp); + feraiseexcept(__oflags); + return (0); +} + +#if __BSD_VISIBLE + +/* We currently provide no external definitions of the functions below. */ + +static inline int +feenableexcept(int __mask) +{ + int __omask = __softfloat_float_exception_mask; + + __softfloat_float_exception_mask |= __mask; + return (__omask); +} + +static inline int +fedisableexcept(int __mask) +{ + int __omask = __softfloat_float_exception_mask; + + __softfloat_float_exception_mask &= ~__mask; + return (__omask); +} + +static inline int +fegetexcept(void) +{ + + return (__softfloat_float_exception_mask); +} + +#endif /* __BSD_VISIBLE */ diff --git a/libm/src/s_isfinite.c b/libm/upstream-freebsd/lib/msun/src/imprecise.c index 394505d..a7503bf 100644 --- a/libm/src/s_isfinite.c +++ b/libm/upstream-freebsd/lib/msun/src/imprecise.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> + * Copyright (c) 2013 David Chisnall * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,36 +23,47 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_isfinite.c,v 1.1 2004/07/09 03:32:39 das Exp $ + * $FreeBSD$ */ +#include <float.h> #include <math.h> -#include "fpmath.h" - -int -__isfinite(double d) -{ - union IEEEd2bits u; - - u.d = d; - return (u.bits.exp != 2047); -} +/* + * If long double is not the same size as double, then these will lose + * precision and we should emit a warning whenever something links against + * them. + */ +#if (LDBL_MANT_DIG > 53) +#define WARN_IMPRECISE(x) \ + __warn_references(x, # x " has lower than advertised precision"); +#else +#define WARN_IMPRECISE(x) +#endif +/* + * Declare the functions as weak variants so that other libraries providing + * real versions can override them. + */ +#define DECLARE_WEAK(x)\ + __weak_reference(imprecise_## x, x);\ + WARN_IMPRECISE(x) -int -__isfinitef(float f) +long double +imprecise_powl(long double x, long double y) { - union IEEEf2bits u; - u.f = f; - return (u.bits.exp != 255); + return pow(x, y); } +DECLARE_WEAK(powl); -int -__isfinitel(long double e) -{ - union IEEEl2bits u; +#define DECLARE_IMPRECISE(f) \ + long double imprecise_ ## f ## l(long double v) { return f(v); }\ + DECLARE_WEAK(f ## l) - u.e = e; - return (u.bits.exp != 32767); -} +DECLARE_IMPRECISE(cosh); +DECLARE_IMPRECISE(erfc); +DECLARE_IMPRECISE(erf); +DECLARE_IMPRECISE(lgamma); +DECLARE_IMPRECISE(sinh); +DECLARE_IMPRECISE(tanh); +DECLARE_IMPRECISE(tgamma); diff --git a/libm/src/k_cos.c b/libm/upstream-freebsd/lib/msun/src/k_cos.c index 00916d7..c4702e6 100644 --- a/libm/src/k_cos.c +++ b/libm/upstream-freebsd/lib/msun/src/k_cos.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_cos.c,v 1.10 2005/10/26 12:36:18 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * __kernel_cos( x, y ) @@ -72,8 +71,9 @@ __kernel_cos(double x, double y) double hz,z,r,w; z = x*x; - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); - hz = (float)0.5*z; + w = z*z; + r = z*(C1+z*(C2+z*C3)) + w*w*(C4+z*(C5+z*C6)); + hz = 0.5*z; w = one-hz; return w + (((one-w)-hz) + (z*r-x*y)); } diff --git a/libm/src/k_cosf.c b/libm/upstream-freebsd/lib/msun/src/k_cosf.c index ff08d5f..f7a2c0a 100644 --- a/libm/src/k_cosf.c +++ b/libm/upstream-freebsd/lib/msun/src/k_cosf.c @@ -15,9 +15,8 @@ */ #ifndef INLINE_KERNEL_COSDF -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_cosf.c,v 1.15 2005/11/30 11:51:17 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #endif #include "math.h" @@ -32,7 +31,7 @@ C2 = -0x16c087e80f1e27.0p-62, /* -0.00138867637746099294692 */ C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */ #ifdef INLINE_KERNEL_COSDF -extern inline +static __inline #endif float __kernel_cosdf(double x) diff --git a/libm/upstream-freebsd/lib/msun/src/k_exp.c b/libm/upstream-freebsd/lib/msun/src/k_exp.c new file mode 100644 index 0000000..f592f69 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/k_exp.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> + +#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/libm/upstream-freebsd/lib/msun/src/k_expf.c b/libm/upstream-freebsd/lib/msun/src/k_expf.c new file mode 100644 index 0000000..548a008 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/k_expf.c @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> + +#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) +{ + float 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/libm/upstream-freebsd/lib/msun/src/k_log.h b/libm/upstream-freebsd/lib/msun/src/k_log.h new file mode 100644 index 0000000..aaff8bd --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/k_log.h @@ -0,0 +1,100 @@ + +/* @(#)e_log.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * 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 + * term of the polynomial are done by the caller for increased accuracy + * when different bases are used. + * + * Method : + * 1. Argument Reduction: find k and f such that + * x = 2^k * (1+f), + * where sqrt(2)/2 < 1+f < sqrt(2) . + * + * 2. Approximation of log(1+f). + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) + * = 2s + 2/3 s**3 + 2/5 s**5 + ....., + * = 2s + s*R + * We use a special Reme algorithm on [0,0.1716] to generate + * a polynomial of degree 14 to approximate R The maximum error + * of this polynomial approximation is bounded by 2**-58.45. In + * other words, + * 2 4 6 8 10 12 14 + * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s + * (the values of Lg1 to Lg7 are listed in the program) + * and + * | 2 14 | -58.45 + * | Lg1*s +...+Lg7*s - R(z) | <= 2 + * | | + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. + * In order to guarantee error in log below 1ulp, we compute log + * by + * log(1+f) = f - s*(f - R) (if f is not too large) + * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) + * + * 3. Finally, log(x) = k*ln2 + log(1+f). + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) + * Here ln2 is split into two floating point number: + * ln2_hi + ln2_lo, + * where n*ln2_hi is always exact for |n| < 2000. + * + * Special cases: + * log(x) is NaN with signal if x < 0 (including -INF) ; + * log(+INF) is +INF; log(0) is -INF with signal; + * log(NaN) is that NaN with no signal. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +static const double +Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ +Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ +Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ +Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ +Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ +Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ +Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ + +/* + * We always inline k_log1p(), since doing so produces a + * substantial performance improvement (~40% on amd64). + */ +static inline double +k_log1p(double f) +{ + double hfsq,s,z,R,w,t1,t2; + + s = f/(2.0+f); + z = s*s; + w = z*z; + t1= w*(Lg2+w*(Lg4+w*Lg6)); + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); + R = t2+t1; + hfsq=0.5*f*f; + return s*(hfsq+R); +} diff --git a/libm/upstream-freebsd/lib/msun/src/k_logf.h b/libm/upstream-freebsd/lib/msun/src/k_logf.h new file mode 100644 index 0000000..71c547e --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/k_logf.h @@ -0,0 +1,39 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * Float version of k_log.h. See the latter for most comments. + */ + +static const float +/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ +Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ +Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ +Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ +Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ + +static inline float +k_log1pf(float f) +{ + float hfsq,s,z,R,w,t1,t2; + + s = f/((float)2.0+f); + z = s*s; + w = z*z; + t1= w*(Lg2+w*Lg4); + t2= z*(Lg1+w*Lg3); + R = t2+t1; + hfsq=(float)0.5*f*f; + return s*(hfsq+R); +} diff --git a/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c b/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c new file mode 100644 index 0000000..3942441 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c @@ -0,0 +1,443 @@ + +/* @(#)k_rem_pio2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * __kernel_rem_pio2(x,y,e0,nx,prec) + * double x[],y[]; int e0,nx,prec; + * + * __kernel_rem_pio2 return the last three digits of N with + * y = x - N*pi/2 + * so that |y| < pi/2. + * + * The method is to compute the integer (mod 8) and fraction parts of + * (2/pi)*x without doing the full multiplication. In general we + * skip the part of the product that are known to be a huge integer ( + * more accurately, = 0 mod 8 ). Thus the number of operations are + * independent of the exponent of the input. + * + * (2/pi) is represented by an array of 24-bit integers in ipio2[]. + * + * Input parameters: + * x[] The input value (must be positive) is broken into nx + * pieces of 24-bit integers in double precision format. + * x[i] will be the i-th 24 bit of x. The scaled exponent + * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 + * match x's up to 24 bits. + * + * Example of breaking a double positive z into x[0]+x[1]+x[2]: + * e0 = ilogb(z)-23 + * z = scalbn(z,-e0) + * for i = 0,1,2 + * x[i] = floor(z) + * z = (z-x[i])*2**24 + * + * + * y[] output result in an array of double precision numbers. + * The dimension of y[] is: + * 24-bit precision 1 + * 53-bit precision 2 + * 64-bit precision 2 + * 113-bit precision 3 + * The actual value is the sum of them. Thus for 113-bit + * precison, one may have to do something like: + * + * long double t,w,r_head, r_tail; + * t = (long double)y[2] + (long double)y[1]; + * w = (long double)y[0]; + * r_head = t+w; + * r_tail = w - (r_head - t); + * + * e0 The exponent of x[0]. Must be <= 16360 or you need to + * expand the ipio2 table. + * + * nx dimension of x[] + * + * prec an integer indicating the precision: + * 0 24 bits (single) + * 1 53 bits (double) + * 2 64 bits (extended) + * 3 113 bits (quad) + * + * External function: + * double scalbn(), floor(); + * + * + * Here is the description of some local variables: + * + * jk jk+1 is the initial number of terms of ipio2[] needed + * in the computation. The minimum and recommended value + * for jk is 3,4,4,6 for single, double, extended, and quad. + * jk+1 must be 2 larger than you might expect so that our + * recomputation test works. (Up to 24 bits in the integer + * part (the 24 bits of it that we compute) and 23 bits in + * the fraction part may be lost to cancelation before we + * recompute.) + * + * jz local integer variable indicating the number of + * terms of ipio2[] used. + * + * jx nx - 1 + * + * jv index for pointing to the suitable ipio2[] for the + * computation. In general, we want + * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 + * is an integer. Thus + * e0-3-24*jv >= 0 or (e0-3)/24 >= jv + * Hence jv = max(0,(e0-3)/24). + * + * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. + * + * q[] double array with integral value, representing the + * 24-bits chunk of the product of x and 2/pi. + * + * q0 the corresponding exponent of q[0]. Note that the + * exponent for q[i] would be q0-24*i. + * + * PIo2[] double precision array, obtained by cutting pi/2 + * into 24 bits chunks. + * + * f[] ipio2[] in floating point + * + * iq[] integer array by breaking up q[] in 24-bits chunk. + * + * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] + * + * ih integer. If >0 it indicates q[] is >= 0.5, hence + * it also indicates the *sign* of the result. + * + */ + + +/* + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include <float.h> + +#include "math.h" +#include "math_private.h" + +static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ + +/* + * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi + * + * integer array, contains the (24*i)-th to (24*i+23)-th + * bit of 2/pi after binary point. The corresponding + * floating value is + * + * ipio2[i] * 2^(-24(i+1)). + * + * NB: This table must have at least (e0-3)/24 + jk terms. + * For quad precision (e0 <= 16360, jk = 6), this is 686. + */ +static const int32_t ipio2[] = { +0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, +0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, +0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, +0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, +0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, +0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, +0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, +0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, +0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, +0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, +0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, + +#if LDBL_MAX_EXP > 1024 +#if LDBL_MAX_EXP > 16384 +#error "ipio2 table needs to be expanded" +#endif +0x47C419, 0xC367CD, 0xDCE809, 0x2A8359, 0xC4768B, 0x961CA6, +0xDDAF44, 0xD15719, 0x053EA5, 0xFF0705, 0x3F7E33, 0xE832C2, +0xDE4F98, 0x327DBB, 0xC33D26, 0xEF6B1E, 0x5EF89F, 0x3A1F35, +0xCAF27F, 0x1D87F1, 0x21907C, 0x7C246A, 0xFA6ED5, 0x772D30, +0x433B15, 0xC614B5, 0x9D19C3, 0xC2C4AD, 0x414D2C, 0x5D000C, +0x467D86, 0x2D71E3, 0x9AC69B, 0x006233, 0x7CD2B4, 0x97A7B4, +0xD55537, 0xF63ED7, 0x1810A3, 0xFC764D, 0x2A9D64, 0xABD770, +0xF87C63, 0x57B07A, 0xE71517, 0x5649C0, 0xD9D63B, 0x3884A7, +0xCB2324, 0x778AD6, 0x23545A, 0xB91F00, 0x1B0AF1, 0xDFCE19, +0xFF319F, 0x6A1E66, 0x615799, 0x47FBAC, 0xD87F7E, 0xB76522, +0x89E832, 0x60BFE6, 0xCDC4EF, 0x09366C, 0xD43F5D, 0xD7DE16, +0xDE3B58, 0x929BDE, 0x2822D2, 0xE88628, 0x4D58E2, 0x32CAC6, +0x16E308, 0xCB7DE0, 0x50C017, 0xA71DF3, 0x5BE018, 0x34132E, +0x621283, 0x014883, 0x5B8EF5, 0x7FB0AD, 0xF2E91E, 0x434A48, +0xD36710, 0xD8DDAA, 0x425FAE, 0xCE616A, 0xA4280A, 0xB499D3, +0xF2A606, 0x7F775C, 0x83C2A3, 0x883C61, 0x78738A, 0x5A8CAF, +0xBDD76F, 0x63A62D, 0xCBBFF4, 0xEF818D, 0x67C126, 0x45CA55, +0x36D9CA, 0xD2A828, 0x8D61C2, 0x77C912, 0x142604, 0x9B4612, +0xC459C4, 0x44C5C8, 0x91B24D, 0xF31700, 0xAD43D4, 0xE54929, +0x10D5FD, 0xFCBE00, 0xCC941E, 0xEECE70, 0xF53E13, 0x80F1EC, +0xC3E7B3, 0x28F8C7, 0x940593, 0x3E71C1, 0xB3092E, 0xF3450B, +0x9C1288, 0x7B20AB, 0x9FB52E, 0xC29247, 0x2F327B, 0x6D550C, +0x90A772, 0x1FE76B, 0x96CB31, 0x4A1679, 0xE27941, 0x89DFF4, +0x9794E8, 0x84E6E2, 0x973199, 0x6BED88, 0x365F5F, 0x0EFDBB, +0xB49A48, 0x6CA467, 0x427271, 0x325D8D, 0xB8159F, 0x09E5BC, +0x25318D, 0x3974F7, 0x1C0530, 0x010C0D, 0x68084B, 0x58EE2C, +0x90AA47, 0x02E774, 0x24D6BD, 0xA67DF7, 0x72486E, 0xEF169F, +0xA6948E, 0xF691B4, 0x5153D1, 0xF20ACF, 0x339820, 0x7E4BF5, +0x6863B2, 0x5F3EDD, 0x035D40, 0x7F8985, 0x295255, 0xC06437, +0x10D86D, 0x324832, 0x754C5B, 0xD4714E, 0x6E5445, 0xC1090B, +0x69F52A, 0xD56614, 0x9D0727, 0x50045D, 0xDB3BB4, 0xC576EA, +0x17F987, 0x7D6B49, 0xBA271D, 0x296996, 0xACCCC6, 0x5414AD, +0x6AE290, 0x89D988, 0x50722C, 0xBEA404, 0x940777, 0x7030F3, +0x27FC00, 0xA871EA, 0x49C266, 0x3DE064, 0x83DD97, 0x973FA3, +0xFD9443, 0x8C860D, 0xDE4131, 0x9D3992, 0x8C70DD, 0xE7B717, +0x3BDF08, 0x2B3715, 0xA0805C, 0x93805A, 0x921110, 0xD8E80F, +0xAF806C, 0x4BFFDB, 0x0F9038, 0x761859, 0x15A562, 0xBBCB61, +0xB989C7, 0xBD4010, 0x04F2D2, 0x277549, 0xF6B6EB, 0xBB22DB, +0xAA140A, 0x2F2689, 0x768364, 0x333B09, 0x1A940E, 0xAA3A51, +0xC2A31D, 0xAEEDAF, 0x12265C, 0x4DC26D, 0x9C7A2D, 0x9756C0, +0x833F03, 0xF6F009, 0x8C402B, 0x99316D, 0x07B439, 0x15200C, +0x5BC3D8, 0xC492F5, 0x4BADC6, 0xA5CA4E, 0xCD37A7, 0x36A9E6, +0x9492AB, 0x6842DD, 0xDE6319, 0xEF8C76, 0x528B68, 0x37DBFC, +0xABA1AE, 0x3115DF, 0xA1AE00, 0xDAFB0C, 0x664D64, 0xB705ED, +0x306529, 0xBF5657, 0x3AFF47, 0xB9F96A, 0xF3BE75, 0xDF9328, +0x3080AB, 0xF68C66, 0x15CB04, 0x0622FA, 0x1DE4D9, 0xA4B33D, +0x8F1B57, 0x09CD36, 0xE9424E, 0xA4BE13, 0xB52333, 0x1AAAF0, +0xA8654F, 0xA5C1D2, 0x0F3F0B, 0xCD785B, 0x76F923, 0x048B7B, +0x721789, 0x53A6C6, 0xE26E6F, 0x00EBEF, 0x584A9B, 0xB7DAC4, +0xBA66AA, 0xCFCF76, 0x1D02D1, 0x2DF1B1, 0xC1998C, 0x77ADC3, +0xDA4886, 0xA05DF7, 0xF480C6, 0x2FF0AC, 0x9AECDD, 0xBC5C3F, +0x6DDED0, 0x1FC790, 0xB6DB2A, 0x3A25A3, 0x9AAF00, 0x9353AD, +0x0457B6, 0xB42D29, 0x7E804B, 0xA707DA, 0x0EAA76, 0xA1597B, +0x2A1216, 0x2DB7DC, 0xFDE5FA, 0xFEDB89, 0xFDBE89, 0x6C76E4, +0xFCA906, 0x70803E, 0x156E85, 0xFF87FD, 0x073E28, 0x336761, +0x86182A, 0xEABD4D, 0xAFE7B3, 0x6E6D8F, 0x396795, 0x5BBF31, +0x48D784, 0x16DF30, 0x432DC7, 0x356125, 0xCE70C9, 0xB8CB30, +0xFD6CBF, 0xA200A4, 0xE46C05, 0xA0DD5A, 0x476F21, 0xD21262, +0x845CB9, 0x496170, 0xE0566B, 0x015299, 0x375550, 0xB7D51E, +0xC4F133, 0x5F6E13, 0xE4305D, 0xA92E85, 0xC3B21D, 0x3632A1, +0xA4B708, 0xD4B1EA, 0x21F716, 0xE4698F, 0x77FF27, 0x80030C, +0x2D408D, 0xA0CD4F, 0x99A520, 0xD3A2B3, 0x0A5D2F, 0x42F9B4, +0xCBDA11, 0xD0BE7D, 0xC1DB9B, 0xBD17AB, 0x81A2CA, 0x5C6A08, +0x17552E, 0x550027, 0xF0147F, 0x8607E1, 0x640B14, 0x8D4196, +0xDEBE87, 0x2AFDDA, 0xB6256B, 0x34897B, 0xFEF305, 0x9EBFB9, +0x4F6A68, 0xA82A4A, 0x5AC44F, 0xBCF82D, 0x985AD7, 0x95C7F4, +0x8D4D0D, 0xA63A20, 0x5F57A4, 0xB13F14, 0x953880, 0x0120CC, +0x86DD71, 0xB6DEC9, 0xF560BF, 0x11654D, 0x6B0701, 0xACB08C, +0xD0C0B2, 0x485551, 0x0EFB1E, 0xC37295, 0x3B06A3, 0x3540C0, +0x7BDC06, 0xCC45E0, 0xFA294E, 0xC8CAD6, 0x41F3E8, 0xDE647C, +0xD8649B, 0x31BED9, 0xC397A4, 0xD45877, 0xC5E369, 0x13DAF0, +0x3C3ABA, 0x461846, 0x5F7555, 0xF5BDD2, 0xC6926E, 0x5D2EAC, +0xED440E, 0x423E1C, 0x87C461, 0xE9FD29, 0xF3D6E7, 0xCA7C22, +0x35916F, 0xC5E008, 0x8DD7FF, 0xE26A6E, 0xC6FDB0, 0xC10893, +0x745D7C, 0xB2AD6B, 0x9D6ECD, 0x7B723E, 0x6A11C6, 0xA9CFF7, +0xDF7329, 0xBAC9B5, 0x5100B7, 0x0DB2E2, 0x24BA74, 0x607DE5, +0x8AD874, 0x2C150D, 0x0C1881, 0x94667E, 0x162901, 0x767A9F, +0xBEFDFD, 0xEF4556, 0x367ED9, 0x13D9EC, 0xB9BA8B, 0xFC97C4, +0x27A831, 0xC36EF1, 0x36C594, 0x56A8D8, 0xB5A8B4, 0x0ECCCF, +0x2D8912, 0x34576F, 0x89562C, 0xE3CE99, 0xB920D6, 0xAA5E6B, +0x9C2A3E, 0xCC5F11, 0x4A0BFD, 0xFBF4E1, 0x6D3B8E, 0x2C86E2, +0x84D4E9, 0xA9B4FC, 0xD1EEEF, 0xC9352E, 0x61392F, 0x442138, +0xC8D91B, 0x0AFC81, 0x6A4AFB, 0xD81C2F, 0x84B453, 0x8C994E, +0xCC2254, 0xDC552A, 0xD6C6C0, 0x96190B, 0xB8701A, 0x649569, +0x605A26, 0xEE523F, 0x0F117F, 0x11B5F4, 0xF5CBFC, 0x2DBC34, +0xEEBC34, 0xCC5DE8, 0x605EDD, 0x9B8E67, 0xEF3392, 0xB817C9, +0x9B5861, 0xBC57E1, 0xC68351, 0x103ED8, 0x4871DD, 0xDD1C2D, +0xA118AF, 0x462C21, 0xD7F359, 0x987AD9, 0xC0549E, 0xFA864F, +0xFC0656, 0xAE79E5, 0x362289, 0x22AD38, 0xDC9367, 0xAAE855, +0x382682, 0x9BE7CA, 0xA40D51, 0xB13399, 0x0ED7A9, 0x480569, +0xF0B265, 0xA7887F, 0x974C88, 0x36D1F9, 0xB39221, 0x4A827B, +0x21CF98, 0xDC9F40, 0x5547DC, 0x3A74E1, 0x42EB67, 0xDF9DFE, +0x5FD45E, 0xA4677B, 0x7AACBA, 0xA2F655, 0x23882B, 0x55BA41, +0x086E59, 0x862A21, 0x834739, 0xE6E389, 0xD49EE5, 0x40FB49, +0xE956FF, 0xCA0F1C, 0x8A59C5, 0x2BFA94, 0xC5C1D3, 0xCFC50F, +0xAE5ADB, 0x86C547, 0x624385, 0x3B8621, 0x94792C, 0x876110, +0x7B4C2A, 0x1A2C80, 0x12BF43, 0x902688, 0x893C78, 0xE4C4A8, +0x7BDBE5, 0xC23AC4, 0xEAF426, 0x8A67F7, 0xBF920D, 0x2BA365, +0xB1933D, 0x0B7CBD, 0xDC51A4, 0x63DD27, 0xDDE169, 0x19949A, +0x9529A8, 0x28CE68, 0xB4ED09, 0x209F44, 0xCA984E, 0x638270, +0x237C7E, 0x32B90F, 0x8EF5A7, 0xE75614, 0x08F121, 0x2A9DB5, +0x4D7E6F, 0x5119A5, 0xABF9B5, 0xD6DF82, 0x61DD96, 0x023616, +0x9F3AC4, 0xA1A283, 0x6DED72, 0x7A8D39, 0xA9B882, 0x5C326B, +0x5B2746, 0xED3400, 0x7700D2, 0x55F4FC, 0x4D5901, 0x8071E0, +#endif + +}; + +static const double PIo2[] = { + 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ + 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ + 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ + 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ + 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ + 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ + 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ + 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ +}; + +static const double +zero = 0.0, +one = 1.0, +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ +twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ + +int +__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec) +{ + int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; + double z,fw,f[20],fq[20],q[20]; + + /* initialize jk*/ + jk = init_jk[prec]; + jp = jk; + + /* determine jx,jv,q0, note that 3>q0 */ + jx = nx-1; + jv = (e0-3)/24; if(jv<0) jv=0; + q0 = e0-24*(jv+1); + + /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ + j = jv-jx; m = jx+jk; + for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; + + /* compute q[0],q[1],...q[jk] */ + for (i=0;i<=jk;i++) { + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; + } + + jz = jk; +recompute: + /* distill q[] into iq[] reversingly */ + for(i=0,j=jz,z=q[jz];j>0;i++,j--) { + fw = (double)((int32_t)(twon24* z)); + iq[i] = (int32_t)(z-two24*fw); + z = q[j-1]+fw; + } + + /* compute n */ + z = scalbn(z,q0); /* actual value of z */ + z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ + n = (int32_t) z; + z -= (double)n; + ih = 0; + if(q0>0) { /* need iq[jz-1] to determine n */ + i = (iq[jz-1]>>(24-q0)); n += i; + iq[jz-1] -= i<<(24-q0); + ih = iq[jz-1]>>(23-q0); + } + else if(q0==0) ih = iq[jz-1]>>23; + else if(z>=0.5) ih=2; + + if(ih>0) { /* q > 0.5 */ + n += 1; carry = 0; + for(i=0;i<jz ;i++) { /* compute 1-q */ + j = iq[i]; + if(carry==0) { + if(j!=0) { + carry = 1; iq[i] = 0x1000000- j; + } + } else iq[i] = 0xffffff - j; + } + if(q0>0) { /* rare case: chance is 1 in 12 */ + switch(q0) { + case 1: + iq[jz-1] &= 0x7fffff; break; + case 2: + iq[jz-1] &= 0x3fffff; break; + } + } + if(ih==2) { + z = one - z; + if(carry!=0) z -= scalbn(one,q0); + } + } + + /* check if recomputation is needed */ + if(z==zero) { + j = 0; + for (i=jz-1;i>=jk;i--) j |= iq[i]; + if(j==0) { /* need recomputation */ + for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ + + for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ + f[jx+i] = (double) ipio2[jv+i]; + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + /* chop off zero terms */ + if(z==0.0) { + jz -= 1; q0 -= 24; + while(iq[jz]==0) { jz--; q0-=24;} + } else { /* break z into 24-bit if necessary */ + z = scalbn(z,-q0); + if(z>=two24) { + fw = (double)((int32_t)(twon24*z)); + iq[jz] = (int32_t)(z-two24*fw); + jz += 1; q0 += 24; + iq[jz] = (int32_t) fw; + } else iq[jz] = (int32_t) z ; + } + + /* convert integer "bit" chunk to floating-point value */ + fw = scalbn(one,q0); + for(i=jz;i>=0;i--) { + q[i] = fw*(double)iq[i]; fw*=twon24; + } + + /* compute PIo2[0,...,jp]*q[jz,...,0] */ + for(i=jz;i>=0;i--) { + for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; + fq[jz-i] = fw; + } + + /* compress fq[] into y[] */ + switch(prec) { + case 0: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + y[0] = (ih==0)? fw: -fw; + break; + case 1: + case 2: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + STRICT_ASSIGN(double,fw,fw); + y[0] = (ih==0)? fw: -fw; + fw = fq[0]-fw; + for (i=1;i<=jz;i++) fw += fq[i]; + y[1] = (ih==0)? fw: -fw; + break; + case 3: /* painful */ + for (i=jz;i>0;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (i=jz;i>1;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; + if(ih==0) { + y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; + } else { + y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; + } + } + return n&7; +} diff --git a/libm/src/k_sin.c b/libm/upstream-freebsd/lib/msun/src/k_sin.c index ae06a9d..12ee8c1 100644 --- a/libm/src/k_sin.c +++ b/libm/upstream-freebsd/lib/msun/src/k_sin.c @@ -11,9 +11,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_sin.c,v 1.10 2005/11/02 13:06:49 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __kernel_sin( x, y, iy) * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 @@ -60,11 +59,12 @@ S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ double __kernel_sin(double x, double y, int iy) { - double z,r,v; + double z,r,v,w; z = x*x; + w = z*z; + r = S2+z*(S3+z*S4) + z*w*(S5+z*S6); v = z*x; - r = S2+z*(S3+z*(S4+z*(S5+z*S6))); if(iy==0) return x+v*(S1+z*r); else return x-((z*(half*y-v*r)-y)-v*S1); } diff --git a/libm/src/k_sinf.c b/libm/upstream-freebsd/lib/msun/src/k_sinf.c index e45dc42..0841759 100644 --- a/libm/src/k_sinf.c +++ b/libm/upstream-freebsd/lib/msun/src/k_sinf.c @@ -15,9 +15,8 @@ */ #ifndef INLINE_KERNEL_SINDF -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_sinf.c,v 1.13 2005/11/30 11:51:17 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #endif #include "math.h" @@ -31,7 +30,7 @@ S3 = -0x1a00f9e2cae774.0p-65, /* -0.000198393348360966317347 */ S4 = 0x16cd878c3b46a7.0p-71; /* 0.0000027183114939898219064 */ #ifdef INLINE_KERNEL_SINDF -extern inline +static __inline #endif float __kernel_sindf(double x) diff --git a/libm/src/k_tan.c b/libm/upstream-freebsd/lib/msun/src/k_tan.c index 82fe155..2e86c3b 100644 --- a/libm/src/k_tan.c +++ b/libm/upstream-freebsd/lib/msun/src/k_tan.c @@ -11,9 +11,8 @@ */ /* INDENT OFF */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_tan.c,v 1.12 2005/11/02 14:01:45 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* __kernel_tan( x, y, k ) * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 diff --git a/libm/src/k_tanf.c b/libm/upstream-freebsd/lib/msun/src/k_tanf.c index 6574030..52f1aaa 100644 --- a/libm/src/k_tanf.c +++ b/libm/upstream-freebsd/lib/msun/src/k_tanf.c @@ -14,9 +14,8 @@ */ #ifndef INLINE_KERNEL_TANDF -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_tanf.c,v 1.20 2005/11/28 11:46:20 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #endif #include "math.h" @@ -34,7 +33,7 @@ T[] = { }; #ifdef INLINE_KERNEL_TANDF -extern inline +static __inline #endif float __kernel_tandf(double x, int iy) diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h new file mode 100644 index 0000000..8af2c65 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/math_private.h @@ -0,0 +1,764 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +/* + * from: @(#)fdlibm.h 5.1 93/09/24 + * $FreeBSD$ + */ + +#ifndef _MATH_PRIVATE_H_ +#define _MATH_PRIVATE_H_ + +#include <sys/types.h> +#include <machine/endian.h> + +/* + * The original fdlibm code used statements like: + * n0 = ((*(int*)&one)>>29)^1; * index of high word * + * ix0 = *(n0+(int*)&x); * high word of x * + * ix1 = *((1-n0)+(int*)&x); * low word of x * + * to dig two 32 bit words out of the 64 bit IEEE floating point + * value. That is non-ANSI, and, moreover, the gcc instruction + * scheduler gets it wrong. We instead use the following macros. + * Unlike the original code, we determine the endianness at compile + * time, not at run time; I don't see much benefit to selecting + * endianness at run time. + */ + +/* + * A union which permits us to convert between a double and two 32 bit + * ints. + */ + +#ifdef __arm__ +#if defined(__VFP_FP__) || defined(__ARM_EABI__) +#define IEEE_WORD_ORDER BYTE_ORDER +#else +#define IEEE_WORD_ORDER BIG_ENDIAN +#endif +#else /* __arm__ */ +#define IEEE_WORD_ORDER BYTE_ORDER +#endif + +#if IEEE_WORD_ORDER == BIG_ENDIAN + +typedef union +{ + double value; + struct + { + u_int32_t msw; + u_int32_t lsw; + } parts; + struct + { + u_int64_t w; + } xparts; +} ieee_double_shape_type; + +#endif + +#if IEEE_WORD_ORDER == LITTLE_ENDIAN + +typedef union +{ + double value; + struct + { + u_int32_t lsw; + u_int32_t msw; + } parts; + struct + { + u_int64_t w; + } xparts; +} ieee_double_shape_type; + +#endif + +/* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (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) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* Get the less significant 32 bit int from a double. */ + +#define GET_LOW_WORD(i,d) \ +do { \ + ieee_double_shape_type gl_u; \ + gl_u.value = (d); \ + (i) = gl_u.parts.lsw; \ +} while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (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) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + +/* Set the less significant 32 bits of a double from an int. */ + +#define SET_LOW_WORD(d,v) \ +do { \ + ieee_double_shape_type sl_u; \ + sl_u.value = (d); \ + sl_u.parts.lsw = (v); \ + (d) = sl_u.value; \ +} while (0) + +/* + * A union which permits us to convert between a float and a 32 bit + * int. + */ + +typedef union +{ + float value; + /* FIXME: Assumes 32 bit int. */ + unsigned int word; +} ieee_float_shape_type; + +/* Get a 32 bit int from a float. */ + +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ +} while (0) + +/* Set a float from a 32 bit int. */ + +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ +} while (0) + +/* + * Get expsign and mantissa as 16 bit and 64 bit ints from an 80 bit long + * double. + */ + +#define EXTRACT_LDBL80_WORDS(ix0,ix1,d) \ +do { \ + union IEEEl2bits ew_u; \ + ew_u.e = (d); \ + (ix0) = ew_u.xbits.expsign; \ + (ix1) = ew_u.xbits.man; \ +} while (0) + +/* + * Get expsign and mantissa as one 16 bit and two 64 bit ints from a 128 bit + * long double. + */ + +#define EXTRACT_LDBL128_WORDS(ix0,ix1,ix2,d) \ +do { \ + union IEEEl2bits ew_u; \ + ew_u.e = (d); \ + (ix0) = ew_u.xbits.expsign; \ + (ix1) = ew_u.xbits.manh; \ + (ix2) = ew_u.xbits.manl; \ +} 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 an 80 bit long double from a 16 bit int expsign and a 64 bit int + * mantissa. + */ + +#define INSERT_LDBL80_WORDS(d,ix0,ix1) \ +do { \ + union IEEEl2bits iw_u; \ + iw_u.xbits.expsign = (ix0); \ + iw_u.xbits.man = (ix1); \ + (d) = iw_u.e; \ +} while (0) + +/* + * Set a 128 bit long double from a 16 bit int expsign and two 64 bit ints + * comprising the mantissa. + */ + +#define INSERT_LDBL128_WORDS(d,ix0,ix1,ix2) \ +do { \ + union IEEEl2bits iw_u; \ + iw_u.xbits.expsign = (ix0); \ + iw_u.xbits.manh = (ix1); \ + iw_u.xbits.manl = (ix2); \ + (d) = iw_u.e; \ +} 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 __i386__ +/* Long double constants are broken on i386. */ +#define LD80C(m, ex, v) { \ + .xbits.man = __CONCAT(m, ULL), \ + .xbits.expsign = (0x3fff + (ex)) | ((v) < 0 ? 0x8000 : 0), \ +} +#else +/* The above works on non-i386 too, but we use this to check v. */ +#define LD80C(m, ex, v) { .e = (v), } +#endif + +#ifdef FLT_EVAL_METHOD +/* + * Attempt to get strict C99 semantics for assignment with non-C99 compilers. + */ +#if FLT_EVAL_METHOD == 0 || __GNUC__ == 0 +#define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval)) +#else +#define STRICT_ASSIGN(type, lval, rval) do { \ + volatile type __lval; \ + \ + if (sizeof(type) >= sizeof(long double)) \ + (lval) = (rval); \ + else { \ + __lval = (rval); \ + (lval) = __lval; \ + } \ +} while (0) +#endif +#endif /* FLT_EVAL_METHOD */ + +/* Support switching the mode to FP_PE if necessary. */ +#if defined(__i386__) && !defined(NO_FPSETPREC) +#define ENTERI() \ + long double __retval; \ + fp_prec_t __oprec; \ + \ + if ((__oprec = fpgetprec()) != FP_PE) \ + fpsetprec(FP_PE) +#define RETURNI(x) do { \ + __retval = (x); \ + if (__oprec != FP_PE) \ + fpsetprec(__oprec); \ + RETURNF(__retval); \ +} while (0) +#else +#define ENTERI(x) +#define RETURNI(x) RETURNF(x) +#endif + +/* Default return statement if hack*_t() is not used. */ +#define RETURNF(v) return (v) + +/* + * 2sum gives the same result as 2sumF without requiring |a| >= |b| or + * a == 0, but is slower. + */ +#define _2sum(a, b) do { \ + __typeof(a) __s, __w; \ + \ + __w = (a) + (b); \ + __s = __w - (a); \ + (b) = ((a) - (__w - __s)) + ((b) - __s); \ + (a) = __w; \ +} while (0) + +/* + * 2sumF algorithm. + * + * "Normalize" the terms in the infinite-precision expression a + b for + * the sum of 2 floating point values so that b is as small as possible + * relative to 'a'. (The resulting 'a' is the value of the expression in + * the same precision as 'a' and the resulting b is the rounding error.) + * |a| must be >= |b| or 0, b's type must be no larger than 'a's type, and + * exponent overflow or underflow must not occur. This uses a Theorem of + * Dekker (1971). See Knuth (1981) 4.2.2 Theorem C. The name "TwoSum" + * is apparently due to Skewchuk (1997). + * + * For this to always work, assignment of a + b to 'a' must not retain any + * extra precision in a + b. This is required by C standards but broken + * in many compilers. The brokenness cannot be worked around using + * STRICT_ASSIGN() like we do elsewhere, since the efficiency of this + * algorithm would be destroyed by non-null strict assignments. (The + * compilers are correct to be broken -- the efficiency of all floating + * point code calculations would be destroyed similarly if they forced the + * conversions.) + * + * Fortunately, a case that works well can usually be arranged by building + * any extra precision into the type of 'a' -- 'a' should have type float_t, + * double_t or long double. b's type should be no larger than 'a's type. + * Callers should use these types with scopes as large as possible, to + * reduce their own extra-precision and efficiciency problems. In + * particular, they shouldn't convert back and forth just to call here. + */ +#ifdef DEBUG +#define _2sumF(a, b) do { \ + __typeof(a) __w; \ + volatile __typeof(a) __ia, __ib, __r, __vw; \ + \ + __ia = (a); \ + __ib = (b); \ + assert(__ia == 0 || fabsl(__ia) >= fabsl(__ib)); \ + \ + __w = (a) + (b); \ + (b) = ((a) - __w) + (b); \ + (a) = __w; \ + \ + /* The next 2 assertions are weak if (a) is already long double. */ \ + assert((long double)__ia + __ib == (long double)(a) + (b)); \ + __vw = __ia + __ib; \ + __r = __ia - __vw; \ + __r += __ib; \ + assert(__vw == (a) && __r == (b)); \ +} while (0) +#else /* !DEBUG */ +#define _2sumF(a, b) do { \ + __typeof(a) __w; \ + \ + __w = (a) + (b); \ + (b) = ((a) - __w) + (b); \ + (a) = __w; \ +} while (0) +#endif /* DEBUG */ + +/* + * Set x += c, where x is represented in extra precision as a + b. + * x must be sufficiently normalized and sufficiently larger than c, + * and the result is then sufficiently normalized. + * + * The details of ordering are that |a| must be >= |c| (so that (a, c) + * can be normalized without extra work to swap 'a' with c). The details of + * the normalization are that b must be small relative to the normalized 'a'. + * Normalization of (a, c) makes the normalized c tiny relative to the + * normalized a, so b remains small relative to 'a' in the result. However, + * b need not ever be tiny relative to 'a'. For example, b might be about + * 2**20 times smaller than 'a' to give about 20 extra bits of precision. + * That is usually enough, and adding c (which by normalization is about + * 2**53 times smaller than a) cannot change b significantly. However, + * cancellation of 'a' with c in normalization of (a, c) may reduce 'a' + * significantly relative to b. The caller must ensure that significant + * cancellation doesn't occur, either by having c of the same sign as 'a', + * or by having |c| a few percent smaller than |a|. Pre-normalization of + * (a, b) may help. + * + * This is is a variant of an algorithm of Kahan (see Knuth (1981) 4.2.2 + * exercise 19). We gain considerable efficiency by requiring the terms to + * be sufficiently normalized and sufficiently increasing. + */ +#define _3sumF(a, b, c) do { \ + __typeof(a) __tmp; \ + \ + __tmp = (c); \ + _2sumF(__tmp, (a)); \ + (b) += (a); \ + (a) = __tmp; \ +} while (0) + +/* + * Common routine to process the arguments to nan(), nanf(), and nanl(). + */ +void _scan_nan(uint32_t *__words, int __num_words, const char *__s); + +#ifdef _COMPLEX_H + +/* + * C99 specifies that complex numbers have the same representation as + * an array of two elements, where the first element is the real part + * and the second element is the imaginary part. + */ +typedef union { + float complex f; + float a[2]; +} float_complex; +typedef union { + double complex f; + double a[2]; +} double_complex; +typedef union { + long double complex f; + long double a[2]; +} long_double_complex; +#define REALPART(z) ((z).a[0]) +#define IMAGPART(z) ((z).a[1]) + +/* + * Inline functions that can be used to construct complex values. + * + * The C99 standard intends x+I*y to be used for this, but x+I*y is + * currently unusable in general since gcc introduces many overflow, + * underflow, sign and efficiency bugs by rewriting I*y as + * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product. + * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted + * to -0.0+I*0.0. + */ +static __inline float complex +cpackf(float x, float y) +{ + float_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} + +static __inline double complex +cpack(double x, double y) +{ + double_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} + +static __inline long double complex +cpackl(long double x, long double y) +{ + long_double_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} +#endif /* _COMPLEX_H */ + +#ifdef __GNUCLIKE_ASM + +/* Asm versions of some functions. */ + +#ifdef __amd64__ +static __inline int +irint(double x) +{ + int n; + + asm("cvtsd2si %1,%0" : "=r" (n) : "x" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINT +#endif + +#ifdef __i386__ +static __inline int +irint(double x) +{ + int n; + + asm("fistl %0" : "=m" (n) : "t" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINT +#endif + +#if defined(__amd64__) || defined(__i386__) +static __inline int +irintl(long double x) +{ + int n; + + asm("fistl %0" : "=m" (n) : "t" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINTL +#endif + +#endif /* __GNUCLIKE_ASM */ + +#ifdef DEBUG +#if defined(__amd64__) || defined(__i386__) +#define breakpoint() asm("int $3") +#else +#include <signal.h> + +#define breakpoint() raise(SIGTRAP) +#endif +#endif + +/* Write a pari script to test things externally. */ +#ifdef DOPRINT +#include <stdio.h> + +#ifndef DOPRINT_SWIZZLE +#define DOPRINT_SWIZZLE 0 +#endif + +#ifdef DOPRINT_LD80 + +#define DOPRINT_START(xp) do { \ + uint64_t __lx; \ + uint16_t __hx; \ + \ + /* Hack to give more-problematic args. */ \ + EXTRACT_LDBL80_WORDS(__hx, __lx, *xp); \ + __lx ^= DOPRINT_SWIZZLE; \ + INSERT_LDBL80_WORDS(*xp, __hx, __lx); \ + printf("x = %.21Lg; ", (long double)*xp); \ +} while (0) +#define DOPRINT_END1(v) \ + printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v)) +#define DOPRINT_END2(hi, lo) \ + printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \ + (long double)(hi), (long double)(lo)) + +#elif defined(DOPRINT_D64) + +#define DOPRINT_START(xp) do { \ + uint32_t __hx, __lx; \ + \ + EXTRACT_WORDS(__hx, __lx, *xp); \ + __lx ^= DOPRINT_SWIZZLE; \ + INSERT_WORDS(*xp, __hx, __lx); \ + printf("x = %.21Lg; ", (long double)*xp); \ +} while (0) +#define DOPRINT_END1(v) \ + printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v)) +#define DOPRINT_END2(hi, lo) \ + printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \ + (long double)(hi), (long double)(lo)) + +#elif defined(DOPRINT_F32) + +#define DOPRINT_START(xp) do { \ + uint32_t __hx; \ + \ + GET_FLOAT_WORD(__hx, *xp); \ + __hx ^= DOPRINT_SWIZZLE; \ + SET_FLOAT_WORD(*xp, __hx); \ + printf("x = %.21Lg; ", (long double)*xp); \ +} while (0) +#define DOPRINT_END1(v) \ + printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v)) +#define DOPRINT_END2(hi, lo) \ + printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \ + (long double)(hi), (long double)(lo)) + +#else /* !DOPRINT_LD80 && !DOPRINT_D64 (LD128 only) */ + +#ifndef DOPRINT_SWIZZLE_HIGH +#define DOPRINT_SWIZZLE_HIGH 0 +#endif + +#define DOPRINT_START(xp) do { \ + uint64_t __lx, __llx; \ + uint16_t __hx; \ + \ + EXTRACT_LDBL128_WORDS(__hx, __lx, __llx, *xp); \ + __llx ^= DOPRINT_SWIZZLE; \ + __lx ^= DOPRINT_SWIZZLE_HIGH; \ + INSERT_LDBL128_WORDS(*xp, __hx, __lx, __llx); \ + printf("x = %.36Lg; ", (long double)*xp); \ +} while (0) +#define DOPRINT_END1(v) \ + printf("y = %.36Lg; z = 0; show(x, y, z);\n", (long double)(v)) +#define DOPRINT_END2(hi, lo) \ + printf("y = %.36Lg; z = %.36Lg; show(x, y, z);\n", \ + (long double)(hi), (long double)(lo)) + +#endif /* DOPRINT_LD80 */ + +#else /* !DOPRINT */ +#define DOPRINT_START(xp) +#define DOPRINT_END1(v) +#define DOPRINT_END2(hi, lo) +#endif /* DOPRINT */ + +#define RETURNP(x) do { \ + DOPRINT_END1(x); \ + RETURNF(x); \ +} while (0) +#define RETURNPI(x) do { \ + DOPRINT_END1(x); \ + RETURNI(x); \ +} while (0) +#define RETURN2P(x, y) do { \ + DOPRINT_END2((x), (y)); \ + RETURNF((x) + (y)); \ +} while (0) +#define RETURN2PI(x, y) do { \ + DOPRINT_END2((x), (y)); \ + RETURNI((x) + (y)); \ +} while (0) +#ifdef STRUCT_RETURN +#define RETURNSP(rp) do { \ + if (!(rp)->lo_set) \ + RETURNP((rp)->hi); \ + RETURN2P((rp)->hi, (rp)->lo); \ +} while (0) +#define RETURNSPI(rp) do { \ + if (!(rp)->lo_set) \ + RETURNPI((rp)->hi); \ + RETURN2PI((rp)->hi, (rp)->lo); \ +} while (0) +#endif +#define SUM2P(x, y) ({ \ + const __typeof (x) __x = (x); \ + const __typeof (y) __y = (y); \ + \ + DOPRINT_END2(__x, __y); \ + __x + __y; \ +}) + +/* + * ieee style elementary functions + * + * We rename functions here to improve other sources' diffability + * against fdlibm. + */ +#define __ieee754_sqrt sqrt +#define __ieee754_acos acos +#define __ieee754_acosh acosh +#define __ieee754_log log +#define __ieee754_log2 log2 +#define __ieee754_atanh atanh +#define __ieee754_asin asin +#define __ieee754_atan2 atan2 +#define __ieee754_exp exp +#define __ieee754_cosh cosh +#define __ieee754_fmod fmod +#define __ieee754_pow pow +#define __ieee754_lgamma lgamma +#define __ieee754_gamma gamma +#define __ieee754_lgamma_r lgamma_r +#define __ieee754_gamma_r gamma_r +#define __ieee754_log10 log10 +#define __ieee754_sinh sinh +#define __ieee754_hypot hypot +#define __ieee754_j0 j0 +#define __ieee754_j1 j1 +#define __ieee754_y0 y0 +#define __ieee754_y1 y1 +#define __ieee754_jn jn +#define __ieee754_yn yn +#define __ieee754_remainder remainder +#define __ieee754_scalb scalb +#define __ieee754_sqrtf sqrtf +#define __ieee754_acosf acosf +#define __ieee754_acoshf acoshf +#define __ieee754_logf logf +#define __ieee754_atanhf atanhf +#define __ieee754_asinf asinf +#define __ieee754_atan2f atan2f +#define __ieee754_expf expf +#define __ieee754_coshf coshf +#define __ieee754_fmodf fmodf +#define __ieee754_powf powf +#define __ieee754_lgammaf lgammaf +#define __ieee754_gammaf gammaf +#define __ieee754_lgammaf_r lgammaf_r +#define __ieee754_gammaf_r gammaf_r +#define __ieee754_log10f log10f +#define __ieee754_log2f log2f +#define __ieee754_sinhf sinhf +#define __ieee754_hypotf hypotf +#define __ieee754_j0f j0f +#define __ieee754_j1f j1f +#define __ieee754_y0f y0f +#define __ieee754_y1f y1f +#define __ieee754_jnf jnf +#define __ieee754_ynf ynf +#define __ieee754_remainderf remainderf +#define __ieee754_scalbf scalbf + +/* fdlibm kernel function */ +int __kernel_rem_pio2(double*,double*,int,int,int); + +/* double precision kernel functions */ +#ifndef INLINE_REM_PIO2 +int __ieee754_rem_pio2(double,double*); +#endif +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 */ +#ifndef INLINE_REM_PIO2F +int __ieee754_rem_pio2f(float,double*); +#endif +#ifndef INLINE_KERNEL_SINDF +float __kernel_sindf(double); +#endif +#ifndef INLINE_KERNEL_COSDF +float __kernel_cosdf(double); +#endif +#ifndef INLINE_KERNEL_TANDF +float __kernel_tandf(double,int); +#endif +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); +long double __kernel_cosl(long double, long double); +long double __kernel_tanl(long double, long double, int); + +#endif /* !_MATH_PRIVATE_H_ */ diff --git a/libm/src/s_asinh.c b/libm/upstream-freebsd/lib/msun/src/s_asinh.c index 079007f..cbb3d46 100644 --- a/libm/src/s_asinh.c +++ b/libm/upstream-freebsd/lib/msun/src/s_asinh.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_asinh.c,v 1.8 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* asinh(x) * Method : @@ -25,6 +24,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_asinh.c,v 1.8 2002/05/28 18: * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -55,3 +56,7 @@ asinh(double x) } if(hx>0) return w; else return -w; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(asinh, asinhl); +#endif diff --git a/libm/src/s_asinhf.c b/libm/upstream-freebsd/lib/msun/src/s_asinhf.c index 73dc798..c1620dd 100644 --- a/libm/src/s_asinhf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_asinhf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_asinhf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/upstream-freebsd/lib/msun/src/s_asinhl.c b/libm/upstream-freebsd/lib/msun/src/s_asinhl.c new file mode 100644 index 0000000..ba28f59 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_asinhl.c @@ -0,0 +1,91 @@ +/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */ + +/* @(#)s_asinh.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See s_asinh.c for complete comments. + * + * Converted to long double by David Schultz <das@FreeBSD.ORG> and + * Bruce D. Evans. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +/* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */ +/* EXP_TINY is the threshold below which we use asinh(x) ~= x. */ +#if LDBL_MANT_DIG == 64 +#define EXP_LARGE 34 +#define EXP_TINY -34 +#elif LDBL_MANT_DIG == 113 +#define EXP_LARGE 58 +#define EXP_TINY -58 +#else +#error "Unsupported long double format" +#endif + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual expsign encoding. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +huge= 1.00000000000000000000e+300; + +#if LDBL_MANT_DIG == 64 +static const union IEEEl2bits +u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); +#define ln2 u_ln2.e +#elif LDBL_MANT_DIG == 113 +static const long double +ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ +#else +#error "Unsupported long double format" +#endif + +long double +asinhl(long double x) +{ + long double t, w; + uint16_t hx, ix; + + ENTERI(); + GET_LDBL_EXPSIGN(hx, x); + ix = hx & 0x7fff; + if (ix >= 0x7fff) RETURNI(x+x); /* x is inf, NaN or misnormal */ + if (ix < BIAS + EXP_TINY) { /* |x| < TINY, or misnormal */ + if (huge + x > one) RETURNI(x); /* return x inexact except 0 */ + } + if (ix >= BIAS + EXP_LARGE) { /* |x| >= LARGE, or misnormal */ + w = logl(fabsl(x))+ln2; + } else if (ix >= 0x4000) { /* LARGE > |x| >= 2.0, or misnormal */ + t = fabsl(x); + w = logl(2.0*t+one/(sqrtl(x*x+one)+t)); + } else { /* 2.0 > |x| >= TINY, or misnormal */ + t = x*x; + w =log1pl(fabsl(x)+t/(one+sqrtl(one+t))); + } + RETURNI((hx & 0x8000) == 0 ? w : -w); +} diff --git a/libm/src/s_atan.c b/libm/upstream-freebsd/lib/msun/src/s_atan.c index 23d7aa8..566f5dc 100644 --- a/libm/src/s_atan.c +++ b/libm/upstream-freebsd/lib/msun/src/s_atan.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atan.c,v 1.9 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* atan(x) * Method @@ -34,6 +33,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atan.c,v 1.9 2003/07/23 04:5 * to produce the hexadecimal values shown. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -83,10 +84,10 @@ atan(double x) if(ix>0x7ff00000|| (ix==0x7ff00000&&(low!=0))) return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; + if(hx>0) return atanhi[3]+*(volatile double *)&atanlo[3]; + else return -atanhi[3]-*(volatile double *)&atanlo[3]; } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ - if (ix < 0x3e200000) { /* |x| < 2^-29 */ + if (ix < 0x3e400000) { /* |x| < 2^-27 */ if(huge+x>one) return x; /* raise inexact */ } id = -1; @@ -117,3 +118,7 @@ atan(double x) return (hx<0)? -z:z; } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(atan, atanl); +#endif diff --git a/libm/src/s_atanf.c b/libm/upstream-freebsd/lib/msun/src/s_atanf.c index f90b35d..b3a371f 100644 --- a/libm/src/s_atanf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_atanf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atanf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -35,20 +34,14 @@ static const float atanlo[] = { }; static const float aT[] = { - 3.3333334327e-01, /* 0x3eaaaaaa */ - -2.0000000298e-01, /* 0xbe4ccccd */ - 1.4285714924e-01, /* 0x3e124925 */ - -1.1111110449e-01, /* 0xbde38e38 */ - 9.0908870101e-02, /* 0x3dba2e6e */ - -7.6918758452e-02, /* 0xbd9d8795 */ - 6.6610731184e-02, /* 0x3d886b35 */ - -5.8335702866e-02, /* 0xbd6ef16b */ - 4.9768779427e-02, /* 0x3d4bda59 */ - -3.6531571299e-02, /* 0xbd15a221 */ - 1.6285819933e-02, /* 0x3c8569d7 */ + 3.3333328366e-01, + -1.9999158382e-01, + 1.4253635705e-01, + -1.0648017377e-01, + 6.1687607318e-02, }; - static const float +static const float one = 1.0, huge = 1.0e30; @@ -60,13 +53,13 @@ atanf(float x) GET_FLOAT_WORD(hx,x); ix = hx&0x7fffffff; - if(ix>=0x50800000) { /* if |x| >= 2^34 */ + if(ix>=0x4c800000) { /* if |x| >= 2**26 */ if(ix>0x7f800000) return x+x; /* NaN */ - if(hx>0) return atanhi[3]+atanlo[3]; - else return -atanhi[3]-atanlo[3]; + if(hx>0) return atanhi[3]+*(volatile float *)&atanlo[3]; + else return -atanhi[3]-*(volatile float *)&atanlo[3]; } if (ix < 0x3ee00000) { /* |x| < 0.4375 */ - if (ix < 0x31000000) { /* |x| < 2^-29 */ + if (ix < 0x39800000) { /* |x| < 2**-12 */ if(huge+x>one) return x; /* raise inexact */ } id = -1; @@ -81,7 +74,7 @@ atanf(float x) } else { if (ix < 0x401c0000) { /* |x| < 2.4375 */ id = 2; x = (x-(float)1.5)/(one+(float)1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ + } else { /* 2.4375 <= |x| < 2**26 */ id = 3; x = -(float)1.0/x; } }} @@ -89,8 +82,8 @@ atanf(float x) z = x*x; w = z*z; /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); + s1 = z*(aT[0]+w*(aT[2]+w*aT[4])); + s2 = w*(aT[1]+w*aT[3]); if (id<0) return x - x*(s1+s2); else { z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); diff --git a/libm/upstream-freebsd/lib/msun/src/s_atanl.c b/libm/upstream-freebsd/lib/msun/src/s_atanl.c new file mode 100644 index 0000000..ff29c3c --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_atanl.c @@ -0,0 +1,85 @@ +/* @(#)s_atan.c 5.1 93/09/24 */ +/* FreeBSD: head/lib/msun/src/s_atan.c 176451 2008-02-22 02:30:36Z das */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * See comments in s_atan.c. + * Converted to long double by David Schultz <das@FreeBSD.ORG>. + */ + +#include <float.h> + +#include "invtrig.h" +#include "math.h" +#include "math_private.h" + +static const long double +one = 1.0, +huge = 1.0e300; + +long double +atanl(long double x) +{ + union IEEEl2bits u; + long double w,s1,s2,z; + int id; + int16_t expsign, expt; + int32_t expman; + + u.e = x; + expsign = u.xbits.expsign; + expt = expsign & 0x7fff; + if(expt >= ATAN_CONST) { /* if |x| is large, atan(x)~=pi/2 */ + if(expt == BIAS + LDBL_MAX_EXP && + ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)!=0) + return x+x; /* NaN */ + if(expsign>0) return atanhi[3]+atanlo[3]; + else return -atanhi[3]-atanlo[3]; + } + /* Extract the exponent and the first few bits of the mantissa. */ + /* XXX There should be a more convenient way to do this. */ + expman = (expt << 8) | ((u.bits.manh >> (MANH_SIZE - 9)) & 0xff); + if (expman < ((BIAS - 2) << 8) + 0xc0) { /* |x| < 0.4375 */ + if (expt < ATAN_LINEAR) { /* if |x| is small, atanl(x)~=x */ + if(huge+x>one) return x; /* raise inexact */ + } + id = -1; + } else { + x = fabsl(x); + if (expman < (BIAS << 8) + 0x30) { /* |x| < 1.1875 */ + if (expman < ((BIAS - 1) << 8) + 0x60) { /* 7/16 <=|x|<11/16 */ + id = 0; x = (2.0*x-one)/(2.0+x); + } else { /* 11/16<=|x|< 19/16 */ + id = 1; x = (x-one)/(x+one); + } + } else { + if (expman < ((BIAS + 1) << 8) + 0x38) { /* |x| < 2.4375 */ + id = 2; x = (x-1.5)/(one+1.5*x); + } else { /* 2.4375 <= |x| < 2^ATAN_CONST */ + id = 3; x = -1.0/x; + } + }} + /* end of argument reduction */ + z = x*x; + w = z*z; + /* break sum aT[i]z**(i+1) into odd and even poly */ + s1 = z*T_even(w); + s2 = w*T_odd(w); + if (id<0) return x - x*(s1+s2); + else { + z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); + return (expsign<0)? -z:z; + } +} diff --git a/libm/i387/s_lrint.S b/libm/upstream-freebsd/lib/msun/src/s_carg.c index 022783c..ea1a0d7 100644 --- a/libm/i387/s_lrint.S +++ b/libm/upstream-freebsd/lib/msun/src/s_carg.c @@ -24,12 +24,15 @@ * SUCH DAMAGE. */ -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_lrint.S,v 1.1 2005/01/11 23:10:53 das Exp $"); - -ENTRY(lrint) - fldl 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax - ret +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +double +carg(double complex z) +{ + + return (atan2(cimag(z), creal(z))); +} diff --git a/libm/i387/s_lrintf.S b/libm/upstream-freebsd/lib/msun/src/s_cargf.c index ac126f0..90232d0 100644 --- a/libm/i387/s_lrintf.S +++ b/libm/upstream-freebsd/lib/msun/src/s_cargf.c @@ -24,12 +24,15 @@ * SUCH DAMAGE. */ -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_lrintf.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(lrintf) - flds 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax - ret +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +float +cargf(float complex z) +{ + + return (atan2f(cimagf(z), crealf(z))); +} diff --git a/libm/i387/s_llrintf.S b/libm/upstream-freebsd/lib/msun/src/s_cargl.c index e1edb09..0555083 100644 --- a/libm/i387/s_llrintf.S +++ b/libm/upstream-freebsd/lib/msun/src/s_cargl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> + * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,13 +24,15 @@ * SUCH DAMAGE. */ -#include <machine/asm.h> -__FBSDID("$FreeBSD: src/lib/msun/i387/s_llrintf.S,v 1.1 2005/04/16 21:12:55 das Exp $") - -ENTRY(llrintf) - flds 4(%esp) - subl $8,%esp - fistpll (%esp) - popl %eax - popl %edx - ret +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +long double +cargl(long double complex z) +{ + + return (atan2l(cimagl(z), creall(z))); +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrt.c b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c new file mode 100644 index 0000000..910f75b --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c @@ -0,0 +1,117 @@ +/* @(#)s_cbrt.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + * Optimized by Bruce D. Evans. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "math.h" +#include "math_private.h" + +/* cbrt(x) + * Return cube root of x + */ +static const u_int32_t + B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */ + B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */ + +/* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */ +static const double +P0 = 1.87595182427177009643, /* 0x3ffe03e6, 0x0f61e692 */ +P1 = -1.88497979543377169875, /* 0xbffe28e0, 0x92f02420 */ +P2 = 1.621429720105354466140, /* 0x3ff9f160, 0x4a49d6c2 */ +P3 = -0.758397934778766047437, /* 0xbfe844cb, 0xbee751d9 */ +P4 = 0.145996192886612446982; /* 0x3fc2b000, 0xd4e4edd7 */ + +double +cbrt(double x) +{ + int32_t hx; + union { + double value; + uint64_t bits; + } u; + double r,s,t=0.0,w; + u_int32_t sign; + u_int32_t high,low; + + EXTRACT_WORDS(hx,low,x); + sign=hx&0x80000000; /* sign= sign(x) */ + hx ^=sign; + if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ + + /* + * Rough cbrt to 5 bits: + * cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3) + * where e is integral and >= 0, m is real and in [0, 1), and "/" and + * "%" are integer division and modulus with rounding towards minus + * infinity. The RHS is always >= the LHS and has a maximum relative + * error of about 1 in 16. Adding a bias of -0.03306235651 to the + * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE + * floating point representation, for finite positive normal values, + * ordinary integer divison of the value in bits magically gives + * almost exactly the RHS of the above provided we first subtract the + * exponent bias (1023 for doubles) and later add it back. We do the + * subtraction virtually to keep e >= 0 so that ordinary integer + * division rounds towards minus infinity; this is also efficient. + */ + if(hx<0x00100000) { /* zero or subnormal? */ + if((hx|low)==0) + return(x); /* cbrt(0) is itself */ + SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */ + t*=x; + GET_HIGH_WORD(high,t); + INSERT_WORDS(t,sign|((high&0x7fffffff)/3+B2),0); + } else + INSERT_WORDS(t,sign|(hx/3+B1),0); + + /* + * New cbrt to 23 bits: + * cbrt(x) = t*cbrt(x/t**3) ~= t*P(t**3/x) + * where P(r) is a polynomial of degree 4 that approximates 1/cbrt(r) + * to within 2**-23.5 when |r - 1| < 1/10. The rough approximation + * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this + * gives us bounds for r = t**3/x. + * + * Try to optimize for parallel evaluation as in k_tanf.c. + */ + r=(t*t)*(t/x); + t=t*((P0+r*(P1+r*P2))+((r*r)*r)*(P3+r*P4)); + + /* + * Round t away from zero to 23 bits (sloppily except for ensuring that + * the result is larger in magnitude than cbrt(x) but not much more than + * 2 23-bit ulps larger). With rounding towards zero, the error bound + * would be ~5/6 instead of ~4/6. With a maximum error of 2 23-bit ulps + * in the rounded t, the infinite-precision error in the Newton + * approximation barely affects third digit in the final error + * 0.667; the error in the rounded t can be up to about 3 23-bit ulps + * before the final error is larger than 0.667 ulps. + */ + u.value=t; + u.bits=(u.bits+0x80000000)&0xffffffffc0000000ULL; + t=u.value; + + /* one step Newton iteration to 53 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 */ + + return(t); +} + +#if (LDBL_MANT_DIG == 53) +__weak_reference(cbrt, cbrtl); +#endif diff --git a/libm/src/s_cbrtf.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c index 75569a2..454f974 100644 --- a/libm/src/s_cbrtf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c @@ -14,9 +14,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.12 2005/12/13 20:17:23 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -28,17 +27,11 @@ static const unsigned B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */ B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */ -static const float -C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */ -D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */ -E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */ -F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */ -G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */ - float cbrtf(float x) { - float r,s,t,w; + double r,T; + float t; int32_t hx; u_int32_t sign; u_int32_t high; @@ -47,11 +40,11 @@ cbrtf(float x) sign=hx&0x80000000; /* sign= sign(x) */ hx ^=sign; if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */ - if(hx==0) - return(x); /* cbrt(0) is itself */ /* rough cbrt to 5 bits */ - if(hx<0x00800000) { /* subnormal number */ + if(hx<0x00800000) { /* zero or subnormal? */ + if(hx==0) + return(x); /* cbrt(+-0) is itself */ SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */ t*=x; GET_FLOAT_WORD(high,t); @@ -59,21 +52,22 @@ cbrtf(float x) } else SET_FLOAT_WORD(t,sign|(hx/3+B1)); - /* new cbrt to 23 bits */ - r=t*t/x; - s=C+r*t; - t*=G+F/(s+E+D/s); - - /* chop t to 12 bits and make it larger in magnitude than cbrt(x) */ - GET_FLOAT_WORD(high,t); - SET_FLOAT_WORD(t,(high&0xfffff000)+0x00001000); + /* + * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In + * double precision so that its terms can be arranged for efficiency + * without causing overflow or underflow. + */ + T=t; + r=T*T*T; + T=T*((double)x+x+r)/(x+r+r); - /* one step Newton iteration to 24 bits with error less than 0.667 ulps */ - s=t*t; /* t*t is exact */ - r=x/s; - w=t+t; - r=(r-t)/(w+r); /* r-t is exact */ - t=t+t*r; + /* + * Second step Newton iteration to 47 bits. In double precision for + * efficiency and accuracy. + */ + r=T*T*T; + T=T*((double)x+x+r)/(x+r+r); - return(t); + /* rounding to 24 bits is perfect in round-to-nearest mode */ + return(T); } diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c new file mode 100644 index 0000000..2236c0f --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c @@ -0,0 +1,143 @@ +/*- + * ==================================================== + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#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); + + ENTERI(); + if (k == 0) { + /* If x = +-0, then cbrt(x) = +-0. */ + if ((u.bits.manh | u.bits.manl) == 0) + RETURNI(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; + RETURNI(t); +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c new file mode 100644 index 0000000..9ea962b --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c new file mode 100644 index 0000000..1de9ad4 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/src/s_ceil.c b/libm/upstream-freebsd/lib/msun/src/s_ceil.c index e5440e2..929f813 100644 --- a/libm/src/s_ceil.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ceil.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceil.c,v 1.9 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * ceil(x) @@ -23,6 +22,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceil.c,v 1.9 2003/07/23 04:5 * Inexact flag raised if x not equal to ceil(x). */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -70,3 +71,7 @@ ceil(double x) INSERT_WORDS(x,i0,i1); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(ceil, ceill); +#endif diff --git a/libm/src/s_ceilf.c b/libm/upstream-freebsd/lib/msun/src/s_ceilf.c index 5c465b3..23bfe04 100644 --- a/libm/src/s_ceilf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ceilf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceilf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/src/s_ceill.c b/libm/upstream-freebsd/lib/msun/src/s_ceill.c index 7e8817c..2d1045f 100644 --- a/libm/src/s_ceill.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ceill.c @@ -11,9 +11,8 @@ * From: @(#)s_ceil.c 5.1 93/09/24 */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceill.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * ceill(x) @@ -63,7 +62,7 @@ ceill(long double x) if (huge + x > 0.0) if (u.bits.exp > 0 || (u.bits.manh | u.bits.manl) != 0) - u.e = u.bits.sign ? 0.0 : 1.0; + u.e = u.bits.sign ? -0.0 : 1.0; } else { uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); if (((u.bits.manh & m) | u.bits.manl) == 0) diff --git a/libm/upstream-freebsd/lib/msun/src/s_cexp.c b/libm/upstream-freebsd/lib/msun/src/s_cexp.c new file mode 100644 index 0000000..abe178f --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cexp.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/upstream-freebsd/lib/msun/src/s_cexpf.c b/libm/upstream-freebsd/lib/msun/src/s_cexpf.c new file mode 100644 index 0000000..0e30d08 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cexpf.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/src/s_cimag.c b/libm/upstream-freebsd/lib/msun/src/s_cimag.c index e4be0b3..cbf6720 100644 --- a/libm/src/s_cimag.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cimag.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_cimag.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" double cimag(double complex z) { - return -z * I; + const double_complex z1 = { .f = z }; + + return (IMAGPART(z1)); } diff --git a/libm/src/s_cimagf.c b/libm/upstream-freebsd/lib/msun/src/s_cimagf.c index 1e0f53f..4e483a2 100644 --- a/libm/src/s_cimagf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cimagf.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_cimagf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" float cimagf(float complex z) { - return -z * I; + const float_complex z1 = { .f = z }; + + return (IMAGPART(z1)); } diff --git a/libm/src/s_cimagl.c b/libm/upstream-freebsd/lib/msun/src/s_cimagl.c index a87677e..c50e967 100644 --- a/libm/src/s_cimagl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cimagl.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_cimagl.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" long double cimagl(long double complex z) { - return -z * I; + const long_double_complex z1 = { .f = z }; + + return (IMAGPART(z1)); } diff --git a/libm/src/s_conj.c b/libm/upstream-freebsd/lib/msun/src/s_conj.c index d47a15d..5770c29 100644 --- a/libm/src/s_conj.c +++ b/libm/upstream-freebsd/lib/msun/src/s_conj.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_conj.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" + double complex conj(double complex z) { - return creal(z) - I * cimag(z); + + return (cpack(creal(z), -cimag(z))); } diff --git a/libm/src/s_conjf.c b/libm/upstream-freebsd/lib/msun/src/s_conjf.c index 24e0398..b090760 100644 --- a/libm/src/s_conjf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_conjf.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_conjf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" + float complex conjf(float complex z) { - return crealf(z) - I * cimagf(z); + + return (cpackf(crealf(z), -cimagf(z))); } diff --git a/libm/src/s_conjl.c b/libm/upstream-freebsd/lib/msun/src/s_conjl.c index 13d80c2..0e431ef 100644 --- a/libm/src/s_conjl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_conjl.c @@ -23,13 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_conjl.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> +#include "math_private.h" + long double complex conjl(long double complex z) { - return creall(z) - I * cimagl(z); + + return (cpackl(creall(z), -cimagl(z))); } diff --git a/libm/src/s_copysign.c b/libm/upstream-freebsd/lib/msun/src/s_copysign.c index f37be0d..a5f3870 100644 --- a/libm/src/s_copysign.c +++ b/libm/upstream-freebsd/lib/msun/src/s_copysign.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_copysign.c,v 1.9 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * copysign(double x, double y) diff --git a/libm/src/s_copysignf.c b/libm/upstream-freebsd/lib/msun/src/s_copysignf.c index 79c4480..05ca1e3 100644 --- a/libm/src/s_copysignf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_copysignf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_copysignf.c,v 1.9 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * copysignf(float x, float y) diff --git a/libm/src/s_copysignl.c b/libm/upstream-freebsd/lib/msun/src/s_copysignl.c index 5c5bd39..8d39f84 100644 --- a/libm/src/s_copysignl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_copysignl.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_copysignl.c,v 1.1 2004/05/07 18:56:31 stefanf Exp $ + * $FreeBSD$ */ #include <math.h> diff --git a/libm/src/s_cos.c b/libm/upstream-freebsd/lib/msun/src/s_cos.c index 0faf91e..29804f4 100644 --- a/libm/src/s_cos.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cos.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cos.c,v 1.10 2005/10/24 14:08:36 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* cos(x) * Return cosine function of x. @@ -45,8 +44,12 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cos.c,v 1.10 2005/10/24 14:0 * TRIG(x) returns trig(x) nearly rounded */ +#include <float.h> + #include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double cos(double x) @@ -60,7 +63,7 @@ cos(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; if(ix <= 0x3fe921fb) { - if(ix<0x3e400000) /* if x < 2**-27 */ + if(ix<0x3e46a09e) /* if x < 2**-27 * sqrt(2) */ if(((int)x)==0) return 1.0; /* generate inexact */ return __kernel_cos(x,z); } @@ -80,3 +83,7 @@ cos(double x) } } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(cos, cosl); +#endif diff --git a/libm/src/s_cosf.c b/libm/upstream-freebsd/lib/msun/src/s_cosf.c index 31adade..b701fd2 100644 --- a/libm/src/s_cosf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_cosf.c @@ -14,14 +14,17 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cosf.c,v 1.15 2005/11/30 06:47:18 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF +#define INLINE_REM_PIO2F #include "math_private.h" +#include "e_rem_pio2f.c" #include "k_cosf.c" #include "k_sinf.c" @@ -35,7 +38,7 @@ c4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ float cosf(float x) { - float y[2]; + double y; int32_t n, hx, ix; GET_FLOAT_WORD(hx,x); @@ -72,13 +75,13 @@ cosf(float x) /* general argument reduction needed */ else { - n = __ieee754_rem_pio2f(x,y); + n = __ieee754_rem_pio2f(x,&y); switch(n&3) { - case 0: return __kernel_cosdf((double)y[0]+y[1]); - case 1: return __kernel_sindf(-(double)y[0]-y[1]); - case 2: return -__kernel_cosdf((double)y[0]+y[1]); + case 0: return __kernel_cosdf(y); + case 1: return __kernel_sindf(-y); + case 2: return -__kernel_cosdf(y); default: - return __kernel_sindf((double)y[0]+y[1]); + return __kernel_sindf(y); } } } diff --git a/libm/upstream-freebsd/lib/msun/src/s_cosl.c b/libm/upstream-freebsd/lib/msun/src/s_cosl.c new file mode 100644 index 0000000..22e74cf --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cosl.c @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2007 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * Limited testing on pseudorandom numbers drawn within [-2e8:4e8] shows + * an accuracy of <= 0.7412 ULP. + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "math.h" +#include "math_private.h" +#if LDBL_MANT_DIG == 64 +#include "../ld80/e_rem_pio2l.h" +#elif LDBL_MANT_DIG == 113 +#include "../ld128/e_rem_pio2l.h" +#else +#error "Unsupported long double format" +#endif + +long double +cosl(long double x) +{ + union IEEEl2bits z; + int e0; + long double y[2]; + long double hi, lo; + + z.e = x; + z.bits.sign = 0; + + /* If x = +-0 or x is a subnormal number, then cos(x) = 1 */ + if (z.bits.exp == 0) + return (1.0); + + /* If x = NaN or Inf, then cos(x) = NaN. */ + if (z.bits.exp == 32767) + return ((x - x) / (x - x)); + + ENTERI(); + + /* Optimize the case where x is already within range. */ + if (z.e < M_PI_4) + RETURNI(__kernel_cosl(z.e, 0)); + + e0 = __ieee754_rem_pio2l(x, y); + hi = y[0]; + lo = y[1]; + + switch (e0 & 3) { + case 0: + hi = __kernel_cosl(hi, lo); + break; + case 1: + hi = - __kernel_sinl(hi, lo, 1); + break; + case 2: + hi = - __kernel_cosl(hi, lo); + break; + case 3: + hi = __kernel_sinl(hi, lo, 1); + break; + } + + RETURNI(hi); +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_cproj.c b/libm/upstream-freebsd/lib/msun/src/s_cproj.c new file mode 100644 index 0000000..8e9404c --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cproj.c @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#include "math_private.h" + +double complex +cproj(double complex z) +{ + + if (!isinf(creal(z)) && !isinf(cimag(z))) + return (z); + else + return (cpack(INFINITY, copysign(0.0, cimag(z)))); +} + +#if LDBL_MANT_DIG == 53 +__weak_reference(cproj, cprojl); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/s_cprojf.c b/libm/upstream-freebsd/lib/msun/src/s_cprojf.c new file mode 100644 index 0000000..68ea77b --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cprojf.c @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#include "math_private.h" + +float complex +cprojf(float complex z) +{ + + if (!isinf(crealf(z)) && !isinf(cimagf(z))) + return (z); + else + return (cpackf(INFINITY, copysignf(0.0, cimagf(z)))); +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_cprojl.c b/libm/upstream-freebsd/lib/msun/src/s_cprojl.c new file mode 100644 index 0000000..07385bc --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_cprojl.c @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#include "math_private.h" + +long double complex +cprojl(long double complex z) +{ + + if (!isinf(creall(z)) && !isinf(cimagl(z))) + return (z); + else + return (cpackl(INFINITY, copysignl(0.0, cimagl(z)))); +} diff --git a/libm/src/s_creal.c b/libm/upstream-freebsd/lib/msun/src/s_creal.c index ad14cdf..3295ff2 100644 --- a/libm/src/s_creal.c +++ b/libm/upstream-freebsd/lib/msun/src/s_creal.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_creal.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> diff --git a/libm/src/s_crealf.c b/libm/upstream-freebsd/lib/msun/src/s_crealf.c index a5c1562..5819b86 100644 --- a/libm/src/s_crealf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_crealf.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_crealf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> diff --git a/libm/src/s_creall.c b/libm/upstream-freebsd/lib/msun/src/s_creall.c index 1531d16..e4946f9 100644 --- a/libm/src/s_creall.c +++ b/libm/upstream-freebsd/lib/msun/src/s_creall.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_creall.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $ + * $FreeBSD$ */ #include <complex.h> diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinh.c b/libm/upstream-freebsd/lib/msun/src/s_csinh.c new file mode 100644 index 0000000..c192f30 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/upstream-freebsd/lib/msun/src/s_csinhf.c b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c new file mode 100644 index 0000000..c523125 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/upstream-freebsd/lib/msun/src/s_csqrt.c b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c new file mode 100644 index 0000000..18a7ae3 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c @@ -0,0 +1,112 @@ +/*- + * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <float.h> +#include <math.h> + +#include "math_private.h" + +/* + * gcc doesn't implement complex multiplication or division correctly, + * so we need to handle infinities specially. We turn on this pragma to + * notify conforming c99 compilers that the fast-but-incorrect code that + * gcc generates is acceptable, since the special cases have already been + * handled. + */ +#pragma STDC CX_LIMITED_RANGE ON + +/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */ +#define THRESH 0x1.a827999fcef32p+1022 + +double complex +csqrt(double complex z) +{ + double complex result; + double a, b; + double t; + int scale; + + a = creal(z); + b = cimag(z); + + /* Handle special cases. */ + if (z == 0) + return (cpack(0, b)); + if (isinf(b)) + return (cpack(INFINITY, b)); + if (isnan(a)) { + t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ + return (cpack(a, t)); /* return NaN + NaN i */ + } + if (isinf(a)) { + /* + * csqrt(inf + NaN i) = inf + NaN i + * csqrt(inf + y i) = inf + 0 i + * csqrt(-inf + NaN i) = NaN +- inf i + * csqrt(-inf + y i) = 0 + inf i + */ + if (signbit(a)) + return (cpack(fabs(b - b), copysign(a, b))); + else + return (cpack(a, copysign(b - b, b))); + } + /* + * The remaining special case (b is NaN) is handled just fine by + * the normal code path below. + */ + + /* Scale to avoid overflow. */ + if (fabs(a) >= THRESH || fabs(b) >= THRESH) { + a *= 0.25; + b *= 0.25; + scale = 1; + } else { + scale = 0; + } + + /* Algorithm 312, CACM vol 10, Oct 1967. */ + if (a >= 0) { + t = sqrt((a + hypot(a, b)) * 0.5); + result = cpack(t, b / (2 * t)); + } else { + t = sqrt((-a + hypot(a, b)) * 0.5); + result = cpack(fabs(b) / (2 * t), copysign(t, b)); + } + + /* Rescale. */ + if (scale) + return (result * 2); + else + return (result); +} + +#if LDBL_MANT_DIG == 53 +__weak_reference(csqrt, csqrtl); +#endif diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c new file mode 100644 index 0000000..da7fe18 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#include "math_private.h" + +/* + * gcc doesn't implement complex multiplication or division correctly, + * so we need to handle infinities specially. We turn on this pragma to + * notify conforming c99 compilers that the fast-but-incorrect code that + * gcc generates is acceptable, since the special cases have already been + * handled. + */ +#pragma STDC CX_LIMITED_RANGE ON + +float complex +csqrtf(float complex z) +{ + float a = crealf(z), b = cimagf(z); + double t; + + /* Handle special cases. */ + if (z == 0) + return (cpackf(0, b)); + if (isinf(b)) + return (cpackf(INFINITY, b)); + if (isnan(a)) { + t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ + return (cpackf(a, t)); /* return NaN + NaN i */ + } + if (isinf(a)) { + /* + * csqrtf(inf + NaN i) = inf + NaN i + * csqrtf(inf + y i) = inf + 0 i + * csqrtf(-inf + NaN i) = NaN +- inf i + * csqrtf(-inf + y i) = 0 + inf i + */ + if (signbit(a)) + return (cpackf(fabsf(b - b), copysignf(a, b))); + else + return (cpackf(a, copysignf(b - b, b))); + } + /* + * The remaining special case (b is NaN) is handled just fine by + * the normal code path below. + */ + + /* + * We compute t in double precision to avoid overflow and to + * provide correct rounding in nearly all cases. + * This is Algorithm 312, CACM vol 10, Oct 1967. + */ + if (a >= 0) { + t = sqrt((a + hypot(a, b)) * 0.5); + return (cpackf(t, b / (2.0 * t))); + } else { + t = sqrt((-a + hypot(a, b)) * 0.5); + return (cpackf(fabsf(b) / (2.0 * t), copysignf(t, b))); + } +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c new file mode 100644 index 0000000..dd18e1e --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2007-2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <float.h> +#include <math.h> + +#include "math_private.h" + +/* + * gcc doesn't implement complex multiplication or division correctly, + * so we need to handle infinities specially. We turn on this pragma to + * notify conforming c99 compilers that the fast-but-incorrect code that + * gcc generates is acceptable, since the special cases have already been + * handled. + */ +#pragma STDC CX_LIMITED_RANGE ON + +/* We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). */ +#define THRESH (LDBL_MAX / 2.414213562373095048801688724209698L) + +long double complex +csqrtl(long double complex z) +{ + long double complex result; + long double a, b; + long double t; + int scale; + + a = creall(z); + b = cimagl(z); + + /* Handle special cases. */ + if (z == 0) + return (cpackl(0, b)); + if (isinf(b)) + return (cpackl(INFINITY, b)); + if (isnan(a)) { + t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ + return (cpackl(a, t)); /* return NaN + NaN i */ + } + if (isinf(a)) { + /* + * csqrt(inf + NaN i) = inf + NaN i + * csqrt(inf + y i) = inf + 0 i + * csqrt(-inf + NaN i) = NaN +- inf i + * csqrt(-inf + y i) = 0 + inf i + */ + if (signbit(a)) + return (cpackl(fabsl(b - b), copysignl(a, b))); + else + return (cpackl(a, copysignl(b - b, b))); + } + /* + * The remaining special case (b is NaN) is handled just fine by + * the normal code path below. + */ + + /* Scale to avoid overflow. */ + if (fabsl(a) >= THRESH || fabsl(b) >= THRESH) { + a *= 0.25; + b *= 0.25; + scale = 1; + } else { + scale = 0; + } + + /* Algorithm 312, CACM vol 10, Oct 1967. */ + if (a >= 0) { + t = sqrtl((a + hypotl(a, b)) * 0.5); + result = cpackl(t, b / (2 * t)); + } else { + t = sqrtl((-a + hypotl(a, b)) * 0.5); + result = cpackl(fabsl(b) / (2 * t), copysignl(t, b)); + } + + /* Rescale. */ + if (scale) + return (result * 2); + else + return (result); +} diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c new file mode 100644 index 0000000..d427e28 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c b/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c new file mode 100644 index 0000000..4be28d8 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +#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/libm/src/s_erf.c b/libm/upstream-freebsd/lib/msun/src/s_erf.c index f33a2a5..0886e5e 100644 --- a/libm/src/s_erf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_erf.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_erf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* double erf(double x) * double erfc(double x) diff --git a/libm/upstream-freebsd/lib/msun/src/s_erff.c b/libm/upstream-freebsd/lib/msun/src/s_erff.c new file mode 100644 index 0000000..a3579f1 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_erff.c @@ -0,0 +1,182 @@ +/* s_erff.c -- float version of s_erf.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "math.h" +#include "math_private.h" + +static const float +tiny = 1e-30, +half= 5.0000000000e-01, /* 0x3F000000 */ +one = 1.0000000000e+00, /* 0x3F800000 */ +two = 2.0000000000e+00, /* 0x40000000 */ +/* + * Coefficients for approximation to erf on [0,0.84375] + */ +efx = 1.2837916613e-01, /* 0x3e0375d4 */ +efx8= 1.0270333290e+00, /* 0x3f8375d4 */ +/* + * Domain [0, 0.84375], range ~[-5.4446e-10,5.5197e-10]: + * |(erf(x) - x)/x - p(x)/q(x)| < 2**-31. + */ +pp0 = 1.28379166e-01F, /* 0x1.06eba8p-3 */ +pp1 = -3.36030394e-01F, /* -0x1.58185ap-2 */ +pp2 = -1.86260219e-03F, /* -0x1.e8451ep-10 */ +qq1 = 3.12324286e-01F, /* 0x1.3fd1f0p-2 */ +qq2 = 2.16070302e-02F, /* 0x1.620274p-6 */ +qq3 = -1.98859419e-03F, /* -0x1.04a626p-9 */ +/* + * Domain [0.84375, 1.25], range ~[-1.953e-11,1.940e-11]: + * |(erf(x) - erx) - p(x)/q(x)| < 2**-36. + */ +erx = 8.42697144e-01F, /* 0x1.af7600p-1. erf(1) rounded to 16 bits. */ +pa0 = 3.64939137e-06F, /* 0x1.e9d022p-19 */ +pa1 = 4.15109694e-01F, /* 0x1.a91284p-2 */ +pa2 = -1.65179938e-01F, /* -0x1.5249dcp-3 */ +pa3 = 1.10914491e-01F, /* 0x1.c64e46p-4 */ +qa1 = 6.02074385e-01F, /* 0x1.344318p-1 */ +qa2 = 5.35934687e-01F, /* 0x1.126608p-1 */ +qa3 = 1.68576106e-01F, /* 0x1.593e6ep-3 */ +qa4 = 5.62181212e-02F, /* 0x1.cc89f2p-5 */ +/* + * Domain [1.25,1/0.35], range ~[-7.043e-10,7.457e-10]: + * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-30 + */ +ra0 = -9.87132732e-03F, /* -0x1.4376b2p-7 */ +ra1 = -5.53605914e-01F, /* -0x1.1b723cp-1 */ +ra2 = -2.17589188e+00F, /* -0x1.1683a0p+1 */ +ra3 = -1.43268085e+00F, /* -0x1.6ec42cp+0 */ +sa1 = 5.45995426e+00F, /* 0x1.5d6fe4p+2 */ +sa2 = 6.69798088e+00F, /* 0x1.acabb8p+2 */ +sa3 = 1.43113089e+00F, /* 0x1.6e5e98p+0 */ +sa4 = -5.77397496e-02F, /* -0x1.d90108p-5 */ +/* + * Domain [1/0.35, 11], range ~[-2.264e-13,2.336e-13]: + * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-42 + */ +rb0 = -9.86494310e-03F, /* -0x1.434124p-7 */ +rb1 = -6.25171244e-01F, /* -0x1.401672p-1 */ +rb2 = -6.16498327e+00F, /* -0x1.8a8f16p+2 */ +rb3 = -1.66696873e+01F, /* -0x1.0ab70ap+4 */ +rb4 = -9.53764343e+00F, /* -0x1.313460p+3 */ +sb1 = 1.26884899e+01F, /* 0x1.96081cp+3 */ +sb2 = 4.51839523e+01F, /* 0x1.6978bcp+5 */ +sb3 = 4.72810211e+01F, /* 0x1.7a3f88p+5 */ +sb4 = 8.93033314e+00F; /* 0x1.1dc54ap+3 */ + +float +erff(float x) +{ + int32_t hx,ix,i; + float R,S,P,Q,s,y,z,r; + GET_FLOAT_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>=0x7f800000) { /* erf(nan)=nan */ + i = ((u_int32_t)hx>>31)<<1; + return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */ + } + + if(ix < 0x3f580000) { /* |x|<0.84375 */ + if(ix < 0x38800000) { /* |x|<2**-14 */ + if (ix < 0x04000000) /* |x|<0x1p-119 */ + return (8*x+efx8*x)/8; /* avoid spurious underflow */ + return x + efx*x; + } + z = x*x; + r = pp0+z*(pp1+z*pp2); + s = one+z*(qq1+z*(qq2+z*qq3)); + y = r/s; + return x + x*y; + } + if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ + s = fabsf(x)-one; + P = pa0+s*(pa1+s*(pa2+s*pa3)); + Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4))); + if(hx>=0) return erx + P/Q; else return -erx - P/Q; + } + if (ix >= 0x40800000) { /* inf>|x|>=4 */ + if(hx>=0) return one-tiny; else return tiny-one; + } + x = fabsf(x); + s = one/(x*x); + if(ix< 0x4036DB6E) { /* |x| < 1/0.35 */ + R=ra0+s*(ra1+s*(ra2+s*ra3)); + S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4))); + } else { /* |x| >= 1/0.35 */ + R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4))); + S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4))); + } + SET_FLOAT_WORD(z,hx&0xffffe000); + r = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S); + if(hx>=0) return one-r/x; else return r/x-one; +} + +float +erfcf(float x) +{ + int32_t hx,ix; + float R,S,P,Q,s,y,z,r; + GET_FLOAT_WORD(hx,x); + ix = hx&0x7fffffff; + if(ix>=0x7f800000) { /* erfc(nan)=nan */ + /* erfc(+-inf)=0,2 */ + return (float)(((u_int32_t)hx>>31)<<1)+one/x; + } + + if(ix < 0x3f580000) { /* |x|<0.84375 */ + if(ix < 0x33800000) /* |x|<2**-24 */ + return one-x; + z = x*x; + r = pp0+z*(pp1+z*pp2); + s = one+z*(qq1+z*(qq2+z*qq3)); + y = r/s; + if(hx < 0x3e800000) { /* x<1/4 */ + return one-(x+x*y); + } else { + r = x*y; + r += (x-half); + return half - r ; + } + } + if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */ + s = fabsf(x)-one; + P = pa0+s*(pa1+s*(pa2+s*pa3)); + Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4))); + if(hx>=0) { + z = one-erx; return z - P/Q; + } else { + z = erx+P/Q; return one+z; + } + } + if (ix < 0x41300000) { /* |x|<11 */ + x = fabsf(x); + s = one/(x*x); + if(ix< 0x4036DB6D) { /* |x| < 1/.35 ~ 2.857143*/ + R=ra0+s*(ra1+s*(ra2+s*ra3)); + S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4))); + } else { /* |x| >= 1/.35 ~ 2.857143 */ + if(hx<0&&ix>=0x40a00000) return two-tiny;/* x < -5 */ + R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4))); + S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4))); + } + SET_FLOAT_WORD(z,hx&0xffffe000); + r = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S); + if(hx>0) return r/x; else return two-r/x; + } else { + if(hx>0) return tiny*tiny; else return two-tiny; + } +} diff --git a/libm/src/s_exp2.c b/libm/upstream-freebsd/lib/msun/src/s_exp2.c index addef04..fde11c2 100644 --- a/libm/src/s_exp2.c +++ b/libm/upstream-freebsd/lib/msun/src/s_exp2.c @@ -25,7 +25,9 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_exp2.c,v 1.1 2005/04/05 02:57:15 das Exp $"); */ +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" @@ -34,8 +36,6 @@ #define TBLSIZE (1 << TBLBITS) static const double - huge = 0x1p1000, - twom1000 = 0x1p-1000, redux = 0x1.8p52 / TBLSIZE, P1 = 0x1.62e42fefa39efp-1, P2 = 0x1.ebfbdff82c575p-3, @@ -43,6 +43,10 @@ static const double P4 = 0x1.3b2ab88f70400p-7, P5 = 0x1.5d88003875c74p-10; +static volatile double + huge = 0x1p1000, + twom1000 = 0x1p-1000; + static const double tbl[TBLSIZE * 2] = { /* exp2(z + eps) eps */ 0x1.6a09e667f3d5dp-1, 0x1.9880p-44, @@ -337,8 +341,8 @@ static const double tbl[TBLSIZE * 2] = { double exp2(double x) { - double r, t, z; - uint32_t hx, hr, ix, lx, i0; + double r, t, twopk, twopkp1000, z; + uint32_t hx, ix, lx, i0; int k; /* Filter out exceptional cases. */ @@ -348,7 +352,7 @@ exp2(double x) if(ix >= 0x7ff00000) { GET_LOW_WORD(lx,x); if(((ix & 0xfffff) | lx) != 0 || (hx & 0x80000000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is NaN or +Inf */ else return (0.0); /* x is -Inf */ } @@ -361,7 +365,7 @@ exp2(double x) } /* Reduce x, computing z, i0, and k. */ - t = x + redux; + STRICT_ASSIGN(double, t, x + redux); GET_LOW_WORD(i0, t); i0 += TBLSIZE / 2; k = (i0 >> TBLBITS) << 20; @@ -372,18 +376,22 @@ exp2(double x) /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */ t = tbl[i0]; /* exp2t[i0] */ z -= tbl[i0 + 1]; /* eps[i0] */ + if (k >= -1021 << 20) + INSERT_WORDS(twopk, 0x3ff00000 + k, 0); + else + INSERT_WORDS(twopkp1000, 0x3ff00000 + k + (1000 << 20), 0); r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5)))); /* Scale by 2**(k>>20). */ if(k >= -1021 << 20) { - if (k != 0) { - GET_HIGH_WORD(hr, r); - SET_HIGH_WORD(r, hr + k); - } - return (r); + if (k == 1024 << 20) + return (r * 2.0 * 0x1p1023); + return (r * twopk); } else { - GET_HIGH_WORD(hr, r); - SET_HIGH_WORD(r, hr + (k + (1000 << 20))); - return (r * twom1000); + return (r * twopkp1000 * twom1000); } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(exp2, exp2l); +#endif diff --git a/libm/src/s_exp2f.c b/libm/upstream-freebsd/lib/msun/src/s_exp2f.c index 5e98e8a..9ac7c1f 100644 --- a/libm/src/s_exp2f.c +++ b/libm/upstream-freebsd/lib/msun/src/s_exp2f.c @@ -25,7 +25,9 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_exp2f.c,v 1.1 2005/04/05 02:57:15 das Exp $"); */ +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" @@ -34,14 +36,16 @@ #define TBLSIZE (1 << TBLBITS) static const float - huge = 0x1p100f, - twom100 = 0x1p-100f, redux = 0x1.8p23f / TBLSIZE, P1 = 0x1.62e430p-1f, P2 = 0x1.ebfbe0p-3f, P3 = 0x1.c6b348p-5f, P4 = 0x1.3b2c9cp-7f; +static volatile float + huge = 0x1p100f, + twom100 = 0x1p-100f; + static const double exp2ft[TBLSIZE] = { 0x1.6a09e667f3bcdp-1, 0x1.7a11473eb0187p-1, @@ -79,7 +83,8 @@ static const double exp2ft[TBLSIZE] = { * * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a * degree-4 minimax polynomial with maximum error under 1.4 * 2**-33. - * Using double precision in the final calculation avoids roundoff error. + * Using double precision for everything except the reduction makes + * roundoff error insignificant and simplifies the scaling step. * * This method is due to Tang, but I do not use his suggested parameters: * @@ -89,19 +94,18 @@ static const double exp2ft[TBLSIZE] = { float exp2f(float x) { - double tv; - float r, z; - volatile float t; /* prevent gcc from using too much precision */ - uint32_t hx, hr, ix, i0; + double tv, twopk, u, z; + float t; + uint32_t hx, ix, i0; int32_t k; /* Filter out exceptional cases. */ - GET_FLOAT_WORD(hx,x); + GET_FLOAT_WORD(hx, x); ix = hx & 0x7fffffff; /* high word of |x| */ if(ix >= 0x43000000) { /* |x| >= 128 */ if(ix >= 0x7f800000) { if ((ix & 0x7fffff) != 0 || (hx & 0x80000000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is NaN or +Inf */ else return (0.0); /* x is -Inf */ } @@ -114,28 +118,20 @@ exp2f(float x) } /* Reduce x, computing z, i0, and k. */ - t = x + redux; + STRICT_ASSIGN(float, t, x + redux); GET_FLOAT_WORD(i0, t); i0 += TBLSIZE / 2; - k = (i0 >> TBLBITS) << 23; + k = (i0 >> TBLBITS) << 20; i0 &= TBLSIZE - 1; t -= redux; z = x - t; + INSERT_WORDS(twopk, 0x3ff00000 + k, 0); /* Compute r = exp2(y) = exp2ft[i0] * p(z). */ tv = exp2ft[i0]; - r = tv + tv * (z * (P1 + z * (P2 + z * (P3 + z * P4)))); + u = tv * z; + tv = tv + u * (P1 + z * P2) + u * (z * z) * (P3 + z * P4); - /* Scale by 2**(k>>23). */ - if(k >= -125 << 23) { - if (k != 0) { - GET_FLOAT_WORD(hr, r); - SET_FLOAT_WORD(r, hr + k); - } - return (r); - } else { - GET_FLOAT_WORD(hr, r); - SET_FLOAT_WORD(r, hr + (k + (100 << 23))); - return (r * twom100); - } + /* Scale by 2**(k>>20). */ + return (tv * twopk); } diff --git a/libm/src/s_expm1.c b/libm/upstream-freebsd/lib/msun/src/s_expm1.c index 57aa3f2..37998a3 100644 --- a/libm/src/s_expm1.c +++ b/libm/upstream-freebsd/lib/msun/src/s_expm1.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* expm1(x) * Returns exp(x)-1, the exponential of x minus 1. @@ -46,7 +45,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1.c,v 1.7 2002/05/28 18: * Q3 = -9.9206344733435987357E-6, * Q4 = 2.5051361420808517002E-7, * Q5 = -6.2843505682382617102E-9; - * (where z=r*r, and the values of Q1 to Q5 are listed below) + * z = r*r, * with error bounded by * | 5 | -61 * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 @@ -109,34 +108,36 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1.c,v 1.7 2002/05/28 18: * to produce the hexadecimal values shown. */ +#include <float.h> + #include "math.h" #include "math_private.h" static const double one = 1.0, -huge = 1.0e+300, tiny = 1.0e-300, o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */ ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */ ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */ invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */ - /* scaled coefficients related to expm1 */ +/* Scaled Q's: Qn_here = 2**n * Qn_above, for R(2*z) where z = hxs = x*x/2: */ Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ +static volatile double huge = 1.0e+300; + double expm1(double x) { - double y,hi,lo,c,t,e,hxs,hfx,r1; + double y,hi,lo,c,t,e,hxs,hfx,r1,twopk; int32_t k,xsb; u_int32_t hx; 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 */ @@ -170,7 +171,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 */ @@ -187,34 +188,35 @@ expm1(double x) e = hxs*((r1-t)/(6.0 - x*t)); if(k==0) return x - (x*e-hxs); /* c is 0 */ else { + INSERT_WORDS(twopk,0x3ff00000+(k<<20),0); /* 2^k */ e = (x*(e-c)-c); e -= hxs; if(k== -1) return 0.5*(x-e)-0.5; - if(k==1) + if(k==1) { if(x < -0.25) return -2.0*(e-(x+0.5)); else return one+2.0*(x-e); + } if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ - u_int32_t high; y = one-(e-x); - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + if (k == 1024) y = y*2.0*0x1p1023; + else y = y*twopk; return y-one; } t = one; if(k<20) { - u_int32_t high; SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */ y = t-(e-x); - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + y = y*twopk; } else { - u_int32_t high; SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */ y = x-(e+t); y += one; - GET_HIGH_WORD(high,y); - SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + y = y*twopk; } } return y; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(expm1, expm1l); +#endif diff --git a/libm/src/s_expm1f.c b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c index a670a72..c0a3934 100644 --- a/libm/src/s_expm1f.c +++ b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c @@ -13,38 +13,40 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1f.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" static const float one = 1.0, -huge = 1.0e+30, tiny = 1.0e-30, o_threshold = 8.8721679688e+01,/* 0x42b17180 */ ln2_hi = 6.9313812256e-01,/* 0x3f317180 */ ln2_lo = 9.0580006145e-06,/* 0x3717f7d1 */ invln2 = 1.4426950216e+00,/* 0x3fb8aa3b */ - /* scaled coefficients related to expm1 */ -Q1 = -3.3333335072e-02, /* 0xbd088889 */ -Q2 = 1.5873016091e-03, /* 0x3ad00d01 */ -Q3 = -7.9365076090e-05, /* 0xb8a670cd */ -Q4 = 4.0082177293e-06, /* 0x36867e54 */ -Q5 = -2.0109921195e-07; /* 0xb457edbb */ +/* + * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]: + * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04 + * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c): + */ +Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */ +Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */ + +static volatile float huge = 1.0e+30; float expm1f(float x) { - float y,hi,lo,c,t,e,hxs,hfx,r1; + float y,hi,lo,c,t,e,hxs,hfx,r1,twopk; int32_t k,xsb; u_int32_t hx; 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 +77,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 */ @@ -87,38 +89,35 @@ expm1f(float x) /* x is now in primary range */ hfx = (float)0.5*x; hxs = x*hfx; - r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); + r1 = one+hxs*(Q1+hxs*Q2); t = (float)3.0-r1*hfx; e = hxs*((r1-t)/((float)6.0 - x*t)); if(k==0) return x - (x*e-hxs); /* c is 0 */ else { + SET_FLOAT_WORD(twopk,0x3f800000+(k<<23)); /* 2^k */ e = (x*(e-c)-c); e -= hxs; if(k== -1) return (float)0.5*(x-e)-(float)0.5; - if(k==1) + if(k==1) { if(x < (float)-0.25) return -(float)2.0*(e-(x+(float)0.5)); else return one+(float)2.0*(x-e); + } if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ - int32_t i; y = one-(e-x); - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ + if (k == 128) y = y*2.0F*0x1p127F; + else y = y*twopk; return y-one; } t = one; if(k<23) { - int32_t i; SET_FLOAT_WORD(t,0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */ y = t-(e-x); - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ + y = y*twopk; } else { - int32_t i; SET_FLOAT_WORD(t,((0x7f-k)<<23)); /* 2^-k */ y = x-(e+t); y += one; - GET_FLOAT_WORD(i,y); - SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */ + y = y*twopk; } } return y; diff --git a/libm/src/s_fabs.c b/libm/upstream-freebsd/lib/msun/src/s_fabs.c index 0dfa940..15529e5 100644 --- a/libm/src/s_fabs.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fabs.c @@ -11,7 +11,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_fabs.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif /* diff --git a/libm/src/s_fabsf.c b/libm/upstream-freebsd/lib/msun/src/s_fabsf.c index 2200705..e9383d0 100644 --- a/libm/src/s_fabsf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fabsf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_fabsf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * fabsf(x) returns the absolute value of x. diff --git a/libm/src/s_fabsl.c b/libm/upstream-freebsd/lib/msun/src/s_fabsl.c index 29831d2..29831d2 100644 --- a/libm/src/s_fabsl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fabsl.c diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_fdim.c index 6a347c1..2f347fd 100644 --- a/libm/src/s_fdim.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fdim.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_finite.c b/libm/upstream-freebsd/lib/msun/src/s_finite.c index 704d1d8..4c51352 100644 --- a/libm/src/s_finite.c +++ b/libm/upstream-freebsd/lib/msun/src/s_finite.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_finite.c,v 1.8 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * finite(x) returns 1 is x is finite, else 0; diff --git a/libm/src/s_finitef.c b/libm/upstream-freebsd/lib/msun/src/s_finitef.c index b430639..c62239e 100644 --- a/libm/src/s_finitef.c +++ b/libm/upstream-freebsd/lib/msun/src/s_finitef.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_finitef.c,v 1.6 2002/05/28 17:51:46 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * finitef(x) returns 1 is x is finite, else 0; diff --git a/libm/src/s_floor.c b/libm/upstream-freebsd/lib/msun/src/s_floor.c index acc3214..65f696a 100644 --- a/libm/src/s_floor.c +++ b/libm/upstream-freebsd/lib/msun/src/s_floor.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floor.c,v 1.9 2003/07/23 04:53:46 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * floor(x) @@ -23,6 +22,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floor.c,v 1.9 2003/07/23 04: * Inexact flag raised if x not equal to floor(x). */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -71,3 +72,7 @@ floor(double x) INSERT_WORDS(x,i0,i1); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(floor, floorl); +#endif diff --git a/libm/src/s_floorf.c b/libm/upstream-freebsd/lib/msun/src/s_floorf.c index 70a71f3..6b510de 100644 --- a/libm/src/s_floorf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_floorf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floorf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * floorf(x) diff --git a/libm/src/s_floorl.c b/libm/upstream-freebsd/lib/msun/src/s_floorl.c index 2ef0acc..6cec3e7 100644 --- a/libm/src/s_floorl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_floorl.c @@ -11,9 +11,8 @@ * From: @(#)s_floor.c 5.1 93/09/24 */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floorl.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * floorl(x) diff --git a/libm/upstream-freebsd/lib/msun/src/s_fma.c b/libm/upstream-freebsd/lib/msun/src/s_fma.c new file mode 100644 index 0000000..b1066c2 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_fma.c @@ -0,0 +1,288 @@ +/*- + * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <fenv.h> +#include <float.h> +#include <math.h> + +#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. + * + * We use scaling to avoid overflow/underflow, along with the + * canonical precision-doubling technique adapted from: + * + * Dekker, T. A Floating-Point Technique for Extending the + * Available Precision. Numer. Math. 18, 224-242 (1971). + * + * This algorithm is sensitive to the rounding precision. FPUs such + * as the i387 must be set in double-precision mode if variables are + * to be stored in FP registers in order to avoid incorrect results. + * This is the default on FreeBSD, but not on many other systems. + * + * Hardware instructions should be used on architectures that support it, + * since this implementation will likely be several times slower. + */ +double +fma(double x, double y, double z) +{ + double xs, ys, zs, adj; + struct dd xy, r; + int oround; + int ex, ey, ez; + int spread; + + /* + * Handle special cases. The order of operations and the particular + * return values here are crucial in handling special cases involving + * infinities, NaNs, overflows, and signed zeroes correctly. + */ + if (x == 0.0 || y == 0.0) + return (x * y + z); + if (z == 0.0) + return (x * y); + if (!isfinite(x) || !isfinite(y)) + return (x * y + z); + if (!isfinite(z)) + return (z); + + xs = frexp(x, &ex); + ys = frexp(y, &ey); + zs = frexp(z, &ez); + oround = fegetround(); + spread = ex + ey - ez; + + /* + * If x * y and z are many orders of magnitude apart, the scaling + * will overflow, so we handle these cases specially. Rounding + * modes other than FE_TONEAREST are painful. + */ + if (spread < -DBL_MANT_DIG) { + feraiseexcept(FE_INEXACT); + if (!isnormal(z)) + feraiseexcept(FE_UNDERFLOW); + switch (oround) { + case FE_TONEAREST: + return (z); + case FE_TOWARDZERO: + if (x > 0.0 ^ y < 0.0 ^ z < 0.0) + return (z); + else + return (nextafter(z, 0)); + case FE_DOWNWARD: + if (x > 0.0 ^ y < 0.0) + return (z); + else + return (nextafter(z, -INFINITY)); + default: /* FE_UPWARD */ + if (x > 0.0 ^ y < 0.0) + return (nextafter(z, INFINITY)); + else + return (z); + } + } + if (spread <= DBL_MANT_DIG * 2) + zs = ldexp(zs, -spread); + else + zs = copysign(DBL_MIN, zs); + + fesetround(FE_TONEAREST); + /* work around clang bug 8100 */ + volatile double vxs = xs; + + /* + * 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(vxs, ys); + r = dd_add(xy.hi, zs); + + spread = ex + ey; + + if (r.hi == 0.0) { + /* + * When the addends cancel to 0, ensure that the result has + * the correct sign. + */ + fesetround(oround); + volatile double vzs = zs; /* XXX gcc CSE bug workaround */ + return (xy.hi + vzs + ldexp(xy.lo, spread)); + } + + if (oround != FE_TONEAREST) { + /* + * There is no need to worry about double rounding in directed + * rounding modes. + */ + fesetround(oround); + /* work around clang bug 8100 */ + volatile double vrlo = r.lo; + adj = vrlo + 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)); +} + +#if (LDBL_MANT_DIG == 53) +__weak_reference(fma, fmal); +#endif diff --git a/libm/src/s_fmaf.c b/libm/upstream-freebsd/lib/msun/src/s_fmaf.c index 31aaaa9..3695823 100644 --- a/libm/src/s_fmaf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fmaf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG> + * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,23 +25,45 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaf.c,v 1.1 2005/01/22 09:53:18 das Exp $"); */ +__FBSDID("$FreeBSD$"); + +#include <fenv.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; + + 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); - return ((double)x * y + z); + /* + * 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/libm/upstream-freebsd/lib/msun/src/s_fmal.c b/libm/upstream-freebsd/lib/msun/src/s_fmal.c new file mode 100644 index 0000000..d435f4f --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_fmal.c @@ -0,0 +1,272 @@ +/*- + * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <fenv.h> +#include <float.h> +#include <math.h> + +#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. + * + * We use scaling to avoid overflow/underflow, along with the + * canonical precision-doubling technique adapted from: + * + * Dekker, T. A Floating-Point Technique for Extending the + * Available Precision. Numer. Math. 18, 224-242 (1971). + */ +long double +fmal(long double x, long double y, long double z) +{ + long double xs, ys, zs, adj; + struct dd xy, r; + int oround; + int ex, ey, ez; + int spread; + + /* + * Handle special cases. The order of operations and the particular + * return values here are crucial in handling special cases involving + * infinities, NaNs, overflows, and signed zeroes correctly. + */ + if (x == 0.0 || y == 0.0) + return (x * y + z); + if (z == 0.0) + return (x * y); + if (!isfinite(x) || !isfinite(y)) + return (x * y + z); + if (!isfinite(z)) + return (z); + + xs = frexpl(x, &ex); + ys = frexpl(y, &ey); + zs = frexpl(z, &ez); + oround = fegetround(); + spread = ex + ey - ez; + + /* + * If x * y and z are many orders of magnitude apart, the scaling + * will overflow, so we handle these cases specially. Rounding + * modes other than FE_TONEAREST are painful. + */ + if (spread < -LDBL_MANT_DIG) { + feraiseexcept(FE_INEXACT); + if (!isnormal(z)) + feraiseexcept(FE_UNDERFLOW); + switch (oround) { + case FE_TONEAREST: + return (z); + case FE_TOWARDZERO: + if (x > 0.0 ^ y < 0.0 ^ z < 0.0) + return (z); + else + return (nextafterl(z, 0)); + case FE_DOWNWARD: + if (x > 0.0 ^ y < 0.0) + return (z); + else + return (nextafterl(z, -INFINITY)); + default: /* FE_UPWARD */ + if (x > 0.0 ^ y < 0.0) + return (nextafterl(z, INFINITY)); + else + return (z); + } + } + if (spread <= LDBL_MANT_DIG * 2) + zs = ldexpl(zs, -spread); + else + zs = copysignl(LDBL_MIN, zs); + + fesetround(FE_TONEAREST); + /* work around clang bug 8100 */ + volatile long double vxs = xs; + + /* + * 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(vxs, ys); + r = dd_add(xy.hi, zs); + + spread = ex + ey; + + if (r.hi == 0.0) { + /* + * When the addends cancel to 0, ensure that the result has + * the correct sign. + */ + fesetround(oround); + volatile long double vzs = zs; /* XXX gcc CSE bug workaround */ + return (xy.hi + vzs + ldexpl(xy.lo, spread)); + } + + if (oround != FE_TONEAREST) { + /* + * There is no need to worry about double rounding in directed + * rounding modes. + */ + fesetround(oround); + /* work around clang bug 8100 */ + volatile long double vrlo = r.lo; + adj = vrlo + 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/libm/src/s_fmax.c b/libm/upstream-freebsd/lib/msun/src/s_fmax.c index 3345f67..b51b865 100644 --- a/libm/src/s_fmax.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fmax.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmax.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_fmaxf.c b/libm/upstream-freebsd/lib/msun/src/s_fmaxf.c index b67f654..423da54 100644 --- a/libm/src/s_fmaxf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fmaxf.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_fmaxl.c b/libm/upstream-freebsd/lib/msun/src/s_fmaxl.c index c1a9dbe..0ac48a9 100644 --- a/libm/src/s_fmaxl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fmaxl.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_fmin.c b/libm/upstream-freebsd/lib/msun/src/s_fmin.c index 49b9cc4..3500c84 100644 --- a/libm/src/s_fmin.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fmin.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmin.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_fminf.c b/libm/upstream-freebsd/lib/msun/src/s_fminf.c index a6fb575..76a5c76 100644 --- a/libm/src/s_fminf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fminf.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fminf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_fminl.c b/libm/upstream-freebsd/lib/msun/src/s_fminl.c index 5f8c50e..f9d3ebb 100644 --- a/libm/src/s_fminl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_fminl.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fminl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_frexp.c b/libm/upstream-freebsd/lib/msun/src/s_frexp.c index d89e135..318a991 100644 --- a/libm/src/s_frexp.c +++ b/libm/upstream-freebsd/lib/msun/src/s_frexp.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.10 2005/03/07 21:27:37 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * for non-zero x @@ -24,7 +23,6 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.10 2005/03/07 21 * with *exp=0. */ -#include <sys/cdefs.h> #include <float.h> #include "math.h" diff --git a/libm/src/s_frexpf.c b/libm/upstream-freebsd/lib/msun/src/s_frexpf.c index c18cd54..5a7c486 100644 --- a/libm/src/s_frexpf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_frexpf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexpf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/src/s_frexpl.c b/libm/upstream-freebsd/lib/msun/src/s_frexpl.c index 20b3167..d34f55d 100644 --- a/libm/src/s_frexpl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_frexpl.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/src/s_frexpl.c,v 1.1 2005/03/07 04:54:51 das Exp $ + * $FreeBSD$ */ #include <float.h> diff --git a/libm/src/s_ilogb.c b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c index bd4a44b..a930bc9 100644 --- a/libm/src/s_ilogb.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogb.c,v 1.9 2004/10/09 17:14:28 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* ilogb(double x) * return the binary exponent of non-zero x diff --git a/libm/src/s_ilogbf.c b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c index 3c9c4de..93fe295 100644 --- a/libm/src/s_ilogbf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogbf.c,v 1.7 2004/10/09 17:14:28 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include <limits.h> diff --git a/libm/src/s_ilogbl.c b/libm/upstream-freebsd/lib/msun/src/s_ilogbl.c index 406ad56..3211f44 100644 --- a/libm/src/s_ilogbl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_ilogbl.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.1 2004/10/11 18:13:52 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include <float.h> #include <limits.h> diff --git a/libm/src/s_llrint.c b/libm/upstream-freebsd/lib/msun/src/s_llrint.c index 8a67f3a..7c959ec 100644 --- a/libm/src/s_llrint.c +++ b/libm/upstream-freebsd/lib/msun/src/s_llrint.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type double #define roundit rint diff --git a/libm/src/s_llrintf.c b/libm/upstream-freebsd/lib/msun/src/s_llrintf.c index 4d75e38..7ec6015 100644 --- a/libm/src/s_llrintf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_llrintf.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type float #define roundit rintf diff --git a/libm/upstream-freebsd/lib/msun/src/s_llrintl.c b/libm/upstream-freebsd/lib/msun/src/s_llrintl.c new file mode 100644 index 0000000..6ef8375 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_llrintl.c @@ -0,0 +1,9 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit rintl +#define dtype long long +#define fn llrintl + +#include "s_lrint.c" diff --git a/libm/upstream-freebsd/lib/msun/src/s_llround.c b/libm/upstream-freebsd/lib/msun/src/s_llround.c new file mode 100644 index 0000000..827dfc1 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_llround.c @@ -0,0 +1,11 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type double +#define roundit round +#define dtype long long +#define DTYPE_MIN LLONG_MIN +#define DTYPE_MAX LLONG_MAX +#define fn llround + +#include "s_lround.c" diff --git a/libm/upstream-freebsd/lib/msun/src/s_llroundf.c b/libm/upstream-freebsd/lib/msun/src/s_llroundf.c new file mode 100644 index 0000000..c037a18 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_llroundf.c @@ -0,0 +1,11 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type float +#define roundit roundf +#define dtype long long +#define DTYPE_MIN LLONG_MIN +#define DTYPE_MAX LLONG_MAX +#define fn llroundf + +#include "s_lround.c" diff --git a/libm/upstream-freebsd/lib/msun/src/s_llroundl.c b/libm/upstream-freebsd/lib/msun/src/s_llroundl.c new file mode 100644 index 0000000..02c44eb --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_llroundl.c @@ -0,0 +1,11 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit roundl +#define dtype long long +#define DTYPE_MIN LLONG_MIN +#define DTYPE_MAX LLONG_MAX +#define fn llroundl + +#include "s_lround.c" diff --git a/libm/src/s_log1p.c b/libm/upstream-freebsd/lib/msun/src/s_log1p.c index 56e1516..3cc77bd 100644 --- a/libm/src/s_log1p.c +++ b/libm/upstream-freebsd/lib/msun/src/s_log1p.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_log1p.c,v 1.8 2005/12/04 12:28:33 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* double log1p(double x) * @@ -79,6 +78,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_log1p.c,v 1.8 2005/12/04 12: * See HP-15C Advanced Functions Handbook, p.193. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -95,6 +96,7 @@ Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ static const double zero = 0.0; +static volatile double vzero = 0.0; double log1p(double x) @@ -108,7 +110,7 @@ log1p(double x) k = 1; if (hx < 0x3FDA827A) { /* 1+x < sqrt(2)+ */ if(ax>=0x3ff00000) { /* x <= -1.0 */ - if(x==-1.0) return -two54/zero; /* log1p(-1)=+inf */ + if(x==-1.0) return -two54/vzero; /* log1p(-1)=+inf */ else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ } if(ax<0x3e200000) { /* |x| < 2**-29 */ @@ -124,7 +126,7 @@ log1p(double x) if (hx >= 0x7ff00000) return x+x; if(k!=0) { if(hx<0x43400000) { - u = 1.0+x; + STRICT_ASSIGN(double,u,1.0+x); GET_HIGH_WORD(hu,u); k = (hu>>20)-1023; c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */ @@ -154,8 +156,14 @@ log1p(double x) } hfsq=0.5*f*f; if(hu==0) { /* |f| < 2**-20 */ - if(f==zero) if(k==0) return zero; - else {c += k*ln2_lo; return k*ln2_hi+c;} + if(f==zero) { + if(k==0) { + return zero; + } else { + c += k*ln2_lo; + return k*ln2_hi+c; + } + } R = hfsq*(1.0-0.66666666666666666*f); if(k==0) return f-R; else return k*ln2_hi-((R-(k*ln2_lo+c))-f); @@ -166,3 +174,7 @@ log1p(double x) if(k==0) return f-(hfsq-s*(hfsq+R)); else return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(log1p, log1pl); +#endif diff --git a/libm/src/s_log1pf.c b/libm/upstream-freebsd/lib/msun/src/s_log1pf.c index 8364da0..df04c67 100644 --- a/libm/src/s_log1pf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_log1pf.c @@ -13,9 +13,10 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_log1pf.c,v 1.9 2005/12/04 12:30:44 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" @@ -33,6 +34,7 @@ Lp6 = 1.5313838422e-01, /* 3E1CD04F */ Lp7 = 1.4798198640e-01; /* 3E178897 */ static const float zero = 0.0; +static volatile float vzero = 0.0; float log1pf(float x) @@ -46,12 +48,12 @@ log1pf(float x) k = 1; if (hx < 0x3ed413d0) { /* 1+x < sqrt(2)+ */ if(ax>=0x3f800000) { /* x <= -1.0 */ - if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */ + if(x==(float)-1.0) return -two25/vzero; /* log1p(-1)=+inf */ else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ } - if(ax<0x31000000) { /* |x| < 2**-29 */ + if(ax<0x38000000) { /* |x| < 2**-15 */ if(two25+x>zero /* raise inexact */ - &&ax<0x24800000) /* |x| < 2**-54 */ + &&ax<0x33800000) /* |x| < 2**-24 */ return x; else return x - x*x*(float)0.5; @@ -62,7 +64,7 @@ log1pf(float x) if (hx >= 0x7f800000) return x+x; if(k!=0) { if(hx<0x5a000000) { - *(volatile float *)&u = (float)1.0+x; + STRICT_ASSIGN(float,u,(float)1.0+x); GET_FLOAT_WORD(hu,u); k = (hu>>23)-127; /* correction term */ @@ -93,8 +95,14 @@ log1pf(float x) } hfsq=(float)0.5*f*f; if(hu==0) { /* |f| < 2**-20 */ - if(f==zero) if(k==0) return zero; - else {c += k*ln2_lo; return k*ln2_hi+c;} + if(f==zero) { + if(k==0) { + return zero; + } else { + c += k*ln2_lo; + return k*ln2_hi+c; + } + } R = hfsq*((float)1.0-(float)0.66666666666666666*f); if(k==0) return f-R; else return k*ln2_hi-((R-(k*ln2_lo+c))-f); diff --git a/libm/src/s_logb.c b/libm/upstream-freebsd/lib/msun/src/s_logb.c index 57f91c4..a47e354 100644 --- a/libm/src/s_logb.c +++ b/libm/upstream-freebsd/lib/msun/src/s_logb.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logb.c,v 1.10 2005/12/03 11:57:19 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * double logb(x) @@ -20,6 +19,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logb.c,v 1.10 2005/12/03 11: * Use ilogb instead. */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -42,3 +43,7 @@ logb(double x) } else return (double) ((ix>>20)-1023); } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(logb, logbl); +#endif diff --git a/libm/src/s_logbf.c b/libm/upstream-freebsd/lib/msun/src/s_logbf.c index c54928c..3ab190d 100644 --- a/libm/src/s_logbf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_logbf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logbf.c,v 1.8 2005/12/03 11:57:19 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/upstream-freebsd/lib/msun/src/s_logbl.c b/libm/upstream-freebsd/lib/msun/src/s_logbl.c new file mode 100644 index 0000000..7e88e36 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_logbl.c @@ -0,0 +1,55 @@ +/* + * From: @(#)s_ilogb.c 5.1 93/09/24 + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifndef lint +static char rcsid[] = "$FreeBSD$"; +#endif + +#include <float.h> +#include <limits.h> +#include <math.h> + +#include "fpmath.h" + +long double +logbl(long double x) +{ + union IEEEl2bits u; + unsigned long m; + int b; + + u.e = x; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) { /* x == 0 */ + u.bits.sign = 1; + return (1.0L / u.e); + } + /* denormalized */ + if (u.bits.manh == 0) { + m = 1lu << (LDBL_MANL_SIZE - 1); + for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1) + b++; + } else { + m = 1lu << (LDBL_MANH_SIZE - 1); + for (b = 0; !(u.bits.manh & m); m >>= 1) + b++; + } +#ifdef LDBL_IMPLICIT_NBIT + b++; +#endif + return ((long double)(LDBL_MIN_EXP - b - 1)); + } + if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) /* normal */ + return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1)); + else /* +/- inf or nan */ + return (x * x); +} diff --git a/libm/src/s_lrint.c b/libm/upstream-freebsd/lib/msun/src/s_lrint.c index 74a09d3..27ff5ff 100644 --- a/libm/src/s_lrint.c +++ b/libm/upstream-freebsd/lib/msun/src/s_lrint.c @@ -29,7 +29,7 @@ #include <math.h> #ifndef type -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type double #define roundit rint #define dtype long diff --git a/libm/src/s_lrintf.c b/libm/upstream-freebsd/lib/msun/src/s_lrintf.c index f258e03..a757ded 100644 --- a/libm/src/s_lrintf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_lrintf.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type float #define roundit rintf diff --git a/libm/upstream-freebsd/lib/msun/src/s_lrintl.c b/libm/upstream-freebsd/lib/msun/src/s_lrintl.c new file mode 100644 index 0000000..497b442 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_lrintl.c @@ -0,0 +1,9 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit rintl +#define dtype long +#define fn lrintl + +#include "s_lrint.c" diff --git a/libm/src/s_lround.c b/libm/upstream-freebsd/lib/msun/src/s_lround.c index e99f46f..3cff489 100644 --- a/libm/src/s_lround.c +++ b/libm/upstream-freebsd/lib/msun/src/s_lround.c @@ -25,12 +25,12 @@ */ #include <sys/cdefs.h> -#include <limits.h> +#include <sys/limits.h> #include <fenv.h> #include <math.h> #ifndef type -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lround.c,v 1.2 2005/04/08 00:52:16 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type double #define roundit round #define dtype long diff --git a/libm/src/s_lroundf.c b/libm/upstream-freebsd/lib/msun/src/s_lroundf.c index e069c9c..e24fe7f 100644 --- a/libm/src/s_lroundf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_lroundf.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lroundf.c,v 1.2 2005/04/08 00:52:27 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type float #define roundit roundf diff --git a/libm/src/s_lroundl.c b/libm/upstream-freebsd/lib/msun/src/s_lroundl.c index 7c3f854..e410827 100644 --- a/libm/src/s_lroundl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_lroundl.c @@ -1,5 +1,5 @@ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lroundl.c,v 1.1 2005/04/08 01:24:08 das Exp $"); */ +__FBSDID("$FreeBSD$"); #define type long double #define roundit roundl diff --git a/libm/src/s_modf.c b/libm/upstream-freebsd/lib/msun/src/s_modf.c index 683fbda..ab13191 100644 --- a/libm/src/s_modf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_modf.c @@ -11,7 +11,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_modf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif /* @@ -55,6 +55,10 @@ modf(double x, double *iptr) } } else if (j0>51) { /* no fraction part */ u_int32_t high; + if (j0 == 0x400) { /* inf/NaN */ + *iptr = x; + return 0.0 / x; + } *iptr = x*one; GET_HIGH_WORD(high,x); INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ diff --git a/libm/src/s_modff.c b/libm/upstream-freebsd/lib/msun/src/s_modff.c index 6c75ffd..062259c 100644 --- a/libm/src/s_modff.c +++ b/libm/upstream-freebsd/lib/msun/src/s_modff.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_modff.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -49,6 +48,8 @@ modff(float x, float *iptr) } else { /* no fraction part */ u_int32_t ix; *iptr = x*one; + if (x != x) /* NaN */ + return x; GET_FLOAT_WORD(ix,x); SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ return x; diff --git a/libm/upstream-freebsd/lib/msun/src/s_modfl.c b/libm/upstream-freebsd/lib/msun/src/s_modfl.c new file mode 100644 index 0000000..3dcdf86 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_modfl.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> + * 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. + * + * Derived from s_modf.c, which has the following Copyright: + * ==================================================== + * 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. + * ==================================================== + * + * $FreeBSD$ + */ + +#include <float.h> +#include <math.h> +#include <sys/types.h> + +#include "fpmath.h" + +#if LDBL_MANL_SIZE > 32 +#define MASK ((uint64_t)-1) +#else +#define MASK ((uint32_t)-1) +#endif +/* Return the last n bits of a word, representing the fractional part. */ +#define GETFRAC(bits, n) ((bits) & ~(MASK << (n))) +/* The number of fraction bits in manh, not counting the integer bit */ +#define HIBITS (LDBL_MANT_DIG - LDBL_MANL_SIZE) + +static const long double zero[] = { 0.0L, -0.0L }; + +long double +modfl(long double x, long double *iptr) +{ + union IEEEl2bits ux; + int e; + + ux.e = x; + e = ux.bits.exp - LDBL_MAX_EXP + 1; + if (e < HIBITS) { /* Integer part is in manh. */ + if (e < 0) { /* |x|<1 */ + *iptr = zero[ux.bits.sign]; + return (x); + } else { + if ((GETFRAC(ux.bits.manh, HIBITS - 1 - e) | + ux.bits.manl) == 0) { /* X is an integer. */ + *iptr = x; + return (zero[ux.bits.sign]); + } else { + /* Clear all but the top e+1 bits. */ + ux.bits.manh >>= HIBITS - 1 - e; + ux.bits.manh <<= HIBITS - 1 - e; + ux.bits.manl = 0; + *iptr = ux.e; + return (x - ux.e); + } + } + } else if (e >= LDBL_MANT_DIG - 1) { /* x has no fraction part. */ + *iptr = x; + if (x != x) /* Handle NaNs. */ + return (x); + return (zero[ux.bits.sign]); + } else { /* Fraction part is in manl. */ + if (GETFRAC(ux.bits.manl, LDBL_MANT_DIG - 1 - e) == 0) { + /* x is integral. */ + *iptr = x; + return (zero[ux.bits.sign]); + } else { + /* Clear all but the top e+1 bits. */ + ux.bits.manl >>= LDBL_MANT_DIG - 1 - e; + ux.bits.manl <<= LDBL_MANT_DIG - 1 - e; + *iptr = ux.e; + return (x - ux.e); + } + } +} diff --git a/libm/src/s_nan.c b/libm/upstream-freebsd/lib/msun/src/s_nan.c index e366e6b..890f471 100644 --- a/libm/src/s_nan.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nan.c @@ -35,27 +35,6 @@ #include "math_private.h" -/* digittoint is in the FreeBSD C library, but not Bionic at this point */ -static int -digittoint(char ch) -{ - int d; - - d = ch - '0'; - if ((unsigned)d < 10) { - return d; - } - d = ch - 'a'; - if ((unsigned)d < 6) { - return d + 10; - } - d = ch - 'A'; - if ((unsigned)d < 6) { - return d + 10; - } - return -1; -} - /* * Scan a string of hexadecimal digits (the format nan(3) expects) and * make a bit array (using the local endianness). We stop when we @@ -127,5 +106,5 @@ nanf(const char *s) } #if (LDBL_MANT_DIG == 53) -__weak_alias(nanl, nan); +__weak_reference(nan, nanl); #endif diff --git a/libm/src/s_nearbyint.c b/libm/upstream-freebsd/lib/msun/src/s_nearbyint.c index 246d325..063f8d7 100644 --- a/libm/src/s_nearbyint.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nearbyint.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_nearbyint.c,v 1.1 2004/07/06 04:46:08 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <fenv.h> #include <math.h> @@ -36,12 +36,16 @@ * instead of feclearexcept()/feupdateenv() to restore the environment * because the only exception defined for rint() is overflow, and * rounding can't overflow as long as emax >= p. + * + * The volatile keyword is needed below because clang incorrectly assumes + * that rint won't raise any floating-point exceptions. Declaring ret volatile + * is sufficient to trick the compiler into doing the right thing. */ #define DECL(type, fn, rint) \ type \ fn(type x) \ { \ - type ret; \ + volatile type ret; \ fenv_t env; \ \ fegetenv(&env); \ @@ -52,3 +56,4 @@ fn(type x) \ DECL(double, nearbyint, rint) DECL(float, nearbyintf, rintf) +DECL(long double, nearbyintl, rintl) diff --git a/libm/src/s_nextafter.c b/libm/upstream-freebsd/lib/msun/src/s_nextafter.c index 3ed0361..52dd21c 100644 --- a/libm/src/s_nextafter.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nextafter.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.11 2005/03/07 21:27:37 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* IEEE functions * nextafter(x,y) @@ -21,7 +20,6 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.11 2005/03/0 * Special cases: */ -#include <sys/cdefs.h> #include <float.h> #include "math.h" diff --git a/libm/src/s_nextafterf.c b/libm/upstream-freebsd/lib/msun/src/s_nextafterf.c index ebeac4a..96e21ef 100644 --- a/libm/src/s_nextafterf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nextafterf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterf.c,v 1.10 2005/03/07 04:55:58 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/src/s_nextafterl.c b/libm/upstream-freebsd/lib/msun/src/s_nextafterl.c index eacfd33..9c61a43 100644 --- a/libm/src/s_nextafterl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nextafterl.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.1 2005/03/07 04:56:46 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* IEEE functions * nextafter(x,y) @@ -21,7 +20,6 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.1 2005/03/0 * Special cases: */ -#include <sys/cdefs.h> #include <float.h> #include "fpmath.h" diff --git a/libm/src/s_nexttoward.c b/libm/upstream-freebsd/lib/msun/src/s_nexttoward.c index 55da4ad..b2a50d3 100644 --- a/libm/src/s_nexttoward.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nexttoward.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nexttoward.c,v 1.1 2005/03/07 04:56:46 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * We assume that a long double has a 15-bit exponent. On systems @@ -64,8 +63,8 @@ nexttoward(double x, long double y) if(ix<0x00100000) { /* underflow */ t = x*x; if(t!=x) { /* raise underflow flag */ - INSERT_WORDS(y,hx,lx); - return y; + INSERT_WORDS(x,hx,lx); + return x; } } INSERT_WORDS(x,hx,lx); diff --git a/libm/src/s_nexttowardf.c b/libm/upstream-freebsd/lib/msun/src/s_nexttowardf.c index 54156e6..9ddfff9 100644 --- a/libm/src/s_nexttowardf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_nexttowardf.c @@ -9,9 +9,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.1 2005/03/07 04:57:38 das Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include <float.h> @@ -51,8 +50,8 @@ nexttowardf(float x, long double y) if(ix<0x00800000) { /* underflow */ t = x*x; if(t!=x) { /* raise underflow flag */ - SET_FLOAT_WORD(y,hx); - return y; + SET_FLOAT_WORD(x,hx); + return x; } } SET_FLOAT_WORD(x,hx); diff --git a/libm/src/s_remquo.c b/libm/upstream-freebsd/lib/msun/src/s_remquo.c index 9ad1e4c..d811c69 100644 --- a/libm/src/s_remquo.c +++ b/libm/upstream-freebsd/lib/msun/src/s_remquo.c @@ -11,7 +11,9 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_remquo.c,v 1.1 2005/03/25 04:40:44 das Exp $"); */ +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #include "math_private.h" @@ -49,7 +51,7 @@ remquo(double x, double y, int *quo) goto fixup; /* |x|<|y| return x or x-y */ } if(lx==ly) { - *quo = (sxy ? -1 : 1); + *quo = (sxy ? -1 : 1); return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/ } } @@ -112,8 +114,8 @@ remquo(double x, double y, int *quo) /* convert back to floating value and restore the sign */ if((hx|lx)==0) { /* return sign(x)*0 */ - q &= 0x7fffffff; - *quo = (sxy ? -q : q); + q &= 0x7fffffff; + *quo = (sxy ? -q : q); return Zero[(u_int32_t)sx>>31]; } while(hx<0x00100000) { /* normalize x */ @@ -128,9 +130,9 @@ remquo(double x, double y, int *quo) lx = (lx>>n)|((u_int32_t)hx<<(32-n)); hx >>= n; } else if (n<=31) { - lx = (hx<<(32-n))|(lx>>n); hx = 0; + lx = (hx<<(32-n))|(lx>>n); hx = 0; } else { - lx = hx>>(n-32); hx = 0; + lx = hx>>(n-32); hx = 0; } } fixup: @@ -151,3 +153,7 @@ fixup: *quo = (sxy ? -q : q); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(remquo, remquol); +#endif diff --git a/libm/src/s_remquof.c b/libm/upstream-freebsd/lib/msun/src/s_remquof.c index 43e05cb..f7b4c00 100644 --- a/libm/src/s_remquof.c +++ b/libm/upstream-freebsd/lib/msun/src/s_remquof.c @@ -11,7 +11,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_remquof.c,v 1.1 2005/03/25 04:40:44 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" @@ -46,7 +46,7 @@ remquof(float x, float y, int *quo) q = 0; goto fixup; /* |x|<|y| return x or x-y */ } else if(hx==hy) { - *quo = (sxy ? -1 : 1); + *quo = (sxy ? -1 : 1); return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/ } @@ -88,8 +88,8 @@ remquof(float x, float y, int *quo) /* convert back to floating value and restore the sign */ if(hx==0) { /* return sign(x)*0 */ - q &= 0x7fffffff; - *quo = (sxy ? -q : q); + q &= 0x7fffffff; + *quo = (sxy ? -q : q); return Zero[(u_int32_t)sx>>31]; } while(hx<0x00800000) { /* normalize x */ diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquol.c b/libm/upstream-freebsd/lib/msun/src/s_remquol.c new file mode 100644 index 0000000..8899293 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_remquol.c @@ -0,0 +1,178 @@ +/* @(#)e_fmod.c 1.3 95/01/18 */ +/*- + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <stdint.h> + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define BIAS (LDBL_MAX_EXP - 1) + +#if LDBL_MANL_SIZE > 32 +typedef uint64_t manl_t; +#else +typedef uint32_t manl_t; +#endif + +#if LDBL_MANH_SIZE > 32 +typedef uint64_t manh_t; +#else +typedef uint32_t manh_t; +#endif + +/* + * These macros add and remove an explicit integer bit in front of the + * fractional mantissa, if the architecture doesn't have such a bit by + * default already. + */ +#ifdef LDBL_IMPLICIT_NBIT +#define SET_NBIT(hx) ((hx) | (1ULL << LDBL_MANH_SIZE)) +#define HFRAC_BITS LDBL_MANH_SIZE +#else +#define SET_NBIT(hx) (hx) +#define HFRAC_BITS (LDBL_MANH_SIZE - 1) +#endif + +#define MANL_SHIFT (LDBL_MANL_SIZE - 1) + +static const long double Zero[] = {0.0L, -0.0L}; + +/* + * Return the IEEE remainder and set *quo to the last n bits of the + * quotient, rounded to the nearest integer. We choose n=31 because + * we wind up computing all the integer bits of the quotient anyway as + * a side-effect of computing the remainder by the shift and subtract + * method. In practice, this is far more bits than are needed to use + * remquo in reduction algorithms. + * + * Assumptions: + * - The low part of the mantissa fits in a manl_t exactly. + * - The high part of the mantissa fits in an int64_t with enough room + * for an explicit integer bit in front of the fractional bits. + */ +long double +remquol(long double x, long double y, int *quo) +{ + union IEEEl2bits ux, uy; + int64_t hx,hz; /* We need a carry bit even if LDBL_MANH_SIZE is 32. */ + manh_t hy; + manl_t lx,ly,lz; + int ix,iy,n,q,sx,sxy; + + ux.e = x; + uy.e = y; + sx = ux.bits.sign; + sxy = sx ^ uy.bits.sign; + ux.bits.sign = 0; /* |x| */ + uy.bits.sign = 0; /* |y| */ + x = ux.e; + + /* purge off exception values */ + if((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */ + (ux.bits.exp == BIAS + LDBL_MAX_EXP) || /* or x not finite */ + (uy.bits.exp == BIAS + LDBL_MAX_EXP && + ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */ + return (x*y)/(x*y); + if(ux.bits.exp<=uy.bits.exp) { + if((ux.bits.exp<uy.bits.exp) || + (ux.bits.manh<=uy.bits.manh && + (ux.bits.manh<uy.bits.manh || + ux.bits.manl<uy.bits.manl))) { + q = 0; + goto fixup; /* |x|<|y| return x or x-y */ + } + if(ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl) { + *quo = (sxy ? -1 : 1); + return Zero[sx]; /* |x|=|y| return x*0*/ + } + } + + /* determine ix = ilogb(x) */ + if(ux.bits.exp == 0) { /* subnormal x */ + ux.e *= 0x1.0p512; + ix = ux.bits.exp - (BIAS + 512); + } else { + ix = ux.bits.exp - BIAS; + } + + /* determine iy = ilogb(y) */ + if(uy.bits.exp == 0) { /* subnormal y */ + uy.e *= 0x1.0p512; + iy = uy.bits.exp - (BIAS + 512); + } else { + iy = uy.bits.exp - BIAS; + } + + /* set up {hx,lx}, {hy,ly} and align y to x */ + hx = SET_NBIT(ux.bits.manh); + hy = SET_NBIT(uy.bits.manh); + lx = ux.bits.manl; + ly = uy.bits.manl; + + /* fix point fmod */ + n = ix - iy; + q = 0; + + while(n--) { + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; + if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;} + else {hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz; q++;} + q <<= 1; + } + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1; + if(hz>=0) {hx=hz;lx=lz;q++;} + + /* convert back to floating value and restore the sign */ + if((hx|lx)==0) { /* return sign(x)*0 */ + q &= 0x7fffffff; + *quo = (sxy ? -q : q); + return Zero[sx]; + } + while(hx<(1ULL<<HFRAC_BITS)) { /* normalize x */ + hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx; + iy -= 1; + } + ux.bits.manh = hx; /* The integer bit is truncated here if needed. */ + ux.bits.manl = lx; + if (iy < LDBL_MIN_EXP) { + ux.bits.exp = iy + (BIAS + 512); + ux.e *= 0x1p-512; + } else { + ux.bits.exp = iy + BIAS; + } + ux.bits.sign = 0; + x = ux.e; +fixup: + y = fabsl(y); + if (y < LDBL_MIN * 2) { + if (x+x>y || (x+x==y && (q & 1))) { + q++; + x-=y; + } + } else if (x>0.5*y || (x==0.5*y && (q & 1))) { + q++; + x-=y; + } + + ux.e = x; + ux.bits.sign ^= sx; + x = ux.e; + + q &= 0x7fffffff; + *quo = (sxy ? -q : q); + return x; +} diff --git a/libm/src/s_rint.c b/libm/upstream-freebsd/lib/msun/src/s_rint.c index a88d7b7..c56f8fb 100644 --- a/libm/src/s_rint.c +++ b/libm/upstream-freebsd/lib/msun/src/s_rint.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rint.c,v 1.13 2005/12/03 07:38:35 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * rint(x) @@ -24,6 +23,8 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rint.c,v 1.13 2005/12/03 07: * Inexact flag raised if x not equal to rint(x). */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -49,7 +50,7 @@ rint(double x) i0 &= 0xfffe0000; i0 |= ((i1|-i1)>>12)&0x80000; SET_HIGH_WORD(x,i0); - w = TWO52[sx]+x; + STRICT_ASSIGN(double,w,TWO52[sx]+x); t = w-TWO52[sx]; GET_HIGH_WORD(i0,t); SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31)); @@ -82,6 +83,10 @@ rint(double x) if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); } INSERT_WORDS(x,i0,i1); - *(volatile double *)&w = TWO52[sx]+x; /* clip any extra precision */ + STRICT_ASSIGN(double,w,TWO52[sx]+x); return w-TWO52[sx]; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(rint, rintl); +#endif diff --git a/libm/src/s_rintf.c b/libm/upstream-freebsd/lib/msun/src/s_rintf.c index 677421a..f8743a4 100644 --- a/libm/src/s_rintf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_rintf.c @@ -13,11 +13,12 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rintf.c,v 1.10 2005/12/03 09:00:29 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <stdint.h> -#include <sys/types.h> #include "math.h" #include "math_private.h" @@ -31,20 +32,20 @@ float rintf(float x) { int32_t i0,j0,sx; - volatile float w,t; /* volatile works around gcc bug */ + float w,t; GET_FLOAT_WORD(i0,x); sx = (i0>>31)&1; j0 = ((i0>>23)&0xff)-0x7f; if(j0<23) { if(j0<0) { if((i0&0x7fffffff)==0) return x; - w = TWO23[sx]+x; + STRICT_ASSIGN(float,w,TWO23[sx]+x); t = w-TWO23[sx]; GET_FLOAT_WORD(i0,t); SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31)); return t; } - w = TWO23[sx]+x; + STRICT_ASSIGN(float,w,TWO23[sx]+x); return w-TWO23[sx]; } if(j0==0x80) return x+x; /* inf or NaN */ diff --git a/libm/upstream-freebsd/lib/msun/src/s_rintl.c b/libm/upstream-freebsd/lib/msun/src/s_rintl.c new file mode 100644 index 0000000..e55b40e --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_rintl.c @@ -0,0 +1,91 @@ +/*- + * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#include <math.h> +#include <stdint.h> + +#include "fpmath.h" + +#if LDBL_MAX_EXP != 0x4000 +/* We also require the usual bias, min exp and expsign packing. */ +#error "Unsupported long double format" +#endif + +#define BIAS (LDBL_MAX_EXP - 1) + +static const float +shift[2] = { +#if LDBL_MANT_DIG == 64 + 0x1.0p63, -0x1.0p63 +#elif LDBL_MANT_DIG == 113 + 0x1.0p112, -0x1.0p112 +#else +#error "Unsupported long double format" +#endif +}; +static const float zero[2] = { 0.0, -0.0 }; + +long double +rintl(long double x) +{ + union IEEEl2bits u; + uint32_t expsign; + int ex, sign; + + u.e = x; + expsign = u.xbits.expsign; + ex = expsign & 0x7fff; + + if (ex >= BIAS + LDBL_MANT_DIG - 1) { + if (ex == BIAS + LDBL_MAX_EXP) + return (x + x); /* Inf, NaN, or unsupported format */ + return (x); /* finite and already an integer */ + } + sign = expsign >> 15; + + /* + * The following code assumes that intermediate results are + * evaluated in long double precision. If they are evaluated in + * greater precision, double rounding may occur, and if they are + * evaluated in less precision (as on i386), results will be + * wildly incorrect. + */ + x += shift[sign]; + x -= shift[sign]; + + /* + * If the result is +-0, then it must have the same sign as x, but + * the above calculation doesn't always give this. Fix up the sign. + */ + if (ex < BIAS && x == 0.0L) + return (zero[sign]); + + return (x); +} diff --git a/libm/src/s_round.c b/libm/upstream-freebsd/lib/msun/src/s_round.c index 274c119..65de31b 100644 --- a/libm/src/s_round.c +++ b/libm/upstream-freebsd/lib/msun/src/s_round.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_roundf.c b/libm/upstream-freebsd/lib/msun/src/s_roundf.c index 823be9b..952e8e7 100644 --- a/libm/src/s_roundf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_roundf.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_roundl.c b/libm/upstream-freebsd/lib/msun/src/s_roundl.c index a65f330..a70b617 100644 --- a/libm/src/s_roundl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_roundl.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_roundl.c,v 1.2 2005/12/02 13:45:06 bde Exp $"); */ +__FBSDID("$FreeBSD$"); #include <math.h> diff --git a/libm/src/s_scalbln.c b/libm/upstream-freebsd/lib/msun/src/s_scalbln.c index 41908d2..d609d4e 100644 --- a/libm/src/s_scalbln.c +++ b/libm/upstream-freebsd/lib/msun/src/s_scalbln.c @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_scalbln.c,v 1.2 2005/03/07 04:57:50 das Exp $"); */ +__FBSDID("$FreeBSD$"); #include <limits.h> #include <math.h> diff --git a/libm/src/s_scalbn.c b/libm/upstream-freebsd/lib/msun/src/s_scalbn.c index 6218c11..e7efaab 100644 --- a/libm/src/s_scalbn.c +++ b/libm/upstream-freebsd/lib/msun/src/s_scalbn.c @@ -11,7 +11,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbn.c,v 1.11 2005/03/07 21:27:37 das Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif /* @@ -60,20 +60,7 @@ scalbn (double x, int n) return x*twom54; } -// this is normally in FreeBSD's libc. -double -ldexp (double x, int n) -{ - return scalbn(x,n); -} - -#if (LDBL_MANT_DIG == 53) //XXX: brian FIXME __weak_reference doesn work -long double ldexpl (long double x, int n) { - return scalbn((double)x,n); -} -long double scalbnl (long double x, int n) { - return scalbn((double)x,n); -} +#if (LDBL_MANT_DIG == 53) __weak_reference(scalbn, ldexpl); __weak_reference(scalbn, scalbnl); #endif diff --git a/libm/src/s_scalbnf.c b/libm/upstream-freebsd/lib/msun/src/s_scalbnf.c index 46c7baf..7666c74 100644 --- a/libm/src/s_scalbnf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_scalbnf.c @@ -14,7 +14,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnf.c,v 1.8 2005/03/07 04:52:43 das Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif #include <sys/cdefs.h> diff --git a/libm/src/s_scalbnl.c b/libm/upstream-freebsd/lib/msun/src/s_scalbnl.c index c645d00..fc89f8d 100644 --- a/libm/src/s_scalbnl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_scalbnl.c @@ -11,7 +11,7 @@ */ #ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnl.c,v 1.1 2005/03/07 04:52:58 das Exp $"; +static char rcsid[] = "$FreeBSD$"; #endif /* diff --git a/libm/src/s_signgam.c b/libm/upstream-freebsd/lib/msun/src/s_signgam.c index d67d591..d67d591 100644 --- a/libm/src/s_signgam.c +++ b/libm/upstream-freebsd/lib/msun/src/s_signgam.c diff --git a/libm/src/s_significand.c b/libm/upstream-freebsd/lib/msun/src/s_significand.c index 08bb303..356e300 100644 --- a/libm/src/s_significand.c +++ b/libm/upstream-freebsd/lib/msun/src/s_significand.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_significand.c,v 1.9 2003/07/23 04:53:47 peter Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * significand(x) computes just diff --git a/libm/src/s_significandf.c b/libm/upstream-freebsd/lib/msun/src/s_significandf.c index b3e341d..ad030e2 100644 --- a/libm/src/s_significandf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_significandf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_significandf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/src/s_sin.c b/libm/upstream-freebsd/lib/msun/src/s_sin.c index e893e23..17ea846 100644 --- a/libm/src/s_sin.c +++ b/libm/upstream-freebsd/lib/msun/src/s_sin.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_sin.c,v 1.10 2005/10/24 14:08:36 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* sin(x) * Return sine function of x. @@ -45,8 +44,12 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_sin.c,v 1.10 2005/10/24 14:0 * TRIG(x) returns trig(x) nearly rounded */ +#include <float.h> + #include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double sin(double x) @@ -60,7 +63,7 @@ sin(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; if(ix <= 0x3fe921fb) { - if(ix<0x3e400000) /* |x| < 2**-27 */ + if(ix<0x3e500000) /* |x| < 2**-26 */ {if((int)x==0) return x;} /* generate inexact */ return __kernel_sin(x,z,0); } @@ -80,3 +83,7 @@ sin(double x) } } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(sin, sinl); +#endif diff --git a/libm/src/s_sinf.c b/libm/upstream-freebsd/lib/msun/src/s_sinf.c index 9dc3cae..41b5dc1 100644 --- a/libm/src/s_sinf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_sinf.c @@ -14,14 +14,17 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_sinf.c,v 1.14 2005/11/28 06:15:10 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF +#define INLINE_REM_PIO2F #include "math_private.h" +#include "e_rem_pio2f.c" #include "k_cosf.c" #include "k_sinf.c" @@ -35,7 +38,7 @@ s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ float sinf(float x) { - float y[2]; + double y; int32_t n, hx, ix; GET_FLOAT_WORD(hx,x); @@ -70,13 +73,13 @@ sinf(float x) /* general argument reduction needed */ else { - n = __ieee754_rem_pio2f(x,y); + n = __ieee754_rem_pio2f(x,&y); switch(n&3) { - case 0: return __kernel_sindf((double)y[0]+y[1]); - case 1: return __kernel_cosdf((double)y[0]+y[1]); - case 2: return __kernel_sindf(-(double)y[0]-y[1]); + case 0: return __kernel_sindf(y); + case 1: return __kernel_cosdf(y); + case 2: return __kernel_sindf(-y); default: - return -__kernel_cosdf((double)y[0]+y[1]); + return -__kernel_cosdf(y); } } } diff --git a/libm/upstream-freebsd/lib/msun/src/s_sinl.c b/libm/upstream-freebsd/lib/msun/src/s_sinl.c new file mode 100644 index 0000000..f454f8f --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_sinl.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2007 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "math.h" +#include "math_private.h" +#if LDBL_MANT_DIG == 64 +#include "../ld80/e_rem_pio2l.h" +#elif LDBL_MANT_DIG == 113 +#include "../ld128/e_rem_pio2l.h" +#else +#error "Unsupported long double format" +#endif + +long double +sinl(long double x) +{ + union IEEEl2bits z; + int e0, s; + long double y[2]; + long double hi, lo; + + z.e = x; + s = z.bits.sign; + z.bits.sign = 0; + + /* If x = +-0 or x is a subnormal number, then sin(x) = x */ + if (z.bits.exp == 0) + return (x); + + /* If x = NaN or Inf, then sin(x) = NaN. */ + if (z.bits.exp == 32767) + return ((x - x) / (x - x)); + + ENTERI(); + + /* Optimize the case where x is already within range. */ + if (z.e < M_PI_4) { + hi = __kernel_sinl(z.e, 0, 0); + RETURNI(s ? -hi : hi); + } + + e0 = __ieee754_rem_pio2l(x, y); + hi = y[0]; + lo = y[1]; + + switch (e0 & 3) { + case 0: + hi = __kernel_sinl(hi, lo, 1); + break; + case 1: + hi = __kernel_cosl(hi, lo); + break; + case 2: + hi = - __kernel_sinl(hi, lo, 1); + break; + case 3: + hi = - __kernel_cosl(hi, lo); + break; + } + + RETURNI(hi); +} diff --git a/libm/src/s_tan.c b/libm/upstream-freebsd/lib/msun/src/s_tan.c index 7f0b4a0..196c27e 100644 --- a/libm/src/s_tan.c +++ b/libm/upstream-freebsd/lib/msun/src/s_tan.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tan.c,v 1.10 2005/11/02 14:01:45 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* tan(x) * Return tangent function of x. @@ -44,8 +43,12 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tan.c,v 1.10 2005/11/02 14:0 * TRIG(x) returns trig(x) nearly rounded */ +#include <float.h> + #include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double tan(double x) @@ -59,7 +62,7 @@ tan(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; if(ix <= 0x3fe921fb) { - if(ix<0x3e300000) /* x < 2**-28 */ + if(ix<0x3e400000) /* x < 2**-27 */ if((int)x==0) return x; /* generate inexact */ return __kernel_tan(x,z,1); } @@ -74,3 +77,7 @@ tan(double x) -1 -- n odd */ } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(tan, tanl); +#endif diff --git a/libm/src/s_tanf.c b/libm/upstream-freebsd/lib/msun/src/s_tanf.c index 7e80d69..4fe8c17 100644 --- a/libm/src/s_tanf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_tanf.c @@ -14,13 +14,16 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanf.c,v 1.14 2005/11/28 05:35:32 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> #include "math.h" #define INLINE_KERNEL_TANDF +#define INLINE_REM_PIO2F #include "math_private.h" +#include "e_rem_pio2f.c" #include "k_tanf.c" /* Small multiples of pi/2 rounded to double precision. */ @@ -33,7 +36,7 @@ t4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ float tanf(float x) { - float y[2]; + double y; int32_t n, hx, ix; GET_FLOAT_WORD(hx,x); @@ -62,8 +65,8 @@ tanf(float x) /* general argument reduction needed */ else { - n = __ieee754_rem_pio2f(x,y); + n = __ieee754_rem_pio2f(x,&y); /* integer parameter: 1 -- n even; -1 -- n odd */ - return __kernel_tandf((double)y[0]+y[1],1-((n&1)<<1)); + return __kernel_tandf(y,1-((n&1)<<1)); } } diff --git a/libm/src/s_tanh.c b/libm/upstream-freebsd/lib/msun/src/s_tanh.c index 4729145..96e3565 100644 --- a/libm/src/s_tanh.c +++ b/libm/upstream-freebsd/lib/msun/src/s_tanh.c @@ -10,9 +10,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanh.c,v 1.7 2002/05/28 18:15:04 alfred Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* Tanh(x) * Return the Hyperbolic Tangent of x @@ -24,14 +23,14 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanh.c,v 1.7 2002/05/28 18:1 * x -x * e + e * 1. reduce x to non-negative by tanh(-x) = -tanh(x). - * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) + * 2. 0 <= x < 2**-28 : tanh(x) := x with inexact if x != 0 * -t - * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x) + * 2**-28 <= x < 1 : tanh(x) := -----; t = expm1(-2x) * t + 2 * 2 - * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x) + * 1 <= x < 22 : tanh(x) := 1 - -----; t = expm1(2x) * t + 2 - * 22.0 < x <= INF : tanh(x) := 1. + * 22 <= x <= INF : tanh(x) := 1. * * Special cases: * tanh(NaN) is NaN; @@ -41,7 +40,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanh.c,v 1.7 2002/05/28 18:1 #include "math.h" #include "math_private.h" -static const double one=1.0, two=2.0, tiny = 1.0e-300; +static const double one = 1.0, two = 2.0, tiny = 1.0e-300, huge = 1.0e300; double tanh(double x) @@ -49,7 +48,6 @@ tanh(double x) double t,z; int32_t jx,ix; - /* High word of |x|. */ GET_HIGH_WORD(jx,x); ix = jx&0x7fffffff; @@ -61,8 +59,9 @@ tanh(double x) /* |x| < 22 */ if (ix < 0x40360000) { /* |x|<22 */ - if (ix<0x3c800000) /* |x|<2**-55 */ - return x*(one+x); /* tanh(small) = small */ + if (ix<0x3e300000) { /* |x|<2**-28 */ + if(huge+x>one) return x; /* tanh(tiny) = tiny with inexact */ + } if (ix>=0x3ff00000) { /* |x|>=1 */ t = expm1(two*fabs(x)); z = one - two/(t+two); @@ -70,9 +69,9 @@ tanh(double x) t = expm1(-two*fabs(x)); z= -t/(t+two); } - /* |x| > 22, return +-1 */ + /* |x| >= 22, return +-1 */ } else { - z = one - tiny; /* raised inexact flag */ + z = one - tiny; /* raise inexact flag */ } return (jx>=0)? z: -z; } diff --git a/libm/src/s_tanhf.c b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c index 0aca6cc..04f09c6 100644 --- a/libm/src/s_tanhf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c @@ -13,9 +13,8 @@ * ==================================================== */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.8 2005/12/11 11:40:55 bde Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "math.h" #include "math_private.h" diff --git a/libm/upstream-freebsd/lib/msun/src/s_tanl.c b/libm/upstream-freebsd/lib/msun/src/s_tanl.c new file mode 100644 index 0000000..eadc837 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/s_tanl.c @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2007 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. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +/* + * Limited testing on pseudorandom numbers drawn within [0:4e8] shows + * an accuracy of <= 1.5 ULP where 247024 values of x out of 40 million + * possibles resulted in tan(x) that exceeded 0.5 ULP (ie., 0.6%). + */ + +#include <float.h> +#ifdef __i386__ +#include <ieeefp.h> +#endif + +#include "math.h" +#include "math_private.h" +#if LDBL_MANT_DIG == 64 +#include "../ld80/e_rem_pio2l.h" +#elif LDBL_MANT_DIG == 113 +#include "../ld128/e_rem_pio2l.h" +#else +#error "Unsupported long double format" +#endif + +long double +tanl(long double x) +{ + union IEEEl2bits z; + int e0, s; + long double y[2]; + long double hi, lo; + + z.e = x; + s = z.bits.sign; + z.bits.sign = 0; + + /* If x = +-0 or x is subnormal, then tan(x) = x. */ + if (z.bits.exp == 0) + return (x); + + /* If x = NaN or Inf, then tan(x) = NaN. */ + if (z.bits.exp == 32767) + return ((x - x) / (x - x)); + + ENTERI(); + + /* Optimize the case where x is already within range. */ + if (z.e < M_PI_4) { + hi = __kernel_tanl(z.e, 0, 0); + RETURNI(s ? -hi : hi); + } + + e0 = __ieee754_rem_pio2l(x, y); + hi = y[0]; + lo = y[1]; + + switch (e0 & 3) { + case 0: + case 2: + hi = __kernel_tanl(hi, lo, 0); + break; + case 1: + case 3: + hi = __kernel_tanl(hi, lo, 1); + break; + } + + RETURNI(hi); +} diff --git a/libm/src/s_tgammaf.c b/libm/upstream-freebsd/lib/msun/src/s_tgammaf.c index 9993d91..9993d91 100644 --- a/libm/src/s_tgammaf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_tgammaf.c diff --git a/libm/src/s_trunc.c b/libm/upstream-freebsd/lib/msun/src/s_trunc.c index d5287eb..63a6753 100644 --- a/libm/src/s_trunc.c +++ b/libm/upstream-freebsd/lib/msun/src/s_trunc.c @@ -11,7 +11,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_trunc.c,v 1.1 2004/06/20 09:25:43 das Exp $"); */ +__FBSDID("$FreeBSD$"); /* * trunc(x) @@ -22,6 +22,8 @@ * Inexact flag raised if x not equal to trunc(x). */ +#include <float.h> + #include "math.h" #include "math_private.h" @@ -31,7 +33,7 @@ double trunc(double x) { int32_t i0,i1,j0; - u_int32_t i,j; + u_int32_t i; EXTRACT_WORDS(i0,i1,x); j0 = ((i0>>20)&0x7ff)-0x3ff; if(j0<20) { @@ -59,3 +61,7 @@ trunc(double x) INSERT_WORDS(x,i0,i1); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(trunc, truncl); +#endif diff --git a/libm/src/s_truncf.c b/libm/upstream-freebsd/lib/msun/src/s_truncf.c index 86b7247..384eaee 100644 --- a/libm/src/s_truncf.c +++ b/libm/upstream-freebsd/lib/msun/src/s_truncf.c @@ -11,7 +11,7 @@ */ #include <sys/cdefs.h> -/* __FBSDID("$FreeBSD: src/lib/msun/src/s_truncf.c,v 1.1 2004/06/20 09:25:43 das Exp $"); */ +__FBSDID("$FreeBSD$"); /* * truncf(x) diff --git a/libm/src/s_truncl.c b/libm/upstream-freebsd/lib/msun/src/s_truncl.c index 39926a5..9e2b511 100644 --- a/libm/src/s_truncl.c +++ b/libm/upstream-freebsd/lib/msun/src/s_truncl.c @@ -11,9 +11,8 @@ * From: @(#)s_floor.c 5.1 93/09/24 */ -#ifndef lint -static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_truncl.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $"; -#endif +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * truncl(x) @@ -37,6 +36,7 @@ static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_truncl.c,v 1.4 2005/04/28 19 #endif static const long double huge = 1.0e300; +static const float zero[] = { 0.0, -0.0 }; long double truncl(long double x) @@ -47,7 +47,7 @@ truncl(long double x) if (e < MANH_SIZE - 1) { if (e < 0) { /* raise inexact if x != 0 */ if (huge + x > 0.0) - u.e = 0.0; + u.e = zero[u.bits.sign]; } else { uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1); if (((u.bits.manh & m) | u.bits.manl) == 0) diff --git a/libm/upstream-freebsd/lib/msun/src/w_cabs.c b/libm/upstream-freebsd/lib/msun/src/w_cabs.c new file mode 100644 index 0000000..543b858 --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/w_cabs.c @@ -0,0 +1,23 @@ +/* + * cabs() wrapper for hypot(). + * + * Written by J.T. Conklin, <jtc@wimsey.com> + * Placed into the Public Domain, 1994. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <float.h> +#include <math.h> + +double +cabs(double complex z) +{ + return hypot(creal(z), cimag(z)); +} + +#if LDBL_MANT_DIG == 53 +__weak_reference(cabs, cabsl); +#endif diff --git a/libm/src/w_cabsf.c b/libm/upstream-freebsd/lib/msun/src/w_cabsf.c index fac152f..e7bfe22 100644 --- a/libm/src/w_cabsf.c +++ b/libm/upstream-freebsd/lib/msun/src/w_cabsf.c @@ -7,7 +7,7 @@ #ifndef lint static const char rcsid[] = - "$FreeBSD: src/lib/msun/src/w_cabsf.c,v 1.3 2001/06/13 15:16:30 ru Exp $"; + "$FreeBSD$"; #endif /* not lint */ #include <complex.h> diff --git a/libm/upstream-freebsd/lib/msun/src/w_cabsl.c b/libm/upstream-freebsd/lib/msun/src/w_cabsl.c new file mode 100644 index 0000000..b715e0c --- /dev/null +++ b/libm/upstream-freebsd/lib/msun/src/w_cabsl.c @@ -0,0 +1,20 @@ +/* + * cabs() wrapper for hypot(). + * + * Written by J.T. Conklin, <jtc@wimsey.com> + * Placed into the Public Domain, 1994. + * + * Modified by Steven G. Kargl for the long double type. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <complex.h> +#include <math.h> + +long double +cabsl(long double complex z) +{ + return hypotl(creall(z), cimagl(z)); +} diff --git a/libm/src/w_drem.c b/libm/upstream-freebsd/lib/msun/src/w_drem.c index 0f68409..0f68409 100644 --- a/libm/src/w_drem.c +++ b/libm/upstream-freebsd/lib/msun/src/w_drem.c diff --git a/libm/src/w_dremf.c b/libm/upstream-freebsd/lib/msun/src/w_dremf.c index e83ac0e..4bfcff2 100644 --- a/libm/src/w_dremf.c +++ b/libm/upstream-freebsd/lib/msun/src/w_dremf.c @@ -4,7 +4,7 @@ * Written by J.T. Conklin, <jtc@wimsey.com> * Placed into the Public Domain, 1994. */ -/* $FreeBSD: src/lib/msun/src/w_dremf.c,v 1.3 2004/07/28 05:53:18 kan Exp $ */ +/* $FreeBSD$ */ #include "math.h" #include "math_private.h" |