From 6ff43c949ec457c91648dc9aef9dbf805e4083d6 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Mon, 8 Apr 2013 15:04:50 -0700 Subject: [PATCH] Bring in FreeBSD's msun code for our libm. Our current libm is a mix of NetBSD and FreeBSD. To ease maintainability, sync with FreeBSD as requested by John Marino. Obtained-from: FreeBSD --- Makefile_upgrade.inc | 10 +- include/Makefile | 13 +- include/complex.h | 151 ---- {sys/cpu/x86_64/include => include}/float.h | 32 +- include/ieeefp.h | 13 +- include/math.h | 521 ------------- lib/libc/gen/Makefile.inc | 25 +- lib/libc/gen/fpclassify.3 | 149 ++-- .../src/s_rintl.c => libc/gen/fpclassify.c} | 100 +-- lib/libc/gen/fpclassifyd.c | 67 -- lib/libc/gen/fpclassifyf.c | 67 -- lib/libc/gen/frexp.3 | 5 +- lib/libc/gen/frexp.c | 2 +- lib/libc/gen/infinity.c | 16 - lib/libc/gen/infinityf.c | 16 - lib/libc/gen/infinityl_dbl.c | 22 - lib/libc/gen/isfinite.3 | 77 -- lib/libc/gen/isfinited.c | 58 -- lib/libc/gen/isfinitef.c | 58 -- lib/libc/gen/isinf.3 | 82 -- lib/libc/gen/{frexp.c => isinf.c} | 51 +- lib/libc/gen/isinfd.c | 55 -- lib/libc/gen/isinff.c | 55 -- lib/libc/gen/isnan.3 | 79 -- lib/libc/gen/{frexp.c => isnan.c} | 49 +- lib/libc/gen/isnand.c | 55 -- lib/libc/gen/isnanf.c | 55 -- lib/libc/gen/isnormal.3 | 77 -- lib/libc/gen/ldexp.3 | 44 +- lib/libc/gen/ldexp.c | 121 +++ lib/libc/gen/modf.3 | 37 +- lib/{libm/src/s_modf.c => libc/gen/modf.c} | 65 +- lib/libc/gen/signbit.3 | 77 -- lib/libc/gen/signbitd.c | 55 -- lib/libc/gen/signbitf.c | 55 -- lib/libc/i386/gen/Makefile.inc | 10 +- lib/libc/i386/gen/fabs.S | 13 +- lib/libc/i386/gen/flt_rounds.S | 33 - lib/libc/{x86_64 => i386}/gen/flt_rounds.c | 5 +- lib/libc/i386/gen/fpclassifyl.c | 70 -- lib/libc/i386/gen/fpgetmask.S | 23 - lib/libc/i386/gen/fpgetround.S | 23 - lib/libc/i386/gen/fpgetsticky.S | 21 - lib/libc/i386/gen/fpsetmask.S | 34 - lib/libc/i386/gen/fpsetround.S | 35 - lib/libc/i386/gen/fpsetsticky.S | 33 - lib/libc/i386/gen/infinity.c | 12 + lib/libc/i386/gen/infinityl.c | 12 - lib/libc/i386/gen/isfinitel.c | 61 -- lib/libc/i386/gen/isinfl.c | 56 -- lib/libc/i386/gen/isnanl.c | 56 -- lib/libc/i386/gen/ldexp.c | 66 -- lib/libc/i386/gen/modf.S | 75 -- lib/libc/i386/gen/nanf.c | 9 - lib/libc/i386/gen/signbitl.c | 55 -- lib/libc/x86_64/gen/Makefile.inc | 9 +- lib/libc/x86_64/gen/fabs.S | 4 +- lib/libc/x86_64/gen/flt_rounds.c | 6 +- lib/libc/x86_64/gen/fpclassifyl.c | 69 -- lib/libc/x86_64/gen/fpgetmask.S | 26 - lib/libc/x86_64/gen/fpgetmask.c | 8 + lib/libc/x86_64/gen/fpgetprec.c | 8 + lib/libc/x86_64/gen/fpgetround.S | 25 - lib/libc/x86_64/gen/fpgetround.c | 8 + lib/libc/x86_64/gen/fpgetsticky.S | 26 - lib/libc/x86_64/gen/fpgetsticky.c | 8 + lib/libc/x86_64/gen/fpsetmask.S | 41 - lib/libc/x86_64/gen/fpsetmask.c | 8 + lib/libc/x86_64/gen/fpsetprec.c | 8 + lib/libc/x86_64/gen/fpsetround.S | 48 -- lib/libc/x86_64/gen/fpsetround.c | 8 + lib/libc/x86_64/gen/fpsetsticky.S | 45 -- lib/libc/x86_64/gen/infinity.c | 12 + lib/libc/x86_64/gen/infinityl.c | 11 - lib/libc/x86_64/gen/isfinitel.c | 60 -- lib/libc/x86_64/gen/isinfl.c | 54 -- lib/libc/x86_64/gen/isnanl.c | 54 -- lib/libc/x86_64/gen/ldexp.c | 59 -- lib/libc/x86_64/gen/modf.S | 87 --- lib/libc/x86_64/gen/nanf.c | 6 - lib/libc/x86_64/gen/signbitl.c | 54 -- lib/libm/Makefile | 297 ++++++- lib/libm/arch/i386/Makefile.inc | 22 - lib/libm/arch/i386/abi.h | 81 -- lib/libm/arch/i386/e_acos.S | 27 - lib/libm/arch/i386/e_asin.S | 26 - lib/libm/arch/i386/e_atan2.S | 21 - lib/libm/arch/i386/e_atan2f.S | 21 - lib/libm/arch/i386/e_expf.S | 57 -- lib/libm/arch/i386/e_fmod.S | 25 - lib/libm/arch/i386/e_log.S | 21 - lib/libm/arch/i386/e_log10.S | 21 - lib/libm/arch/i386/e_log10f.S | 21 - lib/libm/arch/i386/e_log2.S | 20 - lib/libm/arch/i386/e_log2f.S | 20 - lib/libm/arch/i386/e_logf.S | 21 - lib/libm/arch/i386/e_remainder.S | 25 - lib/libm/arch/i386/e_remainderf.S | 25 - lib/libm/arch/i386/e_scalb.S | 22 - lib/libm/arch/i386/e_scalbf.S | 21 - lib/libm/arch/i386/e_sqrt.S | 20 - lib/libm/arch/i386/e_sqrtf.S | 20 - lib/libm/arch/i386/s_atan.S | 21 - lib/libm/arch/i386/s_atanf.S | 21 - lib/libm/arch/i386/s_ceil.S | 48 -- lib/libm/arch/i386/s_copysign.S | 41 - lib/libm/arch/i386/s_copysignf.S | 40 - lib/libm/arch/i386/s_cos.S | 34 - lib/libm/arch/i386/s_cosf.S | 21 - lib/libm/arch/i386/s_finite.S | 29 - lib/libm/arch/i386/s_finitef.S | 28 - lib/libm/arch/i386/s_ilogb.S | 35 - lib/libm/arch/i386/s_ilogbf.S | 35 - lib/libm/arch/i386/s_ilogbl.S | 27 - lib/libm/arch/i386/s_log1p.S | 79 -- lib/libm/arch/i386/s_log1pf.S | 79 -- lib/libm/arch/i386/s_logb.S | 21 - lib/libm/arch/i386/s_logbf.S | 21 - lib/libm/arch/i386/s_logbl.S | 19 - lib/libm/arch/i386/s_modf.S | 106 --- lib/libm/arch/i386/s_rint.S | 20 - lib/libm/arch/i386/s_rintf.S | 20 - lib/libm/arch/i386/s_scalbn.S | 29 - lib/libm/arch/i386/s_scalbnf.S | 32 - lib/libm/arch/i386/s_significand.S | 21 - lib/libm/arch/i386/s_significandf.S | 21 - lib/libm/arch/i386/s_sin.S | 34 - lib/libm/arch/i386/s_sinf.S | 21 - lib/libm/arch/i386/s_tan.S | 36 - lib/libm/arch/i386/s_tanf.S | 22 - lib/libm/arch/x86_64/Makefile.inc | 6 - lib/libm/arch/x86_64/fenv.h | 217 ------ lib/libm/{src => bsdsrc}/b_exp.c | 10 +- lib/libm/{src => bsdsrc}/b_log.c | 76 +- lib/libm/{src => bsdsrc}/b_tgamma.c | 10 +- lib/libm/{src => bsdsrc}/mathimpl.h | 11 +- lib/libm/complex/Makefile.inc | 42 - lib/libm/complex/cabs.c | 16 - lib/libm/complex/cabsf.c | 16 - lib/libm/complex/cacos.3 | 57 -- lib/libm/complex/cacos.c | 44 -- lib/libm/complex/cacosf.c | 44 -- lib/libm/complex/cacosh.3 | 58 -- lib/libm/complex/cacosh.c | 45 -- lib/libm/complex/cacoshf.c | 45 -- lib/libm/complex/carg.3 | 58 -- lib/libm/complex/carg.c | 17 - lib/libm/complex/cargf.c | 17 - lib/libm/complex/casin.3 | 58 -- lib/libm/complex/casin.c | 120 --- lib/libm/complex/casinf.c | 120 --- lib/libm/complex/casinh.3 | 58 -- lib/libm/complex/casinh.c | 42 - lib/libm/complex/casinhf.c | 42 - lib/libm/complex/catan.3 | 58 -- lib/libm/complex/catan.c | 80 -- lib/libm/complex/catanf.c | 80 -- lib/libm/complex/catanh.3 | 58 -- lib/libm/complex/catanh.c | 42 - lib/libm/complex/catanhf.c | 42 - lib/libm/complex/ccos.3 | 53 -- lib/libm/complex/ccos.c | 46 -- lib/libm/complex/ccosf.c | 46 -- lib/libm/complex/ccosh.3 | 53 -- lib/libm/complex/ccosh.c | 46 -- lib/libm/complex/ccoshf.c | 46 -- lib/libm/complex/cephes_subr.c | 124 --- lib/libm/complex/cephes_subr.h | 5 - lib/libm/complex/cephes_subrf.c | 123 --- lib/libm/complex/cephes_subrf.h | 5 - lib/libm/complex/cexp.3 | 54 -- lib/libm/complex/cexp.c | 47 -- lib/libm/complex/cexpf.c | 47 -- lib/libm/complex/cimag.3 | 63 -- lib/libm/complex/cimag.c | 17 - lib/libm/complex/cimagf.c | 17 - lib/libm/complex/cimagl.c | 42 - lib/libm/complex/clog.3 | 58 -- lib/libm/complex/clog.c | 47 -- lib/libm/complex/clogf.c | 47 -- lib/libm/complex/conj.3 | 56 -- lib/libm/complex/conj.c | 19 - lib/libm/complex/conjf.c | 19 - lib/libm/complex/conjl.c | 46 -- lib/libm/complex/cpow.3 | 57 -- lib/libm/complex/cpow.c | 57 -- lib/libm/complex/cpowf.c | 57 -- lib/libm/complex/cproj.3 | 59 -- lib/libm/complex/cproj.c | 62 -- lib/libm/complex/cprojf.c | 63 -- lib/libm/complex/cprojl.c | 62 -- lib/libm/complex/creal.3 | 63 -- lib/libm/complex/creal.c | 17 - lib/libm/complex/crealf.c | 17 - lib/libm/complex/creall.c | 42 - lib/libm/complex/csin.3 | 53 -- lib/libm/complex/csin.c | 46 -- lib/libm/complex/csinf.c | 46 -- lib/libm/complex/csinh.3 | 53 -- lib/libm/complex/csinh.c | 46 -- lib/libm/complex/csinhf.c | 46 -- lib/libm/complex/csqrt.3 | 58 -- lib/libm/complex/csqrt.c | 99 --- lib/libm/complex/csqrtf.c | 99 --- lib/libm/complex/ctan.3 | 53 -- lib/libm/complex/ctan.c | 58 -- lib/libm/complex/ctanf.c | 58 -- lib/libm/complex/ctanh.3 | 53 -- lib/libm/complex/ctanh.c | 48 -- lib/libm/complex/ctanhf.c | 48 -- lib/libm/gen/Makefile.inc | 9 - lib/libm/gen/nan.3 | 101 --- lib/libm/gen/nan.c | 80 -- lib/libm/gen/nanf.c | 36 - lib/libm/gen/nanl.c | 36 - lib/libm/i386/Makefile.inc | 18 + lib/libm/{arch => }/i386/e_exp.S | 56 +- .../{arch/i386/e_sqrtl.S => i386/e_fmod.S} | 21 +- .../{arch/i386/e_sqrtl.S => i386/e_log.S} | 17 +- .../{arch/i386/e_sqrtl.S => i386/e_log10.S} | 17 +- lib/libm/i386/e_log10f.S | 18 + lib/libm/i386/e_logf.S | 18 + .../i386/e_sqrtl.S => i386/e_remainder.S} | 21 +- lib/libm/i386/e_remainderf.S | 22 + lib/libm/{arch => }/i386/e_remainderl.S | 14 +- .../{arch/i386/e_sqrtl.S => i386/e_sqrt.S} | 14 +- lib/libm/i386/e_sqrtf.S | 17 + lib/libm/{arch => }/i386/e_sqrtl.S | 8 +- lib/libm/{arch => }/i386/fenv.c | 32 +- lib/libm/i386/invtrig.c | 85 ++ .../{arch/i386/e_sqrtl.S => i386/s_ceil.S} | 31 +- lib/libm/{arch => }/i386/s_ceilf.S | 20 +- .../{arch/i386/s_ceilf.S => i386/s_ceill.S} | 25 +- .../i386/e_sqrtl.S => i386/s_copysign.S} | 23 +- lib/libm/i386/s_copysignf.S | 22 + lib/libm/i386/s_copysignl.S | 21 + .../{arch/i386/e_sqrtl.S => i386/s_cos.S} | 29 +- .../{arch/i386/e_sqrtl.S => i386/s_finite.S} | 21 +- .../{arch/i386/e_sqrtl.S => i386/s_floor.S} | 31 +- lib/libm/{arch => }/i386/s_floorf.S | 20 +- .../{arch/i386/s_floor.S => i386/s_floorl.S} | 25 +- .../{arch/i386/s_lrint.S => i386/s_llrint.S} | 16 +- .../i386/s_lrintf.S => i386/s_llrintf.S} | 16 +- .../i386/s_lrintf.S => i386/s_llrintl.S} | 18 +- .../{arch/i386/e_sqrtl.S => i386/s_logb.S} | 19 +- lib/libm/i386/s_logbf.S | 18 + .../{arch/i386/e_sqrtl.S => i386/s_logbl.S} | 17 +- lib/libm/{arch => }/i386/s_lrint.S | 7 +- lib/libm/{arch => }/i386/s_lrintf.S | 7 +- lib/libm/{arch => }/i386/s_lrintl.S | 10 +- .../i386/s_remquol.S => i386/s_remquo.S} | 51 +- .../i386/s_remquol.S => i386/s_remquof.S} | 51 +- lib/libm/{arch => }/i386/s_remquol.S | 34 +- .../{arch/i386/e_sqrtl.S => i386/s_rint.S} | 16 +- lib/libm/i386/s_rintf.S | 17 + .../{arch/i386/e_sqrtl.S => i386/s_rintl.S} | 14 +- .../{arch/i386/e_sqrtl.S => i386/s_scalbn.S} | 20 +- lib/libm/i386/s_scalbnf.S | 22 + lib/libm/i386/s_scalbnl.S | 22 + .../i386/e_sqrtl.S => i386/s_significand.S} | 19 +- lib/libm/i386/s_significandf.S | 18 + .../{arch/i386/e_sqrtl.S => i386/s_sin.S} | 29 +- .../i386/e_remainderl.S => i386/s_tan.S} | 38 +- lib/libm/i386/s_trunc.S | 30 + lib/libm/i386/s_truncf.S | 30 + lib/libm/i386/s_truncl.S | 30 + lib/libm/{src => ld80}/e_rem_pio2l.h | 28 +- lib/libm/{src => ld80}/invtrig.c | 2 + lib/libm/{src => ld80}/invtrig.h | 2 +- lib/libm/{src => ld80}/k_cosl.c | 6 +- lib/libm/{src => ld80}/k_sinl.c | 6 +- lib/libm/{src => ld80}/k_tanl.c | 7 +- lib/libm/{src => ld80}/s_exp2l.c | 76 +- lib/libm/ld80/s_expl.c | 303 ++++++++ lib/libm/{src/s_copysignl.c => ld80/s_nanl.c} | 20 +- lib/libm/man/Makefile.inc | 76 -- lib/libm/man/acos.3 | 2 +- lib/libm/man/acosh.3 | 2 +- lib/libm/man/asin.3 | 2 +- lib/libm/man/asinh.3 | 2 +- lib/libm/man/atan.3 | 2 +- lib/libm/man/atan2.3 | 54 +- lib/libm/man/atanh.3 | 2 +- lib/libm/man/cacos.3 | 128 +++ lib/libm/man/{trunc.3 => ccos.3} | 89 ++- lib/libm/man/{trunc.3 => ccosh.3} | 89 ++- lib/libm/man/ceil.3 | 3 +- lib/libm/man/{log.3 => cexp.3} | 143 ++-- lib/libm/man/{fmax.3 => cimag.3} | 121 +-- lib/libm/man/complex.3 | 124 +++ lib/libm/man/copysign.3 | 3 +- lib/libm/man/cos.3 | 2 +- lib/libm/man/cosh.3 | 11 +- lib/libm/man/csqrt.3 | 102 +++ lib/libm/man/erf.3 | 2 +- lib/libm/man/exp.3 | 16 +- lib/libm/man/fabs.3 | 3 +- lib/libm/man/fdim.3 | 2 +- lib/libm/man/feclearexcept.3 | 2 +- lib/libm/man/feenableexcept.3 | 2 +- lib/libm/man/fegetenv.3 | 2 +- lib/libm/man/fegetround.3 | 2 +- lib/libm/man/fenv.3 | 45 +- lib/libm/man/finite.3 | 82 -- lib/libm/man/floor.3 | 3 +- lib/libm/man/fma.3 | 4 +- lib/libm/man/fmax.3 | 2 + lib/libm/man/fmod.3 | 2 +- lib/libm/man/frexp.3 | 87 --- lib/libm/man/hypot.3 | 2 +- lib/libm/man/ieee.3 | 446 +++++++++++ lib/libm/man/ieee_test.3 | 42 +- lib/libm/man/ilogb.3 | 4 +- lib/libm/man/j0.3 | 2 +- lib/libm/man/lgamma.3 | 4 +- lib/libm/man/log.3 | 2 +- lib/libm/man/lrint.3 | 2 +- lib/libm/man/lround.3 | 2 +- lib/libm/man/math.3 | 734 +++++------------- lib/libm/man/nan.3 | 99 +++ lib/libm/man/nextafter.3 | 14 +- lib/libm/man/remainder.3 | 5 +- lib/libm/man/rint.3 | 5 +- lib/libm/man/round.3 | 5 +- lib/libm/man/scalbn.3 | 21 +- lib/libm/man/{trunc.3 => signbit.3} | 65 +- lib/libm/man/sin.3 | 2 +- lib/libm/man/sinh.3 | 12 +- lib/libm/man/sqrt.3 | 14 +- lib/libm/man/tan.3 | 2 +- lib/libm/man/tanh.3 | 2 +- lib/libm/man/trunc.3 | 2 +- lib/libm/src/Makefile.inc | 54 -- lib/libm/src/catrig.c | 642 +++++++++++++++ lib/libm/src/catrigf.c | 387 +++++++++ lib/libm/src/complex.h | 116 +++ lib/libm/src/e_acos.c | 33 +- lib/libm/src/e_acosf.c | 50 +- lib/libm/src/e_acosh.c | 26 +- lib/libm/src/e_acoshf.c | 13 +- lib/libm/src/e_acosl.c | 4 +- lib/libm/src/e_asin.c | 52 +- lib/libm/src/e_asinf.c | 75 +- lib/libm/src/e_asinl.c | 12 +- lib/libm/src/e_atan2.c | 56 +- lib/libm/src/e_atan2f.c | 29 +- lib/libm/src/e_atan2l.c | 6 +- lib/libm/src/e_atanh.c | 23 +- lib/libm/src/e_atanhf.c | 7 +- lib/libm/src/e_cosh.c | 43 +- lib/libm/src/e_coshf.c | 31 +- lib/libm/src/e_exp.c | 80 +- lib/libm/src/e_expf.c | 63 +- lib/libm/src/e_fmod.c | 28 +- lib/libm/src/e_fmodf.c | 12 +- lib/libm/src/e_fmodl.c | 5 +- lib/libm/src/e_gamma.c | 31 + lib/libm/src/e_gamma_r.c | 30 + lib/libm/src/{w_gammaf.c => e_gammaf.c} | 19 +- lib/libm/src/{s_fabsf.c => e_gammaf_r.c} | 21 +- lib/libm/src/e_hypot.c | 61 +- lib/libm/src/e_hypotf.c | 39 +- lib/libm/src/e_hypotl.c | 5 +- lib/libm/src/e_j0.c | 45 +- lib/libm/src/e_j0f.c | 33 +- lib/libm/src/e_j1.c | 47 +- lib/libm/src/e_j1f.c | 38 +- lib/libm/src/e_jn.c | 78 +- lib/libm/src/e_jnf.c | 39 +- lib/libm/src/e_lgamma.c | 31 + lib/libm/src/e_lgamma_r.c | 53 +- lib/libm/src/{w_gammaf_r.c => e_lgammaf.c} | 19 +- lib/libm/src/e_lgammaf_r.c | 23 +- lib/libm/src/e_log.c | 67 +- lib/libm/src/e_log10.c | 107 +-- lib/libm/src/e_log10f.c | 64 +- lib/libm/src/e_log2.c | 111 ++- lib/libm/src/e_log2f.c | 107 +-- lib/libm/src/e_logf.c | 36 +- lib/libm/src/e_pow.c | 77 +- lib/libm/src/e_powf.c | 71 +- lib/libm/src/e_rem_pio2.c | 33 +- lib/libm/src/e_rem_pio2f.c | 19 +- lib/libm/src/e_remainder.c | 71 -- lib/libm/src/e_remainderf.c | 64 -- lib/libm/src/e_scalb.c | 20 +- lib/libm/src/e_scalbf.c | 10 +- lib/libm/src/e_sinh.c | 40 +- lib/libm/src/e_sinhf.c | 28 +- lib/libm/src/e_sqrt.c | 443 ----------- lib/libm/src/e_sqrtf.c | 88 --- lib/libm/src/e_sqrtl.c | 160 ---- lib/libm/{arch/i386 => src}/fenv.h | 233 ++++-- lib/libm/src/k_cos.c | 72 +- lib/libm/src/k_cosf.c | 10 +- lib/libm/src/k_exp.c | 107 +++ lib/libm/src/{s_fmaf.c => k_expf.c} | 81 +- lib/libm/src/{e_log.c => k_log.h} | 106 +-- lib/libm/src/k_logf.h | 38 + lib/libm/src/k_rem_pio2.c | 81 +- lib/libm/src/k_rem_pio2f.c | 195 ----- lib/libm/src/k_sin.c | 42 +- lib/libm/src/k_sinf.c | 11 +- lib/libm/src/k_tan.c | 56 +- lib/libm/src/k_tanf.c | 10 +- lib/libm/src/math.h | 481 ++++++++++++ lib/libm/src/math_private.h | 325 +++++--- lib/libm/src/s_asinh.c | 12 +- lib/libm/src/s_asinhf.c | 11 +- lib/libm/src/s_atan.c | 18 +- lib/libm/src/s_atanf.c | 35 +- lib/libm/src/s_atanl.c | 2 +- lib/libm/{complex/s_cargl.c => src/s_carg.c} | 10 +- lib/libm/{complex/s_cargl.c => src/s_cargf.c} | 10 +- lib/libm/{complex => src}/s_cargl.c | 2 +- lib/libm/src/s_cbrt.c | 13 +- lib/libm/src/s_cbrtf.c | 6 +- lib/libm/src/s_cbrtl.c | 48 +- lib/libm/src/s_ccosh.c | 154 ++++ lib/libm/src/s_ccoshf.c | 103 +++ lib/libm/src/s_ceil.c | 35 +- lib/libm/src/s_ceilf.c | 18 +- lib/libm/src/s_ceill.c | 2 +- lib/libm/src/s_cexp.c | 88 +++ lib/libm/src/s_cexpf.c | 88 +++ lib/libm/src/{s_copysignl.c => s_cimag.c} | 18 +- lib/libm/src/{s_copysignl.c => s_cimagf.c} | 18 +- lib/libm/src/{s_copysignl.c => s_cimagl.c} | 16 +- lib/libm/src/{s_copysignl.c => s_conj.c} | 16 +- lib/libm/src/{s_copysignl.c => s_conjf.c} | 16 +- lib/libm/src/{s_copysignl.c => s_conjl.c} | 16 +- lib/libm/src/s_copysign.c | 6 +- lib/libm/src/s_copysignf.c | 5 +- lib/libm/src/s_copysignl.c | 2 +- lib/libm/src/s_cos.c | 23 +- lib/libm/src/s_cosf.c | 9 +- lib/libm/src/s_cosl.c | 27 +- lib/libm/src/{e_remainderl.c => s_cproj.c} | 19 +- lib/libm/src/{e_remainderl.c => s_cprojf.c} | 15 +- lib/libm/src/{e_remainderl.c => s_cprojl.c} | 15 +- lib/libm/src/{s_copysignl.c => s_creal.c} | 17 +- lib/libm/src/{s_copysignl.c => s_crealf.c} | 17 +- lib/libm/src/{s_copysignl.c => s_creall.c} | 15 +- lib/libm/src/s_csinh.c | 156 ++++ lib/libm/src/s_csinhf.c | 104 +++ .../{complex/s_csqrtl.c => src/s_csqrt.c} | 59 +- .../{complex/s_csqrtl.c => src/s_csqrtf.c} | 81 +- lib/libm/{complex => src}/s_csqrtl.c | 8 +- lib/libm/src/s_ctanh.c | 143 ++++ lib/libm/src/{s_tanl.c => s_ctanhf.c} | 82 +- lib/libm/src/s_erf.c | 12 +- lib/libm/src/s_erff.c | 11 +- lib/libm/src/s_exp2.c | 13 +- lib/libm/src/s_exp2f.c | 13 +- lib/libm/src/s_expm1.c | 36 +- lib/libm/src/s_expm1f.c | 50 +- lib/libm/src/s_fabs.c | 5 +- lib/libm/src/s_fabsf.c | 5 +- lib/libm/src/s_fabsl.c | 50 +- lib/libm/src/s_fdim.c | 2 + lib/libm/src/s_finite.c | 9 +- lib/libm/src/s_finitef.c | 8 +- lib/libm/src/s_floor.c | 35 +- lib/libm/src/s_floorf.c | 18 +- lib/libm/src/s_floorl.c | 2 +- lib/libm/src/s_fma.c | 18 +- lib/libm/src/s_fmaf.c | 5 +- lib/libm/src/s_fmal.c | 18 +- lib/libm/src/s_fmax.c | 20 +- lib/libm/src/s_fmaxf.c | 22 +- lib/libm/src/s_fmaxl.c | 31 +- lib/libm/src/s_fmin.c | 20 +- lib/libm/src/s_fminf.c | 22 +- lib/libm/src/s_fminl.c | 31 +- lib/libm/src/s_frexp.c | 13 +- lib/libm/src/s_frexpf.c | 4 +- lib/libm/src/s_frexpl.c | 2 +- lib/libm/src/s_ilogb.c | 23 +- lib/libm/src/s_ilogbf.c | 15 +- lib/libm/src/s_ilogbl.c | 100 +-- lib/libm/src/{s_fdim.c => s_isfinite.c} | 41 +- lib/{libc/gen/frexp.c => libm/src/s_isnan.c} | 50 +- lib/libm/src/{s_fdim.c => s_isnormal.c} | 41 +- lib/libm/src/s_llrint.c | 10 - lib/libm/src/s_llrintf.c | 10 - lib/libm/src/s_llrintl.c | 10 - lib/libm/src/s_llround.c | 4 +- lib/libm/src/s_llroundf.c | 4 +- lib/libm/src/s_llroundl.c | 4 +- lib/libm/src/s_log1p.c | 39 +- lib/libm/src/s_log1pf.c | 43 +- lib/libm/src/s_logb.c | 25 +- lib/libm/src/s_logbf.c | 19 +- lib/libm/src/s_logbl.c | 71 -- lib/libm/src/s_lrint.c | 58 -- lib/libm/src/s_lrintf.c | 10 - lib/libm/src/s_lrintl.c | 10 - lib/libm/src/s_lround.c | 2 +- lib/libm/src/s_lroundf.c | 4 +- lib/libm/src/s_lroundl.c | 4 +- lib/libm/src/s_modf.c | 5 +- lib/libm/src/s_modff.c | 18 +- lib/libm/src/s_modfl.c | 2 +- lib/libm/src/s_nan.c | 121 +++ lib/libm/src/s_nearbyint.c | 8 +- lib/libm/src/s_nextafter.c | 22 +- lib/libm/src/s_nextafterf.c | 13 +- lib/libm/src/s_nextafterl.c | 111 ++- lib/libm/src/s_nexttoward.c | 82 +- lib/libm/src/s_nexttowardf.c | 6 +- lib/libm/src/s_remquo.c | 153 ---- lib/libm/src/s_remquof.c | 120 --- lib/libm/src/s_remquol.c | 175 ----- lib/libm/src/s_rint.c | 46 +- lib/libm/src/s_rintf.c | 43 +- lib/libm/src/s_round.c | 2 +- lib/libm/src/s_roundf.c | 2 +- lib/libm/src/s_roundl.c | 2 +- lib/libm/src/s_scalbln.c | 2 +- lib/libm/src/s_scalbn.c | 57 -- lib/libm/src/s_scalbnf.c | 53 -- lib/libm/src/s_scalbnl.c | 97 --- .../{complex/s_cargl.c => src/s_signbit.c} | 33 +- lib/libm/src/s_signgam.c | 6 +- lib/libm/src/s_significand.c | 8 +- lib/libm/src/s_significandf.c | 7 +- lib/libm/src/s_sin.c | 23 +- lib/libm/src/s_sinf.c | 9 +- lib/libm/src/s_sinl.c | 27 +- lib/libm/src/s_tan.c | 24 +- lib/libm/src/s_tanf.c | 9 +- lib/libm/src/s_tanh.c | 26 +- lib/libm/src/s_tanhf.c | 21 +- lib/libm/src/s_tanl.c | 23 +- lib/libm/src/s_tgammaf.c | 2 +- lib/libm/src/s_trunc.c | 29 +- lib/libm/src/s_truncf.c | 19 +- lib/libm/src/s_truncl.c | 2 +- lib/libm/src/w_cabs.c | 22 + lib/libm/src/w_cabsf.c | 20 + lib/libm/{complex => src}/w_cabsl.c | 2 +- lib/libm/src/w_drem.c | 6 +- lib/libm/src/w_dremf.c | 6 +- lib/libm/src/w_gamma.c | 29 - lib/libm/src/w_gamma_r.c | 27 - lib/libm/src/w_lgamma.c | 28 - lib/libm/src/w_lgammaf.c | 26 - lib/libm/x86_64/Makefile.inc | 8 + .../e_remainderl.S => x86_64/e_remainder.S} | 30 +- lib/libm/x86_64/e_remainderf.S | 26 + lib/libm/{arch/i386 => x86_64}/e_remainderl.S | 16 +- .../{arch/i386/s_lrint.S => x86_64/e_sqrt.S} | 16 +- .../{arch/i386/s_lrint.S => x86_64/e_sqrtf.S} | 16 +- .../{src/e_remainderl.c => x86_64/e_sqrtl.S} | 16 +- lib/libm/{arch => }/x86_64/fenv.c | 25 +- lib/libm/x86_64/s_llrint.S | 6 + lib/libm/x86_64/s_llrintf.S | 6 + .../i386/s_lrint.S => x86_64/s_llrintl.S} | 19 +- .../{arch/i386/e_sqrtl.S => x86_64/s_logbl.S} | 17 +- lib/libm/{arch/i386 => x86_64}/s_lrint.S | 18 +- lib/libm/{arch/i386 => x86_64}/s_lrintf.S | 18 +- lib/libm/{arch/i386 => x86_64}/s_lrintl.S | 10 +- .../i386/s_remquol.S => x86_64/s_remquo.S} | 54 +- .../i386/s_remquol.S => x86_64/s_remquof.S} | 54 +- lib/libm/{arch/i386 => x86_64}/s_remquol.S | 35 +- .../{arch/i386/e_sqrtl.S => x86_64/s_rintl.S} | 14 +- .../i386/s_lrintf.S => x86_64/s_scalbn.S} | 23 +- .../i386/s_lrintf.S => x86_64/s_scalbnf.S} | 26 +- lib/libm/{arch/i386 => x86_64}/s_scalbnl.S | 12 +- sys/cpu/i386/include/float.h | 97 --- sys/cpu/i386/include/floatingpoint.h | 43 - sys/cpu/i386/include/ieee.h | 112 --- sys/cpu/i386/include/ieeefp.h | 59 +- sys/cpu/i386/include/math.h | 18 - sys/cpu/x86_64/include/floatingpoint.h | 43 - sys/cpu/x86_64/include/ieee.h | 106 --- sys/cpu/x86_64/include/ieeefp.h | 109 +-- sys/cpu/x86_64/include/math.h | 17 - sys/sys/param.h | 3 +- 579 files changed, 9406 insertions(+), 16219 deletions(-) delete mode 100644 include/complex.h rename {sys/cpu/x86_64/include => include}/float.h (77%) delete mode 100644 include/math.h rename lib/{libm/src/s_rintl.c => libc/gen/fpclassify.c} (52%) delete mode 100644 lib/libc/gen/fpclassifyd.c delete mode 100644 lib/libc/gen/fpclassifyf.c delete mode 100644 lib/libc/gen/infinity.c delete mode 100644 lib/libc/gen/infinityf.c delete mode 100644 lib/libc/gen/infinityl_dbl.c delete mode 100644 lib/libc/gen/isfinite.3 delete mode 100644 lib/libc/gen/isfinited.c delete mode 100644 lib/libc/gen/isfinitef.c delete mode 100644 lib/libc/gen/isinf.3 copy lib/libc/gen/{frexp.c => isinf.c} (70%) delete mode 100644 lib/libc/gen/isinfd.c delete mode 100644 lib/libc/gen/isinff.c delete mode 100644 lib/libc/gen/isnan.3 copy lib/libc/gen/{frexp.c => isnan.c} (65%) delete mode 100644 lib/libc/gen/isnand.c delete mode 100644 lib/libc/gen/isnanf.c delete mode 100644 lib/libc/gen/isnormal.3 create mode 100644 lib/libc/gen/ldexp.c copy lib/{libm/src/s_modf.c => libc/gen/modf.c} (60%) delete mode 100644 lib/libc/gen/signbit.3 delete mode 100644 lib/libc/gen/signbitd.c delete mode 100644 lib/libc/gen/signbitf.c delete mode 100644 lib/libc/i386/gen/flt_rounds.S copy lib/libc/{x86_64 => i386}/gen/flt_rounds.c (72%) delete mode 100644 lib/libc/i386/gen/fpclassifyl.c delete mode 100644 lib/libc/i386/gen/fpgetmask.S delete mode 100644 lib/libc/i386/gen/fpgetround.S delete mode 100644 lib/libc/i386/gen/fpgetsticky.S delete mode 100644 lib/libc/i386/gen/fpsetmask.S delete mode 100644 lib/libc/i386/gen/fpsetround.S delete mode 100644 lib/libc/i386/gen/fpsetsticky.S create mode 100644 lib/libc/i386/gen/infinity.c delete mode 100644 lib/libc/i386/gen/infinityl.c delete mode 100644 lib/libc/i386/gen/isfinitel.c delete mode 100644 lib/libc/i386/gen/isinfl.c delete mode 100644 lib/libc/i386/gen/isnanl.c delete mode 100644 lib/libc/i386/gen/ldexp.c delete mode 100644 lib/libc/i386/gen/modf.S delete mode 100644 lib/libc/i386/gen/nanf.c delete mode 100644 lib/libc/i386/gen/signbitl.c delete mode 100644 lib/libc/x86_64/gen/fpclassifyl.c delete mode 100644 lib/libc/x86_64/gen/fpgetmask.S create mode 100644 lib/libc/x86_64/gen/fpgetmask.c create mode 100644 lib/libc/x86_64/gen/fpgetprec.c delete mode 100644 lib/libc/x86_64/gen/fpgetround.S create mode 100644 lib/libc/x86_64/gen/fpgetround.c delete mode 100644 lib/libc/x86_64/gen/fpgetsticky.S create mode 100644 lib/libc/x86_64/gen/fpgetsticky.c delete mode 100644 lib/libc/x86_64/gen/fpsetmask.S create mode 100644 lib/libc/x86_64/gen/fpsetmask.c create mode 100644 lib/libc/x86_64/gen/fpsetprec.c delete mode 100644 lib/libc/x86_64/gen/fpsetround.S create mode 100644 lib/libc/x86_64/gen/fpsetround.c delete mode 100644 lib/libc/x86_64/gen/fpsetsticky.S create mode 100644 lib/libc/x86_64/gen/infinity.c delete mode 100644 lib/libc/x86_64/gen/infinityl.c delete mode 100644 lib/libc/x86_64/gen/isfinitel.c delete mode 100644 lib/libc/x86_64/gen/isinfl.c delete mode 100644 lib/libc/x86_64/gen/isnanl.c delete mode 100644 lib/libc/x86_64/gen/ldexp.c delete mode 100644 lib/libc/x86_64/gen/modf.S delete mode 100644 lib/libc/x86_64/gen/nanf.c delete mode 100644 lib/libc/x86_64/gen/signbitl.c delete mode 100644 lib/libm/arch/i386/Makefile.inc delete mode 100644 lib/libm/arch/i386/abi.h delete mode 100644 lib/libm/arch/i386/e_acos.S delete mode 100644 lib/libm/arch/i386/e_asin.S delete mode 100644 lib/libm/arch/i386/e_atan2.S delete mode 100644 lib/libm/arch/i386/e_atan2f.S delete mode 100644 lib/libm/arch/i386/e_expf.S delete mode 100644 lib/libm/arch/i386/e_fmod.S delete mode 100644 lib/libm/arch/i386/e_log.S delete mode 100644 lib/libm/arch/i386/e_log10.S delete mode 100644 lib/libm/arch/i386/e_log10f.S delete mode 100644 lib/libm/arch/i386/e_log2.S delete mode 100644 lib/libm/arch/i386/e_log2f.S delete mode 100644 lib/libm/arch/i386/e_logf.S delete mode 100644 lib/libm/arch/i386/e_remainder.S delete mode 100644 lib/libm/arch/i386/e_remainderf.S delete mode 100644 lib/libm/arch/i386/e_scalb.S delete mode 100644 lib/libm/arch/i386/e_scalbf.S delete mode 100644 lib/libm/arch/i386/e_sqrt.S delete mode 100644 lib/libm/arch/i386/e_sqrtf.S delete mode 100644 lib/libm/arch/i386/s_atan.S delete mode 100644 lib/libm/arch/i386/s_atanf.S delete mode 100644 lib/libm/arch/i386/s_ceil.S delete mode 100644 lib/libm/arch/i386/s_copysign.S delete mode 100644 lib/libm/arch/i386/s_copysignf.S delete mode 100644 lib/libm/arch/i386/s_cos.S delete mode 100644 lib/libm/arch/i386/s_cosf.S delete mode 100644 lib/libm/arch/i386/s_finite.S delete mode 100644 lib/libm/arch/i386/s_finitef.S delete mode 100644 lib/libm/arch/i386/s_ilogb.S delete mode 100644 lib/libm/arch/i386/s_ilogbf.S delete mode 100644 lib/libm/arch/i386/s_ilogbl.S delete mode 100644 lib/libm/arch/i386/s_log1p.S delete mode 100644 lib/libm/arch/i386/s_log1pf.S delete mode 100644 lib/libm/arch/i386/s_logb.S delete mode 100644 lib/libm/arch/i386/s_logbf.S delete mode 100644 lib/libm/arch/i386/s_logbl.S delete mode 100644 lib/libm/arch/i386/s_modf.S delete mode 100644 lib/libm/arch/i386/s_rint.S delete mode 100644 lib/libm/arch/i386/s_rintf.S delete mode 100644 lib/libm/arch/i386/s_scalbn.S delete mode 100644 lib/libm/arch/i386/s_scalbnf.S delete mode 100644 lib/libm/arch/i386/s_significand.S delete mode 100644 lib/libm/arch/i386/s_significandf.S delete mode 100644 lib/libm/arch/i386/s_sin.S delete mode 100644 lib/libm/arch/i386/s_sinf.S delete mode 100644 lib/libm/arch/i386/s_tan.S delete mode 100644 lib/libm/arch/i386/s_tanf.S delete mode 100644 lib/libm/arch/x86_64/Makefile.inc delete mode 100644 lib/libm/arch/x86_64/fenv.h rename lib/libm/{src => bsdsrc}/b_exp.c (91%) rename lib/libm/{src => bsdsrc}/b_log.c (86%) rename lib/libm/{src => bsdsrc}/b_tgamma.c (95%) rename lib/libm/{src => bsdsrc}/mathimpl.h (86%) delete mode 100644 lib/libm/complex/Makefile.inc delete mode 100644 lib/libm/complex/cabs.c delete mode 100644 lib/libm/complex/cabsf.c delete mode 100644 lib/libm/complex/cacos.3 delete mode 100644 lib/libm/complex/cacos.c delete mode 100644 lib/libm/complex/cacosf.c delete mode 100644 lib/libm/complex/cacosh.3 delete mode 100644 lib/libm/complex/cacosh.c delete mode 100644 lib/libm/complex/cacoshf.c delete mode 100644 lib/libm/complex/carg.3 delete mode 100644 lib/libm/complex/carg.c delete mode 100644 lib/libm/complex/cargf.c delete mode 100644 lib/libm/complex/casin.3 delete mode 100644 lib/libm/complex/casin.c delete mode 100644 lib/libm/complex/casinf.c delete mode 100644 lib/libm/complex/casinh.3 delete mode 100644 lib/libm/complex/casinh.c delete mode 100644 lib/libm/complex/casinhf.c delete mode 100644 lib/libm/complex/catan.3 delete mode 100644 lib/libm/complex/catan.c delete mode 100644 lib/libm/complex/catanf.c delete mode 100644 lib/libm/complex/catanh.3 delete mode 100644 lib/libm/complex/catanh.c delete mode 100644 lib/libm/complex/catanhf.c delete mode 100644 lib/libm/complex/ccos.3 delete mode 100644 lib/libm/complex/ccos.c delete mode 100644 lib/libm/complex/ccosf.c delete mode 100644 lib/libm/complex/ccosh.3 delete mode 100644 lib/libm/complex/ccosh.c delete mode 100644 lib/libm/complex/ccoshf.c delete mode 100644 lib/libm/complex/cephes_subr.c delete mode 100644 lib/libm/complex/cephes_subr.h delete mode 100644 lib/libm/complex/cephes_subrf.c delete mode 100644 lib/libm/complex/cephes_subrf.h delete mode 100644 lib/libm/complex/cexp.3 delete mode 100644 lib/libm/complex/cexp.c delete mode 100644 lib/libm/complex/cexpf.c delete mode 100644 lib/libm/complex/cimag.3 delete mode 100644 lib/libm/complex/cimag.c delete mode 100644 lib/libm/complex/cimagf.c delete mode 100644 lib/libm/complex/cimagl.c delete mode 100644 lib/libm/complex/clog.3 delete mode 100644 lib/libm/complex/clog.c delete mode 100644 lib/libm/complex/clogf.c delete mode 100644 lib/libm/complex/conj.3 delete mode 100644 lib/libm/complex/conj.c delete mode 100644 lib/libm/complex/conjf.c delete mode 100644 lib/libm/complex/conjl.c delete mode 100644 lib/libm/complex/cpow.3 delete mode 100644 lib/libm/complex/cpow.c delete mode 100644 lib/libm/complex/cpowf.c delete mode 100644 lib/libm/complex/cproj.3 delete mode 100644 lib/libm/complex/cproj.c delete mode 100644 lib/libm/complex/cprojf.c delete mode 100644 lib/libm/complex/cprojl.c delete mode 100644 lib/libm/complex/creal.3 delete mode 100644 lib/libm/complex/creal.c delete mode 100644 lib/libm/complex/crealf.c delete mode 100644 lib/libm/complex/creall.c delete mode 100644 lib/libm/complex/csin.3 delete mode 100644 lib/libm/complex/csin.c delete mode 100644 lib/libm/complex/csinf.c delete mode 100644 lib/libm/complex/csinh.3 delete mode 100644 lib/libm/complex/csinh.c delete mode 100644 lib/libm/complex/csinhf.c delete mode 100644 lib/libm/complex/csqrt.3 delete mode 100644 lib/libm/complex/csqrt.c delete mode 100644 lib/libm/complex/csqrtf.c delete mode 100644 lib/libm/complex/ctan.3 delete mode 100644 lib/libm/complex/ctan.c delete mode 100644 lib/libm/complex/ctanf.c delete mode 100644 lib/libm/complex/ctanh.3 delete mode 100644 lib/libm/complex/ctanh.c delete mode 100644 lib/libm/complex/ctanhf.c delete mode 100644 lib/libm/gen/Makefile.inc delete mode 100644 lib/libm/gen/nan.3 delete mode 100644 lib/libm/gen/nan.c delete mode 100644 lib/libm/gen/nanf.c delete mode 100644 lib/libm/gen/nanl.c create mode 100644 lib/libm/i386/Makefile.inc rename lib/libm/{arch => }/i386/e_exp.S (70%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/e_fmod.S} (91%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/e_log.S} (93%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/e_log10.S} (93%) create mode 100644 lib/libm/i386/e_log10f.S create mode 100644 lib/libm/i386/e_logf.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/e_remainder.S} (90%) create mode 100644 lib/libm/i386/e_remainderf.S copy lib/libm/{arch => }/i386/e_remainderl.S (92%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/e_sqrt.S} (94%) create mode 100644 lib/libm/i386/e_sqrtf.S copy lib/libm/{arch => }/i386/e_sqrtl.S (95%) rename lib/libm/{arch => }/i386/fenv.c (86%) create mode 100644 lib/libm/i386/invtrig.c copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_ceil.S} (80%) copy lib/libm/{arch => }/i386/s_ceilf.S (57%) rename lib/libm/{arch/i386/s_ceilf.S => i386/s_ceill.S} (50%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_copysign.S} (87%) create mode 100644 lib/libm/i386/s_copysignf.S create mode 100644 lib/libm/i386/s_copysignl.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_cos.S} (86%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_finite.S} (89%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_floor.S} (80%) rename lib/libm/{arch => }/i386/s_floorf.S (57%) rename lib/libm/{arch/i386/s_floor.S => i386/s_floorl.S} (50%) copy lib/libm/{arch/i386/s_lrint.S => i386/s_llrint.S} (91%) copy lib/libm/{arch/i386/s_lrintf.S => i386/s_llrintf.S} (90%) copy lib/libm/{arch/i386/s_lrintf.S => i386/s_llrintl.S} (90%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_logb.S} (92%) create mode 100644 lib/libm/i386/s_logbf.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_logbl.S} (93%) copy lib/libm/{arch => }/i386/s_lrint.S (94%) copy lib/libm/{arch => }/i386/s_lrintf.S (94%) copy lib/libm/{arch => }/i386/s_lrintl.S (92%) copy lib/libm/{arch/i386/s_remquol.S => i386/s_remquo.S} (70%) copy lib/libm/{arch/i386/s_remquol.S => i386/s_remquof.S} (70%) copy lib/libm/{arch => }/i386/s_remquol.S (77%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_rint.S} (93%) create mode 100644 lib/libm/i386/s_rintf.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_rintl.S} (94%) copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_scalbn.S} (89%) create mode 100644 lib/libm/i386/s_scalbnf.S create mode 100644 lib/libm/i386/s_scalbnl.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_significand.S} (91%) create mode 100644 lib/libm/i386/s_significandf.S copy lib/libm/{arch/i386/e_sqrtl.S => i386/s_sin.S} (86%) copy lib/libm/{arch/i386/e_remainderl.S => i386/s_tan.S} (86%) create mode 100644 lib/libm/i386/s_trunc.S create mode 100644 lib/libm/i386/s_truncf.S create mode 100644 lib/libm/i386/s_truncl.S rename lib/libm/{src => ld80}/e_rem_pio2l.h (89%) rename lib/libm/{src => ld80}/invtrig.c (97%) rename lib/libm/{src => ld80}/invtrig.h (97%) rename lib/libm/{src => ld80}/k_cosl.c (93%) rename lib/libm/{src => ld80}/k_sinl.c (90%) rename lib/libm/{src => ld80}/k_tanl.c (96%) rename lib/libm/{src => ld80}/s_exp2l.c (86%) create mode 100644 lib/libm/ld80/s_expl.c copy lib/libm/{src/s_copysignl.c => ld80/s_nanl.c} (79%) delete mode 100644 lib/libm/man/Makefile.inc create mode 100644 lib/libm/man/cacos.3 copy lib/libm/man/{trunc.3 => ccos.3} (62%) copy lib/libm/man/{trunc.3 => ccosh.3} (61%) copy lib/libm/man/{log.3 => cexp.3} (52%) copy lib/libm/man/{fmax.3 => cimag.3} (50%) create mode 100644 lib/libm/man/complex.3 create mode 100644 lib/libm/man/csqrt.3 delete mode 100644 lib/libm/man/finite.3 delete mode 100644 lib/libm/man/frexp.3 create mode 100644 lib/libm/man/ieee.3 create mode 100644 lib/libm/man/nan.3 copy lib/libm/man/{trunc.3 => signbit.3} (64%) delete mode 100644 lib/libm/src/Makefile.inc create mode 100644 lib/libm/src/catrig.c create mode 100644 lib/libm/src/catrigf.c create mode 100644 lib/libm/src/complex.h create mode 100644 lib/libm/src/e_gamma.c create mode 100644 lib/libm/src/e_gamma_r.c rename lib/libm/src/{w_gammaf.c => e_gammaf.c} (59%) copy lib/libm/src/{s_fabsf.c => e_gammaf_r.c} (54%) create mode 100644 lib/libm/src/e_lgamma.c rename lib/libm/src/{w_gammaf_r.c => e_lgammaf.c} (59%) delete mode 100644 lib/libm/src/e_remainder.c delete mode 100644 lib/libm/src/e_remainderf.c delete mode 100644 lib/libm/src/e_sqrt.c delete mode 100644 lib/libm/src/e_sqrtf.c delete mode 100644 lib/libm/src/e_sqrtl.c rename lib/libm/{arch/i386 => src}/fenv.h (69%) create mode 100644 lib/libm/src/k_exp.c copy lib/libm/src/{s_fmaf.c => k_expf.c} (50%) copy lib/libm/src/{e_log.c => k_log.h} (51%) create mode 100644 lib/libm/src/k_logf.h delete mode 100644 lib/libm/src/k_rem_pio2f.c create mode 100644 lib/libm/src/math.h copy lib/libm/{complex/s_cargl.c => src/s_carg.c} (87%) copy lib/libm/{complex/s_cargl.c => src/s_cargf.c} (87%) copy lib/libm/{complex => src}/s_cargl.c (95%) create mode 100644 lib/libm/src/s_ccosh.c create mode 100644 lib/libm/src/s_ccoshf.c create mode 100644 lib/libm/src/s_cexp.c create mode 100644 lib/libm/src/s_cexpf.c copy lib/libm/src/{s_copysignl.c => s_cimag.c} (86%) copy lib/libm/src/{s_copysignl.c => s_cimagf.c} (86%) copy lib/libm/src/{s_copysignl.c => s_cimagl.c} (86%) copy lib/libm/src/{s_copysignl.c => s_conj.c} (86%) copy lib/libm/src/{s_copysignl.c => s_conjf.c} (86%) copy lib/libm/src/{s_copysignl.c => s_conjl.c} (86%) copy lib/libm/src/{e_remainderl.c => s_cproj.c} (80%) copy lib/libm/src/{e_remainderl.c => s_cprojf.c} (83%) copy lib/libm/src/{e_remainderl.c => s_cprojl.c} (82%) copy lib/libm/src/{s_copysignl.c => s_creal.c} (85%) copy lib/libm/src/{s_copysignl.c => s_crealf.c} (85%) copy lib/libm/src/{s_copysignl.c => s_creall.c} (86%) create mode 100644 lib/libm/src/s_csinh.c create mode 100644 lib/libm/src/s_csinhf.c copy lib/libm/{complex/s_csqrtl.c => src/s_csqrt.c} (68%) copy lib/libm/{complex/s_csqrtl.c => src/s_csqrtf.c} (56%) rename lib/libm/{complex => src}/s_csqrtl.c (95%) create mode 100644 lib/libm/src/s_ctanh.c copy lib/libm/src/{s_tanl.c => s_ctanhf.c} (55%) copy lib/libm/src/{s_fdim.c => s_isfinite.c} (78%) copy lib/{libc/gen/frexp.c => libm/src/s_isnan.c} (73%) copy lib/libm/src/{s_fdim.c => s_isnormal.c} (76%) delete mode 100644 lib/libm/src/s_llrint.c delete mode 100644 lib/libm/src/s_llrintf.c delete mode 100644 lib/libm/src/s_llrintl.c delete mode 100644 lib/libm/src/s_logbl.c delete mode 100644 lib/libm/src/s_lrint.c delete mode 100644 lib/libm/src/s_lrintf.c delete mode 100644 lib/libm/src/s_lrintl.c create mode 100644 lib/libm/src/s_nan.c delete mode 100644 lib/libm/src/s_remquo.c delete mode 100644 lib/libm/src/s_remquof.c delete mode 100644 lib/libm/src/s_remquol.c delete mode 100644 lib/libm/src/s_scalbn.c delete mode 100644 lib/libm/src/s_scalbnf.c delete mode 100644 lib/libm/src/s_scalbnl.c rename lib/libm/{complex/s_cargl.c => src/s_signbit.c} (76%) create mode 100644 lib/libm/src/w_cabs.c create mode 100644 lib/libm/src/w_cabsf.c rename lib/libm/{complex => src}/w_cabsl.c (80%) delete mode 100644 lib/libm/src/w_gamma.c delete mode 100644 lib/libm/src/w_gamma_r.c delete mode 100644 lib/libm/src/w_lgamma.c delete mode 100644 lib/libm/src/w_lgammaf.c create mode 100644 lib/libm/x86_64/Makefile.inc copy lib/libm/{arch/i386/e_remainderl.S => x86_64/e_remainder.S} (86%) create mode 100644 lib/libm/x86_64/e_remainderf.S rename lib/libm/{arch/i386 => x86_64}/e_remainderl.S (92%) copy lib/libm/{arch/i386/s_lrint.S => x86_64/e_sqrt.S} (89%) copy lib/libm/{arch/i386/s_lrint.S => x86_64/e_sqrtf.S} (89%) rename lib/libm/{src/e_remainderl.c => x86_64/e_sqrtl.S} (87%) rename lib/libm/{arch => }/x86_64/fenv.c (83%) create mode 100644 lib/libm/x86_64/s_llrint.S create mode 100644 lib/libm/x86_64/s_llrintf.S copy lib/libm/{arch/i386/s_lrint.S => x86_64/s_llrintl.S} (89%) copy lib/libm/{arch/i386/e_sqrtl.S => x86_64/s_logbl.S} (93%) rename lib/libm/{arch/i386 => x86_64}/s_lrint.S (91%) copy lib/libm/{arch/i386 => x86_64}/s_lrintf.S (91%) rename lib/libm/{arch/i386 => x86_64}/s_lrintl.S (92%) copy lib/libm/{arch/i386/s_remquol.S => x86_64/s_remquo.S} (70%) copy lib/libm/{arch/i386/s_remquol.S => x86_64/s_remquof.S} (70%) rename lib/libm/{arch/i386 => x86_64}/s_remquol.S (77%) rename lib/libm/{arch/i386/e_sqrtl.S => x86_64/s_rintl.S} (94%) copy lib/libm/{arch/i386/s_lrintf.S => x86_64/s_scalbn.S} (85%) rename lib/libm/{arch/i386/s_lrintf.S => x86_64/s_scalbnf.S} (83%) rename lib/libm/{arch/i386 => x86_64}/s_scalbnl.S (54%) delete mode 100644 sys/cpu/i386/include/float.h delete mode 100644 sys/cpu/i386/include/floatingpoint.h delete mode 100644 sys/cpu/i386/include/ieee.h delete mode 100644 sys/cpu/i386/include/math.h delete mode 100644 sys/cpu/x86_64/include/floatingpoint.h delete mode 100644 sys/cpu/x86_64/include/ieee.h delete mode 100644 sys/cpu/x86_64/include/math.h diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index 4b51edd31d..5e2c516917 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -1742,8 +1742,6 @@ TO_REMOVE+=/usr/share/man/cat9/MALLOC.9.gz TO_REMOVE+=/usr/share/man/man9/MALLOC.9.gz TO_REMOVE+=/usr/share/man/cat9/FREE.9.gz TO_REMOVE+=/usr/share/man/man9/FREE.9.gz -TO_REMOVE+=/usr/share/man/cat3/ieee.3.gz -TO_REMOVE+=/usr/share/man/man3/ieee.3.gz TO_REMOVE+=/usr/share/man/cat3/expmlf.3.gz TO_REMOVE+=/usr/share/man/man3/expmlf.3.gz TO_REMOVE+=/usr/share/man/man3/archive.3.gz @@ -2125,6 +2123,14 @@ TO_REMOVE+=/usr/sbin/spkrtest TO_REMOVE+=/usr/share/man/cat8/spkrtest.8.gz TO_REMOVE+=/usr/share/man/man8/spkrtest.8.gz TO_REMOVE+=/usr/include/machine/uvparam.h +TO_REMOVE+=/usr/include/cpu/float.h +TO_REMOVE+=/usr/include/machine/float.h +TO_REMOVE+=/usr/include/cpu/floatingpoint.h +TO_REMOVE+=/usr/include/machine/floatingpoint.h +TO_REMOVE+=/usr/include/cpu/ieee.h +TO_REMOVE+=/usr/include/machine/ieee.h +TO_REMOVE+=/usr/include/cpu/math.h +TO_REMOVE+=/usr/include/machine/math.h .if ${MACHINE_ARCH} == "x86_64" TO_REMOVE+=/usr/sbin/stlstats diff --git a/include/Makefile b/include/Makefile index 675ec5c08d..9e6272ad16 100644 --- a/include/Makefile +++ b/include/Makefile @@ -8,12 +8,12 @@ CLEANFILES= osreldate.h version vers.c vers.txt SUBDIR= arpa protocols rpc rpcsvc -INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h ctype.h db.h \ +INCS= a.out.h ar.h assert.h bitstring.h cpio.h ctype.h db.h \ dirent.h disktab.h \ - dlfcn.h elf.h elf-hints.h err.h fmtmsg.h fnmatch.h fstab.h \ + dlfcn.h elf.h elf-hints.h err.h float.h fmtmsg.h fnmatch.h fstab.h \ fts.h ftw.h getopt.h glob.h grp.h histedit.h \ iconv.h ieeefp.h ifaddrs.h iso646.h inttypes.h \ - langinfo.h libgen.h limits.h link.h locale.h malloc.h math.h memory.h \ + langinfo.h libgen.h limits.h link.h locale.h malloc.h memory.h \ mntopts.h mpool.h mqueue.h monetary.h ndbm.h netconfig.h \ netdb.h nl_types.h nlist.h nss.h nsswitch.h objformat.h \ paths.h printf.h pthread.h pthread_np.h pwd.h \ @@ -22,7 +22,8 @@ INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h ctype.h db.h \ search.h setjmp.h sgtty.h \ signal.h spawn.h stab.h stdarg.h stdbool.h \ stddef.h stdint.h stdio.h stdlib.h \ - string.h stringlist.h strings.h struct.h sysexits.h tar.h time.h \ + string.h stringlist.h strings.h struct.h sysexits.h \ + tar.h time.h \ timeconv.h \ timers.h ttyent.h tzfile.h unistd.h ulimit.h utime.h utmp.h utmpx.h \ uuid.h vis.h \ @@ -32,7 +33,7 @@ INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h ctype.h db.h \ INCS+= hesiod.h .endif -MHDRS= float.h floatingpoint.h varargs.h +MHDRS= varargs.h # Only for default SHARED=copies case SHDRS= soundcard.h joystick.h @@ -150,6 +151,8 @@ INCSLINKS+= netproto/natm ${INCLUDEDIR}/netnatm INCSLINKS+= netproto/ncp ${INCLUDEDIR}/netncp INCSLINKS+= netproto/smb ${INCLUDEDIR}/netsmb INCSLINKS+= bus/pccard ${INCLUDEDIR}/pccard +# Some 3rd party software looks for +INCSLINKS+= ieeefp.h ${INCLUDEDIR}/floatingpoint.h # NOTE! # diff --git a/include/complex.h b/include/complex.h deleted file mode 100644 index cc842ee07d..0000000000 --- a/include/complex.h +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * Copyright (c) 2001 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: src/include/complex.h,v 1.1.2.1 2001/11/23 16:16:18 dd Exp $ - * $DragonFly: src/include/complex.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ - */ - -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __GNUC__ -#if __STDC_VERSION__ < 199901L -#define _Complex __complex__ -#endif -#define _Complex_I 1.0fi -#endif /* !__GNUC__ */ - -/* 7.3 Complex arithmetic */ -/* 7.3.1 */ -#define complex _Complex -#define I _Complex_I - -#include - -__BEGIN_DECLS - -/* 7.3.5 Trigonometric functions */ -/* 7.3.5.1 The cacos functions */ -double complex cacos(double complex); -float complex cacosf(float complex); - -/* 7.3.5.2 The casin functions */ -double complex casin(double complex); -float complex casinf(float complex); - -/* 7.3.5.3 The catan functions */ -double complex catan(double complex); -float complex catanf(float complex); - -/* 7.3.5.4 The ccos functions */ -double complex ccos(double complex); -float complex ccosf(float complex); - -/* 7.3.5.5 The csin functions */ -double complex csin(double complex); -float complex csinf(float complex); - -/* 7.3.5.6 The ctan functions */ -double complex ctan(double complex); -float complex ctanf(float complex); - -/* 7.3.6 Hyperbolic functions */ -/* 7.3.6.1 The cacosh functions */ -double complex cacosh(double complex); -float complex cacoshf(float complex); - -/* 7.3.6.2 The casinh functions */ -double complex casinh(double complex); -float complex casinhf(float complex); - -/* 7.3.6.3 The catanh functions */ -double complex catanh(double complex); -float complex catanhf(float complex); - -/* 7.3.6.4 The ccosh functions */ -double complex ccosh(double complex); -float complex ccoshf(float complex); - -/* 7.3.6.5 The csinh functions */ -double complex csinh(double complex); -float complex csinhf(float complex); - -/* 7.3.6.6 The ctanh functions */ -double complex ctanh(double complex); -float complex ctanhf(float complex); - -/* 7.3.7 Exponential and logarithmic functions */ -/* 7.3.7.1 The cexp functions */ -double complex cexp(double complex); -float complex cexpf(float complex); - -/* 7.3.7.2 The clog functions */ -double complex clog(double complex); -float complex clogf(float complex); - -/* 7.3.8 Power and absolute-value functions */ -/* 7.3.8.1 The cabs functions */ -double cabs(double complex); -float cabsf(float complex); -long double cabsl (long double complex); - -/* 7.3.8.2 The cpow functions */ -double complex cpow(double complex, double complex); -float complex cpowf(float complex, float complex); - -/* 7.3.8.3 The csqrt functions */ -double complex csqrt(double complex); -float complex csqrtf(float complex); -long double complex csqrtl(long double complex); - -/* 7.3.9 Manipulation functions */ -/* 7.3.9.1 The carg functions */ -double carg(double complex); -float cargf(float complex); -long double cargl(long double complex); - -/* 7.3.9.2 The cimag functions */ -double cimag(double complex); -float cimagf(float complex); -long double cimagl(long double complex); - -/* 7.3.9.3 The conj functions */ -double complex conj(double complex); -float complex conjf(float complex); -long double complex conjl(long double complex); - -/* 7.3.9.4 The cproj functions */ -double complex cproj(double complex); -float complex cprojf(float complex); -long double complex cprojl(long double complex); - -/* 7.3.9.5 The creal functions */ -double creal(double complex); -float crealf(float complex); -long double creall(long double complex); - -__END_DECLS - -#endif /* _COMPLEX_H */ diff --git a/sys/cpu/x86_64/include/float.h b/include/float.h similarity index 77% rename from sys/cpu/x86_64/include/float.h rename to include/float.h index b2d89bbc4f..a699e5593f 100644 --- a/sys/cpu/x86_64/include/float.h +++ b/include/float.h @@ -27,22 +27,26 @@ * SUCH DAMAGE. * * from: @(#)float.h 7.1 (Berkeley) 5/8/90 - * $FreeBSD: src/sys/amd64/include/float.h,v 1.16 2008/01/17 13:12:46 bde Exp $ + * $FreeBSD: head/sys/x86/include/float.h 235939 2012-05-24 21:44:46Z obrien $ */ -#ifndef _CPU_FLOAT_H_ -#define _CPU_FLOAT_H_ +#ifndef _FLOAT_H_ +#define _FLOAT_H_ #include __BEGIN_DECLS -extern int __flt_rounds(void); +extern int __flt_rounds(void); __END_DECLS #define FLT_RADIX 2 /* b */ -#define FLT_ROUNDS __flt_rounds() +#define FLT_ROUNDS __flt_rounds() #if __ISO_C_VISIBLE >= 1999 +#ifdef __LP64__ #define FLT_EVAL_METHOD 0 /* no promotions */ +#else +#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ +#endif #define DECIMAL_DIG 21 /* max precision in decimal digits */ #endif @@ -55,6 +59,11 @@ __END_DECLS #define FLT_MAX_EXP 128 /* emax */ #define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ #define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ +#if __ISO_C_VISIBLE >= 2011 +#define FLT_TRUE_MIN 1.40129846E-45F /* b**(emin-p) */ +#define FLT_DECIMAL_DIG 9 /* ceil(1+p*log10(b)) */ +#define FLT_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ #define DBL_MANT_DIG 53 #define DBL_EPSILON 2.2204460492503131E-16 @@ -65,6 +74,11 @@ __END_DECLS #define DBL_MAX_EXP 1024 #define DBL_MAX 1.7976931348623157E+308 #define DBL_MAX_10_EXP 308 +#if __ISO_C_VISIBLE >= 2011 +#define DBL_TRUE_MIN 4.9406564584124654E-324 +#define DBL_DECIMAL_DIG 17 +#define DBL_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ #define LDBL_MANT_DIG 64 #define LDBL_EPSILON 1.0842021724855044340E-19L @@ -75,4 +89,10 @@ __END_DECLS #define LDBL_MAX_EXP 16384 #define LDBL_MAX 1.1897314953572317650E+4932L #define LDBL_MAX_10_EXP 4932 -#endif /* _CPU_FLOAT_H_ */ +#if __ISO_C_VISIBLE >= 2011 +#define LDBL_TRUE_MIN 3.6451995318824746025E-4951L +#define LDBL_DECIMAL_DIG 21 +#define LDBL_HAS_SUBNORM 1 +#endif /* __ISO_C_VISIBLE >= 2011 */ + +#endif /* _FLOAT_H_ */ diff --git a/include/ieeefp.h b/include/ieeefp.h index 981deea0a2..8081d4f201 100644 --- a/include/ieeefp.h +++ b/include/ieeefp.h @@ -1,5 +1,5 @@ /* $NetBSD: ieeefp.h,v 1.4 1998/01/09 08:03:43 perry Exp $ */ -/* $FreeBSD: src/include/ieeefp.h,v 1.7 2003/01/19 06:01:32 marcel Exp $ */ +/* $FreeBSD: head/include/ieeefp.h 226607 2011-10-21 06:41:46Z das $ */ /* * Written by J.T. Conklin, Apr 6, 1995 @@ -12,15 +12,4 @@ #include #include -#if !defined(_IEEEFP_INLINED_) -__BEGIN_DECLS -extern fp_rnd_t fpgetround(void); -extern fp_rnd_t fpsetround(fp_rnd_t); -extern fp_except_t fpgetmask(void); -extern fp_except_t fpsetmask(fp_except_t); -extern fp_except_t fpgetsticky(void); -extern fp_except_t fpsetsticky(fp_except_t); -__END_DECLS -#endif /* !_IEEEFP_INLINED_ */ - #endif /* _IEEEFP_H_ */ diff --git a/include/math.h b/include/math.h deleted file mode 100644 index 52ba5ec270..0000000000 --- a/include/math.h +++ /dev/null @@ -1,521 +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. - * ==================================================== - * - * $NetBSD: math.h,v 1.46 2007/02/22 22:08:19 drochner Exp $ - */ - -/* - * @(#)fdlibm.h 5.1 93/09/24 - */ - -#ifndef _MATH_H_ -#define _MATH_H_ - -#include -#include - -#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) -#define __MATH_BUILTIN_CONSTANTS -#endif - -#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) -#define __MATH_BUILTIN_RELOPS -#endif - -union __float_u { - unsigned char __dummy[sizeof(float)]; - float __val; -}; - -union __double_u { - unsigned char __dummy[sizeof(double)]; - double __val; -}; - -union __long_double_u { - unsigned char __dummy[sizeof(long double)]; - long double __val; -}; - -#include - -#ifdef __HAVE_LONG_DOUBLE -#define __fpmacro_unary_floating(__name, __arg0) \ - /* LINTED */ \ - ((sizeof (__arg0) == sizeof (float)) \ - ? __ ## __name ## f (__arg0) \ - : (sizeof (__arg0) == sizeof (double)) \ - ? __ ## __name ## d (__arg0) \ - : __ ## __name ## l (__arg0)) -#else -#define __fpmacro_unary_floating(__name, __arg0) \ - /* LINTED */ \ - ((sizeof (__arg0) == sizeof (float)) \ - ? __ ## __name ## f (__arg0) \ - : __ ## __name ## d (__arg0)) -#endif /* __HAVE_LONG_DOUBLE */ - -/* - * ANSI/POSIX - */ -/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ -extern const union __double_u __infinity; -#ifdef __MATH_BUILTIN_CONSTANTS -#define HUGE_VAL __builtin_huge_val() -#else -#define HUGE_VAL __infinity.__val -#endif - -/* - * ISO C99 - */ -#if __ISO_C_VISIBLE >= 1999 -/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ -extern const union __float_u __infinityf; -#ifdef __MATH_BUILTIN_CONSTANTS -#define HUGE_VALF __builtin_huge_valf() -#else -#define HUGE_VALF __infinityf.__val -#endif - -extern const union __long_double_u __infinityl; -#ifdef __MATH_BUILTIN_CONSTANTS -#define HUGE_VALL __builtin_huge_vall() -#else -#define HUGE_VALL __infinityl.__val -#endif - -/* 7.12#4 INFINITY */ -#ifdef __MATH_BUILTIN_CONSTANTS -#define INFINITY __builtin_inf() -#elif defined(__INFINITY) -#define INFINITY __INFINITY /* float constant which overflows */ -#else -#define INFINITY HUGE_VALF /* positive infinity */ -#endif /* __INFINITY */ - -/* 7.12#5 NAN: a quiet NaN, if supported */ -#ifdef __MATH_BUILTIN_CONSTANTS -#define NAN __builtin_nan("") -#elif defined(__HAVE_NANF) -extern const union __float_u __nanf; -#define NAN __nanf.__val -#endif /* __HAVE_NANF */ - -/* 7.12#6 number classification macros */ -#define FP_INFINITE 0x00 -#define FP_NAN 0x01 -#define FP_NORMAL 0x02 -#define FP_SUBNORMAL 0x03 -#define FP_ZERO 0x04 -/* NetBSD extensions */ -#define _FP_LOMD 0x80 /* range for machine-specific classes */ -#define _FP_HIMD 0xff - -/* 7.12#8 values returned by ilogb(0) or ilogb(NAN), respectively */ -#define FP_ILOGB0 INT_MIN -#define FP_ILOGBNAN INT_MIN - -#endif /* ISO C99 */ - -/* - * XOPEN/SVID - */ -#if __XSI_VISIBLE > 0 -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log 2e */ -#define M_LOG10E 0.43429448190325182765 /* log 10e */ -#define M_LN2 0.69314718055994530942 /* log e2 */ -#define M_LN10 2.30258509299404568402 /* log e10 */ -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ - -#define MAXFLOAT ((float)3.40282346638528860e+38) -extern int signgam; -#endif /* _XSI_VISIBLE */ - -#if __DF_VISIBLE -#define HUGE MAXFLOAT - -/* - * set X_TLOSS = pi*2**52, which is possibly defined in - * (one may replace the following line by "#include ") - */ - -#define X_TLOSS 1.41484755040568800000e+16 - -#define DOMAIN 1 -#define SING 2 -#define OVERFLOW 3 -#define UNDERFLOW 4 -#define TLOSS 5 -#define PLOSS 6 - -#endif /* __DF_VISIBLE */ - -__BEGIN_DECLS -/* - * ANSI/POSIX - */ -double acos(double); -double asin(double); -double atan(double); -double atan2(double, double); -double cos(double); -double sin(double); -double tan(double); - -double cosh(double); -double sinh(double); -double tanh(double); - -double exp(double); -double exp2(double); -double frexp(double, int *); -double ldexp(double, int); -double log(double); -double log2(double); -double log10(double); -double modf(double, double *); - -double pow(double, double); -double sqrt(double); - -double ceil(double); -double fabs(double); -double floor(double); -double fmod(double, double); - -#if __XSI_VISIBLE > 0 -double erf(double); -double erfc(double); -double gamma(double); -double hypot(double, double); -int finite(double); -double j0(double); -double j1(double); -double jn(int, double); -double lgamma(double); -double tgamma(double); -double y0(double); -double y1(double); -double yn(int, double); -#endif /* __XSI_VISIBLE */ - -#if __XSI_VISIBLE >= 500 -double acosh(double); -double asinh(double); -double atanh(double); -double cbrt(double); -double expm1(double); -int ilogb(double); -double log1p(double); -double logb(double); -double nextafter(double, double); -double remainder(double, double); -double rint(double); -double scalb(double, double); -#endif /* __XSI_VISIBLE >= 500 */ - -/* - * ISO C99 - */ -#if __ISO_C_VISIBLE >= 1999 -/* 7.12.3.1 int fpclassify(real-floating x) */ -#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x) - -/* 7.12.3.2 int isfinite(real-floating x) */ -#define isfinite(__x) __fpmacro_unary_floating(isfinite, __x) - -/* 7.12.3.5 int isnormal(real-floating x) */ -#define isnormal(__x) (fpclassify(__x) == FP_NORMAL) - -/* 7.12.3.6 int signbit(real-floating x) */ -#define signbit(__x) __fpmacro_unary_floating(signbit, __x) - -/* 7.12.4 trigonometric */ - -float acosf(float); -float asinf(float); -float atanf(float); -float atan2f(float, float); -float cosf(float); -float sinf(float); -float tanf(float); - -/* 7.12.5 hyperbolic */ - -float acoshf(float); -float asinhf(float); -float atanhf(float); -float coshf(float); -float sinhf(float); -float tanhf(float); - -/* 7.12.6 exp / log */ - -float expf(float); -float exp2f(float); -float expm1f(float); -float frexpf(float, int *); -int ilogbf(float); -float ldexpf(float, int); -float logf(float); -float log2f(float); -float log10f(float); -float log1pf(float); -float logbf(float); -float modff(float, float *); -float scalblnf(float, long); -float scalbnf(float, int); - -/* 7.12.7 power / absolute */ - -float cbrtf(float); -float fabsf(float); -float hypotf(float, float); -float powf(float, float); -float sqrtf(float); - -/* 7.12.8 error / gamma */ - -float erff(float); -float erfcf(float); -float lgammaf(float); -float tgammaf(float); - -/* 7.12.9 nearest integer */ - -float ceilf(float); -float floorf(float); -float nearbyintf(float); -double nearbyint(double); -float rintf(float); -double round(double); -float roundf(float); -double trunc(double); -float truncf(float); -long int lrint(double); -long int lrintf(float); -/* LONGLONG */ -long long int llrint(double); -/* LONGLONG */ -long long int llrintf(float); -long int lround(double); -long int lroundf(float); -/* LONGLONG */ -long long int llround(double); -/* LONGLONG */ -long long int llroundf(float); - -/* 7.12.10 remainder */ - -float fmodf(float, float); -float remainderf(float, float); - -/* 7.12.10.3 The remquo functions */ -double remquo(double, double, int *); -float remquof(float, float, int *); - -/* 7.12.11 manipulation */ - -float copysignf(float, float); -double nan(const char *); -float nanf(const char *); -float nextafterf(float, float); - -/* 7.12.12 maximum, minimum, positive difference */ -double fdim(double, double); -float fdimf(float, float); - -double fmax(double, double); -float fmaxf(float, float); - -double fmin(double, double); -float fminf(float, float); - - -/* isoC99 */ -double fma (double, double, double); -float fmaf (float, float, float); - - - - -#endif /* __ISO_C_VISIBLE >= 1999 */ - -#if __ISO_C_VISIBLE >= 1999 -/* 7.12.3.3 int isinf(real-floating x) */ -#ifdef __isinf -#define isinf(__x) __isinf(__x) -#else -#define isinf(__x) __fpmacro_unary_floating(isinf, __x) -#endif - -/* 7.12.3.4 int isnan(real-floating x) */ -#ifdef __isnan -#define isnan(__x) __isnan(__x) -#else -#define isnan(__x) __fpmacro_unary_floating(isnan, __x) -#endif - -/* 7.12.14 Comparision macros */ -#ifdef __MATH_BUILTIN_RELOPS -#define isgreater(x, y) __builtin_isgreater((x), (y)) -#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) -#define isless(x, y) __builtin_isless((x), (y)) -#define islessequal(x, y) __builtin_islessequal((x), (y)) -#define islessgreater(x, y) __builtin_islessgreater((x), (y)) -#define isunordered(x, y) __builtin_isunordered((x), (y)) -#else -#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) -#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) -#define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) -#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) -#define islessgreater(x, y) (!isunordered((x), (y)) && \ - ((x) > (y) || (y) > (x))) -#define isunordered(x, y) (isnan(x) || isnan(y)) -#endif /* __MATH_BUILTIN_RELOPS */ - -#endif /* __ISO_C_VISIBLE >= 1999 */ - -#if __DF_VISIBLE -/* - * IEEE Test Vector - */ -double significand(double); - -/* - * Functions callable from C, intended to support IEEE arithmetic. - */ -double copysign(double, double); -double scalbln(double, long); -double scalbn(double, int); - -/* - * BSD math library entry points - */ -double drem(double, double); - -/* - * Reentrant version of gamma & lgamma; passes signgam back by reference - * as the second argument; user must allocate space for signgam. - */ -double gamma_r(double, int *); -double lgamma_r(double, int *); -#endif /* __DF_VISIBLE */ - - -#if __DF_VISIBLE - -/* float versions of ANSI/POSIX functions */ - -float gammaf(float); -int finitef(float); -float j0f(float); -float j1f(float); -float jnf(int, float); -float y0f(float); -float y1f(float); -float ynf(int, float); - -float scalbf(float, float); - -/* - * float version of IEEE Test Vector - */ -float significandf(float); - -/* - * float versions of BSD math library entry points - */ -float dremf(float, float); - -/* - * Float versions of reentrant version of gamma & lgamma; passes - * signgam back by reference as the second argument; user must - * allocate space for signgam. - */ -float gammaf_r(float, int *); -float lgammaf_r(float, int *); -#endif /* __DF_VISIBLE */ - -/* - * Library implementation - */ -int __fpclassifyf(float); -int __fpclassifyd(double); -int __isfinitef(float); -int __isfinited(double); -int __isinff(float); -int __isinfd(double); -int __isnanf(float); -int __isnand(double); -int __signbitf(float); -int __signbitd(double); - -#ifdef __HAVE_LONG_DOUBLE -int __fpclassifyl (long double); -int __isfinitel (long double); -int __isinfl (long double); -int __isnanl (long double); -int __signbitl (long double); - -long double acosl (long double); -long double asinl (long double); -long double atan2l (long double, long double); -long double atanl (long double); -long double ceill (long double); -long double cosl (long double); -long double cbrtl (long double); -long double copysignl (long double, long double); -long double fdiml (long double, long double); -long double exp2l (long double); -long double fabsl (long double); -long double floorl (long double); -long double fmal (long double, long double, long double); -long double frexpl (long double, int *); -long double fmaxl (long double, long double); -long double fminl (long double, long double); -long double fmodl (long double, long double); -long double hypotl (long double, long double); -int ilogbl (long double); -long double ldexpl (long double, int); -long long llrintl (long double); -long long llroundl (long double); -long double logbl (long double); -long lrintl (long double); -long lroundl (long double); -long double modfl (long double, long double *); -long double nanl (const char *); -long double nearbyintl (long double); -long double nextafterl (long double, long double); -double nexttoward (double, long double); -float nexttowardf (float, long double); -long double remainderl (long double, long double); -long double remquol (long double, long double, int *); -long double rintl (long double); -long double roundl (long double); -long double scalblnl (long double, long); -long double scalbnl (long double, int); -long double sinl (long double); -long double sqrtl (long double); -long double tanl (long double); -long double truncl (long double); -#endif -__END_DECLS - -#endif /* _MATH_H_ */ diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 3313c9711a..1b78437853 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -9,7 +9,7 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ clock.c closedir.c confstr.c \ ctermid.c ctype.c daemon.c devname.c dirname.c disklabel.c disktab.c \ dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c exec.c \ - fdevname.c fmtcheck.c fmtmsg.c fnmatch.c fpclassifyd.c fpclassifyf.c \ + fdevname.c fmtcheck.c fmtmsg.c fnmatch.c fpclassify.c \ frexp.c fstab.c ftok.c fts.c ftw.c getbootfile.c getbsize.c \ getcap.c getcwd.c getdevpath.c getdomainname.c \ getgrent.c getgrouplist.c \ @@ -17,10 +17,9 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ getnetgrent.c getobjformat.c getosreldate.c getpagesize.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getvfsbyname.c getvfsent.c glob.c \ - infinity.c infinityf.c initgroups.c isascii.c \ - isatty.c isctype.c isfinited.c isfinitef.c isinfd.c isinff.c \ - isnand.c isnanf.c jrand48.c lcong48.c \ - lockf.c lrand48.c mrand48.c msgctl.c \ + initgroups.c isascii.c isatty.c isctype.c isinf.c isnan.c \ + jrand48.c lcong48.c ldexp.c \ + lockf.c lrand48.c modf.c mrand48.c msgctl.c \ msgget.c msgrcv.c msgsnd.c nftw.c nice.c \ nlist.c nrand48.c ntp_gettime.c opendir.c \ pause.c pmadvise.c popen.c posix_spawn.c posixshm.c \ @@ -30,7 +29,7 @@ SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ setdomainname.c sethostname.c setjmperr.c setmode.c setprogname.c \ setproctitle.c \ siginterrupt.c siglist.c signal.c \ - signbitd.c signbitf.c sigsetops.c sigwait.c sleep.c srand48.c \ + sigsetops.c sigwait.c sleep.c srand48.c \ stringlist.c strtofflags.c sysconf.c sysctl.c sysctlbyname.c \ sysctlnametomib.c syslog.c telldir.c termios.c time.c times.c \ toascii.c tolower.c toupper.c ttyname.c ttyslot.c \ @@ -63,7 +62,7 @@ MAN+= alarm.3 arc4random.3 clock.3 \ getttyent.3 getusershell.3 getvfsbyname.3 getvfsent.3 \ glob.3 initgroups.3 isalnum.3 isalpha.3 isascii.3 isblank.3 \ iscntrl.3 isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 \ - isspace.3 isupper.3 isxdigit.3 isinf.3 isfinite.3 isnan.3 isnormal.3 \ + isspace.3 isupper.3 isxdigit.3 \ ldexp.3 lockf.3 makecontext.3 modf.3 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \ nice.3 nlist.3 pause.3 popen.3 posix_spawn.3 \ posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_init.3 \ @@ -73,7 +72,7 @@ MAN+= alarm.3 arc4random.3 clock.3 \ posix_spawnattr_init.3 psignal.3 pwcache.3 \ raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \ scandir.3 setjmp.3 setmode.3 setproctitle.3 shm_open.3 \ - siginterrupt.3 signal.3 signbit.3 sigsetops.3 sleep.3 stringlist.3 \ + siginterrupt.3 signal.3 sigsetops.3 sleep.3 stringlist.3 \ strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 tcgetsid.3 \ tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 time.3 times.3 \ toascii.3 tolower.3 toupper.3 ttyname.3 tzset.3 ualarm.3 \ @@ -97,6 +96,12 @@ MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \ err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3 MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \ exec.3 execv.3 exec.3 execvP.3 exec.3 execvp.3 +MLINKS+=fpclassify.3 finite.3 \ + fpclassify.3 finitef.3 \ + fpclassify.3 isfinite.3 \ + fpclassify.3 isinf.3 \ + fpclassify.3 isnan.3 \ + fpclassify.3 isnormal.3 MLINKS+=frexp.3 frexpf.3 frexp.3 frexpl.3 MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_get_clientptr.3 \ fts.3 fts_get_stream.3 fts.3 fts_open.3 fts.3 fts_read.3 \ @@ -136,7 +141,11 @@ MLINKS+=getvfsent.3 endvfsent.3 getvfsent.3 getvfsbytype.3 \ getvfsent.3 vfsload.3 MLINKS+=glob.3 globfree.3 MLINKS+=getcontext.3 setcontext.3 +MLINKS+=ldexp.3 ldexpf.3 \ + ldexp.3 ldexpl.3 MLINKS+=makecontext.3 swapcontext.3 +MLINKS+=modf.3 modff.3 \ + modf.3 modfl.3 MLINKS+=popen.3 pclose.3 MLINKS+=posix_spawn.3 posix_spawnp.3 MLINKS+=posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclose.3 \ diff --git a/lib/libc/gen/fpclassify.3 b/lib/libc/gen/fpclassify.3 index 40980853ab..2340f6cd5c 100644 --- a/lib/libc/gen/fpclassify.3 +++ b/lib/libc/gen/fpclassify.3 @@ -1,12 +1,6 @@ -.\" $NetBSD: fpclassify.3,v 1.2 2004/01/15 19:43:45 kleink Exp $ -.\" $DragonFly: src/lib/libc/gen/fpclassify.3,v 1.1 2005/07/26 21:15:19 joerg Exp $ -.\" -.\" Copyright (c) 2003 The NetBSD Foundation, Inc. +.\" Copyright (c) 2003 Mike Barcroft .\" All rights reserved. .\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein. -.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -15,76 +9,125 @@ .\" 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. +.\" +.\" $FreeBSD: head/lib/libc/gen/fpclassify.3 140890 2005-01-27 05:46:17Z das $ .\" -.Dd January 14, 2004 +.Dd January 26, 2005 .Dt FPCLASSIFY 3 .Os .Sh NAME -.Nm fpclassify -.Nd classify real floating type +.Nm fpclassify , isfinite , isinf , isnan , isnormal +.Nd "classify a floating-point number" .Sh LIBRARY -.Lb libc +.Lb libm .Sh SYNOPSIS .In math.h .Ft int .Fn fpclassify "real-floating x" +.Ft int +.Fn isfinite "real-floating x" +.Ft int +.Fn isinf "real-floating x" +.Ft int +.Fn isnan "real-floating x" +.Ft int +.Fn isnormal "real-floating x" .Sh DESCRIPTION The .Fn fpclassify -macro performs classification of its argument -.Fa x . -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The classification is then based on the type of the argument. -.Ss IEEE 754 -.Bl -tag -width "FP_SUBNORMALXXX" -compact -offset indent +macro takes an argument of +.Fa x +and returns one of the following manifest constants. +.Bl -tag -width ".Dv FP_SUBNORMAL" .It Dv FP_INFINITE -infinity, either positive or negative +Indicates that +.Fa x +is an infinite number. .It Dv FP_NAN -not-a-number -.Pq Dq NaN +Indicates that +.Fa x +is not a number (NaN). .It Dv FP_NORMAL -normal +Indicates that +.Fa x +is a normalized number. .It Dv FP_SUBNORMAL -subnormal +Indicates that +.Fa x +is a denormalized number. .It Dv FP_ZERO -zero +Indicates that +.Fa x +is zero (0 or \-0). .El -.Sh RETURN VALUES +.Pp The -.Fn fpclassify -macro returns the value of the number classification macro appropriate -to its argument +.Fn isfinite +macro returns a non-zero value if and only if its argument has +a finite (zero, subnormal, or normal) value. +The +.Fn isinf , +.Fn isnan , +and +.Fn isnormal +macros return non-zero if and only if .Fa x -as described above. -.Sh ERRORS -No errors are defined. +is an infinity, NaN, +or a non-zero normalized number, respectively. +.Pp +The symbol +.Fn isnanf +is provided as an alias to +.Fn isnan +for compatibility, and its use is deprecated. +Similarly, +.Fn finite +and +.Fn finitef +are deprecated versions of +.Fn isfinite . .Sh SEE ALSO -.Xr isfinite 3 , -.Xr isnormal 3 , +.Xr isgreater 3 , .Xr math 3 , .Xr signbit 3 .Sh STANDARDS The -.Fn fpclassify -macro conforms to +.Fn fpclassify , +.Fn isfinite , +.Fn isinf , +.Fn isnan , +and +.Fn isnormal +macros conform to .St -isoC-99 . +.Sh HISTORY +The +.Fn fpclassify , +.Fn isfinite , +.Fn isinf , +.Fn isnan , +and +.Fn isnormal +macros were added in +.Dx 1.3 . +.Bx 3 +introduced +.Fn isinf +and +.Fn isnan +functions, which accepted +.Vt double +arguments; these have been superseded by the macros +described above. diff --git a/lib/libm/src/s_rintl.c b/lib/libc/gen/fpclassify.c similarity index 52% rename from lib/libm/src/s_rintl.c rename to lib/libc/gen/fpclassify.c index e1ab92d916..203cb897f1 100644 --- a/lib/libm/src/s_rintl.c +++ b/lib/libc/gen/fpclassify.c @@ -1,5 +1,6 @@ /*- - * Copyright (c) 2008 David Schultz + * Copyright (c) 2003 Mike Barcroft + * Copyright (c) 2002, 2003 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,61 +24,70 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 176461 (2008-02-22) + * $FreeBSD: head/lib/libc/gen/fpclassify.c 141379 2005-02-06 03:23:31Z das $ */ -#include +#include + #include +#include #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) +int +__fpclassifyf(float f) +{ + union IEEEf2bits u; -static const float -shift[2] = { - 0x1.0p63, -0x1.0p63 -}; -static const float zero[2] = { 0.0, -0.0 }; + 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); +} -long double -rintl(long double x) +int +__fpclassifyd(double d) { - union IEEEl2bits u; - uint32_t expsign; - int ex, sign; - - u.e = x; - expsign = u.xbits.expsign; - ex = expsign & 0x7fff; + union IEEEd2bits u; - 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 */ + u.d = d; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_ZERO); + return (FP_SUBNORMAL); } - 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 (u.bits.exp == 2047) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_INFINITE); + return (FP_NAN); + } + return (FP_NORMAL); +} - /* - * 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]); +int +__fpclassifyl(long double e) +{ + union IEEEl2bits u; - return (x); + 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/lib/libc/gen/fpclassifyd.c b/lib/libc/gen/fpclassifyd.c deleted file mode 100644 index 50f0841873..0000000000 --- a/lib/libc/gen/fpclassifyd.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $NetBSD: fpclassifyd_ieee754.c,v 1.1 2003/10/28 22:50:42 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/fpclassifyd.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include - -/* - * 7.12.3.1 fpclassify - classify real floating type - * IEEE 754 double-precision version - */ -int -__fpclassifyd(double x) -{ - union ieee_double_u u; - - u.dblu_d = x; - - if (u.dblu_dbl.dbl_exp == 0) { - if (u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0) - return FP_ZERO; - else - return FP_SUBNORMAL; - } else if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN) { - if (u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0) - return FP_INFINITE; - else - return FP_NAN; - } - - return FP_NORMAL; -} diff --git a/lib/libc/gen/fpclassifyf.c b/lib/libc/gen/fpclassifyf.c deleted file mode 100644 index 948da0e714..0000000000 --- a/lib/libc/gen/fpclassifyf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $NetBSD: fpclassifyf_ieee754.c,v 1.2 2003/10/29 19:34:11 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/fpclassifyf.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include - -/* - * 7.12.3.1 fpclassify - classify real floating type - * IEEE 754 single-precision version - */ -int -__fpclassifyf(float x) -{ - union ieee_single_u u; - - u.sngu_f = x; - - if (u.sngu_sng.sng_exp == 0) { - if (u.sngu_sng.sng_frac == 0) - return FP_ZERO; - else - return FP_SUBNORMAL; - } else if (u.sngu_sng.sng_exp == SNG_EXP_INFNAN) { - if (u.sngu_sng.sng_frac == 0) - return FP_INFINITE; - else - return FP_NAN; - } - - return FP_NORMAL; -} diff --git a/lib/libc/gen/frexp.3 b/lib/libc/gen/frexp.3 index 2b4aae0dd6..3801832b5a 100644 --- a/lib/libc/gen/frexp.3 +++ b/lib/libc/gen/frexp.3 @@ -30,8 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)frexp.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/gen/frexp.3,v 1.13 2007/01/09 00:27:53 imp Exp $ -.\" $DragonFly: src/lib/libc/gen/frexp.3,v 1.3 2006/02/28 02:25:10 swildner Exp $ +.\" $FreeBSD: head/lib/libc/gen/frexp.3 206616 2010-04-14 18:29:34Z uqs $ .\" .Dd March 4, 2005 .Dt FREXP 3 @@ -71,7 +70,7 @@ such that is a .Vt double with magnitude in the interval -.Eo [ \(12 , 1 Ec ) +.Eo [ 1/2 , 1 Ec ) or zero, and .Fa value equals diff --git a/lib/libc/gen/frexp.c b/lib/libc/gen/frexp.c index 24e10697e5..bd9c66bd3a 100644 --- a/lib/libc/gen/frexp.c +++ b/lib/libc/gen/frexp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/frexp.c,v 1.1 2004/07/18 21:23:39 das Exp $ + * $FreeBSD: head/lib/libc/gen/frexp.c 132366 2004-07-18 21:23:39Z das $ */ #include diff --git a/lib/libc/gen/infinity.c b/lib/libc/gen/infinity.c deleted file mode 100644 index 9700101928..0000000000 --- a/lib/libc/gen/infinity.c +++ /dev/null @@ -1,16 +0,0 @@ -/* $NetBSD: infinity_ieee754.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */ -/* $DragonFly: src/lib/libc/gen/infinity.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * IEEE-compatible infinity.c -- public domain. - */ - -#include -#include - -const union __double_u __infinity = -#if BYTE_ORDER == BIG_ENDIAN - { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } }; -#else - { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; -#endif diff --git a/lib/libc/gen/infinityf.c b/lib/libc/gen/infinityf.c deleted file mode 100644 index f95f3f9ed3..0000000000 --- a/lib/libc/gen/infinityf.c +++ /dev/null @@ -1,16 +0,0 @@ -/* $NetBSD: infinityf_ieee754.c,v 1.2 2005/06/12 05:21:27 lukem Exp $ */ -/* $DragonFly: src/lib/libc/gen/infinityf.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * IEEE-compatible infinityf.c -- public domain. - */ - -#include -#include - -const union __float_u __infinityf = -#if BYTE_ORDER == BIG_ENDIAN - { { 0x7f, 0x80, 0, 0 } }; -#else - { { 0, 0, 0x80, 0x7f } }; -#endif diff --git a/lib/libc/gen/infinityl_dbl.c b/lib/libc/gen/infinityl_dbl.c deleted file mode 100644 index 6122b58554..0000000000 --- a/lib/libc/gen/infinityl_dbl.c +++ /dev/null @@ -1,22 +0,0 @@ -/* $NetBSD: infinityl_dbl_ieee754.c,v 1.1 2003/10/25 22:31:20 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/infinityl_dbl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * IEEE-compatible infinityl.c -- public domain. - * For platforms where long double == double. - */ - -#include -#include -#include - -#if LDBL_MANT_DIG != DBL_MANT_DIG -#error double / long double mismatch -#endif - -const union __long_double_u __infinityl = -#if BYTE_ORDER == BIG_ENDIAN - { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } }; -#else - { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; -#endif diff --git a/lib/libc/gen/isfinite.3 b/lib/libc/gen/isfinite.3 deleted file mode 100644 index 7e43f5c903..0000000000 --- a/lib/libc/gen/isfinite.3 +++ /dev/null @@ -1,77 +0,0 @@ -.\" $NetBSD: isfinite.3,v 1.2 2004/01/15 19:43:45 kleink Exp $ -.\" $DragonFly: src/lib/libc/gen/isfinite.3,v 1.1 2005/07/26 21:15:19 joerg Exp $ -.\" -.\" Copyright (c) 2003 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein. -.\" -.\" 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 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. -.\" -.Dd October 29, 2003 -.Dt ISFINITE 3 -.Os -.Sh NAME -.Nm isfinite -.Nd test for finite value -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn isfinite "real-floating x" -.Sh DESCRIPTION -The -.Fn isfinite -determines whether its argument -.Fa x -has a finite value. -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The determination is then based on the type of the argument. -.Sh RETURN VALUES -The -.Fn isfinite -macro returns a non-zero value if the value of -.Fa x -is finite. -Otherwise 0 is returned. -.Sh ERRORS -No errors are defined. -.Sh SEE ALSO -.Xr fpclassify 3 , -.Xr isnormal 3 , -.Xr math 3 , -.Xr signbit 3 -.Sh STANDARDS -The -.Fn isfinite -macro conforms to -.St -isoC-99 . diff --git a/lib/libc/gen/isfinited.c b/lib/libc/gen/isfinited.c deleted file mode 100644 index 6cfacd7281..0000000000 --- a/lib/libc/gen/isfinited.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: isfinited_ieee754.c,v 1.1 2003/10/29 20:03:51 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isfinited.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include - -/* - * 7.12.3.2 isfinite - determine whether an argument has finite value - * IEEE 754 double-precision version - */ -int -__isfinited(double x) -{ - union ieee_double_u u; - - u.dblu_d = x; - - if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN) - return 0; - - return 1; -} diff --git a/lib/libc/gen/isfinitef.c b/lib/libc/gen/isfinitef.c deleted file mode 100644 index 6bbbb9e147..0000000000 --- a/lib/libc/gen/isfinitef.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: isfinitef_ieee754.c,v 1.1 2003/10/29 20:03:51 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isfinitef.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include - -/* - * 7.12.3.2 isfinite - determine whether an argument has finite value - * IEEE 754 single-precision version - */ -int -__isfinitef(float x) -{ - union ieee_single_u u; - - u.sngu_f = x; - - if (u.sngu_sng.sng_exp == SNG_EXP_INFNAN) - return 0; - - return 1; -} diff --git a/lib/libc/gen/isinf.3 b/lib/libc/gen/isinf.3 deleted file mode 100644 index f046ad8f49..0000000000 --- a/lib/libc/gen/isinf.3 +++ /dev/null @@ -1,82 +0,0 @@ -.\" Copyright (c) 1991, 1993 -.\" 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. 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. -.\" -.\" @(#)isinf.3 8.2 (Berkeley) 1/29/94 -.\" $NetBSD: isinf.3,v 1.12 2004/03/04 23:47:56 wiz Exp $ -.\" $DragonFly: src/lib/libc/gen/isinf.3,v 1.4 2006/05/17 14:06:37 swildner Exp $ -.\" -.Dd March 5, 2004 -.Dt ISINF 3 -.Os -.Sh NAME -.Nm isinf -.Nd test for infinity -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn isinf "real-floating x" -.Sh DESCRIPTION -The -.Fn isinf -macro determines whether its argument -.Fa x -is an infinity (positive or negative). -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The determination is then based on the type of the argument. -.Ss IEEE 754 -It is determined whether the value of -.Fa x -is an infinity. -.Ss VAX -Infinities are not supported. -.Sh RETURN VALUES -The -.Fn isinf -macro returns a non-zero value if the value of -.Fa x -is an infinity. -Otherwise 0 is returned. -.Sh SEE ALSO -.Xr fpclassify 3 , -.Xr isfinite 3 , -.Xr isnan 3 , -.Xr isnormal 3 , -.Xr math 3 , -.Xr signbit 3 -.Rs -.%T "IEEE Standard for Binary Floating-Point Arithmetic" -.%Q ANSI -.%R Std 754-1985 -.Re -.Sh STANDARDS -The -.Fn isinf -macro conforms to -.St -isoC-99 . diff --git a/lib/libc/gen/frexp.c b/lib/libc/gen/isinf.c similarity index 70% copy from lib/libc/gen/frexp.c copy to lib/libc/gen/isinf.c index 24e10697e5..10eded14df 100644 --- a/lib/libc/gen/frexp.c +++ b/lib/libc/gen/isinf.c @@ -23,35 +23,44 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/frexp.c,v 1.1 2004/07/18 21:23:39 das Exp $ + * $FreeBSD: head/lib/libc/gen/isinf.c 131898 2004-07-10 15:52:26Z marcel $ */ #include #include "fpmath.h" -double -frexp(double d, int *ex) +/* + * XXX These routines belong in libm, but they must remain in libc for + * binary compat until we can bump libm's major version number. + */ + +__weak_reference(__isinf, isinf); + +int +__isinf(double d) { union IEEEd2bits u; u.d = d; - switch (u.bits.exp) { - case 0: /* 0 or subnormal */ - if ((u.bits.manl | u.bits.manh) == 0) { - *ex = 0; - } else { - u.d *= 0x1.0p514; - *ex = u.bits.exp - 1536; - u.bits.exp = 1022; - } - break; - case 2047: /* infinity or NaN; value of *ex is unspecified */ - break; - default: /* normal */ - *ex = u.bits.exp - 1022; - u.bits.exp = 1022; - break; - } - return (u.d); + return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0); +} + +int +__isinff(float f) +{ + union IEEEf2bits u; + + u.f = f; + return (u.bits.exp == 255 && u.bits.man == 0); +} + +int +__isinfl(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/lib/libc/gen/isinfd.c b/lib/libc/gen/isinfd.c deleted file mode 100644 index be01f0b6ba..0000000000 --- a/lib/libc/gen/isinfd.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: isinfd_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isinfd.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.3 isinf - test for infinity - * IEEE 754 double-precision version - */ -int -__isinfd(double x) -{ - union ieee_double_u u; - - u.dblu_d = x; - - return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u.dblu_dbl.dbl_frach == 0 && u.dblu_dbl.dbl_fracl == 0)); -} diff --git a/lib/libc/gen/isinff.c b/lib/libc/gen/isinff.c deleted file mode 100644 index 871cefb614..0000000000 --- a/lib/libc/gen/isinff.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: isinff_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isinff.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.3 isinf - test for infinity - * IEEE 754 single-precision version - */ -int -__isinff(float x) -{ - union ieee_single_u u; - - u.sngu_f = x; - - return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN && - u.sngu_sng.sng_frac == 0); -} diff --git a/lib/libc/gen/isnan.3 b/lib/libc/gen/isnan.3 deleted file mode 100644 index d61591878c..0000000000 --- a/lib/libc/gen/isnan.3 +++ /dev/null @@ -1,79 +0,0 @@ -.\" $NetBSD: isnan.3,v 1.2 2004/03/04 23:49:31 wiz Exp $ -.\" $DragonFly: src/lib/libc/gen/isnan.3,v 1.2 2006/05/17 14:06:37 swildner Exp $ -.\" -.\" Copyright (c) 1991, 1993 -.\" 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. 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: @(#)isinf.3 8.2 (Berkeley) 1/29/94 -.\" from: NetBSD: isinf.3,v 1.10 2003/08/07 16:42:52 agc Exp -.\" -.Dd March 5, 2004 -.Dt ISNAN 3 -.Os -.Sh NAME -.Nm isnan -.Nd test for not-a-number -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn isnan "real-floating x" -.Sh DESCRIPTION -The -.Fn isnan -macro determines whether its argument -.Fa x -is not-a-number -.Pq Dq NaN . -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The determination is then based on the type of the argument. -.Sh RETURN VALUES -The -.Fn isnan -macro returns a non-zero value if the value of -.Fa x -is a NaN. -Otherwise 0 is returned. -.Sh SEE ALSO -.Xr fpclassify 3 , -.Xr isfinite 3 , -.Xr isinf 3 , -.Xr isnormal 3 , -.Xr math 3 , -.Xr signbit 3 -.Rs -.%T "IEEE Standard for Binary Floating-Point Arithmetic" -.%Q ANSI -.%R Std 754-1985 -.Re -.Sh STANDARDS -The -.Fn isnan -macro conforms to -.St -isoC-99 . diff --git a/lib/libc/gen/frexp.c b/lib/libc/gen/isnan.c similarity index 65% copy from lib/libc/gen/frexp.c copy to lib/libc/gen/isnan.c index 24e10697e5..2a21e22cbf 100644 --- a/lib/libc/gen/frexp.c +++ b/lib/libc/gen/isnan.c @@ -23,35 +23,42 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/frexp.c,v 1.1 2004/07/18 21:23:39 das Exp $ + * $FreeBSD: head/lib/libc/gen/isnan.c 242894 2012-11-11 13:28:04Z dim $ */ #include #include "fpmath.h" -double -frexp(double d, int *ex) +/* + * XXX These routines belong in libm, but they must remain in libc for + * binary compat until we can bump libm's major version number. + * + * Note this only applies to the dynamic versions of libm and libc, so + * for the static and profiled versions we stub out the definitions. + * Otherwise you cannot link statically to libm and libc at the same + * time, when calling both functions. + */ + +#ifdef PIC +__weak_reference(__isnan, isnan); +__weak_reference(__isnanf, isnanf); + +int +__isnan(double d) { union IEEEd2bits u; u.d = d; - switch (u.bits.exp) { - case 0: /* 0 or subnormal */ - if ((u.bits.manl | u.bits.manh) == 0) { - *ex = 0; - } else { - u.d *= 0x1.0p514; - *ex = u.bits.exp - 1536; - u.bits.exp = 1022; - } - break; - case 2047: /* infinity or NaN; value of *ex is unspecified */ - break; - default: /* normal */ - *ex = u.bits.exp - 1022; - u.bits.exp = 1022; - break; - } - return (u.d); + return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); +} + +int +__isnanf(float f) +{ + union IEEEf2bits u; + + u.f = f; + return (u.bits.exp == 255 && u.bits.man != 0); } +#endif /* PIC */ diff --git a/lib/libc/gen/isnand.c b/lib/libc/gen/isnand.c deleted file mode 100644 index f5b7db7185..0000000000 --- a/lib/libc/gen/isnand.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: isnand_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isnand.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.4 isnan - test for a NaN - * IEEE 754 double-precision version - */ -int -__isnand(double x) -{ - union ieee_double_u u; - - u.dblu_d = x; - - return (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u.dblu_dbl.dbl_frach != 0 || u.dblu_dbl.dbl_fracl != 0)); -} diff --git a/lib/libc/gen/isnanf.c b/lib/libc/gen/isnanf.c deleted file mode 100644 index d34d456411..0000000000 --- a/lib/libc/gen/isnanf.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: isnanf_ieee754.c,v 1.1 2004/03/04 23:42:39 kleink Exp $ */ -/* $DragonFly: src/lib/libc/gen/isnanf.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.4 isnan - test for a NaN - * IEEE 754 single-precision version - */ -int -__isnanf(float x) -{ - union ieee_single_u u; - - u.sngu_f = x; - - return (u.sngu_sng.sng_exp == SNG_EXP_INFNAN && - u.sngu_sng.sng_frac != 0); -} diff --git a/lib/libc/gen/isnormal.3 b/lib/libc/gen/isnormal.3 deleted file mode 100644 index a71d670673..0000000000 --- a/lib/libc/gen/isnormal.3 +++ /dev/null @@ -1,77 +0,0 @@ -.\" $NetBSD: isnormal.3,v 1.2 2004/01/15 20:30:46 wiz Exp $ -.\" $DragonFly: src/lib/libc/gen/isnormal.3,v 1.1 2006/04/08 14:12:36 swildner Exp $ -.\" -.\" Copyright (c) 2003 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein. -.\" -.\" 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 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. -.\" -.Dd October 29, 2003 -.Dt ISNORMAL 3 -.Os -.Sh NAME -.Nm isnormal -.Nd test for normal value -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn isnormal "real-floating x" -.Sh DESCRIPTION -The -.Fn isnormal -macro determines whether its argument -.Fa x -has a normal value. -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The determination is then based on the type of the argument. -.Sh RETURN VALUES -The -.Fn isnormal -macro returns a non-zero value if the value of -.Fa x -is finite. -Otherwise 0 is returned. -.Sh ERRORS -No errors are defined. -.Sh SEE ALSO -.Xr fpclassify 3 , -.Xr isfinite 3 , -.Xr math 3 , -.Xr signbit 3 -.Sh STANDARDS -The -.Fn isnormal -macro conforms to -.St -isoC-99 . diff --git a/lib/libc/gen/ldexp.3 b/lib/libc/gen/ldexp.3 index 389fb75784..aebc831dbd 100644 --- a/lib/libc/gen/ldexp.3 +++ b/lib/libc/gen/ldexp.3 @@ -30,48 +30,48 @@ .\" SUCH DAMAGE. .\" .\" @(#)ldexp.3 8.2 (Berkeley) 4/19/94 -.\" $FreeBSD: src/lib/libc/gen/ldexp.3,v 1.5.2.3 2001/12/14 18:33:51 ru Exp $ -.\" $DragonFly: src/lib/libc/gen/ldexp.3,v 1.2 2003/06/17 04:26:42 dillon Exp $ +.\" $FreeBSD: head/lib/libc/gen/ldexp.3 165903 2007-01-09 00:28:16Z imp $ .\" -.Dd April 19, 1994 +.Dd March 4, 2005 .Dt LDEXP 3 .Os .Sh NAME -.Nm ldexp +.Nm ldexp , +.Nm ldexpf , +.Nm ldexpl .Nd multiply floating-point number by integral power of 2 .Sh LIBRARY -.Lb libc +.Lb libm .Sh SYNOPSIS .In math.h .Ft double .Fn ldexp "double x" "int exp" +.Ft float +.Fn ldexpf "float x" "int exp" +.Ft long double +.Fn ldexpl "long double x" "int exp" .Sh DESCRIPTION The -.Fn ldexp -function multiplies a floating-point number by an integral +.Fn ldexp , +.Fn ldexpf , +and +.Fn ldexpl +functions multiply a floating-point number by an integral power of 2. .Sh RETURN VALUES -The -.Fn ldexp -function returns the value of +These functions return the value of .Fa x times 2 raised to the power .Fa exp . -.Pp -If the resultant value would cause an overflow, -the global variable -.Va errno -is set to -.Er ERANGE -and the value -.Dv HUGE -is returned. .Sh SEE ALSO .Xr frexp 3 , .Xr math 3 , .Xr modf 3 .Sh STANDARDS The -.Fn ldexp -function conforms to -.St -isoC . +.Fn ldexp , +.Fn ldexpf , +and +.Fn ldexpl +functions conform to +.St -isoC-99 . diff --git a/lib/libc/gen/ldexp.c b/lib/libc/gen/ldexp.c new file mode 100644 index 0000000000..87d3dd8ab0 --- /dev/null +++ b/lib/libc/gen/ldexp.c @@ -0,0 +1,121 @@ +/* @(#)s_scalbn.c 5.1 93/09/24 */ +/* @(#)fdlibm.h 5.1 93/09/24 */ +/* $FreeBSD: head/lib/libc/gen/ldexp.c 140607 2005-01-22 06:03:40Z 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 +#include +#include + +/* Bit fiddling routines copied from msun/src/math_private.h,v 1.15 */ + +#if BYTE_ORDER == BIG_ENDIAN + +typedef union +{ + double value; + struct + { + u_int32_t msw; + u_int32_t lsw; + } parts; +} ieee_double_shape_type; + +#endif + +#if BYTE_ORDER == LITTLE_ENDIAN + +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) + +/* 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) + + +static const double +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ +huge = 1.0e+300, +tiny = 1.0e-300; + +static double +_copysign(double x, double y) +{ + u_int32_t hx,hy; + GET_HIGH_WORD(hx,x); + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); + return x; +} + +double +ldexp(double x, int n) +{ + int32_t k,hx,lx; + EXTRACT_WORDS(hx,lx,x); + k = (hx&0x7ff00000)>>20; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx&0x7ff00000)>>20) - 54; + if (n< -50000) return tiny*x; /*underflow*/ + } + if (k==0x7ff) return x+x; /* NaN or Inf */ + k = k+n; + if (k > 0x7fe) return huge*_copysign(huge,x); /* overflow */ + if (k > 0) /* normal result */ + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} + if (k <= -54) { + if (n > 50000) /* in case integer overflow in n+k */ + return huge*_copysign(huge,x); /*overflow*/ + else return tiny*_copysign(tiny,x); /*underflow*/ + } + k += 54; /* subnormal result */ + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + return x*twom54; +} diff --git a/lib/libc/gen/modf.3 b/lib/libc/gen/modf.3 index 692d2a37e7..7f662c0c3a 100644 --- a/lib/libc/gen/modf.3 +++ b/lib/libc/gen/modf.3 @@ -30,36 +30,42 @@ .\" SUCH DAMAGE. .\" .\" @(#)modf.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/gen/modf.3,v 1.3.2.4 2003/03/13 18:05:37 trhodes Exp $ -.\" $DragonFly: src/lib/libc/gen/modf.3,v 1.2 2003/06/17 04:26:42 dillon Exp $ +.\" $FreeBSD: head/lib/libc/gen/modf.3 177710 2008-03-29 16:19:35Z das $ .\" -.Dd June 4, 1993 +.Dd March 29, 2008 .Dt MODF 3 .Os .Sh NAME -.Nm modf +.Nm modf , +.Nm modff , +.Nm modfl .Nd extract signed integral and fractional values from floating-point number .Sh LIBRARY -.Lb libc +.Lb libm .Sh SYNOPSIS .In math.h .Ft double .Fn modf "double value" "double *iptr" +.Ft float +.Fn modff "float value" "float *iptr" +.Ft long double +.Fn modfl "long double value" "long double *iptr" .Sh DESCRIPTION The -.Fn modf -function breaks the argument +.Fn modf , +.Fn modff , +and +.Fn modfl +functions break the argument .Fa value into integral and fractional parts, each of which has the same sign as the argument. It stores the integral part as a -.Vt double +floating point number in the object pointed to by .Fa iptr . .Sh RETURN VALUES -The -.Fn modf -function returns the signed fractional part of +These functions return the signed fractional part of .Fa value . .Sh SEE ALSO .Xr frexp 3 , @@ -67,6 +73,9 @@ function returns the signed fractional part of .Xr math 3 .Sh STANDARDS The -.Fn modf -function conforms to -.St -isoC . +.Fn modf , +.Fn modff , +and +.Fn modfl +functions conform to +.St -isoC-99 . diff --git a/lib/libm/src/s_modf.c b/lib/libc/gen/modf.c similarity index 60% copy from lib/libm/src/s_modf.c copy to lib/libc/gen/modf.c index aab8d0a19e..4e1b80599b 100644 --- a/lib/libm/src/s_modf.c +++ b/lib/libc/gen/modf.c @@ -1,4 +1,5 @@ /* @(#)s_modf.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/libc/gen/modf.c 226606 2011-10-21 06:40:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 165838 (2007-01-06) */ /* @@ -22,8 +21,68 @@ * No exception. */ +#include +#include #include -#include "math_private.h" + +/* Bit fiddling routines copied from msun/src/math_private.h,v 1.15 */ + +#if BYTE_ORDER == BIG_ENDIAN + +typedef union +{ + double value; + struct + { + u_int32_t msw; + u_int32_t lsw; + } parts; +} ieee_double_shape_type; + +#endif + +#if BYTE_ORDER == LITTLE_ENDIAN + +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) + +/* 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) static const double one = 1.0; diff --git a/lib/libc/gen/signbit.3 b/lib/libc/gen/signbit.3 deleted file mode 100644 index a8ecf93a2d..0000000000 --- a/lib/libc/gen/signbit.3 +++ /dev/null @@ -1,77 +0,0 @@ -.\" $NetBSD: signbit.3,v 1.2 2004/01/15 20:31:40 wiz Exp $ -.\" $DragonFly: src/lib/libc/gen/signbit.3,v 1.1 2005/07/26 21:15:19 joerg Exp $ -.\" -.\" Copyright (c) 2003 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein. -.\" -.\" 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 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. -.\" -.Dd October 29, 2003 -.Dt SIGNBIT 3 -.Os -.Sh NAME -.Nm signbit -.Nd test sign -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn signbit "real-floating x" -.Sh DESCRIPTION -The -.Fn signbit -macro determines whether the sign of its argument value -.Fa x -is negative. -An argument represented in a format wider than its semantic type is -converted to its semantic type first. -The determination is then based on the type of the argument. -.Sh RETURN VALUES -The -.Fn signbit -macro returns a non-zero value if the sign of its value -.Fa x -is negative. -Otherwise 0 is returned. -.Sh ERRORS -No errors are defined. -.Sh SEE ALSO -.Xr fpclassify 3 , -.Xr isfinite 3 , -.Xr isnormal 3 , -.Xr math 3 -.Sh STANDARDS -The -.Fn signbit -macro conforms to -.St -isoC-99 . diff --git a/lib/libc/gen/signbitd.c b/lib/libc/gen/signbitd.c deleted file mode 100644 index 9110a65382..0000000000 --- a/lib/libc/gen/signbitd.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - * - * $NetBSD: signbitd_ieee754.c,v 1.1 2004/01/15 19:43:45 kleink Exp $ - * $DragonFly: src/lib/libc/gen/signbitd.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include -#include - -/* - * 7.12.3.6 signbit - determine whether the sign of an argument is negative - * IEEE 754 double-precision version - */ -int -__signbitd(double x) -{ - union ieee_double_u u; - - u.dblu_d = x; - - return (u.dblu_dbl.dbl_sign == 1); -} diff --git a/lib/libc/gen/signbitf.c b/lib/libc/gen/signbitf.c deleted file mode 100644 index 4f8b69e258..0000000000 --- a/lib/libc/gen/signbitf.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - * - * $NetBSD: signbitf_ieee754.c,v 1.1 2004/01/15 19:43:45 kleink Exp $ - * $DragonFly: src/lib/libc/gen/signbitf.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include -#include - -/* - * 7.12.3.6 signbit - determine whether the sign of an argument is negative - * IEEE 754 single-precision version - */ -int -__signbitf(float x) -{ - union ieee_single_u u; - - u.sngu_f = x; - - return (u.sngu_sng.sng_sign == 1); -} diff --git a/lib/libc/i386/gen/Makefile.inc b/lib/libc/i386/gen/Makefile.inc index 9d0fbbd1e9..3c29621964 100644 --- a/lib/libc/i386/gen/Makefile.inc +++ b/lib/libc/i386/gen/Makefile.inc @@ -1,10 +1,8 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 # $FreeBSD: src/lib/libc/i386/gen/Makefile.inc,v 1.10.2.1 2001/02/07 00:12:45 peter Exp $ -SRCS+= fpclassifyl.c infinityl.c isfinitel.c isinfl.c isnanl.c \ - ldexp.c makecontext.c nanf.c signbitl.c \ - _ctx_start.S _setjmp.S alloca.S fabs.S flt_rounds.S fpgetmask.S \ - fpgetround.S \ - fpgetsticky.S fpsetmask.S fpsetround.S fpsetsticky.S mcontext.S modf.S \ +SRCS+= fabs.S flt_rounds.c infinity.c \ + makecontext.c \ + _ctx_start.S _setjmp.S alloca.S \ + mcontext.S \ rfork_thread.S setjmp.S sigsetjmp.S - diff --git a/lib/libc/i386/gen/fabs.S b/lib/libc/i386/gen/fabs.S index a86a5b788d..a91d9767a4 100644 --- a/lib/libc/i386/gen/fabs.S +++ b/lib/libc/i386/gen/fabs.S @@ -13,10 +13,6 @@ * 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. @@ -33,13 +29,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/i386/gen/fabs.S,v 1.5 1999/08/27 23:59:20 peter Exp $ - * $DragonFly: src/lib/libc/i386/gen/fabs.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ + * @(#)fabs.s 5.2 (Berkeley) 12/17/90 + * $FreeBSD: head/lib/libc/i386/gen/fabs.S 217106 2011-01-07 16:08:40Z kib $ */ -#include "DEFS.h" +#include ENTRY(fabs) fldl 4(%esp) fabs ret +END(fabs) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/i386/gen/flt_rounds.S b/lib/libc/i386/gen/flt_rounds.S deleted file mode 100644 index 4f49c3e370..0000000000 --- a/lib/libc/i386/gen/flt_rounds.S +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * - * $NetBSD: flt_rounds.S,v 1.6 1999/08/23 08:45:09 kleink Exp $ - * $DragonFly: src/lib/libc/i386/gen/flt_rounds.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -_START_ENTRY -_map: - .byte 1 /* round to nearest */ - .byte 3 /* round to negative infinity */ - .byte 2 /* round to positive infinity */ - .byte 0 /* round to zero */ - -ENTRY(__flt_rounds) - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - shrl $10,%eax - andl $3,%eax -#ifdef PIC - PIC_PROLOGUE - leal PIC_GOTOFF(_map),%ecx - PIC_EPILOGUE - movb (%ecx,%eax,1),%al -#else - movb _map(,%eax,1),%al -#endif - addl $4,%esp - ret diff --git a/lib/libc/x86_64/gen/flt_rounds.c b/lib/libc/i386/gen/flt_rounds.c similarity index 72% copy from lib/libc/x86_64/gen/flt_rounds.c copy to lib/libc/i386/gen/flt_rounds.c index cd7e501af5..b965e5d507 100644 --- a/lib/libc/x86_64/gen/flt_rounds.c +++ b/lib/libc/i386/gen/flt_rounds.c @@ -1,6 +1,8 @@ /* * Written by J.T. Conklin, Apr 10, 1995 * Public domain. + * + * $FreeBSD: head/lib/libc/i386/gen/flt_rounds.c 132383 2004-07-19 08:17:25Z das $ */ #include @@ -17,7 +19,6 @@ __flt_rounds(void) { int x; - /* Assume that the x87 and the SSE unit agree on the rounding mode. */ __asm("fnstcw %0" : "=m" (x)); - return (map[(x >> 10) & 0x03]); + return (map[(x >> 10) & 0x03]); } diff --git a/lib/libc/i386/gen/fpclassifyl.c b/lib/libc/i386/gen/fpclassifyl.c deleted file mode 100644 index c39106ca3f..0000000000 --- a/lib/libc/i386/gen/fpclassifyl.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $NetBSD: fpclassifyl.c,v 1.1 2003/10/28 22:05:37 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/fpclassifyl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include -#include - -/* - * 7.12.3.1 fpclassify - classify real floating type - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__fpclassifyl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - _DIAGASSERT(u.extu_ext.ext_exp == 0 || u.extu_ext.ext_int == 1); - - if (u.extu_ext.ext_exp == 0) { - if (u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0) - return FP_ZERO; - else - return FP_SUBNORMAL; - } else if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) { - if (u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0) - return FP_INFINITE; - else - return FP_NAN; - } - - return FP_NORMAL; -} diff --git a/lib/libc/i386/gen/fpgetmask.S b/lib/libc/i386/gen/fpgetmask.S deleted file mode 100644 index aa9c432c0a..0000000000 --- a/lib/libc/i386/gen/fpgetmask.S +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * - * $NetBSD: fpgetmask.S,v 1.4 2002/01/13 21:45:42 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpgetmask.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetmask, _fpgetmask) -ENTRY(_fpgetmask) -#else -ENTRY(fpgetmask) -#endif - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - notl %eax - andl $63,%eax - addl $4,%esp - ret diff --git a/lib/libc/i386/gen/fpgetround.S b/lib/libc/i386/gen/fpgetround.S deleted file mode 100644 index 3a7f9a7a98..0000000000 --- a/lib/libc/i386/gen/fpgetround.S +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * - * $NetBSD: fpgetround.S,v 1.5 2002/01/13 21:45:43 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpgetround.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetround, _fpgetround) -ENTRY(_fpgetround) -#else -ENTRY(fpgetround) -#endif - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - rorl $10,%eax - andl $3,%eax - addl $4,%esp - ret diff --git a/lib/libc/i386/gen/fpgetsticky.S b/lib/libc/i386/gen/fpgetsticky.S deleted file mode 100644 index a6285dc0ae..0000000000 --- a/lib/libc/i386/gen/fpgetsticky.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * $NetBSD: fpgetsticky.S,v 1.6 2002/01/13 21:45:43 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpgetsticky.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetsticky, _fpgetsticky) -ENTRY(_fpgetsticky) -#else -ENTRY(fpgetsticky) -#endif - subl $4,%esp - fnstsw (%esp) - movl (%esp),%eax - andl $63,%eax - addl $4,%esp - ret diff --git a/lib/libc/i386/gen/fpsetmask.S b/lib/libc/i386/gen/fpsetmask.S deleted file mode 100644 index ad8278c1f0..0000000000 --- a/lib/libc/i386/gen/fpsetmask.S +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Written by Charles M. Hannum, Apr 9, 1995 - * Public domain. - * - * $NetBSD: fpsetmask.S,v 1.4 2002/01/13 21:45:43 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpsetmask.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetmask, _fpsetmask) -ENTRY(_fpsetmask) -#else -ENTRY(fpsetmask) -#endif - subl $4,%esp - - fnstcw (%esp) - movl (%esp),%eax - movl %eax,%edx - - notl %eax - andl $63,%eax - - addl %eax,%edx - movl 8(%esp),%ecx - andl $63,%ecx - subl %ecx,%edx - movl %edx,(%esp) - fldcw (%esp) - - addl $4,%esp - ret diff --git a/lib/libc/i386/gen/fpsetround.S b/lib/libc/i386/gen/fpsetround.S deleted file mode 100644 index 24f63d807d..0000000000 --- a/lib/libc/i386/gen/fpsetround.S +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Written by Charles M. Hannum, Apr 9, 1995 - * Public domain. - * - * $NetBSD: fpsetround.S,v 1.3 2002/01/13 21:45:43 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpsetround.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetround, _fpsetround) -ENTRY(_fpsetround) -#else -ENTRY(fpsetround) -#endif - subl $4,%esp - - fnstcw (%esp) - movl (%esp),%eax - - rorl $10,%eax - movl %eax,%edx - andl $3,%eax - - subl %eax,%edx - movl 8(%esp),%ecx - andl $3,%ecx - orl %ecx,%edx - roll $10,%edx - movl %edx,(%esp) - fldcw (%esp) - - addl $4,%esp - ret diff --git a/lib/libc/i386/gen/fpsetsticky.S b/lib/libc/i386/gen/fpsetsticky.S deleted file mode 100644 index 58b7b7ecff..0000000000 --- a/lib/libc/i386/gen/fpsetsticky.S +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Written by Charles M. Hannum, Apr 9, 1995 - * Public domain. - * - * $NetBSD: fpsetsticky.S,v 1.6 2002/01/13 21:45:43 thorpej Exp $ - * $DragonFly: src/lib/libc/i386/gen/fpsetsticky.S,v 1.1 2005/07/26 21:15:19 joerg Exp $ - */ - -#include - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetsticky, _fpsetsticky) -ENTRY(_fpsetsticky) -#else -ENTRY(fpsetsticky) -#endif - subl $28,%esp - - fnstenv (%esp) - movl 4(%esp),%eax - movl %eax,%edx - - andl $63,%eax - - subl %eax,%edx - movl 32(%esp),%ecx - andl $63,%ecx - addl %ecx,%edx - movl %edx,4(%esp) - fldenv (%esp) - - addl $28,%esp - ret diff --git a/lib/libc/i386/gen/infinity.c b/lib/libc/i386/gen/infinity.c new file mode 100644 index 0000000000..cd765b9d0b --- /dev/null +++ b/lib/libc/i386/gen/infinity.c @@ -0,0 +1,12 @@ +/* + * infinity.c + * $FreeBSD: head/lib/libc/i386/gen/infinity.c 110566 2003-02-08 20:37:55Z mike $ + */ + +#include + +/* bytes for +Infinity on a 387 */ +const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; + +/* bytes for NaN */ +const union __nan_un __nan = { { 0, 0, 0xc0, 0xff } }; diff --git a/lib/libc/i386/gen/infinityl.c b/lib/libc/i386/gen/infinityl.c deleted file mode 100644 index 08b868bf94..0000000000 --- a/lib/libc/i386/gen/infinityl.c +++ /dev/null @@ -1,12 +0,0 @@ -/* $NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:26 lukem Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/infinityl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * IEEE-compatible infinityl.c for little-endian 80-bit format -- public domain. - * Note that the representation includes 16 bits of tail padding per i386 ABI. - */ - -#include - -const union __long_double_u __infinityl = - { { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f, 0, 0 } }; diff --git a/lib/libc/i386/gen/isfinitel.c b/lib/libc/i386/gen/isfinitel.c deleted file mode 100644 index a6c09a065f..0000000000 --- a/lib/libc/i386/gen/isfinitel.c +++ /dev/null @@ -1,61 +0,0 @@ -/* $NetBSD: isfinitel.c,v 1.1 2003/10/29 20:03:51 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/isfinitel.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include -#include - -/* - * 7.12.3.2 isfinite - determine whether an argument has finite value - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isfinitel(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - _DIAGASSERT(u.extu_ext.ext_exp == 0 || u.extu_ext.ext_int == 1); - - if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) - return 0; - - return 1; -} diff --git a/lib/libc/i386/gen/isinfl.c b/lib/libc/i386/gen/isinfl.c deleted file mode 100644 index 4482c45a01..0000000000 --- a/lib/libc/i386/gen/isinfl.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: isinfl.c,v 1.5 2004/03/04 23:42:38 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/isinfl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.3 isinf - test for infinity - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isinfl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_exp == EXT_EXP_INFNAN && - (u.extu_ext.ext_int == 1 && - u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0)); -} diff --git a/lib/libc/i386/gen/isnanl.c b/lib/libc/i386/gen/isnanl.c deleted file mode 100644 index ca5e9300b4..0000000000 --- a/lib/libc/i386/gen/isnanl.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: isnanl.c,v 1.5 2004/03/04 23:42:38 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/isnanl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - */ - -#include -#include - -/* - * 7.12.3.4 isnan - test for a NaN - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isnanl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_exp == EXT_EXP_INFNAN && - u.extu_ext.ext_int == 1 && - (u.extu_ext.ext_frach != 0 || u.extu_ext.ext_fracl != 0)); -} diff --git a/lib/libc/i386/gen/ldexp.c b/lib/libc/i386/gen/ldexp.c deleted file mode 100644 index 0b00bab8fa..0000000000 --- a/lib/libc/i386/gen/ldexp.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan. - * - * 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. - * - * $FreeBSD: src/lib/libc/i386/gen/ldexp.c,v 1.6 1999/08/27 23:59:21 peter Exp $ - * $DragonFly: src/lib/libc/i386/gen/ldexp.c,v 1.5 2005/11/20 09:18:36 swildner Exp $ - */ - -#include - -/* - * ldexp(value, exp): return value * (2 ** exp). - * - * Written by Sean Eric Fagan (sef@kithrup.COM) - * Sun Mar 11 20:27:09 PST 1990 - */ - -/* - * We do the conversion in C to let gcc optimize it away, if possible. - * The "fxch ; fstp" stuff is because value is still on the stack - * (stupid 8087!). - */ -double -ldexp (double value, int expo) -{ - double temp; -#ifdef __GNUC__ - __asm ("fscale" - : "=t" (temp) - : "0" (value), "u" ((double)expo)); -#else -#error "Compiler not supported" -#endif - return (temp); -} diff --git a/lib/libc/i386/gen/modf.S b/lib/libc/i386/gen/modf.S deleted file mode 100644 index 98d44a7156..0000000000 --- a/lib/libc/i386/gen/modf.S +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan. - * - * 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. - * - * $FreeBSD: src/lib/libc/i386/gen/modf.S,v 1.6 1999/08/27 23:59:22 peter Exp $ - * $DragonFly: src/lib/libc/i386/gen/modf.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ - */ - -/* - * modf(value, iptr): return fractional part of value, and stores the - * integral part into iptr (a pointer to double). - * - * Written by Sean Eric Fagan (sef@kithrup.COM) - * Sun Mar 11 20:27:30 PST 1990 - */ - -/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ - -#include "DEFS.h" - -ENTRY(modf) - pushl %ebp - movl %esp,%ebp - subl $16,%esp - fnstcw -12(%ebp) - movw -12(%ebp),%dx - orw $3072,%dx - movw %dx,-16(%ebp) - fldcw -16(%ebp) - fldl 8(%ebp) - frndint - fstpl -8(%ebp) - fldcw -12(%ebp) - movl 16(%ebp),%eax - movl -8(%ebp),%edx - movl -4(%ebp),%ecx - movl %edx,(%eax) - movl %ecx,4(%eax) - fldl 8(%ebp) - fsubl -8(%ebp) - jmp L1 -L1: - leave - ret diff --git a/lib/libc/i386/gen/nanf.c b/lib/libc/i386/gen/nanf.c deleted file mode 100644 index 730b6d95e6..0000000000 --- a/lib/libc/i386/gen/nanf.c +++ /dev/null @@ -1,9 +0,0 @@ -/* $NetBSD: nanf.c,v 1.3 2005/04/15 22:39:11 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/nanf.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -#include -#include - -/* bytes for quiet NaN (IEEE single precision) */ -const union __float_u __nanf = - { { 0, 0, 0xc0, 0x7f } }; diff --git a/lib/libc/i386/gen/signbitl.c b/lib/libc/i386/gen/signbitl.c deleted file mode 100644 index ba5ede6c31..0000000000 --- a/lib/libc/i386/gen/signbitl.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: signbitl.c,v 1.1 2004/01/15 19:43:45 kleink Exp $ */ -/* $DragonFly: src/lib/libc/i386/gen/signbitl.c,v 1.1 2005/07/26 21:15:19 joerg Exp $ */ - -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - */ - -#include -#include - -/* - * 7.12.3.6 signbit - determine whether the sign of an argument is negative - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__signbitl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_sign == 1); -} diff --git a/lib/libc/x86_64/gen/Makefile.inc b/lib/libc/x86_64/gen/Makefile.inc index f379caa076..3338f21f8e 100644 --- a/lib/libc/x86_64/gen/Makefile.inc +++ b/lib/libc/x86_64/gen/Makefile.inc @@ -2,9 +2,6 @@ # $FreeBSD: src/lib/libc/amd64/gen/Makefile.inc,v 1.24 2003/10/13 20:32:33 alc Exp $ SRCS+= _setjmp.S rfork_thread.S setjmp.S sigsetjmp.S \ - fabs.S modf.S mcontext.S\ - fpclassifyl.c nanf.c signbitl.c flt_rounds.c \ - infinityl.c isinfl.c isfinitel.c isnanl.c \ - ldexp.c makecontext.c \ - fpgetmask.S fpsetmask.S fpgetround.S fpsetround.S \ - fpgetsticky.S fpsetsticky.S + mcontext.S makecontext.c \ + fabs.S flt_rounds.c fpgetmask.c fpgetprec.c fpgetround.c \ + fpgetsticky.c fpsetmask.c fpsetprec.c fpsetround.c infinity.c diff --git a/lib/libc/x86_64/gen/fabs.S b/lib/libc/x86_64/gen/fabs.S index 171e3e0cb4..fd8feffe1c 100644 --- a/lib/libc/x86_64/gen/fabs.S +++ b/lib/libc/x86_64/gen/fabs.S @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/amd64/gen/fabs.S,v 1.4 2008/11/02 01:10:54 peter Exp $ + * $FreeBSD: head/lib/libc/amd64/gen/fabs.S 217106 2011-01-07 16:08:40Z kib $ */ #include @@ -43,3 +43,5 @@ END(fabs) .data signbit: .quad 0x8000000000000000 + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libc/x86_64/gen/flt_rounds.c b/lib/libc/x86_64/gen/flt_rounds.c index cd7e501af5..d24a47005b 100644 --- a/lib/libc/x86_64/gen/flt_rounds.c +++ b/lib/libc/x86_64/gen/flt_rounds.c @@ -1,6 +1,8 @@ /* * Written by J.T. Conklin, Apr 10, 1995 * Public domain. + * + * $FreeBSD: head/lib/libc/amd64/gen/flt_rounds.c 132383 2004-07-19 08:17:25Z das $ */ #include @@ -17,7 +19,7 @@ __flt_rounds(void) { int x; - /* Assume that the x87 and the SSE unit agree on the rounding mode. */ + /* Assume that the x87 and the SSE unit agree on the rounding mode. */ __asm("fnstcw %0" : "=m" (x)); - return (map[(x >> 10) & 0x03]); + return (map[(x >> 10) & 0x03]); } diff --git a/lib/libc/x86_64/gen/fpclassifyl.c b/lib/libc/x86_64/gen/fpclassifyl.c deleted file mode 100644 index b235c7e41e..0000000000 --- a/lib/libc/x86_64/gen/fpclassifyl.c +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - * - * $NetBSD: fpclassifyl.c,v 1.2 2004/01/18 19:33:01 matt Exp $ - */ - -#include -#include -#include - -/* - * 7.12.3.1 fpclassify - classify real floating type - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__fpclassifyl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - _DIAGASSERT(u.extu_ext.ext_exp == 0 || u.extu_ext.ext_int == 1); - - if (u.extu_ext.ext_exp == 0) { - if (u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0) - return FP_ZERO; - else - return FP_SUBNORMAL; - } else if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) { - if (u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0) - return FP_INFINITE; - else - return FP_NAN; - } - - return FP_NORMAL; -} diff --git a/lib/libc/x86_64/gen/fpgetmask.S b/lib/libc/x86_64/gen/fpgetmask.S deleted file mode 100644 index 589818ebbd..0000000000 --- a/lib/libc/x86_64/gen/fpgetmask.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * - * $NetBSD: fpgetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ - */ - -#include - -/* - * XXX only read x87 control word here. If an application only - * uses the fp* interface to manipulate FP bits, it should - * always remain in sync with the SSE mxcsr register. - */ - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetmask, _fpgetmask) -ENTRY(_fpgetmask) -#else -ENTRY(fpgetmask) -#endif - fnstcw -4(%rsp) - movl -4(%rsp),%eax - notl %eax - andl $63,%eax - ret diff --git a/lib/libc/x86_64/gen/fpgetmask.c b/lib/libc/x86_64/gen/fpgetmask.c new file mode 100644 index 0000000000..bae64a3bda --- /dev/null +++ b/lib/libc/x86_64/gen/fpgetmask.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpgetmask.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_except_t fpgetmask(void) +{ + return __fpgetmask(); +} diff --git a/lib/libc/x86_64/gen/fpgetprec.c b/lib/libc/x86_64/gen/fpgetprec.c new file mode 100644 index 0000000000..8565d0e8f3 --- /dev/null +++ b/lib/libc/x86_64/gen/fpgetprec.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpgetprec.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_prec_t fpgetprec(void) +{ + return __fpgetprec(); +} diff --git a/lib/libc/x86_64/gen/fpgetround.S b/lib/libc/x86_64/gen/fpgetround.S deleted file mode 100644 index 1a0885012e..0000000000 --- a/lib/libc/x86_64/gen/fpgetround.S +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - * - * $NetBSD: fpgetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ - */ - -#include - -/* - * XXX store only x87 state. If an application only uses the fp* - * interface, this should be in sync with the SSE mxcsr register. - */ - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetround, _fpgetround) -ENTRY(_fpgetround) -#else -ENTRY(fpgetround) -#endif - fnstcw -4(%rsp) - movl -4(%rsp),%eax - rorl $10,%eax - andl $3,%eax - ret diff --git a/lib/libc/x86_64/gen/fpgetround.c b/lib/libc/x86_64/gen/fpgetround.c new file mode 100644 index 0000000000..26feee4445 --- /dev/null +++ b/lib/libc/x86_64/gen/fpgetround.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpgetround.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_rnd_t fpgetround(void) +{ + return __fpgetround(); +} diff --git a/lib/libc/x86_64/gen/fpgetsticky.S b/lib/libc/x86_64/gen/fpgetsticky.S deleted file mode 100644 index 76ffeb36a5..0000000000 --- a/lib/libc/x86_64/gen/fpgetsticky.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Written by Frank van der Linden at Wasabi Systems for NetBSD. - * Public domain. - * - * $NetBSD: fpgetsticky.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ - */ - -#include - -/* - * XXX read both the x87 and SSE status words here, and OR - * them to get a complete picture of exceptions. - */ - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpgetsticky, _fpgetsticky) -ENTRY(_fpgetsticky) -#else -ENTRY(fpgetsticky) -#endif - fnstsw -4(%rsp) - stmxcsr -8(%rsp) - movl -4(%rsp),%eax - orl -8(%rsp),%eax - andl $63,%eax - ret diff --git a/lib/libc/x86_64/gen/fpgetsticky.c b/lib/libc/x86_64/gen/fpgetsticky.c new file mode 100644 index 0000000000..65987735ae --- /dev/null +++ b/lib/libc/x86_64/gen/fpgetsticky.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpgetsticky.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_except_t fpgetsticky(void) +{ + return __fpgetsticky(); +} diff --git a/lib/libc/x86_64/gen/fpsetmask.S b/lib/libc/x86_64/gen/fpsetmask.S deleted file mode 100644 index 42476f9197..0000000000 --- a/lib/libc/x86_64/gen/fpsetmask.S +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Written by Frank van der Linden at Wasabi Systems for NetBSD. - * Public domain. - * - * $NetBSD: fpsetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ - */ - -#include - -/* - * XXX set both the x87 control word and the SSE mxcsr register. - * Applications should only set exception and round flags - * via the fp*() interface, otherwise the status words - * will get our of sync. - */ - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetmask, _fpsetmask) -ENTRY(_fpsetmask) -#else -ENTRY(fpsetmask) -#endif - fnstcw -4(%rsp) - stmxcsr -8(%rsp) - andl $63,%edi - notl %edi - - movl -4(%rsp),%edx - movl %edx,%eax - andl %edi,%edx - movl %edx,-4(%rsp) - - movl -8(%rsp),%edx - roll $7,%edi - andl %edi,%edx - movl %edx,-8(%rsp) - - fldcw -4(%rsp) - ldmxcsr -8(%rsp) - andl $63,%eax - ret diff --git a/lib/libc/x86_64/gen/fpsetmask.c b/lib/libc/x86_64/gen/fpsetmask.c new file mode 100644 index 0000000000..6660d29b5e --- /dev/null +++ b/lib/libc/x86_64/gen/fpsetmask.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpsetmask.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_except_t fpsetmask(fp_except_t m) +{ + return (__fpsetmask(m)); +} diff --git a/lib/libc/x86_64/gen/fpsetprec.c b/lib/libc/x86_64/gen/fpsetprec.c new file mode 100644 index 0000000000..d144952c5a --- /dev/null +++ b/lib/libc/x86_64/gen/fpsetprec.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpsetprec.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_prec_t fpsetprec(fp_prec_t m) +{ + return (__fpsetprec(m)); +} diff --git a/lib/libc/x86_64/gen/fpsetround.S b/lib/libc/x86_64/gen/fpsetround.S deleted file mode 100644 index 43d7e5045d..0000000000 --- a/lib/libc/x86_64/gen/fpsetround.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Written by Frank van der Linden at Wasabi Systems for NetBSD. - * Public domain. - * - * $NetBSD: fpsetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ - */ - -#include - -/* - * XXX set both the x87 control word and the SSE mxcsr register. - * Applications should only set exception and round flags - * via the fp*() interface, otherwise the status words - * will get our of sync. - */ - - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetround, _fpsetround) -ENTRY(_fpsetround) -#else -ENTRY(fpsetround) -#endif - fnstcw -4(%rsp) - stmxcsr -8(%rsp) - - andl $3,%edi - - movl -4(%rsp),%edx - rorl $10,%edx - movl %edx,%eax - andl $3,%eax - - andl $~3,%edx - orl %edi,%edx - roll $10,%edx - movl %edx,-4(%rsp) - - movl -8(%rsp),%edx - rorl $13,%edx - andl $~3,%edx - orl %edi,%edx - roll $13,%edx - movl %edx,-8(%rsp) - - ldmxcsr -8(%rsp) - fldcw -4(%rsp) - ret diff --git a/lib/libc/x86_64/gen/fpsetround.c b/lib/libc/x86_64/gen/fpsetround.c new file mode 100644 index 0000000000..d9639103c6 --- /dev/null +++ b/lib/libc/x86_64/gen/fpsetround.c @@ -0,0 +1,8 @@ +/* $FreeBSD: head/lib/libc/amd64/gen/fpsetround.c 117864 2003-07-22 06:46:17Z peter $ */ +#define __IEEEFP_NOINLINES__ 1 +#include + +fp_rnd_t fpsetround(fp_rnd_t m) +{ + return (__fpsetround(m)); +} diff --git a/lib/libc/x86_64/gen/fpsetsticky.S b/lib/libc/x86_64/gen/fpsetsticky.S deleted file mode 100644 index 1659045cf7..0000000000 --- a/lib/libc/x86_64/gen/fpsetsticky.S +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Written by Frank van der Linden at Wasabi Systems for NetBSD - * Public domain. - * - * $NetBSD: fpsetsticky.S,v 1.5 2004/03/09 17:16:13 drochner Exp $ - */ - -#include - -/* - * XXX set both the x87 status word and the SSE mxcsr register. - * Applications should only set exception and round flags - * via the fp*() interface, otherwise the status words - * will get our of sync. - */ - - -#ifdef WEAK_ALIAS -WEAK_ALIAS(fpsetsticky, _fpsetsticky) -ENTRY(_fpsetsticky) -#else -ENTRY(fpsetsticky) -#endif - fnstenv -28(%rsp) - stmxcsr -32(%rsp) - - andl $63,%edi - - movl -24(%rsp),%eax - movl %eax,%edx - andb $0xc0,%dl - - orl %edi,%edx - movl %edx,-24(%rsp) - - movl -32(%rsp),%edx - orl %edx,%eax - andl $63,%eax - andb $0xc0,%dl - orl %edi,%edx - movl %edx,-32(%rsp) - - ldmxcsr -32(%rsp) - fldenv -28(%rsp) - ret diff --git a/lib/libc/x86_64/gen/infinity.c b/lib/libc/x86_64/gen/infinity.c new file mode 100644 index 0000000000..561f1a89ce --- /dev/null +++ b/lib/libc/x86_64/gen/infinity.c @@ -0,0 +1,12 @@ +/* + * infinity.c + * $FreeBSD: head/lib/libc/amd64/gen/infinity.c 110566 2003-02-08 20:37:55Z mike $ + */ + +#include + +/* bytes for +Infinity on a 387 */ +const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; + +/* bytes for NaN */ +const union __nan_un __nan = { { 0, 0, 0xc0, 0xff } }; diff --git a/lib/libc/x86_64/gen/infinityl.c b/lib/libc/x86_64/gen/infinityl.c deleted file mode 100644 index d31464e59f..0000000000 --- a/lib/libc/x86_64/gen/infinityl.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * IEEE-compatible infinityl.c for little-endian 80-bit format -- public domain. - * Note that the representation includes 48 bits of tail padding per x86_64 ABI. - * - * $NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:27 lukem Exp $ - */ - -#include - -const union __long_double_u __infinityl = - { { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f, 0, 0, 0, 0, 0, 0 } }; diff --git a/lib/libc/x86_64/gen/isfinitel.c b/lib/libc/x86_64/gen/isfinitel.c deleted file mode 100644 index ca3744c2c7..0000000000 --- a/lib/libc/x86_64/gen/isfinitel.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - * - * $NetBSD: isfinitel.c,v 1.1 2003/10/29 20:03:51 kleink Exp $ - */ - -#include -#include -#include - -/* - * 7.12.3.2 isfinite - determine whether an argument has finite value - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isfinitel(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - _DIAGASSERT(u.extu_ext.ext_exp == 0 || u.extu_ext.ext_int == 1); - - if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) - return 0; - - return 1; -} diff --git a/lib/libc/x86_64/gen/isinfl.c b/lib/libc/x86_64/gen/isinfl.c deleted file mode 100644 index c94d9a1006..0000000000 --- a/lib/libc/x86_64/gen/isinfl.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - * $NetBSD: isinfl.c,v 1.5 2004/03/04 23:42:39 kleink Exp $ - */ - -#include -#include - -/* - * 7.12.3.3 isinf - test for infinity - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isinfl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_exp == EXT_EXP_INFNAN && - (u.extu_ext.ext_int == 1 && - u.extu_ext.ext_frach == 0 && u.extu_ext.ext_fracl == 0)); -} diff --git a/lib/libc/x86_64/gen/isnanl.c b/lib/libc/x86_64/gen/isnanl.c deleted file mode 100644 index 91e915d32e..0000000000 --- a/lib/libc/x86_64/gen/isnanl.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp - * $NetBSD: isnanl.c,v 1.5 2004/03/04 23:42:39 kleink Exp $ - */ - -#include -#include - -/* - * 7.12.3.4 isnan - test for a NaN - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__isnanl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_exp == EXT_EXP_INFNAN && - u.extu_ext.ext_int == 1 && - (u.extu_ext.ext_frach != 0 || u.extu_ext.ext_fracl != 0)); -} diff --git a/lib/libc/x86_64/gen/ldexp.c b/lib/libc/x86_64/gen/ldexp.c deleted file mode 100644 index 272da6e7f8..0000000000 --- a/lib/libc/x86_64/gen/ldexp.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan. - * - * 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. 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. - * - * @(#)ldexp.c 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/amd64/gen/ldexp.c,v 1.14 2007/01/09 00:38:24 imp Exp $ - */ - -/* - * ldexp(value, exp): return value * (2 ** exp). - * - * Written by Sean Eric Fagan (sef@kithrup.COM) - * Sun Mar 11 20:27:09 PST 1990 - */ - -/* - * We do the conversion in C to let gcc optimize it away, if possible. - */ -double -ldexp(double value, int exp) -{ - double temp, texp, temp2; - texp = exp; -#ifdef __GNUC__ - __asm ("fscale " - : "=u" (temp2), "=t" (temp) - : "0" (texp), "1" (value)); -#else -#error unknown asm -#endif - return (temp); -} diff --git a/lib/libc/x86_64/gen/modf.S b/lib/libc/x86_64/gen/modf.S deleted file mode 100644 index 42895d0dc5..0000000000 --- a/lib/libc/x86_64/gen/modf.S +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)modf.s 5.5 (Berkeley) 3/18/91 - * $NetBSD: modf.S,v 1.5 1997/07/16 14:37:18 christos Exp $ - * $FreeBSD: src/lib/libc/amd64/gen/modf.S,v 1.4 2008/11/02 01:10:54 peter Exp $ - */ - -#include - -/* - * modf(value, iptr): return fractional part of value, and stores the - * integral part into iptr (a pointer to double). - * - * Written by Sean Eric Fagan (sef@kithrup.COM) - * Sun Mar 11 20:27:30 PST 1990 - */ - -/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ -ENTRY(modf) - - /* - * Set chop mode. - */ - fnstcw -12(%rsp) - movw -12(%rsp),%dx - orw $3072,%dx - movw %dx,-16(%rsp) - fldcw -16(%rsp) - - /* - * Get integral part. - */ - movsd %xmm0,-24(%rsp) - fldl -24(%rsp) - frndint - fstpl -8(%rsp) - - /* - * Restore control word. - */ - fldcw -12(%rsp) - - /* - * Store integral part. - */ - movsd -8(%rsp),%xmm0 - movsd %xmm0,(%rdi) - - /* - * Get fractional part and return it. - */ - fldl -24(%rsp) - fsubl -8(%rsp) - fstpl -8(%rsp) - movsd -8(%rsp),%xmm0 - - ret -END(modf) diff --git a/lib/libc/x86_64/gen/nanf.c b/lib/libc/x86_64/gen/nanf.c deleted file mode 100644 index efc19068da..0000000000 --- a/lib/libc/x86_64/gen/nanf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -/* bytes for quiet NaN (IEEE single precision) */ -const union __float_u __nanf = - { { 0, 0, 0xc0, 0x7f } }; diff --git a/lib/libc/x86_64/gen/signbitl.c b/lib/libc/x86_64/gen/signbitl.c deleted file mode 100644 index 504a2ed4b5..0000000000 --- a/lib/libc/x86_64/gen/signbitl.c +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 2003 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 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. - * - * $NetBSD: signbitl.c,v 1.1 2004/01/15 19:43:45 kleink Exp $ - */ - -#include -#include - -/* - * 7.12.3.6 signbit - determine whether the sign of an argument is negative - * IEEE 754 compatible 80-bit extended-precision Intel 386 version - */ -int -__signbitl(long double x) -{ - union ieee_ext_u u; - - u.extu_ld = x; - - return (u.extu_ext.ext_sign == 1); -} diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 156fea4b26..3f3390a7de 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,15 +1,292 @@ -# $DragonFly: src/lib/libm/Makefile,v 1.8 2008/11/03 00:25:44 pavalos Exp $ +# @(#)Makefile 5.1beta 93/09/24 +# $FreeBSD: head/lib/msun/Makefile 238724 2012-07-23 19:23:49Z kargl $ +# +# ==================================================== +# 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. +# ==================================================== +# +# -LIB= m -SHLIB_MAJOR= 3 -WARNS?= 2 +.include "${MACHINE_ARCH}/Makefile.inc" -.include "arch/${MACHINE_ARCH}/Makefile.inc" -.include "gen/Makefile.inc" -.include "man/Makefile.inc" -.include "src/Makefile.inc" +.PATH: ${.CURDIR}/${MACHINE_ARCH} -# Complex arithmentic -.include "complex/Makefile.inc" +.PATH: ${.CURDIR}/ld80 +CFLAGS+= -I${.CURDIR}/ld80 + +.PATH: ${.CURDIR}/bsdsrc +.PATH: ${.CURDIR}/src +.PATH: ${.CURDIR}/man + +LIB= m +SHLIB_MAJOR= 3 +WARNS?= 1 +COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \ + e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ + e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_cosh.c e_coshf.c e_exp.c \ + e_expf.c e_fmod.c e_fmodf.c e_gamma.c e_gamma_r.c e_gammaf.c \ + e_gammaf_r.c e_hypot.c e_hypotf.c e_j0.c e_j0f.c e_j1.c e_j1f.c \ + e_jn.c e_jnf.c e_lgamma.c e_lgamma_r.c e_lgammaf.c e_lgammaf_r.c \ + e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c \ + e_pow.c e_powf.c e_rem_pio2.c \ + e_rem_pio2f.c e_scalb.c e_scalbf.c \ + e_sinh.c e_sinhf.c fenv.c \ + k_cos.c k_cosf.c k_exp.c k_expf.c k_rem_pio2.c k_sin.c k_sinf.c \ + k_tan.c k_tanf.c \ + s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_carg.c s_cargf.c s_cargl.c \ + s_cbrt.c s_cbrtf.c s_ceil.c s_ceilf.c \ + s_copysign.c s_copysignf.c s_cos.c s_cosf.c \ + s_csqrt.c s_csqrtf.c s_erf.c s_erff.c \ + s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c \ + s_finite.c s_finitef.c \ + s_floor.c s_floorf.c s_fma.c s_fmaf.c \ + s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c \ + s_fminf.c s_fminl.c s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \ + s_ilogbl.c s_isfinite.c s_isnan.c s_isnormal.c \ + s_llround.c s_llroundf.c s_llroundl.c \ + s_log1p.c s_log1pf.c s_logb.c s_logbf.c \ + s_lround.c s_lroundf.c s_lroundl.c s_modff.c \ + s_nan.c s_nearbyint.c s_nextafter.c s_nextafterf.c \ + s_nexttowardf.c \ + s_rint.c s_rintf.c s_round.c s_roundf.c s_roundl.c \ + s_scalbln.c s_signbit.c \ + s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \ + s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \ + w_cabs.c w_cabsf.c w_drem.c w_dremf.c + +# Location of fpmath.h and _fpmath.h +LIBCDIR=${.CURDIR}/../libc +CFLAGS+=-I${.CURDIR}/src -I${LIBCDIR}/include -I${LIBCDIR}/${MACHINE_ARCH} + +# C99 long double functions +COMMON_SRCS+= s_copysignl.c s_fabsl.c s_modfl.c +# If long double != double use these; otherwise, we alias the double versions. +COMMON_SRCS+= e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c \ + e_hypotl.c \ + invtrig.c k_cosl.c k_sinl.c k_tanl.c \ + s_atanl.c s_cbrtl.c s_ceill.c s_cosl.c s_cprojl.c \ + s_csqrtl.c s_exp2l.c s_expl.c s_floorl.c s_fmal.c \ + s_frexpl.c s_nanl.c s_nextafterl.c s_nexttoward.c \ + s_sinl.c s_tanl.c s_truncl.c w_cabsl.c + +# C99 complex functions +COMMON_SRCS+= catrig.c catrigf.c \ + s_ccosh.c s_ccoshf.c s_cexp.c s_cexpf.c \ + s_cimag.c s_cimagf.c s_cimagl.c \ + s_conj.c s_conjf.c s_conjl.c \ + s_cproj.c s_cprojf.c s_creal.c s_crealf.c s_creall.c \ + s_csinh.c s_csinhf.c s_ctanh.c s_ctanhf.c + +# libc supplies these functions: +#COMMON_SRCS+= s_fabs.c s_frexp.c s_isnan.c s_ldexp.c s_modf.c + +# Exclude the generic versions of what we provide in the MD area. +.if defined(ARCH_SRCS) +.for i in ${ARCH_SRCS} +COMMON_SRCS:= ${COMMON_SRCS:N${i:R}.c} +.endfor +.endif + +SRCS= ${COMMON_SRCS} ${ARCH_SRCS} + +INCS+= complex.h fenv.h math.h + +MAN= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \ + ceil.3 cacos.3 ccos.3 ccosh.3 cexp.3 cimag.3 complex.3 copysign.3 \ + cos.3 cosh.3 csqrt.3 erf.3 exp.3 fabs.3 fdim.3 \ + feclearexcept.3 feenableexcept.3 fegetenv.3 fegetround.3 fenv.3 \ + floor.3 fma.3 fmax.3 fmod.3 hypot.3 ieee.3 ieee_test.3 ilogb.3 \ + j0.3 lgamma.3 log.3 lrint.3 lround.3 math.3 nan.3 nextafter.3 \ + remainder.3 rint.3 round.3 scalbn.3 signbit.3 sin.3 sinh.3 sqrt.3 \ + tan.3 tanh.3 trunc.3 + +MLINKS+=acos.3 acosf.3 \ + acos.3 acosl.3 +MLINKS+=acosh.3 acoshf.3 +MLINKS+=asin.3 asinf.3 \ + asin.3 asinl.3 +MLINKS+=asinh.3 asinhf.3 +MLINKS+=atan.3 atanf.3 \ + atan.3 atanl.3 +MLINKS+=atan2.3 atan2f.3 \ + atan2.3 atan2l.3 \ + atan2.3 carg.3 \ + atan2.3 cargf.3 \ + atan2.3 cargl.3 +MLINKS+=atanh.3 atanhf.3 +MLINKS+=cacos.3 cacosf.3 \ + cacos.3 cacosh.3 \ + cacos.3 cacoshf.3 \ + cacos.3 casin.3 \ + cacos.3 casinf.3 \ + cacos.3 casinh.3 \ + cacos.3 casinhf \ + cacos.3 catan.3 \ + cacos.3 catanf.3 \ + cacos.3 catanh.3 \ + cacos.3 catanhf.3 +MLINKS+=ccos.3 ccosf.3 \ + ccos.3 csin.3 \ + ccos.3 csinf.3 \ + ccos.3 ctan.3 \ + ccos.3 ctanf.3 +MLINKS+=ccosh.3 ccoshf.3 \ + ccosh.3 csinh.3 \ + ccosh.3 csinhf.3 \ + ccosh.3 ctanh.3 \ + ccosh.3 ctanhf.3 +MLINKS+=ceil.3 ceilf.3 \ + ceil.3 ceill.3 +MLINKS+=cexp.3 cexpf.3 +MLINKS+=cimag.3 cimagf.3 \ + cimag.3 cimagl.3 \ + cimag.3 conj.3 \ + cimag.3 conjf.3 \ + cimag.3 conjl.3 \ + cimag.3 cproj.3 \ + cimag.3 cprojf.3 \ + cimag.3 cprojl.3 \ + cimag.3 creal.3 \ + cimag.3 crealf.3 \ + cimag.3 creall.3 +MLINKS+=copysign.3 copysignf.3 \ + copysign.3 copysignl.3 +MLINKS+=cos.3 cosf.3 \ + cos.3 cosl.3 +MLINKS+=cosh.3 coshf.3 +MLINKS+=csqrt.3 csqrtf.3 \ + csqrt.3 csqrtl.3 +MLINKS+=erf.3 erff.3 \ + erf.3 erfc.3 \ + erf.3 erfcf.3 +MLINKS+=exp.3 expf.3 \ + exp.3 expl.3 \ + exp.3 exp2.3 \ + exp.3 exp2f.3 \ + exp.3 exp2l.3 \ + exp.3 expm1.3 \ + exp.3 expm1f.3 \ + exp.3 pow.3 \ + exp.3 powf.3 +MLINKS+=fabs.3 fabsf.3 \ + fabs.3 fabsl.3 +MLINKS+=fdim.3 fdimf.3 \ + fdim.3 fdiml.3 +MLINKS+=feclearexcept.3 fegetexceptflag.3 \ + feclearexcept.3 feraiseexcept.3 \ + feclearexcept.3 fesetexceptflag.3 \ + feclearexcept.3 fetestexcept.3 +MLINKS+=feenableexcept.3 fedisableexcept.3 \ + feenableexcept.3 fegetexcept.3 +MLINKS+=fegetenv.3 feholdexcept.3 \ + fegetenv.3 fesetenv.3 \ + fegetenv.3 feupdateenv.3 +MLINKS+=fegetround.3 fesetround.3 +MLINKS+=floor.3 floorf.3 \ + floor.3 floorl.3 +MLINKS+=fma.3 fmaf.3 \ + fma.3 fmal.3 +MLINKS+=fmax.3 fmaxf.3 \ + fmax.3 fmaxl.3 \ + fmax.3 fmin.3 \ + fmax.3 fminf.3 \ + fmax.3 fminl.3 +MLINKS+=fmod.3 fmodf.3 \ + fmod.3 fmodl.3 +MLINKS+=hypot.3 cabs.3 \ + hypot.3 cabsf.3 \ + hypot.3 cabsl.3 \ + hypot.3 hypotf.3 \ + hypot.3 hypotl.3 +MLINKS+=ieee.3 libm.3 +MLINKS+=ieee_test.3 scalb.3 \ + ieee_test.3 scalbf.3 \ + ieee_test.3 significand.3 \ + ieee_test.3 significandf.3 +MLINKS+=ilogb.3 ilogbf.3 \ + ilogb.3 ilogbl.3 \ + ilogb.3 logb.3 \ + ilogb.3 logbf.3 \ + ilogb.3 logbl.3 +MLINKS+=j0.3 j0f.3 \ + j0.3 j1.3 \ + j0.3 j1f.3 \ + j0.3 jn.3 \ + j0.3 jnf.3 \ + j0.3 y0.3 \ + j0.3 y0f.3 \ + j0.3 y1.3 \ + j0.3 y1f.3 \ + j0.3 yn.3 \ + j0.3 ynf.3 +MLINKS+=lgamma.3 lgamma_r.3 \ + lgamma.3 lgammaf.3 \ + lgamma.3 lgammaf_r.3 \ + lgamma.3 gamma.3 \ + lgamma.3 gamma_r.3 \ + lgamma.3 gammaf.3 \ + lgamma.3 gammaf_r.3 \ + lgamma.3 tgamma.3 \ + lgamma.3 tgammaf.3 +MLINKS+=log.3 logf.3 \ + log.3 logl.3 \ + log.3 log10.3 \ + log.3 log10f.3 \ + log.3 log2.3 \ + log.3 log2f.3 \ + log.3 log1p.3 \ + log.3 log1pf.3 +MLINKS+=lrint.3 llrint.3 \ + lrint.3 llrintf.3 \ + lrint.3 llrintl.3 \ + lrint.3 lrintf.3 \ + lrint.3 lrintl.3 +MLINKS+=lround.3 llround.3 \ + lround.3 llroundf.3 \ + lround.3 llroundl.3 \ + lround.3 lroundf.3 \ + lround.3 lroundl.3 +MLINKS+=nan.3 nanf.3 \ + nan.3 nanl.3 +MLINKS+=nextafter.3 nextafterf.3 \ + nextafter.3 nextafterl.3 \ + nextafter.3 nexttoward.3 \ + nextafter.3 nexttowardf.3 \ + nextafter.3 nexttowardl.3 +MLINKS+=remainder.3 remainderf.3 \ + remainder.3 remainderl.3 \ + remainder.3 remquo.3 \ + remainder.3 remquof.3 \ + remainder.3 remquol.3 +MLINKS+=rint.3 rintf.3 \ + rint.3 rintl.3 \ + rint.3 nearbyint.3 \ + rint.3 nearbyintf.3 \ + rint.3 nearbyintl.3 +MLINKS+=round.3 roundf.3 \ + round.3 roundl.3 +MLINKS+=scalbn.3 scalbln.3 \ + scalbn.3 scalblnf.3 \ + scalbn.3 scalblnl.3 \ + scalbn.3 scalbnf.3 \ + scalbn.3 scalbnl.3 +MLINKS+=sin.3 sinf.3 \ + sin.3 sinl.3 +MLINKS+=sinh.3 sinhf.3 +MLINKS+=sqrt.3 cbrt.3 \ + sqrt.3 cbrtf.3 \ + sqrt.3 cbrtl.3 \ + sqrt.3 sqrtf.3 \ + sqrt.3 sqrtl.3 +MLINKS+=tan.3 tanf.3 \ + tan.3 tanl.3 +MLINKS+=tanh.3 tanhf.3 +MLINKS+=trunc.3 truncf.3 \ + trunc.3 truncl.3 .include diff --git a/lib/libm/arch/i386/Makefile.inc b/lib/libm/arch/i386/Makefile.inc deleted file mode 100644 index 12fe3c71ab..0000000000 --- a/lib/libm/arch/i386/Makefile.inc +++ /dev/null @@ -1,22 +0,0 @@ -# $DragonFly: src/lib/libm/arch/i386/Makefile.inc,v 1.2 2007/06/16 22:26:53 pavalos Exp $ - -.PATH: ${.CURDIR}/arch/i386 - -SRCS+= e_acos.S e_asin.S e_atan2.S e_atan2f.S e_exp.S e_expf.S e_fmod.S \ - e_log.S e_log10.S e_log10f.S e_log2.S e_log2f.S e_logf.S \ - e_scalb.S e_scalbf.S e_sqrt.S e_sqrtf.S s_lrint.S s_atan.S s_atanf.S \ - s_ceil.S s_ceilf.S s_copysign.S s_copysignf.S s_cos.S s_cosf.S \ - s_finite.S s_finitef.S s_floor.S s_floorf.S s_ilogb.S s_ilogbf.S \ - s_log1p.S s_log1pf.S s_logb.S s_logbf.S s_rint.S s_rintf.S \ - s_scalbn.S s_scalbnf.S s_significand.S s_significandf.S s_sin.S \ - s_sinf.S s_tan.S s_tanf.S e_remainder.S e_remainderf.S -SRCS+= s_ilogbl.S s_logbl.S s_modf.S s_scalbnl.S -SRCS+= s_remquol.S e_remainderl.S s_lrintf.S s_lrintl.S - -# This file is included by arch/x86_64/Makefile.inc, so pull in the right -# fenv.[ch]. -# -.if ${MACHINE_ARCH} == "i386" -SRCS+= fenv.c -INCS= fenv.h -.endif diff --git a/lib/libm/arch/i386/abi.h b/lib/libm/arch/i386/abi.h deleted file mode 100644 index 38edf95ad2..0000000000 --- a/lib/libm/arch/i386/abi.h +++ /dev/null @@ -1,81 +0,0 @@ -/* $NetBSD: abi.h,v 1.7 2011/06/18 22:19:52 joerg Exp $ */ - -/* - * Written by Frank van der Linden (fvdl@wasabisystems.com) - */ - -/* - * The x86-64 ABI specifies that float and double arguments - * are passed in SSE2 (xmm) registers. Unfortunately, - * there is no way to push those on to the FP stack, which is - * where the fancier instructions get their arguments from. - * - * Define some prologues and epilogues to store and retrieve - * xmm regs to local variables. - */ - -#ifdef __x86_64__ - -#define ARG_LONG_DOUBLE_ONE 8(%rsp) -#define ARG_LONG_DOUBLE_TWO 24(%rsp) -#define ARG_DOUBLE_ONE -8(%rsp) -#define ARG_DOUBLE_ONE_LSW -8(%rsp) -#define ARG_DOUBLE_ONE_MSW -4(%rsp) -#define ARG_DOUBLE_TWO -16(%rsp) -#define ARG_FLOAT_ONE -4(%rsp) -#define ARG_FLOAT_TWO -8(%rsp) - -#define XMM_ONE_ARG_DOUBLE_PROLOGUE \ - movsd %xmm0, ARG_DOUBLE_ONE - -#define XMM_TWO_ARG_DOUBLE_PROLOGUE \ - movsd %xmm0, ARG_DOUBLE_ONE ; \ - movsd %xmm1, ARG_DOUBLE_TWO - -#define XMM_ONE_ARG_FLOAT_PROLOGUE \ - movss %xmm0, ARG_FLOAT_ONE - -#define XMM_TWO_ARG_FLOAT_PROLOGUE \ - movss %xmm0, ARG_FLOAT_ONE ; \ - movss %xmm1, ARG_FLOAT_TWO - -#define XMM_DOUBLE_EPILOGUE \ - fstpl ARG_DOUBLE_ONE ; \ - movsd ARG_DOUBLE_ONE, %xmm0 - -#define XMM_FLOAT_EPILOGUE \ - fstps ARG_FLOAT_ONE ; \ - movss ARG_FLOAT_ONE, %xmm0 - -#define FLDL_VAR(x) fldl x(%rip) - -#else - -#define ARG_LONG_DOUBLE_ONE 4(%esp) -#define ARG_LONG_DOUBLE_TWO 16(%esp) -#define ARG_DOUBLE_ONE 4(%esp) -#define ARG_DOUBLE_ONE_LSW 4(%esp) -#define ARG_DOUBLE_ONE_MSW 8(%esp) -#define ARG_DOUBLE_TWO 12(%esp) -#define ARG_FLOAT_ONE 4(%esp) -#define ARG_FLOAT_TWO 8(%esp) - -#define XMM_ONE_ARG_DOUBLE_PROLOGUE -#define XMM_TWO_ARG_DOUBLE_PROLOGUE -#define XMM_ONE_ARG_FLOAT_PROLOGUE -#define XMM_TWO_ARG_FLOAT_PROLOGUE - -#define XMM_DOUBLE_EPILOGUE -#define XMM_FLOAT_EPILOGUE - -#ifdef PIC -#define FLDL_VAR(x) \ - PIC_PROLOGUE ; \ - fldl PIC_GOTOFF(x) ; \ - PIC_EPILOGUE -#else -#define FLDL_VAR(x) \ - fldl x - -#endif -#endif diff --git a/lib/libm/arch/i386/e_acos.S b/lib/libm/arch/i386/e_acos.S deleted file mode 100644 index 8864d12410..0000000000 --- a/lib/libm/arch/i386/e_acos.S +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_acos.S,v 1.8 2003/07/26 19:24:57 salo Exp $ - */ - -#include - -#include "abi.h" - -/* acos = atan (sqrt(1 - x^2) / x) */ -ENTRY(acos) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE /* x */ - fld %st(0) - fmul %st(0) /* x^2 */ - fld1 - fsubp /* 1 - x^2 */ - fsqrt /* sqrt (1 - x^2) */ - fxch %st(1) - fpatan - XMM_DOUBLE_EPILOGUE - ret -END(acos) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_asin.S b/lib/libm/arch/i386/e_asin.S deleted file mode 100644 index 5268c07786..0000000000 --- a/lib/libm/arch/i386/e_asin.S +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_asin.S,v 1.7 2003/07/26 19:24:58 salo Exp $ - */ - -#include - -#include "abi.h" - -/* asin = atan (x / sqrt(1 - x^2)) */ -ENTRY(asin) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE /* x */ - fld %st(0) - fmul %st(0) /* x^2 */ - fld1 - fsubp /* 1 - x^2 */ - fsqrt /* sqrt (1 - x^2) */ - fpatan - XMM_DOUBLE_EPILOGUE - ret -END(asin) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_atan2.S b/lib/libm/arch/i386/e_atan2.S deleted file mode 100644 index 594c798044..0000000000 --- a/lib/libm/arch/i386/e_atan2.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_atan2.S,v 1.6 2003/07/26 19:24:58 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(atan2) - XMM_TWO_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fldl ARG_DOUBLE_TWO - fpatan - XMM_DOUBLE_EPILOGUE - ret -END(atan2) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_atan2f.S b/lib/libm/arch/i386/e_atan2f.S deleted file mode 100644 index cd5e420ff1..0000000000 --- a/lib/libm/arch/i386/e_atan2f.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_atan2f.S,v 1.3 2003/07/26 19:24:58 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(atan2f) - XMM_TWO_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - flds ARG_FLOAT_TWO - fpatan - XMM_FLOAT_EPILOGUE - ret -END(atan2f) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_expf.S b/lib/libm/arch/i386/e_expf.S deleted file mode 100644 index f50337ee72..0000000000 --- a/lib/libm/arch/i386/e_expf.S +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_expf.S,v 1.6 2008/06/24 17:27:56 drochner Exp $ $ - */ - -#include - -#include "abi.h" - -/* e^x = 2^(x * log2(e)) */ -ENTRY(expf) - XMM_ONE_ARG_FLOAT_PROLOGUE - - /* - * catch +/-Inf and NaN arguments - */ - movl ARG_FLOAT_ONE,%eax - andl $0x7fffffff,%eax - cmpl $0x7f800000,%eax - jae x_Inf_or_NaN - - flds ARG_FLOAT_ONE - fldl2e - fmulp /* x * log2(e) */ - fld %st(0) - frndint /* int(x * log2(e)) */ - fsubr %st(0),%st(1) /* fract(x * log2(e)) */ - fxch - f2xm1 /* 2^(fract(x * log2(e))) - 1 */ - fld1 - faddp /* 2^(fract(x * log2(e))) */ - fscale /* e^x */ - fstp %st(1) - XMM_FLOAT_EPILOGUE - ret - -x_Inf_or_NaN: - /* - * Return 0 if x is -Inf. Otherwise just return x, although the - * C version would return (x + x) (Real Indefinite) if x is a NaN. - */ - movl ARG_FLOAT_ONE,%eax - cmpl $0xff800000,%eax - jne x_not_minus_Inf - fldz - XMM_FLOAT_EPILOGUE - ret - -x_not_minus_Inf: - flds ARG_FLOAT_ONE - XMM_FLOAT_EPILOGUE - ret -END(expf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_fmod.S b/lib/libm/arch/i386/e_fmod.S deleted file mode 100644 index 1620c320bb..0000000000 --- a/lib/libm/arch/i386/e_fmod.S +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_fmod.S,v 1.7 2003/07/26 19:24:58 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(fmod) - XMM_TWO_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_TWO - fldl ARG_DOUBLE_ONE -1: fprem - fstsw %ax - btw $10,%ax - jc 1b - fstp %st(1) - XMM_DOUBLE_EPILOGUE - ret -END(fmod) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_log.S b/lib/libm/arch/i386/e_log.S deleted file mode 100644 index 9fb08b1dd4..0000000000 --- a/lib/libm/arch/i386/e_log.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_log.S,v 1.6 2003/07/26 19:24:58 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(log) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldln2 - fldl ARG_DOUBLE_ONE - fyl2x - XMM_DOUBLE_EPILOGUE - ret -END(log) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_log10.S b/lib/libm/arch/i386/e_log10.S deleted file mode 100644 index 581c77853f..0000000000 --- a/lib/libm/arch/i386/e_log10.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_log10.S,v 1.6 2003/07/26 19:24:59 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(log10) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldlg2 - fldl ARG_DOUBLE_ONE - fyl2x - XMM_DOUBLE_EPILOGUE - ret -END(log10) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_log10f.S b/lib/libm/arch/i386/e_log10f.S deleted file mode 100644 index 81a0d8e3c2..0000000000 --- a/lib/libm/arch/i386/e_log10f.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_log10f.S,v 1.3 2003/07/26 19:24:59 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(log10f) - XMM_ONE_ARG_FLOAT_PROLOGUE - fldlg2 - flds ARG_FLOAT_ONE - fyl2x - XMM_FLOAT_EPILOGUE - ret -END(log10f) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_log2.S b/lib/libm/arch/i386/e_log2.S deleted file mode 100644 index 877fef4455..0000000000 --- a/lib/libm/arch/i386/e_log2.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by Rui Paulo , based on e_log.S. - * Public domain. - * $NetBSD: e_log2.S,v 1.1 2005/07/21 20:58:21 rpaulo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(log2) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fld1 - fldl ARG_DOUBLE_ONE - fyl2x - XMM_DOUBLE_EPILOGUE - ret -END(log2) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_log2f.S b/lib/libm/arch/i386/e_log2f.S deleted file mode 100644 index dc7d818423..0000000000 --- a/lib/libm/arch/i386/e_log2f.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by Rui Paulo , based on e_logf.S. - * Public domain. - * $NetBSD: e_log2f.S,v 1.1 2005/07/21 20:58:21 rpaulo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(log2f) - XMM_ONE_ARG_FLOAT_PROLOGUE - fld1 - flds ARG_FLOAT_ONE - fyl2x - XMM_FLOAT_EPILOGUE - ret -END(log2f) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_logf.S b/lib/libm/arch/i386/e_logf.S deleted file mode 100644 index 5517bedd26..0000000000 --- a/lib/libm/arch/i386/e_logf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_logf.S,v 1.4 2003/07/26 19:24:59 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(logf) - XMM_ONE_ARG_FLOAT_PROLOGUE - fldln2 - flds ARG_FLOAT_ONE - fyl2x - XMM_FLOAT_EPILOGUE - ret -END(logf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_remainder.S b/lib/libm/arch/i386/e_remainder.S deleted file mode 100644 index 8cbc96852c..0000000000 --- a/lib/libm/arch/i386/e_remainder.S +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_remainder.S,v 1.7 2003/07/26 19:24:59 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(remainder) - XMM_TWO_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_TWO - fldl ARG_DOUBLE_ONE -1: fprem1 - fstsw %ax - btw $10,%ax - jc 1b - fstp %st(1) - XMM_DOUBLE_EPILOGUE - ret -END(remainder) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_remainderf.S b/lib/libm/arch/i386/e_remainderf.S deleted file mode 100644 index a58df3b432..0000000000 --- a/lib/libm/arch/i386/e_remainderf.S +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_remainderf.S,v 1.5 2003/07/26 19:24:59 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(remainderf) - XMM_TWO_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_TWO - flds ARG_FLOAT_ONE -1: fprem1 - fstsw %ax - btw $10,%ax - jc 1b - fstp %st(1) - XMM_FLOAT_EPILOGUE - ret -END(remainderf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_scalb.S b/lib/libm/arch/i386/e_scalb.S deleted file mode 100644 index 03c57c9e4f..0000000000 --- a/lib/libm/arch/i386/e_scalb.S +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_scalb.S,v 1.7 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(scalb) - XMM_TWO_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_TWO - fldl ARG_DOUBLE_ONE - fscale - fstp %st(1) /* bug fix for fp stack overflow */ - XMM_DOUBLE_EPILOGUE - ret -END(scalb) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_scalbf.S b/lib/libm/arch/i386/e_scalbf.S deleted file mode 100644 index a5fc150be3..0000000000 --- a/lib/libm/arch/i386/e_scalbf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_scalbf.S,v 1.3 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(scalbf) - XMM_TWO_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_TWO - flds ARG_FLOAT_ONE - fscale - XMM_FLOAT_EPILOGUE - ret -END(scalbf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrt.S b/lib/libm/arch/i386/e_sqrt.S deleted file mode 100644 index 5a2928fecd..0000000000 --- a/lib/libm/arch/i386/e_sqrt.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_sqrt.S,v 1.6 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -ENTRY(sqrt) -#ifdef __i386__ - fldl 4(%esp) - fsqrt -#else - sqrtsd %xmm0,%xmm0 -#endif - ret -END(sqrt) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtf.S b/lib/libm/arch/i386/e_sqrtf.S deleted file mode 100644 index cfc89c1fef..0000000000 --- a/lib/libm/arch/i386/e_sqrtf.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: e_sqrtf.S,v 1.4 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -ENTRY(sqrtf) -#ifdef __i386__ - flds 4(%esp) - fsqrt -#else - sqrtss %xmm0,%xmm0 -#endif - ret -END(sqrtf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_atan.S b/lib/libm/arch/i386/s_atan.S deleted file mode 100644 index 15216d2b77..0000000000 --- a/lib/libm/arch/i386/s_atan.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_atan.S,v 1.6 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(atan) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fld1 - fpatan - XMM_DOUBLE_EPILOGUE - ret -END(atan) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_atanf.S b/lib/libm/arch/i386/s_atanf.S deleted file mode 100644 index 56a566e2be..0000000000 --- a/lib/libm/arch/i386/s_atanf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_atanf.S,v 1.5 2003/07/26 19:25:00 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(atanf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fld1 - fpatan - XMM_FLOAT_EPILOGUE - ret -END(atanf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_ceil.S b/lib/libm/arch/i386/s_ceil.S deleted file mode 100644 index 5280c3967a..0000000000 --- a/lib/libm/arch/i386/s_ceil.S +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_ceil.S,v 1.8 2011/06/18 21:24:51 joerg Exp - */ - -#include - -#include "abi.h" - -ENTRY(ceil) -#ifdef __i386__ - 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 -#else - fstcw -12(%rsp) - movw -12(%rsp),%dx - orw $0x0800,%dx - andw $0xfbff,%dx - movw %dx,-16(%rsp) - fldcw -16(%rsp) - movsd %xmm0,-8(%rsp) - fldl -8(%rsp) - frndint - fldcw -12(%rsp) - fstpl -8(%rsp) - movsd -8(%rsp),%xmm0 -#endif - ret -END(ceil) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_copysign.S b/lib/libm/arch/i386/s_copysign.S deleted file mode 100644 index 23674393e0..0000000000 --- a/lib/libm/arch/i386/s_copysign.S +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_copysign.S,v 1.7 2011/06/18 20:49:26 joerg Exp - */ - -/* - * XXXfvdl might as well split this file. - */ - -#include - -#ifdef __x86_64__ -.Lpos: - .quad 0x8000000000000000 -.Lneg: - .quad 0x7fffffffffffffff -#endif - - -ENTRY(copysign) -#ifdef __i386__ - movl 16(%esp),%edx - andl $0x80000000,%edx - movl 8(%esp),%eax - andl $0x7fffffff,%eax - orl %edx,%eax - movl %eax,8(%esp) - fldl 4(%esp) -#else - movq .Lpos(%rip),%xmm2 - movq .Lneg(%rip),%xmm3 - pand %xmm2,%xmm1 - pand %xmm3,%xmm0 - por %xmm1,%xmm0 -#endif - ret -END(copysign) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_copysignf.S b/lib/libm/arch/i386/s_copysignf.S deleted file mode 100644 index 838d352024..0000000000 --- a/lib/libm/arch/i386/s_copysignf.S +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_copysignf.S,v 1.7 2011/06/21 21:52:49 joerg Exp - */ - -#include - -/* - * XXXfvdl split this file. - */ - -#ifdef __x86_64__ -.Lneg: - .long 0x7fffffff -.Lpos: - .long 0x80000000 -#endif - -ENTRY(copysignf) -#ifdef __i386__ - movl 8(%esp),%edx - andl $0x80000000,%edx - movl 4(%esp),%eax - andl $0x7fffffff,%eax - orl %edx,%eax - movl %eax,4(%esp) - flds 4(%esp) -#else - movss .Lpos(%rip),%xmm2 - movss .Lneg(%rip),%xmm3 - pand %xmm2,%xmm1 - pand %xmm3,%xmm0 - por %xmm1,%xmm0 -#endif - ret -END(copysignf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_cos.S b/lib/libm/arch/i386/s_cos.S deleted file mode 100644 index 20f3e04f60..0000000000 --- a/lib/libm/arch/i386/s_cos.S +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_cos.S,v 1.8 2003/07/26 19:25:01 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(cos) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fcos - fnstsw %ax - andw $0x400,%ax - jnz 1f - XMM_DOUBLE_EPILOGUE - ret -1: fldpi - fadd %st(0) - fxch %st(1) -2: fprem1 - fnstsw %ax - andw $0x400,%ax - jnz 2b - fstp %st(1) - fcos - XMM_DOUBLE_EPILOGUE - ret -END(cos) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_cosf.S b/lib/libm/arch/i386/s_cosf.S deleted file mode 100644 index 09d106d67b..0000000000 --- a/lib/libm/arch/i386/s_cosf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_cosf.S,v 1.6 2003/07/26 19:25:01 salo Exp $ - */ - -#include - -#include "abi.h" - -/* A float's domain isn't large enough to require argument reduction. */ -ENTRY(cosf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fcos - XMM_FLOAT_EPILOGUE - ret -END(cosf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_finite.S b/lib/libm/arch/i386/s_finite.S deleted file mode 100644 index 3be7c9af4b..0000000000 --- a/lib/libm/arch/i386/s_finite.S +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_finite.S,v 1.7 2003/07/26 19:25:01 salo Exp $ - */ - -#include - -ENTRY(finite) -#ifdef __i386__ - movl 8(%esp),%eax - andl $0x7ff00000, %eax - cmpl $0x7ff00000, %eax - setne %al - andl $0x000000ff, %eax -#else - xorl %eax,%eax - movq $0x7ff0000000000000,%rsi - movq %rsi,%rdi - movsd %xmm0,-8(%rsp) - andq -8(%rsp),%rsi - cmpq %rdi,%rsi - setne %al -#endif - ret -END(finite) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_finitef.S b/lib/libm/arch/i386/s_finitef.S deleted file mode 100644 index c977ebafd3..0000000000 --- a/lib/libm/arch/i386/s_finitef.S +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_finitef.S,v 1.6 2003/07/26 19:25:01 salo Exp $ - */ - -#include - -ENTRY(finitef) -#ifdef __i386__ - movl 4(%esp),%eax - andl $0x7f800000, %eax - cmpl $0x7f800000, %eax - setne %al - andl $0x000000ff, %eax -#else - xorl %eax,%eax - movl $0x7ff00000,%esi - movss %xmm0,-4(%rsp) - andl -4(%rsp),%esi - cmpl $0x7ff00000,%esi - setne %al -#endif - ret -END(finitef) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_ilogb.S b/lib/libm/arch/i386/s_ilogb.S deleted file mode 100644 index 3ac9bc26d1..0000000000 --- a/lib/libm/arch/i386/s_ilogb.S +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_ilogb.S,v 1.7 2003/07/26 19:25:02 salo Exp $ - */ - -#include - -ENTRY(ilogb) -#ifdef __i386__ - pushl %ebp - movl %esp,%ebp - subl $4,%esp - - fldl 8(%ebp) - fxtract - fstp %st - - fistpl -4(%ebp) - movl -4(%ebp),%eax - - leave -#else - movsd %xmm0,-8(%rsp) - fldl -8(%rsp) - fxtract - fstp %st - fistpl -8(%rsp) - movl -8(%rsp),%eax -#endif - ret -END(ilogb) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_ilogbf.S b/lib/libm/arch/i386/s_ilogbf.S deleted file mode 100644 index 72e79f7ca8..0000000000 --- a/lib/libm/arch/i386/s_ilogbf.S +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_ilogbf.S,v 1.6 2003/07/26 19:25:02 salo Exp $ - */ - -#include - -ENTRY(ilogbf) -#ifdef __i386__ - pushl %ebp - movl %esp,%ebp - subl $4,%esp - - flds 8(%ebp) - fxtract - fstp %st - - fistpl -4(%ebp) - movl -4(%ebp),%eax - - leave -#else - movss %xmm0,-4(%rsp) - flds -4(%rsp) - fxtract - fstp %st - fistpl -4(%rsp) - movl -4(%rsp),%eax -#endif - ret -END(ilogbf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_ilogbl.S b/lib/libm/arch/i386/s_ilogbl.S deleted file mode 100644 index 727b297253..0000000000 --- a/lib/libm/arch/i386/s_ilogbl.S +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_ilogbl.S,v 1.1 2011/07/28 22:32:28 joerg Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(ilogbl) - fldt ARG_LONG_DOUBLE_ONE - fxtract - fstp %st -#ifdef __i386__ - pushl %eax - fistpl 0(%esp) - popl %eax -#else - fistpl -4(%rsp) - movl -4(%rsp), %eax -#endif - ret -END(ilogbl) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_log1p.S b/lib/libm/arch/i386/s_log1p.S deleted file mode 100644 index 1a57762c3e..0000000000 --- a/lib/libm/arch/i386/s_log1p.S +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_log1p.S,v 1.13 2003/09/16 18:17:11 wennmach Exp $ - */ - -/* - * Modified by Lex Wennmacher - * Still public domain. - */ - -#include - -#include "abi.h" - -/* - * The log1p() function is provided to compute an accurate value of - * log(1 + x), even for tiny values of x. The i387 FPU provides the - * fyl2xp1 instruction for this purpose. However, the range of this - * instruction is limited to: - * -(1 - (sqrt(2) / 2)) <= x <= sqrt(2) - 1 - * -0.292893 <= x <= 0.414214 - * at least on older processor versions. - * - * log1p() is implemented by testing the range of the argument. - * If it is appropriate for fyl2xp1, this instruction is used. - * Else, we compute log1p(x) = ln(2)*ld(1 + x) the traditional way - * (using fyl2x). - * - * The range testing costs speed, but as the rationale for the very - * existence of this function is accuracy, we accept that. - * - * In order to reduce the cost for testing the range, we check if - * the argument is in the range - * -0.25 <= x <= 0.25 - * which can be done with just one conditional branch. If x is - * inside this range, we use fyl2xp1. Outside of this range, - * the use of fyl2x is accurate enough. - * - */ - -.text - .align 4 -ENTRY(log1p) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fabs - fld1 /* ... x 1 */ - fadd %st(0) /* ... x 2 */ - fadd %st(0) /* ... x 4 */ - fld1 /* ... 4 1 */ - fdivp /* ... x 0.25 */ - fcompp - fnstsw %ax - andb $69,%ah - jne use_fyl2x - jmp use_fyl2xp1 - - .align 4 -use_fyl2x: - fldln2 - fldl ARG_DOUBLE_ONE - fld1 - faddp - fyl2x - XMM_DOUBLE_EPILOGUE - ret - - .align 4 -use_fyl2xp1: - fldln2 - fldl ARG_DOUBLE_ONE - fyl2xp1 - XMM_DOUBLE_EPILOGUE - ret -END(log1p) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_log1pf.S b/lib/libm/arch/i386/s_log1pf.S deleted file mode 100644 index 31f62a5856..0000000000 --- a/lib/libm/arch/i386/s_log1pf.S +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_log1pf.S,v 1.10 2003/09/16 18:17:11 wennmach Exp $ - */ - -/* - * Modified by Lex Wennmacher - * Still public domain. - */ - -#include - -#include "abi.h" - -/* - * The log1pf() function is provided to compute an accurate value of - * log(1 + x), even for tiny values of x. The i387 FPU provides the - * fyl2xp1 instruction for this purpose. However, the range of this - * instruction is limited to: - * -(1 - (sqrt(2) / 2)) <= x <= sqrt(2) - 1 - * -0.292893 <= x <= 0.414214 - * at least on older processor versions. - * - * log1pf() is implemented by testing the range of the argument. - * If it is appropriate for fyl2xp1, this instruction is used. - * Else, we compute log1pf(x) = ln(2)*ld(1 + x) the traditional way - * (using fyl2x). - * - * The range testing costs speed, but as the rationale for the very - * existence of this function is accuracy, we accept that. - * - * In order to reduce the cost for testing the range, we check if - * the argument is in the range - * -0.25 <= x <= 0.25 - * which can be done with just one conditional branch. If x is - * inside this range, we use fyl2xp1. Outside of this range, - * the use of fyl2x is accurate enough. - * - */ - -.text - .align 4 -ENTRY(log1pf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fabs - fld1 /* ... x 1 */ - fadd %st(0) /* ... x 2 */ - fadd %st(0) /* ... x 4 */ - fld1 /* ... 4 1 */ - fdivp /* ... x 0.25 */ - fcompp - fnstsw %ax - andb $69,%ah - jne use_fyl2x - jmp use_fyl2xp1 - - .align 4 -use_fyl2x: - fldln2 - flds ARG_FLOAT_ONE - fld1 - faddp - fyl2x - XMM_FLOAT_EPILOGUE - ret - - .align 4 -use_fyl2xp1: - fldln2 - flds ARG_FLOAT_ONE - fyl2xp1 - XMM_FLOAT_EPILOGUE - ret -END(log1pf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_logb.S b/lib/libm/arch/i386/s_logb.S deleted file mode 100644 index 5a16a49fc7..0000000000 --- a/lib/libm/arch/i386/s_logb.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_logb.S,v 1.6 2003/07/26 19:25:02 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(logb) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fxtract - fstp %st - XMM_DOUBLE_EPILOGUE - ret -END(logb) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_logbf.S b/lib/libm/arch/i386/s_logbf.S deleted file mode 100644 index 6199b8d506..0000000000 --- a/lib/libm/arch/i386/s_logbf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_logbf.S,v 1.5 2003/07/26 19:25:02 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(logbf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fxtract - fstp %st - XMM_FLOAT_EPILOGUE - ret -END(logbf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_logbl.S b/lib/libm/arch/i386/s_logbl.S deleted file mode 100644 index fcfbbe74be..0000000000 --- a/lib/libm/arch/i386/s_logbl.S +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_logbl.S,v 1.1 2011/08/03 14:13:07 joerg Exp - */ - -#include - -#include "abi.h" - -ENTRY(logbl) - fldt ARG_LONG_DOUBLE_ONE - fxtract - fstp %st - ret -END(logbl) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_modf.S b/lib/libm/arch/i386/s_modf.S deleted file mode 100644 index a038030e2e..0000000000 --- a/lib/libm/arch/i386/s_modf.S +++ /dev/null @@ -1,106 +0,0 @@ -/* $NetBSD: s_modf.S,v 1.1 2006/03/22 20:45:58 drochner Exp $ */ - -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sean Eric Fagan. - * - * 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. 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: @(#)modf.s 5.5 (Berkeley) 3/18/91 - */ - -#include - -/* - * modf(value, iptr): return fractional part of value, and stores the - * integral part into iptr (a pointer to double). - * - * Written by Sean Eric Fagan (sef@kithrup.COM) - * Sun Mar 11 20:27:30 PST 1990 - */ - -/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ -ENTRY(modf) -#ifdef __x86_64__ - pushq %rbp - movq %rsp,%rbp - subq $24,%rsp - - /* Set chop mode. */ - fnstcw -12(%rbp) - movw -12(%rbp),%dx - orw $3072,%dx - movw %dx,-16(%rbp) - fldcw -16(%rbp) - - /* Get integral part. */ - movsd %xmm0,-24(%rbp) - fldl -24(%rbp) - frndint - fstpl -8(%rbp) - - /* Restore control word. */ - fldcw -12(%rbp) - - /* Store integral part. */ - movsd -8(%rbp),%xmm0 - movsd %xmm0,(%rdi) - - /* Get fractional part and return it. */ - fldl -24(%rbp) - fsubl -8(%rbp) - fstpl -24(%rbp) - movsd -24(%rbp),%xmm0 -#else - pushl %ebp - movl %esp,%ebp - subl $16,%esp - fnstcw -12(%ebp) - movw -12(%ebp),%dx - orw $3072,%dx - movw %dx,-16(%ebp) - fldcw -16(%ebp) - fldl 8(%ebp) - frndint - fstpl -8(%ebp) - fldcw -12(%ebp) - movl 16(%ebp),%eax - movl -8(%ebp),%edx - movl -4(%ebp),%ecx - movl %edx,(%eax) - movl %ecx,4(%eax) - fldl 8(%ebp) - fsubl -8(%ebp) - jmp L1 -L1: -#endif - leave - ret -END(modf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_rint.S b/lib/libm/arch/i386/s_rint.S deleted file mode 100644 index ae756d2a92..0000000000 --- a/lib/libm/arch/i386/s_rint.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_rint.S,v 1.6 2003/07/26 19:25:03 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(rint) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - frndint - XMM_DOUBLE_EPILOGUE - ret -END(rint) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_rintf.S b/lib/libm/arch/i386/s_rintf.S deleted file mode 100644 index 85d29b14f0..0000000000 --- a/lib/libm/arch/i386/s_rintf.S +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_rintf.S,v 1.5 2003/07/26 19:25:03 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(rintf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - frndint - XMM_FLOAT_EPILOGUE - ret -END(rintf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_scalbn.S b/lib/libm/arch/i386/s_scalbn.S deleted file mode 100644 index 884be7154c..0000000000 --- a/lib/libm/arch/i386/s_scalbn.S +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_scalbn.S,v 1.9 2010/04/23 19:17:07 drochner Exp $ - */ - -#include - -ENTRY(scalbn) -#ifdef __x86_64__ - movl %edi,-12(%rsp) - fildl -12(%rsp) - movsd %xmm0,-8(%rsp) - fldl -8(%rsp) - fscale - fstpl -8(%rsp) - movsd -8(%rsp),%xmm0 - fstp %st(0) -#else - fildl 12(%esp) - fldl 4(%esp) - fscale - fstp %st(1) /* clean up stack */ -#endif - ret -END(scalbn) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_scalbnf.S b/lib/libm/arch/i386/s_scalbnf.S deleted file mode 100644 index b32fda117c..0000000000 --- a/lib/libm/arch/i386/s_scalbnf.S +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_scalbnf.S,v 1.8 2010/04/23 19:17:07 drochner Exp $ - */ - -#include - -ENTRY(scalbnf) -#ifdef __x86_64__ - movl %edi,-8(%rsp) - fildl -8(%rsp) - movss %xmm0,-4(%rsp) - flds -4(%rsp) - fscale - fstps -4(%rsp) - movss -4(%rsp),%xmm0 - fstp %st(0) -#else - fildl 8(%esp) - flds 4(%esp) - fscale - fstp %st(1) /* clean up stack */ -#endif - ret -END(scalbnf) - -.globl CNAME(ldexpf) -.set CNAME(ldexpf),CNAME(scalbnf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_significand.S b/lib/libm/arch/i386/s_significand.S deleted file mode 100644 index 58f67ba711..0000000000 --- a/lib/libm/arch/i386/s_significand.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_significand.S,v 1.6 2003/07/26 19:25:03 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(significand) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fxtract - fstp %st(1) - XMM_DOUBLE_EPILOGUE - ret -END(significand) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_significandf.S b/lib/libm/arch/i386/s_significandf.S deleted file mode 100644 index 7d1cb0b5e6..0000000000 --- a/lib/libm/arch/i386/s_significandf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_significandf.S,v 1.5 2003/07/26 19:25:03 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(significandf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fxtract - fstp %st(1) - XMM_FLOAT_EPILOGUE - ret -END(significandf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_sin.S b/lib/libm/arch/i386/s_sin.S deleted file mode 100644 index 3c011321cf..0000000000 --- a/lib/libm/arch/i386/s_sin.S +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_sin.S,v 1.7 2003/07/26 19:25:03 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(sin) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fsin - fnstsw %ax - andw $0x400,%ax - jnz 1f - XMM_DOUBLE_EPILOGUE - ret -1: fldpi - fadd %st(0) - fxch %st(1) -2: fprem1 - fnstsw %ax - andw $0x400,%ax - jnz 2b - fstp %st(1) - fsin - XMM_DOUBLE_EPILOGUE - ret -END(sin) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_sinf.S b/lib/libm/arch/i386/s_sinf.S deleted file mode 100644 index 5585bbd959..0000000000 --- a/lib/libm/arch/i386/s_sinf.S +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_sinf.S,v 1.5 2003/07/26 19:25:04 salo Exp $ - */ - -#include - -#include "abi.h" - -/* A float's domain isn't large enough to require argument reduction. */ -ENTRY(sinf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fsin - XMM_FLOAT_EPILOGUE - ret -END(sinf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_tan.S b/lib/libm/arch/i386/s_tan.S deleted file mode 100644 index c0c3611eb6..0000000000 --- a/lib/libm/arch/i386/s_tan.S +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_tan.S,v 1.7 2003/07/26 19:25:04 salo Exp $ - */ - -#include - -#include "abi.h" - -ENTRY(tan) - XMM_ONE_ARG_DOUBLE_PROLOGUE - fldl ARG_DOUBLE_ONE - fptan - fnstsw %ax - andw $0x400,%ax - jnz 1f - fstp %st(0) - XMM_DOUBLE_EPILOGUE - 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) - XMM_DOUBLE_EPILOGUE - ret -END(tan) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_tanf.S b/lib/libm/arch/i386/s_tanf.S deleted file mode 100644 index cd8f30cbc5..0000000000 --- a/lib/libm/arch/i386/s_tanf.S +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Written by J.T. Conklin . - * Public domain. - * - * $NetBSD: s_tanf.S,v 1.5 2003/07/26 19:25:04 salo Exp $ - */ - -#include - -#include "abi.h" - -/* A float's domain isn't large enough to require argument reduction. */ -ENTRY(tanf) - XMM_ONE_ARG_FLOAT_PROLOGUE - flds ARG_FLOAT_ONE - fptan - fstp %st(0) - XMM_FLOAT_EPILOGUE - ret -END(tanf) - - .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/x86_64/Makefile.inc b/lib/libm/arch/x86_64/Makefile.inc deleted file mode 100644 index 2b2164d1a6..0000000000 --- a/lib/libm/arch/x86_64/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -.PATH: ${.CURDIR}/arch/x86_64 - -SRCS+= fenv.c -INCS= fenv.h - -.include "${.CURDIR}/arch/i386/Makefile.inc" diff --git a/lib/libm/arch/x86_64/fenv.h b/lib/libm/arch/x86_64/fenv.h deleted file mode 100644 index 807971a4f4..0000000000 --- a/lib/libm/arch/x86_64/fenv.h +++ /dev/null @@ -1,217 +0,0 @@ -/*- - * Copyright (c) 2004-2005 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/msun/amd64/fenv.h,v 1.7 2010/02/03 20:23:47 kib Exp $ - */ - -#ifndef _FENV_H_ -#define _FENV_H_ - -#include -#include - -typedef struct { - struct { - __uint32_t __control; - __uint32_t __status; - __uint32_t __tag; - char __other[16]; - } __x87; - __uint32_t __mxcsr; -} 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) - -/* - * 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 - -__BEGIN_DECLS - -/* Default floating-point environment */ -extern const fenv_t __fe_dfl_env; -#define FE_DFL_ENV (&__fe_dfl_env) - -#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 __fnclex() __asm __volatile("fnclex") -#define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) -#define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) -#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw))) -#define __fwait() __asm __volatile("fwait") -#define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) -#define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) - -static __inline int -feclearexcept(int __excepts) -{ - fenv_t __env; - - if (__excepts == FE_ALL_EXCEPT) { - __fnclex(); - } else { - __fnstenv(&__env.__x87); - __env.__x87.__status &= ~__excepts; - __fldenv(__env.__x87); - } - __stmxcsr(&__env.__mxcsr); - __env.__mxcsr &= ~__excepts; - __ldmxcsr(__env.__mxcsr); - return (0); -} - -static __inline int -fegetexceptflag(fexcept_t *__flagp, int __excepts) -{ - __uint32_t __mxcsr; - __uint16_t __status; - - __stmxcsr(&__mxcsr); - __fnstsw(&__status); - *__flagp = (__mxcsr | __status) & __excepts; - return (0); -} - -int fesetexceptflag(const fexcept_t *__flagp, int __excepts); -int feraiseexcept(int __excepts); - -static __inline int -fetestexcept(int __excepts) -{ - __uint32_t __mxcsr; - __uint16_t __status; - - __stmxcsr(&__mxcsr); - __fnstsw(&__status); - return ((__status | __mxcsr) & __excepts); -} - -static __inline 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); -} - -static __inline int -fesetround(int __round) -{ - __uint32_t __mxcsr; - __uint16_t __control; - - if (__round & ~_ROUND_MASK) - return (-1); - - __fnstcw(&__control); - __control &= ~_ROUND_MASK; - __control |= __round; - __fldcw(__control); - - __stmxcsr(&__mxcsr); - __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); - __mxcsr |= __round << _SSE_ROUND_SHIFT; - __ldmxcsr(__mxcsr); - - return (0); -} - -int fegetenv(fenv_t *__envp); -int feholdexcept(fenv_t *__envp); - -static __inline int -fesetenv(const fenv_t *__envp) -{ - - /* - * 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(__envp->__x87); - __ldmxcsr(__envp->__mxcsr); - return (0); -} - -int feupdateenv(const fenv_t *__envp); - -#if __BSD_VISIBLE - -int feenableexcept(int __mask); -int fedisableexcept(int __mask); - -static __inline 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); -} - -#endif /* __BSD_VISIBLE */ - -__END_DECLS - -#endif /* !_FENV_H_ */ diff --git a/lib/libm/src/b_exp.c b/lib/libm/bsdsrc/b_exp.c similarity index 91% rename from lib/libm/src/b_exp.c rename to lib/libm/bsdsrc/b_exp.c index bc74ad4061..ed0a6c70ec 100644 --- a/lib/libm/src/b_exp.c +++ b/lib/libm/bsdsrc/b_exp.c @@ -10,11 +10,7 @@ * 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 + * 3. 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. * @@ -30,10 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 226414 (2011-10-16) + * @(#)exp.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: head/lib/msun/bsdsrc/b_exp.c 226414 2011-10-16 05:37:20Z das $ */ -/* @(#)exp.c 8.1 (Berkeley) 6/4/93 */ /* EXP(X) * RETURN THE EXPONENTIAL OF X diff --git a/lib/libm/src/b_log.c b/lib/libm/bsdsrc/b_log.c similarity index 86% rename from lib/libm/src/b_log.c rename to lib/libm/bsdsrc/b_log.c index a212083bb3..4f97ba2828 100644 --- a/lib/libm/src/b_log.c +++ b/lib/libm/bsdsrc/b_log.c @@ -10,11 +10,7 @@ * 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 + * 3. 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. * @@ -30,11 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 176449 (2008-02-22) + * @(#)log.c 8.2 (Berkeley) 11/30/93 + * $FreeBSD: head/lib/msun/bsdsrc/b_log.c 176449 2008-02-22 02:26:51Z das $ */ -/* @(#)log.c 8.2 (Berkeley) 11/30/93 */ - #include #include @@ -355,71 +350,6 @@ static double logF_tail[N+1] = { -.00000000000017239444525614834 }; -#if 0 -double -#ifdef _ANSI_SOURCE -log(double x) -#else -log(x) double x; -#endif -{ - int m, j; - double F, f, g, q, u, u2, v, zero = 0.0, one = 1.0; - volatile double u1; - - /* Catch special cases */ - if (x <= 0) - if (x == zero) /* log(0) = -Inf */ - return (-one/zero); - else /* log(neg) = NaN */ - return (zero/zero); - else if (!finite(x)) - return (x+x); /* x = NaN, Inf */ - - /* Argument reduction: 1 <= g < 2; x/2^m = g; */ - /* y = F*(1 + f/F) for |f| <= 2^-8 */ - - m = logb(x); - g = ldexp(x, -m); - if (m == -1022) { - j = logb(g), m += j; - g = ldexp(g, -j); - } - j = N*(g-1) + .5; - F = (1.0/N) * j + 1; /* F*128 is an integer in [128, 512] */ - f = g - F; - - /* Approximate expansion for log(1+f/F) ~= u + q */ - g = 1/(2*F+f); - u = 2*f*g; - v = u*u; - q = u*v*(A1 + v*(A2 + v*(A3 + v*A4))); - - /* case 1: u1 = u rounded to 2^-43 absolute. Since u < 2^-8, - * u1 has at most 35 bits, and F*u1 is exact, as F has < 8 bits. - * It also adds exactly to |m*log2_hi + log_F_head[j] | < 750 - */ - if (m | j) - u1 = u + 513, u1 -= 513; - - /* case 2: |1-x| < 1/256. The m- and j- dependent terms are zero; - * u1 = u to 24 bits. - */ - else - u1 = u, TRUNC(u1); - u2 = (2.0*(f - F*u1) - u1*f) * g; - /* u1 + u2 = 2f/(2F+f) to extra precision. */ - - /* log(x) = log(2^m*F*(1+f/F)) = */ - /* (m*log2_hi+logF_head[j]+u1) + (m*log2_lo+logF_tail[j]+q); */ - /* (exact) + (tiny) */ - - u1 += m*logF_head[N] + logF_head[j]; /* exact */ - u2 = (u2 + logF_tail[j]) + q; /* tiny */ - u2 += logF_tail[N]*m; - return (u1 + u2); -} -#endif /* * Extra precision variant, returning struct {double a, b;}; diff --git a/lib/libm/src/b_tgamma.c b/lib/libm/bsdsrc/b_tgamma.c similarity index 95% rename from lib/libm/src/b_tgamma.c rename to lib/libm/bsdsrc/b_tgamma.c index 453286b38c..7d4e424281 100644 --- a/lib/libm/src/b_tgamma.c +++ b/lib/libm/bsdsrc/b_tgamma.c @@ -10,11 +10,7 @@ * 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 + * 3. 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. * @@ -30,8 +26,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)gamma.c 8.1 (Berkeley) 6/4/93 - * FreeBSD SVN: 176449 (2008-02-22) + * @(#)gamma.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: head/lib/msun/bsdsrc/b_tgamma.c 176449 2008-02-22 02:26:51Z das $ */ /* diff --git a/lib/libm/src/mathimpl.h b/lib/libm/bsdsrc/mathimpl.h similarity index 86% rename from lib/libm/src/mathimpl.h rename to lib/libm/bsdsrc/mathimpl.h index dc719cd824..132c28222e 100644 --- a/lib/libm/src/mathimpl.h +++ b/lib/libm/bsdsrc/mathimpl.h @@ -10,11 +10,7 @@ * 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 + * 3. 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. * @@ -31,15 +27,14 @@ * SUCH DAMAGE. * * @(#)mathimpl.h 8.1 (Berkeley) 6/4/93 - * FreeBSD SVN: 152566 (2005-11-18) + * $FreeBSD: head/lib/msun/bsdsrc/mathimpl.h 152566 2005-11-18 05:03:12Z bde $ */ #ifndef _MATHIMPL_H_ #define _MATHIMPL_H_ #include - -#include "math_private.h" +#include "../src/math_private.h" /* * TRUNC() is a macro that sets the trailing 27 bits in the mantissa of an diff --git a/lib/libm/complex/Makefile.inc b/lib/libm/complex/Makefile.inc deleted file mode 100644 index 34d6133165..0000000000 --- a/lib/libm/complex/Makefile.inc +++ /dev/null @@ -1,42 +0,0 @@ -# $NetBSD: Makefile.inc,v 1.2 2008/03/08 14:21:41 drochner Exp $ - -.PATH: ${.CURDIR}/complex - -SRCS+= cabs.c cabsf.c w_cabsl.c -SRCS+= carg.c cargf.c s_cargl.c -SRCS+= creal.c crealf.c creall.c -SRCS+= cimag.c cimagf.c cimagl.c -SRCS+= conj.c conjf.c conjl.c -SRCS+= cproj.c cprojf.c cprojl.c -SRCS+= csqrt.c csqrtf.c s_csqrtl.c -SRCS+= cexp.c cexpf.c -SRCS+= clog.c clogf.c -SRCS+= cpow.c cpowf.c -SRCS+= cephes_subr.c cephes_subrf.c -SRCS+= csin.c csinf.c -SRCS+= ccos.c ccosf.c -SRCS+= ctan.c ctanf.c -SRCS+= csinh.c csinhf.c -SRCS+= ccosh.c ccoshf.c -SRCS+= ctanh.c ctanhf.c -SRCS+= casin.c casinf.c -SRCS+= cacos.c cacosf.c -SRCS+= catan.c catanf.c -SRCS+= casinh.c casinhf.c -SRCS+= cacosh.c cacoshf.c -SRCS+= catanh.c catanhf.c - -MAN+= cacos.3 cacosh.3 carg.3 casin.3 casinh.3 catan.3 catanh.3 -MAN+= ccos.3 ccosh.3 cexp.3 cimag.3 clog.3 conj.3 cpow.3 cproj.3 creal.3 -MAN+= csin.3 csinh.3 csqrt.3 ctan.3 ctanh.3 - -MLINKS+= cacos.3 cacosf.3 cacosh.3 cacoshf.3 -MLINKS+= carg.3 cargf.3 carg.3 cargl.3 -MLINKS+= casin.3 casinf.3 casinh.3 casinhf.3 -MLINKS+= catan.3 catanf.3 catanh.3 catanhf.3 ccos.3 ccosf.3 -MLINKS+= ccosh.3 ccoshf.3 cexp.3 cexpf.3 cimag.3 cimagf.3 cimag.3 cimagl.3 -MLINKS+= clog.3 clogf.3 conj.3 conjf.3 conj.3 conjl.3 cpow.3 cpowf.3 -MLINKS+= cproj.3 cprojf.3 cproj.3 cprojl.3 -MLINKS+= creal.3 crealf.3 creal.3 creall.3 csin.3 csinf.3 csinh.3 csinhf.3 -MLINKS+= csqrt.3 csqrtf.3 csqrt.3 csqrtl.3 -MLINKS+= ctan.3 ctanf.3 ctanh.3 ctanhf.3 diff --git a/lib/libm/complex/cabs.c b/lib/libm/complex/cabs.c deleted file mode 100644 index f37f27cd0c..0000000000 --- a/lib/libm/complex/cabs.c +++ /dev/null @@ -1,16 +0,0 @@ -/* $NetBSD: cabs.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include - -double -cabs(double complex z) -{ - - return hypot(__real__ z, __imag__ z); -} diff --git a/lib/libm/complex/cabsf.c b/lib/libm/complex/cabsf.c deleted file mode 100644 index 00b63132a3..0000000000 --- a/lib/libm/complex/cabsf.c +++ /dev/null @@ -1,16 +0,0 @@ -/* $NetBSD: cabsf.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include - -float -cabsf(float complex z) -{ - - return hypotf(__real__ z, __imag__ z); -} diff --git a/lib/libm/complex/cacos.3 b/lib/libm/complex/cacos.3 deleted file mode 100644 index 2e6fb5a2e4..0000000000 --- a/lib/libm/complex/cacos.3 +++ /dev/null @@ -1,57 +0,0 @@ -.\" $NetBSD: cacos.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CACOS" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cacos -.SH NAME -cacos, cacosf \- complex arc cosine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex cacos(double complex\fP \fIz\fP\fB); -.br -float complex cacosf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc cosine of \fIz\fP, with -branch cuts outside the interval [-1,\ +1] along the -real axis. -.SH RETURN VALUE -.LP -These functions return the complex arc cosine value, in the -range of a strip mathematically unbounded along the imaginary -axis and in the interval [0,\ pi] along the real axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIccos\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cacos.c b/lib/libm/complex/cacos.c deleted file mode 100644 index 328a18d1ee..0000000000 --- a/lib/libm/complex/cacos.c +++ /dev/null @@ -1,44 +0,0 @@ -/* $NetBSD: cacos.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -cacos(double complex z) -{ - double complex w; - - w = casin(z); - w = (M_PI_2 - creal(w)) - cimag(w) * I; - return w; -} diff --git a/lib/libm/complex/cacosf.c b/lib/libm/complex/cacosf.c deleted file mode 100644 index 8411e58ff5..0000000000 --- a/lib/libm/complex/cacosf.c +++ /dev/null @@ -1,44 +0,0 @@ -/* $NetBSD: cacosf.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -cacosf(float complex z) -{ - float complex w; - - w = casinf(z); - w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I; - return w; -} diff --git a/lib/libm/complex/cacosh.3 b/lib/libm/complex/cacosh.3 deleted file mode 100644 index 422e45a672..0000000000 --- a/lib/libm/complex/cacosh.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: cacosh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CACOSH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cacosh -.SH NAME -cacosh, cacoshf \- complex arc hyperbolic cosine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex cacosh(double complex\fP \fIz\fP\fB); -.br -float complex cacoshf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc hyperbolic cosine of -\fIz\fP, with a branch cut at values less than 1 along the -real axis. -.SH RETURN VALUE -.LP -These functions return the complex arc hyperbolic cosine value, -in the range of a half-strip of non-negative values along -the real axis and in the interval [-\fIi\fPpi,\ +\fIi\fPpi] along -the imaginary axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIccosh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cacosh.c b/lib/libm/complex/cacosh.c deleted file mode 100644 index fcfb365bea..0000000000 --- a/lib/libm/complex/cacosh.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $NetBSD: cacosh.c,v 1.2 2009/08/03 19:41:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include - -double complex -cacosh(double complex z) -{ - double complex w; - -#if 0 /* does not give the principal value */ - w = I * cacos(z); -#else - w = clog(z + csqrt(z + 1) * csqrt(z - 1)); -#endif - return w; -} diff --git a/lib/libm/complex/cacoshf.c b/lib/libm/complex/cacoshf.c deleted file mode 100644 index 76295d5972..0000000000 --- a/lib/libm/complex/cacoshf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* $NetBSD: cacoshf.c,v 1.2 2009/08/03 19:41:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include - -float complex -cacoshf(float complex z) -{ - float complex w; - -#if 0 /* does not give the principal value */ - w = I * cacosf(z); -#else - w = clogf(z + csqrtf(z + 1) * csqrtf(z - 1)); -#endif - return w; -} diff --git a/lib/libm/complex/carg.3 b/lib/libm/complex/carg.3 deleted file mode 100644 index 4e3516f59f..0000000000 --- a/lib/libm/complex/carg.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: carg.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CARG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" carg -.SH NAME -carg, cargf, cargl \- complex argument functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double carg(double complex\fP \fIz\fP\fB); -.br -float cargf(float complex\fP \fIz\fP\fB); -.br -long double cargl(long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the argument (also called phase angle) -of \fIz\fP, with a branch cut along the negative real -axis. -.SH RETURN VALUE -.LP -These functions return the value of the argument in the interval -[-pi,\ +pi]. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcimag\fP(), \fIconj\fP(), \fIcproj\fP(), the -Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/carg.c b/lib/libm/complex/carg.c deleted file mode 100644 index a91758f51d..0000000000 --- a/lib/libm/complex/carg.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: carg.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - - -#include -#include - -double -carg(double complex z) -{ - - return atan2(__imag__ z, __real__ z); -} diff --git a/lib/libm/complex/cargf.c b/lib/libm/complex/cargf.c deleted file mode 100644 index 119555aed2..0000000000 --- a/lib/libm/complex/cargf.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: cargf.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - - -#include -#include - -float -cargf(float complex z) -{ - - return atan2f(__imag__ z, __real__ z); -} diff --git a/lib/libm/complex/casin.3 b/lib/libm/complex/casin.3 deleted file mode 100644 index 66319e3264..0000000000 --- a/lib/libm/complex/casin.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: casin.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CASIN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" casin -.SH NAME -casin, casinf \- complex arc sine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex casin(double complex\fP \fIz\fP\fB); -.br -float complex casinf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc sine of \fIz\fP, with -branch cuts outside the interval [-1,\ +1] along the -real axis. -.SH RETURN VALUE -.LP -These functions return the complex arc sine value, in the range -of a strip mathematically unbounded along the imaginary -axis and in the interval [-pi/2,\ +pi/2] along the -real axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcsin\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/casin.c b/lib/libm/complex/casin.c deleted file mode 100644 index 92010b99eb..0000000000 --- a/lib/libm/complex/casin.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $NetBSD: casin.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -#ifdef __weak_alias -__weak_alias(casin, _casin) -#endif - -double complex -casin(double complex z) -{ - double complex w; - double complex ca, ct, zz, z2; - double x, y; - - x = creal(z); - y = cimag(z); - -#if 0 /* MD: test is incorrect, casin(>1) is defined */ - if (y == 0.0) { - if (fabs(x) > 1.0) { - w = M_PI_2 + 0.0 * I; -#if 0 - mtherr ("casin", DOMAIN); -#endif - } else { - w = asin(x) + 0.0 * I; - } - return w; - } -#endif - -/* Power series expansion */ -/* -b = cabs(z); -if( b < 0.125 ) -{ -z2.r = (x - y) * (x + y); -z2.i = 2.0 * x * y; - -cn = 1.0; -n = 1.0; -ca.r = x; -ca.i = y; -sum.r = x; -sum.i = y; -do - { - ct.r = z2.r * ca.r - z2.i * ca.i; - ct.i = z2.r * ca.i + z2.i * ca.r; - ca.r = ct.r; - ca.i = ct.i; - - cn *= n; - n += 1.0; - cn /= n; - n += 1.0; - b = cn/n; - - ct.r *= b; - ct.i *= b; - sum.r += ct.r; - sum.i += ct.i; - b = fabs(ct.r) + fabs(ct.i); - } -while( b > MACHEP ); -w->r = sum.r; -w->i = sum.i; -return; -} -*/ - - - ca = x + y * I; - ct = ca * I; - /* sqrt( 1 - z*z) */ - /* cmul( &ca, &ca, &zz ) */ - /*x * x - y * y */ - zz = (x - y) * (x + y) + (2.0 * x * y) * I; - - zz = 1.0 - creal(zz) - cimag(zz) * I; - z2 = csqrt(zz); - - zz = ct + z2; - zz = clog(zz); - /* multiply by 1/i = -i */ - w = zz * (-1.0 * I); - return w; -} diff --git a/lib/libm/complex/casinf.c b/lib/libm/complex/casinf.c deleted file mode 100644 index f123199eca..0000000000 --- a/lib/libm/complex/casinf.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $NetBSD: casinf.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -#ifdef __weak_alias -__weak_alias(casinf, _casinf) -#endif - -float complex -casinf(float complex z) -{ - float complex w; - float complex ca, ct, zz, z2; - float x, y; - - x = crealf(z); - y = cimagf(z); - -#if 0 /* MD: test is incorrect, casin(>1) is defined */ - if (y == 0.0f) { - if (fabsf(x) > 1.0) { - w = M_PI_2 + 0.0f * I; -#if 0 - mtherr ("casin", DOMAIN); -#endif - } else { - w = asinf(x) + 0.0f * I; - } - return w; - } -#endif - -/* Power series expansion */ -/* -b = cabsf(z); -if( b < 0.125 ) -{ -z2.r = (x - y) * (x + y); -z2.i = 2.0 * x * y; - -cn = 1.0; -n = 1.0; -ca.r = x; -ca.i = y; -sum.r = x; -sum.i = y; -do - { - ct.r = z2.r * ca.r - z2.i * ca.i; - ct.i = z2.r * ca.i + z2.i * ca.r; - ca.r = ct.r; - ca.i = ct.i; - - cn *= n; - n += 1.0; - cn /= n; - n += 1.0; - b = cn/n; - - ct.r *= b; - ct.i *= b; - sum.r += ct.r; - sum.i += ct.i; - b = fabsf(ct.r) + fabsf(ct.i); - } -while( b > MACHEP ); -w->r = sum.r; -w->i = sum.i; -return; -} -*/ - - - ca = x + y * I; - ct = ca * I; - /* sqrt( 1 - z*z) */ - /* cmul( &ca, &ca, &zz ) */ - /*x * x - y * y */ - zz = (x - y) * (x + y) + (2.0f * x * y) * I; - - zz = 1.0f - crealf(zz) - cimagf(zz) * I; - z2 = csqrtf(zz); - - zz = ct + z2; - zz = clogf(zz); - /* multiply by 1/i = -i */ - w = zz * (-1.0f * I); - return w; -} diff --git a/lib/libm/complex/casinh.3 b/lib/libm/complex/casinh.3 deleted file mode 100644 index 666f265f32..0000000000 --- a/lib/libm/complex/casinh.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: casinh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CASINH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" casinh -.SH NAME -casinh, casinhf \- complex arc hyperbolic sine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex casinh(double complex\fP \fIz\fP\fB); -.br -float complex casinhf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc hyperbolic sine of \fIz\fP, -with branch cuts outside the interval -[-\fIi\fP,\ +\fIi\fP] along the imaginary axis. -.SH RETURN VALUE -.LP -These functions return the complex arc hyperbolic sine value, -in the range of a strip mathematically unbounded along the -real axis and in the interval [-\fIi\fPpi/2,\ +\fIi\fPpi/2] along -the imaginary axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcsinh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/casinh.c b/lib/libm/complex/casinh.c deleted file mode 100644 index 1e88095fa0..0000000000 --- a/lib/libm/complex/casinh.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: casinh.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include - -double complex -casinh(double complex z) -{ - double complex w; - - w = -1.0 * I * casin(z * I); - return w; -} diff --git a/lib/libm/complex/casinhf.c b/lib/libm/complex/casinhf.c deleted file mode 100644 index 8d4c8a490f..0000000000 --- a/lib/libm/complex/casinhf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: casinhf.c,v 1.1 2007/08/20 16:01:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include - -float complex -casinhf(float complex z) -{ - float complex w; - - w = -1.0f * I * casinf(z * I); - return w; -} diff --git a/lib/libm/complex/catan.3 b/lib/libm/complex/catan.3 deleted file mode 100644 index a030ece492..0000000000 --- a/lib/libm/complex/catan.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: catan.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CATAN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" catan -.SH NAME -catan, catanf \- complex arc tangent functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex catan(double complex\fP \fIz\fP\fB); -.br -float complex catanf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc tangent of \fIz\fP, -with branch cuts outside the interval -[-\fIi\fP,\ +\fIi\fP] along the imaginary axis. -.SH RETURN VALUE -.LP -These functions return the complex arc tangent value, in the -range of a strip mathematically unbounded along the imaginary -axis and in the interval [-pi/2,\ +pi/2] along the -real axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIctan\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/catan.c b/lib/libm/complex/catan.c deleted file mode 100644 index f0c18512c0..0000000000 --- a/lib/libm/complex/catan.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $NetBSD: catan.c,v 1.2 2011/07/03 06:45:24 mrg Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include -#include "cephes_subr.h" - -#ifdef __weak_alias -__weak_alias(catan, _catan) -#endif - -#define MAXNUM DBL_MAX - -double complex -catan(double complex z) -{ - double complex w; - double a, t, x, x2, y; - - x = creal(z); - y = cimag(z); - - if ((x == 0.0) && (y > 1.0)) - goto ovrf; - - x2 = x * x; - a = 1.0 - x2 - (y * y); - if (a == 0.0) - goto ovrf; - - t = 0.5 * atan2(2.0 * x, a); - w = _redupi(t); - - t = y - 1.0; - a = x2 + (t * t); - if (a == 0.0) - goto ovrf; - - t = y + 1.0; - a = (x2 + (t * t))/a; - w = w + (0.25 * log(a)) * I; - return w; - -ovrf: -#if 0 - mtherr ("catan", OVERFLOW); -#endif - w = MAXNUM + MAXNUM * I; - return w; -} diff --git a/lib/libm/complex/catanf.c b/lib/libm/complex/catanf.c deleted file mode 100644 index 7a4f86b38a..0000000000 --- a/lib/libm/complex/catanf.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $NetBSD: catanf.c,v 1.2 2011/07/03 06:45:24 mrg Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include -#include "cephes_subrf.h" - -#ifdef __weak_alias -__weak_alias(catanf, _catanf) -#endif - -#define MAXNUMF FLT_MAX - -float complex -catanf(float complex z) -{ - float complex w; - float a, t, x, x2, y; - - x = crealf(z); - y = cimagf(z); - - if ((x == 0.0f) && (y > 1.0f)) - goto ovrf; - - x2 = x * x; - a = 1.0f - x2 - (y * y); - if (a == 0.0f) - goto ovrf; - - t = 0.5f * atan2f(2.0f * x, a); - w = _redupif(t); - - t = y - 1.0f; - a = x2 + (t * t); - if (a == 0.0f) - goto ovrf; - - t = y + 1.0f; - a = (x2 + (t * t))/a; - w = w + (0.25f * logf(a)) * I; - return w; - -ovrf: -#if 0 - mtherr ("catan", OVERFLOW); -#endif - w = MAXNUMF + MAXNUMF * I; - return w; -} diff --git a/lib/libm/complex/catanh.3 b/lib/libm/complex/catanh.3 deleted file mode 100644 index 489ca8878c..0000000000 --- a/lib/libm/complex/catanh.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: catanh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CATANH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" catanh -.SH NAME -catanh, catanhf \- complex arc hyperbolic tangent functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex catanh(double complex\fP \fIz\fP\fB); -.br -float complex catanhf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex arc hyperbolic tangent of -\fIz\fP, with branch cuts outside the interval -[-1,\ +1] along the real axis. -.SH RETURN VALUE -.LP -These functions return the complex arc hyperbolic tangent value, -in the range of a strip mathematically unbounded along -the real axis and in the interval [-\fIi\fPpi/2,\ +\fIi\fPpi/2] along -the imaginary axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIctanh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/catanh.c b/lib/libm/complex/catanh.c deleted file mode 100644 index 99b3fbb8d4..0000000000 --- a/lib/libm/complex/catanh.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: catanh.c,v 1.1 2007/08/20 16:01:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include - -double complex -catanh(double complex z) -{ - double complex w; - - w = -1.0 * I * catan(z * I); - return w; -} diff --git a/lib/libm/complex/catanhf.c b/lib/libm/complex/catanhf.c deleted file mode 100644 index 094a2b64fe..0000000000 --- a/lib/libm/complex/catanhf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: catanhf.c,v 1.1 2007/08/20 16:01:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include - -float complex -catanhf(float complex z) -{ - float complex w; - - w = -1.0f * I * catanf(z * I); - return w; -} diff --git a/lib/libm/complex/ccos.3 b/lib/libm/complex/ccos.3 deleted file mode 100644 index c952a83cf0..0000000000 --- a/lib/libm/complex/ccos.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: ccos.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CCOS" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" ccos -.SH NAME -ccos, ccosf \- complex cosine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex ccos(double complex\fP \fIz\fP\fB); -.br -float complex ccosf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex cosine of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex cosine value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcacos\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/ccos.c b/lib/libm/complex/ccos.c deleted file mode 100644 index 4b92ea44a5..0000000000 --- a/lib/libm/complex/ccos.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: ccos.c,v 1.1 2007/08/20 16:01:32 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subr.h" - -double complex -ccos(double complex z) -{ - double complex w; - double ch, sh; - - _cchsh(cimag(z), &ch, &sh); - w = cos(creal(z)) * ch - (sin(creal(z)) * sh) * I; - return w; -} diff --git a/lib/libm/complex/ccosf.c b/lib/libm/complex/ccosf.c deleted file mode 100644 index 32abc63f82..0000000000 --- a/lib/libm/complex/ccosf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: ccosf.c,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subrf.h" - -float complex -ccosf(float complex z) -{ - float complex w; - float ch, sh; - - _cchshf(cimagf(z), &ch, &sh); - w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I; - return w; -} diff --git a/lib/libm/complex/ccosh.3 b/lib/libm/complex/ccosh.3 deleted file mode 100644 index e073360b93..0000000000 --- a/lib/libm/complex/ccosh.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: ccosh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CCOSH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" ccosh -.SH NAME -ccosh, ccoshf \- complex hyperbolic cosine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex ccosh(double complex\fP \fIz\fP\fB); -.br -float complex ccoshf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex hyperbolic cosine of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex hyperbolic cosine value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcacosh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/ccosh.c b/lib/libm/complex/ccosh.c deleted file mode 100644 index 1a5c91319b..0000000000 --- a/lib/libm/complex/ccosh.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: ccosh.c,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -ccosh(double complex z) -{ - double complex w; - double x, y; - - x = creal(z); - y = cimag(z); - w = cosh(x) * cos(y) + (sinh(x) * sin(y)) * I; - return w; -} diff --git a/lib/libm/complex/ccoshf.c b/lib/libm/complex/ccoshf.c deleted file mode 100644 index 690c8bca9b..0000000000 --- a/lib/libm/complex/ccoshf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: ccoshf.c,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -ccoshf(float complex z) -{ - float complex w; - float x, y; - - x = crealf(z); - y = cimagf(z); - w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I; - return w; -} diff --git a/lib/libm/complex/cephes_subr.c b/lib/libm/complex/cephes_subr.c deleted file mode 100644 index c6e14912df..0000000000 --- a/lib/libm/complex/cephes_subr.c +++ /dev/null @@ -1,124 +0,0 @@ -/* $NetBSD: cephes_subr.c,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subr.h" - -/* calculate cosh and sinh */ - -void -_cchsh(double x, double *c, double *s) -{ - double e, ei; - - if (fabs(x) <= 0.5) { - *c = cosh(x); - *s = sinh(x); - } else { - e = exp(x); - ei = 0.5 / e; - e = 0.5 * e; - *s = e - ei; - *c = e + ei; - } -} - -/* Program to subtract nearest integer multiple of PI */ - -/* extended precision value of PI: */ -static const double DP1 = 3.14159265160560607910E0; -static const double DP2 = 1.98418714791870343106E-9; -static const double DP3 = 1.14423774522196636802E-17; -#define MACHEP 1.1e-16 - -double -_redupi(double x) -{ - double t; - long i; - - t = x / M_PI; - if (t >= 0.0) - t += 0.5; - else - t -= 0.5; - - i = t; /* the multiple */ - t = i; - t = ((x - t * DP1) - t * DP2) - t * DP3; - return t; -} - -/* Taylor series expansion for cosh(2y) - cos(2x) */ - -double -_ctans(double complex z) -{ - double f, x, x2, y, y2, rn, t; - double d; - - x = fabs(2.0 * creal(z)); - y = fabs(2.0 * cimag(z)); - - x = _redupi(x); - - x = x * x; - y = y * y; - x2 = 1.0; - y2 = 1.0; - f = 1.0; - rn = 0.0; - d = 0.0; - do { - rn += 1.0; - f *= rn; - rn += 1.0; - f *= rn; - x2 *= x; - y2 *= y; - t = y2 + x2; - t /= f; - d += t; - - rn += 1.0; - f *= rn; - rn += 1.0; - f *= rn; - x2 *= x; - y2 *= y; - t = y2 - x2; - t /= f; - d += t; - } while (fabs(t/d) > MACHEP); - return d; -} diff --git a/lib/libm/complex/cephes_subr.h b/lib/libm/complex/cephes_subr.h deleted file mode 100644 index 7d230525f3..0000000000 --- a/lib/libm/complex/cephes_subr.h +++ /dev/null @@ -1,5 +0,0 @@ -/* $NetBSD: cephes_subr.h,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ - -void _cchsh(double, double *, double *); -double _redupi(double); -double _ctans(double complex); diff --git a/lib/libm/complex/cephes_subrf.c b/lib/libm/complex/cephes_subrf.c deleted file mode 100644 index 6b0192ff42..0000000000 --- a/lib/libm/complex/cephes_subrf.c +++ /dev/null @@ -1,123 +0,0 @@ -/* $NetBSD: cephes_subrf.c,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subrf.h" - -/* calculate cosh and sinh */ - -void -_cchshf(float x, float *c, float *s) -{ - float e, ei; - - if (fabsf(x) <= 0.5f) { - *c = coshf(x); - *s = sinhf(x); - } else { - e = expf(x); - ei = 0.5f / e; - e = 0.5f * e; - *s = e - ei; - *c = e + ei; - } -} - -/* Program to subtract nearest integer multiple of PI */ - -/* extended precision value of PI: */ -static const double DP1 = 3.140625; -static const double DP2 = 9.67502593994140625E-4; -static const double DP3 = 1.509957990978376432E-7; -#define MACHEPF 3.0e-8 - -float -_redupif(float x) -{ - float t; - long i; - - t = x / (float)M_PI; - if (t >= 0.0f) - t += 0.5f; - else - t -= 0.5f; - - i = t; /* the multiple */ - t = i; - t = ((x - t * DP1) - t * DP2) - t * DP3; - return t; -} - -/* Taylor series expansion for cosh(2y) - cos(2x) */ - -float -_ctansf(float complex z) -{ - float f, x, x2, y, y2, rn, t, d; - - x = fabsf(2.0f * crealf(z)); - y = fabsf(2.0f * cimagf(z)); - - x = _redupif(x); - - x = x * x; - y = y * y; - x2 = 1.0f; - y2 = 1.0f; - f = 1.0f; - rn = 0.0f; - d = 0.0f; - do { - rn += 1.0f; - f *= rn; - rn += 1.0f; - f *= rn; - x2 *= x; - y2 *= y; - t = y2 + x2; - t /= f; - d += t; - - rn += 1.0f; - f *= rn; - rn += 1.0f; - f *= rn; - x2 *= x; - y2 *= y; - t = y2 - x2; - t /= f; - d += t; - } while (fabsf(t/d) > MACHEPF); - return d; -} diff --git a/lib/libm/complex/cephes_subrf.h b/lib/libm/complex/cephes_subrf.h deleted file mode 100644 index 81aec46304..0000000000 --- a/lib/libm/complex/cephes_subrf.h +++ /dev/null @@ -1,5 +0,0 @@ -/* $NetBSD: cephes_subrf.h,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ - -void _cchshf(float, float *, float *); -float _redupif(float); -float _ctansf(float complex); diff --git a/lib/libm/complex/cexp.3 b/lib/libm/complex/cexp.3 deleted file mode 100644 index 71c170b908..0000000000 --- a/lib/libm/complex/cexp.3 +++ /dev/null @@ -1,54 +0,0 @@ -.\" $NetBSD: cexp.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CEXP" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cexp -.SH NAME -cexp, cexpf \- complex exponential functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex cexp(double complex\fP \fIz\fP\fB); -.br -float complex cexpf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex exponent of \fIz\fP, defined -as \fIe**z\fP. -.SH RETURN VALUE -.LP -These functions return the complex exponential value of \fIz\fP. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIclog\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cexp.c b/lib/libm/complex/cexp.c deleted file mode 100644 index e329110429..0000000000 --- a/lib/libm/complex/cexp.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $NetBSD: cexp.c,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -cexp(double complex z) -{ - double complex w; - double r, x, y; - - x = creal(z); - y = cimag(z); - r = exp(x); - w = r * cos(y) + r * sin(y) * I; - return w; -} diff --git a/lib/libm/complex/cexpf.c b/lib/libm/complex/cexpf.c deleted file mode 100644 index ba7390b90d..0000000000 --- a/lib/libm/complex/cexpf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $NetBSD: cexpf.c,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -cexpf(float complex z) -{ - float complex w; - float r, x, y; - - x = crealf(z); - y = cimagf(z); - r = expf(x); - w = r * cosf(y) + r * sinf(y) * I; - return w; -} diff --git a/lib/libm/complex/cimag.3 b/lib/libm/complex/cimag.3 deleted file mode 100644 index e6fc1e8bc4..0000000000 --- a/lib/libm/complex/cimag.3 +++ /dev/null @@ -1,63 +0,0 @@ -.\" $NetBSD: cimag.3,v 1.3 2010/09/15 18:40:27 wiz Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CIMAG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cimag -.SH NAME -cimag, cimagf \- complex imaginary functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double cimag(double complex\fP \fIz\fP\fB); -.br -float cimagf(float complex\fP \fIz\fP\fB); -.br -long double cimagl(long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the imaginary part of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the imaginary part value (as a real). -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -For a variable \fIz\fP of complex type: -.sp -.RS -.nf - -\fBz == creal(z) + cimag(z)*I -\fP -.fi -.RE -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcarg\fP(), \fIconj\fP(), \fIcproj\fP(), \fIcreal\fP(), the -Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cimag.c b/lib/libm/complex/cimag.c deleted file mode 100644 index 5e98447c4f..0000000000 --- a/lib/libm/complex/cimag.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: cimag.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -double -cimag(double complex z) -{ - double_complex w = { .z = z }; - - return (IMAG_PART(w)); -} diff --git a/lib/libm/complex/cimagf.c b/lib/libm/complex/cimagf.c deleted file mode 100644 index a82d696fbe..0000000000 --- a/lib/libm/complex/cimagf.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: cimagf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -float -cimagf(float complex z) -{ - float_complex w = { .z = z }; - - return (IMAG_PART(w)); -} diff --git a/lib/libm/complex/cimagl.c b/lib/libm/complex/cimagl.c deleted file mode 100644 index f325db619f..0000000000 --- a/lib/libm/complex/cimagl.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: cimagl.c,v 1.3 2010/09/20 16:55:20 christos 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. - */ - -#include -#include "../src/math_private.h" - -/* - * cimagl(long double complex z) - * This function returns the imaginary part value (as a real) of z. - */ -long double -cimagl(long double complex z) -{ - long_double_complex w = { .z = z }; - - return (IMAG_PART(w)); -} diff --git a/lib/libm/complex/clog.3 b/lib/libm/complex/clog.3 deleted file mode 100644 index d5460e4077..0000000000 --- a/lib/libm/complex/clog.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: clog.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CLOG" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" clog -.SH NAME -clog, clogf \- complex natural logarithm functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex clog(double complex\fP \fIz\fP\fB); -.br -float complex clogf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex natural (base \fIe\fP) logarithm -of \fIz\fP, with a branch cut along the negative -real axis. -.SH RETURN VALUE -.LP -These functions return the complex natural logarithm value, -in the range of a strip mathematically unbounded along the -real axis and in the interval [-\fIi\fPpi,\ +\fIi\fPpi] along the -imaginary axis. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcexp\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/clog.c b/lib/libm/complex/clog.c deleted file mode 100644 index 2165f63a57..0000000000 --- a/lib/libm/complex/clog.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $NetBSD: clog.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -clog(double complex z) -{ - double complex w; - double p, rr; - - rr = cabs(z); - p = log(rr); - rr = atan2(cimag(z), creal(z)); - w = p + rr * I; - return w; -} diff --git a/lib/libm/complex/clogf.c b/lib/libm/complex/clogf.c deleted file mode 100644 index 1c718baf1e..0000000000 --- a/lib/libm/complex/clogf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $NetBSD: clogf.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -clogf(float complex z) -{ - float complex w; - float p, rr; - - rr = cabsf(z); - p = logf(rr); - rr = atan2f(cimagf(z), crealf(z)); - w = p + rr * I; - return w; -} diff --git a/lib/libm/complex/conj.3 b/lib/libm/complex/conj.3 deleted file mode 100644 index 6f0fe7818b..0000000000 --- a/lib/libm/complex/conj.3 +++ /dev/null @@ -1,56 +0,0 @@ -.\" $NetBSD: conj.3,v 1.3 2010/09/15 18:40:27 wiz Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CONJ" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" conj -.SH NAME -conj, conjf \- complex conjugate functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex conj(double complex\fP \fIz\fP\fB); -.br -float complex conjf(float complex\fP \fIz\fP\fB); -.br -long double complex conjl(long double complex\fP \fIz\fP\fB, long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex conjugate of \fIz\fP, by -reversing the sign of its imaginary part. -.SH RETURN VALUE -.LP -These functions return the complex conjugate value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcarg\fP(), \fIcimag\fP(), \fIcproj\fP(), \fIcreal\fP(), the -Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/conj.c b/lib/libm/complex/conj.c deleted file mode 100644 index ba8713dda5..0000000000 --- a/lib/libm/complex/conj.c +++ /dev/null @@ -1,19 +0,0 @@ -/* $NetBSD: conj.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -double complex -conj(double complex z) -{ - double_complex w = { .z = z }; - - IMAG_PART(w) = -IMAG_PART(w); - - return (w.z); -} diff --git a/lib/libm/complex/conjf.c b/lib/libm/complex/conjf.c deleted file mode 100644 index 4b7dacb4fa..0000000000 --- a/lib/libm/complex/conjf.c +++ /dev/null @@ -1,19 +0,0 @@ -/* $NetBSD: conjf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -float complex -conjf(float complex z) -{ - float_complex w = { .z = z }; - - IMAG_PART(w) = -IMAG_PART(w); - - return (w.z); -} diff --git a/lib/libm/complex/conjl.c b/lib/libm/complex/conjl.c deleted file mode 100644 index fdabb3fb54..0000000000 --- a/lib/libm/complex/conjl.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: conjl.c,v 1.4 2010/09/20 16:55:20 christos 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. - */ - -#include -#include - -#include "../src/math_private.h" - -/* - * conjl(long double complex z) - * This function returns the complex conjugate value of its argument, z. - */ -long double complex -conjl(long double complex z) -{ - long_double_complex w = { .z = z }; - - IMAG_PART(w) = -IMAG_PART(w); - - return (w.z); -} diff --git a/lib/libm/complex/cpow.3 b/lib/libm/complex/cpow.3 deleted file mode 100644 index 5c78e368ca..0000000000 --- a/lib/libm/complex/cpow.3 +++ /dev/null @@ -1,57 +0,0 @@ -.\" $NetBSD: cpow.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CPOW" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cpow -.SH NAME -cpow, cpowf \- complex power functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex cpow(double complex\fP \fIx\fP\fB, double complex\fP -\fIy\fP\fB); -.br -float complex cpowf(float complex\fP \fIx\fP\fB, float complex\fP -\fIy\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex power function \fIx**y\fP, -with a branch cut for the first -parameter along the negative real axis. -.SH RETURN VALUE -.LP -These functions return the complex power function value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcabs\fP(), \fIcsqrt\fP(), the Base Definitions volume of -IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cpow.c b/lib/libm/complex/cpow.c deleted file mode 100644 index e9e1179910..0000000000 --- a/lib/libm/complex/cpow.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $NetBSD: cpow.c,v 1.1 2007/08/20 16:01:35 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -cpow(double complex a, double complex z) -{ - double complex w; - double x, y, r, theta, absa, arga; - - x = creal(z); - y = cimag(z); - absa = cabs(a); - if (absa == 0.0) { - return (0.0 + 0.0 * I); - } - arga = carg(a); - r = pow(absa, x); - theta = x * arga; - if (y != 0.0) { - r = r * exp(-y * arga); - theta = theta + y * log(absa); - } - w = r * cos(theta) + (r * sin(theta)) * I; - return w; -} diff --git a/lib/libm/complex/cpowf.c b/lib/libm/complex/cpowf.c deleted file mode 100644 index c195ffa4c1..0000000000 --- a/lib/libm/complex/cpowf.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $NetBSD: cpowf.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -cpowf(float complex a, float complex z) -{ - float complex w; - float x, y, r, theta, absa, arga; - - x = crealf(z); - y = cimagf(z); - absa = cabsf(a); - if (absa == 0.0f) { - return (0.0f + 0.0f * I); - } - arga = cargf(a); - r = powf(absa, x); - theta = x * arga; - if (y != 0.0f) { - r = r * expf(-y * arga); - theta = theta + y * logf(absa); - } - w = r * cosf(theta) + (r * sinf(theta)) * I; - return w; -} diff --git a/lib/libm/complex/cproj.3 b/lib/libm/complex/cproj.3 deleted file mode 100644 index b122374a58..0000000000 --- a/lib/libm/complex/cproj.3 +++ /dev/null @@ -1,59 +0,0 @@ -.\" $NetBSD: cproj.3,v 1.3 2011/11/29 13:17:04 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CPROJ" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" cproj -.SH NAME -cproj, cprojf, cprojl \- complex projection functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double cproj(double complex\fP \fIz\fP\fB); -.br -float cprojf(float complex\fP \fIz\fP\fB); -.br -long double cprojl(long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute a projection of \fIz\fP onto the Riemann sphere: -\fIz\fP projects to \fIz\fP , except that all complex infinities (even those -with one infinite part and one NaN part) project to positive infinity on the -real axis. If \fIz\fP has an infinite part, then cproj(z) shall be equivalent to: -INFINITY + I * copysign(0.0, cimag(z)) -.SH RETURN VALUE -.LP -These functions return the value of the projection onto the Riemann sphere. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcarg\fP(), \fIcimag\fP(), \fIconj\fP(), \fIcreal\fP() the -Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/cproj.c b/lib/libm/complex/cproj.c deleted file mode 100644 index af84a76ee3..0000000000 --- a/lib/libm/complex/cproj.c +++ /dev/null @@ -1,62 +0,0 @@ -/* $NetBSD: cproj.c,v 1.5 2011/11/02 02:34:56 christos 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. - */ - -#include -#include - -#include "../src/math_private.h" - -/* - * cproj(double complex z) - * - * These functions return the value of the projection (not stereographic!) - * onto the Riemann sphere. - * - * z projects to z, except that all complex infinities (even those with one - * infinite part and one NaN part) project to positive infinity on the real axis. - * If z has an infinite part, then cproj(z) shall be equivalent to: - * - * INFINITY + I * copysign(0.0, cimag(z)) - */ -double complex -cproj(double complex z) -{ - double_complex w = { .z = z }; - - /*CONSTCOND*/ - if (isinf(creal(z)) || isinf(cimag(z))) { -#ifdef __INFINITY - REAL_PART(w) = HUGE_VAL; -#else - REAL_PART(w) = INFINITY; -#endif - IMAG_PART(w) = copysign(0.0, cimag(z)); - } - - return (w.z); -} diff --git a/lib/libm/complex/cprojf.c b/lib/libm/complex/cprojf.c deleted file mode 100644 index 6747d1e267..0000000000 --- a/lib/libm/complex/cprojf.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $NetBSD: cprojf.c,v 1.5 2011/11/02 02:34:56 christos 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. - */ - -#include -#include - -#include "../src/math_private.h" - -/* - * cprojf(float complex z) - * - * These functions return the value of the projection (not stereographic!) - * onto the Riemann sphere. - * - * z projects to z, except that all complex infinities (even those with one - * infinite part and one NaN part) project to positive infinity on the real axis. - * If z has an infinite part, then cproj(z) shall be equivalent to: - * - * INFINITY + I * copysign(0.0, cimag(z)) - */ - -float complex -cprojf(float complex z) -{ - float_complex w = { .z = z }; - - /*CONSTCOND*/ - if (isinf(crealf(z)) || isinf(cimagf(z))) { -#ifdef __INFINITY - REAL_PART(w) = HUGE_VAL; -#else - REAL_PART(w) = INFINITY; -#endif - IMAG_PART(w) = copysignf(0.0, cimagf(z)); - } - - return (w.z); -} diff --git a/lib/libm/complex/cprojl.c b/lib/libm/complex/cprojl.c deleted file mode 100644 index 378b330ae7..0000000000 --- a/lib/libm/complex/cprojl.c +++ /dev/null @@ -1,62 +0,0 @@ -/* $NetBSD: cprojl.c,v 1.6 2011/11/02 02:34:56 christos 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. - */ - -#include -#include - -#include "../src/math_private.h" - -/* - * cprojl(long double complex z) - * - * These functions return the value of the projection (not stereographic!) - * onto the Riemann sphere. - * - * z projects to z, except that all complex infinities (even those with one - * infinite part and one NaN part) project to positive infinity on the real axis. - * If z has an infinite part, then cproj(z) shall be equivalent to: - * - * INFINITY + I * copysign(0.0, cimag(z)) - */ -long double complex -cprojl(long double complex z) -{ - long_double_complex w = { .z = z }; - - /*CONSTCOND*/ - if (isinf(creall(z)) || isinf(cimagl(z))) { -#ifdef __INFINITY - REAL_PART(w) = HUGE_VAL; -#else - REAL_PART(w) = INFINITY; -#endif - IMAG_PART(w) = copysignl(0.0, cimagl(z)); - } - - return (w.z); -} diff --git a/lib/libm/complex/creal.3 b/lib/libm/complex/creal.3 deleted file mode 100644 index ff6ecc0fbe..0000000000 --- a/lib/libm/complex/creal.3 +++ /dev/null @@ -1,63 +0,0 @@ -.\" $NetBSD: creal.3,v 1.3 2010/09/15 18:40:27 wiz Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CREAL" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" creal -.SH NAME -creal, crealf \- complex real functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double creal(double complex\fP \fIz\fP\fB); -.br -float crealf(float complex\fP \fIz\fP\fB); -.br -long double creall(long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the real part of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the real part value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -For a variable \fIz\fP of type \fBcomplex\fP: -.sp -.RS -.nf - -\fBz == creal(z) + cimag(z)*I -\fP -.fi -.RE -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcarg\fP(), \fIcimag\fP(), \fIconj\fP(), \fIcproj\fP(), the -Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/creal.c b/lib/libm/complex/creal.c deleted file mode 100644 index 98c5cb5a19..0000000000 --- a/lib/libm/complex/creal.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: creal.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -double -creal(double complex z) -{ - double_complex w = { .z = z }; - - return (REAL_PART(w)); -} diff --git a/lib/libm/complex/crealf.c b/lib/libm/complex/crealf.c deleted file mode 100644 index 5499c8de92..0000000000 --- a/lib/libm/complex/crealf.c +++ /dev/null @@ -1,17 +0,0 @@ -/* $NetBSD: crealf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ - -/* - * Written by Matthias Drochner . - * Public domain. - */ - -#include -#include "../src/math_private.h" - -float -crealf(float complex z) -{ - float_complex w = { .z = z }; - - return (REAL_PART(w)); -} diff --git a/lib/libm/complex/creall.c b/lib/libm/complex/creall.c deleted file mode 100644 index 543e90b2c0..0000000000 --- a/lib/libm/complex/creall.c +++ /dev/null @@ -1,42 +0,0 @@ -/* $NetBSD: creall.c,v 1.3 2010/09/20 16:55:20 christos 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. - */ - -#include -#include "../src/math_private.h" - -/* - * creall(long double complex z) - * This function returns the real part value of z. - */ -long double -creall(long double complex z) -{ - long_double_complex w = { .z = z }; - - return (REAL_PART(w)); -} diff --git a/lib/libm/complex/csin.3 b/lib/libm/complex/csin.3 deleted file mode 100644 index 69394eb21a..0000000000 --- a/lib/libm/complex/csin.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: csin.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CSIN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" csin -.SH NAME -csin, csinf \- complex sine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex csin(double complex\fP \fIz\fP\fB); -.br -float complex csinf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex sine of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex sine value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcasin\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/csin.c b/lib/libm/complex/csin.c deleted file mode 100644 index e09b5cbf03..0000000000 --- a/lib/libm/complex/csin.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: csin.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subr.h" - -double complex -csin(double complex z) -{ - double complex w; - double ch, sh; - - _cchsh(cimag(z), &ch, &sh); - w = sin(creal(z)) * ch + (cos(creal(z)) * sh) * I; - return w; -} diff --git a/lib/libm/complex/csinf.c b/lib/libm/complex/csinf.c deleted file mode 100644 index 4ff8fed320..0000000000 --- a/lib/libm/complex/csinf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: csinf.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include -#include "cephes_subrf.h" - -float complex -csinf(float complex z) -{ - float complex w; - float ch, sh; - - _cchshf(cimagf(z), &ch, &sh); - w = sinf(crealf(z)) * ch + (cosf(crealf(z)) * sh) * I; - return w; -} diff --git a/lib/libm/complex/csinh.3 b/lib/libm/complex/csinh.3 deleted file mode 100644 index ad2e2226c4..0000000000 --- a/lib/libm/complex/csinh.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: csinh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CSINH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" csinh -.SH NAME -csinh, csinhf \- complex hyperbolic sine functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex csinh(double complex\fP \fIz\fP\fB); -.br -float complex csinhf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex hyperbolic sine of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex hyperbolic sine value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcasinh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/csinh.c b/lib/libm/complex/csinh.c deleted file mode 100644 index 6845e5e796..0000000000 --- a/lib/libm/complex/csinh.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: csinh.c,v 1.1 2007/08/20 16:01:36 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -csinh(double complex z) -{ - double complex w; - double x, y; - - x = creal(z); - y = cimag(z); - w = sinh(x) * cos(y) + (cosh(x) * sin(y)) * I; - return w; -} diff --git a/lib/libm/complex/csinhf.c b/lib/libm/complex/csinhf.c deleted file mode 100644 index 0bbe5a3b2b..0000000000 --- a/lib/libm/complex/csinhf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: csinhf.c,v 1.1 2007/08/20 16:01:37 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -csinhf(float complex z) -{ - float complex w; - float x, y; - - x = crealf(z); - y = cimagf(z); - w = sinhf(x) * cosf(y) + (coshf(x) * sinf(y)) * I; - return w; -} diff --git a/lib/libm/complex/csqrt.3 b/lib/libm/complex/csqrt.3 deleted file mode 100644 index 5eb62d9334..0000000000 --- a/lib/libm/complex/csqrt.3 +++ /dev/null @@ -1,58 +0,0 @@ -.\" $NetBSD: csqrt.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CSQRT" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" csqrt -.SH NAME -csqrt, csqrtf, csqrtl \- complex square root functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex csqrt(double complex\fP \fIz\fP\fB); -.br -float complex csqrtf(float complex\fP \fIz\fP\fB); -.br -long double complex csqrtl(long double complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex square root of \fIz\fP, -with a branch cut along the negative real axis. -.SH RETURN VALUE -.LP -These functions return the complex square root value, in the -range of the right half-plane (including the imaginary -axis). -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcabs\fP(), \fIcpow\fP(), the Base Definitions volume of -IEEE\ Std\ 1003.1-2001, \fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/csqrt.c b/lib/libm/complex/csqrt.c deleted file mode 100644 index f9267ec13d..0000000000 --- a/lib/libm/complex/csqrt.c +++ /dev/null @@ -1,99 +0,0 @@ -/* $NetBSD: csqrt.c,v 1.1 2007/08/20 16:01:37 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include -#include - -double complex -csqrt(double complex z) -{ - double complex w; - double x, y, r, t, scale; - - x = creal (z); - y = cimag (z); - - if (y == 0.0) { - if (x == 0.0) { - w = 0.0 + y * I; - } else { - r = fabs(x); - r = sqrt(r); - if (x < 0.0) { - w = 0.0 + r * I; - } else { - w = r + y * I; - } - } - return w; - } - if (x == 0.0) { - r = fabs(y); - r = sqrt(0.5 * r); - if (y > 0) - w = r + r * I; - else - w = r - r * I; - return w; - } - /* Rescale to avoid internal overflow or underflow. */ - if ((fabs(x) > 4.0) || (fabs(y) > 4.0)) { - x *= 0.25; - y *= 0.25; - scale = 2.0; - } else { -#if 1 - x *= 1.8014398509481984e16; /* 2^54 */ - y *= 1.8014398509481984e16; - scale = 7.450580596923828125e-9; /* 2^-27 */ -#else - x *= 4.0; - y *= 4.0; - scale = 0.5; -#endif - } - w = x + y * I; - r = cabs(w); - if (x > 0) { - t = sqrt(0.5 * r + 0.5 * x); - r = scale * fabs((0.5 * y) / t ); - t *= scale; - } else { - r = sqrt(0.5 * r - 0.5 * x); - t = scale * fabs((0.5 * y) / r); - r *= scale; - } - if (y < 0) - w = t - r * I; - else - w = t + r * I; - return w; -} diff --git a/lib/libm/complex/csqrtf.c b/lib/libm/complex/csqrtf.c deleted file mode 100644 index a230430a87..0000000000 --- a/lib/libm/complex/csqrtf.c +++ /dev/null @@ -1,99 +0,0 @@ -/* $NetBSD: csqrtf.c,v 1.1 2007/08/20 16:01:37 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include -#include - -float complex -csqrtf(float complex z) -{ - float complex w; - float x, y, r, t, scale; - - x = crealf (z); - y = cimagf (z); - - if (y == 0.0f) { - if (x < 0.0f) { - w = 0.0f + sqrtf(-x) * I; - return w; - } else if (x == 0.0f) { - return (0.0f + y * I); - } else { - w = sqrtf(x) + y * I; - return w; - } - } - - if (x == 0.0f) { - r = fabsf(y); - r = sqrtf(0.5f * r); - if (y > 0) - w = r + r * I; - else - w = r - r * I; - return w; - } - - /* Rescale to avoid internal overflow or underflow. */ - if ((fabsf(x) > 4.0f) || (fabsf(y) > 4.0f)) { - x *= 0.25f; - y *= 0.25f; - scale = 2.0f; - } else { -#if 1 - x *= 6.7108864e7f; /* 2^26 */ - y *= 6.7108864e7f; - scale = 1.220703125e-4f; /* 2^-13 */ -#else - x *= 4.0f; - y *= 4.0f; - scale = 0.5f; -#endif - } - w = x + y * I; - r = cabsf(w); - if( x > 0 ) { - t = sqrtf(0.5f * r + 0.5f * x); - r = scale * fabsf((0.5f * y) / t); - t *= scale; - } else { - r = sqrtf(0.5f * r - 0.5f * x); - t = scale * fabsf((0.5f * y) / r); - r *= scale; - } - - if (y < 0) - w = t - r * I; - else - w = t + r * I; - return w; -} diff --git a/lib/libm/complex/ctan.3 b/lib/libm/complex/ctan.3 deleted file mode 100644 index 02293c9773..0000000000 --- a/lib/libm/complex/ctan.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: ctan.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CTAN" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" ctan -.SH NAME -ctan, ctanf \- complex tangent functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex ctan(double complex\fP \fIz\fP\fB); -.br -float complex ctanf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex tangent of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex tangent value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcatan\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/ctan.c b/lib/libm/complex/ctan.c deleted file mode 100644 index 41cbbb5842..0000000000 --- a/lib/libm/complex/ctan.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: ctan.c,v 1.2 2011/07/03 06:45:24 mrg Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include -#include -#include -#include "cephes_subr.h" - -#define MAXNUM DBL_MAX - -double complex -ctan(double complex z) -{ - double complex w; - double d; - - d = cos(2.0 * creal(z)) + cosh(2.0 * cimag(z)); - - if (fabs(d) < 0.25) - d = _ctans(z); - - if (d == 0.0) { - /* mtherr ("ctan", OVERFLOW); */ - w = MAXNUM + MAXNUM * I; - return w; - } - - w = sin(2.0 * creal(z)) / d + (sinh(2.0 * cimag(z)) / d) * I; - return w; -} diff --git a/lib/libm/complex/ctanf.c b/lib/libm/complex/ctanf.c deleted file mode 100644 index f9b92ebf63..0000000000 --- a/lib/libm/complex/ctanf.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $NetBSD: ctanf.c,v 1.2 2011/07/03 06:45:24 mrg Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - -#include -#include -#include -#include "cephes_subrf.h" - -#define MAXNUMF FLT_MAX - -float complex -ctanf(float complex z) -{ - float complex w; - float d; - - d = cosf(2.0f * crealf(z)) + coshf(2.0f * cimagf(z)); - - if (fabsf(d) < 0.25f) - d = _ctansf(z); - - if (d == 0.0f) { - /* mtherr ("ctan", OVERFLOW); */ - w = MAXNUMF + MAXNUMF * I; - return w; - } - - w = sinf(2.0f * crealf(z)) / d + (sinhf(2.0f * cimagf(z)) / d) * I; - return w; -} diff --git a/lib/libm/complex/ctanh.3 b/lib/libm/complex/ctanh.3 deleted file mode 100644 index 85c976e3f2..0000000000 --- a/lib/libm/complex/ctanh.3 +++ /dev/null @@ -1,53 +0,0 @@ -.\" $NetBSD: ctanh.3,v 1.1 2008/02/20 09:55:38 drochner Exp $ -.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved -.TH "CTANH" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" -.\" ctanh -.SH NAME -ctanh, ctanhf \- complex hyperbolic tangent functions -.SH SYNOPSIS -.LP -\fB#include -.br -.sp -double complex ctanh(double complex\fP \fIz\fP\fB); -.br -float complex ctanhf(float complex\fP \fIz\fP\fB); -.br -\fP -.SH DESCRIPTION -.LP -These functions compute the complex hyperbolic tangent of \fIz\fP. -.SH RETURN VALUE -.LP -These functions return the complex hyperbolic tangent value. -.SH ERRORS -.LP -No errors are defined. -.LP -\fIThe following sections are informative.\fP -.SH EXAMPLES -.LP -None. -.SH APPLICATION USAGE -.LP -None. -.SH RATIONALE -.LP -None. -.SH FUTURE DIRECTIONS -.LP -None. -.SH SEE ALSO -.LP -\fIcatanh\fP(), the Base Definitions volume of IEEE\ Std\ 1003.1-2001, -\fI\fP -.SH COPYRIGHT -Portions of this text are reprinted and reproduced in electronic form -from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology --- Portable Operating System Interface (POSIX), The Open Group Base -Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of -Electrical and Electronics Engineers, Inc and The Open Group. In the -event of any discrepancy between this version and the original IEEE and -The Open Group Standard, the original IEEE and The Open Group Standard -is the referee document. The original Standard can be obtained online at -http://www.opengroup.org/unix/online.html . diff --git a/lib/libm/complex/ctanh.c b/lib/libm/complex/ctanh.c deleted file mode 100644 index 34c976a07a..0000000000 --- a/lib/libm/complex/ctanh.c +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: ctanh.c,v 1.1 2007/08/20 16:01:38 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -double complex -ctanh(double complex z) -{ - double complex w; - double x, y, d; - - x = creal(z); - y = cimag(z); - d = cosh(2.0 * x) + cos(2.0 * y); - w = sinh(2.0 * x) / d + (sin(2.0 * y) / d) * I; - - return w; -} diff --git a/lib/libm/complex/ctanhf.c b/lib/libm/complex/ctanhf.c deleted file mode 100644 index d4197caae6..0000000000 --- a/lib/libm/complex/ctanhf.c +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: ctanhf.c,v 1.1 2007/08/20 16:01:38 drochner Exp $ */ - -/*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software written by Stephen L. Moshier. - * It is redistributed by the NetBSD Foundation by permission of the author. - * - * 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. - */ - - -#include -#include - -float complex -ctanhf(float complex z) -{ - float complex w; - float x, y, d; - - x = crealf(z); - y = cimagf(z); - d = coshf(2.0f * x) + cosf(2.0f * y); - w = sinhf(2.0f * x) / d + (sinf(2.0f * y) / d) * I; - - return w; -} diff --git a/lib/libm/gen/Makefile.inc b/lib/libm/gen/Makefile.inc deleted file mode 100644 index 0c63c22ca5..0000000000 --- a/lib/libm/gen/Makefile.inc +++ /dev/null @@ -1,9 +0,0 @@ -# $DragonFly: src/lib/libm/gen/Makefile.inc,v 1.1 2007/06/17 17:46:01 pavalos Exp $ - -.PATH: ${.CURDIR}/gen - -SRCS+= nan.c nanf.c nanl.c - -MAN+= nan.3 - -MLINKS+=nan.3 nanf.3 nan.3 nanl.3 diff --git a/lib/libm/gen/nan.3 b/lib/libm/gen/nan.3 deleted file mode 100644 index 9d979017d7..0000000000 --- a/lib/libm/gen/nan.3 +++ /dev/null @@ -1,101 +0,0 @@ -.\" -.\" Copyright (c) 2006 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein. -.\" -.\" 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 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. -.\" -.\" $NetBSD: nan.3,v 1.1 2006/03/15 22:07:09 kleink Exp $ -.\" $DragonFly: src/lib/libm/gen/nan.3,v 1.1 2007/06/17 17:46:01 pavalos Exp $ -.\" -.Dd March 15, 2006 -.Dt NAN 3 -.Os -.Sh NAME -.Nm nan , -.Nm nanf , -.Nm nanl -.Nd return quiet NaN -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft double -.Fn nan "const char *tagp" -.Ft float -.Fn nanf "const char *tagp" -.Ft long double -.Fn nanl "const char *tagp" -.Sh DESCRIPTION -The call -.Fn nan "\*qn-char-sequence\*q" -is equivalent to the call -.Fn strtod "\*qNAN(n-char-sequence)\*q" "NULL" . -The call -.Fn nan "\*q\*q" -is equivalent to the call -.Fn strtod "\*qNAN()\*q" "NULL" . -.Pp -The -.Fn nanf -and -.Fn nanl -functions are equivalent to -.Fn nan -but substituting -.Fn strtod . -.Sh RETURN VALUES -.Ss IEEE 754 -The -.Fn nan , -.Fn nanf , -and -.Fn nanl -functions return a quiet NaN as specified by -.Fa tagp . -.Ss VAX -The -.Fn nan , -.Fn nanf , -and -.Fn nanl -functions return zero. -.Sh SEE ALSO -.Xr math 3 , -.Xr strtod 3 -.Sh STANDARDS -The -.Fn nan , -.Fn nanf , -and -.Fn nanl -functions conform to -.St -isoC-99 . diff --git a/lib/libm/gen/nan.c b/lib/libm/gen/nan.c deleted file mode 100644 index 1046f82655..0000000000 --- a/lib/libm/gen/nan.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $NetBSD: nan.c,v 1.2 2008/04/28 20:23:01 martin Exp $ */ - -/*- - * Copyright (c) 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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. - */ - -#include -#include -#include -#include -#include - - -#ifndef NAN_FUNCTION -#define NAN_FUNCTION nan -#define NAN_TYPE double -#define NAN_STRTOD strtod -#endif - -NAN_TYPE -NAN_FUNCTION(const char *tagp) -{ - const char *nstr; - char *buf; - NAN_TYPE res; - - _DIAGASSERT(tagp != NULL); - - nstr = "NAN()"; - buf = NULL; - - if (tagp[0] != '\0') { - size_t l; - - l = strlen(tagp); - buf = malloc(5 + l + 1); - - if (buf != NULL) { - /* Avoiding stdio in libm. */ - memcpy(buf, "NAN(", 4); - memcpy(buf + 4, tagp, l); - memcpy(buf + 4 + l, ")", 2); - nstr = buf; - } else { - /* Best effort: Fall back to "NAN()". */ - } - } - - res = NAN_STRTOD(nstr, NULL); - - if (buf != NULL) - free(buf); - - return res; -} diff --git a/lib/libm/gen/nanf.c b/lib/libm/gen/nanf.c deleted file mode 100644 index e3c7527a6a..0000000000 --- a/lib/libm/gen/nanf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $NetBSD: nanf.c,v 1.2 2008/04/28 20:23:01 martin Exp $ */ - -/*- - * Copyright (c) 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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. - */ - -#define NAN_FUNCTION nanf -#define NAN_TYPE float -#define NAN_STRTOD strtof - -#include "nan.c" diff --git a/lib/libm/gen/nanl.c b/lib/libm/gen/nanl.c deleted file mode 100644 index 5452e487ba..0000000000 --- a/lib/libm/gen/nanl.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $NetBSD: nanl.c,v 1.2 2008/04/28 20:23:01 martin Exp $ */ - -/*- - * Copyright (c) 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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. - */ - -#define NAN_FUNCTION nanl -#define NAN_TYPE long double -#define NAN_STRTOD strtold - -#include "nan.c" diff --git a/lib/libm/i386/Makefile.inc b/lib/libm/i386/Makefile.inc new file mode 100644 index 0000000000..6769cee59e --- /dev/null +++ b/lib/libm/i386/Makefile.inc @@ -0,0 +1,18 @@ +# $FreeBSD: head/lib/msun/i387/Makefile.inc 177768 2008-03-30 21:21:53Z das $ + +ARCH_SRCS = e_exp.S e_fmod.S e_log.S e_log10.S \ + e_remainder.S e_sqrt.S s_ceil.S s_copysign.S \ + s_cos.S s_finite.S s_floor.S s_llrint.S s_logb.S s_lrint.S \ + s_remquo.S s_rint.S s_scalbn.S s_significand.S s_sin.S s_tan.S \ + s_trunc.S + +# float counterparts +ARCH_SRCS+= e_log10f.S e_logf.S e_remainderf.S \ + e_sqrtf.S s_ceilf.S s_copysignf.S s_floorf.S \ + s_llrintf.S s_logbf.S s_lrintf.S \ + s_remquof.S s_rintf.S s_scalbnf.S s_significandf.S s_truncf.S + +# long double counterparts +ARCH_SRCS+= e_remainderl.S e_sqrtl.S s_ceill.S s_copysignl.S \ + s_floorl.S s_llrintl.S \ + s_logbl.S s_lrintl.S s_remquol.S s_rintl.S s_scalbnl.S s_truncl.S diff --git a/lib/libm/arch/i386/e_exp.S b/lib/libm/i386/e_exp.S similarity index 70% rename from lib/libm/arch/i386/e_exp.S rename to lib/libm/i386/e_exp.S index 5f80f11160..a8b4d04c7d 100644 --- a/lib/libm/arch/i386/e_exp.S +++ b/lib/libm/i386/e_exp.S @@ -1,5 +1,3 @@ -/* $NetBSD: e_exp.S,v 1.14 2008/06/23 10:24:13 drochner Exp $ */ - /* * Copyright (c) 1993,94 Winning Strategies, Inc. * All rights reserved. @@ -28,6 +26,8 @@ * 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: head/lib/msun/i387/e_exp.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -37,37 +37,32 @@ #include -#include "abi.h" - - /* e^x = 2^(x * log2(e)) */ ENTRY(exp) - XMM_ONE_ARG_DOUBLE_PROLOGUE /* * If x is +-Inf, then the subtraction would give Inf-Inf = NaN. * Avoid this. Also avoid it if x is NaN for convenience. */ - movl ARG_DOUBLE_ONE_MSW, %eax - andl $0x7fffffff, %eax - cmpl $0x7ff00000, %eax + movl 8(%esp),%eax + andl $0x7fffffff,%eax + cmpl $0x7ff00000,%eax jae x_Inf_or_NaN - fldl ARG_DOUBLE_ONE + fldl 4(%esp) /* - * Ensure that the rounding mode is to nearest (to give the smallest - * possible fraction) and that the precision is as high as possible. - * We may as well mask interrupts if we switch the mode. + * 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. */ -#define CWSTORE_SAV ARG_DOUBLE_ONE_LSW /* XXX overwrites the argument */ -#define CWSTORE_TMP ARG_DOUBLE_ONE_MSW - fstcw CWSTORE_SAV - movl CWSTORE_SAV, %eax - andl $0x0f00, %eax - cmpl $0x0300, %eax /* RC == 0 && PC == 3? */ + 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, CWSTORE_TMP - fldcw CWSTORE_TMP + movl $0x137f,8(%esp) + fldcw 8(%esp) 1: fldl2e fmulp /* x * log2(e) */ @@ -75,32 +70,31 @@ ENTRY(exp) frndint /* int(x * log2(e)) */ fst %st(2) fsubrp /* fract(x * log2(e)) */ - f2xm1 /* 2^(fract(x * log2(e))) - 1 */ + f2xm1 /* 2^(fract(x * log2(e))) - 1 */ fld1 faddp /* 2^(fract(x * log2(e))) */ fscale /* e^x */ fstp %st(1) je 1f - fldcw CWSTORE_SAV + fldcw 4(%esp) 1: - XMM_DOUBLE_EPILOGUE ret + x_Inf_or_NaN: /* - * Return 0 if x is -Inf. Otherwise just return x, although the - * C version would return (x + x) (Real Indefinite) if x is a 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, ARG_DOUBLE_ONE_MSW + cmpl $0xfff00000,8(%esp) jne x_not_minus_Inf - cmpl $0, ARG_DOUBLE_ONE_LSW + cmpl $0,4(%esp) jne x_not_minus_Inf fldz - XMM_DOUBLE_EPILOGUE ret x_not_minus_Inf: - fldl ARG_DOUBLE_ONE - XMM_DOUBLE_EPILOGUE + fldl 4(%esp) ret END(exp) diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_fmod.S similarity index 91% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_fmod.S index 769e66060b..4686783453 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_fmod.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_fmod.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,15 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(fmod) + fldl 12(%esp) + fldl 4(%esp) +1: fprem + fstsw %ax + sahf + jp 1b + fstp %st(1) ret -#endif -END(sqrtl) +END(fmod) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_log.S similarity index 93% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_log.S index 769e66060b..20005dd2ec 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_log.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_log.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(log) + fldln2 + fldl 4(%esp) + fyl2x ret -#endif -END(sqrtl) +END(log) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_log10.S similarity index 93% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_log10.S index 769e66060b..ba41571505 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_log10.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_log10.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(log10) + fldlg2 + fldl 4(%esp) + fyl2x ret -#endif -END(sqrtl) +END(log10) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/e_log10f.S b/lib/libm/i386/e_log10f.S new file mode 100644 index 0000000000..f22207a704 --- /dev/null +++ b/lib/libm/i386/e_log10f.S @@ -0,0 +1,18 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/e_log10f.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: e_log10f.S,v 1.1 1996/07/03 16:50:22 jtc Exp $ + */ + +#include + +ENTRY(log10f) + fldlg2 + flds 4(%esp) + fyl2x + ret +END(log10f) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/e_logf.S b/lib/libm/i386/e_logf.S new file mode 100644 index 0000000000..f393ef7507 --- /dev/null +++ b/lib/libm/i386/e_logf.S @@ -0,0 +1,18 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/e_logf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: e_logf.S,v 1.2 1996/07/06 00:15:45 jtc Exp $ + */ + +#include + +ENTRY(logf) + fldln2 + flds 4(%esp) + fyl2x + ret +END(logf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_remainder.S similarity index 90% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_remainder.S index 769e66060b..99ea651f4d 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_remainder.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_remainder.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,15 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(remainder) + fldl 12(%esp) + fldl 4(%esp) +1: fprem1 + fstsw %ax + sahf + jp 1b + fstp %st(1) ret -#endif -END(sqrtl) +END(remainder) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/e_remainderf.S b/lib/libm/i386/e_remainderf.S new file mode 100644 index 0000000000..37e9d23991 --- /dev/null +++ b/lib/libm/i386/e_remainderf.S @@ -0,0 +1,22 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/e_remainderf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: e_remainderf.S,v 1.2 1995/05/08 23:49:47 jtc Exp $ + */ + +#include + +ENTRY(remainderf) + flds 8(%esp) + flds 4(%esp) +1: fprem1 + fstsw %ax + sahf + jp 1b + fstp %st(1) + ret +END(remainderf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_remainderl.S b/lib/libm/i386/e_remainderl.S similarity index 92% copy from lib/libm/arch/i386/e_remainderl.S copy to lib/libm/i386/e_remainderl.S index 3781ba941b..5994210489 100644 --- a/lib/libm/arch/i386/e_remainderl.S +++ b/lib/libm/i386/e_remainderl.S @@ -26,18 +26,18 @@ * 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: head/lib/msun/i387/e_remainderl.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Written by: * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - * FreeBSD SVN: 217108 (2011-01-07) */ #include ENTRY(remainderl) -#ifdef __i386__ fldt 16(%esp) fldt 4(%esp) 1: fprem1 @@ -46,16 +46,6 @@ ENTRY(remainderl) jp 1b fstp %st(1) ret -#else - fldt 24(%rsp) - fldt 8(%rsp) -1: fprem1 - fstsw %ax - testw $0x400,%ax - jne 1b - fstp %st(1) - ret -#endif END(remainderl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_sqrt.S similarity index 94% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_sqrt.S index 769e66060b..e34397d170 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_sqrt.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_sqrt.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,10 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) +ENTRY(sqrt) + fldl 4(%esp) fsqrt ret -#endif -END(sqrtl) +END(sqrt) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/e_sqrtf.S b/lib/libm/i386/e_sqrtf.S new file mode 100644 index 0000000000..3f9e5806d2 --- /dev/null +++ b/lib/libm/i386/e_sqrtf.S @@ -0,0 +1,17 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/e_sqrtf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: e_sqrtf.S,v 1.2 1995/05/08 23:50:14 jtc Exp $ + */ + +#include + +ENTRY(sqrtf) + flds 4(%esp) + fsqrt + ret +END(sqrtf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/e_sqrtl.S similarity index 95% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/e_sqrtl.S index 769e66060b..25da517bc2 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/e_sqrtl.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/e_sqrtl.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -36,15 +38,9 @@ #include ENTRY(sqrtl) -#ifdef __i386__ fldt 4(%esp) fsqrt ret -#else - fldt 8(%rsp) - fsqrt - ret -#endif END(sqrtl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/fenv.c b/lib/libm/i386/fenv.c similarity index 86% rename from lib/libm/arch/i386/fenv.c rename to lib/libm/i386/fenv.c index 52aa093898..062d65d6a2 100644 --- a/lib/libm/arch/i386/fenv.c +++ b/lib/libm/i386/fenv.c @@ -23,17 +23,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/i387/fenv.c,v 1.4 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: head/lib/msun/i387/fenv.c 226594 2011-10-21 06:25:31Z das $ */ #include #include + +#define __fenv_static #include "fenv.h" +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = { __INITIAL_NPXCW__, 0x0000, - 0x00001f80, + 0x0000, + 0x1f80, 0xffffffff, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } @@ -81,6 +88,9 @@ __test_sse(void) return (0); } +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { @@ -112,6 +122,10 @@ feraiseexcept(int excepts) return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { @@ -125,7 +139,7 @@ fegetenv(fenv_t *envp) __fldcw(envp->__control); if (__HAS_SSE()) { __stmxcsr(&mxcsr); - envp->__mxcsr = mxcsr; + __set_mxcsr(*envp, mxcsr); } return (0); } @@ -139,7 +153,7 @@ feholdexcept(fenv_t *envp) __fnclex(); if (__HAS_SSE()) { __stmxcsr(&mxcsr); - envp->__mxcsr = mxcsr; + __set_mxcsr(*envp, mxcsr); mxcsr &= ~FE_ALL_EXCEPT; mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); @@ -147,6 +161,8 @@ feholdexcept(fenv_t *envp) return (0); } +extern inline int fesetenv(const fenv_t *__envp); + int feupdateenv(const fenv_t *envp) { @@ -175,14 +191,14 @@ __feenableexcept(int mask) __stmxcsr(&mxcsr); else mxcsr = 0; - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); if (__HAS_SSE()) { mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); } - return (~omask); + return (omask); } int @@ -197,14 +213,14 @@ __fedisableexcept(int mask) __stmxcsr(&mxcsr); else mxcsr = 0; - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); if (__HAS_SSE()) { mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); } - return (~omask); + return (omask); } __weak_reference(__feenableexcept, feenableexcept); diff --git a/lib/libm/i386/invtrig.c b/lib/libm/i386/invtrig.c new file mode 100644 index 0000000000..0521d75a89 --- /dev/null +++ b/lib/libm/i386/invtrig.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/lib/msun/i387/invtrig.c 181152 2008-08-02 03:56:22Z das $ + */ + +#include + +#define STRUCT_DECLS +#include "invtrig.h" + +/* + * asinl() and acosl() + */ +const LONGDOUBLE +pS0 = { 0xaaaaaaaaaaaaaaa8ULL, 0x3ffcU }, /* 1.66666666666666666631e-01L */ +pS1 = { 0xd5271b6699b48bfaULL, 0xbffdU }, /* -4.16313987993683104320e-01L */ +pS2 = { 0xbcf67ca9e9f669cfULL, 0x3ffdU }, /* 3.69068046323246813704e-01L */ +pS3 = { 0x8b7baa3d15f9830dULL, 0xbffcU }, /* -1.36213932016738603108e-01L */ +pS4 = { 0x92154b093a3bff1cULL, 0x3ff9U }, /* 1.78324189708471965733e-02L */ +pS5 = { 0xe5dd76401964508cULL, 0xbff2U }, /* -2.19216428382605211588e-04L */ +pS6 = { 0xee69c5b0fdb76951ULL, 0xbfedU }, /* -7.10526623669075243183e-06L */ +qS1 = { 0xbcaa2159c01436a0ULL, 0xc000U }, /* -2.94788392796209867269e+00L */ +qS2 = { 0xd17a73d1e1564c29ULL, 0x4000U }, /* 3.27309890266528636716e+00L */ +qS3 = { 0xd767e411c9cf4c2cULL, 0xbfffU }, /* -1.68285799854822427013e+00L */ +qS4 = { 0xc809c0dfb9b0d0b7ULL, 0x3ffdU }, /* 3.90699412641738801874e-01L */ +qS5 = { 0x80c3a2197c8ced57ULL, 0xbffaU }; /* -3.14365703596053263322e-02L */ + +/* + * atanl() + */ +const LONGDOUBLE atanhi[] = { + { 0xed63382b0dda7b45ULL, 0x3ffdU }, /* 4.63647609000806116202e-01L */ + { 0xc90fdaa22168c235ULL, 0x3ffeU }, /* 7.85398163397448309628e-01L */ + { 0xfb985e940fb4d900ULL, 0x3ffeU }, /* 9.82793723247329067960e-01L */ + { 0xc90fdaa22168c235ULL, 0x3fffU }, /* 1.57079632679489661926e+00L */ +}; + +const LONGDOUBLE atanlo[] = { + { 0xdfc88bd978751a07ULL, 0x3fbcU }, /* 1.18469937025062860669e-20L */ + { 0xece675d1fc8f8cbbULL, 0xbfbcU }, /* -1.25413940316708300586e-20L */ + { 0xf10f5e197793c283ULL, 0x3fbdU }, /* 2.55232234165405176172e-20L */ + { 0xece675d1fc8f8cbbULL, 0xbfbdU }, /* -2.50827880633416601173e-20L */ +}; + +const LONGDOUBLE aT[] = { + { 0xaaaaaaaaaaaaaa9fULL, 0x3ffdU }, /* 3.33333333333333333017e-01L */ + { 0xcccccccccccc62bcULL, 0xbffcU }, /* -1.99999999999999632011e-01L */ + { 0x9249249248b81e3fULL, 0x3ffcU }, /* 1.42857142857046531280e-01L */ + { 0xe38e38e3316f3de5ULL, 0xbffbU }, /* -1.11111111100562372733e-01L */ + { 0xba2e8b8dc280726aULL, 0x3ffbU }, /* 9.09090902935647302252e-02L */ + { 0x9d89d5b4c6847ec4ULL, 0xbffbU }, /* -7.69230552476207730353e-02L */ + { 0x8888461d3099c677ULL, 0x3ffbU }, /* 6.66661718042406260546e-02L */ + { 0xf0e8ee0f5328dc29ULL, 0xbffaU }, /* -5.88158892835030888692e-02L */ + { 0xd73ea84d24bae54aULL, 0x3ffaU }, /* 5.25499891539726639379e-02L */ + { 0xc08fa381dcd9213aULL, 0xbffaU }, /* -4.70119845393155721494e-02L */ + { 0xa54a26f4095f2a3aULL, 0x3ffaU }, /* 4.03539201366454414072e-02L */ + { 0xeea2d8d059ef3ad6ULL, 0xbff9U }, /* -2.91303858419364158725e-02L */ + { 0xcc82292ab894b051ULL, 0x3ff8U }, /* 1.24822046299269234080e-02L */ +}; + +const LONGDOUBLE +pi_lo = { 0xece675d1fc8f8cbbULL, 0xbfbeU }; /* -5.01655761266833202345e-20L */ diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_ceil.S similarity index 80% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_ceil.S index 769e66060b..b25e0cdfb0 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_ceil.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_ceil.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,25 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +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 -#endif -END(sqrtl) +END(ceil) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_ceilf.S b/lib/libm/i386/s_ceilf.S similarity index 57% copy from lib/libm/arch/i386/s_ceilf.S copy to lib/libm/i386/s_ceilf.S index 3ed54e94e5..fc6b5ebed7 100644 --- a/lib/libm/arch/i386/s_ceilf.S +++ b/lib/libm/i386/s_ceilf.S @@ -1,14 +1,14 @@ /* - * Written by J.T. Conklin . + * Written by J.T. Conklin . * Public domain. * - * $NetBSD: s_ceilf.S,v 1.9 2011/06/18 21:24:51 joerg Exp $ + * $FreeBSD: head/lib/msun/i387/s_ceilf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_ceilf.S,v 1.3 1995/05/08 23:52:44 jtc Exp $ */ #include ENTRY(ceilf) -#ifdef __i386__ pushl %ebp movl %esp,%ebp subl $8,%esp @@ -26,20 +26,6 @@ ENTRY(ceilf) fldcw -4(%ebp) /* restore original control word */ leave -#else - fstcw -8(%rsp) - movw -8(%rsp),%dx - orw $0x0800,%dx - andw $0xfbff,%dx - movw %dx,-12(%rsp) - fldcw -12(%rsp) - movss %xmm0,-4(%rsp) - flds -4(%rsp) - frndint - fldcw -8(%rsp) - fstps -4(%rsp) - movss -4(%rsp),%xmm0 -#endif ret END(ceilf) diff --git a/lib/libm/arch/i386/s_ceilf.S b/lib/libm/i386/s_ceill.S similarity index 50% rename from lib/libm/arch/i386/s_ceilf.S rename to lib/libm/i386/s_ceill.S index 3ed54e94e5..fd7fcaf776 100644 --- a/lib/libm/arch/i386/s_ceilf.S +++ b/lib/libm/i386/s_ceill.S @@ -1,14 +1,13 @@ /* - * Written by J.T. Conklin . + * Based on code written by J.T. Conklin . * Public domain. * - * $NetBSD: s_ceilf.S,v 1.9 2011/06/18 21:24:51 joerg Exp $ + * $FreeBSD: head/lib/msun/i387/s_ceill.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(ceilf) -#ifdef __i386__ +ENTRY(ceill) pushl %ebp movl %esp,%ebp subl $8,%esp @@ -20,27 +19,13 @@ ENTRY(ceilf) movw %dx,-8(%ebp) fldcw -8(%ebp) /* load modfied control word */ - flds 8(%ebp) /* round */ + fldt 8(%ebp) /* round */ frndint fldcw -4(%ebp) /* restore original control word */ leave -#else - fstcw -8(%rsp) - movw -8(%rsp),%dx - orw $0x0800,%dx - andw $0xfbff,%dx - movw %dx,-12(%rsp) - fldcw -12(%rsp) - movss %xmm0,-4(%rsp) - flds -4(%rsp) - frndint - fldcw -8(%rsp) - fstps -4(%rsp) - movss -4(%rsp),%xmm0 -#endif ret -END(ceilf) +END(ceill) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_copysign.S similarity index 87% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_copysign.S index 769e66060b..526d045dfc 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_copysign.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_copysign.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,15 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +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 -#endif -END(sqrtl) +END(copysign) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_copysignf.S b/lib/libm/i386/s_copysignf.S new file mode 100644 index 0000000000..97b4de7e37 --- /dev/null +++ b/lib/libm/i386/s_copysignf.S @@ -0,0 +1,22 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_copysignf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_copysignf.S,v 1.3 1995/05/08 23:53:25 jtc Exp $ + */ + +#include + +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 +END(copysignf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_copysignl.S b/lib/libm/i386/s_copysignl.S new file mode 100644 index 0000000000..73e5e7026d --- /dev/null +++ b/lib/libm/i386/s_copysignl.S @@ -0,0 +1,21 @@ +/* + * Based on code written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_copysignl.S 217108 2011-01-07 16:13:12Z kib $ + */ + +#include + +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 +END(copysignl) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_cos.S similarity index 86% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_cos.S index 769e66060b..1af6031bf6 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_cos.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993,94 Winning Strategies, Inc. + * Copyright (c) 1994 Winning Strategies, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_cos.S 240566 2012-09-16 16:58:49Z tijl $ */ /* @@ -35,16 +37,23 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt +ENTRY(cos) + fldl 4(%esp) + fcos + fnstsw %ax + sahf + jp 1f ret -#else - fldt 8(%rsp) - fsqrt +1: fldpi + fadd %st(0) + fxch %st(1) +2: fprem + fnstsw %ax + sahf + jp 2b + fstp %st(1) + fcos ret -#endif -END(sqrtl) +END(cos) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_finite.S similarity index 89% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_finite.S index 769e66060b..afebb9f0b2 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_finite.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_finite.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,13 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(finite) + movl 8(%esp),%eax + andl $0x7ff00000, %eax + cmpl $0x7ff00000, %eax + setneb %al + andl $0x000000ff, %eax ret -#endif -END(sqrtl) +END(finite) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_floor.S similarity index 80% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_floor.S index 769e66060b..a1f9414531 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_floor.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_floor.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,25 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +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 -#endif -END(sqrtl) +END(floor) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_floorf.S b/lib/libm/i386/s_floorf.S similarity index 57% rename from lib/libm/arch/i386/s_floorf.S rename to lib/libm/i386/s_floorf.S index 70c2a9d07f..ba99174ea6 100644 --- a/lib/libm/arch/i386/s_floorf.S +++ b/lib/libm/i386/s_floorf.S @@ -1,14 +1,14 @@ /* - * Written by J.T. Conklin . + * Written by J.T. Conklin . * Public domain. * - * $NetBSD: s_floorf.S,v 1.8 2011/06/18 21:24:51 joerg Exp $ + * $FreeBSD: head/lib/msun/i387/s_floorf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_floorf.S,v 1.3 1995/05/09 00:04:32 jtc Exp $ */ #include ENTRY(floorf) -#ifdef __i386__ pushl %ebp movl %esp,%ebp subl $8,%esp @@ -26,20 +26,6 @@ ENTRY(floorf) fldcw -4(%ebp) /* restore original control word */ leave -#else - movss %xmm0, -4(%rsp) - fstcw -8(%rsp) - movw -8(%rsp),%dx - orw $0x0400,%dx - andw $0xf7ff,%dx - movw %dx,-12(%rsp) - fldcw -12(%rsp) - flds -4(%rsp) - frndint - fldcw -8(%rsp) - fstps -4(%rsp) - movss -4(%rsp),%xmm0 -#endif ret END(floorf) diff --git a/lib/libm/arch/i386/s_floor.S b/lib/libm/i386/s_floorl.S similarity index 50% rename from lib/libm/arch/i386/s_floor.S rename to lib/libm/i386/s_floorl.S index fc6ff951c0..8a9e835980 100644 --- a/lib/libm/arch/i386/s_floor.S +++ b/lib/libm/i386/s_floorl.S @@ -1,14 +1,13 @@ /* - * Written by J.T. Conklin . + * Based on code written by J.T. Conklin . * Public domain. * - * $NetBSD: s_floor.S,v 1.9 2011/06/18 21:24:51 joerg Exp $ + * $FreeBSD: head/lib/msun/i387/s_floorl.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(floor) -#ifdef __i386__ +ENTRY(floorl) pushl %ebp movl %esp,%ebp subl $8,%esp @@ -20,27 +19,13 @@ ENTRY(floor) movw %dx,-8(%ebp) fldcw -8(%ebp) /* load modfied control word */ - fldl 8(%ebp) /* round */ + fldt 8(%ebp) /* round */ frndint fldcw -4(%ebp) /* restore original control word */ leave -#else - movsd %xmm0, -8(%rsp) - fstcw -12(%rsp) - movw -12(%rsp),%dx - orw $0x0400,%dx - andw $0xf7ff,%dx - movw %dx,-16(%rsp) - fldcw -16(%rsp) - fldl -8(%rsp) - frndint - fldcw -12(%rsp) - fstpl -8(%rsp) - movsd -8(%rsp),%xmm0 -#endif ret -END(floor) +END(floorl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/i386/s_llrint.S similarity index 91% copy from lib/libm/arch/i386/s_lrint.S copy to lib/libm/i386/s_llrint.S index 17cef8998d..67338e5537 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/i386/s_llrint.S @@ -23,22 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_llrint.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrint) -#ifdef __i386__ +ENTRY(llrint) fldl 4(%esp) - subl $4,%esp - fistpl (%esp) + subl $8,%esp + fistpll (%esp) popl %eax + popl %edx ret -#else - cvtsd2si %xmm0, %rax - ret -#endif -END(lrint) +END(llrint) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/i386/s_llrintf.S similarity index 90% copy from lib/libm/arch/i386/s_lrintf.S copy to lib/libm/i386/s_llrintf.S index 975d1b00ef..c9c6d0b09e 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/i386/s_llrintf.S @@ -23,22 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_llrintf.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrintf) -#ifdef __i386__ +ENTRY(llrintf) flds 4(%esp) - subl $4,%esp - fistpl (%esp) + subl $8,%esp + fistpll (%esp) popl %eax + popl %edx ret -#else - cvtss2si %xmm0, %rax - ret -#endif -END(lrintf) +END(llrintf) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/i386/s_llrintl.S similarity index 90% copy from lib/libm/arch/i386/s_lrintf.S copy to lib/libm/i386/s_llrintl.S index 975d1b00ef..0a058f39d4 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/i386/s_llrintl.S @@ -23,22 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_llrintl.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrintf) -#ifdef __i386__ - flds 4(%esp) - subl $4,%esp - fistpl (%esp) +ENTRY(llrintl) + fldt 4(%esp) + subl $8,%esp + fistpll (%esp) popl %eax + popl %edx ret -#else - cvtss2si %xmm0, %rax - ret -#endif -END(lrintf) +END(llrintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_logb.S similarity index 92% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_logb.S index 769e66060b..f67c5bacf4 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_logb.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_logb.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(logb) + fldl 4(%esp) + fxtract + fstp %st ret -#endif -END(sqrtl) +END(logb) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_logbf.S b/lib/libm/i386/s_logbf.S new file mode 100644 index 0000000000..ae5d91be4a --- /dev/null +++ b/lib/libm/i386/s_logbf.S @@ -0,0 +1,18 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_logbf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_logbf.S,v 1.3 1995/05/09 00:15:12 jtc Exp $ + */ + +#include + +ENTRY(logbf) + flds 4(%esp) + fxtract + fstp %st + ret +END(logbf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_logbl.S similarity index 93% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_logbl.S index 769e66060b..0c8bbca1ff 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_logbl.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_logbl.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ +ENTRY(logbl) fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt + fxtract + fstp %st ret -#endif -END(sqrtl) +END(logbl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/i386/s_lrint.S similarity index 94% copy from lib/libm/arch/i386/s_lrint.S copy to lib/libm/i386/s_lrint.S index 17cef8998d..d3f2f11a78 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/i386/s_lrint.S @@ -23,22 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_lrint.S 217108 2011-01-07 16:13:12Z kib $ */ #include ENTRY(lrint) -#ifdef __i386__ fldl 4(%esp) subl $4,%esp fistpl (%esp) popl %eax ret -#else - cvtsd2si %xmm0, %rax - ret -#endif END(lrint) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/i386/s_lrintf.S similarity index 94% copy from lib/libm/arch/i386/s_lrintf.S copy to lib/libm/i386/s_lrintf.S index 975d1b00ef..8878e7aede 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/i386/s_lrintf.S @@ -23,22 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_lrintf.S 217108 2011-01-07 16:13:12Z kib $ */ #include ENTRY(lrintf) -#ifdef __i386__ flds 4(%esp) subl $4,%esp fistpl (%esp) popl %eax ret -#else - cvtss2si %xmm0, %rax - ret -#endif END(lrintf) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintl.S b/lib/libm/i386/s_lrintl.S similarity index 92% copy from lib/libm/arch/i386/s_lrintl.S copy to lib/libm/i386/s_lrintl.S index 6550d3881d..d4c4d67b90 100644 --- a/lib/libm/arch/i386/s_lrintl.S +++ b/lib/libm/i386/s_lrintl.S @@ -23,25 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/i387/s_lrintl.S 217108 2011-01-07 16:13:12Z kib $ */ #include ENTRY(lrintl) -#ifdef __i386__ fldt 4(%esp) subl $4,%esp fistpl (%esp) popl %eax ret -#else - fldt 8(%rsp) - subq $8,%rsp - fistpll (%rsp) - popq %rax - ret -#endif END(lrintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/i386/s_remquo.S similarity index 70% copy from lib/libm/arch/i386/s_remquol.S copy to lib/libm/i386/s_remquo.S index 312d1dca05..43487b7426 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/i386/s_remquo.S @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,19 +22,19 @@ * 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: head/lib/msun/i387/s_remquo.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remquol) -#ifdef __i386__ - fldt 16(%esp) - fldt 4(%esp) +ENTRY(remquo) + fldl 12(%esp) + fldl 4(%esp) 1: fprem1 fstsw %ax sahf @@ -50,48 +50,17 @@ ENTRY(remquol) orl %ecx,%eax andl $7,%eax /* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 24(%esp),%ecx - xorl 12(%esp),%ecx - movsx %cx,%ecx + 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 28(%esp),%ecx + movl 20(%esp),%ecx movl %eax,(%ecx) ret -#else - fldt 24(%rsp) - fldt 8(%rsp) -1: fprem1 - fstsw %ax - btw $10,%ax - jc 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 32(%rsp),%ecx - xorl 16(%rsp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl %eax,(%rdi) - ret -#endif -END(remquol) +END(remquo) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/i386/s_remquof.S similarity index 70% copy from lib/libm/arch/i386/s_remquol.S copy to lib/libm/i386/s_remquof.S index 312d1dca05..8c753698d7 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/i386/s_remquof.S @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,19 +22,19 @@ * 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: head/lib/msun/i387/s_remquof.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remquol) -#ifdef __i386__ - fldt 16(%esp) - fldt 4(%esp) +ENTRY(remquof) + flds 8(%esp) + flds 4(%esp) 1: fprem1 fstsw %ax sahf @@ -50,48 +50,17 @@ ENTRY(remquol) orl %ecx,%eax andl $7,%eax /* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 24(%esp),%ecx - xorl 12(%esp),%ecx - movsx %cx,%ecx + 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 28(%esp),%ecx + movl 12(%esp),%ecx movl %eax,(%ecx) ret -#else - fldt 24(%rsp) - fldt 8(%rsp) -1: fprem1 - fstsw %ax - btw $10,%ax - jc 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 32(%rsp),%ecx - xorl 16(%rsp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl %eax,(%rdi) - ret -#endif -END(remquol) +END(remquof) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/i386/s_remquol.S similarity index 77% copy from lib/libm/arch/i386/s_remquol.S copy to lib/libm/i386/s_remquol.S index 312d1dca05..4ea2b0483d 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/i386/s_remquol.S @@ -22,17 +22,17 @@ * 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: head/lib/msun/i387/s_remquol.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include ENTRY(remquol) -#ifdef __i386__ fldt 16(%esp) fldt 4(%esp) 1: fprem1 @@ -62,36 +62,6 @@ ENTRY(remquol) movl 28(%esp),%ecx movl %eax,(%ecx) ret -#else - fldt 24(%rsp) - fldt 8(%rsp) -1: fprem1 - fstsw %ax - btw $10,%ax - jc 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 32(%rsp),%ecx - xorl 16(%rsp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl %eax,(%rdi) - ret -#endif END(remquol) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_rint.S similarity index 93% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_rint.S index 769e66060b..a9699918c5 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_rint.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_rint.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,10 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(rint) + fldl 4(%esp) + frndint ret -#endif -END(sqrtl) +END(rint) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_rintf.S b/lib/libm/i386/s_rintf.S new file mode 100644 index 0000000000..1fe0fc3ce5 --- /dev/null +++ b/lib/libm/i386/s_rintf.S @@ -0,0 +1,17 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_rintf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_rintf.S,v 1.3 1995/05/09 00:17:22 jtc Exp $ + */ + +#include + +ENTRY(rintf) + flds 4(%esp) + frndint + ret +END(rintf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_rintl.S similarity index 94% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_rintl.S index 769e66060b..e9cf7a73b3 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_rintl.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_rintl.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,10 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ +ENTRY(rintl) fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt + frndint ret -#endif -END(sqrtl) +END(rintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_scalbn.S similarity index 89% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_scalbn.S index 769e66060b..c0c0bfb56f 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_scalbn.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993,94 Winning Strategies, Inc. + * Copyright (c) 1994 Winning Strategies, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_scalbn.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,12 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(scalbn) + fildl 12(%esp) + fldl 4(%esp) + fscale + fstp %st(1) ret -#endif -END(sqrtl) +END(scalbn) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_scalbnf.S b/lib/libm/i386/s_scalbnf.S new file mode 100644 index 0000000000..b7833159e0 --- /dev/null +++ b/lib/libm/i386/s_scalbnf.S @@ -0,0 +1,22 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_scalbnf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_scalbnf.S,v 1.4 1999/01/02 05:15:40 kristerw Exp $ + */ + +#include + +ENTRY(scalbnf) + fildl 8(%esp) + flds 4(%esp) + fscale + fstp %st(1) /* bug fix for fp stack overflow */ + ret +END(scalbnf) + +.globl CNAME(ldexpf) +.set CNAME(ldexpf),CNAME(scalbnf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_scalbnl.S b/lib/libm/i386/s_scalbnl.S new file mode 100644 index 0000000000..7a17f760f1 --- /dev/null +++ b/lib/libm/i386/s_scalbnl.S @@ -0,0 +1,22 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_scalbnl.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_scalbnf.S,v 1.4 1999/01/02 05:15:40 kristerw Exp $ + */ + +#include + +ENTRY(scalbnl) + fildl 16(%esp) + fldt 4(%esp) + fscale + fstp %st(1) + ret +END(scalbnl) + +.globl CNAME(ldexpl) +.set CNAME(ldexpl),CNAME(scalbnl) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_significand.S similarity index 91% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_significand.S index 769e66060b..ea42d6c42d 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_significand.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_significand.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else - fldt 8(%rsp) - fsqrt +ENTRY(significand) + fldl 4(%esp) + fxtract + fstp %st(1) ret -#endif -END(sqrtl) +END(significand) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_significandf.S b/lib/libm/i386/s_significandf.S new file mode 100644 index 0000000000..29ba1f352f --- /dev/null +++ b/lib/libm/i386/s_significandf.S @@ -0,0 +1,18 @@ +/* + * Written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_significandf.S 217108 2011-01-07 16:13:12Z kib $ + * $NetBSD: s_significandf.S,v 1.3 1995/05/09 00:24:07 jtc Exp $ + */ + +#include + +ENTRY(significandf) + flds 4(%esp) + fxtract + fstp %st(1) + ret +END(significandf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/i386/s_sin.S similarity index 86% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/i386/s_sin.S index 769e66060b..62e10f4369 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/i386/s_sin.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993,94 Winning Strategies, Inc. + * Copyright (c) 1994 Winning Strategies, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,6 +26,8 @@ * 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: head/lib/msun/i387/s_sin.S 240566 2012-09-16 16:58:49Z tijl $ */ /* @@ -35,16 +37,23 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt +ENTRY(sin) + fldl 4(%esp) + fsin + fnstsw %ax + sahf + jp 1f ret -#else - fldt 8(%rsp) - fsqrt +1: fldpi + fadd %st(0) + fxch %st(1) +2: fprem + fnstsw %ax + sahf + jp 2b + fstp %st(1) + fsin ret -#endif -END(sqrtl) +END(sin) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_remainderl.S b/lib/libm/i386/s_tan.S similarity index 86% copy from lib/libm/arch/i386/e_remainderl.S copy to lib/libm/i386/s_tan.S index 3781ba941b..6548787685 100644 --- a/lib/libm/arch/i386/e_remainderl.S +++ b/lib/libm/i386/s_tan.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993,94 Winning Strategies, Inc. + * Copyright (c) 1994 Winning Strategies, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,36 +26,36 @@ * 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: head/lib/msun/i387/s_tan.S 240566 2012-09-16 16:58:49Z tijl $ */ /* * Written by: * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remainderl) -#ifdef __i386__ - fldt 16(%esp) - fldt 4(%esp) -1: fprem1 - fstsw %ax +ENTRY(tan) + fldl 4(%esp) + fptan + fnstsw %ax sahf - jp 1b - fstp %st(1) + jp 1f + fstp %st(0) ret -#else - fldt 24(%rsp) - fldt 8(%rsp) -1: fprem1 - fstsw %ax - testw $0x400,%ax - jne 1b +1: fldpi + fadd %st(0) + fxch %st(1) +2: fprem + fnstsw %ax + sahf + jp 2b fstp %st(1) + fptan + fstp %st(0) ret -#endif -END(remainderl) +END(tan) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_trunc.S b/lib/libm/i386/s_trunc.S new file mode 100644 index 0000000000..4873f37724 --- /dev/null +++ b/lib/libm/i386/s_trunc.S @@ -0,0 +1,30 @@ +/* + * Based on code written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_trunc.S 217108 2011-01-07 16:13:12Z kib $ + */ + +#include + +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 +END(trunc) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_truncf.S b/lib/libm/i386/s_truncf.S new file mode 100644 index 0000000000..145dc8144a --- /dev/null +++ b/lib/libm/i386/s_truncf.S @@ -0,0 +1,30 @@ +/* + * Based on code written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_truncf.S 217108 2011-01-07 16:13:12Z kib $ + */ + +#include + +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 +END(truncf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/i386/s_truncl.S b/lib/libm/i386/s_truncl.S new file mode 100644 index 0000000000..095212d5b2 --- /dev/null +++ b/lib/libm/i386/s_truncl.S @@ -0,0 +1,30 @@ +/* + * Based on code written by J.T. Conklin . + * Public domain. + * + * $FreeBSD: head/lib/msun/i387/s_truncl.S 217108 2011-01-07 16:13:12Z kib $ + */ + +#include + +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 +END(truncl) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/src/e_rem_pio2l.h b/lib/libm/ld80/e_rem_pio2l.h similarity index 89% rename from lib/libm/src/e_rem_pio2l.h rename to lib/libm/ld80/e_rem_pio2l.h index 6f0cdd433b..0a9dd26f4d 100644 --- a/lib/libm/src/e_rem_pio2l.h +++ b/lib/libm/ld80/e_rem_pio2l.h @@ -1,4 +1,5 @@ /* From: @(#)e_rem_pio2.c 1.4 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_acoshf.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -6,17 +7,16 @@ * * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== * * Optimized by Bruce D. Evans. - * FreeBSD SVN: 223262 (2011-06-18) */ /* ld80 version of __ieee754_rem_pio2l(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] + * + * return the remainder of x rem pi/2 in y[0]+y[1] * use __kernel_rem_pio2() */ @@ -45,7 +45,7 @@ pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ -#if defined(__amd64__) || defined(__i386__) +#if defined(__x86_64__) || defined(__i386__) /* Long double constants are slow on these arches, and broken on i386. */ static const volatile double invpio2hi = 6.3661977236758138e-01, /* 0x145f306dc9c883.0p-53 */ @@ -69,7 +69,7 @@ pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ #endif static inline __always_inline int -__libm_rem_pio2l(long double x, long double *y) +__ieee754_rem_pio2l(long double x, long double *y) { union IEEEl2bits u,u1; long double z,w,t,r,fn; @@ -96,24 +96,24 @@ __libm_rem_pio2l(long double x, long double *y) union IEEEl2bits u2; int ex1; j = ex; - y[0] = r-w; + y[0] = r-w; u2.e = y[0]; ex1 = u2.xbits.expsign & 0x7fff; i = j-ex1; if(i>22) { /* 2nd iteration needed, good to 141 */ t = r; - w = fn*pio2_2; + w = fn*pio2_2; r = t-w; - w = fn*pio2_2t-((t-r)-w); + w = fn*pio2_2t-((t-r)-w); y[0] = r-w; u2.e = y[0]; ex1 = u2.xbits.expsign & 0x7fff; i = j-ex1; if(i>61) { /* 3rd iteration need, 180 bits acc */ - t = r; /* will cover all possible cases */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); + 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; } } @@ -121,7 +121,7 @@ __libm_rem_pio2l(long double x, long double *y) y[1] = (r-y[0])-w; return n; } - /* + /* * all other (large) arguments */ if(ex==0x7fff) { /* x is inf or NaN */ diff --git a/lib/libm/src/invtrig.c b/lib/libm/ld80/invtrig.c similarity index 97% rename from lib/libm/src/invtrig.c rename to lib/libm/ld80/invtrig.c index 57c9881bcb..f1bc23e561 100644 --- a/lib/libm/src/invtrig.c +++ b/lib/libm/ld80/invtrig.c @@ -22,6 +22,8 @@ * 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: head/lib/msun/ld80/invtrig.c 181074 2008-07-31 22:41:26Z das $ */ #include "invtrig.h" diff --git a/lib/libm/src/invtrig.h b/lib/libm/ld80/invtrig.h similarity index 97% rename from lib/libm/src/invtrig.h rename to lib/libm/ld80/invtrig.h index fe30c01b72..0ca3b59caa 100644 --- a/lib/libm/src/invtrig.h +++ b/lib/libm/ld80/invtrig.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/lib/msun/ld80/invtrig.h 181152 2008-08-02 03:56:22Z das $ */ #include diff --git a/lib/libm/src/k_cosl.c b/lib/libm/ld80/k_cosl.c similarity index 93% rename from lib/libm/src/k_cosl.c rename to lib/libm/ld80/k_cosl.c index c2fa4af23f..1de96e14a8 100644 --- a/lib/libm/src/k_cosl.c +++ b/lib/libm/ld80/k_cosl.c @@ -1,4 +1,5 @@ /* From: @(#)k_cos.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/ld80/k_cosl.c 176357 2008-02-17 07:32:14Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -6,10 +7,9 @@ * * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176357 (2008-02-17) */ /* @@ -44,7 +44,7 @@ static const double one = 1.0; -#if defined(__amd64__) || defined(__i386__) +#if defined(__x86_64__) || defined(__i386__) /* Long double constants are slow on these arches, and broken on i386. */ static const volatile double C1hi = 0.041666666666666664, /* 0x15555555555555.0p-57 */ diff --git a/lib/libm/src/k_sinl.c b/lib/libm/ld80/k_sinl.c similarity index 90% rename from lib/libm/src/k_sinl.c rename to lib/libm/ld80/k_sinl.c index 3cf9117655..e222c1a9d6 100644 --- a/lib/libm/src/k_sinl.c +++ b/lib/libm/ld80/k_sinl.c @@ -1,4 +1,5 @@ /* From: @(#)k_sin.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/ld80/k_sinl.c 176357 2008-02-17 07:32:14Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -6,10 +7,9 @@ * * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176357 (2008-02-17) */ /* @@ -27,7 +27,7 @@ half = 0.5; * * See ../ld80/k_cosl.c for more details about the polynomial. */ -#if defined(__amd64__) || defined(__i386__) +#if defined(__x86_64__) || defined(__i386__) /* Long double constants are slow on these arches, and broken on i386. */ static const volatile double S1hi = -0.16666666666666666, /* -0x15555555555555.0p-55 */ diff --git a/lib/libm/src/k_tanl.c b/lib/libm/ld80/k_tanl.c similarity index 96% rename from lib/libm/src/k_tanl.c rename to lib/libm/ld80/k_tanl.c index 0aa28ed8a4..b7004bb071 100644 --- a/lib/libm/src/k_tanl.c +++ b/lib/libm/ld80/k_tanl.c @@ -1,5 +1,5 @@ /* From: @(#)k_tan.c 1.5 04/04/22 SMI */ - +/* $FreeBSD: head/lib/msun/ld80/k_tanl.c 176387 2008-02-18 15:39:52Z bde $ */ /* * ==================================================== * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. @@ -9,14 +9,13 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176357 (2008-02-17) */ /* * ld80 version of k_tan.c. See ../src/k_tan.c for most comments. */ -#include +#include "math.h" #include "math_private.h" /* @@ -25,7 +24,7 @@ * * See k_cosl.c for more details about the polynomial. */ -#if defined(__amd64__) || defined(__i386__) +#if defined(__x86_64__) || defined(__i386__) /* Long double constants are slow on these arches, and broken on i386. */ static const volatile double T3hi = 0.33333333333333331, /* 0x15555555555555.0p-54 */ diff --git a/lib/libm/src/s_exp2l.c b/lib/libm/ld80/s_exp2l.c similarity index 86% rename from lib/libm/src/s_exp2l.c rename to lib/libm/ld80/s_exp2l.c index 4abf91b4ec..523ebcdbed 100644 --- a/lib/libm/src/s_exp2l.c +++ b/lib/libm/ld80/s_exp2l.c @@ -23,10 +23,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 176231 (2008-02-13) + * $FreeBSD: head/lib/msun/ld80/s_exp2l.c 251046 2013-05-27 22:45:05Z kargl $ */ -#include #include #include @@ -35,28 +34,32 @@ #endif #include "fpmath.h" +#include "math.h" +#include "math_private.h" #define TBLBITS 7 #define TBLSIZE (1 << TBLBITS) #define BIAS (LDBL_MAX_EXP - 1) -#define EXPMASK (BIAS + LDBL_MAX_EXP) -static const long double huge = 0x1p10000L; -#if 0 /* XXX Prevent gcc from erroneously constant folding this. */ -static const long double twom10000 = 0x1p-10000L; -#else -static volatile long double twom10000 = 0x1p-10000L; -#endif +static volatile long double + huge = 0x1p10000L, + twom10000 = 0x1p-10000L; + +static const union IEEEl2bits +P1 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309429e-1L); static const double - redux = 0x1.8p63 / TBLSIZE, - P1 = 0x1.62e42fefa39efp-1, - P2 = 0x1.ebfbdff82c58fp-3, - P3 = 0x1.c6b08d7049fap-5, - P4 = 0x1.3b2ab6fba4da5p-7, - P5 = 0x1.5d8804780a736p-10, - P6 = 0x1.430918835e33dp-13; +redux = 0x1.8p63 / TBLSIZE, +/* + * Domain [-0.00390625, 0.00390625], range ~[-1.7079e-23, 1.7079e-23] + * |exp(x) - p(x)| < 2**-75.6 + */ +P2 = 2.4022650695910072e-1, /* 0x1ebfbdff82c58f.0p-55 */ +P3 = 5.5504108664816879e-2, /* 0x1c6b08d7049e1a.0p-57 */ +P4 = 9.6181291055695180e-3, /* 0x13b2ab6fa8321a.0p-59 */ +P5 = 1.3333563089183052e-3, /* 0x15d8806f67f251.0p-62 */ +P6 = 1.5413361552277414e-4; /* 0x1433ddacff3441.0p-65 */ static const double tbl[TBLSIZE * 2] = { 0x1.6a09e667f3bcdp-1, -0x1.bdd3413b2648p-55, @@ -189,8 +192,8 @@ static const double tbl[TBLSIZE * 2] = { 0x1.68155d44ca973p+0, 0x1.038ae44f74p-57, }; -/* - * exp2l(x): compute the base 2 exponential of x +/** + * Compute the base 2 exponential of x for Intel 80-bit format. * * Accuracy: Peak error < 0.511 ulp. * @@ -206,7 +209,7 @@ static const double tbl[TBLSIZE * 2] = { * with |z| <= 2**-(TBLBITS+1). * * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a - * degree-6 minimax polynomial with maximum error under 2**-69. + * degree-6 minimax polynomial with maximum error under 2**-75.6. * The table entries each have 104 bits of accuracy, encoded as * a pair of double precision values. */ @@ -221,30 +224,22 @@ exp2l(long double x) /* Filter out exceptional cases. */ u.e = x; hx = u.xbits.expsign; - ix = hx & EXPMASK; + ix = hx & 0x7fff; if (ix >= BIAS + 14) { /* |x| >= 16384 or x is NaN */ if (ix == BIAS + LDBL_MAX_EXP) { - if (u.xbits.man != 1ULL << 63 || (hx & 0x8000) == 0) - return (x + x); /* x is +Inf or NaN */ - else - return (0.0); /* x is -Inf */ + if (hx & 0x8000 && u.xbits.man == 1ULL << 63) + return (0.0L); /* x is -Inf */ + return (x + x); /* x is +Inf, NaN or unsupported */ } if (x >= 16384) return (huge * huge); /* overflow */ if (x <= -16446) return (twom10000 * twom10000); /* underflow */ - } else if (ix <= BIAS - 66) { /* |x| < 0x1p-66 */ - return (1.0 + x); + } else if (ix <= BIAS - 66) { /* |x| < 0x1p-65 (includes pseudos) */ + return (1.0L + x); /* 1 with inexact */ } -#ifdef __i386__ - /* - * The default precision on i386 is 53 bits, so long doubles are - * broken. Call exp2() to get an accurate (double precision) result. - */ - if (fpgetprec() != FP_PE) - return (exp2(x)); -#endif + ENTERI(); /* * Reduce x, computing z, i0, and k. The low bits of x + redux @@ -268,26 +263,25 @@ exp2l(long double x) z = x - u.e; v.xbits.man = 1ULL << 63; if (k >= LDBL_MIN_EXP) { - v.xbits.expsign = LDBL_MAX_EXP - 1 + k; + v.xbits.expsign = BIAS + k; twopk = v.e; } else { - v.xbits.expsign = LDBL_MAX_EXP - 1 + k + 10000; + v.xbits.expsign = BIAS + k + 10000; twopkp10000 = v.e; } /* Compute r = exp2l(y) = exp2lt[i0] * p(z). */ long double t_hi = tbl[i0]; long double t_lo = tbl[i0 + 1]; - /* XXX This gives > 1 ulp errors outside of FE_TONEAREST mode */ - r = t_lo + (t_hi + t_lo) * z * (P1 + z * (P2 + z * (P3 + z * (P4 + r = t_lo + (t_hi + t_lo) * z * (P1.e + z * (P2 + z * (P3 + z * (P4 + z * (P5 + z * P6))))) + t_hi; /* Scale by 2**k. */ if (k >= LDBL_MIN_EXP) { if (k == LDBL_MAX_EXP) - return (r * 2.0 * 0x1p16383L); - return (r * twopk); + RETURNI(r * 2.0 * 0x1p16383L); + RETURNI(r * twopk); } else { - return (r * twopkp10000 * twom10000); + RETURNI(r * twopkp10000 * twom10000); } } diff --git a/lib/libm/ld80/s_expl.c b/lib/libm/ld80/s_expl.c new file mode 100644 index 0000000000..48a92ab7e9 --- /dev/null +++ b/lib/libm/ld80/s_expl.c @@ -0,0 +1,303 @@ +/*- + * Copyright (c) 2009-2012 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. + * + * $FreeBSD: head/lib/msun/ld80/s_expl.c 241516 2012-10-13 19:53:11Z kargl $ + */ + +/*- + * Compute the exponential of x for Intel 80-bit format. This is based on: + * + * PTP Tang, "Table-driven implementation of the exponential function + * in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 15, + * 144-157 (1989). + * + * where the 32 table entries have been expanded to INTERVALS (see below). + */ + +#include + +#ifdef __i386__ +#include +#endif + +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + +#define INTERVALS 128 +#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 union IEEEl2bits +/* log(2**16384 - 0.5) rounded towards zero: */ +o_threshold = LD80C(0xb17217f7d1cf79ab, 13, 11356.5234062941439488L), +/* log(2**(-16381-64-1)) rounded towards zero: */ +u_threshold = LD80C(0xb21dfe7f09e2baa9, 13, -11399.4985314888605581L); + +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 */ +L1 = 5.4152123484527692e-3, /* 0x162e42ff000000.0p-60 */ +L2 = -3.2819649005320973e-13, /* -0x1718432a1b0e26.0p-94 */ +/* + * Domain [-0.002708, 0.002708], range ~[-5.7136e-24, 5.7110e-24]: + * |exp(x) - p(x)| < 2**-77.2 + * (0.002708 is ln2/(2*INTERVALS) rounded up a little). + */ +P2 = 0.5, +P3 = 1.6666666666666119e-1, /* 0x15555555555490.0p-55 */ +P4 = 4.1666666666665887e-2, /* 0x155555555554e5.0p-57 */ +P5 = 8.3333354987869413e-3, /* 0x1111115b789919.0p-59 */ +P6 = 1.3888891738560272e-3; /* 0x16c16c651633ae.0p-62 */ + +/* + * 2^(i/INTERVALS) for i in [0,INTERVALS] is represented by two values where + * the first 53 bits of the significand are stored in hi and the next 53 + * bits are in lo. Tang's paper states that the trailing 6 bits of hi must + * be zero for his algorithm in both single and double precision, because + * the table is re-used in the implementation of expm1() where a floating + * point addition involving hi must be exact. Here hi is double, so + * converting it to long double gives 11 trailing zero bits. + */ +static const struct { + double hi; + double lo; +/* XXX should rename 's'. */ +} s[INTERVALS] = { + 0x1p+0, 0x0p+0, + 0x1.0163da9fb3335p+0, 0x1.b61299ab8cdb7p-54, + 0x1.02c9a3e778060p+0, 0x1.dcdef95949ef4p-53, + 0x1.04315e86e7f84p+0, 0x1.7ae71f3441b49p-53, + 0x1.059b0d3158574p+0, 0x1.d73e2a475b465p-55, + 0x1.0706b29ddf6ddp+0, 0x1.8db880753b0f6p-53, + 0x1.0874518759bc8p+0, 0x1.186be4bb284ffp-57, + 0x1.09e3ecac6f383p+0, 0x1.1487818316136p-54, + 0x1.0b5586cf9890fp+0, 0x1.8a62e4adc610bp-54, + 0x1.0cc922b7247f7p+0, 0x1.01edc16e24f71p-54, + 0x1.0e3ec32d3d1a2p+0, 0x1.03a1727c57b53p-59, + 0x1.0fb66affed31ap+0, 0x1.e464123bb1428p-53, + 0x1.11301d0125b50p+0, 0x1.49d77e35db263p-53, + 0x1.12abdc06c31cbp+0, 0x1.f72575a649ad2p-53, + 0x1.1429aaea92ddfp+0, 0x1.66820328764b1p-53, + 0x1.15a98c8a58e51p+0, 0x1.2406ab9eeab0ap-55, + 0x1.172b83c7d517ap+0, 0x1.b9bef918a1d63p-53, + 0x1.18af9388c8de9p+0, 0x1.777ee1734784ap-53, + 0x1.1a35beb6fcb75p+0, 0x1.e5b4c7b4968e4p-55, + 0x1.1bbe084045cd3p+0, 0x1.3563ce56884fcp-53, + 0x1.1d4873168b9aap+0, 0x1.e016e00a2643cp-54, + 0x1.1ed5022fcd91cp+0, 0x1.71033fec2243ap-53, + 0x1.2063b88628cd6p+0, 0x1.dc775814a8495p-55, + 0x1.21f49917ddc96p+0, 0x1.2a97e9494a5eep-55, + 0x1.2387a6e756238p+0, 0x1.9b07eb6c70573p-54, + 0x1.251ce4fb2a63fp+0, 0x1.ac155bef4f4a4p-55, + 0x1.26b4565e27cddp+0, 0x1.2bd339940e9d9p-55, + 0x1.284dfe1f56380p+0, 0x1.2d9e2b9e07941p-53, + 0x1.29e9df51fdee1p+0, 0x1.612e8afad1255p-55, + 0x1.2b87fd0dad98fp+0, 0x1.fbbd48ca71f95p-53, + 0x1.2d285a6e4030bp+0, 0x1.0024754db41d5p-54, + 0x1.2ecafa93e2f56p+0, 0x1.1ca0f45d52383p-56, + 0x1.306fe0a31b715p+0, 0x1.6f46ad23182e4p-55, + 0x1.32170fc4cd831p+0, 0x1.a9ce78e18047cp-55, + 0x1.33c08b26416ffp+0, 0x1.32721843659a6p-54, + 0x1.356c55f929ff0p+0, 0x1.928c468ec6e76p-53, + 0x1.371a7373aa9cap+0, 0x1.4e28aa05e8a8fp-53, + 0x1.38cae6d05d865p+0, 0x1.0b53961b37da2p-53, + 0x1.3a7db34e59ff6p+0, 0x1.d43792533c144p-53, + 0x1.3c32dc313a8e4p+0, 0x1.08003e4516b1ep-53, + 0x1.3dea64c123422p+0, 0x1.ada0911f09ebcp-55, + 0x1.3fa4504ac801bp+0, 0x1.417ee03548306p-53, + 0x1.4160a21f72e29p+0, 0x1.f0864b71e7b6cp-53, + 0x1.431f5d950a896p+0, 0x1.b8e088728219ap-53, + 0x1.44e086061892dp+0, 0x1.89b7a04ef80d0p-59, + 0x1.46a41ed1d0057p+0, 0x1.c944bd1648a76p-54, + 0x1.486a2b5c13cd0p+0, 0x1.3c1a3b69062f0p-56, + 0x1.4a32af0d7d3dep+0, 0x1.9cb62f3d1be56p-54, + 0x1.4bfdad5362a27p+0, 0x1.d4397afec42e2p-56, + 0x1.4dcb299fddd0dp+0, 0x1.8ecdbbc6a7833p-54, + 0x1.4f9b2769d2ca6p+0, 0x1.5a67b16d3540ep-53, + 0x1.516daa2cf6641p+0, 0x1.8225ea5909b04p-53, + 0x1.5342b569d4f81p+0, 0x1.be1507893b0d5p-53, + 0x1.551a4ca5d920ep+0, 0x1.8a5d8c4048699p-53, + 0x1.56f4736b527dap+0, 0x1.9bb2c011d93adp-54, + 0x1.58d12d497c7fdp+0, 0x1.295e15b9a1de8p-55, + 0x1.5ab07dd485429p+0, 0x1.6324c054647adp-54, + 0x1.5c9268a5946b7p+0, 0x1.c4b1b816986a2p-60, + 0x1.5e76f15ad2148p+0, 0x1.ba6f93080e65ep-54, + 0x1.605e1b976dc08p+0, 0x1.60edeb25490dcp-53, + 0x1.6247eb03a5584p+0, 0x1.63e1f40dfa5b5p-53, + 0x1.6434634ccc31fp+0, 0x1.8edf0e2989db3p-53, + 0x1.6623882552224p+0, 0x1.224fb3c5371e6p-53, + 0x1.68155d44ca973p+0, 0x1.038ae44f73e65p-57, + 0x1.6a09e667f3bccp+0, 0x1.21165f626cdd5p-53, + 0x1.6c012750bdabep+0, 0x1.daed533001e9ep-53, + 0x1.6dfb23c651a2ep+0, 0x1.e441c597c3775p-53, + 0x1.6ff7df9519483p+0, 0x1.9f0fc369e7c42p-53, + 0x1.71f75e8ec5f73p+0, 0x1.ba46e1e5de15ap-53, + 0x1.73f9a48a58173p+0, 0x1.7ab9349cd1562p-53, + 0x1.75feb564267c8p+0, 0x1.7edd354674916p-53, + 0x1.780694fde5d3fp+0, 0x1.866b80a02162dp-54, + 0x1.7a11473eb0186p+0, 0x1.afaa2047ed9b4p-53, + 0x1.7c1ed0130c132p+0, 0x1.f124cd1164dd6p-54, + 0x1.7e2f336cf4e62p+0, 0x1.05d02ba15797ep-56, + 0x1.80427543e1a11p+0, 0x1.6c1bccec9346bp-53, + 0x1.82589994cce12p+0, 0x1.159f115f56694p-53, + 0x1.8471a4623c7acp+0, 0x1.9ca5ed72f8c81p-53, + 0x1.868d99b4492ecp+0, 0x1.01c83b21584a3p-53, + 0x1.88ac7d98a6699p+0, 0x1.994c2f37cb53ap-54, + 0x1.8ace5422aa0dbp+0, 0x1.6e9f156864b27p-54, + 0x1.8cf3216b5448bp+0, 0x1.de55439a2c38bp-53, + 0x1.8f1ae99157736p+0, 0x1.5cc13a2e3976cp-55, + 0x1.9145b0b91ffc5p+0, 0x1.114c368d3ed6ep-53, + 0x1.93737b0cdc5e4p+0, 0x1.e8a0387e4a814p-53, + 0x1.95a44cbc8520ep+0, 0x1.d36906d2b41f9p-53, + 0x1.97d829fde4e4fp+0, 0x1.173d241f23d18p-53, + 0x1.9a0f170ca07b9p+0, 0x1.7462137188ce7p-53, + 0x1.9c49182a3f090p+0, 0x1.c7c46b071f2bep-56, + 0x1.9e86319e32323p+0, 0x1.824ca78e64c6ep-56, + 0x1.a0c667b5de564p+0, 0x1.6535b51719567p-53, + 0x1.a309bec4a2d33p+0, 0x1.6305c7ddc36abp-54, + 0x1.a5503b23e255cp+0, 0x1.1684892395f0fp-53, + 0x1.a799e1330b358p+0, 0x1.bcb7ecac563c7p-54, + 0x1.a9e6b5579fdbfp+0, 0x1.0fac90ef7fd31p-54, + 0x1.ac36bbfd3f379p+0, 0x1.81b72cd4624ccp-53, + 0x1.ae89f995ad3adp+0, 0x1.7a1cd345dcc81p-54, + 0x1.b0e07298db665p+0, 0x1.2108559bf8deep-53, + 0x1.b33a2b84f15fap+0, 0x1.ed7fa1cf7b290p-53, + 0x1.b59728de55939p+0, 0x1.1c7102222c90ep-53, + 0x1.b7f76f2fb5e46p+0, 0x1.d54f610356a79p-53, + 0x1.ba5b030a10649p+0, 0x1.0819678d5eb69p-53, + 0x1.bcc1e904bc1d2p+0, 0x1.23dd07a2d9e84p-55, + 0x1.bf2c25bd71e08p+0, 0x1.0811ae04a31c7p-53, + 0x1.c199bdd85529cp+0, 0x1.11065895048ddp-55, + 0x1.c40ab5fffd07ap+0, 0x1.b4537e083c60ap-54, + 0x1.c67f12e57d14bp+0, 0x1.2884dff483cadp-54, + 0x1.c8f6d9406e7b5p+0, 0x1.1acbc48805c44p-56, + 0x1.cb720dcef9069p+0, 0x1.503cbd1e949dbp-56, + 0x1.cdf0b555dc3f9p+0, 0x1.889f12b1f58a3p-53, + 0x1.d072d4a07897bp+0, 0x1.1a1e45e4342b2p-53, + 0x1.d2f87080d89f1p+0, 0x1.15bc247313d44p-53, + 0x1.d5818dcfba487p+0, 0x1.2ed02d75b3707p-55, + 0x1.d80e316c98397p+0, 0x1.7709f3a09100cp-53, + 0x1.da9e603db3285p+0, 0x1.c2300696db532p-54, + 0x1.dd321f301b460p+0, 0x1.2da5778f018c3p-54, + 0x1.dfc97337b9b5ep+0, 0x1.72d195873da52p-53, + 0x1.e264614f5a128p+0, 0x1.424ec3f42f5b5p-53, + 0x1.e502ee78b3ff6p+0, 0x1.39e8980a9cc8fp-55, + 0x1.e7a51fbc74c83p+0, 0x1.2d522ca0c8de2p-54, + 0x1.ea4afa2a490d9p+0, 0x1.0b1ee7431ebb6p-53, + 0x1.ecf482d8e67f0p+0, 0x1.1b60625f7293ap-53, + 0x1.efa1bee615a27p+0, 0x1.dc7f486a4b6b0p-54, + 0x1.f252b376bba97p+0, 0x1.3a1a5bf0d8e43p-54, + 0x1.f50765b6e4540p+0, 0x1.9d3e12dd8a18bp-54, + 0x1.f7bfdad9cbe13p+0, 0x1.1227697fce57bp-53, + 0x1.fa7c1819e90d8p+0, 0x1.74853f3a5931ep-55, + 0x1.fd3c22b8f71f1p+0, 0x1.2eb74966579e7p-57 +}; + +long double +expl(long double x) +{ + union IEEEl2bits u, v; + long double fn, q, r, r1, r2, t, t23, t45, twopk, twopkp10000, z; + 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 && u.xbits.man == 1ULL << 63) + return (0.0L); /* x is -Inf */ + return (x + x); /* x is +Inf, NaN or unsupported */ + } + if (x > o_threshold.e) + return (huge * huge); + if (x < u_threshold.e) + return (tiny * tiny); + } else if (ix < BIAS - 66) { /* |x| < 0x1p-66 */ + /* includes pseudo-denormals */ + if (huge + x > 1.0L) /* trigger inexact iff x != 0 */ + return (1.0L + x); + } + + ENTERI(); + + /* Reduce x to (k*ln2 + midpoint[n2] + r1 + r2). */ + /* Use a specialized rint() to get fn. Assume round-to-nearest. */ + fn = x * INV_L + 0x1.8p63 - 0x1.8p63; + r = x - fn * L1 - fn * L2; /* r = r1 + r2 done independently. */ +#if defined(HAVE_EFFICIENT_IRINTL) + n = irintl(fn); +#elif defined(HAVE_EFFICIENT_IRINT) + n = irint(fn); +#else + n = (int)fn; +#endif + n2 = (unsigned)n % INTERVALS; + k = (n - n2) / INTERVALS; + r1 = x - fn * L1; + r2 = -fn * L2; + + /* Prepare scale factors. */ + v.xbits.man = 1ULL << 63; + 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(midpoint[n2] + r1 + r2) = s[n2] * expl(r1 + r2). */ + /* Here q = q(r), not q(r1), since r1 is lopped like L1. */ + t45 = r * P5 + P4; + z = r * r; + t23 = r * P3 + P2; + q = r2 + z * t23 + z * z * t45 + z * z * z * P6; + t = (long double)s[n2].lo + s[n2].hi; + t = s[n2].lo + t * (q + r1) + s[n2].hi; + + /* Scale by 2**k. */ + if (k >= LDBL_MIN_EXP) { + if (k == LDBL_MAX_EXP) + RETURNI(t * 2.0L * 0x1p16383L); + RETURNI(t * twopk); + } else { + RETURNI(t * twopkp10000 * twom10000); + } +} diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/ld80/s_nanl.c similarity index 79% copy from lib/libm/src/s_copysignl.c copy to lib/libm/ld80/s_nanl.c index a209a1e233..d6c90452ec 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/ld80/s_nanl.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 Stefan Farfeleder + * Copyright (c) 2007 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,20 +23,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/ld80/s_nanl.c 174759 2007-12-18 23:46:32Z das $ */ #include #include "fpmath.h" +#include "../src/math_private.h" long double -copysignl(long double x, long double y) +nanl(const char *s) { - union IEEEl2bits ux, uy; + union { + union IEEEl2bits ieee; + uint32_t bits[3]; + } u; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + _scan_nan(u.bits, 3, s); + u.ieee.bits.exp = 0x7fff; + u.ieee.bits.manh |= 0xc0000000; /* make it a quiet NaN */ + return (u.ieee.e); } diff --git a/lib/libm/man/Makefile.inc b/lib/libm/man/Makefile.inc deleted file mode 100644 index f484418840..0000000000 --- a/lib/libm/man/Makefile.inc +++ /dev/null @@ -1,76 +0,0 @@ -.PATH: ${.CURDIR}/man - -MAN+= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 ceil.3 \ - cos.3 cosh.3 erf.3 exp.3 fabs.3 fdim.3 feclearexcept.3 feenableexcept.3 \ - fegetenv.3 fegetround.3 fenv.3 floor.3 fmax.3 fmod.3 hypot.3 \ - ieee_test.3 j0.3 lgamma.3 math.3 rint.3 round.3 sin.3 \ - sinh.3 sqrt.3 tan.3 tanh.3 trunc.3 -MAN+= copysign.3 frexp.3 ilogb.3 log.3 scalbn.3 nextafter.3 remainder.3 \ - finite.3 -MAN+= fma.3 lrint.3 lround.3 - -MLINKS+=acos.3 acosf.3 acos.3 acosl.3 -MLINKS+=acosh.3 acoshf.3 -MLINKS+=asin.3 asinf.3 asin.3 asinl.3 -MLINKS+=asinh.3 asinhf.3 -MLINKS+=atan.3 atanf.3 atan.3 atanl.3 -MLINKS+=atan2.3 atan2f.3 atan2.3 atan2l.3 -MLINKS+=atanh.3 atanhf.3 -MLINKS+=ceil.3 ceilf.3 ceil.3 ceill.3 -MLINKS+=cos.3 cosf.3 cos.3 cosl.3 -MLINKS+=cosh.3 coshf.3 -MLINKS+=erf.3 erff.3 erf.3 erfc.3 erf.3 erfcf.3 -MLINKS+=log.3 logf.3 log.3 log10.3 log.3 log10f.3 log.3 log1p.3 log.3 log1pf.3 \ - log.3 log2.3 log.3 log2f.3 log.3 logl.3 -MLINKS+=exp.3 expf.3 exp.3 exp2.3 exp.3 exp2f.3 exp.3 expm1.3 exp.3 expm1f.3 -MLINKS+=exp.3 powf.3 exp.3 pow.3 exp.3 exp2l.3 - -MLINKS+=fabs.3 fabsf.3 fabs.3 fabsl.3 -MLINKS+=fdim.3 fdimf.3 fdim.3 fdiml.3 -MLINKS+=feclearexcept.3 fegetexceptflag.3 feclearexcept.3 feraiseexcept.3 \ - feclearexcept.3 fesetexceptflag.3 feclearexcept.3 fetestexcept.3 -MLINKS+=feenableexcept.3 fedisableexcept.3 feenableexcept.3 fegetexcept.3 -MLINKS+=fegetenv.3 feholdexcept.3 fegetenv.3 fesetenv.3 fegetenv.3 feupdateenv.3 -MLINKS+=fegetround.3 fesetround.3 -MLINKS+=floor.3 floorf.3 floor.3 floorl.3 -MLINKS+=fmax.3 fmaxf.3 fmax.3 fmaxl.3 \ - fmax.3 fmin.3 fmax.3 fminf.3 fmax.3 fminl.3 -MLINKS+=fmod.3 fmodf.3 fmod.3 fmodl.3 -MLINKS+=hypot.3 hypotf.3 hypot.3 hypotl.3 -MLINKS+=hypot.3 cabs.3 hypot.3 cabsf.3 hypot.3 cabsl.3 -MLINKS+=ieee_test.3 logb.3 ieee_test.3 logbf.3 ieee_test.3 scalb.3 \ - ieee_test.3 scalbf.3 ieee_test.3 significand.3 \ - ieee_test.3 significandf.3 -MLINKS+=j0.3 j0f.3 j0.3 j1.3 j0.3 j1f.3 j0.3 jn.3 j0.3 jnf.3 j0.3 y0.3 \ - j0.3 y0f.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 j0.3 ynf.3 -MLINKS+=lgamma.3 lgammaf.3 lgamma.3 lgamma_r.3 lgamma.3 lgammaf_r.3 \ - lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 gamma_r.3 \ - lgamma.3 gammaf_r.3 lgamma.3 tgamma.3 lgamma.3 tgammaf.3 -MLINKS+=rint.3 nearbyint.3 rint.3 nearbyintf.3 rint.3 nearbyintl.3 -MLINKS+=rint.3 rintf.3 rint.3 rintl.3 -MLINKS+=round.3 roundf.3 round.3 roundl.3 -MLINKS+=sin.3 sinf.3 sin.3 sinl.3 -MLINKS+=sinh.3 sinhf.3 -MLINKS+=sqrt.3 cbrtf.3 sqrt.3 cbrtl.3 sqrt.3 cbrt.3 -MLINKS+=sqrt.3 sqrtf.3 sqrt.3 sqrtl.3 -MLINKS+=tan.3 tanf.3 tan.3 tanl.3 -MLINKS+=tanh.3 tanhf.3 -MLINKS+=trunc.3 truncf.3 trunc.3 truncl.3 -MLINKS+=copysign.3 copysignf.3 copysign.3 copysignl.3 -MLINKS+=scalbn.3 scalbnf.3 scalbn.3 scalbnl.3 -MLINKS+=scalbn.3 scalbln.3 scalbn.3 scalblnf.3 scalbn.3 scalblnl.3 -MLINKS+=scalbn.3 ldexp.3 scalbn.3 ldexpf.3 scalbn.3 ldexpl.3 -MLINKS+=pow.3 powf.3 -MLINKS+=frexp.3 frexpf.3 frexp.3 frexpl.3 -MLINKS+=ilogb.3 logb.3 ilogb.3 logbf.3 logb.3 logbl.3 -MLINKS+=ilogb.3 ilogbf.3 ilogb.3 ilogbl.3 -MLINKS+=nextafter.3 nextafterf.3 nextafter.3 nextafterl.3 -MLINKS+=nextafter.3 nexttoward.3 nextafter.3 nexttowardf.3 -MLINKS+=remainder.3 remainderf.3 remainder.3 remainderl.3 -MLINKS+=remainder.3 remquo.3 remainder.3 remquof.3 remainder.3 remquol.3 -MLINKS+=finite.3 finitef.3 -MLINKS+=fma.3 fmaf.3 fma.3 fmal.3 -MLINKS+=lrint.3 lrintf.3 lrint.3 lrintl.3 -MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 llrintl.3 -MLINKS+=lround.3 lroundf.3 lround.3 lroundl.3 -MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 diff --git a/lib/libm/man/acos.3 b/lib/libm/man/acos.3 index eb854748d9..082ecae59a 100644 --- a/lib/libm/man/acos.3 +++ b/lib/libm/man/acos.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)acos.3 5.1 (Berkeley) 5/2/91 -.\" FreeBSD SVN: 181074 (2008-07-31) +.\" $FreeBSD: head/lib/msun/man/acos.3 181074 2008-07-31 22:41:26Z das $ .\" .Dd December 21, 2011 .Dt ACOS 3 diff --git a/lib/libm/man/acosh.3 b/lib/libm/man/acosh.3 index ed078d5516..8db27ea782 100644 --- a/lib/libm/man/acosh.3 +++ b/lib/libm/man/acosh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)acosh.3 5.2 (Berkeley) 5/6/91 -.\" FreeBSD SVN: 165906 (2007-01-09) +.\" $FreeBSD: head/lib/msun/man/acosh.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd January 14, 2005 .Dt ACOSH 3 diff --git a/lib/libm/man/asin.3 b/lib/libm/man/asin.3 index 86beed0e92..a7ef2387ac 100644 --- a/lib/libm/man/asin.3 +++ b/lib/libm/man/asin.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)asin.3 5.1 (Berkeley) 5/2/91 -.\" FreeBSD: 181074 (2008-07-31) +.\" $FreeBSD: head/lib/msun/man/asin.3 181074 2008-07-31 22:41:26Z das $ .\" .Dd December 21, 2011 .Dt ASIN 3 diff --git a/lib/libm/man/asinh.3 b/lib/libm/man/asinh.3 index 40b5b58474..77ac19e7ec 100644 --- a/lib/libm/man/asinh.3 +++ b/lib/libm/man/asinh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)asinh.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/asinh.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd May 6, 1991 .Dt ASINH 3 diff --git a/lib/libm/man/atan.3 b/lib/libm/man/atan.3 index 0aac319166..3f9b35ac7a 100644 --- a/lib/libm/man/atan.3 +++ b/lib/libm/man/atan.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)atan.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/atan.3 181074 2008-07-31 22:41:26Z das $ .\" .Dd December 21, 2011 .Dt ATAN 3 diff --git a/lib/libm/man/atan2.3 b/lib/libm/man/atan2.3 index a716d028bf..778b098f55 100644 --- a/lib/libm/man/atan2.3 +++ b/lib/libm/man/atan2.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/atan2.3 208935 2010-06-09 07:31:32Z uqs $ .\" .Dd December 21, 2011 .Dt ATAN2 3 @@ -34,8 +34,11 @@ .Sh NAME .Nm atan2 , .Nm atan2f , -.Nm atan2l -.Nd arc tangent function of two variables +.Nm atan2l , +.Nm carg , +.Nm cargf , +.Nm cargl +.Nd arc tangent and complex phase angle functions .Sh LIBRARY .Lb libm .Sh SYNOPSIS @@ -46,6 +49,13 @@ .Fn atan2f "float y" "float x" .Ft long double .Fn atan2l "long double y" "long double x" +.In complex.h +.Ft double +.Fn carg "double complex z" +.Ft float +.Fn cargf "float complex z" +.Ft long double +.Fn cargl "long double complex z" .Sh DESCRIPTION The .Fn atan2 , @@ -56,6 +66,26 @@ functions compute the principal value of the arc tangent of .Fa y/ Ns Ar x , using the signs of both arguments to determine the quadrant of the return value. +.Pp +The +.Fn carg , +.Fn cargf , +and +.Fn cargl +functions compute the complex argument (or phase angle) of +.Fa z . +The complex argument is the number theta such that +.Li z = r * e^(I * theta) , +where +.Li r = cabs(z) . +The call +.Li carg(z) +is equivalent to +.Li atan2(cimag(z), creal(z)) , +and similarly for +.Fn cargf +and +.Fn cargl . .Sh RETURN VALUES The .Fn atan2 , @@ -76,26 +106,26 @@ Here are some of the special cases: .Fn atan y/x Ta if .Ar x -\*[Gt] 0, +> 0, .It Ta sign( Ns Ar y Ns )*(\*(Pi - -.Fn atan "\\*(Bay/x\\*(Ba" ) Ta +.Fn atan "\*(Bay/x\*(Ba" ) Ta if .Ar x -\*[Lt] 0, +< 0, .It Ta .No 0 Ta if x = y = 0, or .It Ta -.Pf sign( Ar y Ns )*\\*(Pi/2 Ta +.Pf sign( Ar y Ns )*\*(Pi/2 Ta if .Ar x -= 0 \*(Ne += 0 \(!= .Ar y . .El .Sh NOTES The function .Fn atan2 -defines "if x \*[Gt] 0," +defines "if x > 0," .Fn atan2 0 0 = 0 despite that previously .Fn atan2 0 0 @@ -175,7 +205,6 @@ r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); .Xr asin 3 , .Xr atan 3 , .Xr cabs 3 , -.Xr carg 3 , .Xr cos 3 , .Xr cosh 3 , .Xr math 3 , @@ -187,7 +216,10 @@ r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); The .Fn atan2 , .Fn atan2f , +.Fn atan2l , +.Fn carg , +.Fn cargf , and -.Fn atan2l +.Fn cargl functions conform to .St -isoC-99 . diff --git a/lib/libm/man/atanh.3 b/lib/libm/man/atanh.3 index cc5342dcee..9c1480a24f 100644 --- a/lib/libm/man/atanh.3 +++ b/lib/libm/man/atanh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)atanh.3 5.2 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/atanh.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd January 14, 2005 .Dt ATANH 3 diff --git a/lib/libm/man/cacos.3 b/lib/libm/man/cacos.3 new file mode 100644 index 0000000000..fee38bc0d2 --- /dev/null +++ b/lib/libm/man/cacos.3 @@ -0,0 +1,128 @@ +.\" Copyright (c) 2013 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/msun/man/cacos.3 251121 2013-05-30 04:49:26Z das $ +.\" +.Dd May 27, 2013 +.Dt CACOS 3 +.Os +.Sh NAME +.Nm cacos , +.Nm cacosf , +.Nm cacosh , +.Nm cacoshf , +.Nm casin , +.Nm casinf +.Nm casinh , +.Nm casinhf +.Nm catan , +.Nm catanf +.Nm catanh , +.Nm catanhf +.Nd complex arc trigonometric and hyperbolic functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn cacos "double complex z" +.Ft float complex +.Fn cacosf "float complex z" +.Ft double complex +.Fn cacosh "double complex z" +.Ft float complex +.Fn cacoshf "float complex z" +.Ft double complex +.Fn casin "double complex z" +.Ft float complex +.Fn casinf "float complex z" +.Ft double complex +.Fn casinh "double complex z" +.Ft float complex +.Fn casinhf "float complex z" +.Ft double complex +.Fn catan "double complex z" +.Ft float complex +.Fn catanf "float complex z" +.Ft double complex +.Fn catanh "double complex z" +.Ft float complex +.Fn catanhf "float complex z" +.Sh DESCRIPTION +The +.Fn cacos , +.Fn casin , +and +.Fn catan +functions compute the principal value of the inverse cosine, sine, +and tangent of the complex number +.Fa z , +respectively. +The +.Fn cacosh , +.Fn casinh , +and +.Fn catanh +functions compute the principal value of the inverse hyperbolic +cosine, sine, and tangent. +The +.Fn cacosf , +.Fn casinf , +.Fn catanf +.Fn cacoshf , +.Fn casinhf , +and +.Fn catanhf +functions perform the same operations in +.Fa float +precision. +.Pp +.ie '\*[.T]'utf8' +. ds Un \[cu] +.el +. ds Un U +. +There is no universal convention for defining the principal values of +these functions. The following table gives the branch cuts, and the +corresponding ranges for the return values, adopted by the C language. +.Bl -column ".Sy Function" ".Sy (-\*(If*I, -I) \*(Un (I, \*(If*I)" ".Sy [-\*(Pi/2*I, \*(Pi/2*I]" +.It Sy Function Ta Sy Branch Cut(s) Ta Sy Range +.It cacos Ta (-\*(If, -1) \*(Un (1, \*(If) Ta [0, \*(Pi] +.It casin Ta (-\*(If, -1) \*(Un (1, \*(If) Ta [-\*(Pi/2, \*(Pi/2] +.It catan Ta (-\*(If*I, -i) \*(Un (I, \*(If*I) Ta [-\*(Pi/2, \*(Pi/2] +.It cacosh Ta (-\*(If, 1) Ta [-\*(Pi*I, \*(Pi*I] +.It casinh Ta (-\*(If*I, -i) \*(Un (I, \*(If*I) Ta [-\*(Pi/2*I, \*(Pi/2*I] +.It catanh Ta (-\*(If, -1) \*(Un (1, \*(If) Ta [-\*(Pi/2*I, \*(Pi/2*I] +.El +.Sh SEE ALSO +.Xr ccos 3 , +.Xr ccosh 3 , +.Xr complex 3 , +.Xr cos 3 , +.Xr math 3 , +.Xr sin 3 , +.Xr tan 3 +.Sh STANDARDS +These functions conform to +.St -isoC-99 . diff --git a/lib/libm/man/trunc.3 b/lib/libm/man/ccos.3 similarity index 62% copy from lib/libm/man/trunc.3 copy to lib/libm/man/ccos.3 index 563601bdd4..573b395bed 100644 --- a/lib/libm/man/trunc.3 +++ b/lib/libm/man/ccos.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2004, 2005 David Schultz +.\" Copyright (c) 2011 David Schultz .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,61 +22,60 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/ccos.3 251121 2013-05-30 04:49:26Z das $ .\" -.Dd December 21, 2011 -.Dt TRUNC 3 +.Dd October 17, 2011 +.Dt CCOS 3 .Os .Sh NAME -.Nm trunc , -.Nm truncf , -.Nm truncl -.Nd nearest integral value with magnitude less than or equal to |x| +.Nm ccos , +.Nm ccosf , +.Nm csin , +.Nm csinf +.Nm ctan , +.Nm ctanf +.Nd complex trigonometric functions .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" +.In complex.h +.Ft double complex +.Fn ccos "double complex z" +.Ft float complex +.Fn ccosf "float complex z" +.Ft double complex +.Fn csin "double complex z" +.Ft float complex +.Fn csinf "float complex z" +.Ft double complex +.Fn ctan "double complex z" +.Ft float complex +.Fn ctanf "float complex z" .Sh DESCRIPTION The -.Fn trunc , -.Fn truncf , +.Fn ccos , +.Fn csin , 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 , +.Fn ctan +functions compute the cosine, sine, and tangent of the complex number +.Fa z , +respectively. +The +.Fn ccosf , +.Fn csinf , and -.Fn rintl , -respectively, in the -.Dv FE_TOWARDZERO -rounding mode. +.Fn ctanf +functions perform the same operations in +.Fa float +precision. .Sh SEE ALSO -.Xr ceil 3 , -.Xr fesetround 3 , -.Xr floor 3 , +.Xr cacos 3 , +.Xr ccosh 3 , +.Xr complex 3 , +.Xr cos 3 , .Xr math 3 , -.Xr nextafter 3 , -.Xr rint 3 , -.Xr round 3 +.Xr sin 3 , +.Xr tan 3 .Sh STANDARDS -The -.Fn trunc , -.Fn truncf , -and -.Fn truncl -functions conform to +These functions conform to .St -isoC-99 . -.Sh HISTORY -These routines first appeared in -.Dx 1.9 . -The long double version appeared in -.Dx 2.13 . diff --git a/lib/libm/man/trunc.3 b/lib/libm/man/ccosh.3 similarity index 61% copy from lib/libm/man/trunc.3 copy to lib/libm/man/ccosh.3 index 563601bdd4..b5c0eab0b4 100644 --- a/lib/libm/man/trunc.3 +++ b/lib/libm/man/ccosh.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2004, 2005 David Schultz +.\" Copyright (c) 2011 David Schultz .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,61 +22,60 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/ccosh.3 251121 2013-05-30 04:49:26Z das $ .\" -.Dd December 21, 2011 -.Dt TRUNC 3 +.Dd October 17, 2011 +.Dt CCOSH 3 .Os .Sh NAME -.Nm trunc , -.Nm truncf , -.Nm truncl -.Nd nearest integral value with magnitude less than or equal to |x| +.Nm ccosh , +.Nm ccoshf , +.Nm csinh , +.Nm csinhf +.Nm ctanh , +.Nm ctanhf +.Nd complex hyperbolic functions .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" +.In complex.h +.Ft double complex +.Fn ccosh "double complex z" +.Ft float complex +.Fn ccoshf "float complex z" +.Ft double complex +.Fn csinh "double complex z" +.Ft float complex +.Fn csinhf "float complex z" +.Ft double complex +.Fn ctanh "double complex z" +.Ft float complex +.Fn ctanhf "float complex z" .Sh DESCRIPTION The -.Fn trunc , -.Fn truncf , +.Fn ccosh , +.Fn csinh , 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 , +.Fn ctanh +functions compute the hyperbolic cosine, sine, and tangent of the complex number +.Fa z , +respectively. +The +.Fn ccoshf , +.Fn csinhf , and -.Fn rintl , -respectively, in the -.Dv FE_TOWARDZERO -rounding mode. +.Fn ctanhf +functions perform the same operations in +.Fa float +precision. .Sh SEE ALSO -.Xr ceil 3 , -.Xr fesetround 3 , -.Xr floor 3 , +.Xr cacosh 3 , +.Xr ccos 3 , +.Xr complex 3 , +.Xr cosh 3 , .Xr math 3 , -.Xr nextafter 3 , -.Xr rint 3 , -.Xr round 3 +.Xr sinh 3 , +.Xr tanh 3 .Sh STANDARDS -The -.Fn trunc , -.Fn truncf , -and -.Fn truncl -functions conform to +These functions conform to .St -isoC-99 . -.Sh HISTORY -These routines first appeared in -.Dx 1.9 . -The long double version appeared in -.Dx 2.13 . diff --git a/lib/libm/man/ceil.3 b/lib/libm/man/ceil.3 index 9b4e0c6b60..dd24bfbee0 100644 --- a/lib/libm/man/ceil.3 +++ b/lib/libm/man/ceil.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ceil.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/ceil.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt CEIL 3 @@ -60,6 +60,7 @@ expressed as a floating-point number. .Xr abs 3 , .Xr fabs 3 , .Xr floor 3 , +.Xr ieee 3 , .Xr math 3 , .Xr rint 3 , .Xr round 3 , diff --git a/lib/libm/man/log.3 b/lib/libm/man/cexp.3 similarity index 52% copy from lib/libm/man/log.3 copy to lib/libm/man/cexp.3 index 163e782d94..807da39e87 100644 --- a/lib/libm/man/log.3 +++ b/lib/libm/man/cexp.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2008-2010 David Schultz +.\" Copyright (c) 2011 David Schultz .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,97 +22,92 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/cexp.3 240368 2012-09-11 17:40:06Z joel $ .\" -.Dd December 21, 2011 -.Dt LOG 3 +.Dd March 6, 2011 +.Dt CEXP 3 .Os .Sh NAME -.Nm log , -.Nm logf , -.Nm logl , -.Nm log10 , -.Nm log10f , -.Nm log2 , -.Nm log2f , -.Nm log1p , -.Nm log1pf -.Nd logarithm functions +.Nm cexp , +.Nm cexpf +.Nd complex exponential functions .Sh LIBRARY .Lb libm .Sh SYNOPSIS -.In math.h -.Ft double -.Fn log "double x" -.Ft float -.Fn logf "float x" -.Ft double -.Fn log10 "double x" -.Ft float -.Fn log10f "float x" -.Ft double -.Fn log2 "double x" -.Ft float -.Fn log2f "float x" -.Ft double -.Fn log1p "double x" -.Ft float -.Fn log1pf "float x" +.In complex.h +.Ft double complex +.Fn cexp "double complex z" +.Ft float complex +.Fn cexpf "float complex z" .Sh DESCRIPTION The -.Fn log +.Fn cexp and -.Fn logf -functions compute the natural logarithm of -.Fa x . -.Pp -The -.Fn log10 -and -.Fn log10f -functions compute the logarithm base 10 of -.Fa x , -while -.Fn log2 +.Fn cexpf +functions compute the complex exponential of +.Fa z , +also known as +.Em cis Ns ( Ns +.Fa z Ns ) . +.Sh RETURN VALUES +For real numbers +.Fa x and -.Fn log2f -compute the logarithm base 2 of -.Fa x . +.Fa y , +.Fn cexp +behaves according to Euler's formula: +.Bd -ragged -offset indent +.Fn cexp "x + I*y" += +.Po Sy e Ns ** Ns +.Fa x * +.Em cos Ns Po Ns +.Fa y Ns Pc Pc + Po Ns +.Sy I +* +.Sy e Ns ** Ns +.Fa x +* +.Em sin Ns Po Ns +.Fa y Ns Pc Pc +.Ed .Pp -The -.Fn log1p +Generally speaking, infinities, zeroes and \*(Nas are handled as would +be expected from this identity given the usual rules of floating-point +arithmetic. +However, care is taken to avoid generating \*(Nas when they are not deserved. +For example, mathematically we expect that +.Fo cimag +.Fn cexp "x + I*0" Fc += 0 regardless of the value of +.Fa x , and -.Fn log1pf -functions compute the natural logarithm of -.No "1 + x" . -Computing the natural logarithm as -.Li log1p(x) -is more accurate than computing it as -.Li log(1 + x) -when +.Fn cexp +preserves this identity even if .Fa x -is close to zero. -.Sh RETURN VALUES -These functions return the requested logarithm; the logarithm of 1 is +0. -An attempt to take the logarithm of \*(Pm0 results in a divide-by-zero -exception, and -\*(If is returned. -Otherwise, attempting to take the logarithm of a negative number -results in an invalid exception and a return value of \*(Na. +is \*(If or \*(Na. +Likewise, +.Fn cexp "-\*(If + I*y" += 0 and +.Fo creal +.Fn cexp "\*(If + I*y" Fc += \*(If +for any +.Fa y +(even though the latter property is only mathematically true for +representable +.Fa y . ) +If +.Fa y +is not finite, the sign of the result is indeterminate. .Sh SEE ALSO +.Xr complex 3 , .Xr exp 3 , -.Xr ilogb 3 , .Xr math 3 , -.Xr pow 3 .Sh STANDARDS The -.Fn log , -.Fn logf , -.Fn log10 , -.Fn log10f , -.Fn log2 , -.Fn log2f , -.Fn log1p , +.Fn cexp and -.Fn log1pf +.Fn cexpf functions conform to .St -isoC-99 . diff --git a/lib/libm/man/fmax.3 b/lib/libm/man/cimag.3 similarity index 50% copy from lib/libm/man/fmax.3 copy to lib/libm/man/cimag.3 index e358d844cb..7aad9a5143 100644 --- a/lib/libm/man/fmax.3 +++ b/lib/libm/man/cimag.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2004 David Schultz +.\" Copyright (c) 2004 Stefan Farfeleder .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,74 +22,91 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd May 31, 2009 -.Dt FMAX 3 +.\" $FreeBSD: head/lib/msun/man/cimag.3 205076 2010-03-12 10:01:06Z uqs $ +.\" +.Dd August 7, 2008 +.Dt CIMAG 3 .Os .Sh NAME -.Nm fmax , -.Nm fmaxf , -.Nm fmaxl , -.Nm fmin , -.Nm fminf , -.Nm fminl -.Nd floating-point maximum and minimum functions +.Nm cimag , cimagf , cimagl , +.Nm conj , conjf , conjl , +.Nm cproj , cprojf , cprojl , +.Nm creal , crealf , creall +.Nd "functions to manipulate complex numbers" .Sh LIBRARY .Lb libm .Sh SYNOPSIS -.In math.h +.In complex.h .Ft double -.Fn fmax "double x" "double y" +.Fn cimag "double complex z" .Ft float -.Fn fmaxf "float x" "float y" +.Fn cimagf "float complex z" .Ft "long double" -.Fn fmaxl "long double x" "long double y" +.Fn cimagl "long double complex z" +.Ft "double complex" +.Fn conj "double complex z" +.Ft "float complex" +.Fn conjf "float complex z" +.Ft "long double complex" +.Fn conjl "long double complex z" +.Ft "double complex" +.Fn cproj "double complex z" +.Ft "float complex" +.Fn cprojf "float complex z" +.Ft "long double complex" +.Fn cprojl "long double complex z" .Ft double -.Fn fmin "double x" "double y" +.Fn creal "double complex z" .Ft float -.Fn fminf "float x" "float y" +.Fn crealf "float complex z" .Ft "long double" -.Fn fminl "long double x" "long double y" +.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 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 +.Fn creal +functions return the real part +.Fa a , +and the +.Fn cimag +functions return the imaginary part +.Fa b . +.Pp +The +.Fn conj +functions return the complex conjugate +.Sm off +.Fa a - b * Em i . +.Sm on +.Pp +The +.Fn cproj +functions return the projection onto the Riemann sphere. +If +.Fa z +contains an infinite component, then the result is +.Fa \*(If \*(Pm 0 Ns * Ns Em i , +where the (zero) imaginary part of the result has the same sign as +.Fa b . +Otherwise, the result is +.Fa z . +.Pp +These functions do not signal any floating point exceptions. .Sh STANDARDS The -.Fn fmax , -.Fn fmaxf , -.Fn fmaxl , -.Fn fmin , -.Fn fminf , +.Fn cimag , +.Fn conj , +.Fn cproj , and -.Fn fminl +.Fn creal functions conform to .St -isoC-99 . .Sh HISTORY -These routines first appeared in +These functions first appeared in .Dx 2.3 . diff --git a/lib/libm/man/complex.3 b/lib/libm/man/complex.3 new file mode 100644 index 0000000000..553da6bbff --- /dev/null +++ b/lib/libm/man/complex.3 @@ -0,0 +1,124 @@ +.\" Copyright (c) 2011 Murray Stokely +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/msun/man/complex.3 251121 2013-05-30 04:49:26Z das $ +.\" +.Dd October 17, 2011 +.Dt COMPLEX 3 +.Os +.Sh NAME +.Nm complex +.Nd "complex arithmetic" +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Sh DESCRIPTION +These functions support complex arithmetic in the C math library. +.Sh "LIST OF FUNCTIONS" +Each of the following +.Vt "double complex" +functions has a +.Vt "float complex" +counterpart with an +.Ql f +appended to the name and a +.Vt "long double complex" +counterpart with an +.Ql l +appended. +As an example, the +.Vt "float complex" +and +.Vt "long double complex" +counterparts of +.Ft double +.Fn cabs "double complex z" +are +.Ft float +.Fn cabsf "float complex z" +and +.Ft "long double" +.Fn cabsl "long double complex z" , +respectively. +.de Cl +.Bl -column "csqrt" "complex absolute value (i.e. norm, modulus, magnitude)" +.Em "Name Description" +.. +.\" Section 7.3.5 - 7.3.7 of ISO C99 standard unimplemented, see BUGS +.\" Section 7.3.8 of ISO C99 standard +.Ss Absolute-value Functions +.Cl +cabs complex absolute value (i.e. norm, modulus, magnitude) +csqrt complex square root +.El +.Ss Exponential Function +.Cl +cexp exponential base e +.El +.\" Section 7.3.9 of ISO C99 standard +.Ss Manipulation Functions +.Cl +carg compute the argument (i.e. phase angle) +cimag compute the imaginary part +conj compute the complex conjugate +cproj compute projection onto Riemann sphere +creal compute the real part +.El +.\" Section 7.3.5-6 of ISO C99 standard +.Ss Trigonometric and Hyperbolic Functions +.Cl +cacos arc cosine +cacosh arc hyperbolic cosine +casin arc sine +casinh arc hyperbolic sine +catan arc tangent +catanh arc hyperbolic tangent +ccos cosine +ccosh hyperbolic cosine +csin sine +csinh hyperbolic sine +ctan tangent +ctanh hyperbolic tangent +.El +.Sh SEE ALSO +.Xr math 3 , +.Xr fenv 3 , +.Xr ieee 3 , +.Xr tgmath 3 +.Rs +.%T "ISO/IEC 9899:TC3" +.%U http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf +.Re +.Sh STANDARDS +The +.In complex.h +functions described here conform to +.St -isoC-99 . +.Sh BUGS +The logarithmic functions +.Fn clog +and the power functions +.Fn cpow +are not implemented. diff --git a/lib/libm/man/copysign.3 b/lib/libm/man/copysign.3 index 127eeab740..ab5cbc6492 100644 --- a/lib/libm/man/copysign.3 +++ b/lib/libm/man/copysign.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/copysign.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt COPYSIGN 3 @@ -60,6 +60,7 @@ with its sign changed to .Sh SEE ALSO .Xr fabs 3 , .Xr fdim 3 , +.Xr ieee 3 , .Xr math 3 .Sh STANDARDS The diff --git a/lib/libm/man/cos.3 b/lib/libm/man/cos.3 index 15a0bf2ee7..6d8430bd2a 100644 --- a/lib/libm/man/cos.3 +++ b/lib/libm/man/cos.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)cos.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/cos.3 226458 2011-10-17 05:41:03Z das $ .\" .Dd December 21, 2011 .Dt COS 3 diff --git a/lib/libm/man/cosh.3 b/lib/libm/man/cosh.3 index 16f7f6af8e..bc95df4cf0 100644 --- a/lib/libm/man/cosh.3 +++ b/lib/libm/man/cosh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)cosh.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/cosh.3 226458 2011-10-17 05:41:03Z das $ .\" .Dd January 14, 2005 .Dt COSH 3 @@ -50,15 +50,6 @@ and the .Fn coshf functions compute the hyperbolic cosine of .Fa x . -.Sh RETURN VALUES -If the magnitude of x is too large, -.Fn cosh "x" -and -.Fn coshf "x" -return Inf and sets the global variable -.Va errno -to -.Er ERANGE . .Sh SEE ALSO .Xr acos 3 , .Xr asin 3 , diff --git a/lib/libm/man/csqrt.3 b/lib/libm/man/csqrt.3 new file mode 100644 index 0000000000..3aa1af383e --- /dev/null +++ b/lib/libm/man/csqrt.3 @@ -0,0 +1,102 @@ +.\" Copyright (c) 2007-2008 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/msun/man/csqrt.3 233992 2012-04-07 09:05:30Z joel $ +.\" +.Dd March 30, 2008 +.Dt CSQRT 3 +.Os +.Sh NAME +.Nm csqrt , +.Nm csqrtf , +.Nm csqrtl +.Nd complex square root functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In complex.h +.Ft double complex +.Fn csqrt "double complex z" +.Ft float complex +.Fn csqrtf "float complex z" +.Ft long double complex +.Fn csqrtl "long double complex z" +.Sh DESCRIPTION +The +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +functions compute the square root of +.Fa z +in the complex plane, with a branch cut along the negative real axis. +In other words, +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +always return the square root whose real part is non-negative. +.Sh RETURN VALUES +These functions return the requested square root. +The square root of 0 is +.Li +0 \*(Pm 0 , +where the imaginary parts of the input and respective result have +the same sign. +For infinities and \*(Nas, the following rules apply, with the +earlier rules having precedence: +.Bl -column -offset indent "-\*(If + \*(Na*I" "\*(If \*(Pm \*(If*I " "(for all k)" +.Em "Input" Ta Em "Result" Ta \& +k + \*(If*I \*(If + \*(If*I (for all k) +-\*(If + \*(Na*I \*(Na \*(Pm \*(If*I \& +\*(If + \*(Na*I \*(If + \*(Na*I \& +k + \*(Na*I \*(Na + \*(Na*I \& +\*(Na + k*I \*(Na + \*(Na*I \& +-\*(If + k*I +0 + \*(If*I \& +\*(If + k*I \*(If + 0*I \& +.El +.Pp +For numbers with negative imaginary parts, the above special cases +apply given the identity: +.Dl csqrt(conj(z) = conj(sqrt(z)) +Note that the sign of \*(Na is indeterminate. +Also, if the real or imaginary part of the input is finite and +an \*(Na is generated, an invalid exception will be thrown. +.Sh SEE ALSO +.Xr cabs 3 , +.Xr fenv 3 , +.Xr math 3 , +.Sh STANDARDS +The +.Fn csqrt , +.Fn csqrtf , +and +.Fn csqrtl +functions conform to +.St -isoC-99 . +.Sh BUGS +For +.Fn csqrt +and +.Fn csqrtl , +inexact results are not always correctly rounded. diff --git a/lib/libm/man/erf.3 b/lib/libm/man/erf.3 index 6d234e85a0..c34234d104 100644 --- a/lib/libm/man/erf.3 +++ b/lib/libm/man/erf.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)erf.3 6.4 (Berkeley) 4/20/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/erf.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd April 20, 1991 .Dt ERF 3 diff --git a/lib/libm/man/exp.3 b/lib/libm/man/exp.3 index e9307e9250..143aae2a80 100644 --- a/lib/libm/man/exp.3 +++ b/lib/libm/man/exp.3 @@ -26,15 +26,16 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)exp.3 6.12 (Berkeley) 7/31/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/exp.3 238722 2012-07-23 19:13:55Z kargl $ .\" -.Dd December 21, 2011 +.Dd July 10, 2012 .Dt EXP 3 .Os .Sh NAME .Nm exp , .Nm expf , -.\" The sorting error is intentional. exp and expf should be adjacent. +.Nm expl , +.\" The sorting error is intentional. exp, expf, and expl should be adjacent. .Nm exp2 , .Nm exp2f , .Nm exp2l , @@ -51,6 +52,8 @@ .Fn exp "double x" .Ft float .Fn expf "float x" +.Ft long double +.Fn expl "long double x" .Ft double .Fn exp2 "double x" .Ft float @@ -67,9 +70,10 @@ .Fn powf "float x" "float y" .Sh DESCRIPTION The -.Fn exp -and the -.Fn expf +.Fn exp , +.Fn expf , +and +.Fn expl functions compute the base .Ms e exponential value of the given argument diff --git a/lib/libm/man/fabs.3 b/lib/libm/man/fabs.3 index 3b4fd02f86..47e730c293 100644 --- a/lib/libm/man/fabs.3 +++ b/lib/libm/man/fabs.3 @@ -27,7 +27,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)fabs.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/fabs.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt FABS 3 @@ -67,6 +67,7 @@ functions return the absolute value of .Xr abs 3 , .Xr ceil 3 , .Xr floor 3 , +.Xr ieee 3 , .Xr math 3 , .Xr rint 3 .Sh STANDARDS diff --git a/lib/libm/man/fdim.3 b/lib/libm/man/fdim.3 index 3aff734f24..0c3fe8167b 100644 --- a/lib/libm/man/fdim.3 +++ b/lib/libm/man/fdim.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/fdim.3 211397 2010-08-16 15:18:30Z joel $ .\" .Dd June 1, 2009 .Dt FDIM 3 diff --git a/lib/libm/man/feclearexcept.3 b/lib/libm/man/feclearexcept.3 index 073de67b83..c3a52d12df 100644 --- a/lib/libm/man/feclearexcept.3 +++ b/lib/libm/man/feclearexcept.3 @@ -22,7 +22,7 @@ .\" 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 $ +.\" $FreeBSD: head/lib/msun/man/feclearexcept.3 140225 2005-01-14 09:12:05Z ru $ .\" .Dd May 8, 2004 .Dt FECLEAREXCEPT 3 diff --git a/lib/libm/man/feenableexcept.3 b/lib/libm/man/feenableexcept.3 index 0b790e7a32..b82b4bbba2 100644 --- a/lib/libm/man/feenableexcept.3 +++ b/lib/libm/man/feenableexcept.3 @@ -22,7 +22,7 @@ .\" 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 $ +.\" $FreeBSD: head/lib/msun/man/feenableexcept.3 143709 2005-03-16 19:04:28Z das $ .\" .Dd March 16, 2005 .Dt FEENABLEEXCEPT 3 diff --git a/lib/libm/man/fegetenv.3 b/lib/libm/man/fegetenv.3 index 2e386adad4..7f8c2fbf9b 100644 --- a/lib/libm/man/fegetenv.3 +++ b/lib/libm/man/fegetenv.3 @@ -22,7 +22,7 @@ .\" 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 $ +.\" $FreeBSD: head/lib/msun/man/fegetenv.3 130148 2004-06-06 10:06:26Z das $ .\" .Dd May 8, 2004 .Dt FEGETENV 3 diff --git a/lib/libm/man/fegetround.3 b/lib/libm/man/fegetround.3 index 9384158804..72b80dcace 100644 --- a/lib/libm/man/fegetround.3 +++ b/lib/libm/man/fegetround.3 @@ -22,7 +22,7 @@ .\" 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 $ +.\" $FreeBSD: head/lib/msun/man/fegetround.3 140225 2005-01-14 09:12:05Z ru $ .\" .Dd May 8, 2004 .Dt FEGETROUND 3 diff --git a/lib/libm/man/fenv.3 b/lib/libm/man/fenv.3 index d212411549..36f65b2eca 100644 --- a/lib/libm/man/fenv.3 +++ b/lib/libm/man/fenv.3 @@ -22,7 +22,7 @@ .\" 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.6 2007/01/05 07:14:26 das Exp $ +.\" $FreeBSD: head/lib/msun/man/fenv.3 226618 2011-10-21 14:23:59Z das $ .\" .Dd March 16, 2005 .Dt FENV 3 @@ -91,24 +91,35 @@ The following macros expand to bit flags of type 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. +A divide-by-zero exception occurs when the +.Em exact +result of a computation is infinite (according to the limit definition). +For example, dividing a finite non-zero number by zero or computing +.Fn log 0 +raises a divide-by-zero exception. .It Dv FE_INEXACT -An inexact exception is raised whenever there is a loss of precision +An inexact exception is raised whenever there is a loss of accuracy due to rounding. .It Dv FE_INVALID Invalid operation exceptions occur when a program attempts to perform calculations for which there is no reasonable representable answer. -For instance, subtraction of infinities, division of zero by zero, -ordered comparison involving \*(Nas, and taking the square root of a +For instance, subtraction of like-signed infinities, division of zero by zero, +ordered comparison involving \*(Nas, and taking the real square root of a negative number are all invalid operations. .It Dv FE_OVERFLOW -An overflow exception occurs when the magnitude of the result of a -computation is too large to fit in the destination type. +In contrast with divide-by-zero, +an overflow exception occurs when an infinity is produced because +the magnitude of the exact result is +.Em finite +but too large to fit in the destination type. +For example, computing +.Li DBL_MAX * 2 +raises an overflow exception. .It Dv FE_UNDERFLOW -Underflow occurs when the result of a computation is too close to zero -to be represented as a non-zero value in the destination type. +Underflow occurs when the result of a computation loses precision +because it is too close to zero. +The result is a subnormal number or zero. .El .Pp Additionally, the @@ -183,9 +194,9 @@ 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. +.Fn feenableexcept +and +.Fn fedisableexcept . The .Fn feupdateenv function restores a saved environment similarly to @@ -209,18 +220,18 @@ double sqrt(double n) { double x = 1.0; fenv_t env; - if (isnan(n) || n \*[Lt] 0.0) { + if (isnan(n) || n < 0.0) { feraiseexcept(FE_INVALID); return (NAN); } if (isinf(n) || n == 0.0) return (n); - feholdexcept(\*[Am]env); - while (fabs((x * x) - n) \*[Gt] DBL_EPSILON * 2 * x) + 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(\*[Am]env); + feupdateenv(&env); return (x); } .Ed diff --git a/lib/libm/man/finite.3 b/lib/libm/man/finite.3 deleted file mode 100644 index 6b122374ff..0000000000 --- a/lib/libm/man/finite.3 +++ /dev/null @@ -1,82 +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. 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 -.\" $NetBSD: finite.3,v 1.2 2011/08/06 11:09:22 wiz Exp $ -.\" -.Dd July 28, 2011 -.Dt FINITE 3 -.Os -.Sh NAME -.Nm finite , -.Nm finitef -.Nd tests for finite values -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft int -.Fn finite "double x" -.Ft int -.Fn finitef "float x" -.Sh DESCRIPTION -The -.Fn finite -function returns the value 1 when -.Bd -ragged -offset indent -\-\*(If \*(Lt -.Fa x -\*(Lt +\*(If. -.Ed -.Pp -Otherwise a zero is returned -(that is, -.Pf \*(Ba Ns Fa x Ns \*(Ba -= \*(If or -.Fa x -is \*(Na). -.Sh SEE ALSO -.Xr isfinite 3 , -.Xr math 3 -.Sh STANDARDS -The described functions conform to -.St -ieee754 . -Note that unlike -.Xr isfinite 3 , -neither function is present in the -.Dv ISO -C-language standards or in the -.Dv IEEE -.Dv POSIX -standards. -.Sh HISTORY -The -.Nm finite -and -.Fn finitef -functions first appeared in -.Bx 4.3 . diff --git a/lib/libm/man/floor.3 b/lib/libm/man/floor.3 index d05b6ae55f..10a9e95f05 100644 --- a/lib/libm/man/floor.3 +++ b/lib/libm/man/floor.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)floor.3 6.5 (Berkeley) 4/19/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/floor.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt FLOOR 3 @@ -60,6 +60,7 @@ expressed as a floating-point number. .Xr abs 3 , .Xr ceil 3 , .Xr fabs 3 , +.Xr ieee 3 , .Xr math 3 , .Xr rint 3 , .Xr round 3 , diff --git a/lib/libm/man/fma.3 b/lib/libm/man/fma.3 index 6ffa6d08ee..70e37b596b 100644 --- a/lib/libm/man/fma.3 +++ b/lib/libm/man/fma.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" FreeBSD SVN: 152755 (2005-11-24) +.\" $FreeBSD: head/lib/msun/man/fma.3 152755 2005-11-24 09:25:10Z joel $ .\" .Dd December 21, 2011 .Dt FMA 3 @@ -104,5 +104,5 @@ functions conform to A fused multiply-add operation with virtually identical characteristics appears in IEEE draft standard 754R. .Sh HISTORY -The routines first appeared in +These routines first appeared in .Dx 2.13 . diff --git a/lib/libm/man/fmax.3 b/lib/libm/man/fmax.3 index e358d844cb..b87175df25 100644 --- a/lib/libm/man/fmax.3 +++ b/lib/libm/man/fmax.3 @@ -22,6 +22,8 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" +.\" $FreeBSD: head/lib/msun/man/fmax.3 140225 2005-01-14 09:12:05Z ru $ +.\" .Dd May 31, 2009 .Dt FMAX 3 .Os diff --git a/lib/libm/man/fmod.3 b/lib/libm/man/fmod.3 index f01aa959e0..68dd1b8fdd 100644 --- a/lib/libm/man/fmod.3 +++ b/lib/libm/man/fmod.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)fmod.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/fmod.3 179882 2008-06-19 22:39:53Z das $ .\" .Dd June 19, 2008 .Dt FMOD 3 diff --git a/lib/libm/man/frexp.3 b/lib/libm/man/frexp.3 deleted file mode 100644 index 9802202d61..0000000000 --- a/lib/libm/man/frexp.3 +++ /dev/null @@ -1,87 +0,0 @@ -.\" $NetBSD: frexp.3,v 1.2 2010/04/29 08:35:03 joerg Exp $ -.\" -.\" Copyright (c) 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" 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. 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. -.\" -.\" @(#)frexp.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd December 21, 2011 -.Dt FREXP 3 -.Os -.Sh NAME -.Nm frexp -.Nd convert floating-point number to fractional and integral components -.Sh LIBRARY -.Lb libm -.Sh SYNOPSIS -.In math.h -.Ft double -.Fn frexp "double value" "int *exp" -.Ft float -.Fn frexpf "float value" "int *exp" -.Ft long double -.Fn frexpf "long double value" "int *exp" -.Sh DESCRIPTION -The -.Fn frexp -function breaks a floating-point number into a normalized -fraction and an integral power of 2. -It stores the integer in the -.Em int -object pointed to by -.Fa exp . -.Sh RETURN VALUES -The -.Fn frexp -function returns the value -.Em x , -such that -.Em x -is a -.Em double -with magnitude in the interval [1/2, 1) or zero, and -.Fa value -equals -.Em x -times 2 raised to the power -.Fa *exp . -If -.Fa value -is zero, both parts of the result are zero. -.Sh SEE ALSO -.Xr ldexp 3 , -.Xr math 3 , -.Xr modf 3 -.Sh STANDARDS -The -.Fn frexp -function conforms to -.St -ansiC . diff --git a/lib/libm/man/hypot.3 b/lib/libm/man/hypot.3 index 84e1d70bd0..8c0b00cb49 100644 --- a/lib/libm/man/hypot.3 +++ b/lib/libm/man/hypot.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)hypot.3 6.7 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/hypot.3 208028 2010-05-13 12:08:11Z uqs $ .\" .Dd December 21, 2011 .Dt HYPOT 3 diff --git a/lib/libm/man/ieee.3 b/lib/libm/man/ieee.3 new file mode 100644 index 0000000000..93216208ac --- /dev/null +++ b/lib/libm/man/ieee.3 @@ -0,0 +1,446 @@ +.\" 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. 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: head/lib/msun/man/ieee.3 241545 2012-10-14 14:45:54Z joel $ +.\" +.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. +.Pp +If x and x' are consecutive positive single-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bl -column "XXX" -compact +5.9e\-08 < 0.5**24 < (x'\-x)/x \(<= 0.5**23 < 1.2e\-07. +.El +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**128 = 3.4e38 + Underflow threshold = 0.5**126 = 1.2e\-38 +.El +.Pp +Underflowed results round to the nearest +integer multiple of +.Bl -column "XXX" -compact +0.5**149 = 1.4e\-45. +.El +.Ed +.Pp +Double-precision: +.Bd -ragged -offset indent -compact +Type name: +.Vt double +.Po On some architectures, +.Vt long double +is the same as +.Vt double +.Pc +.Pp +Wordsize: 64 bits. +.Pp +Precision: 53 significant bits, +roughly like 16 significant decimals. +.Pp +If x and x' are consecutive positive double-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bl -column "XXX" -compact +1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16. +.El +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**1024 = 1.8e308 + Underflow threshold = 0.5**1022 = 2.2e\-308 +.El +.Pp +Underflowed results round to the nearest +integer multiple of +.Bl -column "XXX" -compact +0.5**1074 = 4.9e\-324. +.El +.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. +.Pp +If x and x' are consecutive positive extended-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bl -column "XXX" -compact +1.0e\-19 < 0.5**63 < (x'\-x)/x \(<= 0.5**62 < 2.2e\-19. +.El +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**16384 = 1.2e4932 + Underflow threshold = 0.5**16382 = 3.4e\-4932 +.El +.Pp +Underflowed results round to the nearest +integer multiple of +.Bl -column "XXX" -compact +0.5**16445 = 5.7e\-4953. +.El +.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. +.Pp +If x and x' are consecutive positive quad-extended-precision +numbers (they differ by 1 +.Em ulp ) , +then +.Bl -column "XXX" -compact +9.6e\-35 < 0.5**113 < (x'\-x)/x \(<= 0.5**112 < 2.0e\-34. +.El +.Pp +.Bl -column "XXX" -compact +Range: Overflow threshold = 2.0**16384 = 1.2e4932 + Underflow threshold = 0.5**16382 = 3.4e\-4932 +.El +.Pp +Underflowed results round to the nearest +integer multiple of +.Bl -column "XXX" -compact +0.5**16494 = 6.5e\-4966. +.El +.Ed +.Ss Additional Information Regarding Exceptions +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/lib/libm/man/ieee_test.3 b/lib/libm/man/ieee_test.3 index 488a7b625b..def1d21173 100644 --- a/lib/libm/man/ieee_test.3 +++ b/lib/libm/man/ieee_test.3 @@ -26,14 +26,12 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" $NetBSD: ieee_test.3,v 1.10 2003/08/07 16:44:48 agc Exp $ +.\" $FreeBSD: head/lib/msun/man/ieee_test.3 165906 2007-01-09 01:02:06Z imp $ .\" -.Dd March 10, 1994 +.Dd November 6, 2005 .Dt IEEE_TEST 3 .Os .Sh NAME -.Nm logb , -.Nm logbf , .Nm scalb , .Nm scalbf , .Nm significand , @@ -44,10 +42,6 @@ .Sh SYNOPSIS .In math.h .Ft double -.Fn logb "double x" -.Ft float -.Fn logbf "float x" -.Ft double .Fn scalb "double x" "double n" .Ft float .Fn scalbf "float x" "float n" @@ -60,36 +54,36 @@ These functions allow users to test conformance to .St -ieee754 . Their use is not otherwise recommended. .Pp -.Fn logb x -returns -.Fa x Ns 's exponent -.Fa n , -a signed integer converted to double\-precision floating\-point. -.Fn logb \*(Pm\*(If -= +\*(If; -.Fn logb 0 -= -\*(If with a division by zero exception. -.Pp -.Fn scalbn x n -returns +.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 -returns +and +.Fn significandf x +return .Fa sig , where .Fa x := .Fa sig No \(** 2** Ns Fa n -with 1 \*[Le] +with 1 \(<= .Fa sig -\*[Lt] 2. +< 2. .Fn significand x -is not defined when +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/lib/libm/man/ilogb.3 b/lib/libm/man/ilogb.3 index beb6be26c2..e964bdb56d 100644 --- a/lib/libm/man/ilogb.3 +++ b/lib/libm/man/ilogb.3 @@ -1,3 +1,4 @@ +.\" Copyright (c) 1985, 1991 Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -25,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/ilogb.3 174698 2007-12-17 03:53:38Z das $ .\" .Dd December 21, 2011 .Dt ILOGB 3 @@ -87,6 +88,7 @@ returns +\*(If, and 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 diff --git a/lib/libm/man/j0.3 b/lib/libm/man/j0.3 index bea06c5070..fa9b890354 100644 --- a/lib/libm/man/j0.3 +++ b/lib/libm/man/j0.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)j0.3 6.7 (Berkeley) 4/19/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/j0.3 176390 2008-02-18 19:02:49Z das $ .\" .Dd February 18, 2008 .Dt J0 3 diff --git a/lib/libm/man/lgamma.3 b/lib/libm/man/lgamma.3 index bee4be0994..c477e5612d 100644 --- a/lib/libm/man/lgamma.3 +++ b/lib/libm/man/lgamma.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)lgamma.3 6.6 (Berkeley) 12/3/92 -.\" FreeBSD SVN: 176388 (2008-02-18) +.\" $FreeBSD: head/lib/msun/man/lgamma.3 176388 2008-02-18 17:27:11Z das $ .\" .Dd December 21, 2011 .Dt LGAMMA 3 @@ -78,7 +78,7 @@ and 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 \*[Lt] 1. +\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px)) for x < 1. .Ed .\} .if n \ diff --git a/lib/libm/man/log.3 b/lib/libm/man/log.3 index 163e782d94..c068b0a1e1 100644 --- a/lib/libm/man/log.3 +++ b/lib/libm/man/log.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/log.3 216211 2010-12-05 22:11:22Z das $ .\" .Dd December 21, 2011 .Dt LOG 3 diff --git a/lib/libm/man/lrint.3 b/lib/libm/man/lrint.3 index 26f0750042..2f4201ede9 100644 --- a/lib/libm/man/lrint.3 +++ b/lib/libm/man/lrint.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/lrint.3 175309 2008-01-14 02:12:07Z das $ .\" .Dd December 21, 2011 .Dt LRINT 3 diff --git a/lib/libm/man/lround.3 b/lib/libm/man/lround.3 index ccbae2473c..1d8ba474f1 100644 --- a/lib/libm/man/lround.3 +++ b/lib/libm/man/lround.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/lround.3 147402 2005-06-15 19:04:04Z ru $ .\" .Dd December 21, 2011 .Dt LROUND 3 diff --git a/lib/libm/man/math.3 b/lib/libm/man/math.3 index 2ea6e250a5..56a7662dde 100644 --- a/lib/libm/man/math.3 +++ b/lib/libm/man/math.3 @@ -1,5 +1,3 @@ -.\" $NetBSD: math.3,v 1.25 2011/09/22 18:14:09 njoly Exp $ -.\" .\" Copyright (c) 1985 Regents of the University of California. .\" All rights reserved. .\" @@ -28,557 +26,229 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 +.\" $FreeBSD: head/lib/msun/man/math.3 226460 2011-10-17 06:10:32Z das $ .\" .Dd December 21, 2011 .Dt MATH 3 .Os .Sh NAME .Nm math -.Nd introduction to mathematical library functions +.Nd "floating-point mathematical library" .Sh LIBRARY .Lb libm .Sh SYNOPSIS .In math.h .Sh DESCRIPTION -These functions constitute the C -.Lb libm . -Declarations for these functions may be obtained from the include file -.In math.h . -.\" The Fortran math library is described in ``man 3f intro''. -.Ss List of Functions -.Bl -column "copysignX" "gammaX3XX" "inverse trigonometric funcX" -.It Sy Name Ta Sy Man page Ta Sy Description Ta Sy Error Bound Dv ( ULP Ns No s) -.It acos Ta Xr acos 3 Ta inverse trigonometric function Ta 3 -.It acosh Ta Xr acosh 3 Ta inverse hyperbolic function Ta 3 -.It asin Ta Xr asin 3 Ta inverse trigonometric function Ta 3 -.It asinh Ta Xr asinh 3 Ta inverse hyperbolic function Ta 3 -.It atan Ta Xr atan 3 Ta inverse trigonometric function Ta 1 -.It atanh Ta Xr atanh 3 Ta inverse hyperbolic function Ta 3 -.It atan2 Ta Xr atan2 3 Ta inverse trigonometric function Ta 2 -.It cbrt Ta Xr sqrt 3 Ta cube root Ta 1 -.It ceil Ta Xr ceil 3 Ta integer no less than Ta 0 -.It copysign Ta Xr copysign 3 Ta copy sign bit Ta 0 -.It cos Ta Xr cos 3 Ta trigonometric function Ta 1 -.It cosh Ta Xr cosh 3 Ta hyperbolic function Ta 3 -.It erf Ta Xr erf 3 Ta error function Ta ??? -.It erfc Ta Xr erf 3 Ta complementary error function Ta ??? -.It exp Ta Xr exp 3 Ta exponential Ta 1 -.It expm1 Ta Xr exp 3 Ta exp(x)\-1 Ta 1 -.It fabs Ta Xr fabs 3 Ta absolute value Ta 0 -.It finite Ta Xr finite 3 Ta test for finity Ta 0 -.It floor Ta Xr floor 3 Ta integer no greater than Ta 0 -.It fmod Ta Xr fmod 3 Ta remainder Ta ??? -.It hypot Ta Xr hypot 3 Ta Euclidean distance Ta 1 -.It ilogb Ta Xr ilogb 3 Ta exponent extraction Ta 0 -.It isinf Ta Xr isinf 3 Ta test for infinity Ta 0 -.It isnan Ta Xr isnan 3 Ta test for not-a-number Ta 0 -.It j0 Ta Xr j0 3 Ta Bessel function Ta ??? -.It j1 Ta Xr j0 3 Ta Bessel function Ta ??? -.It jn Ta Xr j0 3 Ta Bessel function Ta ??? -.It ldexp Ta Xr ldexp 3 Ta Multiply by power of 2 Ta ??? -.It lgamma Ta Xr lgamma 3 Ta log gamma function Ta ??? -.It log Ta Xr log 3 Ta natural logarithm Ta 1 -.It log10 Ta Xr log 3 Ta logarithm to base 10 Ta 3 -.It log1p Ta Xr log 3 Ta log(1+x) Ta 1 -.It nan Ta Xr nan 3 Ta return quiet \*(Na Ta 0 -.It nextafter Ta Xr nextafter 3 Ta next representable number Ta 0 -.It pow Ta Xr pow 3 Ta exponential x**y Ta 60\-500 -.It remainder Ta Xr remainder 3 Ta remainder Ta 0 -.It rint Ta Xr rint 3 Ta round to nearest integer Ta 0 -.It scalbn Ta Xr scalbn 3 Ta exponent adjustment Ta 0 -.It sin Ta Xr sin 3 Ta trigonometric function Ta 1 -.It sinh Ta Xr sinh 3 Ta hyperbolic function Ta 3 -.It sqrt Ta Xr sqrt 3 Ta square root Ta 1 -.It tan Ta Xr tan 3 Ta trigonometric function Ta 3 -.It tanh Ta Xr tanh 3 Ta hyperbolic function Ta 3 -.It tgamma Ta Xr tgamma 3 Ta True gamma function Ta 3 -.It trunc Ta Xr trunc 3 Ta nearest integral value Ta 3 -.It y0 Ta Xr j0 3 Ta Bessel function Ta ??? -.It y1 Ta Xr j0 3 Ta Bessel function Ta ??? -.It yn Ta Xr j0 3 Ta Bessel function Ta ??? -.El -.Ss List of Defined Values -.Bl -column "M_2_SQRTPIXX" "1.12837916709551257390XX" "2/sqrt(pi)XXX" -.It Sy Name Ta Sy Value Ta Sy Description -.It M_E 2.7182818284590452354 e -.It M_LOG2E 1.4426950408889634074 log 2e -.It M_LOG10E 0.43429448190325182765 log 10e -.It M_LN2 0.69314718055994530942 log e2 -.It M_LN10 2.30258509299404568402 log e10 -.It M_PI 3.14159265358979323846 pi -.It M_PI_2 1.57079632679489661923 pi/2 -.It M_PI_4 0.78539816339744830962 pi/4 -.It M_1_PI 0.31830988618379067154 1/pi -.It M_2_PI 0.63661977236758134308 2/pi -.It M_2_SQRTPI 1.12837916709551257390 2/sqrt(pi) -.It M_SQRT2 1.41421356237309504880 sqrt(2) -.It M_SQRT1_2 0.70710678118654752440 1/sqrt(2) -.El -.Sh NOTES -In 4.3 BSD, distributed from the University of California -in late 1985, most of the foregoing functions come in two -versions, one for the double\-precision "D" format in the -DEC VAX\-11 family of computers, another for double\-precision -arithmetic conforming to the IEEE Standard 754 for Binary -Floating\-Point Arithmetic. -The two versions behave very -similarly, as should be expected from programs more accurate -and robust than was the norm when UNIX was born. -For instance, the programs are accurate to within the numbers -of -.Dv ULPs -tabulated above; an -.Dv ULP -is one Unit in the Last Place. -And the programs have been cured of anomalies that -afflicted the older math library -in which incidents like -the following had been reported: -.Bd -literal -offset indent -sqrt(\-1.0) = 0.0 and log(\-1.0) = \-1.7e38. -cos(1.0e\-11) \*[Gt] cos(0.0) \*[Gt] 1.0. -pow(x,1.0) \(!= x when x = 2.0, 3.0, 4.0, ..., 9.0. -pow(\-1.0,1.0e10) trapped on Integer Overflow. -sqrt(1.0e30) and sqrt(1.0e\-30) were very slow. -.Ed -However the two versions do differ in ways that have to be -explained, to which end the following notes are provided. -.Ss DEC VAX\-11 D_floating\-point -This is the format for which the original math library -was developed, and to which this manual is still principally dedicated. -It is -.Em the -double\-precision format for the PDP\-11 -and the earlier VAX\-11 machines; VAX\-11s after 1983 were -provided with an optional "G" format closer to the IEEE -double\-precision format. -The earlier DEC MicroVAXs have no D format, only G double\-precision. -(Why? -Why not?) -.Pp -Properties of D_floating\-point: -.Bl -hang -offset indent -.It Wordsize : -64 bits, 8 bytes. -.It Radix : -Binary. -.It Precision : -56 significant bits, roughly like 17 significant decimals. -If x and x' are consecutive positive D_floating\-point -numbers (they differ by 1 -.Dv ULP ) , -then -.Dl 1.3e\-17 \*[Lt] 0.5**56 \*[Lt] (x'\-x)/x \*[Le] 0.5**55 \*[Lt] 2.8e\-17. -.It Range : -.Bl -column "Underflow thresholdX" "2.0**127X" -.It Overflow threshold = 2.0**127 = 1.7e38. -.It Underflow threshold = 0.5**128 = 2.9e\-39. -.El -.Em NOTE: THIS RANGE IS COMPARATIVELY NARROW. -.Pp -Overflow customarily stops computation. -Underflow is customarily flushed quietly to zero. -.Em CAUTION : -It is possible to have x -\(!= -y and yet x\-y = 0 because of underflow. -Similarly x \*[Gt] y \*[Gt] 0 cannot prevent either x\(**y = 0 -or y/x = 0 from happening without warning. -.It Zero is represented ambiguously : -Although 2**55 different representations of zero are accepted by -the hardware, only the obvious representation is ever produced. -There is no \-0 on a VAX. -.It \*(If is not part of the VAX architecture . -.It Reserved operands : -of the 2**55 that the hardware -recognizes, only one of them is ever produced. -Any floating\-point operation upon a reserved -operand, even a MOVF or MOVD, customarily stops -computation, so they are not much used. -.It Exceptions : -Divisions by zero and operations that -overflow are invalid operations that customarily -stop computation or, in earlier machines, produce -reserved operands that will stop computation. -.It Rounding : -Every rational operation (+, \-, \(**, /) on a -VAX (but not necessarily on a PDP\-11), if not an -over/underflow nor division by zero, is rounded to -within half an -.Dv ULP , -and when the rounding error is -exactly half an -.Dv ULP -then rounding is away from 0. -.El -.Pp -Except for its narrow range, D_floating\-point is one of the -better computer arithmetics designed in the 1960's. -Its properties are reflected fairly faithfully in the elementary -functions for a VAX distributed in 4.3 BSD. -They over/underflow only if their results have to lie out of range -or very nearly so, and then they behave much as any rational -arithmetic operation that over/underflowed would behave. -Similarly, expressions like log(0) and atanh(1) behave -like 1/0; and sqrt(\-3) and acos(3) behave like 0/0; -they all produce reserved operands and/or stop computation! -The situation is described in more detail in manual pages. -.Pp -.Em This response seems excessively punitive, so it is destined -.Em to be replaced at some time in the foreseeable future by a -.Em more flexible but still uniform scheme being developed to -.Em handle all floating\-point arithmetic exceptions neatly. -.Pp -How do the functions in 4.3 BSD's new math library for UNIX -compare with their counterparts in DEC's VAX/VMS library? -Some of the VMS functions are a little faster, some are -a little more accurate, some are more puritanical about -exceptions (like pow(0.0,0.0) and atan2(0.0,0.0)), -and most occupy much more memory than their counterparts in -libm. -The VMS codes interpolate in large table to achieve -speed and accuracy; the libm codes use tricky formulas -compact enough that all of them may some day fit into a ROM. -.Pp -More important, DEC regards the VMS codes as proprietary -and guards them zealously against unauthorized use. -But the libm codes in 4.3 BSD are intended for the public domain; -they may be copied freely provided their provenance is always -acknowledged, and provided users assist the authors in their -researches by reporting experience with the codes. -Therefore no user of UNIX on a machine whose arithmetic resembles -VAX D_floating\-point need use anything worse than the new libm. -.Ss IEEE STANDARD 754 Floating\-Point Arithmetic -This standard is on its way to becoming more widely adopted -than any other design for computer arithmetic. -VLSI chips that conform to some version of that standard have been -produced by a host of manufacturers, among them ... -.Bl -column "Intel i8070, i80287XX" -.It Intel i8087, i80287 National Semiconductor 32081 -.It 68881 Weitek WTL-1032, ... , -1165 -.It Zilog Z8070 Western Electric (AT\*[Am]T) WE32106. +The math library includes the following components: +.Bl -column "" "polymorphic (type-generic) versions of functions" -compact -offset indent +.In math.h Ta basic routines and real-valued functions +.In complex.h Ta complex number support +.In tgmath.h Ta polymorphic (type-generic) versions of functions +.In fenv.h Ta routines to control rounding and exceptions .El -Other implementations range from software, done thoroughly -in the Apple Macintosh, through VLSI in the Hewlett\-Packard -9000 series, to the ELXSI 6400 running ECL at 3 Megaflops. -Several other companies have adopted the formats -of IEEE 754 without, alas, adhering to the standard's way -of handling rounding and exceptions like over/underflow. -The DEC VAX G_floating\-point format is very similar to the IEEE -754 Double format, so similar that the C programs for the -IEEE versions of most of the elementary functions listed -above could easily be converted to run on a MicroVAX, though -nobody has volunteered to do that yet. -.Pp -The codes in 4.3 BSD's libm for machines that conform to -IEEE 754 are intended primarily for the National Semiconductor 32081 -and WTL 1164/65. -To use these codes with the Intel or Zilog -chips, or with the Apple Macintosh or ELXSI 6400, is to -forego the use of better codes provided (perhaps freely) by -those companies and designed by some of the authors of the -codes above. -Except for -.Fn atan , -.Fn cbrt , -.Fn erf , -.Fn erfc , -.Fn hypot , -.Fn j0-jn , -.Fn lgamma , -.Fn pow , +The rest of this manual page describes the functions provided by +.In math.h . +Please consult +.Xr complex 3 , +.Xr tgmath 3 , and -.Fn y0\-yn , -the Motorola 68881 has all the functions in libm on chip, -and faster and more accurate; -it, Apple, the i8087, Z8070 and WE32106 all use 64 significant bits. -The main virtue of 4.3 BSD's -libm codes is that they are intended for the public domain; -they may be copied freely provided their provenance is always -acknowledged, and provided users assist the authors in their -researches by reporting experience with the codes. -Therefore no user of UNIX on a machine that conforms to -IEEE 754 need use anything worse than the new libm. -.Pp -Properties of IEEE 754 Double\-Precision: -.Bl -hang -offset indent -.It Wordsize : -64 bits, 8 bytes. -.It Radix : -Binary. -.It Precision : -53 significant bits, roughly like 16 significant decimals. -If x and x' are consecutive positive Double\-Precision -numbers (they differ by 1 -.Dv ULP ) , -then -.Dl 1.1e\-16 \*[Lt] 0.5**53 \*[Lt] (x'\-x)/x \*[Le] 0.5**52 \*[Lt] 2.3e\-16. -.It Range : -.Bl -column "Underflow thresholdX" "2.0**1024X" -.It Overflow threshold = 2.0**1024 = 1.8e308 -.It Underflow threshold = 0.5**1022 = 2.2e\-308 +.Xr fenv 3 +for information on the other components. +.Sh "LIST OF FUNCTIONS" +Each of the following +.Vt double +functions has a +.Vt float +counterpart with an +.Ql f +appended to the name and a +.Vt "long double" +counterpart with an +.Ql l +appended. +As an example, the +.Vt float +and +.Vt "long double" +counterparts of +.Ft double +.Fn acos "double x" +are +.Ft float +.Fn acosf "float x" +and +.Ft "long double" +.Fn acosl "long double x" , +respectively. +The classification macros and silent order predicates are type generic and +should not be suffixed with +.Ql f +or +.Ql l . +.de Cl +.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0" +.Em "Name Description" +.. +.Ss Algebraic Functions +.Cl +cbrt cube root +fma fused multiply-add +hypot Euclidean distance +sqrt square root .El -Overflow goes by default to a signed \*(If. -Underflow is -.Sy Gradual , -rounding to the nearest -integer multiple of 0.5**1074 = 4.9e\-324. -.It Zero is represented ambiguously as +0 or \-0: -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 copysign(x,\(+-0). -In particular, comparison (x \*[Gt] y, x \*[Ge] y, etc.) -cannot be affected by the sign of zero; but if -finite x = y then \*(If -\&= 1/(x\-y) -\(!= -\-1/(y\-x) = -\- \*(If . -.It \*(If is signed : -it persists when added to itself -or to any finite number. -Its sign transforms -correctly through multiplication and division, and -\*(If (finite)/\(+- \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. -.It Reserved operands : -there are 2**53\-2 of them, all -called \*(Na (Not A Number). -Some, called Signaling \*[Na]s, 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 \*[Na]s; 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 \*[Gt] y, x = y, x \*[Lt] y, ...) is FALSE if \*(Na is involved. -.Pp -.Em NOTE : -Trichotomy is violated by \*(Na. -Besides being FALSE, predicates that entail ordered -comparison, rather than mere (in)equality, -signal Invalid Operation when \*(Na is involved. -.It Rounding : -Every algebraic operation (+, \-, \(**, /, -\(sr) -is rounded by default to within half an -.Dv ULP , -and when the rounding error is exactly half an -.Dv ULP -then the rounded value's least significant bit is zero. -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. -And the same kinds of rounding are specified for -Binary\-Decimal Conversions, at least for magnitudes -between roughly 1.0e\-10 and 1.0e37. -.It Exceptions : -IEEE 754 recognizes five kinds of floating\-point exceptions, -listed below in declining order of probable importance. -.Bl -column "Invalid OperationX" "Gradual OverflowX" -.It Sy Exception Ta Sy Default Result -.It Invalid Operation \*(Na, or FALSE -.It Overflow \(+-\(if -.It Divide by Zero \(+-\(if \} -.It Underflow Gradual Underflow -.It Inexact Rounded value +.Ss Classification Macros +.Cl +fpclassify classify a floating-point value +isfinite determine whether a value is finite +isinf determine whether a value is infinite +isnan determine whether a value is \*(Na +isnormal determine whether a value is normalized .El -.Pp -.Em 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. +.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 -.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. -.Em 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. -.Pp -At the option of an implementor conforming to IEEE 754, -other ways to cope with exceptions may be provided: -.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. +.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 -.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. +.Ss Not a Number Functions +.Cl +nan generate a quiet \*(Na .El -.Pp -The crucial problem for exception handling is the problem of -Scope, and the problem's solution is understood, but not -enough manpower was available to implement it fully in time -to be distributed in 4.3 BSD's libm. -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. +.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 -Ideally, every programmer should be able -.Em conveniently -to turn a debugged subprogram into one that appears atomic to -its users. -But simulating all three characteristics of an -atomic function is still a tedious affair, entailing hosts -of tests and saves\-restores; work is under way to ameliorate -the inconvenience. -.Pp -Meanwhile, the functions in libm are only approximately atomic. -They signal no inappropriate exception except possibly ... -.Bl -ohang -offset indent -.It Over/Underflow -when a result, if properly computed, might have lain barely within range, and -.It Inexact in Fn cbrt , Fn hypot , Fn log10 and Fn pow -when it happens to be exact, thanks to fortuitous cancellation of errors. +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 -Otherwise, ... -.Bl -ohang -offset indent -.It Invalid Operation is signaled only when -any result but \*(Na would probably be misleading. -.It Overflow is signaled only when -the exact result would be finite but beyond the overflow threshold. -.It Divide\-by\-Zero is signaled only when -a function takes exactly infinite values at finite operands. -.It Underflow is signaled only when -the exact result would be nonzero but tinier than the underflow threshold. -.It Inexact is signaled only when -greater range or precision would be needed to represent the exact result. +.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 -.\" .Sh FILES -.\" .Bl -tag -width /usr/lib/profile/libm.a -compact -.\" .It Pa /usr/lib/libm.a -.\" the static math library -.\" .It Pa /usr/lib/libm.so -.\" the dynamic math library -.\" .It Pa /usr/lib/profile/libm.a -.\" the static math library compiled for profiling -.\" .El +.Pp +The routines +in this section might not produce a result that is correctly rounded, +so reproducible results cannot be guaranteed across platforms. +For most of these functions, however, incorrect rounding occurs +rarely, and then only in very-close-to-halfway cases. .Sh SEE ALSO -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 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. +.Xr complex 3 , +.Xr fenv 3 , +.Xr ieee 3 , +.Xr tgmath 3 +.Sh HISTORY +A math library with many of the present functions appeared in +.At v7 . +The library was substantially rewritten for +.Bx 4.3 +to provide +better accuracy and speed on machines supporting either VAX +or IEEE 754 floating-point. +Most of this library was replaced with FDLIBM, developed at Sun +Microsystems, in +.Fx 1.1.5 . +Additional routines, including ones for +.Vt float +and +.Vt long double +values, were written for or imported into subsequent versions of FreeBSD. .Sh BUGS -When signals are appropriate, they are emitted by certain -operations within the codes, so a subroutine\-trace may be -needed to identify the function with its signal in case -method 5) above is in use. -And the codes all take the -IEEE 754 defaults for granted; this means that a decision to -trap all divisions by zero could disrupt a code that would -otherwise get correct results despite division by zero. +Some of the +.Vt "long double" +math functions in +.St -isoC-99 +are not available. +.Pp +Many of the routines to compute transcendental functions produce +inaccurate results in other than the default rounding mode. +.Pp +On the i386 platform, trigonometric argument reduction is not +performed accurately for huge arguments, resulting in +large errors +for such arguments to +.Fn cos , +.Fn sin , +and +.Fn tan . diff --git a/lib/libm/man/nan.3 b/lib/libm/man/nan.3 new file mode 100644 index 0000000000..93f7ea4335 --- /dev/null +++ b/lib/libm/man/nan.3 @@ -0,0 +1,99 @@ +.\" Copyright (c) 2007 David Schultz +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/msun/man/nan.3 174684 2007-12-16 21:19:28Z das $ +.\" +.Dd December 16, 2007 +.Dt NAN 3 +.Os +.Sh NAME +.Nm nan , +.Nm nanf , +.Nm nanl +.Nd quiet \*(Nas +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn nan "const char *s" +.Ft float +.Fn nanf "const char *s" +.Ft long double +.Fn nanl "const char *s" +.Sh DESCRIPTION +The +.Dv NAN +macro expands to a quiet \*(Na (Not A Number). +Similarly, each of the +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions generate a quiet \*(Na value without raising an invalid exception. +The argument +.Fa s +should point to either an empty string or a hexadecimal representation +of a non-negative integer (e.g., "0x1234".) +In the latter case, the integer is encoded in some free bits in the +representation of the \*(Na, which sometimes store +machine-specific information about why a particular \*(Na was generated. +There are 22 such bits available for +.Vt float +variables, 51 bits for +.Vt double +variables, and at least 51 bits for a +.Vt long double . +If +.Fa s +is improperly formatted or represents an integer that is too large, +then the particular encoding of the quiet \*(Na that is returned +is indeterminate. +.Sh COMPATIBILITY +Calling these functions with a non-empty string isn't portable. +Another operating system may translate the string into a different +\*(Na encoding, and furthermore, the meaning of a given \*(Na encoding +varies across machine architectures. +If you understood the innards of a particular platform well enough to +know what string to use, then you would have no need for these functions +anyway, so don't use them. +Use the +.Dv NAN +macro instead. +.Sh SEE ALSO +.Xr fenv 3 , +.Xr ieee 3 , +.Xr isnan 3 , +.Xr math 3 , +.Xr strtod 3 +.Sh STANDARDS +The +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions and the +.Dv NAN +macro conform to +.St -isoC-99 . diff --git a/lib/libm/man/nextafter.3 b/lib/libm/man/nextafter.3 index 0f1ab1daf1..02d4718b46 100644 --- a/lib/libm/man/nextafter.3 +++ b/lib/libm/man/nextafter.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/nextafter.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt NEXTAFTER 3 @@ -36,7 +36,8 @@ .Nm nextafterf , .Nm nextafterl , .Nm nexttoward , -.Nm nexttowardf +.Nm nexttowardf , +.Nm nexttowardl .Nd next representable value .Sh LIBRARY .Lb libm @@ -52,6 +53,8 @@ .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 @@ -59,6 +62,7 @@ return the next machine representable number from in direction .Fa y . .Sh SEE ALSO +.Xr ieee 3 , .Xr math 3 .Sh STANDARDS The @@ -66,8 +70,9 @@ The .Fn nextafterf , .Fn nextafterl , .Fn nexttoward , +.Fn nexttowardf , and -.Fn nexttowardf +.Fn nexttowardl routines conform to .St -isoC-99 . They implement the Nextafter function recommended by @@ -89,6 +94,3 @@ and .Fn nextafterf appeared in .Fx 2.0 . -.Fn nextafterl -appeared in -.Dx 2.13 . diff --git a/lib/libm/man/remainder.3 b/lib/libm/man/remainder.3 index 114dc7aec9..834e2ce811 100644 --- a/lib/libm/man/remainder.3 +++ b/lib/libm/man/remainder.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/remainder.3 208734 2010-06-02 10:20:38Z uqs $ .\" .Dd December 21, 2011 .Dt REMAINDER 3 @@ -120,6 +120,7 @@ The number of bits 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 @@ -150,5 +151,5 @@ The .Fn remquol , and .Fn remainderl -were added in +functions were added in .Dx 2.13 . diff --git a/lib/libm/man/rint.3 b/lib/libm/man/rint.3 index 363240376a..2a08cea927 100644 --- a/lib/libm/man/rint.3 +++ b/lib/libm/man/rint.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)rint.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/rint.3 175309 2008-01-14 02:12:07Z das $ .\" .Dd December 21, 2011 .Dt RINT 3 @@ -80,6 +80,7 @@ an inexact exception. .Xr fabs 3 , .Xr fenv 3 , .Xr floor 3 , +.Xr ieee 3 , .Xr lrint 3 , .Xr lround 3 , .Xr math 3 , @@ -99,4 +100,4 @@ and functions appeared in .Dx 2.5 , and the long double variants were first available in -.Fx 2.13 . +.Dx 2.13 . diff --git a/lib/libm/man/round.3 b/lib/libm/man/round.3 index f7efe0843f..c0d6e673e4 100644 --- a/lib/libm/man/round.3 +++ b/lib/libm/man/round.3 @@ -1,5 +1,3 @@ -.\" $NetBSD: round.3,v 1.6 2011/09/13 07:11:43 njoly Exp $ -.\" .\" Copyright (c) 2003, Steven G. Kargl .\" All rights reserved. .\" @@ -24,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/round.3 147402 2005-06-15 19:04:04Z ru $ .\" .Dd December 21, 2011 .Dt ROUND 3 @@ -60,6 +58,7 @@ 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 , diff --git a/lib/libm/man/scalbn.3 b/lib/libm/man/scalbn.3 index 60c876ee52..c58e83726c 100644 --- a/lib/libm/man/scalbn.3 +++ b/lib/libm/man/scalbn.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91 -.\" FreeBSD SVN: 165906 (2007-01-09) +.\" $FreeBSD: head/lib/msun/man/scalbn.3 165906 2007-01-09 01:02:06Z imp $ .\" .Dd December 21, 2011 .Dt SCALBN 3 @@ -37,10 +37,7 @@ .Nm scalblnl , .Nm scalbn , .Nm scalbnf , -.Nm scalbnl , -.Nm ldexp , -.Nm ldexpf , -.Nm ldexpl +.Nm scalbnl .Nd adjust exponent .Sh LIBRARY .Lb libm @@ -58,19 +55,12 @@ .Fn scalbnf "float x" "int n" .Ft long double .Fn scalbnl "long double x" "int n" -.Ft double -.Fn ldexp "double x" "int n" -.Ft float -.Fn ldexpf "float x" "int n" -.Ft long double -.Fn ldexpl "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 exp 3 , -.Xr frexp 3 , +.Xr ieee 3 , .Xr math 3 .Sh STANDARDS These routines conform to @@ -90,8 +80,9 @@ respectively. The .Fn scalbln , .Fn scalblnf , -.Fn scalblnl +.Fn scalblnl , and .Fn scalbln -first appeared in +functions first appeared in +in .Dx 2.13 . diff --git a/lib/libm/man/trunc.3 b/lib/libm/man/signbit.3 similarity index 64% copy from lib/libm/man/trunc.3 copy to lib/libm/man/signbit.3 index 563601bdd4..846b99fe3f 100644 --- a/lib/libm/man/trunc.3 +++ b/lib/libm/man/signbit.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2004, 2005 David Schultz +.\" Copyright (c) 2003 Mike Barcroft .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,61 +22,36 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/signbit.3 132382 2004-07-19 08:16:10Z das $ .\" -.Dd December 21, 2011 -.Dt TRUNC 3 +.Dd July 18, 2004 +.Dt SIGNBIT 3 .Os .Sh NAME -.Nm trunc , -.Nm truncf , -.Nm truncl -.Nd nearest integral value with magnitude less than or equal to |x| +.Nm signbit +.Nd "determine whether a floating-point number's sign is negative" .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" +.Ft int +.Fn signbit "real-floating 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. +.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 ceil 3 , -.Xr fesetround 3 , -.Xr floor 3 , -.Xr math 3 , -.Xr nextafter 3 , -.Xr rint 3 , -.Xr round 3 +.Xr fpclassify 3 , +.Xr math 3 .Sh STANDARDS The -.Fn trunc , -.Fn truncf , -and -.Fn truncl -functions conform to +.Fn signbit +macro conforms to .St -isoC-99 . .Sh HISTORY -These routines first appeared in -.Dx 1.9 . -The long double version appeared in -.Dx 2.13 . +The +.Fn signbit +macro was added in +.Dx 1.3 . diff --git a/lib/libm/man/sin.3 b/lib/libm/man/sin.3 index 48e9b98077..d5497ac608 100644 --- a/lib/libm/man/sin.3 +++ b/lib/libm/man/sin.3 @@ -27,7 +27,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)sin.3 6.7 (Berkeley) 4/19/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/sin.3 226458 2011-10-17 05:41:03Z das $ .\" .Dd December 21, 2011 .Dt SIN 3 diff --git a/lib/libm/man/sinh.3 b/lib/libm/man/sinh.3 index 5e0cff788d..66ade3f0ba 100644 --- a/lib/libm/man/sinh.3 +++ b/lib/libm/man/sinh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)sinh.3 6.6 (Berkeley) 4/19/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/sinh.3 226458 2011-10-17 05:41:03Z das $ .Dd December 21, 2011 .Dt SINH 3 .Os @@ -49,16 +49,6 @@ and the .Fn sinhf functions compute the hyperbolic sine of .Fa x . -.Sh RETURN VALUES -The -.Fn sinh -function returns the hyperbolic sine value unless -the magnitude of -.Fa x -is too large; in this event, the global variable -.Va errno -is set to -.Er ERANGE . .Sh SEE ALSO .Xr acos 3 , .Xr asin 3 , diff --git a/lib/libm/man/sqrt.3 b/lib/libm/man/sqrt.3 index a9a8571396..34c3b7baa6 100644 --- a/lib/libm/man/sqrt.3 +++ b/lib/libm/man/sqrt.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)sqrt.3 6.4 (Berkeley) 5/6/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/sqrt.3 219571 2011-03-12 16:50:39Z kargl $ .\" .Dd December 21, 2011 .Dt SQRT 3 @@ -109,16 +109,12 @@ functions conform to .St -isoC-99 . .Sh HISTORY The -.Fn sqrt , -.Fn sqrtf , -.Fn cbrt , -and -.Fn cbrtf -functions appeared in +.Fn cbrt +function appeared in .Bx 4.3 . The .Fn sqrtl -and the +and .Fn cbrtl -function appeared in +functions appeared in .Dx 2.13 . diff --git a/lib/libm/man/tan.3 b/lib/libm/man/tan.3 index b325eb2ef4..187eea45c9 100644 --- a/lib/libm/man/tan.3 +++ b/lib/libm/man/tan.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)tan.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/tan.3 226458 2011-10-17 05:41:03Z das $ .\" .Dd December 21, 2011 .Dt TAN 3 diff --git a/lib/libm/man/tanh.3 b/lib/libm/man/tanh.3 index 78e504cb24..c15c8330ac 100644 --- a/lib/libm/man/tanh.3 +++ b/lib/libm/man/tanh.3 @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)tanh.3 5.1 (Berkeley) 5/2/91 -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/tanh.3 226458 2011-10-17 05:41:03Z das $ .\" .Dd September 18, 2011 .Dt TANH 3 diff --git a/lib/libm/man/trunc.3 b/lib/libm/man/trunc.3 index 563601bdd4..a2aabd0646 100644 --- a/lib/libm/man/trunc.3 +++ b/lib/libm/man/trunc.3 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/msun/man/trunc.3 147402 2005-06-15 19:04:04Z ru $ .\" .Dd December 21, 2011 .Dt TRUNC 3 diff --git a/lib/libm/src/Makefile.inc b/lib/libm/src/Makefile.inc deleted file mode 100644 index 2128bc945f..0000000000 --- a/lib/libm/src/Makefile.inc +++ /dev/null @@ -1,54 +0,0 @@ -# $DragonFly: src/lib/libm/src/Makefile.inc,v 1.3 2007/06/17 06:26:18 pavalos Exp $ - -.PATH: ${.CURDIR}/src - -LIBCDIR=${.CURDIR}/../libc -CFLAGS+=-I${LIBCDIR}/include -I${LIBCDIR}/${MACHINE_ARCH} - -# These files are always used. -SRCS+= k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c \ - k_tan.c k_tanf.c s_llrint.c s_llrintf.c s_llround.c s_llroundf.c \ - s_lrintf.c s_lround.c s_lroundf.c s_trunc.c s_truncf.c \ - w_drem.c w_dremf.c w_gamma.c w_gamma_r.c w_gammaf.c w_gammaf_r.c \ - w_lgamma.c w_lgammaf.c - -# Origin: FreeBSD's msun library, always used source files -# Long Double: 80-bit version used (LD80 on FreeBSD) - -SRCS+= invtrig.c e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c e_hypotl.c \ - k_sinl.c k_cosl.c k_tanl.c b_log.c b_exp.c \ - s_atanl.c s_sinl.c s_cosl.c s_tanl.c s_exp2l.c s_cbrtl.c s_floorl.c \ - s_roundl.c s_lroundl.c s_llroundl.c s_rintl.c s_lrintl.c s_modfl.c \ - s_fabs.c s_fma.c s_fmaf.c s_fmal.c s_tgammaf.c b_tgamma.c s_scalbln.c - -# These files are only used if the MI Makefile didn't already provide -# them as assembler version. - -MI_FUNCS+= \ - e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ - e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_cosh.c e_coshf.c \ - e_exp.c e_expf.c e_fmod.c e_fmodf.c e_hypot.c e_hypotf.c e_j0.c \ - e_j0f.c e_j1.c e_j1f.c e_jn.c e_jnf.c e_lgamma_r.c e_lgammaf_r.c \ - e_log.c e_log10.c e_log10f.c e_log2.c e_log2f.c e_logf.c e_pow.c e_powf.c e_rem_pio2.c \ - e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c \ - e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \ - s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c s_ceil.c \ - s_ceilf.c s_copysign.c s_copysignf.c s_copysignl.c s_cos.c s_cosf.c s_erf.c \ - s_erff.c s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c s_finite.c \ - s_finitef.c s_floor.c s_floorf.c s_fmax.c s_fmaxf.c s_fmaxl.c \ - s_fmin.c s_fminf.c s_fminl.c s_frexpf.c s_frexpl.c s_ilogb.c \ - s_ilogbf.c s_log1p.c s_log1pf.c s_logb.c s_logbf.c \ - s_modff.c s_nearbyint.c s_nextafter.c s_nextafterf.c s_rint.c s_rintf.c \ - s_round.c s_roundf.c s_scalbn.c s_scalbnf.c \ - s_signgam.c s_significand.c s_significandf.c s_sin.c s_sinf.c \ - s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_lrint.c -MI_FUNCS+= s_exp2.c s_exp2f.c s_frexp.c s_ilogbl.c s_logbl.c s_nextafterl.c \ - s_nexttoward.c s_remquo.c s_remquof.c s_scalbnl.c s_fabsl.c -MI_FUNCS+= e_sqrtl.c e_remainderl.c s_remquol.c s_ceill.c s_llrintl.c \ - s_modf.c s_nexttowardf.c s_truncl.c - -.for f in ${MI_FUNCS} -.if empty(SRCS:M${f:H:R}) -SRCS+= $f -.endif -.endfor diff --git a/lib/libm/src/catrig.c b/lib/libm/src/catrig.c new file mode 100644 index 0000000000..fd1312d2af --- /dev/null +++ b/lib/libm/src/catrig.c @@ -0,0 +1,642 @@ +/*- + * Copyright (c) 2012 Stephen Montgomery-Smith + * 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: head/lib/msun/src/catrig.c 251121 2013-05-30 04:49:26Z das $ + */ + +#include +#include + +#include "math.h" +#include "math_private.h" + +#undef isinf +#define isinf(x) (fabs(x) == INFINITY) +#undef isnan +#define isnan(x) ((x) != (x)) +#define raise_inexact() do { volatile float junk = 1 + tiny; } while(0) +#undef signbit +#define signbit(x) (__builtin_signbit(x)) + +/* We need that DBL_EPSILON^2/128 is larger than FOUR_SQRT_MIN. */ +static const double +A_crossover = 10, /* Hull et al suggest 1.5, but 10 works better */ +B_crossover = 0.6417, /* suggested by Hull et al */ +FOUR_SQRT_MIN = 0x1p-509, /* >= 4 * sqrt(DBL_MIN) */ +QUARTER_SQRT_MAX = 0x1p509, /* <= sqrt(DBL_MAX) / 4 */ +m_e = 2.7182818284590452e0, /* 0x15bf0a8b145769.0p-51 */ +m_ln2 = 6.9314718055994531e-1, /* 0x162e42fefa39ef.0p-53 */ +pio2_hi = 1.5707963267948966e0, /* 0x1921fb54442d18.0p-52 */ +RECIP_EPSILON = 1 / DBL_EPSILON, +SQRT_3_EPSILON = 2.5809568279517849e-8, /* 0x1bb67ae8584caa.0p-78 */ +SQRT_6_EPSILON = 3.6500241499888571e-8, /* 0x13988e1409212e.0p-77 */ +SQRT_MIN = 0x1p-511; /* >= sqrt(DBL_MIN) */ + +static const volatile double +pio2_lo = 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */ +static const volatile float +tiny = 0x1p-100; + +static double complex clog_for_large_values(double complex z); + +/* + * Testing indicates that all these functions are accurate up to 4 ULP. + * The functions casin(h) and cacos(h) are about 2.5 times slower than asinh. + * The functions catan(h) are a little under 2 times slower than atanh. + * + * The code for casinh, casin, cacos, and cacosh comes first. The code is + * rather complicated, and the four functions are highly interdependent. + * + * The code for catanh and catan comes at the end. It is much simpler than + * the other functions, and the code for these can be disconnected from the + * rest of the code. + */ + +/* + * ================================ + * | casinh, casin, cacos, cacosh | + * ================================ + */ + +/* + * The algorithm is very close to that in "Implementing the complex arcsine + * and arccosine functions using exception handling" by T. E. Hull, Thomas F. + * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on + * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335, + * http://dl.acm.org/citation.cfm?id=275324. + * + * Throughout we use the convention z = x + I*y. + * + * casinh(z) = sign(x)*log(A+sqrt(A*A-1)) + I*asin(B) + * where + * A = (|z+I| + |z-I|) / 2 + * B = (|z+I| - |z-I|) / 2 = y/A + * + * These formulas become numerically unstable: + * (a) for Re(casinh(z)) when z is close to the line segment [-I, I] (that + * is, Re(casinh(z)) is close to 0); + * (b) for Im(casinh(z)) when z is close to either of the intervals + * [I, I*infinity) or (-I*infinity, -I] (that is, |Im(casinh(z))| is + * close to PI/2). + * + * These numerical problems are overcome by defining + * f(a, b) = (hypot(a, b) - b) / 2 = a*a / (hypot(a, b) + b) / 2 + * Then if A < A_crossover, we use + * log(A + sqrt(A*A-1)) = log1p((A-1) + sqrt((A-1)*(A+1))) + * A-1 = f(x, 1+y) + f(x, 1-y) + * and if B > B_crossover, we use + * asin(B) = atan2(y, sqrt(A*A - y*y)) = atan2(y, sqrt((A+y)*(A-y))) + * A-y = f(x, y+1) + f(x, y-1) + * where without loss of generality we have assumed that x and y are + * non-negative. + * + * Much of the difficulty comes because the intermediate computations may + * produce overflows or underflows. This is dealt with in the paper by Hull + * et al by using exception handling. We do this by detecting when + * computations risk underflow or overflow. The hardest part is handling the + * underflows when computing f(a, b). + * + * Note that the function f(a, b) does not appear explicitly in the paper by + * Hull et al, but the idea may be found on pages 308 and 309. Introducing the + * function f(a, b) allows us to concentrate many of the clever tricks in this + * paper into one function. + */ + +/* + * Function f(a, b, hypot_a_b) = (hypot(a, b) - b) / 2. + * Pass hypot(a, b) as the third argument. + */ +static inline double +f(double a, double b, double hypot_a_b) +{ + if (b < 0) + return ((hypot_a_b - b) / 2); + if (b == 0) + return (a / 2); + return (a * a / (hypot_a_b + b) / 2); +} + +/* + * All the hard work is contained in this function. + * x and y are assumed positive or zero, and less than RECIP_EPSILON. + * Upon return: + * rx = Re(casinh(z)) = -Im(cacos(y + I*x)). + * B_is_usable is set to 1 if the value of B is usable. + * If B_is_usable is set to 0, sqrt_A2my2 = sqrt(A*A - y*y), and new_y = y. + * If returning sqrt_A2my2 has potential to result in an underflow, it is + * rescaled, and new_y is similarly rescaled. + */ +static inline void +do_hard_work(double x, double y, double *rx, int *B_is_usable, double *B, + double *sqrt_A2my2, double *new_y) +{ + double R, S, A; /* A, B, R, and S are as in Hull et al. */ + double Am1, Amy; /* A-1, A-y. */ + + R = hypot(x, y + 1); /* |z+I| */ + S = hypot(x, y - 1); /* |z-I| */ + + /* A = (|z+I| + |z-I|) / 2 */ + A = (R + S) / 2; + /* + * Mathematically A >= 1. There is a small chance that this will not + * be so because of rounding errors. So we will make certain it is + * so. + */ + if (A < 1) + A = 1; + + if (A < A_crossover) { + /* + * Am1 = fp + fm, where fp = f(x, 1+y), and fm = f(x, 1-y). + * rx = log1p(Am1 + sqrt(Am1*(A+1))) + */ + if (y == 1 && x < DBL_EPSILON*DBL_EPSILON / 128) { + /* + * fp is of order x^2, and fm = x/2. + * A = 1 (inexactly). + */ + *rx = sqrt(x); + } else if (x >= DBL_EPSILON * fabs(y - 1)) { + /* + * Underflow will not occur because + * x >= DBL_EPSILON^2/128 >= FOUR_SQRT_MIN + */ + Am1 = f(x, 1 + y, R) + f(x, 1 - y, S); + *rx = log1p(Am1 + sqrt(Am1 * (A + 1))); + } else if (y < 1) { + /* + * fp = x*x/(1+y)/4, fm = x*x/(1-y)/4, and + * A = 1 (inexactly). + */ + *rx = x / sqrt((1 - y) * (1 + y)); + } else /* if (y > 1) */ { + /* + * A-1 = y-1 (inexactly). + */ + *rx = log1p((y - 1) + sqrt((y - 1) * (y + 1))); + } + } else { + *rx = log(A + sqrt(A * A - 1)); + } + + *new_y = y; + + if (y < FOUR_SQRT_MIN) { + /* + * Avoid a possible underflow caused by y/A. For casinh this + * would be legitimate, but will be picked up by invoking atan2 + * later on. For cacos this would not be legitimate. + */ + *B_is_usable = 0; + *sqrt_A2my2 = A * (2 / DBL_EPSILON); + *new_y = y * (2 / DBL_EPSILON); + return; + } + + /* B = (|z+I| - |z-I|) / 2 = y/A */ + *B = y / A; + *B_is_usable = 1; + + if (*B > B_crossover) { + *B_is_usable = 0; + /* + * Amy = fp + fm, where fp = f(x, y+1), and fm = f(x, y-1). + * sqrt_A2my2 = sqrt(Amy*(A+y)) + */ + if (y == 1 && x < DBL_EPSILON / 128) { + /* + * fp is of order x^2, and fm = x/2. + * A = 1 (inexactly). + */ + *sqrt_A2my2 = sqrt(x) * sqrt((A + y) / 2); + } else if (x >= DBL_EPSILON * fabs(y - 1)) { + /* + * Underflow will not occur because + * x >= DBL_EPSILON/128 >= FOUR_SQRT_MIN + * and + * x >= DBL_EPSILON^2 >= FOUR_SQRT_MIN + */ + Amy = f(x, y + 1, R) + f(x, y - 1, S); + *sqrt_A2my2 = sqrt(Amy * (A + y)); + } else if (y > 1) { + /* + * fp = x*x/(y+1)/4, fm = x*x/(y-1)/4, and + * A = y (inexactly). + * + * y < RECIP_EPSILON. So the following + * scaling should avoid any underflow problems. + */ + *sqrt_A2my2 = x * (4 / DBL_EPSILON / DBL_EPSILON) * y / + sqrt((y + 1) * (y - 1)); + *new_y = y * (4 / DBL_EPSILON / DBL_EPSILON); + } else /* if (y < 1) */ { + /* + * fm = 1-y >= DBL_EPSILON, fp is of order x^2, and + * A = 1 (inexactly). + */ + *sqrt_A2my2 = sqrt((1 - y) * (1 + y)); + } + } +} + +/* + * casinh(z) = z + O(z^3) as z -> 0 + * + * casinh(z) = sign(x)*clog(sign(x)*z) + O(1/z^2) as z -> infinity + * The above formula works for the imaginary part as well, because + * Im(casinh(z)) = sign(x)*atan2(sign(x)*y, fabs(x)) + O(y/z^3) + * as z -> infinity, uniformly in y + */ +double complex +casinh(double complex z) +{ + double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y; + int B_is_usable; + double complex w; + + x = creal(z); + y = cimag(z); + ax = fabs(x); + ay = fabs(y); + + if (isnan(x) || isnan(y)) { + /* casinh(+-Inf + I*NaN) = +-Inf + I*NaN */ + if (isinf(x)) + return (cpack(x, y + y)); + /* casinh(NaN + I*+-Inf) = opt(+-)Inf + I*NaN */ + if (isinf(y)) + return (cpack(y, x + x)); + /* casinh(NaN + I*0) = NaN + I*0 */ + if (y == 0) + return (cpack(x + x, y)); + /* + * All other cases involving NaN return NaN + I*NaN. + * C99 leaves it optional whether to raise invalid if one of + * the arguments is not NaN, so we opt not to raise it. + */ + /* Bruce Evans tells me this is the way to do this: */ + return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + /* clog...() will raise inexact unless x or y is infinite. */ + if (signbit(x) == 0) + w = clog_for_large_values(z) + m_ln2; + else + w = clog_for_large_values(-z) + m_ln2; + return (cpack(copysign(creal(w), x), copysign(cimag(w), y))); + } + + /* Avoid spuriously raising inexact for z = 0. */ + if (x == 0 && y == 0) + return (z); + + /* All remaining cases are inexact. */ + raise_inexact(); + + if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) + return (z); + + do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y); + if (B_is_usable) + ry = asin(B); + else + ry = atan2(new_y, sqrt_A2my2); + return (cpack(copysign(rx, x), copysign(ry, y))); +} + +/* + * casin(z) = reverse(casinh(reverse(z))) + * where reverse(x + I*y) = y + I*x = I*conj(z). + */ +double complex +casin(double complex z) +{ + double complex w = casinh(cpack(cimag(z), creal(z))); + return (cpack(cimag(w), creal(w))); +} + +/* + * cacos(z) = PI/2 - casin(z) + * but do the computation carefully so cacos(z) is accurate when z is + * close to 1. + * + * cacos(z) = PI/2 - z + O(z^3) as z -> 0 + * + * cacos(z) = -sign(y)*I*clog(z) + O(1/z^2) as z -> infinity + * The above formula works for the real part as well, because + * Re(cacos(z)) = atan2(fabs(y), x) + O(y/z^3) + * as z -> infinity, uniformly in y + */ +double complex +cacos(double complex z) +{ + double x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x; + int sx, sy; + int B_is_usable; + double complex w; + + x = creal(z); + y = cimag(z); + sx = signbit(x); + sy = signbit(y); + ax = fabs(x); + ay = fabs(y); + + if (isnan(x) || isnan(y)) { + /* cacos(+-Inf + I*NaN) = NaN + I*opt(-)Inf */ + if (isinf(x)) + return (cpack(y + y, -INFINITY)); + /* cacos(NaN + I*+-Inf) = NaN + I*-+Inf */ + if (isinf(y)) + return (cpack(x + x, -y)); + /* cacos(0 + I*NaN) = PI/2 + I*NaN with inexact */ + if (x == 0) + return (cpack(pio2_hi + pio2_lo, y + y)); + /* + * All other cases involving NaN return NaN + I*NaN. + * C99 leaves it optional whether to raise invalid if one of + * the arguments is not NaN, so we opt not to raise it. + */ + return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + /* clog...() will raise inexact unless x or y is infinite. */ + w = clog_for_large_values(z); + rx = fabs(cimag(w)); + ry = creal(w) + m_ln2; + if (sy == 0) + ry = -ry; + return (cpack(rx, ry)); + } + + /* Avoid spuriously raising inexact for z = 1. */ + if (x == 1 && y == 0) + return (cpack(0, -y)); + + /* All remaining cases are inexact. */ + raise_inexact(); + + if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON/4) + return (cpack(pio2_hi - (x - pio2_lo), -y)); + + do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x); + if (B_is_usable) { + if (sx==0) + rx = acos(B); + else + rx = acos(-B); + } else { + if (sx==0) + rx = atan2(sqrt_A2mx2, new_x); + else + rx = atan2(sqrt_A2mx2, -new_x); + } + if (sy == 0) + ry = -ry; + return (cpack(rx, ry)); +} + +/* + * cacosh(z) = I*cacos(z) or -I*cacos(z) + * where the sign is chosen so Re(cacosh(z)) >= 0. + */ +double complex +cacosh(double complex z) +{ + double complex w; + double rx, ry; + + w = cacos(z); + rx = creal(w); + ry = cimag(w); + /* cacosh(NaN + I*NaN) = NaN + I*NaN */ + if (isnan(rx) && isnan(ry)) + return (cpack(ry, rx)); + /* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */ + /* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */ + if (isnan(rx)) + return (cpack(fabs(ry), rx)); + /* cacosh(0 + I*NaN) = NaN + I*NaN */ + if (isnan(ry)) + return (cpack(ry, ry)); + return (cpack(fabs(ry), copysign(rx, cimag(z)))); +} + +/* + * Optimized version of clog() for |z| finite and larger than ~RECIP_EPSILON. + */ +static double complex +clog_for_large_values(double complex z) +{ + double x, y; + double ax, ay, t; + + x = creal(z); + y = cimag(z); + ax = fabs(x); + ay = fabs(y); + if (ax < ay) { + t = ax; + ax = ay; + ay = t; + } + + /* + * Avoid overflow in hypot() when x and y are both very large. + * Divide x and y by E, and then add 1 to the logarithm. This depends + * on E being larger than sqrt(2). + * Dividing by E causes an insignificant loss of accuracy; however + * this method is still poor since it is uneccessarily slow. + */ + if (ax > DBL_MAX / 2) + return (cpack(log(hypot(x / m_e, y / m_e)) + 1, atan2(y, x))); + + /* + * Avoid overflow when x or y is large. Avoid underflow when x or + * y is small. + */ + if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN) + return (cpack(log(hypot(x, y)), atan2(y, x))); + + return (cpack(log(ax * ax + ay * ay) / 2, atan2(y, x))); +} + +/* + *============================================================================= + */ + +/* + * ================= + * | catanh, catan | + * ================= + */ + +/* + * sum_squares(x,y) = x*x + y*y (or just x*x if y*y would underflow). + * Assumes x*x and y*y will not overflow. + * Assumes x and y are finite. + * Assumes y is non-negative. + * Assumes fabs(x) >= DBL_EPSILON. + */ +static inline double +sum_squares(double x, double y) +{ + + /* Avoid underflow when y is small. */ + if (y < SQRT_MIN) + return (x * x); + return (x * x + y * y); +} + +/* + * real_part_reciprocal(x, y) = Re(1/(x+I*y)) = x/(x*x + y*y). + * Assumes x and y are not NaN, and one of x and y is larger than + * RECIP_EPSILON. We avoid unwarranted underflow. It is important to not use + * the code creal(1/z), because the imaginary part may produce an unwanted + * underflow. + * This is only called in a context where inexact is always raised before + * the call, so no effort is made to avoid or force inexact. + */ +static inline double +real_part_reciprocal(double x, double y) +{ + double scale; + uint32_t hx, hy; + int32_t ix, iy; + + /* + * This code is inspired by the C99 document n1124.pdf, Section G.5.1, + * example 2. + */ + GET_HIGH_WORD(hx, x); + ix = hx & 0x7ff00000; + GET_HIGH_WORD(hy, y); + iy = hy & 0x7ff00000; +#define BIAS (DBL_MAX_EXP - 1) +/* XXX more guard digits are useful iff there is extra precision. */ +#define CUTOFF (DBL_MANT_DIG / 2 + 1) /* just half or 1 guard digit */ + if (ix - iy >= CUTOFF << 20 || isinf(x)) + return (1 / x); /* +-Inf -> +-0 is special */ + if (iy - ix >= CUTOFF << 20) + return (x / y / y); /* should avoid double div, but hard */ + if (ix <= (BIAS + DBL_MAX_EXP / 2 - CUTOFF) << 20) + return (x / (x * x + y * y)); + scale = 1; + SET_HIGH_WORD(scale, 0x7ff00000 - ix); /* 2**(1-ilogb(x)) */ + x *= scale; + y *= scale; + return (x / (x * x + y * y) * scale); +} + +/* + * catanh(z) = log((1+z)/(1-z)) / 2 + * = log1p(4*x / |z-1|^2) / 4 + * + I * atan2(2*y, (1-x)*(1+x)-y*y) / 2 + * + * catanh(z) = z + O(z^3) as z -> 0 + * + * catanh(z) = 1/z + sign(y)*I*PI/2 + O(1/z^3) as z -> infinity + * The above formula works for the real part as well, because + * Re(catanh(z)) = x/|z|^2 + O(x/z^4) + * as z -> infinity, uniformly in x + */ +double complex +catanh(double complex z) +{ + double x, y, ax, ay, rx, ry; + + x = creal(z); + y = cimag(z); + ax = fabs(x); + ay = fabs(y); + + /* This helps handle many cases. */ + if (y == 0 && ax <= 1) + return (cpack(atanh(x), y)); + + /* To ensure the same accuracy as atan(), and to filter out z = 0. */ + if (x == 0) + return (cpack(x, atan(y))); + + if (isnan(x) || isnan(y)) { + /* catanh(+-Inf + I*NaN) = +-0 + I*NaN */ + if (isinf(x)) + return (cpack(copysign(0, x), y + y)); + /* catanh(NaN + I*+-Inf) = sign(NaN)0 + I*+-PI/2 */ + if (isinf(y)) { + return (cpack(copysign(0, x), + copysign(pio2_hi + pio2_lo, y))); + } + /* + * All other cases involving NaN return NaN + I*NaN. + * C99 leaves it optional whether to raise invalid if one of + * the arguments is not NaN, so we opt not to raise it. + */ + return (cpack(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + return (cpack(real_part_reciprocal(x, y), + copysign(pio2_hi + pio2_lo, y))); + } + + if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) { + /* + * z = 0 was filtered out above. All other cases must raise + * inexact, but this is the only only that needs to do it + * explicitly. + */ + raise_inexact(); + return (z); + } + + if (ax == 1 && ay < DBL_EPSILON) + rx = (log(ay) - m_ln2) / -2; + else + rx = log1p(4 * ax / sum_squares(ax - 1, ay)) / 4; + + if (ax == 1) + ry = atan2(2, -ay) / 2; + else if (ay < DBL_EPSILON) + ry = atan2(2 * ay, (1 - ax) * (1 + ax)) / 2; + else + ry = atan2(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2; + + return (cpack(copysign(rx, x), copysign(ry, y))); +} + +/* + * catan(z) = reverse(catanh(reverse(z))) + * where reverse(x + I*y) = y + I*x = I*conj(z). + */ +double complex +catan(double complex z) +{ + double complex w = catanh(cpack(cimag(z), creal(z))); + return (cpack(cimag(w), creal(w))); +} diff --git a/lib/libm/src/catrigf.c b/lib/libm/src/catrigf.c new file mode 100644 index 0000000000..f44a319bad --- /dev/null +++ b/lib/libm/src/catrigf.c @@ -0,0 +1,387 @@ +/*- + * Copyright (c) 2012 Stephen Montgomery-Smith + * 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: head/lib/msun/src/catrigf.c 251121 2013-05-30 04:49:26Z das $ + */ + +/* + * The algorithm is very close to that in "Implementing the complex arcsine + * and arccosine functions using exception handling" by T. E. Hull, Thomas F. + * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on + * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335, + * http://dl.acm.org/citation.cfm?id=275324. + * + * The code for catrig.c contains complete comments. + */ + +#include +#include + +#include "math.h" +#include "math_private.h" + +#undef isinf +#define isinf(x) (fabsf(x) == INFINITY) +#undef isnan +#define isnan(x) ((x) != (x)) +#define raise_inexact() do { volatile float junk = 1 + tiny; } while(0) +#undef signbit +#define signbit(x) (__builtin_signbitf(x)) + +static const float +A_crossover = 10, +B_crossover = 0.6417, +FOUR_SQRT_MIN = 0x1p-61, +QUARTER_SQRT_MAX = 0x1p61, +m_e = 2.7182818285e0, /* 0xadf854.0p-22 */ +m_ln2 = 6.9314718056e-1, /* 0xb17218.0p-24 */ +pio2_hi = 1.5707962513e0, /* 0xc90fda.0p-23 */ +RECIP_EPSILON = 1 / FLT_EPSILON, +SQRT_3_EPSILON = 5.9801995673e-4, /* 0x9cc471.0p-34 */ +SQRT_6_EPSILON = 8.4572793338e-4, /* 0xddb3d7.0p-34 */ +SQRT_MIN = 0x1p-63; + +static const volatile float +pio2_lo = 7.5497899549e-8, /* 0xa22169.0p-47 */ +tiny = 0x1p-100; + +static float complex clog_for_large_values(float complex z); + +static inline float +f(float a, float b, float hypot_a_b) +{ + if (b < 0) + return ((hypot_a_b - b) / 2); + if (b == 0) + return (a / 2); + return (a * a / (hypot_a_b + b) / 2); +} + +static inline void +do_hard_work(float x, float y, float *rx, int *B_is_usable, float *B, + float *sqrt_A2my2, float *new_y) +{ + float R, S, A; + float Am1, Amy; + + R = hypotf(x, y + 1); + S = hypotf(x, y - 1); + + A = (R + S) / 2; + if (A < 1) + A = 1; + + if (A < A_crossover) { + if (y == 1 && x < FLT_EPSILON * FLT_EPSILON / 128) { + *rx = sqrtf(x); + } else if (x >= FLT_EPSILON * fabsf(y - 1)) { + Am1 = f(x, 1 + y, R) + f(x, 1 - y, S); + *rx = log1pf(Am1 + sqrtf(Am1 * (A + 1))); + } else if (y < 1) { + *rx = x / sqrtf((1 - y)*(1 + y)); + } else { + *rx = log1pf((y - 1) + sqrtf((y - 1) * (y + 1))); + } + } else { + *rx = logf(A + sqrtf(A * A - 1)); + } + + *new_y = y; + + if (y < FOUR_SQRT_MIN) { + *B_is_usable = 0; + *sqrt_A2my2 = A * (2 / FLT_EPSILON); + *new_y = y * (2 / FLT_EPSILON); + return; + } + + *B = y / A; + *B_is_usable = 1; + + if (*B > B_crossover) { + *B_is_usable = 0; + if (y == 1 && x < FLT_EPSILON / 128) { + *sqrt_A2my2 = sqrtf(x) * sqrtf((A + y) / 2); + } else if (x >= FLT_EPSILON * fabsf(y - 1)) { + Amy = f(x, y + 1, R) + f(x, y - 1, S); + *sqrt_A2my2 = sqrtf(Amy * (A + y)); + } else if (y > 1) { + *sqrt_A2my2 = x * (4 / FLT_EPSILON / FLT_EPSILON) * y / + sqrtf((y + 1) * (y - 1)); + *new_y = y * (4 / FLT_EPSILON / FLT_EPSILON); + } else { + *sqrt_A2my2 = sqrtf((1 - y) * (1 + y)); + } + } +} + +float complex +casinhf(float complex z) +{ + float x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y; + int B_is_usable; + float complex w; + + x = crealf(z); + y = cimagf(z); + ax = fabsf(x); + ay = fabsf(y); + + if (isnan(x) || isnan(y)) { + if (isinf(x)) + return (cpackf(x, y + y)); + if (isinf(y)) + return (cpackf(y, x + x)); + if (y == 0) + return (cpackf(x + x, y)); + return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + if (signbit(x) == 0) + w = clog_for_large_values(z) + m_ln2; + else + w = clog_for_large_values(-z) + m_ln2; + return (cpackf(copysignf(crealf(w), x), + copysignf(cimagf(w), y))); + } + + if (x == 0 && y == 0) + return (z); + + raise_inexact(); + + if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) + return (z); + + do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y); + if (B_is_usable) + ry = asinf(B); + else + ry = atan2f(new_y, sqrt_A2my2); + return (cpackf(copysignf(rx, x), copysignf(ry, y))); +} + +float complex +casinf(float complex z) +{ + float complex w = casinhf(cpackf(cimagf(z), crealf(z))); + return (cpackf(cimagf(w), crealf(w))); +} + +float complex +cacosf(float complex z) +{ + float x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x; + int sx, sy; + int B_is_usable; + float complex w; + + x = crealf(z); + y = cimagf(z); + sx = signbit(x); + sy = signbit(y); + ax = fabsf(x); + ay = fabsf(y); + + if (isnan(x) || isnan(y)) { + if (isinf(x)) + return (cpackf(y + y, -INFINITY)); + if (isinf(y)) + return (cpackf(x + x, -y)); + if (x == 0) return (cpackf(pio2_hi + pio2_lo, y + y)); + return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + w = clog_for_large_values(z); + rx = fabsf(cimagf(w)); + ry = crealf(w) + m_ln2; + if (sy == 0) + ry = -ry; + return (cpackf(rx, ry)); + } + + if (x == 1 && y == 0) + return (cpackf(0, -y)); + + raise_inexact(); + + if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4) + return (cpackf(pio2_hi - (x - pio2_lo), -y)); + + do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x); + if (B_is_usable) { + if (sx==0) + rx = acosf(B); + else + rx = acosf(-B); + } else { + if (sx==0) + rx = atan2f(sqrt_A2mx2, new_x); + else + rx = atan2f(sqrt_A2mx2, -new_x); + } + if (sy==0) + ry = -ry; + return (cpackf(rx, ry)); +} + +float complex +cacoshf(float complex z) +{ + float complex w; + float rx, ry; + + w = cacosf(z); + rx = crealf(w); + ry = cimagf(w); + if (isnan(rx) && isnan(ry)) + return (cpackf(ry, rx)); + if (isnan(rx)) + return (cpackf(fabsf(ry), rx)); + if (isnan(ry)) + return (cpackf(ry, ry)); + return (cpackf(fabsf(ry), copysignf(rx, cimagf(z)))); +} + +static float complex +clog_for_large_values(float complex z) +{ + float x, y; + float ax, ay, t; + + x = crealf(z); + y = cimagf(z); + ax = fabsf(x); + ay = fabsf(y); + if (ax < ay) { + t = ax; + ax = ay; + ay = t; + } + + if (ax > FLT_MAX / 2) { + return (cpackf(logf(hypotf(x / m_e, y / m_e)) + 1, + atan2f(y, x))); + } + + if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN) + return (cpackf(logf(hypotf(x, y)), atan2f(y, x))); + + return (cpackf(logf(ax * ax + ay * ay) / 2, atan2f(y, x))); +} + +static inline float +sum_squares(float x, float y) +{ + + if (y < SQRT_MIN) + return (x*x); + return (x*x + y*y); +} + +static inline float +real_part_reciprocal(float x, float y) +{ + float scale; + uint32_t hx, hy; + int32_t ix, iy; + + GET_FLOAT_WORD(hx, x); + ix = hx & 0x7f800000; + GET_FLOAT_WORD(hy, y); + iy = hy & 0x7f800000; +#define BIAS (FLT_MAX_EXP - 1) +#define CUTOFF (FLT_MANT_DIG / 2 + 1) + if (ix - iy >= CUTOFF << 23 || isinf(x)) + return (1/x); + if (iy - ix >= CUTOFF << 23) + return (x/y/y); + if (ix <= (BIAS + FLT_MAX_EXP / 2 - CUTOFF) << 23) + return (x / (x * x + y * y)); + SET_FLOAT_WORD(scale, 0x7f800000 - ix); + x *= scale; + y *= scale; + return (x / (x * x + y * y) * scale); +} + +float complex +catanhf(float complex z) +{ + float x, y, ax, ay, rx, ry; + + x = crealf(z); + y = cimagf(z); + ax = fabsf(x); + ay = fabsf(y); + + if (y == 0 && ax <= 1) + return (cpackf(atanhf(x), y)); + + if (x == 0) + return (cpackf(x, atanf(y))); + + if (isnan(x) || isnan(y)) { + if (isinf(x)) + return (cpackf(copysignf(0, x), y+y)); + if (isinf(y)) { + return (cpackf(copysignf(0, x), + copysignf(pio2_hi + pio2_lo, y))); + } + return (cpackf(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); + } + + if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) { + return (cpackf(real_part_reciprocal(x, y), + copysignf(pio2_hi + pio2_lo, y))); + } + + if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) { + raise_inexact(); + return (z); + } + + if (ax == 1 && ay < FLT_EPSILON) + rx = (logf(ay) - m_ln2) / -2; + else + rx = log1pf(4 * ax / sum_squares(ax - 1, ay)) / 4; + + if (ax == 1) + ry = atan2f(2, -ay) / 2; + else if (ay < FLT_EPSILON) + ry = atan2f(2 * ay, (1 - ax) * (1 + ax)) / 2; + else + ry = atan2f(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2; + + return (cpackf(copysignf(rx, x), copysignf(ry, y))); +} + +float complex +catanf(float complex z) +{ + float complex w = catanhf(cpackf(cimagf(z), crealf(z))); + return (cpackf(cimagf(w), crealf(w))); +} diff --git a/lib/libm/src/complex.h b/lib/libm/src/complex.h new file mode 100644 index 0000000000..5640fd6062 --- /dev/null +++ b/lib/libm/src/complex.h @@ -0,0 +1,116 @@ +/*- + * 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: head/include/complex.h 251121 2013-05-30 04:49:26Z das $ + */ + +#ifndef _COMPLEX_H +#define _COMPLEX_H + +#include + +#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 + +#if __ISO_C_VISIBLE >= 2011 +#ifdef __clang__ +#define CMPLX(x, y) ((double complex){ x, y }) +#define CMPLXF(x, y) ((float complex){ x, y }) +#define CMPLXL(x, y) ((long double complex){ x, y }) +#elif __GNUC_PREREQ__(4, 7) +#define CMPLX(x, y) __builtin_complex((double)(x), (double)(y)) +#define CMPLXF(x, y) __builtin_complex((float)(x), (float)(y)) +#define CMPLXL(x, y) __builtin_complex((long double)(x), (long double)(y)) +#endif +#endif /* __ISO_C_VISIBLE >= 2011 */ + +__BEGIN_DECLS + +double cabs(double complex); +float cabsf(float complex); +long double cabsl(long double complex); +double complex cacos(double complex); +float complex cacosf(float complex); +double complex cacosh(double complex); +float complex cacoshf(float complex); +double carg(double complex); +float cargf(float complex); +long double cargl(long double complex); +double complex casin(double complex); +float complex casinf(float complex); +double complex casinh(double complex); +float complex casinhf(float complex); +double complex catan(double complex); +float complex catanf(float complex); +double complex catanh(double complex); +float complex catanhf(float 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/lib/libm/src/e_acos.c b/lib/libm/src/e_acos.c index 685a94e5c4..27616f43de 100644 --- a/lib/libm/src/e_acos.c +++ b/lib/libm/src/e_acos.c @@ -1,27 +1,26 @@ -/* @(#)e_acos.c 5.1 93/09/24 */ + +/* @(#)e_acos.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_acos.c 181074 2008-07-31 22:41:26Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_acos.c,v 1.12 2002/05/26 22:01:47 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_acos.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* acos(x) - * Method : +/* __ieee754_acos(x) + * Method : * acos(x) = pi/2 - asin(x) * acos(-x) = pi/2 + asin(x) * For |x|<=0.5 * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) * For x>0.5 * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) - * = 2asin(sqrt((1-x)/2)) + * = 2asin(sqrt((1-x)/2)) * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) * = 2f + (2c + 2s*z*R(z)) * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term @@ -37,14 +36,18 @@ * Function needed: sqrt */ -#include +#include + +#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 */ @@ -57,7 +60,7 @@ qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ double -acos(double x) +__ieee754_acos(double x) { double z,p,q,r,w,s,c,df; int32_t hx,ix; @@ -100,3 +103,7 @@ acos(double x) return 2.0*(df+w); } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(acos, acosl); +#endif diff --git a/lib/libm/src/e_acosf.c b/lib/libm/src/e_acosf.c index 627c86d933..b26a913b7c 100644 --- a/lib/libm/src/e_acosf.c +++ b/lib/libm/src/e_acosf.c @@ -12,53 +12,49 @@ * is preserved. * ==================================================== * - * $NetBSD: e_acosf.c,v 1.8 2002/05/26 22:01:48 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_acosf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_acosf.c 181257 2008-08-03 17:39:54Z das $ */ -#include +#include "math.h" #include "math_private.h" 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 -acosf(float x) +__ieee754_acosf(float x) { float z,p,q,r,w,s,c,df; 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))); + p = z*(pS0+z*(pS1+z*pS2)); + q = one+z*qS1; s = sqrtf(z); r = p/q; w = r*s-pio2_lo; @@ -71,8 +67,8 @@ acosf(float x) 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/lib/libm/src/e_acosh.c b/lib/libm/src/e_acosh.c index 3ecfcfaa32..a14e09cb03 100644 --- a/lib/libm/src/e_acosh.c +++ b/lib/libm/src/e_acosh.c @@ -1,22 +1,20 @@ -/* @(#)e_acosh.c 5.1 93/09/24 */ + +/* @(#)e_acosh.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_acosh.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_acosh.c,v 1.12 2002/05/26 22:01:48 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_acosh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ - -/* acosh(x) +/* __ieee754_acosh(x) * Method : - * Based on + * Based on * acosh(x) = log [ x + sqrt(x*x-1) ] * we have * acosh(x) := log(x)+ln2, if x is large; else @@ -28,7 +26,7 @@ * acosh(NaN) is NaN without signal. */ -#include +#include "math.h" #include "math_private.h" static const double @@ -36,7 +34,7 @@ one = 1.0, ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */ double -acosh(double x) +__ieee754_acosh(double x) { double t; int32_t hx; @@ -47,13 +45,13 @@ acosh(double x) } else if(hx >=0x41b00000) { /* x > 2**28 */ if(hx >=0x7ff00000) { /* x is inf of NaN */ return x+x; - } else - return log(x)+ln2; /* acosh(huge)=log(2x) */ + } else + return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */ } else if(((hx-0x3ff00000)|lx)==0) { return 0.0; /* acosh(1) = 0 */ } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ t=x*x; - return log(2.0*x-one/(x+sqrt(t-one))); + return __ieee754_log(2.0*x-one/(x+sqrt(t-one))); } else { /* 1 +#include "math.h" #include "math_private.h" static const float @@ -24,7 +23,7 @@ one = 1.0, ln2 = 6.9314718246e-01; /* 0x3f317218 */ float -acoshf(float x) +__ieee754_acoshf(float x) { float t; int32_t hx; @@ -35,14 +34,14 @@ acoshf(float x) if(hx >=0x7f800000) { /* x is inf of NaN */ return x+x; } else - return logf(x)+ln2; /* acosh(huge)=log(2x) */ + return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */ } else if (hx==0x3f800000) { return 0.0; /* acosh(1) = 0 */ } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ t=x*x; - return logf((float)2.0*x-one/(x+sqrtf(t-one))); + return __ieee754_logf((float)2.0*x-one/(x+__ieee754_sqrtf(t-one))); } else { /* 1 -#include +#include "math.h" #include "math_private.h" static const double @@ -66,12 +66,10 @@ qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ double -asin(double x) +__ieee754_asin(double x) { - double t,w,p,q,c,r,s; + double t=0.0,w,p,q,c,r,s; int32_t hx,ix; - - t = 0; GET_HIGH_WORD(hx,x); ix = hx&0x7fffffff; if(ix>= 0x3ff00000) { /* |x|>= 1 */ @@ -79,17 +77,17 @@ asin(double x) GET_LOW_WORD(lx,x); if(((ix-0x3ff00000)|lx)==0) /* asin(1)=+-pi/2 with inexact */ - return x*pio2_hi+x*pio2_lo; - return (x-x)/(x-x); /* asin(|x|>1) is NaN */ + 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); @@ -108,6 +106,10 @@ asin(double x) p = 2.0*s*r-(pio2_lo-2.0*c); q = pio4_hi-2.0*w; t = pio4_hi-(p-q); - } - if(hx>0) return t; else return -t; + } + if(hx>0) return t; else return -t; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(asin, asinl); +#endif diff --git a/lib/libm/src/e_asinf.c b/lib/libm/src/e_asinf.c index a8aa9dffc8..6af26df804 100644 --- a/lib/libm/src/e_asinf.c +++ b/lib/libm/src/e_asinf.c @@ -12,74 +12,53 @@ * is preserved. * ==================================================== * - * $NetBSD: e_asinf.c,v 1.8 2002/05/26 22:01:48 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_asinf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_asinf.c 181405 2008-08-08 00:21:27Z das $ */ -#include +#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.8539818525e-01, /* 0x3f490fdb */ /* 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 */ +pS0 = 1.6666586697e-01, +pS1 = -4.2743422091e-02, +pS2 = -8.6563630030e-03, +qS1 = -7.0662963390e-01; + +static const double +pio2 = 1.570796326794896558e+00; float -asinf(float x) +__ieee754_asinf(float x) { - float t,w,p,q,c,r,s; + double s; + float t,w,p,q; int32_t hx,ix; - - t = 0; 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 */ + 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<0x32000000) { /* if |x| < 2**-27 */ + if(ix<0x39800000) { /* |x| < 2**-12 */ 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)); + 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+t*(pS3+t*(pS4+t*pS5))))); - q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); - s = 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); - } + 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/lib/libm/src/e_asinl.c b/lib/libm/src/e_asinl.c index f587ef6694..688183784e 100644 --- a/lib/libm/src/e_asinl.c +++ b/lib/libm/src/e_asinl.c @@ -1,13 +1,13 @@ /* @(#)e_asin.c 1.3 95/01/18 */ -/* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */ +/* $FreeBSD: head/lib/msun/src/e_asinl.c 181258 2008-08-03 17:49:05Z 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== */ @@ -39,8 +39,8 @@ asinl(long double x) 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 */ + return x*pio2_hi+x*pio2_lo; + return (x-x)/(x-x); /* asin(|x|>1) is NaN */ } else if (exptone) return x;/* return x with inexact if x!=0*/ @@ -69,6 +69,6 @@ asinl(long double x) 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; + } + if(expsign>0) return t; else return -t; } diff --git a/lib/libm/src/e_atan2.c b/lib/libm/src/e_atan2.c index ff64adfe9d..f6f2c610f2 100644 --- a/lib/libm/src/e_atan2.c +++ b/lib/libm/src/e_atan2.c @@ -1,22 +1,22 @@ -/* @(#)e_atan2.c 5.1 93/09/24 */ + +/* @(#)e_atan2.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_atan2.c 181204 2008-08-02 19:17:00Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== * - * $NetBSD: e_atan2.c,v 1.12 2002/05/26 22:01:48 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_atan2.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* atan2(y,x) +/* __ieee754_atan2(y,x) * Method : * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). - * 2. Reduce x to positive by (if x and y are unexceptional): + * 2. Reduce x to positive by (if x and y are unexceptional): * ARG (x+iy) = arctan(y/x) ... if x > 0, * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, * @@ -34,25 +34,29 @@ * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; * * 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 + * 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 +#include + +#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 -atan2(double y, double x) +__ieee754_atan2(double y, double x) { double z; int32_t k,m,hx,hy,ix,iy; @@ -65,13 +69,13 @@ 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 */ if((iy|ly)==0) { switch(m) { - case 0: + 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 */ @@ -79,7 +83,7 @@ atan2(double y, double x) } /* when x = 0 */ if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; - + /* when x is INF */ if(ix==0x7ff00000) { if(iy==0x7ff00000) { @@ -103,19 +107,21 @@ 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/lib/libm/src/e_atan2f.c b/lib/libm/src/e_atan2f.c index 378d34c0d4..052c62fd60 100644 --- a/lib/libm/src/e_atan2f.c +++ b/lib/libm/src/e_atan2f.c @@ -12,23 +12,24 @@ * is preserved. * ==================================================== * - * $NetBSD: e_atan2f.c,v 1.7 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_atan2f.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_atan2f.c 181257 2008-08-03 17:39:54Z das $ */ -#include +#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.1415925026e+00, /* 0x40490fda */ -pi_lo = 1.5099578832e-07; /* 0x34222168 */ +pi = 3.1415927410e+00; /* 0x40490fdb */ +static volatile float +pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ float -atan2f(float y, float x) +__ieee754_atan2f(float y, float x) { float z; int32_t k,m,hx,hy,ix,iy; @@ -78,17 +79,15 @@ 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/lib/libm/src/e_atan2l.c b/lib/libm/src/e_atan2l.c index 0bb68eed54..4409350829 100644 --- a/lib/libm/src/e_atan2l.c +++ b/lib/libm/src/e_atan2l.c @@ -1,13 +1,13 @@ /* @(#)e_atan2.c 1.3 95/01/18 */ -/* FreeBSD: head/lib/msun/src/e_atan2.c 176451 2008-02-22 02:30:36Z das */ +/* $FreeBSD: head/lib/msun/src/e_atan2l.c 181204 2008-08-02 19:17:00Z 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== * @@ -67,7 +67,7 @@ atan2l(long double y, long double x) /* when y = 0 */ if(expty==0 && ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)==0) { switch(m) { - case 0: + 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 */ diff --git a/lib/libm/src/e_atanh.c b/lib/libm/src/e_atanh.c index 3b1a8ec05f..c91f1add14 100644 --- a/lib/libm/src/e_atanh.c +++ b/lib/libm/src/e_atanh.c @@ -1,26 +1,26 @@ -/* @(#)e_atanh.c 5.1 93/09/24 */ + +/* @(#)e_atanh.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_atanh.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== * - * $NetBSD: e_atanh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_atanh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* atanh(x) +/* __ieee754_atanh(x) * Method : * 1.Reduced x to positive by atanh(-x) = -atanh(x) * 2.For x>=0.5 * 1 2x x * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) * 2 1 - x 1 - x - * + * * For x<0.5 * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) * @@ -31,15 +31,14 @@ * */ -#include +#include "math.h" #include "math_private.h" static const double one = 1.0, huge = 1e300; - static const double zero = 0.0; double -atanh(double x) +__ieee754_atanh(double x) { double t; int32_t hx,ix; @@ -48,14 +47,14 @@ atanh(double x) ix = hx&0x7fffffff; if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ return (x-x)/(x-x); - if(ix==0x3ff00000) + if(ix==0x3ff00000) return x/zero; if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ SET_HIGH_WORD(x,ix); if(ix<0x3fe00000) { /* x < 0.5 */ t = x+x; t = 0.5*log1p(t+t*x/(one-x)); - } else + } else t = 0.5*log1p((x+x)/(one-x)); if(hx>=0) return t; else return -t; } diff --git a/lib/libm/src/e_atanhf.c b/lib/libm/src/e_atanhf.c index 31b71fd065..906393036a 100644 --- a/lib/libm/src/e_atanhf.c +++ b/lib/libm/src/e_atanhf.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: e_atanhf.c,v 1.7 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_atanhf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_atanhf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float one = 1.0, huge = 1e30; @@ -24,7 +23,7 @@ static const float one = 1.0, huge = 1e30; static const float zero = 0.0; float -atanhf(float x) +__ieee754_atanhf(float x) { float t; int32_t hx,ix; diff --git a/lib/libm/src/e_cosh.c b/lib/libm/src/e_cosh.c index 598c3ada98..b7d8cfc99e 100644 --- a/lib/libm/src/e_cosh.c +++ b/lib/libm/src/e_cosh.c @@ -1,31 +1,30 @@ -/* @(#)e_cosh.c 5.1 93/09/24 */ + +/* @(#)e_cosh.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_cosh.c 226598 2011-10-21 06:28:47Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_cosh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_cosh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* cosh(x) - * Method : +/* __ieee754_cosh(x) + * Method : * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2 - * 1. Replace x by |x| (cosh(x) = cosh(-x)). - * 2. - * [ exp(x) - 1 ]^2 + * 1. Replace x by |x| (cosh(x) = cosh(-x)). + * 2. + * [ exp(x) - 1 ]^2 * 0 <= x <= ln2/2 : cosh(x) := 1 + ------------------- * 2*exp(x) * * exp(x) + 1/exp(x) * ln2/2 <= x <= 22 : cosh(x) := ------------------- * 2 - * 22 <= x <= lnovft : cosh(x) := exp(x)/2 + * 22 <= x <= lnovft : cosh(x) := exp(x)/2 * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2) * ln2ovft < x : cosh(x) := huge*huge (overflow) * @@ -34,24 +33,23 @@ * only cosh(0)=1 is exact for finite x. */ -#include +#include "math.h" #include "math_private.h" static const double one = 1.0, half=0.5, huge = 1.0e300; double -cosh(double x) +__ieee754_cosh(double x) { double t,w; int32_t ix; - u_int32_t lx; /* High word of |x|. */ GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; /* x is INF or NaN */ - if(ix>=0x7ff00000) return x*x; + if(ix>=0x7ff00000) return x*x; /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ if(ix<0x3fd62e43) { @@ -63,21 +61,16 @@ cosh(double x) /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ if (ix < 0x40360000) { - t = exp(fabs(x)); + t = __ieee754_exp(fabs(x)); return half*t+half/t; } /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ - if (ix < 0x40862E42) return half*exp(fabs(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 = 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/lib/libm/src/e_coshf.c b/lib/libm/src/e_coshf.c index 9e47cd507b..0627b691ec 100644 --- a/lib/libm/src/e_coshf.c +++ b/lib/libm/src/e_coshf.c @@ -12,18 +12,16 @@ * is preserved. * ==================================================== * - * $NetBSD: e_coshf.c,v 1.9 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_coshf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_coshf.c 226598 2011-10-21 06:28:47Z das $ */ -#include +#include "math.h" #include "math_private.h" -static const float huge = 1.0e30; -static const float one = 1.0, half=0.5; +static const float one = 1.0, half=0.5, huge = 1.0e30; float -coshf(float x) +__ieee754_coshf(float x) { float t,w; int32_t ix; @@ -38,25 +36,22 @@ coshf(float x) if(ix<0x3eb17218) { t = expm1f(fabsf(x)); w = one+t; - if (ix<0x24000000) return w; /* cosh(tiny) = 1 */ + if (ix<0x39800000) return one; /* cosh(tiny) = 1 */ return one+(t*t)/(w+w); } - /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ - if (ix < 0x41b00000) { - t = expf(fabsf(x)); + /* |x| in [0.5*ln2,9], return (exp(|x|)+1/exp(|x|))/2; */ + if (ix < 0x41100000) { + t = __ieee754_expf(fabsf(x)); return half*t+half/t; } - /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ - if (ix < 0x42b17180) return half*expf(fabsf(x)); + /* |x| in [9, log(maxfloat)] return half*exp(|x|) */ + if (ix < 0x42b17217) return half*__ieee754_expf(fabsf(x)); - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = expf(half*fabsf(x)); - t = half*w; - return t*w; - } + /* |x| in [log(maxfloat), overflowthresold] */ + if (ix<=0x42b2d4fc) + return __ldexp_expf(fabsf(x), -1); /* |x| > overflowthresold, cosh(x) overflow */ return huge*huge; diff --git a/lib/libm/src/e_exp.c b/lib/libm/src/e_exp.c index bdbb8f29bc..6fb8000226 100644 --- a/lib/libm/src/e_exp.c +++ b/lib/libm/src/e_exp.c @@ -1,19 +1,17 @@ -/* @(#)e_exp.c 5.1 93/09/24 */ + +/* @(#)e_exp.c 1.6 04/04/22 */ +/* $FreeBSD: head/lib/msun/src/e_exp.c 251024 2013-05-27 08:50:10Z das $ */ /* * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (C) 2004 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_exp.c,v 1.11 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_exp.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* exp(x) +/* __ieee754_exp(x) * Returns the exponential of x. * * Method @@ -21,36 +19,36 @@ * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. * Given x, find r and integer k such that * - * x = k*ln2 + r, |r| <= 0.5*ln2. + * x = k*ln2 + r, |r| <= 0.5*ln2. * - * Here r will be represented as r = hi-lo for better + * Here r will be represented as r = hi-lo for better * accuracy. * * 2. Approximation of exp(r) by a special rational function on * the interval [0,0.34658]: * Write * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... - * We use a special Reme algorithm on [0,0.34658] to generate - * a polynomial of degree 5 to approximate R. The maximum error + * We use a special Remes algorithm on [0,0.34658] to generate + * a polynomial of degree 5 to approximate R. The maximum error * of this polynomial approximation is bounded by 2**-59. In * other words, * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 * (where z=r*r, and the values of P1 to P5 are listed below) * and * | 5 | -59 - * | 2.0+P1*z+...+P5*z - R(z) | <= 2 + * | 2.0+P1*z+...+P5*z - R(z) | <= 2 * | | * The computation of exp(r) thus becomes * 2*r * exp(r) = 1 + ------- * R - r - * r*R1(r) + * r*R1(r) * = 1 + r + ----------- (for better accuracy) * 2 - R1(r) * where * 2 4 10 * R1(r) = r - (P1*r + P2*r + ... + P5*r ). - * + * * 3. Scale back to obtain exp(x): * From step 1, we have * exp(x) = 2^k * exp(r) @@ -65,25 +63,25 @@ * 1 ulp (unit in the last place). * * Misc. info. - * For IEEE double + * For IEEE double * if x > 7.09782712893383973096e+02 then exp(x) overflow * if x < -7.45133219101941108420e+02 then exp(x) underflow * * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the + * 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 +#include + +#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 */ @@ -97,16 +95,17 @@ 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 -exp(double x) /* default IEEE double exp */ +__ieee754_exp(double x) /* default IEEE double exp */ { - double y,hi,lo,c,t; - int32_t k,xsb; + double y,hi=0.0,lo=0.0,c,t,twopk; + int32_t k=0,xsb; u_int32_t hx; - hi = lo = 0; - k = 0; GET_HIGH_WORD(hx,x); xsb = (hx>>31)&1; /* sign bit of x */ hx &= 0x7fffffff; /* high word of |x| */ @@ -125,17 +124,17 @@ exp(double x) /* default IEEE double exp */ } /* argument reduction */ - if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; } else { - k = invln2*x+halF[xsb]; + k = (int)(invln2*x+halF[xsb]); t = k; 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 */ } @@ -143,18 +142,21 @@ 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); + 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/lib/libm/src/e_expf.c b/lib/libm/src/e_expf.c index 30d0ee7496..15d33ef828 100644 --- a/lib/libm/src/e_expf.c +++ b/lib/libm/src/e_expf.c @@ -11,42 +11,42 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_expf.c,v 1.9 2002/05/26 22:01:49 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_expf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_expf.c 251024 2013-05-27 08:50:10Z das $ */ -#include -#include "math_private.h" +#include -static const float huge = 1.0e+30; +#include "math.h" +#include "math_private.h" static const float one = 1.0, halF[2] = {0.5,-0.5,}, -twom100 = 7.8886090522e-31, /* 2**-100=0x0d800000 */ o_threshold= 8.8721679688e+01, /* 0x42b17180 */ u_threshold= -1.0397208405e+02, /* 0xc2cff1b5 */ -ln2HI[2] ={ 6.9313812256e-01, /* 0x3f317180 */ - -6.9313812256e-01,}, /* 0xbf317180 */ -ln2LO[2] ={ 9.0580006145e-06, /* 0x3717f7d1 */ - -9.0580006145e-06,}, /* 0xb717f7d1 */ +ln2HI[2] ={ 6.9314575195e-01, /* 0x3f317200 */ + -6.9314575195e-01,}, /* 0xbf317200 */ +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 -expf(float x) /* default IEEE double exp */ +__ieee754_expf(float x) { - float y,hi,lo,c,t; - int32_t k,xsb; + float y,hi=0.0,lo=0.0,c,t,twopk; + int32_t k=0,xsb; u_int32_t hx; - hi = lo = 0; - k = 0; GET_FLOAT_WORD(hx,x); xsb = (hx>>31)&1; /* sign bit of x */ hx &= 0x7fffffff; /* high word of |x| */ @@ -71,27 +71,26 @@ 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/lib/libm/src/e_fmod.c b/lib/libm/src/e_fmod.c index bf98826d3d..627e83019e 100644 --- a/lib/libm/src/e_fmod.c +++ b/lib/libm/src/e_fmod.c @@ -1,30 +1,30 @@ -/* @(#)e_fmod.c 5.1 93/09/24 */ + +/* @(#)e_fmod.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_fmod.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_fmod.c,v 1.11 2002/05/26 22:01:49 wiz Exp $ */ -/* - * fmod(x,y) +/* + * __ieee754_fmod(x,y) * Return x mod y in exact arithmetic * Method: shift and subtract */ -#include +#include "math.h" #include "math_private.h" static const double one = 1.0, Zero[] = {0.0, -0.0,}; double -fmod(double x, double y) +__ieee754_fmod(double x, double y) { int32_t n,hx,hy,hz,ix,iy,sx,i; u_int32_t lx,ly,lz; @@ -41,7 +41,7 @@ fmod(double x, double y) return (x*y)/(x*y); if(hx<=hy) { if((hx>31]; /* |x|=|y| return x*0*/ } @@ -64,7 +64,7 @@ fmod(double x, double y) } else iy = (hy>>20)-1023; /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -1022) + if(ix >= -1022) hx = 0x00100000|(0x000fffff&hx); else { /* subnormal x, shift x to normal */ n = -1022-ix; @@ -76,7 +76,7 @@ fmod(double x, double y) lx = 0; } } - if(iy >= -1022) + if(iy >= -1022) hy = 0x00100000|(0x000fffff&hy); else { /* subnormal y, shift y to normal */ n = -1022-iy; @@ -95,9 +95,9 @@ fmod(double x, double y) hz=hx-hy;lz=lx-ly; if(lx>31); lx = lx+lx;} else { - if((hz|lz)==0) /* return sign(x)*0 */ + if((hz|lz)==0) /* return sign(x)*0 */ return Zero[(u_int32_t)sx>>31]; - hx = hz+hz+(lz>>31); lx = lz+lz; + hx = hz+hz+(lz>>31); lx = lz+lz; } } hz=hx-hy;lz=lx-ly; if(lx +#include "math.h" #include "math_private.h" static const float one = 1.0, Zero[] = {0.0, -0.0,}; float -fmodf(float x, float y) +__ieee754_fmodf(float x, float y) { int32_t n,hx,hy,hz,ix,iy,sx,i; @@ -75,9 +75,9 @@ fmodf(float x, float y) hz=hx-hy; if(hz<0){hx = hx+hx;} else { - if(hz==0) /* return sign(x)*0 */ + if(hz==0) /* return sign(x)*0 */ return Zero[(u_int32_t)sx>>31]; - hx = hz+hz; + hx = hz+hz; } } hz=hx-hy; diff --git a/lib/libm/src/e_fmodl.c b/lib/libm/src/e_fmodl.c index d71a2811c2..716c7fdbca 100644 --- a/lib/libm/src/e_fmodl.c +++ b/lib/libm/src/e_fmodl.c @@ -1,15 +1,14 @@ /* @(#)e_fmod.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_fmodl.c 181063 2008-07-31 20:09:47Z 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 181063 (2008-07-31) */ #include diff --git a/lib/libm/src/e_gamma.c b/lib/libm/src/e_gamma.c new file mode 100644 index 0000000000..e9cfde488e --- /dev/null +++ b/lib/libm/src/e_gamma.c @@ -0,0 +1,31 @@ + +/* @(#)e_gamma.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_gamma.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. + * ==================================================== + * + */ + +/* __ieee754_gamma(x) + * Return the logarithm of the Gamma function of x. + * + * Method: call __ieee754_gamma_r + */ + +#include "math.h" +#include "math_private.h" + +extern int signgam; + +double +__ieee754_gamma(double x) +{ + return __ieee754_gamma_r(x,&signgam); +} diff --git a/lib/libm/src/e_gamma_r.c b/lib/libm/src/e_gamma_r.c new file mode 100644 index 0000000000..df33a36ffd --- /dev/null +++ b/lib/libm/src/e_gamma_r.c @@ -0,0 +1,30 @@ + +/* @(#)e_gamma_r.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_gamma_r.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. + * ==================================================== + * + */ + +/* __ieee754_gamma_r(x, signgamp) + * Reentrant version of the logarithm of the Gamma function + * with user provide pointer for the sign of Gamma(x). + * + * Method: See __ieee754_lgamma_r + */ + +#include "math.h" +#include "math_private.h" + +double +__ieee754_gamma_r(double x, int *signgamp) +{ + return __ieee754_lgamma_r(x,signgamp); +} diff --git a/lib/libm/src/w_gammaf.c b/lib/libm/src/e_gammaf.c similarity index 59% rename from lib/libm/src/w_gammaf.c rename to lib/libm/src/e_gammaf.c index 9502d8691d..a73495053e 100644 --- a/lib/libm/src/w_gammaf.c +++ b/lib/libm/src/e_gammaf.c @@ -1,4 +1,4 @@ -/* w_gammaf.c -- float version of w_gamma.c. +/* e_gammaf.c -- float version of e_gamma.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. */ @@ -12,15 +12,22 @@ * is preserved. * ==================================================== * - * $NetBSD: w_gammaf.c,v 1.8 2002/05/26 22:02:01 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_gammaf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_gammaf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +/* __ieee754_gammaf(x) + * Return the logarithm of the Gamma function of x. + * + * Method: call __ieee754_gammaf_r + */ + +#include "math.h" #include "math_private.h" +extern int signgam; + float -gammaf(float x) +__ieee754_gammaf(float x) { - return lgammaf_r(x,&signgam); + return __ieee754_gammaf_r(x,&signgam); } diff --git a/lib/libm/src/s_fabsf.c b/lib/libm/src/e_gammaf_r.c similarity index 54% copy from lib/libm/src/s_fabsf.c copy to lib/libm/src/e_gammaf_r.c index 8d81c3d536..8b692eb073 100644 --- a/lib/libm/src/s_fabsf.c +++ b/lib/libm/src/e_gammaf_r.c @@ -1,4 +1,4 @@ -/* s_fabsf.c -- float version of s_fabs.c. +/* e_gammaf_r.c -- float version of e_gamma_r.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. */ @@ -12,22 +12,21 @@ * is preserved. * ==================================================== * - * $NetBSD: s_fabsf.c,v 1.7 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_fabsf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_gammaf_r.c 176451 2008-02-22 02:30:36Z das $ */ -/* - * fabsf(x) returns the absolute value of x. +/* __ieee754_gammaf_r(x, signgamp) + * Reentrant version of the logarithm of the Gamma function + * with user provide pointer for the sign of Gamma(x). + * + * Method: See __ieee754_lgammaf_r */ -#include +#include "math.h" #include "math_private.h" float -fabsf(float x) +__ieee754_gammaf_r(float x, int *signgamp) { - u_int32_t ix; - GET_FLOAT_WORD(ix,x); - SET_FLOAT_WORD(x,ix&0x7fffffff); - return x; + return __ieee754_lgammaf_r(x,signgamp); } diff --git a/lib/libm/src/e_hypot.c b/lib/libm/src/e_hypot.c index fcca397221..77d920dbf1 100644 --- a/lib/libm/src/e_hypot.c +++ b/lib/libm/src/e_hypot.c @@ -1,25 +1,25 @@ -/* @(#)e_hypot.c 5.1 93/09/24 */ + +/* @(#)e_hypot.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_hypot.c 226380 2011-10-15 07:00:28Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_hypot.c,v 1.13 2008/04/25 22:21:53 christos */ -/* hypot(x,y) +/* __ieee754_hypot(x,y) * - * Method : - * If (assume round-to-nearest) z=x*x+y*y - * has error less than sqrt(2)/2 ulp, than + * Method : + * If (assume round-to-nearest) z=x*x+y*y + * has error less than sqrt(2)/2 ulp, than * sqrt(z) has error less than 1 ulp (exercise). * - * So, compute sqrt(x*x+y*y) with some care as + * So, compute sqrt(x*x+y*y) with some care as * follows to get the error below 1 ulp: * * Assume x>y>0; @@ -28,11 +28,11 @@ * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y * where x1 = x with lower 32 bits cleared, x2 = x-x1; else * 2. if x <= 2y use - * t1*yy1+((x-y)*(x-y)+(t1*y2+t2*y)) - * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, - * yy1= y with lower 32 bits chopped, y2 = y-yy1. - * - * NOTE: scaling may be necessary if some argument is too + * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) + * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, + * y1= y with lower 32 bits chopped, y2 = y-y1. + * + * NOTE: scaling may be necessary if some argument is too * large or too tiny * * Special cases: @@ -40,17 +40,19 @@ * hypot(x,y) is NAN if x or y is NAN. * * Accuracy: - * hypot(x,y) returns sqrt(x^2+y^2) with error less - * than 1 ulps (units in the last place) + * hypot(x,y) returns sqrt(x^2+y^2) with error less + * than 1 ulps (units in the last place) */ -#include +#include + +#include "math.h" #include "math_private.h" double -hypot(double x, double y) +__ieee754_hypot(double x, double y) { - double a=x,b=y,t1,t2,yy1,y2,w; + double a,b,t1,t2,y1,y2,w; int32_t j,k,ha,hb; GET_HIGH_WORD(ha,x); @@ -58,14 +60,15 @@ 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); @@ -104,13 +107,13 @@ hypot(double x, double y) w = sqrt(t1*t1-(b*(-b)-t2*(a+t1))); } else { a = a+a; - yy1 = 0; - SET_HIGH_WORD(yy1,hb); - y2 = b - yy1; + y1 = 0; + SET_HIGH_WORD(y1,hb); + y2 = b - y1; t1 = 0; SET_HIGH_WORD(t1,ha+0x00100000); t2 = a - t1; - w = sqrt(t1*yy1-(w*(-w)-(t1*y2+t2*b))); + w = sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b))); } if(k!=0) { u_int32_t high; @@ -120,3 +123,7 @@ hypot(double x, double y) return t1*w; } else return w; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(hypot, hypotl); +#endif diff --git a/lib/libm/src/e_hypotf.c b/lib/libm/src/e_hypotf.c index 365d0cbbf0..1e794c49a0 100644 --- a/lib/libm/src/e_hypotf.c +++ b/lib/libm/src/e_hypotf.c @@ -12,16 +12,16 @@ * is preserved. * ==================================================== * - * $NetBSD: e_hypotf.c,v 1.9 2008/04/25 22:21:53 christos Exp $ + * $FreeBSD: head/lib/msun/src/e_hypotf.c 226380 2011-10-15 07:00:28Z das $ */ -#include +#include "math.h" #include "math_private.h" float -hypotf(float x, float y) +__ieee754_hypotf(float x, float y) { - float a=x,b=y,t1,t2,yy1,y2,w; + float a,b,t1,t2,y1,y2,w; int32_t j,k,ha,hb; GET_FLOAT_WORD(ha,x); @@ -29,33 +29,34 @@ 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; } - /* scale a and b by 2**-60 */ - ha -= 0x5d800000; hb -= 0x5d800000; k += 60; + /* scale a and b by 2**-68 */ + ha -= 0x22000000; hb -= 0x22000000; k += 68; SET_FLOAT_WORD(a,ha); SET_FLOAT_WORD(b,hb); } if(hb < 0x26800000) { /* b < 2**-50 */ if(hb <= 0x007fffff) { /* subnormal b or 0 */ if(hb==0) return a; - SET_FLOAT_WORD(t1,0x3f000000); /* t1=2^126 */ + SET_FLOAT_WORD(t1,0x7e800000); /* t1=2^126 */ b *= t1; a *= t1; k -= 126; - } else { /* scale a and b by 2^60 */ - ha += 0x5d800000; /* a *= 2^60 */ - hb += 0x5d800000; /* b *= 2^60 */ - k -= 60; + } else { /* scale a and b by 2^68 */ + ha += 0x22000000; /* a *= 2^68 */ + hb += 0x22000000; /* b *= 2^68 */ + k -= 68; SET_FLOAT_WORD(a,ha); SET_FLOAT_WORD(b,hb); } @@ -65,14 +66,14 @@ hypotf(float x, float y) if (w>b) { SET_FLOAT_WORD(t1,ha&0xfffff000); t2 = a-t1; - w = sqrtf(t1*t1-(b*(-b)-t2*(a+t1))); + w = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1))); } else { a = a+a; - SET_FLOAT_WORD(yy1,hb&0xfffff000); - y2 = b - yy1; - SET_FLOAT_WORD(t1,ha+0x00800000); + SET_FLOAT_WORD(y1,hb&0xfffff000); + y2 = b - y1; + SET_FLOAT_WORD(t1,(ha+0x00800000)&0xfffff000); t2 = a - t1; - w = sqrtf(t1*yy1-(w*(-w)-(t1*y2+t2*b))); + w = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b))); } if(k!=0) { SET_FLOAT_WORD(t1,0x3f800000+(k<<23)); diff --git a/lib/libm/src/e_hypotl.c b/lib/libm/src/e_hypotl.c index a469479d08..eb522b5fa0 100644 --- a/lib/libm/src/e_hypotl.c +++ b/lib/libm/src/e_hypotl.c @@ -1,15 +1,14 @@ /* From: @(#)e_hypot.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_hypotl.c 226412 2011-10-16 05:36:39Z 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 226412 (2011-10-16) */ /* long double version of hypot(). See e_hypot.c for most comments. */ diff --git a/lib/libm/src/e_j0.c b/lib/libm/src/e_j0.c index d7abd31475..61a7b14639 100644 --- a/lib/libm/src/e_j0.c +++ b/lib/libm/src/e_j0.c @@ -1,18 +1,18 @@ -/* @(#)e_j0.c 5.1 93/09/24 */ + +/* @(#)e_j0.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_j0.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_j0.c,v 1.12 2007/08/20 16:01:38 drochner Exp $ */ -/* j0(x), y0(x) +/* __ieee754_j0(x), __ieee754_y0(x) * Bessel function of the first and second kinds of order zero. * Method -- j0(x): * 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ... @@ -31,20 +31,20 @@ * (To avoid cancellation, use * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) * to compute the worse one.) - * + * * 3 Special cases * j0(nan)= nan * j0(0) = 1 * j0(inf) = 0 - * + * * Method -- y0(x): * 1. For x<2. - * Since + * Since * y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...) * therefore y0(x)-2/pi*j0(x)*ln(x) is an even function. * We use the following function to approximate y0, * y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2 - * where + * where * U(z) = u00 + u01*z + ... + u06*z^6 * V(z) = 1 + v01*z + ... + v04*z^4 * with absolute approximation error bounded by 2**-72. @@ -57,8 +57,7 @@ * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0. */ -#include -#include +#include "math.h" #include "math_private.h" static double pzero(double), qzero(double); @@ -81,7 +80,7 @@ S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */ static const double zero = 0.0; double -j0(double x) +__ieee754_j0(double x) { double z, s,c,ss,cc,r,u,v; int32_t hx,ix; @@ -142,7 +141,7 @@ v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */ v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */ double -y0(double x) +__ieee754_y0(double x) { double z, s,c,ss,cc,u,v; int32_t hx,ix,lx; @@ -150,7 +149,7 @@ y0(double x) EXTRACT_WORDS(hx,lx,x); ix = 0x7fffffff&hx; /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */ - if(ix>=0x7ff00000) return one/(x+x*x); + if(ix>=0x7ff00000) return one/(x+x*x); if((ix|lx)==0) return -one/zero; if(hx<0) return zero/zero; if(ix >= 0x40000000) { /* |x| >= 2.0 */ @@ -186,12 +185,12 @@ y0(double x) return z; } if(ix<=0x3e400000) { /* x < 2**-27 */ - return(u00 + tpi*log(x)); + return(u00 + tpi*__ieee754_log(x)); } z = x*x; u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); v = one+z*(v01+z*(v02+z*(v03+z*v04))); - return(u/v + tpi*(j0(x)*log(x))); + return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x))); } /* The asymptotic expansions of pzero is @@ -267,14 +266,11 @@ static const double pS2[5] = { 1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */ }; -static double -pzero(double x) + static double pzero(double x) { const double *p,*q; double z,r,s; int32_t ix; - - p = q = NULL; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x40200000) {p = pR8; q= pS8;} @@ -286,7 +282,7 @@ pzero(double x) s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); return one+ r/s; } - + /* For x >= 8, the asymptotic expansions of qzero is * -1/8 s + 75/1024 s^3 - ..., where s = 1/x. @@ -365,14 +361,11 @@ static const double qS2[6] = { -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */ }; -static double -qzero(double x) + static double qzero(double x) { const double *p,*q; double s,r,z; int32_t ix; - - p = q = NULL; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x40200000) {p = qR8; q= qS8;} diff --git a/lib/libm/src/e_j0f.c b/lib/libm/src/e_j0f.c index 510756d7fe..0a2bcc209d 100644 --- a/lib/libm/src/e_j0f.c +++ b/lib/libm/src/e_j0f.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: e_j0f.c,v 1.10 2007/08/20 16:01:38 drochner Exp $ + * $FreeBSD: head/lib/msun/src/e_j0f.c 176451 2008-02-22 02:30:36Z das $ */ -#include -#include +#include "math.h" #include "math_private.h" static float pzerof(float), qzerof(float); @@ -39,7 +38,7 @@ S04 = 1.1661400734e-09; /* 0x30a045e8 */ static const float zero = 0.0; float -j0f(float x) +__ieee754_j0f(float x) { float z, s,c,ss,cc,r,u,v; int32_t hx,ix; @@ -62,11 +61,8 @@ 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) */ -#ifdef DEAD_CODE if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x); - else -#endif - { + else { u = pzerof(x); v = qzerof(x); z = invsqrtpi*(u*cc-v*ss)/sqrtf(x); } @@ -103,7 +99,7 @@ v03 = 2.5915085189e-07, /* 0x348b216c */ v04 = 4.4111031494e-10; /* 0x2ff280c2 */ float -y0f(float x) +__ieee754_y0f(float x) { float z, s,c,ss,cc,u,v; int32_t hx,ix; @@ -139,23 +135,20 @@ y0f(float x) if ((s*c)0x80000000) z = (invsqrtpi*ss)/sqrtf(x); - else -#endif - { + else { u = pzerof(x); v = qzerof(x); z = invsqrtpi*(u*ss+v*cc)/sqrtf(x); } return z; } if(ix<=0x32000000) { /* x < 2**-27 */ - return(u00 + tpi*logf(x)); + return(u00 + tpi*__ieee754_logf(x)); } z = x*x; u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); v = one+z*(v01+z*(v02+z*(v03+z*v04))); - return(u/v + tpi*(j0f(x)*logf(x))); + return(u/v + tpi*(__ieee754_j0f(x)*__ieee754_logf(x))); } /* The asymptotic expansions of pzero is @@ -230,14 +223,11 @@ static const float pS2[5] = { 1.4657617569e+01, /* 0x416a859a */ }; -static float -pzerof(float x) + static float pzerof(float x) { const float *p,*q; float z,r,s; int32_t ix; - - p = q = NULL; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x41000000) {p = pR8; q= pS8;} @@ -328,14 +318,11 @@ static const float qS2[6] = { -5.3109550476e+00, /* 0xc0a9f358 */ }; -static float -qzerof(float x) + static float qzerof(float x) { const float *p,*q; float s,r,z; int32_t ix; - - p = q = NULL; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x41000000) {p = qR8; q= qS8;} diff --git a/lib/libm/src/e_j1.c b/lib/libm/src/e_j1.c index b5ee297735..7a4ac08f31 100644 --- a/lib/libm/src/e_j1.c +++ b/lib/libm/src/e_j1.c @@ -1,18 +1,18 @@ -/* @(#)e_j1.c 5.1 93/09/24 */ + +/* @(#)e_j1.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_j1.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_j1.c,v 1.12 2007/08/20 16:01:38 drochner Exp $ */ -/* j1(x), y1(x) +/* __ieee754_j1(x), __ieee754_y1(x) * Bessel function of the first and second kinds of order zero. * Method -- j1(x): * 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ... @@ -32,16 +32,16 @@ * (To avoid cancellation, use * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) * to compute the worse one.) - * + * * 3 Special cases * j1(nan)= nan * j1(0) = 0 * j1(inf) = 0 - * + * * Method -- y1(x): - * 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN + * 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN * 2. For x<2. - * Since + * Since * y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...) * therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function. * We use the following function to approximate y1, @@ -57,8 +57,7 @@ * by method mentioned above. */ -#include -#include +#include "math.h" #include "math_private.h" static double pone(double), qone(double); @@ -82,7 +81,7 @@ s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */ static const double zero = 0.0; double -j1(double x) +__ieee754_j1(double x) { double z, s,c,ss,cc,r,u,v,y; int32_t hx,ix; @@ -139,7 +138,7 @@ static const double V0[5] = { }; double -y1(double x) +__ieee754_y1(double x) { double z, s,c,ss,cc,u,v; int32_t hx,ix,lx; @@ -147,7 +146,7 @@ y1(double x) EXTRACT_WORDS(hx,lx,x); ix = 0x7fffffff&hx; /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */ - if(ix>=0x7ff00000) return one/(x+x*x); + if(ix>=0x7ff00000) return one/(x+x*x); if((ix|lx)==0) return -one/zero; if(hx<0) return zero/zero; if(ix >= 0x40000000) { /* |x| >= 2.0 */ @@ -177,14 +176,14 @@ y1(double x) z = invsqrtpi*(u*ss+v*cc)/sqrt(x); } return z; - } + } if(ix<=0x3c900000) { /* x < 2**-54 */ return(-tpi/x); - } + } z = x*x; u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); - return(x*(u/v) + tpi*(j1(x)*log(x)-one/x)); + return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x)); } /* For x >= 8, the asymptotic expansions of pone is @@ -261,14 +260,11 @@ static const double ps2[5] = { 8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */ }; -static double -pone(double x) + static double pone(double x) { const double *p,*q; double z,r,s; int32_t ix; - - p = q = NULL; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x40200000) {p = pr8; q= ps8;} @@ -280,7 +276,7 @@ pone(double x) s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); return one+ r/s; } - + /* For x >= 8, the asymptotic expansions of qone is * 3/8 s - 105/1024 s^3 - ..., where s = 1/x. @@ -360,14 +356,11 @@ static const double qs2[6] = { -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */ }; -static double -qone(double x) + static double qone(double x) { const double *p,*q; double s,r,z; int32_t ix; - - p = q = NULL; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x40200000) {p = qr8; q= qs8;} diff --git a/lib/libm/src/e_j1f.c b/lib/libm/src/e_j1f.c index f5bc513c8c..b06d2a6974 100644 --- a/lib/libm/src/e_j1f.c +++ b/lib/libm/src/e_j1f.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: e_j1f.c,v 1.11 2007/08/20 16:01:38 drochner Exp $ + * $FreeBSD: head/lib/msun/src/e_j1f.c 176451 2008-02-22 02:30:36Z das $ */ -#include -#include +#include "math.h" #include "math_private.h" static float ponef(float), qonef(float); @@ -40,7 +39,7 @@ s05 = 1.2354227016e-11; /* 0x2d59567e */ static const float zero = 0.0; float -j1f(float x) +__ieee754_j1f(float x) { float z, s,c,ss,cc,r,u,v,y; int32_t hx,ix; @@ -63,11 +62,8 @@ 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) */ -#ifdef DEAD_CODE if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y); - else -#endif - { + else { u = ponef(y); v = qonef(y); z = invsqrtpi*(u*cc-v*ss)/sqrtf(y); } @@ -100,7 +96,7 @@ static const float V0[5] = { }; float -y1f(float x) +__ieee754_y1f(float x) { float z, s,c,ss,cc,u,v; int32_t hx,ix; @@ -145,7 +141,7 @@ y1f(float x) z = x*x; u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); - return(x*(u/v) + tpi*(j1f(x)*logf(x)-one/x)); + return(x*(u/v) + tpi*(__ieee754_j1f(x)*__ieee754_logf(x)-one/x)); } /* For x >= 8, the asymptotic expansions of pone is @@ -222,14 +218,11 @@ static const float ps2[5] = { 8.3646392822e+00, /* 0x4105d590 */ }; -static float -ponef(float x) + static float ponef(float x) { const float *p,*q; float z,r,s; int32_t ix; - - p = q = NULL; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; if(ix>=0x41000000) {p = pr8; q= ps8;} @@ -287,7 +280,7 @@ static const float qs5[6] = { -4.7191835938e+03, /* 0xc5937978 */ }; -static const float qr3[6] = { /* for x in [4.5454,2.8570]=1/[0.22001,0.3499] */ +static const float qr3[6] = { -5.0783124372e-09, /* 0xb1ae7d4f */ -1.0253783315e-01, /* 0xbdd1ff5b */ -4.6101160049e+00, /* 0xc0938612 */ @@ -321,23 +314,16 @@ static const float qs2[6] = { -4.9594988823e+00, /* 0xc09eb437 */ }; -static float -qonef(float x) + static float qonef(float x) { const float *p,*q; float s,r,z; int32_t ix; - - p = q = NULL; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; - /* [inf, 8] (8 41000000) */ - if(ix>=0x41000000) {p = qr8; q= qs8;} - /* [8, 4.5454] (4.5454 409173eb) */ - else if(ix>=0x409173eb){p = qr5; q= qs5;} - /* [4.5454, 2.8570] (2.8570 4036d917) */ - else if(ix>=0x4036d917){p = qr3; q= qs3;} - /* [2.8570, 2] (2 40000000) */ + if(ix>=0x40200000) {p = qr8; q= qs8;} + else if(ix>=0x40f71c58){p = qr5; q= qs5;} + else if(ix>=0x4036db68){p = qr3; q= qs3;} else if(ix>=0x40000000){p = qr2; q= qs2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); diff --git a/lib/libm/src/e_jn.c b/lib/libm/src/e_jn.c index b30e17ad61..196652a88e 100644 --- a/lib/libm/src/e_jn.c +++ b/lib/libm/src/e_jn.c @@ -1,22 +1,22 @@ -/* @(#)e_jn.c 5.1 93/09/24 */ + +/* @(#)e_jn.c 1.4 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_jn.c 215237 2010-11-13 10:54:10Z uqs $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_jn.c,v 1.14 2010/11/29 15:10:06 drochner Exp $ */ /* - * jn(n, x), yn(n, x) + * __ieee754_jn(n, x), __ieee754_yn(n, x) * floating point Bessel's function of the 1st and 2nd kind * of order n - * + * * Special cases: * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. @@ -35,10 +35,10 @@ * yn(n,x) is similar in all respects, except * that forward recursion is used for all * values of n>1. - * + * */ -#include +#include "math.h" #include "math_private.h" static const double @@ -49,13 +49,12 @@ one = 1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */ static const double zero = 0.00000000000000000000e+00; double -jn(int n, double x) +__ieee754_jn(int n, double x) { int32_t i,hx,ix,lx, sgn; double a, b, temp, di; double z, w; - temp = 0; /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x) * Thus, J(-n,x) = J(n,-x) */ @@ -63,24 +62,24 @@ jn(int n, double x) ix = 0x7fffffff&hx; /* if J(n,NaN) is NaN */ if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x; - if(n<0){ + if(n<0){ n = -n; x = -x; hx ^= 0x80000000; } - if(n==0) return(j0(x)); - if(n==1) return(j1(x)); + if(n==0) return(__ieee754_j0(x)); + if(n==1) return(__ieee754_j1(x)); sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */ x = fabs(x); if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */ b = zero; - else if((double)n<=x) { + else if((double)n<=x) { /* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ if(ix>=0x52D00000) { /* x > 2**302 */ - /* (x >> n**2) + /* (x >> n**2) * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Let s=sin(x), c=cos(x), + * Let s=sin(x), c=cos(x), * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then * * n sin(xn)*sqt2 cos(xn)*sqt2 @@ -97,9 +96,9 @@ jn(int n, double x) case 3: temp = cos(x)-sin(x); break; } b = invsqrtpi*temp/sqrt(x); - } else { - a = j0(x); - b = j1(x); + } else { + a = __ieee754_j0(x); + b = __ieee754_j1(x); for(i=1;i33) /* underflow */ @@ -123,14 +122,14 @@ jn(int n, double x) } } else { /* use backward recurrence */ - /* x x^2 x^2 + /* x x^2 x^2 * J(n,x)/J(n-1,x) = ---- ------ ------ ..... * 2n - 2(n+1) - 2(n+2) * - * 1 1 1 + * 1 1 1 * (for large x) = ---- ------ ------ ..... * 2n 2(n+1) 2(n+2) - * -- - ------ - ------ - + * -- - ------ - ------ - * x x x * * Let w = 2n/x and h=2/x, then the above quotient @@ -146,9 +145,9 @@ jn(int n, double x) * To determine how many terms needed, let * Q(0) = w, Q(1) = w(w+h) - 1, * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), - * When Q(k) > 1e4 good for single - * When Q(k) > 1e9 good for double - * When Q(k) > 1e17 good for quadruple + * When Q(k) > 1e4 good for single + * When Q(k) > 1e9 good for double + * When Q(k) > 1e17 good for quadruple */ /* determine k */ double t,v; @@ -175,7 +174,7 @@ jn(int n, double x) */ tmp = n; v = two/x; - tmp = tmp*log(fabs(v*tmp)); + tmp = tmp*__ieee754_log(fabs(v*tmp)); if(tmp<7.09782712893383973096e+02) { for(i=n-1,di=(double)(i+i);i>0;i--){ temp = b; @@ -199,25 +198,24 @@ jn(int n, double x) } } } - z = j0(x); - w = j1(x); + z = __ieee754_j0(x); + w = __ieee754_j1(x); if (fabs(z) >= fabs(w)) - b = (t*z/b); + b = (t*z/b); else - b = (t*w/a); + b = (t*w/a); } } if(sgn==1) return -b; else return b; } double -yn(int n, double x) +__ieee754_yn(int n, double x) { int32_t i,hx,ix,lx; int32_t sign; double a, b, temp; - temp = 0; EXTRACT_WORDS(hx,lx,x); ix = 0x7fffffff&hx; /* if Y(n,NaN) is NaN */ @@ -229,14 +227,14 @@ yn(int n, double x) n = -n; sign = 1 - ((n&1)<<1); } - if(n==0) return(y0(x)); - if(n==1) return(sign*y1(x)); + if(n==0) return(__ieee754_y0(x)); + if(n==1) return(sign*__ieee754_y1(x)); if(ix==0x7ff00000) return zero; if(ix>=0x52D00000) { /* x > 2**302 */ - /* (x >> n**2) + /* (x >> n**2) * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Let s=sin(x), c=cos(x), + * Let s=sin(x), c=cos(x), * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then * * n sin(xn)*sqt2 cos(xn)*sqt2 @@ -255,8 +253,8 @@ yn(int n, double x) b = invsqrtpi*temp/sqrt(x); } else { u_int32_t high; - a = y0(x); - b = y1(x); + a = __ieee754_y0(x); + b = __ieee754_y1(x); /* quit if b is -inf */ GET_HIGH_WORD(high,b); for(i=1;i +#include "math.h" #include "math_private.h" static const float -#if 0 -invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */ -#endif two = 2.0000000000e+00, /* 0x40000000 */ one = 1.0000000000e+00; /* 0x3F800000 */ static const float zero = 0.0000000000e+00; float -jnf(int n, float x) +__ieee754_jnf(int n, float x) { int32_t i,hx,ix, sgn; float a, b, temp, di; @@ -46,16 +43,16 @@ jnf(int n, float x) x = -x; hx ^= 0x80000000; } - if(n==0) return(j0f(x)); - if(n==1) return(j1f(x)); + if(n==0) return(__ieee754_j0f(x)); + if(n==1) return(__ieee754_j1f(x)); sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */ x = fabsf(x); if(ix==0||ix>=0x7f800000) /* if x is 0 or inf */ b = zero; else if((float)n<=x) { /* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ - a = j0f(x); - b = j1f(x); + a = __ieee754_j0f(x); + b = __ieee754_j1f(x); for(i=1;i0;i--){ temp = b; @@ -154,19 +151,19 @@ jnf(int n, float x) } } } - z = j0f(x); - w = j1f(x); + z = __ieee754_j0f(x); + w = __ieee754_j1f(x); if (fabsf(z) >= fabsf(w)) - b = (t*z/b); + b = (t*z/b); else - b = (t*w/a); + b = (t*w/a); } } if(sgn==1) return -b; else return b; } float -ynf(int n, float x) +__ieee754_ynf(int n, float x) { int32_t i,hx,ix,ib; int32_t sign; @@ -183,15 +180,15 @@ ynf(int n, float x) n = -n; sign = 1 - ((n&1)<<1); } - if(n==0) return(y0f(x)); - if(n==1) return(sign*y1f(x)); + if(n==0) return(__ieee754_y0f(x)); + if(n==1) return(sign*__ieee754_y1f(x)); if(ix==0x7f800000) return zero; - a = y0f(x); - b = y1f(x); + a = __ieee754_y0f(x); + b = __ieee754_y1f(x); /* quit if b is -inf */ GET_FLOAT_WORD(ib,b); - for(i=1;i +#include "math.h" #include "math_private.h" static const double @@ -154,8 +154,7 @@ w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */ static const double zero= 0.00000000000000000000e+00; -static -double sin_pi(double x) + static double sin_pi(double x) { double y,z; int n,ix; @@ -188,9 +187,9 @@ double sin_pi(double x) } switch (n) { case 0: y = __kernel_sin(pi*y,zero,0); break; - case 1: + case 1: case 2: y = __kernel_cos(pi*(0.5-y),zero); break; - case 3: + case 3: case 4: y = __kernel_sin(pi*(one-y),zero,0); break; case 5: case 6: y = -__kernel_cos(pi*(y-1.5),zero); break; @@ -201,7 +200,7 @@ double sin_pi(double x) double -lgamma_r(double x, int *signgamp) +__ieee754_lgamma_r(double x, int *signgamp) { double t,y,z,nadj,p,p1,p2,p3,q,r,w; int32_t hx; @@ -217,15 +216,15 @@ lgamma_r(double x, int *signgamp) if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */ if(hx<0) { *signgamp = -1; - return -log(-x); - } else return -log(x); + return -__ieee754_log(-x); + } else return -__ieee754_log(x); } if(hx<0) { if(ix>=0x43300000) /* |x|>=2**52, must be -integer */ return one/zero; t = sin_pi(x); if(t==zero) return one/zero; /* -integer */ - nadj = log(pi/fabs(t*x)); + nadj = __ieee754_log(pi/fabs(t*x)); if(t=0x3FE76944) {y = one-x; i= 0;} else if(ix>=0x3FCDA661) {y= x-(tc-one); i=1;} else {y = x; i=2;} @@ -260,7 +259,7 @@ lgamma_r(double x, int *signgamp) p3 = t2+w*(t5+w*(t8+w*(t11+w*t14))); p = z*p1-(tt-w*(p2+y*p3)); r += (tf + p); break; - case 2: + case 2: p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5))))); p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5)))); r += (-0.5*y + p1/p2); @@ -279,18 +278,18 @@ lgamma_r(double x, int *signgamp) case 5: z *= (y+4.0); /* FALLTHRU */ case 4: z *= (y+3.0); /* FALLTHRU */ case 3: z *= (y+2.0); /* FALLTHRU */ - r += log(z); break; + r += __ieee754_log(z); break; } /* 8.0 <= x < 2**58 */ } else if (ix < 0x43900000) { - t = log(x); + t = __ieee754_log(x); z = one/x; y = z*z; w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); r = (x-half)*(t-one)+w; - } else + } else /* 2**58 <= x <= inf */ - r = x*(log(x)-one); + r = x*(__ieee754_log(x)-one); if(hx<0) r = nadj - r; return r; } diff --git a/lib/libm/src/w_gammaf_r.c b/lib/libm/src/e_lgammaf.c similarity index 59% rename from lib/libm/src/w_gammaf_r.c rename to lib/libm/src/e_lgammaf.c index 2a70a8153b..e082f57f07 100644 --- a/lib/libm/src/w_gammaf_r.c +++ b/lib/libm/src/e_lgammaf.c @@ -1,4 +1,4 @@ -/* w_gammaf_r.c -- float version of w_gamma_r.c. +/* e_lgammaf.c -- float version of e_lgamma.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. */ @@ -12,19 +12,22 @@ * is preserved. * ==================================================== * - * $NetBSD: w_gammaf_r.c,v 1.8 2002/05/26 22:02:01 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_gammaf_r.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_lgammaf.c 176451 2008-02-22 02:30:36Z das $ */ -/* - * wrapper float gammaf_r(float x, int *signgamp) +/* __ieee754_lgammaf(x) + * Return the logarithm of the Gamma function of x. + * + * Method: call __ieee754_lgammaf_r */ -#include +#include "math.h" #include "math_private.h" +extern int signgam; + float -gammaf_r(float x, int *signgamp) /* wrapper lgammaf_r */ +__ieee754_lgammaf(float x) { - return lgammaf_r(x,signgamp); + return __ieee754_lgammaf_r(x,&signgam); } diff --git a/lib/libm/src/e_lgammaf_r.c b/lib/libm/src/e_lgammaf_r.c index f267c46d85..2f12b407d3 100644 --- a/lib/libm/src/e_lgammaf_r.c +++ b/lib/libm/src/e_lgammaf_r.c @@ -12,10 +12,10 @@ * is preserved. * ==================================================== * - * FreeBSD SVN: 226380 (2011-10-15) + * $FreeBSD: head/lib/msun/src/e_lgammaf_r.c 226380 2011-10-15 07:00:28Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float @@ -88,8 +88,7 @@ w6 = -1.6309292987e-03; /* 0xbad5c4e8 */ static const float zero= 0.0000000000e+00; -static float -sin_pif(float x) + static float sin_pif(float x) { float y,z; int n,ix; @@ -135,7 +134,7 @@ sin_pif(float x) float -lgammaf_r(float x, int *signgamp) +__ieee754_lgammaf_r(float x, int *signgamp) { float t,y,z,nadj,p,p1,p2,p3,q,r,w; int32_t hx; @@ -151,15 +150,15 @@ lgammaf_r(float x, int *signgamp) if(ix<0x35000000) { /* |x|<2**-21, return -log(|x|) */ if(hx<0) { *signgamp = -1; - return -logf(-x); - } else return -logf(x); + return -__ieee754_logf(-x); + } else return -__ieee754_logf(x); } if(hx<0) { if(ix>=0x4b000000) /* |x|>=2**23, must be -integer */ return one/zero; t = sin_pif(x); if(t==zero) return one/zero; /* -integer */ - nadj = logf(pi/fabsf(t*x)); + nadj = __ieee754_logf(pi/fabsf(t*x)); if(t=0x3f3b4a20) {y = one-x; i= 0;} else if(ix>=0x3e6d3308) {y= x-(tc-one); i=1;} else {y = x; i=2;} @@ -213,18 +212,18 @@ lgammaf_r(float x, int *signgamp) case 5: z *= (y+(float)4.0); /* FALLTHRU */ case 4: z *= (y+(float)3.0); /* FALLTHRU */ case 3: z *= (y+(float)2.0); /* FALLTHRU */ - r += logf(z); break; + r += __ieee754_logf(z); break; } /* 8.0 <= x < 2**58 */ } else if (ix < 0x5c800000) { - t = logf(x); + t = __ieee754_logf(x); z = one/x; y = z*z; w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); r = (x-half)*(t-one)+w; } else /* 2**58 <= x <= inf */ - r = x*(logf(x)-one); + r = x*(__ieee754_logf(x)-one); if(hx<0) r = nadj - r; return r; } diff --git a/lib/libm/src/e_log.c b/lib/libm/src/e_log.c index 917b2e12ca..dd875c1065 100644 --- a/lib/libm/src/e_log.c +++ b/lib/libm/src/e_log.c @@ -1,32 +1,31 @@ -/* @(#)e_log.c 5.1 93/09/24 */ + +/* @(#)e_log.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_log.c 251024 2013-05-27 08:50:10Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_log.c,v 1.12 2002/05/26 22:01:51 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_log.c,v 1.2 2007/06/24 05:17:51 pavalos Exp $ */ -/* log(x) - * Return the logrithm of x +/* __ieee754_log(x) + * Return the logarithm of x * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), + * 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 + * 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 @@ -34,22 +33,22 @@ * (the values of Lg1 to Lg7 are listed in the program) * and * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 + * | 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). + * + * 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: + * 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(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. * @@ -58,13 +57,13 @@ * 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 + * 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 +#include "math.h" #include "math_private.h" static const double @@ -80,9 +79,10 @@ 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 -log(double x) +__ieee754_log(double x) { double hfsq,f,s,z,R,w,t1,t2,dk; int32_t k,hx,i,j; @@ -92,12 +92,12 @@ log(double x) k=0; if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ + 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; k += (hx>>20)-1023; hx &= 0x000fffff; @@ -106,21 +106,26 @@ log(double x) k += (i>>20); f = x-1.0; 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;} + 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);} } - s = f/(2.0+f); + s = f/(2.0+f); dk = (double)k; z = s*s; i = hx-0x6147a; w = z*z; j = 0x6b851-hx; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); + t1= w*(Lg2+w*(Lg4+w*Lg6)); + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); i |= j; R = t2+t1; if(i>0) { diff --git a/lib/libm/src/e_log10.c b/lib/libm/src/e_log10.c index 610b39258e..d744fb5b53 100644 --- a/lib/libm/src/e_log10.c +++ b/lib/libm/src/e_log10.c @@ -1,85 +1,86 @@ -/* @(#)e_log10.c 5.1 93/09/24 */ + +/* @(#)e_log10.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_log10.c 251024 2013-05-27 08:50:10Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_log10.c,v 1.12 2002/05/26 22:01:51 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_log10.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* 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. +/* + * Return the base 10 logarithm of x. See e_log.c and k_log.h for most + * comments. * - * 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. + * log10(x) = (f - 0.5*f*f + k_log1p(f)) / ln10 + k * log10(2) + * in not-quite-routine extra precision. */ -#include +#include "math.h" #include "math_private.h" +#include "k_log.h" static const double two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ +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 -log10(double x) +__ieee754_log10(double x) { - double y,z; + double f,hfsq,hi,lo,r,val_hi,val_lo,w,y,y2; int32_t i,k,hx; u_int32_t lx; EXTRACT_WORDS(hx,lx,x); - k=0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx&0x7fffffff)|lx)==0) - return -two54/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 54; x *= two54; /* subnormal number, scale up x */ + k=0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx&0x7fffffff)|lx)==0) + return -two54/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; - 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*log(x); - return z+y*log10_2hi; + 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; } diff --git a/lib/libm/src/e_log10f.c b/lib/libm/src/e_log10f.c index b5689d76be..34d172e9a7 100644 --- a/lib/libm/src/e_log10f.c +++ b/lib/libm/src/e_log10f.c @@ -1,7 +1,3 @@ -/* 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. @@ -11,44 +7,64 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_log10f.c,v 1.8 2002/05/26 22:01:51 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_log10f.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_log10f.c 251024 2013-05-27 08:50:10Z das $ */ -#include +/* + * 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 */ -ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */ +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 -log10f(float x) +__ieee754_log10f(float x) { - float y,z; + float f,hfsq,hi,lo,r,y; int32_t i,k,hx; GET_FLOAT_WORD(hx,x); - k=0; - if (hx < 0x00800000) { /* x < 2**-126 */ - if ((hx&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ - if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ - k -= 25; x *= two25; /* subnormal number, scale up x */ + k=0; + if (hx < 0x00800000) { /* x < 2**-126 */ + if ((hx&0x7fffffff)==0) + return -two25/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; - 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*logf(x); - return z+y*log10_2hi; + 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/lib/libm/src/e_log2.c b/lib/libm/src/e_log2.c index 9656c8d2f0..a7388e5ce7 100644 --- a/lib/libm/src/e_log2.c +++ b/lib/libm/src/e_log2.c @@ -1,40 +1,44 @@ -/* @(#)e_log.c 1.3 95/01/18 */ +/* @(#)e_log10.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_log2.c 251024 2013-05-27 08:50:10Z 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== + */ + +/* + * Return the base 2 logarithm of x. See e_log.c and k_log.h for most + * comments. * - * $NetBSD: e_log2.c,v 1.1 2005/07/21 12:55:58 christos Exp $ - * $DragonFly: src/lib/libm/src/e_log2.c,v 1.1 2007/06/16 22:26:53 pavalos Exp $ + * 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 +#include "math.h" #include "math_private.h" +#include "k_log.h" static const double -ln2 = 0.6931471805599452862268, -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ -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 */ +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 -log2(double x) +__ieee754_log2(double x) { - double hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,hx,i,j; + 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); @@ -42,37 +46,64 @@ log2(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); } 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); - f = x-1.0; - dk = (double)k; - if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */ - if (f==zero) - return (dk); - R = f*f*(0.5-0.33333333333333333*f); - return (dk-(R-f)/ln2); - } - s = f/(2.0+f); - z = s*s; - i = hx-0x6147a; - w = z*z; - j = 0x6b851-hx; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2+t1; - if(i>0) { - hfsq=0.5*f*f; - return (dk-(hfsq-s*(hfsq+R)-f)/ln2); - } else - return (dk-((s*(f-R))-f)/ln2); + y = (double)k; + f = x - 1.0; + hfsq = 0.5*f*f; + r = k_log1p(f); + + /* + * f-hfsq must (for args near 1) be evaluated in extra precision + * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2). + * This is fairly efficient since f-hfsq only depends on f, so can + * be evaluated in parallel with R. Not combining hfsq with R also + * keeps R small (though not as small as a true `lo' term would be), + * so that extra precision is not needed for terms involving R. + * + * Compiler bugs involving extra precision used to break Dekker's + * theorem for spitting f-hfsq as hi+lo, unless double_t was used + * or the multi-precision calculations were avoided when double_t + * has extra precision. These problems are now automatically + * avoided as a side effect of the optimization of combining the + * Dekker splitting step with the clear-low-bits step. + * + * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra + * precision to avoid a very large cancellation when x is very near + * these values. Unlike the above cancellations, this problem is + * specific to base 2. It is strange that adding +-1 is so much + * harder than adding +-ln2 or +-log10_2. + * + * This uses Dekker's theorem to normalize y+val_hi, so the + * compiler bugs are back in some configurations, sigh. And I + * don't want to used double_t to avoid them, since that gives a + * pessimization and the support for avoiding the pessimization + * is not yet available. + * + * The multi-precision calculations for the multiplications are + * routine. + */ + hi = f - hfsq; + SET_LOW_WORD(hi,0); + lo = (f - hi) - hfsq + r; + val_hi = hi*ivln2hi; + val_lo = (lo+hi)*ivln2lo + lo*ivln2hi; + + /* spadd(val_hi, val_lo, y), except for not using double_t: */ + w = y + val_hi; + val_lo += (y - w) + val_hi; + val_hi = w; + + return val_lo + val_hi; } diff --git a/lib/libm/src/e_log2f.c b/lib/libm/src/e_log2f.c index 2a6b5a2234..dcc1cf72ab 100644 --- a/lib/libm/src/e_log2f.c +++ b/lib/libm/src/e_log2f.c @@ -1,7 +1,3 @@ -/* e_logf.c -- float version of e_log.c. - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ - /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -11,69 +7,74 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_log2f.c,v 1.1 2005/07/21 12:55:58 christos Exp $ - * $DragonFly: src/lib/libm/src/e_log2f.c,v 1.1 2007/06/16 22:26:53 pavalos Exp $ + * $FreeBSD: head/lib/msun/src/e_log2f.c 251024 2013-05-27 08:50:10Z das $ */ -#include +/* + * 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 -ln2 = 0.6931471805599452862268, -two25 = 3.355443200e+07, /* 0x4c000000 */ -Lg1 = 6.6666668653e-01, /* 3F2AAAAB */ -Lg2 = 4.0000000596e-01, /* 3ECCCCCD */ -Lg3 = 2.8571429849e-01, /* 3E924925 */ -Lg4 = 2.2222198546e-01, /* 3E638E29 */ -Lg5 = 1.8183572590e-01, /* 3E3A3325 */ -Lg6 = 1.5313838422e-01, /* 3E1CD04F */ -Lg7 = 1.4798198640e-01; /* 3E178897 */ +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 -log2f(float x) +__ieee754_log2f(float x) { - float hfsq,f,s,z,R,w,t1,t2,dk; - int32_t k,ix,i,j; + float f,hfsq,hi,lo,r,y; + int32_t i,k,hx; - GET_FLOAT_WORD(ix,x); + GET_FLOAT_WORD(hx,x); k=0; - if (ix < 0x00800000) { /* x < 2**-126 */ - if ((ix&0x7fffffff)==0) - return -two25/zero; /* log(+-0)=-inf */ - if (ix<0) return (x-x)/zero; /* log(-#) = NaN */ + 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(ix,x); + GET_FLOAT_WORD(hx,x); } - if (ix >= 0x7f800000) return x+x; - k += (ix>>23)-127; - ix &= 0x007fffff; - i = (ix+(0x95f64<<3))&0x800000; - SET_FLOAT_WORD(x,ix|(i^0x3f800000)); /* normalize x or x/2 */ + 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); - dk = (float)k; - f = x-(float)1.0; - if((0x007fffff&(15+ix))<16) { /* |f| < 2**-20 */ - if (f==zero) - return (dk); - R = f*f*((float)0.5-(float)0.33333333333333333*f); - return (dk-(R-f)/ln2); - } - s = f/((float)2.0+f); - z = s*s; - i = ix-(0x6147a<<3); - w = z*z; - j = (0x6b851<<3)-ix; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; - R = t2+t1; - if(i>0) { - hfsq=(float)0.5*f*f; - return (dk-(hfsq-s*(hfsq+R)-f)/ln2); - } else - return (dk-((s*(f-R))-f)/ln2); + 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/lib/libm/src/e_logf.c b/lib/libm/src/e_logf.c index 1302feae17..b67b7d2d99 100644 --- a/lib/libm/src/e_logf.c +++ b/lib/libm/src/e_logf.c @@ -11,30 +11,27 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_logf.c,v 1.8 2002/05/26 22:01:51 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_logf.c,v 1.2 2007/06/24 05:17:51 pavalos Exp $ + * $FreeBSD: head/lib/msun/src/e_logf.c 251024 2013-05-27 08:50:10Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ two25 = 3.355443200e+07, /* 0x4c000000 */ -Lg1 = 6.6666668653e-01, /* 3F2AAAAB */ -Lg2 = 4.0000000596e-01, /* 3ECCCCCD */ -Lg3 = 2.8571429849e-01, /* 3E924925 */ -Lg4 = 2.2222198546e-01, /* 3E638E29 */ -Lg5 = 1.8183572590e-01, /* 3E3A3325 */ -Lg6 = 1.5313838422e-01, /* 3E1CD04F */ -Lg7 = 1.4798198640e-01; /* 3E178897 */ +/* |(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 const float zero = 0.0; +static volatile float vzero = 0.0; float -logf(float x) +__ieee754_logf(float x) { float hfsq,f,s,z,R,w,t1,t2,dk; int32_t k,ix,i,j; @@ -44,7 +41,7 @@ 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); @@ -57,8 +54,13 @@ logf(float x) k += (i>>23); f = x-(float)1.0; 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;} + 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; @@ -70,8 +72,8 @@ logf(float x) i = ix-(0x6147a<<3); w = z*z; j = (0x6b851<<3)-ix; - t1= w*(Lg2+w*(Lg4+w*Lg6)); - t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); + t1= w*(Lg2+w*Lg4); + t2= z*(Lg1+w*Lg3); i |= j; R = t2+t1; if(i>0) { diff --git a/lib/libm/src/e_pow.c b/lib/libm/src/e_pow.c index 667a1777b3..2e6189c00b 100644 --- a/lib/libm/src/e_pow.c +++ b/lib/libm/src/e_pow.c @@ -1,25 +1,23 @@ -/* @(#)e_pow.c 5.1 93/09/24 */ +/* @(#)e_pow.c 1.5 04/04/22 SMI */ +/* $FreeBSD: head/lib/msun/src/e_pow.c 226595 2011-10-21 06:26:07Z das $ */ /* * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright (C) 2004 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_pow.c,v 1.16 2010/04/23 19:17:07 drochner Exp $ */ -/* pow(x,y) return x**y +/* __ieee754_pow(x,y) return x**y * * n * Method: Let x = 2 * (1+f) * 1. Compute and return log2(x) in two pieces: * log2(x) = w1 + w2, * where w1 has 53-24 = 29 bit trailing zeros. - * 2. Perform y*log2(x) = n+y' by simulating multi-precision + * 2. Perform y*log2(x) = n+y' by simulating muti-precision * arithmetic, where |y'|<=0.5. * 3. Return x**y = 2**n*exp(y'*log2) * @@ -47,17 +45,17 @@ * Accuracy: * pow(x,y) returns x**y nearly rounded. In particular * pow(integer,integer) - * always returns the correct integer provided it is + * always returns the correct integer provided it is * representable. * * 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 + * 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 +#include "math.h" #include "math_private.h" static const double @@ -94,10 +92,10 @@ ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ double -pow(double x, double y) +__ieee754_pow(double x, double y) { double z,ax,z_h,z_l,p_h,p_l; - double yy1,t1,t2,r,s,t,u,v,w; + double y1,t1,t2,r,s,t,u,v,w; int32_t i,j,k,yisint,n; int32_t hx,hy,ix,iy; u_int32_t lx,ly; @@ -107,12 +105,15 @@ pow(double x, double y) ix = hx&0x7fffffff; iy = hy&0x7fffffff; /* y==zero: x**0 = 1 */ - if((iy|ly)==0) return one; + if((iy|ly)==0) return one; + + /* x==1: 1**y = 1, even if y is NaN */ + if (hx==0x3ff00000 && lx == 0) return one; - /* +-NaN return x+y */ + /* 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; + iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) + return (x+0.0)+(y+0.0); /* determine if y is an odd int when x < 0 * yisint = 0 ... y is not an integer @@ -120,37 +121,37 @@ pow(double x, double y) * yisint = 2 ... y is an even int */ yisint = 0; - if(hx<0) { + if(hx<0) { if(iy>=0x43400000) yisint = 2; /* even integer y */ else if(iy>=0x3ff00000) { k = (iy>>20)-0x3ff; /* exponent */ if(k>20) { j = ly>>(52-k); - if((uint32_t)(j<<(52-k))==ly) yisint = 2-(j&1); + if((j<<(52-k))==ly) yisint = 2-(j&1); } else if(ly==0) { j = iy>>(20-k); if((j<<(20-k))==iy) yisint = 2-(j&1); } - } - } + } + } /* special value of y */ - if(ly==0) { + 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 */ return (hy<0)?-y: zero; - } + } if(iy==0x3ff00000) { /* y is +-1 */ if(hy<0) return one/x; else return x; } if(hy==0x40000000) return x*x; /* y is 2 */ if(hy==0x3fe00000) { /* y is 0.5 */ if(hx>=0) /* x >= +0 */ - return sqrt(x); + return sqrt(x); } } @@ -163,14 +164,18 @@ pow(double x, double y) if(hx<0) { if(((ix-0x3ff00000)|yisint)==0) { z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if(yisint==1) + } else if(yisint==1) z = -z; /* (x<0)**odd = -(|x|**odd) */ } return z; } } - + + /* CYGNUS LOCAL + fdlibm-5.3 fix: This used to be n = (hx>>31)+1; + but ANSI C says a right shift of a signed negative quantity is + implementation defined. */ + n = ((u_int32_t)hx>>31)-1; /* (x<0)**(non-int) is NaN */ if((n|yisint)==0) return (x-x)/(x-x); @@ -187,7 +192,7 @@ pow(double x, double y) /* over/underflow if x is not close to one */ if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny; if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute + /* now |1-x| is tiny <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 */ t = ax-one; /* t has 20 trailing zeros */ w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); @@ -246,11 +251,11 @@ pow(double x, double y) t2 = z_l-(((t1-t)-dp_h[k])-z_h); } - /* split up y into yy1+y2 and compute (yy1+y2)*(t1+t2) */ - yy1 = y; - SET_LOW_WORD(yy1,0); - p_l = (y-yy1)*t1+y*t2; - p_h = yy1*t1; + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + y1 = y; + SET_LOW_WORD(y1,0); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; z = p_l+p_h; EXTRACT_WORDS(j,i,z); if (j>=0x40900000) { /* z >= 1024 */ @@ -280,7 +285,7 @@ pow(double x, double y) n = ((n&0x000fffff)|0x00100000)>>(20-k); if(j<0) n = -n; p_h -= t; - } + } t = p_l+p_h; SET_LOW_WORD(t,0); u = t*lg2_h; diff --git a/lib/libm/src/e_powf.c b/lib/libm/src/e_powf.c index 983c9204e6..5507c8af39 100644 --- a/lib/libm/src/e_powf.c +++ b/lib/libm/src/e_powf.c @@ -12,14 +12,12 @@ * is preserved. * ==================================================== * - * $NetBSD: e_powf.c,v 1.15 2010/04/23 19:17:07 drochner Exp $ + * $FreeBSD: head/lib/msun/src/e_powf.c 226595 2011-10-21 06:26:07Z das $ */ -#include +#include "math.h" #include "math_private.h" -static const float huge = 1.0e+30, tiny = 1.0e-30; - static const float bp[] = {1.0, 1.5,}, dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */ @@ -28,6 +26,8 @@ zero = 0.0, one = 1.0, two = 2.0, two24 = 16777216.0, /* 0x4b800000 */ +huge = 1.0e30, +tiny = 1.0e-30, /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ L1 = 6.0000002384e-01, /* 0x3f19999a */ L2 = 4.2857143283e-01, /* 0x3edb6db7 */ @@ -45,17 +45,17 @@ 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*/ float -powf(float x, float y) +__ieee754_powf(float x, float y) { float z,ax,z_h,z_l,p_h,p_l; - float yy1,t1,t2,r,s,t,u,v,w; + float y1,t1,t2,r,s,sn,t,u,v,w; int32_t i,j,k,yisint,n; int32_t hx,hy,ix,iy,is; @@ -66,10 +66,13 @@ 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 @@ -89,7 +92,7 @@ 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 */ @@ -101,7 +104,7 @@ powf(float x, float y) if(hy==0x40000000) return x*x; /* y is 2 */ if(hy==0x3f000000) { /* y is 0.5 */ if(hx>=0) /* x >= +0 */ - return sqrtf(x); + return __ieee754_sqrtf(x); } ax = fabsf(x); @@ -118,17 +121,22 @@ powf(float x, float y) return z; } + n = ((u_int32_t)hx>>31)-1; + /* (x<0)**(non-int) is NaN */ - if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); + if((n|yisint)==0) return (x-x)/(x-x); + + sn = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if((n|(yisint-1))==0) sn = -one;/* (-ve)**(odd int) */ /* |y| is huge */ if(iy>0x4d000000) { /* if |y| > 2**27 */ /* over/underflow if x is not close to one */ - if(ix<0x3f7ffff8) return (hy<0)? huge*huge:tiny*tiny; - if(ix>0x3f800007) return (hy>0)? huge*huge:tiny*tiny; + if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny; + if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny; /* now |1-x| is tiny <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax-one; /* t has 20 trailing zeros */ + t = ax-1; /* t has 20 trailing zeros */ w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25)); u = ivln2_h*t; /* ivln2_h has 16 sig. bits */ v = t*ivln2_l-w*ivln2; @@ -159,7 +167,8 @@ powf(float x, float y) GET_FLOAT_WORD(is,s_h); SET_FLOAT_WORD(s_h,is&0xfffff000); /* t_h=ax+bp[k] High */ - SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21)); + is = ((ix>>1)&0xfffff000)|0x20000000; + SET_FLOAT_WORD(t_h,is+0x00400000+(k<<21)); t_l = ax - (t_h-bp[k]); s_l = v*((u-s_h*t_h)-s_h*t_l); /* compute log(ax) */ @@ -189,27 +198,23 @@ powf(float x, float y) t2 = z_l-(((t1-t)-dp_h[k])-z_h); } - s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0) - s = -one; /* (-ve)**(odd int) */ - - /* split up y into yy1+y2 and compute (yy1+y2)*(t1+t2) */ + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ GET_FLOAT_WORD(is,y); - SET_FLOAT_WORD(yy1,is&0xfffff000); - p_l = (y-yy1)*t1+y*t2; - p_h = yy1*t1; + SET_FLOAT_WORD(y1,is&0xfffff000); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; z = p_l+p_h; GET_FLOAT_WORD(j,z); if (j>0x43000000) /* if z > 128 */ - return s*huge*huge; /* overflow */ + return sn*huge*huge; /* overflow */ else if (j==0x43000000) { /* if z == 128 */ - if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ - } - else if ((uint32_t)j==0xc3160000){ /* z == -150 */ - if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ + if(p_l+ovt>z-p_h) return sn*huge*huge; /* overflow */ } else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */ - return s*tiny*tiny; /* underflow */ + return sn*tiny*tiny; /* underflow */ + else if (j==0xc3160000){ /* z == -150 */ + if(p_l<=z-p_h) return sn*tiny*tiny; /* underflow */ + } /* * compute 2**(p_h+p_l) */ @@ -226,7 +231,7 @@ powf(float x, float y) } t = p_l+p_h; GET_FLOAT_WORD(is,t); - SET_FLOAT_WORD(t,is&0xfffff000); + SET_FLOAT_WORD(t,is&0xffff8000); u = t*lg2_h; v = (p_l-(t-p_h))*lg2+t*lg2_l; z = u+v; @@ -239,5 +244,5 @@ powf(float x, float y) j += (n<<23); if((j>>23)<=0) z = scalbnf(z,n); /* subnormal output */ else SET_FLOAT_WORD(z,j); - return s*z; + return sn*z; } diff --git a/lib/libm/src/e_rem_pio2.c b/lib/libm/src/e_rem_pio2.c index 866aaad9db..c8584844c3 100644 --- a/lib/libm/src/e_rem_pio2.c +++ b/lib/libm/src/e_rem_pio2.c @@ -1,26 +1,28 @@ /* @(#)e_rem_pio2.c 1.4 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_rem_pio2.c 239195 2012-08-11 15:47:22Z dim $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== * * Optimized by Bruce D. Evans. - * FreeBSD SVN: 223302 (2011-06-19) */ -/* __libm_rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] +/* __ieee754_rem_pio2(x,y) + * + * return the remainder of x rem pi/2 in y[0]+y[1] * use __kernel_rem_pio2() */ -#include +#include + +#include "math.h" #include "math_private.h" /* @@ -44,8 +46,11 @@ pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ -__inline int -__libm_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],ty[2]; @@ -133,22 +138,22 @@ medium: { u_int32_t high; j = ix>>20; - y[0] = r-w; + y[0] = r-w; GET_HIGH_WORD(high,y[0]); i = j-((high>>20)&0x7ff); if(i>16) { /* 2nd iteration needed, good to 118 */ t = r; - w = fn*pio2_2; + w = fn*pio2_2; r = t-w; - w = fn*pio2_2t-((t-r)-w); + w = fn*pio2_2t-((t-r)-w); y[0] = r-w; GET_HIGH_WORD(high,y[0]); i = j-((high>>20)&0x7ff); if(i>49) { /* 3rd iteration need, 151 bits acc */ t = r; /* will cover all possible cases */ - w = fn*pio2_3; + w = fn*pio2_3; r = t-w; - w = fn*pio2_3t-((t-r)-w); + w = fn*pio2_3t-((t-r)-w); y[0] = r-w; } } @@ -156,7 +161,7 @@ medium: y[1] = (r-y[0])-w; return n; } - /* + /* * all other (large) arguments */ if(ix>=0x7ff00000) { /* x is inf or NaN */ diff --git a/lib/libm/src/e_rem_pio2f.c b/lib/libm/src/e_rem_pio2f.c index c653571ebf..1dcdfa080a 100644 --- a/lib/libm/src/e_rem_pio2f.c +++ b/lib/libm/src/e_rem_pio2f.c @@ -12,22 +12,25 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 193368 (2009-06-03) + * + * $FreeBSD: head/lib/msun/src/e_rem_pio2f.c 239195 2012-08-11 15:47:22Z dim $ */ -/* __libm_rem_pio2f(x,y) +/* __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 +#include + +#include "math.h" #include "math_private.h" /* * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 + * pio2_1: first 25 bits of pi/2 * pio2_1t: pi/2 - pio2_1 */ @@ -36,11 +39,11 @@ invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */ pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ -#ifndef INLINE_REM_PIO2F -extern +#ifdef INLINE_REM_PIO2F +static __inline __always_inline #endif -__inline int -__libm_rem_pio2f(float x, double *y) +int +__ieee754_rem_pio2f(float x, double *y) { double w,r,fn; double tx[1],ty[1]; diff --git a/lib/libm/src/e_remainder.c b/lib/libm/src/e_remainder.c deleted file mode 100644 index 9d01ed01ad..0000000000 --- a/lib/libm/src/e_remainder.c +++ /dev/null @@ -1,71 +0,0 @@ -/* @(#)e_remainder.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. - * ==================================================== - * - * $NetBSD: e_remainder.c,v 1.11 2002/05/26 22:01:52 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_remainder.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -/* remainder(x,p) - * Return : - * returns x REM p = x - [x/p]*p as if in infinite - * precise arithmetic, where [x/p] is the (infinite bit) - * integer nearest x/p (in half way case choose the even one). - * Method : - * Based on fmod() return x-[x/p]chopped*p exactlp. - */ - -#include -#include "math_private.h" - -static const double zero = 0.0; - - -double -remainder(double x, double p) -{ - int32_t hx,hp; - u_int32_t sx,lx,lp; - double p_half; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hp,lp,p); - sx = hx&0x80000000; - hp &= 0x7fffffff; - hx &= 0x7fffffff; - - /* purge off exception values */ - if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */ - if((hx>=0x7ff00000)|| /* x not finite */ - ((hp>=0x7ff00000)&& /* p is NaN */ - (((hp-0x7ff00000)|lp)!=0))) - return (x*p)/(x*p); - - - if (hp<=0x7fdfffff) x = fmod(x,p+p); /* now x < 2p */ - if (((hx-hp)|(lx-lp))==0) return zero*x; - x = fabs(x); - p = fabs(p); - if (hp<0x00200000) { - if(x+x>p) { - x-=p; - if(x+x>=p) x -= p; - } - } else { - p_half = 0.5*p; - if(x>p_half) { - x-=p; - if(x>=p_half) x -= p; - } - } - GET_HIGH_WORD(hx,x); - SET_HIGH_WORD(x,hx^sx); - return x; -} diff --git a/lib/libm/src/e_remainderf.c b/lib/libm/src/e_remainderf.c deleted file mode 100644 index d609965eca..0000000000 --- a/lib/libm/src/e_remainderf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* e_remainderf.c -- float version of e_remainder.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. - * ==================================================== - * - * $NetBSD: e_remainderf.c,v 1.7 2002/05/26 22:01:52 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_remainderf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -#include -#include "math_private.h" - -static const float zero = 0.0; - - -float -remainderf(float x, float p) -{ - int32_t hx,hp; - u_int32_t sx; - float p_half; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hp,p); - sx = hx&0x80000000; - hp &= 0x7fffffff; - hx &= 0x7fffffff; - - /* purge off exception values */ - 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); - - - if (hp<=0x7effffff) x = fmodf(x,p+p); /* now x < 2p */ - if ((hx-hp)==0) return zero*x; - x = fabsf(x); - p = fabsf(p); - if (hp<0x01000000) { - if(x+x>p) { - x-=p; - if(x+x>=p) x -= p; - } - } else { - p_half = (float)0.5*p; - if(x>p_half) { - x-=p; - if(x>=p_half) x -= p; - } - } - GET_FLOAT_WORD(hx,x); - SET_FLOAT_WORD(x,hx^sx); - return x; -} diff --git a/lib/libm/src/e_scalb.c b/lib/libm/src/e_scalb.c index 3e7eb4d8d6..5a23526451 100644 --- a/lib/libm/src/e_scalb.c +++ b/lib/libm/src/e_scalb.c @@ -1,32 +1,32 @@ -/* @(#)e_scalb.c 5.1 93/09/24 */ + +/* @(#)e_scalb.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_scalb.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. + * Developed at SunSoft, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_scalb.c,v 1.10 2010/04/23 19:17:07 drochner Exp $ */ /* - * scalb(x, fn) is provide for - * passing various standard test suite. One + * __ieee754_scalb(x, fn) is provide for + * passing various standard test suite. One * should use scalbn() instead. */ -#include +#include "math.h" #include "math_private.h" #ifdef _SCALB_INT double -scalb(double x, int fn) +__ieee754_scalb(double x, int fn) #else double -scalb(double x, double fn) +__ieee754_scalb(double x, double fn) #endif { #ifdef _SCALB_INT diff --git a/lib/libm/src/e_scalbf.c b/lib/libm/src/e_scalbf.c index 68a80ec626..9557e6a867 100644 --- a/lib/libm/src/e_scalbf.c +++ b/lib/libm/src/e_scalbf.c @@ -12,24 +12,24 @@ * is preserved. * ==================================================== * - * $NetBSD: e_scalbf.c,v 1.7 2010/04/23 19:17:07 drochner Exp $ + * $FreeBSD: head/lib/msun/src/e_scalbf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" #ifdef _SCALB_INT float -scalbf(float x, int fn) +__ieee754_scalbf(float x, int fn) #else float -scalbf(float x, float fn) +__ieee754_scalbf(float x, float fn) #endif { #ifdef _SCALB_INT return scalbnf(x,fn); #else - if (isnanf(x)||isnanf(fn)) return x*fn; + if ((isnanf)(x)||(isnanf)(fn)) return x*fn; if (!finitef(fn)) { if(fn>(float)0.0) return x*fn; else return x/(-fn); diff --git a/lib/libm/src/e_sinh.c b/lib/libm/src/e_sinh.c index 4d54278b5c..0e46787bef 100644 --- a/lib/libm/src/e_sinh.c +++ b/lib/libm/src/e_sinh.c @@ -1,28 +1,27 @@ -/* @(#)e_sinh.c 5.1 93/09/24 */ + +/* @(#)e_sinh.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/e_sinh.c 226598 2011-10-21 06:28:47Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_sinh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ -/* sinh(x) - * Method : +/* __ieee754_sinh(x) + * Method : * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 - * 1. Replace x by |x| (sinh(-x) = -sinh(x)). - * 2. + * 1. Replace x by |x| (sinh(-x) = -sinh(x)). + * 2. * E + E/(E+1) * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) * 2 * - * 22 <= x <= lnovft : sinh(x) := exp(x)/2 + * 22 <= x <= lnovft : sinh(x) := exp(x)/2 * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) * ln2ovft < x : sinh(x) := x*shuge (overflow) * @@ -31,24 +30,23 @@ * only sinh(0)=0 is exact for finite x. */ -#include +#include "math.h" #include "math_private.h" static const double one = 1.0, shuge = 1.0e307; double -sinh(double x) +__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); ix = jx&0x7fffffff; /* x is INF or NaN */ - if(ix>=0x7ff00000) return x+x; + if(ix>=0x7ff00000) return x+x; h = 0.5; if (jx<0) h = -h; @@ -62,15 +60,11 @@ sinh(double x) } /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x40862E42) return h*exp(fabs(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 = 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/lib/libm/src/e_sinhf.c b/lib/libm/src/e_sinhf.c index cf33533fa4..ab366e0e90 100644 --- a/lib/libm/src/e_sinhf.c +++ b/lib/libm/src/e_sinhf.c @@ -12,19 +12,18 @@ * is preserved. * ==================================================== * - * $NetBSD: e_sinhf.c,v 1.7 2002/05/26 22:01:52 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_sinhf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/e_sinhf.c 226598 2011-10-21 06:28:47Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float one = 1.0, shuge = 1.0e37; float -sinhf(float x) +__ieee754_sinhf(float x) { - float t,w,h; + float t,h; int32_t ix,jx; GET_FLOAT_WORD(jx,x); @@ -35,24 +34,21 @@ sinhf(float x) h = 0.5; if (jx<0) h = -h; - /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ - if (ix < 0x41b00000) { /* |x|<22 */ - if (ix<0x31800000) /* |x|<2**-28 */ + /* |x| in [0,9], return sign(x)*0.5*(E+E/(E+1))) */ + if (ix < 0x41100000) { /* |x|<9 */ + if (ix<0x39800000) /* |x|<2**-12 */ if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ t = expm1f(fabsf(x)); if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one)); return h*(t+t/(t+one)); } - /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x42b17180) return h*expf(fabsf(x)); + /* |x| in [9, logf(maxfloat)] return 0.5*exp(|x|) */ + if (ix < 0x42b17217) return h*__ieee754_expf(fabsf(x)); - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix<=0x42b2d4fc) { - w = expf((float)0.5*fabsf(x)); - t = h*w; - return t*w; - } + /* |x| in [logf(maxfloat), overflowthresold] */ + if (ix<=0x42b2d4fc) + return h*2.0F*__ldexp_expf(fabsf(x), -1); /* |x| > overflowthresold, sinh(x) overflow */ return x*shuge; diff --git a/lib/libm/src/e_sqrt.c b/lib/libm/src/e_sqrt.c deleted file mode 100644 index 5bf731cbe3..0000000000 --- a/lib/libm/src/e_sqrt.c +++ /dev/null @@ -1,443 +0,0 @@ -/* @(#)e_sqrt.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. - * ==================================================== - * - * $NetBSD: e_sqrt.c,v 1.13 2009/02/16 01:19:34 lukem Exp $ - */ - -/* sqrt(x) - * Return correctly rounded sqrt. - * ------------------------------------------ - * | Use the hardware sqrt if you have one | - * ------------------------------------------ - * Method: - * Bit by bit method using integer arithmetic. (Slow, but portable) - * 1. Normalization - * Scale x to y in [1,4) with even powers of 2: - * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then - * sqrt(x) = 2^k * sqrt(y) - * 2. Bit by bit computation - * Let q = sqrt(y) truncated to i bit after binary point (q = 1), - * i 0 - * i+1 2 - * s = 2*q , and y = 2 * ( y - q ). (1) - * i i i i - * - * To compute q from q , one checks whether - * i+1 i - * - * -(i+1) 2 - * (q + 2 ) <= y. (2) - * i - * -(i+1) - * If (2) is false, then q = q ; otherwise q = q + 2 . - * i+1 i i+1 i - * - * With some algebric manipulation, it is not difficult to see - * that (2) is equivalent to - * -(i+1) - * s + 2 <= y (3) - * i i - * - * The advantage of (3) is that s and y can be computed by - * i i - * the following recurrence formula: - * if (3) is false - * - * s = s , y = y ; (4) - * i+1 i i+1 i - * - * otherwise, - * -i -(i+1) - * s = s + 2 , y = y - s - 2 (5) - * i+1 i i+1 i i - * - * One may easily use induction to prove (4) and (5). - * Note. Since the left hand side of (3) contain only i+2 bits, - * it does not necessary to do a full (53-bit) comparison - * in (3). - * 3. Final rounding - * After generating the 53 bits result, we compute one more bit. - * Together with the remainder, we can decide whether the - * result is exact, bigger than 1/2ulp, or less than 1/2ulp - * (it will never equal to 1/2ulp). - * The rounding mode can be detected by checking whether - * huge + tiny is equal to huge, and whether huge - tiny is - * equal to huge for some floating point number "huge" and "tiny". - * - * Special cases: - * sqrt(+-0) = +-0 ... exact - * sqrt(inf) = inf - * sqrt(-ve) = NaN ... with invalid signal - * sqrt(NaN) = NaN ... with invalid signal for signaling NaN - * - * Other methods : see the appended file at the end of the program below. - *--------------- - */ - -#include -#include "math_private.h" - -static const double one = 1.0, tiny=1.0e-300; - -double -sqrt(double x) -{ - double z; - int32_t sign = (int)0x80000000; - int32_t ix0,s0,q,m,t,i; - u_int32_t r,t1,s1,ix1,q1; - - EXTRACT_WORDS(ix0,ix1,x); - - /* take care of Inf and NaN */ - if((ix0&0x7ff00000)==0x7ff00000) { - return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf - sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if(ix0<=0) { - if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ - else if(ix0<0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = (ix0>>20); - if(m==0) { /* subnormal x */ - while(ix0==0) { - m -= 21; - ix0 |= (ix1>>11); ix1 <<= 21; - } - for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; - m -= i-1; - ix0 |= (ix1>>(32-i)); - ix1 <<= i; - } - m -= 1023; /* unbias exponent */ - ix0 = (ix0&0x000fffff)|0x00100000; - if(m&1){ /* odd m, double x to make it even */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - } - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ - r = 0x00200000; /* r = moving bit from right to left */ - - while(r!=0) { - t = s0+r; - if(t<=ix0) { - s0 = t+r; - ix0 -= t; - q += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r>>=1; - } - - r = sign; - while(r!=0) { - t1 = s1+r; - t = s0; - if((t>31); - ix1 += ix1; - r>>=1; - } - - /* use floating add to find out rounding direction */ - if((ix0|ix1)!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;} - else if (z>one) { - if (q1==(u_int32_t)0xfffffffe) q+=1; - q1+=2; - } else - q1 += (q1&1); - } - } - ix0 = (q>>1)+0x3fe00000; - ix1 = q1>>1; - if ((q&1)==1) ix1 |= sign; - ix0 += (m <<20); - INSERT_WORDS(z,ix0,ix1); - return z; -} - -/* -Other methods (use floating-point arithmetic) -------------- -(This is a copy of a drafted paper by Prof W. Kahan -and K.C. Ng, written in May, 1986) - - Two algorithms are given here to implement sqrt(x) - (IEEE double precision arithmetic) in software. - Both supply sqrt(x) correctly rounded. The first algorithm (in - Section A) uses newton iterations and involves four divisions. - The second one uses reciproot iterations to avoid division, but - requires more multiplications. Both algorithms need the ability - to chop results of arithmetic operations instead of round them, - and the INEXACT flag to indicate when an arithmetic operation - is executed exactly with no roundoff error, all part of the - standard (IEEE 754-1985). The ability to perform shift, add, - subtract and logical AND operations upon 32-bit words is needed - too, though not part of the standard. - -A. sqrt(x) by Newton Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - - 1 11 52 ...widths - ------------------------------------------------------ - x: |s| e | f | - ------------------------------------------------------ - msb lsb msb lsb ...order - - - ------------------------ ------------------------ - x0: |s| e | f1 | x1: | f2 | - ------------------------ ------------------------ - - By performing shifts and subtracts on x0 and x1 (both regarded - as integers), we obtain an 8-bit approximation of sqrt(x) as - follows. - - k := (x0>>1) + 0x1ff80000; - y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits - Here k is a 32-bit integer and T1[] is an integer array containing - correction terms. Now magically the floating value of y (y's - leading 32-bit word is y0, the value of its trailing word is 0) - approximates sqrt(x) to almost 8-bit. - - Value of T1: - static int T1[32]= { - 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592, - 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215, - 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581, - 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,}; - - (2) Iterative refinement - - Apply Heron's rule three times to y, we have y approximates - sqrt(x) to within 1 ulp (Unit in the Last Place): - - y := (y+x/y)/2 ... almost 17 sig. bits - y := (y+x/y)/2 ... almost 35 sig. bits - y := y-(y-x/y)/2 ... within 1 ulp - - - Remark 1. - Another way to improve y to within 1 ulp is: - - y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x) - y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x) - - 2 - (x-y )*y - y := y + 2* ---------- ...within 1 ulp - 2 - 3y + x - - - This formula has one division fewer than the one above; however, - it requires more multiplications and additions. Also x must be - scaled in advance to avoid spurious overflow in evaluating the - expression 3y*y+x. Hence it is not recommended uless division - is slow. If division is very slow, then one should use the - reciproot algorithm given in section B. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - I := FALSE; ... reset INEXACT flag I - R := RZ; ... set rounding mode to round-toward-zero - z := x/y; ... chopped quotient, possibly inexact - If(not I) then { ... if the quotient is exact - if(z=y) { - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - } else { - z := z - ulp; ... special rounding - } - } - i := TRUE; ... sqrt(x) is inexact - If (r=RN) then z=z+ulp ... rounded-to-nearest - If (r=RP) then { ... round-toward-+inf - y = y+ulp; z=z+ulp; - } - y := y+z; ... chopped sum - y0:=y0-0x00100000; ... y := y/2 is correctly rounded. - I := i; ... restore inexact flag - R := r; ... restore rounded mode - return sqrt(x):=y. - - (4) Special cases - - Square root of +inf, +-0, or NaN is itself; - Square root of a negative number is NaN with invalid signal. - - -B. sqrt(x) by Reciproot Iteration - - (1) Initial approximation - - Let x0 and x1 be the leading and the trailing 32-bit words of - a floating point number x (in IEEE double format) respectively - (see section A). By performing shifs and subtracts on x0 and y0, - we obtain a 7.8-bit approximation of 1/sqrt(x) as follows. - - k := 0x5fe80000 - (x0>>1); - y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits - - Here k is a 32-bit integer and T2[] is an integer array - containing correction terms. Now magically the floating - value of y (y's leading 32-bit word is y0, the value of - its trailing word y1 is set to zero) approximates 1/sqrt(x) - to almost 7.8-bit. - - Value of T2: - static int T2[64]= { - 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866, - 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f, - 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d, - 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0, - 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989, - 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd, - 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e, - 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,}; - - (2) Iterative refinement - - Apply Reciproot iteration three times to y and multiply the - result by x to get an approximation z that matches sqrt(x) - to about 1 ulp. To be exact, we will have - -1ulp < sqrt(x)-z<1.0625ulp. - - ... set rounding mode to Round-to-nearest - y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x) - y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x) - ... special arrangement for better accuracy - z := x*y ... 29 bits to sqrt(x), with z*y<1 - z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x) - - Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that - (a) the term z*y in the final iteration is always less than 1; - (b) the error in the final result is biased upward so that - -1 ulp < sqrt(x) - z < 1.0625 ulp - instead of |sqrt(x)-z|<1.03125ulp. - - (3) Final adjustment - - By twiddling y's last bit it is possible to force y to be - correctly rounded according to the prevailing rounding mode - as follows. Let r and i be copies of the rounding mode and - inexact flag before entering the square root program. Also we - use the expression y+-ulp for the next representable floating - numbers (up and down) of y. Note that y+-ulp = either fixed - point y+-1, or multiply y by nextafter(1,+-inf) in chopped - mode. - - R := RZ; ... set rounding mode to round-toward-zero - switch(r) { - case RN: ... round-to-nearest - if(x<= z*(z-ulp)...chopped) z = z - ulp; else - if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp; - break; - case RZ:case RM: ... round-to-zero or round-to--inf - R:=RP; ... reset rounding mod to round-to-+inf - if(x=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp; - break; - case RP: ... round-to-+inf - if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else - if(x>z*z ...chopped) z = z+ulp; - break; - } - - Remark 3. The above comparisons can be done in fixed point. For - example, to compare x and w=z*z chopped, it suffices to compare - x1 and w1 (the trailing parts of x and w), regarding them as - two's complement integers. - - ...Is z an exact square root? - To determine whether z is an exact square root of x, let z1 be the - trailing part of z, and also let x0 and x1 be the leading and - trailing parts of x. - - If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0 - I := 1; ... Raise Inexact flag: z is not exact - else { - j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2 - k := z1 >> 26; ... get z's 25-th and 26-th - fraction bits - I := i or (k&j) or ((k&(j+j+1))!=(x1&3)); - } - R:= r ... restore rounded mode - return sqrt(x):=z. - - If multiplication is cheaper than the foregoing red tape, the - Inexact flag can be evaluated by - - I := i; - I := (z*z!=x) or I. - - Note that z*z can overwrite I; this value must be sensed if it is - True. - - Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be - zero. - - -------------------- - z1: | f2 | - -------------------- - bit 31 bit 0 - - Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd - or even of logb(x) have the following relations: - - ------------------------------------------------- - bit 27,26 of z1 bit 1,0 of x1 logb(x) - ------------------------------------------------- - 00 00 odd and even - 01 01 even - 10 10 odd - 10 00 even - 11 01 even - ------------------------------------------------- - - (4) Special cases (see (4) of Section A). - - */ - diff --git a/lib/libm/src/e_sqrtf.c b/lib/libm/src/e_sqrtf.c deleted file mode 100644 index eaad9f3fc0..0000000000 --- a/lib/libm/src/e_sqrtf.c +++ /dev/null @@ -1,88 +0,0 @@ -/* e_sqrtf.c -- float version of e_sqrt.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. - * ==================================================== - * - * $NetBSD: e_sqrtf.c,v 1.7 2002/05/26 22:01:53 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_sqrtf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -#include -#include "math_private.h" - -static const float one = 1.0, tiny=1.0e-30; - -float -sqrtf(float x) -{ - float z; - int32_t sign = (int)0x80000000; - int32_t ix,s,q,m,t,i; - u_int32_t r; - - GET_FLOAT_WORD(ix,x); - - /* take care of Inf and NaN */ - if((ix&0x7f800000)==0x7f800000) { - return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf - sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if(ix<=0) { - if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */ - else if(ix<0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = (ix>>23); - if(m==0) { /* subnormal x */ - for(i=0;(ix&0x00800000)==0;i++) ix<<=1; - m -= i-1; - } - m -= 127; /* unbias exponent */ - ix = (ix&0x007fffff)|0x00800000; - if(m&1) /* odd m, double x to make it even */ - ix += ix; - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix += ix; - q = s = 0; /* q = sqrt(x) */ - r = 0x01000000; /* r = moving bit from right to left */ - - while(r!=0) { - t = s+r; - if(t<=ix) { - s = t+r; - ix -= t; - q += r; - } - ix += ix; - r>>=1; - } - - /* use floating add to find out rounding direction */ - if(ix!=0) { - z = one-tiny; /* trigger inexact flag */ - if (z>=one) { - z = one+tiny; - if (z>one) - q += 2; - else - q += (q&1); - } - } - ix = (q>>1)+0x3f000000; - ix += (m <<23); - SET_FLOAT_WORD(z,ix); - return z; -} diff --git a/lib/libm/src/e_sqrtl.c b/lib/libm/src/e_sqrtl.c deleted file mode 100644 index 3bb0361561..0000000000 --- a/lib/libm/src/e_sqrtl.c +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * 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. - * - * FreeBSD SVN: 176720 (2008-03-02) - */ - -#include -#include - -#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); -} - -#if 0 /* Ignored by gcc, emits warning */ -#pragma STDC FENV_ACCESS ON -#endif - -/* - * 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/lib/libm/arch/i386/fenv.h b/lib/libm/src/fenv.h similarity index 69% rename from lib/libm/arch/i386/fenv.h rename to lib/libm/src/fenv.h index 2186895b4e..2133e7d06f 100644 --- a/lib/libm/arch/i386/fenv.h +++ b/lib/libm/src/fenv.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.7 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: head/lib/msun/x86/fenv.h 249724 2013-04-21 13:31:55Z kib $ */ #ifndef _FENV_H_ @@ -32,17 +32,9 @@ #include #include -/* - * 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 __status; - __uint32_t __mxcsr; - __uint32_t __tag; - char __other[16]; -} fenv_t; +#ifndef __fenv_static +#define __fenv_static static +#endif typedef __uint16_t fexcept_t; @@ -72,18 +64,32 @@ typedef __uint16_t fexcept_t; #define _SSE_ROUND_SHIFT 3 #define _SSE_EMASK_SHIFT 7 -__BEGIN_DECLS +#ifdef __i386__ +/* + * To preserve binary compatibility, 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; +#else /* __x86_64__ */ +typedef struct { + struct { + __uint32_t __control; + __uint32_t __status; + __uint32_t __tag; + char __other[16]; + } __x87; + __uint32_t __mxcsr; +} fenv_t; +#endif /* __i386__ */ -/* After testing for SSE support once, we cache the result in __has_sse. */ -enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK }; -extern enum __sse_support __has_sse; -int __test_sse(void); -#ifdef __SSE__ -#define __HAS_SSE() 1 -#else -#define __HAS_SSE() (__has_sse == __SSE_YES || \ - (__has_sse == __SSE_UNK && __test_sse())) -#endif +__BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; @@ -102,7 +108,69 @@ extern const fenv_t __fe_dfl_env; #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) -static __inline int +int fegetenv(fenv_t *__envp); +int feholdexcept(fenv_t *__envp); +int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +int feraiseexcept(int __excepts); +int feupdateenv(const fenv_t *__envp); + +__fenv_static inline 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); +} + +#if __BSD_VISIBLE + +int feenableexcept(int __mask); +int fedisableexcept(int __mask); + +/* We currently provide no external definition of fegetexcept(). */ +static inline 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); +} + +#endif /* __BSD_VISIBLE */ + +#ifdef __i386__ + +/* After testing for SSE support once, we cache the result in __has_sse. */ +enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK }; +extern enum __sse_support __has_sse; +int __test_sse(void); +#ifdef __SSE__ +#define __HAS_SSE() 1 +#else +#define __HAS_SSE() (__has_sse == __SSE_YES || \ + (__has_sse == __SSE_UNK && __test_sse())) +#endif + +#define __get_mxcsr(env) (((env).__mxcsr_hi << 16) | \ + ((env).__mxcsr_lo)) +#define __set_mxcsr(env, x) do { \ + (env).__mxcsr_hi = (__uint32_t)(x) >> 16; \ + (env).__mxcsr_lo = (__uint16_t)(x); \ +} while (0) + +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __env; @@ -123,7 +191,7 @@ feclearexcept(int __excepts) return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { __uint32_t __mxcsr; @@ -138,10 +206,7 @@ fegetexceptflag(fexcept_t *__flagp, int __excepts) return (0); } -int fesetexceptflag(const fexcept_t *__flagp, int __excepts); -int feraiseexcept(int __excepts); - -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { __uint32_t __mxcsr; @@ -155,22 +220,7 @@ fetestexcept(int __excepts) return ((__status | __mxcsr) & __excepts); } -static __inline 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); -} - -static __inline int +__fenv_static inline int fesetround(int __round) { __uint32_t __mxcsr; @@ -194,17 +244,14 @@ fesetround(int __round) return (0); } -int fegetenv(fenv_t *__envp); -int feholdexcept(fenv_t *__envp); - -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { fenv_t __env = *__envp; __uint32_t __mxcsr; - __mxcsr = __env.__mxcsr; - __env.__mxcsr = 0xffffffff; + __mxcsr = __get_mxcsr(__env); + __set_mxcsr(__env, 0xffffffff); /* * XXX Using fldenvx() instead of fldenv() tells the compiler that this * instruction clobbers the i387 register stack. This happens because @@ -219,27 +266,89 @@ fesetenv(const fenv_t *__envp) return (0); } -int feupdateenv(const fenv_t *__envp); +#else /* __x86_64__ */ -#if __BSD_VISIBLE +__fenv_static inline int +feclearexcept(int __excepts) +{ + fenv_t __env; -int feenableexcept(int __mask); -int fedisableexcept(int __mask); + if (__excepts == FE_ALL_EXCEPT) { + __fnclex(); + } else { + __fnstenv(&__env.__x87); + __env.__x87.__status &= ~__excepts; + __fldenv(__env.__x87); + } + __stmxcsr(&__env.__mxcsr); + __env.__mxcsr &= ~__excepts; + __ldmxcsr(__env.__mxcsr); + return (0); +} -static __inline int -fegetexcept(void) +__fenv_static inline int +fegetexceptflag(fexcept_t *__flagp, int __excepts) { + __uint32_t __mxcsr; + __uint16_t __status; + + __stmxcsr(&__mxcsr); + __fnstsw(&__status); + *__flagp = (__mxcsr | __status) & __excepts; + return (0); +} + +__fenv_static inline int +fetestexcept(int __excepts) +{ + __uint32_t __mxcsr; + __uint16_t __status; + + __stmxcsr(&__mxcsr); + __fnstsw(&__status); + return ((__status | __mxcsr) & __excepts); +} + +__fenv_static inline int +fesetround(int __round) +{ + __uint32_t __mxcsr; __uint16_t __control; + if (__round & ~_ROUND_MASK) + return (-1); + + __fnstcw(&__control); + __control &= ~_ROUND_MASK; + __control |= __round; + __fldcw(__control); + + __stmxcsr(&__mxcsr); + __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); + __mxcsr |= __round << _SSE_ROUND_SHIFT; + __ldmxcsr(__mxcsr); + + return (0); +} + +__fenv_static inline int +fesetenv(const fenv_t *__envp) +{ + /* - * We assume that the masks for the x87 and the SSE unit are - * the same. + * 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. */ - __fnstcw(&__control); - return (~__control & FE_ALL_EXCEPT); + __fldenvx(__envp->__x87); + __ldmxcsr(__envp->__mxcsr); + return (0); } -#endif /* __BSD_VISIBLE */ +#endif /* __i386__ */ __END_DECLS diff --git a/lib/libm/src/k_cos.c b/lib/libm/src/k_cos.c index 5657f3e0da..da79534d1c 100644 --- a/lib/libm/src/k_cos.c +++ b/lib/libm/src/k_cos.c @@ -1,23 +1,22 @@ -/* @(#)k_cos.c 5.1 93/09/24 */ + +/* @(#)k_cos.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/k_cos.c 176408 2008-02-19 12:54:14Z bde $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: k_cos.c,v 1.11 2002/05/26 22:01:53 wiz Exp $ - * $DragonFly: src/lib/libm/src/k_cos.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* * __kernel_cos( x, y ) * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. + * Input y is the tail of x. * * Algorithm * 1. Since cos(-x) = cos(x), we need only to consider positive x. @@ -27,28 +26,32 @@ * 4 14 * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x * where the remez error is - * + * * | 2 4 6 8 10 12 14 | -58 * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 - * | | - * - * 4 6 8 10 12 14 + * | | + * + * 4 6 8 10 12 14 * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then - * cos(x) = 1 - x*x/2 + r - * since cos(x+y) ~ cos(x) - sin(x)*y + * cos(x) ~ 1 - x*x/2 + r + * since cos(x+y) ~ cos(x) - sin(x)*y * ~ cos(x) - x*y, * a correction term is necessary in cos(x) and hence * cos(x+y) = 1 - (x*x/2 - (r - x*y)) - * For better accuracy when x > 0.3, let qx = |x|/4 with - * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125. - * Then - * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)). - * Note that 1-qx and (x*x/2-qx) is EXACT here, and the - * magnitude of the latter is at least a quarter of x*x/2, - * thus, reducing the rounding error in the subtraction. + * For better accuracy, rearrange to + * cos(x+y) ~ w + (tmp + (r-x*y)) + * where w = 1 - x*x/2 and tmp is a tiny correction term + * (1 - x*x/2 == w + tmp exactly in infinite precision). + * The exactness of w + tmp in infinite precision depends on w + * and tmp having the same precision as x. If they have extra + * precision due to compiler bugs, then the extra precision is + * only good provided it is retained in all terms of the final + * expression for cos(). Retention happens in all cases tested + * under FreeBSD, so don't pessimize things by forcibly clipping + * any extra precision in w. */ -#include +#include "math.h" #include "math_private.h" static const double @@ -63,25 +66,12 @@ C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ double __kernel_cos(double x, double y) { - double a,hz,z,r,qx; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* ix = |x|'s high word*/ - if(ix<0x3e400000) { /* if x < 2**27 */ - if(((int)x)==0) return one; /* generate inexact */ - } + double hz,z,r,w; + z = x*x; - r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); - if(ix < 0x3FD33333) /* if |x| < 0.3 */ - return one - (0.5*z - (z*r - x*y)); - else { - if(ix > 0x3fe90000) { /* x > 0.78125 */ - qx = 0.28125; - } else { - INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */ - } - hz = 0.5*z-qx; - a = one-qx; - return a - (hz - (z*r-x*y)); - } + 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/lib/libm/src/k_cosf.c b/lib/libm/src/k_cosf.c index 6beaa79ecd..8adf47e152 100644 --- a/lib/libm/src/k_cosf.c +++ b/lib/libm/src/k_cosf.c @@ -12,10 +12,11 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 193368 (2009-06-03) + * + * $FreeBSD: head/lib/msun/src/k_cosf.c 239192 2012-08-11 11:13:48Z dim $ */ -#include +#include "math.h" #include "math_private.h" /* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */ @@ -26,7 +27,10 @@ C1 = 0x155553e1053a42.0p-57, /* 0.0416666233237390631894 */ C2 = -0x16c087e80f1e27.0p-62, /* -0.00138867637746099294692 */ C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */ -__inline float +#ifdef INLINE_KERNEL_COSDF +static __inline +#endif +float __kernel_cosdf(double x) { double r, w, z; diff --git a/lib/libm/src/k_exp.c b/lib/libm/src/k_exp.c new file mode 100644 index 0000000000..8ddc7b0fa2 --- /dev/null +++ b/lib/libm/src/k_exp.c @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/lib/msun/src/k_exp.c 226597 2011-10-21 06:27:56Z das $ + */ + +#include + +#include "math.h" +#include "math_private.h" + +static const uint32_t k = 1799; /* constant for reduction */ +static const double kln2 = 1246.97177782734161156; /* k * ln2 */ + +/* + * Compute exp(x), scaled to avoid spurious overflow. An exponent is + * returned separately in 'expt'. + * + * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91 + * Output: 2**1023 <= y < 2**1024 + */ +static double +__frexp_exp(double x, int *expt) +{ + double exp_x; + uint32_t hx; + + /* + * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to + * minimize |exp(kln2) - 2**k|. We also scale the exponent of + * exp_x to MAX_EXP so that the result can be multiplied by + * a tiny number without losing accuracy due to denormalization. + */ + exp_x = exp(x - kln2); + GET_HIGH_WORD(hx, exp_x); + *expt = (hx >> 20) - (0x3ff + 1023) + k; + SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20)); + return (exp_x); +} + +/* + * __ldexp_exp(x, expt) and __ldexp_cexp(x, expt) compute exp(x) * 2**expt. + * They are intended for large arguments (real part >= ln(DBL_MAX)) + * where care is needed to avoid overflow. + * + * The present implementation is narrowly tailored for our hyperbolic and + * exponential functions. We assume expt is small (0 or -1), and the caller + * has filtered out very large x, for which overflow would be inevitable. + */ + +double +__ldexp_exp(double x, int expt) +{ + double exp_x, scale; + int ex_expt; + + exp_x = __frexp_exp(x, &ex_expt); + expt += ex_expt; + INSERT_WORDS(scale, (0x3ff + expt) << 20, 0); + return (exp_x * scale); +} + +double complex +__ldexp_cexp(double complex z, int expt) +{ + double x, y, exp_x, scale1, scale2; + int ex_expt, half_expt; + + x = creal(z); + y = cimag(z); + exp_x = __frexp_exp(x, &ex_expt); + expt += ex_expt; + + /* + * Arrange so that scale1 * scale2 == 2**expt. We use this to + * compensate for scalbn being horrendously slow. + */ + half_expt = expt / 2; + INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0); + half_expt = expt - half_expt; + INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0); + + return (cpack(cos(y) * exp_x * scale1 * scale2, + sin(y) * exp_x * scale1 * scale2)); +} diff --git a/lib/libm/src/s_fmaf.c b/lib/libm/src/k_expf.c similarity index 50% copy from lib/libm/src/s_fmaf.c copy to lib/libm/src/k_expf.c index e589d51278..bc60436bb5 100644 --- a/lib/libm/src/s_fmaf.c +++ b/lib/libm/src/k_expf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2011 David Schultz + * Copyright (c) 2011 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,45 +23,64 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 226371 (2011-10-15) + * $FreeBSD: head/lib/msun/src/k_expf.c 230371 2012-01-20 07:02:42Z das $ */ -#include -#include +#include + +#include "math.h" #include "math_private.h" +static const uint32_t k = 235; /* constant for reduction */ +static const float kln2 = 162.88958740F; /* k * ln2 */ + /* - * Fused multiply-add: Compute x * y + z with a single rounding error. + * See k_exp.c for details. * - * A double has more than twice as much precision than a float, so - * direct double-precision arithmetic suffices, except where double - * rounding occurs. + * 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 -fmaf(float x, float y, float z) +__ldexp_expf(float x, int expt) { - double xy, result; - uint32_t hr, lr; + 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; - 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); + 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); - /* - * 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); + return (cpackf(cosf(y) * exp_x * scale1 * scale2, + sinf(y) * exp_x * scale1 * scale2)); } diff --git a/lib/libm/src/e_log.c b/lib/libm/src/k_log.h similarity index 51% copy from lib/libm/src/e_log.c copy to lib/libm/src/k_log.h index 917b2e12ca..34b8fe4900 100644 --- a/lib/libm/src/e_log.c +++ b/lib/libm/src/k_log.h @@ -1,32 +1,37 @@ -/* @(#)e_log.c 5.1 93/09/24 */ + +/* @(#)e_log.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/k_log.h 226376 2011-10-15 05:23:28Z das $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: e_log.c,v 1.12 2002/05/26 22:01:51 wiz Exp $ - * $DragonFly: src/lib/libm/src/e_log.c,v 1.2 2007/06/24 05:17:51 pavalos Exp $ */ -/* log(x) - * Return the logrithm of x +/* + * k_log1p(f): + * Return log(1+f) - f for 1+f in ~[sqrt(2)/2, sqrt(2)]. * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), + * 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 + * 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 @@ -34,22 +39,22 @@ * (the values of Lg1 to Lg7 are listed in the program) * and * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 + * | 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). + * + * 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: + * 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(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. * @@ -58,19 +63,13 @@ * 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 + * 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 -#include "math_private.h" - static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ @@ -79,56 +78,21 @@ Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ -static const double zero = 0.0; - -double -log(double x) +/* + * 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,f,s,z,R,w,t1,t2,dk; - int32_t k,hx,i,j; - u_int32_t lx; - - EXTRACT_WORDS(hx,lx,x); + double hfsq,s,z,R,w,t1,t2; - 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; - hx &= 0x000fffff; - i = (hx+0x95f64)&0x100000; - SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ - k += (i>>20); - f = x-1.0; - 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);} - } s = f/(2.0+f); - dk = (double)k; z = s*s; - i = hx-0x6147a; w = z*z; - j = 0x6b851-hx; t1= w*(Lg2+w*(Lg4+w*Lg6)); t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - i |= j; R = t2+t1; - if(i>0) { - hfsq=0.5*f*f; - if(k==0) return f-(hfsq-s*(hfsq+R)); else - return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); - } else { - if(k==0) return f-s*(f-R); else - return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); - } + hfsq=0.5*f*f; + return s*(hfsq+R); } diff --git a/lib/libm/src/k_logf.h b/lib/libm/src/k_logf.h new file mode 100644 index 0000000000..c87b119e65 --- /dev/null +++ b/lib/libm/src/k_logf.h @@ -0,0 +1,38 @@ +/* + * ==================================================== + * 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: head/lib/msun/src/k_logf.h 226376 2011-10-15 05:23:28Z das $ + */ + +/* + * 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/lib/libm/src/k_rem_pio2.c b/lib/libm/src/k_rem_pio2.c index 6328f83bda..d4ce3acb67 100644 --- a/lib/libm/src/k_rem_pio2.c +++ b/lib/libm/src/k_rem_pio2.c @@ -1,27 +1,26 @@ /* @(#)k_rem_pio2.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/k_rem_pio2.c 242692 2012-11-07 07:00:59Z kevlo $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 176550 (2008-02-25) */ /* * __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 + * + * __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 + * 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 @@ -30,10 +29,10 @@ * (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 + * 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 + * 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]: @@ -85,8 +84,8 @@ * the fraction part may be lost to cancelation before we * recompute.) * - * jz local integer variable indicating the number of - * terms of ipio2[] used. + * jz local integer variable indicating the number of + * terms of ipio2[] used. * * jx nx - 1 * @@ -106,9 +105,9 @@ * exponent for q[i] would be q0-24*i. * * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. + * into 24 bits chunks. * - * f[] ipio2[] in floating point + * f[] ipio2[] in floating point * * iq[] integer array by breaking up q[] in 24-bits chunk. * @@ -122,13 +121,15 @@ /* * 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 + * 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 +#include + +#include "math.h" #include "math_private.h" static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ @@ -136,8 +137,8 @@ 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 + * 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)). @@ -146,17 +147,17 @@ static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ * 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, +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 @@ -281,7 +282,7 @@ static const double PIo2[] = { 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ }; -static const double +static const double zero = 0.0, one = 1.0, two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ @@ -330,7 +331,7 @@ recompute: 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; @@ -381,7 +382,7 @@ recompute: while(iq[jz]==0) { jz--; q0-=24;} } else { /* break z into 24-bit if necessary */ z = scalbn(z,-q0); - if(z>=two24) { + if(z>=two24) { fw = (double)((int32_t)(twon24*z)); iq[jz] = (int32_t)(z-two24*fw); jz += 1; q0 += 24; @@ -406,30 +407,30 @@ recompute: case 0: fw = 0.0; for (i=jz;i>=0;i--) fw += fq[i]; - y[0] = (ih==0)? fw: -fw; + y[0] = (ih==0)? fw: -fw; break; case 1: case 2: fw = 0.0; - for (i=jz;i>=0;i--) fw += fq[i]; + for (i=jz;i>=0;i--) fw += fq[i]; STRICT_ASSIGN(double,fw,fw); - y[0] = (ih==0)? 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; + y[1] = (ih==0)? fw: -fw; break; case 3: /* painful */ for (i=jz;i>0;i--) { - fw = fq[i-1]+fq[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]; + 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]; + 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 { diff --git a/lib/libm/src/k_rem_pio2f.c b/lib/libm/src/k_rem_pio2f.c deleted file mode 100644 index e47e61cafb..0000000000 --- a/lib/libm/src/k_rem_pio2f.c +++ /dev/null @@ -1,195 +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. - * ==================================================== - * - * $NetBSD: k_rem_pio2f.c,v 1.8 2010/04/23 19:17:07 drochner Exp $ - */ - -#include -#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]>>8; - else if(z>=(float)0.5) ih=2; - - if(ih>0) { /* q > 0.5 */ - n += 1; carry = 0; - for(i=0;i0) { /* 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]; - 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/lib/libm/src/k_sin.c b/lib/libm/src/k_sin.c index 5cc78c2bdb..f90fdbb164 100644 --- a/lib/libm/src/k_sin.c +++ b/lib/libm/src/k_sin.c @@ -1,47 +1,48 @@ -/* @(#)k_sin.c 5.1 93/09/24 */ + +/* @(#)k_sin.c 1.3 95/01/18 */ +/* $FreeBSD: head/lib/msun/src/k_sin.c 176408 2008-02-19 12:54:14Z bde $ */ /* * ==================================================== * 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 + * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: k_sin.c,v 1.11 2002/05/26 22:01:53 wiz Exp $ - * $DragonFly: src/lib/libm/src/k_sin.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* __kernel_sin( x, y, iy) - * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 + * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 * Input x is assumed to be bounded by ~pi/4 in magnitude. * Input y is the tail of x. - * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). + * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). * * Algorithm - * 1. Since sin(-x) = -sin(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. + * 1. Since sin(-x) = -sin(x), we need only to consider positive x. + * 2. Callers must return sin(-0) = -0 without calling here since our + * odd polynomial is not evaluated in a way that preserves -0. + * Callers may do the optimization sin(x) ~ x for tiny x. * 3. sin(x) is approximated by a polynomial of degree 13 on * [0,pi/4] * 3 13 * sin(x) ~ x + S1*x + ... + S6*x * where - * + * * |sin(x) 2 4 6 8 10 12 | -58 * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 - * | x | - * + * | x | + * * 4. sin(x+y) = sin(x) + sin'(x')*y * ~ sin(x) + (1-x*x/2)*y - * For better accuracy, let + * For better accuracy, let * 3 2 2 2 2 * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) * then 3 2 * sin(x) = x + (S1*x + (x *(r-y/2)+y)) */ -#include +#include "math.h" #include "math_private.h" static const double @@ -56,15 +57,12 @@ S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ double __kernel_sin(double x, double y, int iy) { - double z,r,v; - int32_t ix; - GET_HIGH_WORD(ix,x); - ix &= 0x7fffffff; /* high word of x */ - if(ix<0x3e400000) /* |x| < 2**-27 */ - {if((int)x==0) return x;} /* generate inexact */ + 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/lib/libm/src/k_sinf.c b/lib/libm/src/k_sinf.c index af8f355b8e..ef92794d51 100644 --- a/lib/libm/src/k_sinf.c +++ b/lib/libm/src/k_sinf.c @@ -12,11 +12,11 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 193368 (2009-06-03) + * + * $FreeBSD: head/lib/msun/src/k_sinf.c 239192 2012-08-11 11:13:48Z dim $ */ - -#include +#include "math.h" #include "math_private.h" /* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */ @@ -26,7 +26,10 @@ S2 = 0x111110896efbb2.0p-59, /* 0.0083333293858894631756 */ S3 = -0x1a00f9e2cae774.0p-65, /* -0.000198393348360966317347 */ S4 = 0x16cd878c3b46a7.0p-71; /* 0.0000027183114939898219064 */ -__inline float +#ifdef INLINE_KERNEL_SINDF +static __inline +#endif +float __kernel_sindf(double x) { double r, s, w, z; diff --git a/lib/libm/src/k_tan.c b/lib/libm/src/k_tan.c index 715509587a..1be1af6988 100644 --- a/lib/libm/src/k_tan.c +++ b/lib/libm/src/k_tan.c @@ -1,28 +1,28 @@ -/* @(#)k_tan.c 5.1 93/09/24 */ +/* @(#)k_tan.c 1.5 04/04/22 SMI */ +/* $FreeBSD: head/lib/msun/src/k_tan.c 176451 2008-02-22 02:30:36Z das $ */ + /* * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * Copyright 2004 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. * ==================================================== - * - * $NetBSD: k_tan.c,v 1.12 2004/07/22 18:24:09 drochner Exp $ - * $DragonFly: src/lib/libm/src/k_tan.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ +/* INDENT OFF */ /* __kernel_tan( x, y, k ) - * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 + * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 * Input x is assumed to be bounded by ~pi/4 in magnitude. * Input y is the tail of x. - * Input k indicates whether tan (if k=1) or - * -1/tan (if k= -1) is returned. + * Input k indicates whether tan (if k = 1) or -1/tan (if k = -1) is returned. * * Algorithm * 1. Since tan(-x) = -tan(x), we need only to consider positive x. - * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0. + * 2. Callers must return tan(-0) = -0 without calling here since our + * odd polynomial is not evaluated in a way that preserves -0. + * Callers may do the optimization tan(x) ~ x for tiny x. * 3. tan(x) is approximated by a odd polynomial of degree 27 on * [0,0.67434] * 3 27 @@ -47,9 +47,8 @@ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ -#include +#include "math.h" #include "math_private.h" - static const double xxx[] = { 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */ @@ -72,38 +71,15 @@ static const double xxx[] = { #define pio4 xxx[14] #define pio4lo xxx[15] #define T xxx +/* INDENT ON */ double -__kernel_tan(double x, double y, int iy) -{ +__kernel_tan(double x, double y, int iy) { double z, r, v, w, s; int32_t ix, hx; - GET_HIGH_WORD(hx, x); /* high word of x */ + GET_HIGH_WORD(hx,x); ix = hx & 0x7fffffff; /* high word of |x| */ - if (ix < 0x3e300000) { /* x < 2**-28 */ - if ((int) x == 0) { /* generate inexact */ - u_int32_t low; - GET_LOW_WORD(low, x); - if(((ix | low) | (iy + 1)) == 0) - return one / fabs(x); - else { - if (iy == 1) - return x; - else { /* compute -1 / (x+y) carefully */ - double a, t; - - z = w = x + y; - SET_LOW_WORD(z, 0); - v = y - (z - x); - t = a = -one / w; - SET_LOW_WORD(t, 0); - s = one + t * z; - return t + a * (s + t * v); - } - } - } - } if (ix >= 0x3FE59428) { /* |x| >= 0.6744 */ if (hx < 0) { x = -x; @@ -144,10 +120,10 @@ __kernel_tan(double x, double y, int iy) /* compute -1.0 / (x+r) accurately */ double a, t; z = w; - SET_LOW_WORD(z, 0); + SET_LOW_WORD(z,0); v = r - (z - x); /* z+v = r+x */ t = a = -1.0 / w; /* a = -1.0/w */ - SET_LOW_WORD(t, 0); + SET_LOW_WORD(t,0); s = 1.0 + t * z; return t + a * (s + t * v); } diff --git a/lib/libm/src/k_tanf.c b/lib/libm/src/k_tanf.c index 21e2d2f273..96f53c6c90 100644 --- a/lib/libm/src/k_tanf.c +++ b/lib/libm/src/k_tanf.c @@ -11,10 +11,11 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 193368 (2009-06-03) + * + * $FreeBSD: head/lib/msun/src/k_tanf.c 239192 2012-08-11 11:13:48Z dim $ */ -#include +#include "math.h" #include "math_private.h" /* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ @@ -28,7 +29,10 @@ T[] = { 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ }; -__inline float +#ifdef INLINE_KERNEL_TANDF +static __inline +#endif +float __kernel_tandf(double x, int iy) { double z,r,w,s,t,u; diff --git a/lib/libm/src/math.h b/lib/libm/src/math.h new file mode 100644 index 0000000000..3768ac35b5 --- /dev/null +++ b/lib/libm/src/math.h @@ -0,0 +1,481 @@ +/* + * ==================================================== + * 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: head/lib/msun/src/math.h 238722 2012-07-23 19:13:55Z kargl $ + */ + +#ifndef _MATH_H_ +#define _MATH_H_ + +#include +#include +#include + +/* + * ANSI/POSIX + */ +extern const union __infinity_un { + unsigned char __uc[8]; + double __ud; +} __infinity; + +extern const union __nan_un { + unsigned char __uc[sizeof(float)]; + float __uf; +} __nan; + +#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __MATH_BUILTIN_CONSTANTS +#endif + +#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) +#define __MATH_BUILTIN_RELOPS +#endif + +#ifdef __MATH_BUILTIN_CONSTANTS +#define HUGE_VAL __builtin_huge_val() +#else +#define HUGE_VAL (__infinity.__ud) +#endif + +#if __ISO_C_VISIBLE >= 1999 +#define FP_ILOGB0 (-INT_MAX) +#define FP_ILOGBNAN INT_MAX + +#ifdef __MATH_BUILTIN_CONSTANTS +#define HUGE_VALF __builtin_huge_valf() +#define HUGE_VALL __builtin_huge_vall() +#define INFINITY __builtin_inff() +#define NAN __builtin_nanf("") +#else +#define HUGE_VALF (float)HUGE_VAL +#define HUGE_VALL (long double)HUGE_VAL +#define INFINITY HUGE_VALF +#define NAN (__nan.__uf) +#endif /* __MATH_BUILTIN_CONSTANTS */ + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#define math_errhandling MATH_ERREXCEPT + +#define FP_FAST_FMAF 1 + +/* Symbolic constants to classify floating point numbers. */ +#define FP_INFINITE 0x01 +#define FP_NAN 0x02 +#define FP_NORMAL 0x04 +#define FP_SUBNORMAL 0x08 +#define FP_ZERO 0x10 +#define fpclassify(x) \ + ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ + : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ + : __fpclassifyl(x)) + +#define isfinite(x) \ + ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \ + : (sizeof (x) == sizeof (double)) ? __isfinite(x) \ + : __isfinitel(x)) +#define isinf(x) \ + ((sizeof (x) == sizeof (float)) ? __isinff(x) \ + : (sizeof (x) == sizeof (double)) ? isinf(x) \ + : __isinfl(x)) +#define isnan(x) \ + ((sizeof (x) == sizeof (float)) ? __isnanf(x) \ + : (sizeof (x) == sizeof (double)) ? isnan(x) \ + : __isnanl(x)) +#define isnormal(x) \ + ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \ + : (sizeof (x) == sizeof (double)) ? __isnormal(x) \ + : __isnormall(x)) + +#ifdef __MATH_BUILTIN_RELOPS +#define isgreater(x, y) __builtin_isgreater((x), (y)) +#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) +#define isless(x, y) __builtin_isless((x), (y)) +#define islessequal(x, y) __builtin_islessequal((x), (y)) +#define islessgreater(x, y) __builtin_islessgreater((x), (y)) +#define isunordered(x, y) __builtin_isunordered((x), (y)) +#else +#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) +#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) +#define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) +#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) +#define islessgreater(x, y) (!isunordered((x), (y)) && \ + ((x) > (y) || (y) > (x))) +#define isunordered(x, y) (isnan(x) || isnan(y)) +#endif /* __MATH_BUILTIN_RELOPS */ + +#define signbit(x) \ + ((sizeof (x) == sizeof (float)) ? __signbitf(x) \ + : (sizeof (x) == sizeof (double)) ? __signbit(x) \ + : __signbitl(x)) + +#ifdef __LP64__ +typedef double double_t; +typedef float float_t; +#else +typedef long double double_t; +typedef long double float_t; +#endif /* __LP64__ */ +#endif /* __ISO_C_VISIBLE >= 1999 */ + +/* + * XOPEN/SVID + */ +#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 */ +#define M_LN2 0.69314718055994530942 /* log e2 */ +#define M_LN10 2.30258509299404568402 /* log e10 */ +#define M_PI 3.14159265358979323846 /* pi */ +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#define M_PI_4 0.78539816339744830962 /* pi/4 */ +#define M_1_PI 0.31830988618379067154 /* 1/pi */ +#define M_2_PI 0.63661977236758134308 /* 2/pi */ +#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ + +#define MAXFLOAT ((float)3.40282346638528860e+38) +extern int signgam; +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +#if __BSD_VISIBLE +#if 0 +/* Old value from 4.4BSD-Lite math.h; this is probably better. */ +#define HUGE HUGE_VAL +#else +#define HUGE MAXFLOAT +#endif +#endif /* __BSD_VISIBLE */ + +/* + * Most of these functions depend on the rounding mode and have the side + * 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 + */ +int __fpclassifyd(double) __pure2; +int __fpclassifyf(float) __pure2; +int __fpclassifyl(long double) __pure2; +int __isfinitef(float) __pure2; +int __isfinite(double) __pure2; +int __isfinitel(long double) __pure2; +int __isinff(float) __pure2; +int __isinfl(long double) __pure2; +int __isnanf(float) __pure2; +int __isnanl(long double) __pure2; +int __isnormalf(float) __pure2; +int __isnormal(double) __pure2; +int __isnormall(long double) __pure2; +int __signbit(double) __pure2; +int __signbitf(float) __pure2; +int __signbitl(long double) __pure2; + +double acos(double); +double asin(double); +double atan(double); +double atan2(double, double); +double cos(double); +double sin(double); +double tan(double); + +double cosh(double); +double sinh(double); +double tanh(double); + +double exp(double); +double frexp(double, int *); /* fundamentally !__pure2 */ +double ldexp(double, int); +double log(double); +double log10(double); +double modf(double, double *); /* fundamentally !__pure2 */ + +double pow(double, double); +double sqrt(double); + +double ceil(double); +double fabs(double) __pure2; +double floor(double); +double fmod(double, double); + +/* + * These functions are not in C90. + */ +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE +double acosh(double); +double asinh(double); +double atanh(double); +double cbrt(double); +double erf(double); +double erfc(double); +double exp2(double); +double expm1(double); +double fma(double, double, double); +double hypot(double, double); +int ilogb(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); +double nan(const char *) __pure2; +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 */ + +#if __BSD_VISIBLE || __XSI_VISIBLE +double j0(double); +double j1(double); +double jn(int, double); +double y0(double); +double y1(double); +double yn(int, double); + +#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE +double gamma(double); +#endif + +#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; +double fmin(double, double) __pure2; +double nearbyint(double); +double round(double); +double scalbln(double, long); +double scalbn(double, int); +double tgamma(double); +double trunc(double); +#endif + +/* + * BSD math library entry points + */ +#if __BSD_VISIBLE +double drem(double, double); +int finite(double) __pure2; +int isnanf(float) __pure2; + +/* + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +double gamma_r(double, int *); +double lgamma_r(double, int *); + +/* + * IEEE Test Vector + */ +double significand(double); +#endif /* __BSD_VISIBLE */ + +/* float versions of ANSI/POSIX functions */ +#if __ISO_C_VISIBLE >= 1999 +float acosf(float); +float asinf(float); +float atanf(float); +float atan2f(float, float); +float cosf(float); +float sinf(float); +float tanf(float); + +float coshf(float); +float sinhf(float); +float tanhf(float); + +float exp2f(float); +float expf(float); +float expm1f(float); +float frexpf(float, int *); /* fundamentally !__pure2 */ +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 */ + +float powf(float, float); +float sqrtf(float); + +float ceilf(float); +float fabsf(float) __pure2; +float floorf(float); +float fmodf(float, float); +float roundf(float); + +float erff(float); +float erfcf(float); +float hypotf(float, float); +float lgammaf(float); +float tgammaf(float); + +float acoshf(float); +float asinhf(float); +float atanhf(float); +float cbrtf(float); +float logbf(float); +float copysignf(float, float) __pure2; +long long llrintf(float); +long long llroundf(float); +long lrintf(float); +long lroundf(float); +float nanf(const char *) __pure2; +float nearbyintf(float); +float nextafterf(float, float); +float remainderf(float, float); +float remquof(float, float, int *); +float rintf(float); +float scalblnf(float, long); +float scalbnf(float, int); +float truncf(float); + +float fdimf(float, float); +float fmaf(float, float, float); +float fmaxf(float, float) __pure2; +float fminf(float, float) __pure2; +#endif + +/* + * float versions of BSD math library entry points + */ +#if __BSD_VISIBLE +float dremf(float, float); +int finitef(float) __pure2; +float gammaf(float); +float j0f(float); +float j1f(float); +float jnf(int, float); +float scalbf(float, float); +float y0f(float); +float y1f(float); +float ynf(int, float); + +/* + * Float versions of reentrant version of gamma & lgamma; passes + * signgam back by reference as the second argument; user must + * allocate space for signgam. + */ +float gammaf_r(float, int *); +float lgammaf_r(float, int *); + +/* + * float version of IEEE Test Vector + */ +float significandf(float); +#endif /* __BSD_VISIBLE */ + +/* + * long double versions of ISO/POSIX math functions + */ +#if __ISO_C_VISIBLE >= 1999 +long double acosl(long double); +long double asinl(long double); +long double atan2l(long double, long double); +long double atanl(long double); +long double cbrtl(long double); +long double ceill(long double); +long double copysignl(long double, long double) __pure2; +long double cosl(long double); +long double exp2l(long double); +long double expl(long double); +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; +long double fmodl(long double, long double); +long double frexpl(long double value, int *); /* fundamentally !__pure2 */ +long double hypotl(long double, long double); +int ilogbl(long double) __pure2; +long double ldexpl(long double, int); +long long llrintl(long double); +long long llroundl(long double); +long double logbl(long double); +long lrintl(long double); +long lroundl(long double); +long double modfl(long double, long double *); /* fundamentally !__pure2 */ +long double nanl(const char *) __pure2; +long double nearbyintl(long double); +long double nextafterl(long double, long double); +double nexttoward(double, long double); +float nexttowardf(float, long double); +long double nexttowardl(long double, long double); +long double remainderl(long double, long double); +long double remquol(long double, long double, int *); +long double rintl(long double); +long double roundl(long double); +long double scalblnl(long double, long); +long double scalbnl(long double, int); +long double sinl(long double); +long double sqrtl(long double); +long double tanl(long double); +long double truncl(long double); + +#endif /* __ISO_C_VISIBLE >= 1999 */ +__END_DECLS + +#endif /* !_MATH_H_ */ + +/* separate header for cmath */ +#ifndef _MATH_EXTRA_H_ +#if __ISO_C_VISIBLE >= 1999 +#if _DECLARE_C99_LDBL_MATH + +#define _MATH_EXTRA_H_ + +/* + * extra long double versions of math functions for C99 and cmath + */ +__BEGIN_DECLS + +long double acoshl(long double); +long double asinhl(long double); +long double atanhl(long double); +long double coshl(long double); +long double erfcl(long double); +long double erfl(long double); +long double expm1l(long double); +long double lgammal(long double); +long double log10l(long double); +long double log1pl(long double); +long double log2l(long double); +long double logl(long double); +long double powl(long double, long double); +long double sinhl(long double); +long double tanhl(long double); +long double tgammal(long double); + +__END_DECLS + +#endif /* !_DECLARE_C99_LDBL_MATH */ +#endif /* __ISO_C_VISIBLE >= 1999 */ +#endif /* !_MATH_EXTRA_H_ */ diff --git a/lib/libm/src/math_private.h b/lib/libm/src/math_private.h index d1ee45b540..34e8f5967a 100644 --- a/lib/libm/src/math_private.h +++ b/lib/libm/src/math_private.h @@ -11,34 +11,36 @@ /* * from: @(#)fdlibm.h 5.1 93/09/24 - * $NetBSD: math_private.h,v 1.16 2010/09/16 20:39:50 drochner Exp $ + * $FreeBSD: head/lib/msun/src/math_private.h 241051 2012-09-29 16:40:12Z kargl $ */ #ifndef _MATH_PRIVATE_H_ -#define _MATH_PRIVATE_H_ +#define _MATH_PRIVATE_H_ #include +#include -/* 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. */ +/* + * 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. + */ /* - * The ARM ports are little endian except for the FPA word order which is - * big endian. + * A union which permits us to convert between a double and two 32 bit + * ints. */ -#if BYTE_ORDER == BIG_ENDIAN +#define IEEE_WORD_ORDER BYTE_ORDER + +#if IEEE_WORD_ORDER == BIG_ENDIAN typedef union { @@ -56,7 +58,7 @@ typedef union #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if IEEE_WORD_ORDER == LITTLE_ENDIAN typedef union { @@ -82,12 +84,9 @@ do { \ ew_u.value = (d); \ (ix0) = ew_u.parts.msw; \ (ix1) = ew_u.parts.lsw; \ -} while (/*CONSTCOND*/0) +} while (0) -/* - * Get a 64-bit int from a double. - * Origin: FreeBSD msun/src/math_private.h - */ +/* Get a 64-bit int from a double. */ #define EXTRACT_WORD64(ix,d) \ do { \ ieee_double_shape_type ew_u; \ @@ -102,7 +101,7 @@ do { \ ieee_double_shape_type gh_u; \ gh_u.value = (d); \ (i) = gh_u.parts.msw; \ -} while (/*CONSTCOND*/0) +} while (0) /* Get the less significant 32 bit int from a double. */ @@ -111,7 +110,7 @@ do { \ ieee_double_shape_type gl_u; \ gl_u.value = (d); \ (i) = gl_u.parts.lsw; \ -} while (/*CONSTCOND*/0) +} while (0) /* Set a double from two 32 bit ints. */ @@ -121,12 +120,9 @@ do { \ iw_u.parts.msw = (ix0); \ iw_u.parts.lsw = (ix1); \ (d) = iw_u.value; \ -} while (/*CONSTCOND*/0) +} while (0) -/* - * Set a double from a 64-bit int. - * Origin: FreeBSD msun/src/math_private.h - */ +/* Set a double from a 64-bit int. */ #define INSERT_WORD64(d,ix) \ do { \ ieee_double_shape_type iw_u; \ @@ -142,7 +138,7 @@ do { \ sh_u.value = (d); \ sh_u.parts.msw = (v); \ (d) = sh_u.value; \ -} while (/*CONSTCOND*/0) +} while (0) /* Set the less significant 32 bits of a double from an int. */ @@ -152,15 +148,18 @@ do { \ sl_u.value = (d); \ sl_u.parts.lsw = (v); \ (d) = sl_u.value; \ -} while (/*CONSTCOND*/0) +} while (0) -/* A union which permits us to convert between a float and a 32 bit - int. */ +/* + * A union which permits us to convert between a float and a 32 bit + * int. + */ typedef union { float value; - u_int32_t word; + /* FIXME: Assumes 32 bit int. */ + unsigned int word; } ieee_float_shape_type; /* Get a 32 bit int from a float. */ @@ -170,7 +169,7 @@ do { \ ieee_float_shape_type gf_u; \ gf_u.value = (d); \ (i) = gf_u.word; \ -} while (/*CONSTCOND*/0) +} while (0) /* Set a float from a 32 bit int. */ @@ -179,23 +178,18 @@ do { \ ieee_float_shape_type sf_u; \ sf_u.word = (i); \ (d) = sf_u.value; \ -} while (/*CONSTCOND*/0) +} while (0) -/* - * Get expsign as a 16 bit int from a long double. - * Origin: FreeBSD msun/src/math_private.h - */ +/* 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 (/*CONSTCOND*/0) +} while (0) -/* - * Set expsign of a long double from a 16 bit int. - */ +/* Set expsign of a long double from a 16 bit int. */ #define SET_LDBL_EXPSIGN(d,v) \ do { \ @@ -203,8 +197,20 @@ do { \ se_u.e = (d); \ se_u.xbits.expsign = (v); \ (d) = se_u.e; \ -} while (/*CONSTCOND*/0) +} 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. */ @@ -214,43 +220,64 @@ do { \ #define STRICT_ASSIGN(type, lval, rval) do { \ volatile type __lval; \ \ - if (sizeof(type) >= sizeof(double)) \ + if (sizeof(type) >= sizeof(long double)) \ (lval) = (rval); \ else { \ __lval = (rval); \ (lval) = __lval; \ } \ -} while (/*CONSTCOND*/0) +} 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 -#ifdef _COMPLEX_H +/* Default return statement if hack*_t() is not used. */ +#define RETURNF(v) return (v) /* - * Quoting from ISO/IEC 9899:TC2: - * - * 6.2.5.13 Types - * Each complex type has the same representation and alignment requirements as - * an array type containing exactly two elements of the corresponding real type; - * the first element is equal to the real part, and the second element to the - * imaginary part, of the complex number. + * 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 z; - float parts[2]; + float complex f; + float a[2]; } float_complex; - typedef union { - double complex z; - double parts[2]; + double complex f; + double a[2]; } double_complex; - typedef union { - long double complex z; - long double parts[2]; + long double complex f; + long double a[2]; } long_double_complex; - -#define REAL_PART(z) ((z).parts[0]) -#define IMAG_PART(z) ((z).parts[1]) +#define REALPART(z) ((z).a[0]) +#define IMAGPART(z) ((z).a[1]) /* * Inline functions that can be used to construct complex values. @@ -265,59 +292,171 @@ typedef union { static __inline float complex cpackf(float x, float y) { - float_complex fc; + float_complex z; - REAL_PART(fc) = x; - IMAG_PART(fc) = y; - return (fc.z); + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); } static __inline double complex cpack(double x, double y) { - double_complex dc; + double_complex z; - REAL_PART(dc) = x; - IMAG_PART(dc) = y; - return (dc.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 ldc; + long_double_complex z; + + REALPART(z) = x; + IMAGPART(z) = y; + return (z.f); +} +#endif /* _COMPLEX_H */ + +#ifdef __GNUC__ + +/* Asm versions of some functions. */ + +#ifdef __x86_64__ +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; - REAL_PART(ldc) = x; - IMAG_PART(ldc) = y; - return (ldc.z); + asm("fistl %0" : "=m" (n) : "t" (x)); + return (n); } +#define HAVE_EFFICIENT_IRINT +#endif -#endif /* _COMPLEX_H */ +static __inline int +irintl(long double x) +{ + int n; + + asm("fistl %0" : "=m" (n) : "t" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINTL -__BEGIN_DECLS -#pragma GCC visibility push(hidden) +#endif /* __GNUC__ */ + +/* + * 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 */ -int __libm_rem_pio2(double, double*); -double __kernel_sin(double, double, int); -double __kernel_cos(double, double); -double __kernel_tan(double, double, int); +#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 */ -int __libm_rem_pio2f(float,double*); +#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); -float __kernel_tandf(double, int); +#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); -#pragma GCC visibility pop -__END_DECLS - -#endif /* _MATH_PRIVATE_H_ */ +#endif /* !_MATH_PRIVATE_H_ */ diff --git a/lib/libm/src/s_asinh.c b/lib/libm/src/s_asinh.c index 02f3ad1c02..50720bc6f3 100644 --- a/lib/libm/src/s_asinh.c +++ b/lib/libm/src/s_asinh.c @@ -1,4 +1,5 @@ /* @(#)s_asinh.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_asinh.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_asinh.c,v 1.12 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_asinh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* asinh(x) @@ -24,7 +22,7 @@ * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) */ -#include +#include "math.h" #include "math_private.h" static const double @@ -44,13 +42,13 @@ asinh(double x) if(huge+x>one) return x; /* return x inexact except 0 */ } if(ix>0x41b00000) { /* |x| > 2**28 */ - w = log(fabs(x))+ln2; + w = __ieee754_log(fabs(x))+ln2; } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ t = fabs(x); - w = log(2.0*t+one/(sqrt(x*x+one)+t)); + w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t)); } else { /* 2.0 > |x| > 2**-28 */ t = x*x; - w =log1p(fabs(x)+t/(one+sqrt(one+t))); + w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t))); } if(hx>0) return w; else return -w; } diff --git a/lib/libm/src/s_asinhf.c b/lib/libm/src/s_asinhf.c index 5908cd816f..a1731c8ea9 100644 --- a/lib/libm/src/s_asinhf.c +++ b/lib/libm/src/s_asinhf.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: s_asinhf.c,v 1.8 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_asinhf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_asinhf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float @@ -36,13 +35,13 @@ asinhf(float x) if(huge+x>one) return x; /* return x inexact except 0 */ } if(ix>0x4d800000) { /* |x| > 2**28 */ - w = logf(fabsf(x))+ln2; + w = __ieee754_logf(fabsf(x))+ln2; } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ t = fabsf(x); - w = logf((float)2.0*t+one/(sqrtf(x*x+one)+t)); + w = __ieee754_logf((float)2.0*t+one/(__ieee754_sqrtf(x*x+one)+t)); } else { /* 2.0 > |x| > 2**-28 */ t = x*x; - w =log1pf(fabsf(x)+t/(one+sqrtf(one+t))); + w =log1pf(fabsf(x)+t/(one+__ieee754_sqrtf(one+t))); } if(hx>0) return w; else return -w; } diff --git a/lib/libm/src/s_atan.c b/lib/libm/src/s_atan.c index cceeeb09e9..d82e644496 100644 --- a/lib/libm/src/s_atan.c +++ b/lib/libm/src/s_atan.c @@ -1,4 +1,5 @@ /* @(#)s_atan.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_atan.c 218509 2011-02-10 07:37:50Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_atan.c,v 1.11 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_atan.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* atan(x) @@ -33,7 +31,9 @@ * to produce the hexadecimal values shown. */ -#include +#include + +#include "math.h" #include "math_private.h" static const double atanhi[] = { @@ -82,10 +82,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; @@ -116,3 +116,7 @@ atan(double x) return (hx<0)? -z:z; } } + +#if LDBL_MANT_DIG == 53 +__weak_reference(atan, atanl); +#endif diff --git a/lib/libm/src/s_atanf.c b/lib/libm/src/s_atanf.c index 573d5cdb3c..2e0a0388f4 100644 --- a/lib/libm/src/s_atanf.c +++ b/lib/libm/src/s_atanf.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: s_atanf.c,v 1.7 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_atanf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_atanf.c 181100 2008-08-01 01:24:25Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float atanhi[] = { @@ -34,17 +33,11 @@ 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 @@ -59,13 +52,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; @@ -80,7 +73,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; } }} @@ -88,8 +81,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/lib/libm/src/s_atanl.c b/lib/libm/src/s_atanl.c index a030c21263..08713016ac 100644 --- a/lib/libm/src/s_atanl.c +++ b/lib/libm/src/s_atanl.c @@ -1,5 +1,5 @@ /* @(#)s_atan.c 5.1 93/09/24 */ -/* FreeBSD: head/lib/msun/src/s_atan.c 176451 2008-02-22 02:30:36Z das */ +/* $FreeBSD: head/lib/msun/src/s_atanl.c 181074 2008-07-31 22:41:26Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. diff --git a/lib/libm/complex/s_cargl.c b/lib/libm/src/s_carg.c similarity index 87% copy from lib/libm/complex/s_cargl.c copy to lib/libm/src/s_carg.c index e0cbd7aeda..ee9eace469 100644 --- a/lib/libm/complex/s_cargl.c +++ b/lib/libm/src/s_carg.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,15 +23,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181074 (2008-07-31) + * $FreeBSD: head/lib/msun/src/s_carg.c 174561 2007-12-12 23:43:51Z das $ */ #include #include -long double -cargl(long double complex z) +double +carg(double complex z) { - return (atan2l(cimagl(z), creall(z))); + return (atan2(cimag(z), creal(z))); } diff --git a/lib/libm/complex/s_cargl.c b/lib/libm/src/s_cargf.c similarity index 87% copy from lib/libm/complex/s_cargl.c copy to lib/libm/src/s_cargf.c index e0cbd7aeda..b1c36a6793 100644 --- a/lib/libm/complex/s_cargl.c +++ b/lib/libm/src/s_cargf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,15 +23,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181074 (2008-07-31) + * $FreeBSD: head/lib/msun/src/s_cargf.c 174561 2007-12-12 23:43:51Z das $ */ #include #include -long double -cargl(long double complex z) +float +cargf(float complex z) { - return (atan2l(cimagl(z), creall(z))); + return (atan2f(cimagf(z), crealf(z))); } diff --git a/lib/libm/complex/s_cargl.c b/lib/libm/src/s_cargl.c similarity index 95% copy from lib/libm/complex/s_cargl.c copy to lib/libm/src/s_cargl.c index e0cbd7aeda..c604930527 100644 --- a/lib/libm/complex/s_cargl.c +++ b/lib/libm/src/s_cargl.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181074 (2008-07-31) + * $FreeBSD: head/lib/msun/src/s_cargl.c 183714 2008-10-09 02:25:18Z peter $ */ #include diff --git a/lib/libm/src/s_cbrt.c b/lib/libm/src/s_cbrt.c index 1bfcaed433..3c8bd904a6 100644 --- a/lib/libm/src/s_cbrt.c +++ b/lib/libm/src/s_cbrt.c @@ -1,4 +1,5 @@ /* @(#)s_cbrt.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_cbrt.c 219571 2011-03-12 16:50:39Z kargl $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -10,13 +11,9 @@ * ==================================================== * * Optimized by Bruce D. Evans. - * - * $FreeBSD: src/lib/msun/src/s_cbrt.c,v 1.14 2005/12/20 01:21:30 bde Exp $ - * $NetBSD: s_cbrt.c,v 1.11 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_cbrt.c,v 1.2 2007/07/03 04:54:07 pavalos Exp $ */ -#include +#include "math.h" #include "math_private.h" /* cbrt(x) @@ -95,7 +92,7 @@ cbrt(double x) * 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 the final error + * 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. */ @@ -112,3 +109,7 @@ cbrt(double x) return(t); } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(cbrt, cbrtl); +#endif diff --git a/lib/libm/src/s_cbrtf.c b/lib/libm/src/s_cbrtf.c index 325a989c84..62f849b0e2 100644 --- a/lib/libm/src/s_cbrtf.c +++ b/lib/libm/src/s_cbrtf.c @@ -13,12 +13,10 @@ * is preserved. * ==================================================== * - * $FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.17 2007/05/29 07:13:07 bde Exp $ - * $NetBSD: s_cbrtf.c,v 1.7 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_cbrtf.c,v 1.2 2007/07/03 04:54:07 pavalos Exp $ + * $FreeBSD: head/lib/msun/src/s_cbrtf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" /* cbrtf(x) diff --git a/lib/libm/src/s_cbrtl.c b/lib/libm/src/s_cbrtl.c index c9ae65b7e2..fa9a027e3f 100644 --- a/lib/libm/src/s_cbrtl.c +++ b/lib/libm/src/s_cbrtl.c @@ -13,14 +13,16 @@ * written by Steven G. Kargl with input from Bruce D. Evans * and David A. Schultz. * - * FreeBSD SVN: 219576 (2011-03-12) + * $FreeBSD: head/lib/msun/src/s_cbrtl.c 238924 2012-07-30 21:58:28Z kargl $ */ #include -#include +#ifdef __i386__ #include +#endif -#include "fpmath.h" +#include "fpmath.h" +#include "math.h" #include "math_private.h" #define BIAS (LDBL_MAX_EXP - 1) @@ -50,23 +52,11 @@ cbrtl(long double x) if (k == BIAS + LDBL_MAX_EXP) return (x + x); -#ifdef __i386__ - fp_prec_t oprec; - - oprec = fpgetprec(); - if (oprec != FP_PE) - fpsetprec(FP_PE); -#endif - + ENTERI(); if (k == 0) { /* If x = +-0, then cbrt(x) = +-0. */ - if ((u.bits.manh | u.bits.manl) == 0) { -#ifdef __i386__ - if (oprec != FP_PE) - fpsetprec(oprec); -#endif - return (x); - } + if ((u.bits.manh | u.bits.manl) == 0) + RETURNI(x); /* Adjust subnormal numbers. */ u.e *= 0x1.0p514; k = u.bits.exp; @@ -74,7 +64,7 @@ cbrtl(long double x) } else k -= BIAS; u.xbits.expsign = BIAS; - v.e = 1; + v.e = 1; x = u.e; switch (k % 3) { @@ -112,6 +102,7 @@ cbrtl(long double x) 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 @@ -122,6 +113,19 @@ cbrtl(long double x) #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 @@ -134,9 +138,5 @@ cbrtl(long double x) t=t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ t *= v.e; -#ifdef __i386__ - if (oprec != FP_PE) - fpsetprec(oprec); -#endif - return (t); + RETURNI(t); } diff --git a/lib/libm/src/s_ccosh.c b/lib/libm/src/s_ccosh.c new file mode 100644 index 0000000000..71a0d6d02f --- /dev/null +++ b/lib/libm/src/s_ccosh.c @@ -0,0 +1,154 @@ +/*- + * 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. + * + * $FreeBSD: head/lib/msun/src/s_ccosh.c 226599 2011-10-21 06:29:32Z das $ + */ + +/* + * 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 +#include + +#include "math_private.h" + +static const double huge = 0x1p1023; + +double complex +ccosh(double complex z) +{ + double x, y, h; + int32_t hx, hy, ix, iy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + EXTRACT_WORDS(hy, ly, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + /* Handle the nearly-non-exceptional cases where x and y are finite. */ + if (ix < 0x7ff00000 && iy < 0x7ff00000) { + if ((iy | ly) == 0) + return (cpack(cosh(x), x * y)); + if (ix < 0x40360000) /* small x: normal case */ + return (cpack(cosh(x) * cos(y), sinh(x) * sin(y))); + + /* |x| >= 22, so cosh(x) ~= exp(|x|) */ + if (ix < 0x40862e42) { + /* x < 710: exp(|x|) won't overflow */ + h = exp(fabs(x)) * 0.5; + return (cpack(h * cos(y), copysign(h, x) * sin(y))); + } else if (ix < 0x4096bbaa) { + /* x < 1455: scale to avoid overflow */ + z = __ldexp_cexp(cpack(fabs(x), y), -1); + return (cpack(creal(z), cimag(z) * copysign(1, x))); + } else { + /* x >= 1455: the result always overflows */ + h = huge * x; + return (cpack(h * h * cos(y), h * sin(y))); + } + } + + /* + * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as dNaN. Raise the invalid floating-point exception. + * + * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as d(NaN). + */ + if ((ix | lx) == 0 && iy >= 0x7ff00000) + return (cpack(y - y, copysign(0, x * (y - y)))); + + /* + * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. + * + * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. + * The sign of 0 in the result is unspecified. + */ + if ((iy | ly) == 0 && ix >= 0x7ff00000) { + if (((hx & 0xfffff) | lx) == 0) + return (cpack(x * x, copysign(0, x) * y)); + return (cpack(x * x, copysign(0, (x + x) * y))); + } + + /* + * cosh(x +- I Inf) = dNaN + I dNaN. + * Raise the invalid floating-point exception for finite nonzero x. + * + * cosh(x + I NaN) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero x. Choice = don't raise (except for signaling NaNs). + */ + if (ix < 0x7ff00000 && iy >= 0x7ff00000) + return (cpack(y - y, x * (y - y))); + + /* + * cosh(+-Inf + I NaN) = +Inf + I d(NaN). + * + * cosh(+-Inf +- I Inf) = +Inf + I dNaN. + * The sign of Inf in the result is unspecified. Choice = always +. + * Raise the invalid floating-point exception. + * + * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) + */ + if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { + if (iy >= 0x7ff00000) + return (cpack(x * x, x * (y - y))); + return (cpack((x * x) * cos(y), x * sin(y))); + } + + /* + * cosh(NaN + I NaN) = d(NaN) + I d(NaN). + * + * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception. + * Choice = raise. + * + * cosh(NaN + I y) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero y. Choice = don't raise (except for signaling NaNs). + */ + return (cpack((x * x) * (y - y), (x + x) * (y - y))); +} + +double complex +ccos(double complex z) +{ + + /* ccos(z) = ccosh(I * z) */ + return (ccosh(cpack(-cimag(z), creal(z)))); +} diff --git a/lib/libm/src/s_ccoshf.c b/lib/libm/src/s_ccoshf.c new file mode 100644 index 0000000000..335274606c --- /dev/null +++ b/lib/libm/src/s_ccoshf.c @@ -0,0 +1,103 @@ +/*- + * 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. + * + * $FreeBSD: head/lib/msun/src/s_ccoshf.c 226599 2011-10-21 06:29:32Z das $ + */ + +/* + * Hyperbolic cosine of a complex argument. See s_ccosh.c for details. + */ + +#include +#include + +#include "math_private.h" + +static const float huge = 0x1p127; + +float complex +ccoshf(float complex z) +{ + float x, y, h; + int32_t hx, hy, ix, iy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hx, x); + GET_FLOAT_WORD(hy, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + if (ix < 0x7f800000 && iy < 0x7f800000) { + if (iy == 0) + return (cpackf(coshf(x), x * y)); + if (ix < 0x41100000) /* small x: normal case */ + return (cpackf(coshf(x) * cosf(y), sinhf(x) * sinf(y))); + + /* |x| >= 9, so cosh(x) ~= exp(|x|) */ + if (ix < 0x42b17218) { + /* x < 88.7: expf(|x|) won't overflow */ + h = expf(fabsf(x)) * 0.5f; + return (cpackf(h * cosf(y), copysignf(h, x) * sinf(y))); + } else if (ix < 0x4340b1e7) { + /* x < 192.7: scale to avoid overflow */ + z = __ldexp_cexpf(cpackf(fabsf(x), y), -1); + return (cpackf(crealf(z), cimagf(z) * copysignf(1, x))); + } else { + /* x >= 192.7: the result always overflows */ + h = huge * x; + return (cpackf(h * h * cosf(y), h * sinf(y))); + } + } + + if (ix == 0 && iy >= 0x7f800000) + return (cpackf(y - y, copysignf(0, x * (y - y)))); + + if (iy == 0 && ix >= 0x7f800000) { + if ((hx & 0x7fffff) == 0) + return (cpackf(x * x, copysignf(0, x) * y)); + return (cpackf(x * x, copysignf(0, (x + x) * y))); + } + + if (ix < 0x7f800000 && iy >= 0x7f800000) + return (cpackf(y - y, x * (y - y))); + + if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { + if (iy >= 0x7f800000) + return (cpackf(x * x, x * (y - y))); + return (cpackf((x * x) * cosf(y), x * sinf(y))); + } + + return (cpackf((x * x) * (y - y), (x + x) * (y - y))); +} + +float complex +ccosf(float complex z) +{ + + return (ccoshf(cpackf(-cimagf(z), crealf(z)))); +} diff --git a/lib/libm/src/s_ceil.c b/lib/libm/src/s_ceil.c index e2a29c0648..bd5eb13d12 100644 --- a/lib/libm/src/s_ceil.c +++ b/lib/libm/src/s_ceil.c @@ -1,4 +1,5 @@ /* @(#)s_ceil.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_ceil.c 176305 2008-02-15 07:01:40Z bde $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_ceil.c,v 1.13 2009/02/16 01:22:18 lukem Exp $ */ /* @@ -21,7 +20,9 @@ * Inexact flag raised if x not equal to ceil(x). */ -#include +#include + +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; @@ -29,36 +30,36 @@ static const double huge = 1.0e300; double ceil(double x) { - int32_t i0,i1,jj0; + int32_t i0,i1,j0; u_int32_t i,j; EXTRACT_WORDS(i0,i1,x); - jj0 = ((i0>>20)&0x7ff)-0x3ff; - if(jj0<20) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ if(i0<0) {i0=0x80000000;i1=0;} else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} } } else { - i = (0x000fffff)>>jj0; + i = (0x000fffff)>>j0; if(((i0&i)|i1)==0) return x; /* x is integral */ if(huge+x>0.0) { /* raise inexact flag */ - if(i0>0) i0 += (0x00100000)>>jj0; + if(i0>0) i0 += (0x00100000)>>j0; i0 &= (~i); i1=0; } } - } else if (jj0>51) { - if(jj0==0x400) return x+x; /* inf or NaN */ + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ else return x; /* x is integral */ } else { - i = ((u_int32_t)(0xffffffff))>>(jj0-20); + i = ((u_int32_t)(0xffffffff))>>(j0-20); if((i1&i)==0) return x; /* x is integral */ if(huge+x>0.0) { /* raise inexact flag */ if(i0>0) { - if(jj0==20) i0+=1; + if(j0==20) i0+=1; else { - j = i1 + (1<<(52-jj0)); - if(j<(u_int32_t)i1) i0+=1; /* got a carry */ + j = i1 + (1<<(52-j0)); + if(j +#include "math.h" #include "math_private.h" static const float huge = 1.0e30; @@ -23,27 +23,27 @@ static const float huge = 1.0e30; float ceilf(float x) { - int32_t i0,jj0; + int32_t i0,j0; u_int32_t i; GET_FLOAT_WORD(i0,x); - jj0 = ((i0>>23)&0xff)-0x7f; - if(jj0<23) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ if(i0<0) {i0=0x80000000;} else if(i0!=0) { i0=0x3f800000;} } } else { - i = (0x007fffff)>>jj0; + i = (0x007fffff)>>j0; if((i0&i)==0) return x; /* x is integral */ if(huge+x>(float)0.0) { /* raise inexact flag */ - if(i0>0) i0 += (0x00800000)>>jj0; + if(i0>0) i0 += (0x00800000)>>j0; i0 &= (~i); } } } else { - if(jj0==0x80) return x+x; /* inf or NaN */ + if(j0==0x80) return x+x; /* inf or NaN */ else return x; /* x is integral */ } SET_FLOAT_WORD(x,i0); diff --git a/lib/libm/src/s_ceill.c b/lib/libm/src/s_ceill.c index 6838e12ea5..e1c5acb13a 100644 --- a/lib/libm/src/s_ceill.c +++ b/lib/libm/src/s_ceill.c @@ -9,7 +9,7 @@ * ==================================================== * * From: @(#)s_ceil.c 5.1 93/09/24 - * FreeBSD SVN: 176280 (2008-02-14) + * $FreeBSD: head/lib/msun/src/s_ceill.c 176280 2008-02-14 15:10:34Z bde $ */ /* diff --git a/lib/libm/src/s_cexp.c b/lib/libm/src/s_cexp.c new file mode 100644 index 0000000000..ee4be046b4 --- /dev/null +++ b/lib/libm/src/s_cexp.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/lib/msun/src/s_cexp.c 226597 2011-10-21 06:27:56Z das $ + */ + +#include +#include + +#include "math_private.h" + +static const uint32_t +exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */ +cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ + +double complex +cexp(double complex z) +{ + double x, y, exp_x; + uint32_t hx, hy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hy, ly, y); + hy &= 0x7fffffff; + + /* cexp(x + I 0) = exp(x) + I 0 */ + if ((hy | ly) == 0) + return (cpack(exp(x), y)); + EXTRACT_WORDS(hx, lx, x); + /* cexp(0 + I y) = cos(y) + I sin(y) */ + if (((hx & 0x7fffffff) | lx) == 0) + return (cpack(cos(y), sin(y))); + + if (hy >= 0x7ff00000) { + if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) { + /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ + return (cpack(y - y, y - y)); + } else if (hx & 0x80000000) { + /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ + return (cpack(0.0, 0.0)); + } else { + /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ + return (cpack(x, y - y)); + } + } + + if (hx >= exp_ovfl && hx <= cexp_ovfl) { + /* + * x is between 709.7 and 1454.3, so we must scale to avoid + * overflow in exp(x). + */ + return (__ldexp_cexp(z, 0)); + } else { + /* + * Cases covered here: + * - x < exp_ovfl and exp(x) won't overflow (common case) + * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 + * - x = +-Inf (generated by exp()) + * - x = NaN (spurious inexact exception from y) + */ + exp_x = exp(x); + return (cpack(exp_x * cos(y), exp_x * sin(y))); + } +} diff --git a/lib/libm/src/s_cexpf.c b/lib/libm/src/s_cexpf.c new file mode 100644 index 0000000000..6902de0610 --- /dev/null +++ b/lib/libm/src/s_cexpf.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2011 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/lib/msun/src/s_cexpf.c 226597 2011-10-21 06:27:56Z das $ + */ + +#include +#include + +#include "math_private.h" + +static const uint32_t +exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */ +cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ + +float complex +cexpf(float complex z) +{ + float x, y, exp_x; + uint32_t hx, hy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hy, y); + hy &= 0x7fffffff; + + /* cexp(x + I 0) = exp(x) + I 0 */ + if (hy == 0) + return (cpackf(expf(x), y)); + GET_FLOAT_WORD(hx, x); + /* cexp(0 + I y) = cos(y) + I sin(y) */ + if ((hx & 0x7fffffff) == 0) + return (cpackf(cosf(y), sinf(y))); + + if (hy >= 0x7f800000) { + if ((hx & 0x7fffffff) != 0x7f800000) { + /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ + return (cpackf(y - y, y - y)); + } else if (hx & 0x80000000) { + /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ + return (cpackf(0.0, 0.0)); + } else { + /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ + return (cpackf(x, y - y)); + } + } + + if (hx >= exp_ovfl && hx <= cexp_ovfl) { + /* + * x is between 88.7 and 192, so we must scale to avoid + * overflow in expf(x). + */ + return (__ldexp_cexpf(z, 0)); + } else { + /* + * Cases covered here: + * - x < exp_ovfl and exp(x) won't overflow (common case) + * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 + * - x = +-Inf (generated by exp()) + * - x = NaN (spurious inexact exception from y) + */ + exp_x = expf(x); + return (cpackf(exp_x * cosf(y), exp_x * sinf(y))); + } +} diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_cimag.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_cimag.c index a209a1e233..ce742f249d 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_cimag.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_cimag.c 189803 2009-03-14 18:24:15Z das $ */ -#include +#include +#include "math_private.h" -#include "fpmath.h" - -long double -copysignl(long double x, long double y) +double +cimag(double complex z) { - union IEEEl2bits ux, uy; + const double_complex z1 = { .f = z }; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (IMAGPART(z1)); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_cimagf.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_cimagf.c index a209a1e233..f0619659ac 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_cimagf.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_cimagf.c 189803 2009-03-14 18:24:15Z das $ */ -#include +#include +#include "math_private.h" -#include "fpmath.h" - -long double -copysignl(long double x, long double y) +float +cimagf(float complex z) { - union IEEEl2bits ux, uy; + const float_complex z1 = { .f = z }; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (IMAGPART(z1)); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_cimagl.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_cimagl.c index a209a1e233..771e63ab0a 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_cimagl.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_cimagl.c 189803 2009-03-14 18:24:15Z das $ */ -#include - -#include "fpmath.h" +#include +#include "math_private.h" long double -copysignl(long double x, long double y) +cimagl(long double complex z) { - union IEEEl2bits ux, uy; + const long_double_complex z1 = { .f = z }; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (IMAGPART(z1)); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_conj.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_conj.c index a209a1e233..8556610427 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_conj.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_conj.c 181374 2008-08-07 14:39:56Z das $ */ -#include +#include -#include "fpmath.h" +#include "math_private.h" -long double -copysignl(long double x, long double y) +double complex +conj(double complex z) { - union IEEEl2bits ux, uy; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (cpack(creal(z), -cimag(z))); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_conjf.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_conjf.c index a209a1e233..ef8be7fd98 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_conjf.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_conjf.c 181374 2008-08-07 14:39:56Z das $ */ -#include +#include -#include "fpmath.h" +#include "math_private.h" -long double -copysignl(long double x, long double y) +float complex +conjf(float complex z) { - union IEEEl2bits ux, uy; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (cpackf(crealf(z), -cimagf(z))); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_conjl.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_conjl.c index a209a1e233..483f621913 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_conjl.c @@ -23,20 +23,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_conjl.c 181374 2008-08-07 14:39:56Z das $ */ -#include +#include -#include "fpmath.h" +#include "math_private.h" -long double -copysignl(long double x, long double y) +long double complex +conjl(long double complex z) { - union IEEEl2bits ux, uy; - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return (cpackl(creall(z), -cimagl(z))); } diff --git a/lib/libm/src/s_copysign.c b/lib/libm/src/s_copysign.c index 475c221051..c42c6bdb68 100644 --- a/lib/libm/src/s_copysign.c +++ b/lib/libm/src/s_copysign.c @@ -1,4 +1,5 @@ /* @(#)s_copysign.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_copysign.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_copysign.c,v 1.11 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_copysign.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* @@ -19,7 +17,7 @@ * with the sign bit of y. */ -#include +#include "math.h" #include "math_private.h" double diff --git a/lib/libm/src/s_copysignf.c b/lib/libm/src/s_copysignf.c index 0880dbe66d..5b8d634f30 100644 --- a/lib/libm/src/s_copysignf.c +++ b/lib/libm/src/s_copysignf.c @@ -12,8 +12,7 @@ * is preserved. * ==================================================== * - * $NetBSD: s_copysignf.c,v 1.7 2002/05/26 22:01:54 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_copysignf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_copysignf.c 176451 2008-02-22 02:30:36Z das $ */ /* @@ -22,7 +21,7 @@ * with the sign bit of y. */ -#include +#include "math.h" #include "math_private.h" float diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_copysignl.c index a209a1e233..928f19f618 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/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 SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_copysignl.c 165855 2007-01-07 07:54:21Z das $ */ #include diff --git a/lib/libm/src/s_cos.c b/lib/libm/src/s_cos.c index 1b67a5cf1a..e897b0a03c 100644 --- a/lib/libm/src/s_cos.c +++ b/lib/libm/src/s_cos.c @@ -1,4 +1,5 @@ /* @(#)s_cos.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_cos.c 218509 2011-02-10 07:37:50Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_cos.c,v 1.11 2007/08/20 16:01:39 drochner Exp $ */ /* cos(x) @@ -18,7 +17,7 @@ * kernel function: * __kernel_sin ... sine function on [-pi/4,pi/4] * __kernel_cos ... cosine function on [-pi/4,pi/4] - * __libm_rem_pio2 ... argument reduction routine + * __ieee754_rem_pio2 ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on @@ -43,8 +42,12 @@ * TRIG(x) returns trig(x) nearly rounded */ -#include +#include + +#include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double cos(double x) @@ -57,14 +60,18 @@ cos(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_cos(x,z); + if(ix <= 0x3fe921fb) { + if(ix<0x3e46a09e) /* if x < 2**-27 * sqrt(2) */ + if(((int)x)==0) return 1.0; /* generate inexact */ + return __kernel_cos(x,z); + } /* cos(Inf or NaN) is NaN */ else if (ix>=0x7ff00000) return x-x; /* argument reduction needed */ else { - n = __libm_rem_pio2(x,y); + n = __ieee754_rem_pio2(x,y); switch(n&3) { case 0: return __kernel_cos(y[0],y[1]); case 1: return -__kernel_sin(y[0],y[1],1); @@ -74,3 +81,7 @@ cos(double x) } } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(cos, cosl); +#endif diff --git a/lib/libm/src/s_cosf.c b/lib/libm/src/s_cosf.c index 1c8e3299a3..a2d10a5306 100644 --- a/lib/libm/src/s_cosf.c +++ b/lib/libm/src/s_cosf.c @@ -12,10 +12,13 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176569 (2008-02-25) + * + * $FreeBSD: head/lib/msun/src/s_cosf.c 176569 2008-02-25 22:19:17Z bde $ */ -#include +#include + +#include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF #define INLINE_REM_PIO2F @@ -71,7 +74,7 @@ cosf(float x) /* general argument reduction needed */ else { - n = __libm_rem_pio2f(x,&y); + n = __ieee754_rem_pio2f(x,&y); switch(n&3) { case 0: return __kernel_cosdf(y); case 1: return __kernel_sindf(-y); diff --git a/lib/libm/src/s_cosl.c b/lib/libm/src/s_cosl.c index 345feb110b..a91616b1c0 100644 --- a/lib/libm/src/s_cosl.c +++ b/lib/libm/src/s_cosl.c @@ -23,7 +23,7 @@ * (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 SVN: 222508 (2011-05-30) + * $FreeBSD: head/lib/msun/src/s_cosl.c 240828 2012-09-22 15:38:29Z kargl $ */ /* @@ -31,9 +31,20 @@ * an accuracy of <= 0.7412 ULP. */ -#include +#include +#ifdef __i386__ +#include +#endif + +#include "math.h" #include "math_private.h" -#include "e_rem_pio2l.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) @@ -54,11 +65,13 @@ cosl(long double x) 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) - return (__kernel_cosl(z.e, 0)); + RETURNI(__kernel_cosl(z.e, 0)); - e0 = __libm_rem_pio2l(x, y); + e0 = __ieee754_rem_pio2l(x, y); hi = y[0]; lo = y[1]; @@ -76,6 +89,6 @@ cosl(long double x) hi = __kernel_sinl(hi, lo, 1); break; } - - return (hi); + + RETURNI(hi); } diff --git a/lib/libm/src/e_remainderl.c b/lib/libm/src/s_cproj.c similarity index 80% copy from lib/libm/src/e_remainderl.c copy to lib/libm/src/s_cproj.c index 7d70e2e847..100d31e162 100644 --- a/lib/libm/src/e_remainderl.c +++ b/lib/libm/src/s_cproj.c @@ -23,15 +23,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 177765 (2008-03-30) + * $FreeBSD: head/lib/msun/src/s_cproj.c 181377 2008-08-07 15:07:48Z das $ */ +#include #include -long double -remainderl(long double x, long double y) +#include "math_private.h" + +double complex +cproj(double complex z) { - int quo; - return (remquol(x, y, &quo)); + 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/lib/libm/src/e_remainderl.c b/lib/libm/src/s_cprojf.c similarity index 83% copy from lib/libm/src/e_remainderl.c copy to lib/libm/src/s_cprojf.c index 7d70e2e847..7154cf5c56 100644 --- a/lib/libm/src/e_remainderl.c +++ b/lib/libm/src/s_cprojf.c @@ -23,15 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 177765 (2008-03-30) + * $FreeBSD: head/lib/msun/src/s_cprojf.c 181377 2008-08-07 15:07:48Z das $ */ +#include #include -long double -remainderl(long double x, long double y) +#include "math_private.h" + +float complex +cprojf(float complex z) { - int quo; - return (remquol(x, y, &quo)); + if (!isinf(crealf(z)) && !isinf(cimagf(z))) + return (z); + else + return (cpackf(INFINITY, copysignf(0.0, cimagf(z)))); } diff --git a/lib/libm/src/e_remainderl.c b/lib/libm/src/s_cprojl.c similarity index 82% copy from lib/libm/src/e_remainderl.c copy to lib/libm/src/s_cprojl.c index 7d70e2e847..d1b397cf96 100644 --- a/lib/libm/src/e_remainderl.c +++ b/lib/libm/src/s_cprojl.c @@ -23,15 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 177765 (2008-03-30) + * $FreeBSD: head/lib/msun/src/s_cprojl.c 181377 2008-08-07 15:07:48Z das $ */ +#include #include -long double -remainderl(long double x, long double y) +#include "math_private.h" + +long double complex +cprojl(long double complex z) { - int quo; - return (remquol(x, y, &quo)); + if (!isinf(creall(z)) && !isinf(cimagl(z))) + return (z); + else + return (cpackl(INFINITY, copysignl(0.0, cimagl(z)))); } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_creal.c similarity index 85% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_creal.c index a209a1e233..70089f9dfe 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_creal.c @@ -23,20 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_creal.c 129864 2004-05-30 09:21:56Z stefanf $ */ -#include +#include -#include "fpmath.h" - -long double -copysignl(long double x, long double y) +double +creal(double complex z) { - union IEEEl2bits ux, uy; - - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return z; } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_crealf.c similarity index 85% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_crealf.c index a209a1e233..28cc6f3183 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_crealf.c @@ -23,20 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_crealf.c 129864 2004-05-30 09:21:56Z stefanf $ */ -#include +#include -#include "fpmath.h" - -long double -copysignl(long double x, long double y) +float +crealf(float complex z) { - union IEEEl2bits ux, uy; - - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return z; } diff --git a/lib/libm/src/s_copysignl.c b/lib/libm/src/s_creall.c similarity index 86% copy from lib/libm/src/s_copysignl.c copy to lib/libm/src/s_creall.c index a209a1e233..7521420eae 100644 --- a/lib/libm/src/s_copysignl.c +++ b/lib/libm/src/s_creall.c @@ -23,20 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 129040 (2004-05-07) + * $FreeBSD: head/lib/msun/src/s_creall.c 129864 2004-05-30 09:21:56Z stefanf $ */ -#include - -#include "fpmath.h" +#include long double -copysignl(long double x, long double y) +creall(long double complex z) { - union IEEEl2bits ux, uy; - - ux.e = x; - uy.e = y; - ux.bits.sign = uy.bits.sign; - return (ux.e); + return z; } diff --git a/lib/libm/src/s_csinh.c b/lib/libm/src/s_csinh.c new file mode 100644 index 0000000000..572822d6e3 --- /dev/null +++ b/lib/libm/src/s_csinh.c @@ -0,0 +1,156 @@ +/*- + * 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. + * + * $FreeBSD: head/lib/msun/src/s_csinh.c 226599 2011-10-21 06:29:32Z das $ + */ + +/* + * 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 +#include + +#include "math_private.h" + +static const double huge = 0x1p1023; + +double complex +csinh(double complex z) +{ + double x, y, h; + int32_t hx, hy, ix, iy, lx, ly; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + EXTRACT_WORDS(hy, ly, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + /* Handle the nearly-non-exceptional cases where x and y are finite. */ + if (ix < 0x7ff00000 && iy < 0x7ff00000) { + if ((iy | ly) == 0) + return (cpack(sinh(x), y)); + if (ix < 0x40360000) /* small x: normal case */ + return (cpack(sinh(x) * cos(y), cosh(x) * sin(y))); + + /* |x| >= 22, so cosh(x) ~= exp(|x|) */ + if (ix < 0x40862e42) { + /* x < 710: exp(|x|) won't overflow */ + h = exp(fabs(x)) * 0.5; + return (cpack(copysign(h, x) * cos(y), h * sin(y))); + } else if (ix < 0x4096bbaa) { + /* x < 1455: scale to avoid overflow */ + z = __ldexp_cexp(cpack(fabs(x), y), -1); + return (cpack(creal(z) * copysign(1, x), cimag(z))); + } else { + /* x >= 1455: the result always overflows */ + h = huge * x; + return (cpack(h * cos(y), h * h * sin(y))); + } + } + + /* + * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN. + * The sign of 0 in the result is unspecified. Choice = normally + * the same as dNaN. Raise the invalid floating-point exception. + * + * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN). + * The sign of 0 in the result is unspecified. Choice = normally + * the same as d(NaN). + */ + if ((ix | lx) == 0 && iy >= 0x7ff00000) + return (cpack(copysign(0, x * (y - y)), y - y)); + + /* + * sinh(+-Inf +- I 0) = +-Inf + I +-0. + * + * sinh(NaN +- I 0) = d(NaN) + I +-0. + */ + if ((iy | ly) == 0 && ix >= 0x7ff00000) { + if (((hx & 0xfffff) | lx) == 0) + return (cpack(x, y)); + return (cpack(x, copysign(0, y))); + } + + /* + * sinh(x +- I Inf) = dNaN + I dNaN. + * Raise the invalid floating-point exception for finite nonzero x. + * + * sinh(x + I NaN) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero x. Choice = don't raise (except for signaling NaNs). + */ + if (ix < 0x7ff00000 && iy >= 0x7ff00000) + return (cpack(y - y, x * (y - y))); + + /* + * sinh(+-Inf + I NaN) = +-Inf + I d(NaN). + * The sign of Inf in the result is unspecified. Choice = normally + * the same as d(NaN). + * + * sinh(+-Inf +- I Inf) = +Inf + I dNaN. + * The sign of Inf in the result is unspecified. Choice = always +. + * Raise the invalid floating-point exception. + * + * sinh(+-Inf + I y) = +-Inf cos(y) + I Inf sin(y) + */ + if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { + if (iy >= 0x7ff00000) + return (cpack(x * x, x * (y - y))); + return (cpack(x * cos(y), INFINITY * sin(y))); + } + + /* + * sinh(NaN + I NaN) = d(NaN) + I d(NaN). + * + * sinh(NaN +- I Inf) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception. + * Choice = raise. + * + * sinh(NaN + I y) = d(NaN) + I d(NaN). + * Optionally raises the invalid floating-point exception for finite + * nonzero y. Choice = don't raise (except for signaling NaNs). + */ + return (cpack((x * x) * (y - y), (x + x) * (y - y))); +} + +double complex +csin(double complex z) +{ + + /* csin(z) = -I * csinh(I * z) */ + z = csinh(cpack(-cimag(z), creal(z))); + return (cpack(cimag(z), -creal(z))); +} diff --git a/lib/libm/src/s_csinhf.c b/lib/libm/src/s_csinhf.c new file mode 100644 index 0000000000..cf4e793da4 --- /dev/null +++ b/lib/libm/src/s_csinhf.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. + * + * $FreeBSD: head/lib/msun/src/s_csinhf.c 226599 2011-10-21 06:29:32Z das $ + */ + +/* + * Hyperbolic sine of a complex argument z. See s_csinh.c for details. + */ + +#include +#include + +#include "math_private.h" + +static const float huge = 0x1p127; + +float complex +csinhf(float complex z) +{ + float x, y, h; + int32_t hx, hy, ix, iy; + + x = crealf(z); + y = cimagf(z); + + GET_FLOAT_WORD(hx, x); + GET_FLOAT_WORD(hy, y); + + ix = 0x7fffffff & hx; + iy = 0x7fffffff & hy; + + if (ix < 0x7f800000 && iy < 0x7f800000) { + if (iy == 0) + return (cpackf(sinhf(x), y)); + if (ix < 0x41100000) /* small x: normal case */ + return (cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y))); + + /* |x| >= 9, so cosh(x) ~= exp(|x|) */ + if (ix < 0x42b17218) { + /* x < 88.7: expf(|x|) won't overflow */ + h = expf(fabsf(x)) * 0.5f; + return (cpackf(copysignf(h, x) * cosf(y), h * sinf(y))); + } else if (ix < 0x4340b1e7) { + /* x < 192.7: scale to avoid overflow */ + z = __ldexp_cexpf(cpackf(fabsf(x), y), -1); + return (cpackf(crealf(z) * copysignf(1, x), cimagf(z))); + } else { + /* x >= 192.7: the result always overflows */ + h = huge * x; + return (cpackf(h * cosf(y), h * h * sinf(y))); + } + } + + if (ix == 0 && iy >= 0x7f800000) + return (cpackf(copysignf(0, x * (y - y)), y - y)); + + if (iy == 0 && ix >= 0x7f800000) { + if ((hx & 0x7fffff) == 0) + return (cpackf(x, y)); + return (cpackf(x, copysignf(0, y))); + } + + if (ix < 0x7f800000 && iy >= 0x7f800000) + return (cpackf(y - y, x * (y - y))); + + if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { + if (iy >= 0x7f800000) + return (cpackf(x * x, x * (y - y))); + return (cpackf(x * cosf(y), INFINITY * sinf(y))); + } + + return (cpackf((x * x) * (y - y), (x + x) * (y - y))); +} + +float complex +csinf(float complex z) +{ + + z = csinhf(cpackf(-cimagf(z), crealf(z))); + return (cpackf(cimagf(z), -crealf(z))); +} diff --git a/lib/libm/complex/s_csqrtl.c b/lib/libm/src/s_csqrt.c similarity index 68% copy from lib/libm/complex/s_csqrtl.c copy to lib/libm/src/s_csqrt.c index a67023c4c3..93f8ff41c4 100644 --- a/lib/libm/complex/s_csqrtl.c +++ b/lib/libm/src/s_csqrt.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007-2008 David Schultz + * Copyright (c) 2007 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,14 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181402 (2008-08-08) + * $FreeBSD: head/lib/msun/src/s_csqrt.c 181402 2008-08-08 00:15:16Z das $ */ #include #include #include -#include "../src/math_private.h" +#include "math_private.h" /* * gcc doesn't implement complex multiplication or division correctly, @@ -38,40 +38,31 @@ * notify conforming c99 compilers that the fast-but-incorrect code that * gcc generates is acceptable, since the special cases have already been * handled. - * - * IGNORED BY DRAGONFLY BASE COMPILER, MASK TO AVOID WARNING=ERROR - * #pragma STDC CX_LIMITED_RANGE ON */ +#pragma STDC CX_LIMITED_RANGE ON -/* - * XXX: gcc47 really shouldn't warn here on i386, exclude from -Werror for now - */ -#if defined(__i386__) && __GNUC_PREREQ__(4, 7) -#pragma GCC diagnostic warning "-Woverflow" -#endif +/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */ +#define THRESH 0x1.a827999fcef32p+1022 -/* 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) +double complex +csqrt(double complex z) { - long double complex result; - long double a, b; - long double t; + double complex result; + double a, b; + double t; int scale; - a = creall(z); - b = cimagl(z); + a = creal(z); + b = cimag(z); /* Handle special cases. */ if (z == 0) - return (cpackl(0, b)); + return (cpack(0, b)); if (isinf(b)) - return (cpackl(INFINITY, b)); + return (cpack(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 */ + return (cpack(a, t)); /* return NaN + NaN i */ } if (isinf(a)) { /* @@ -81,9 +72,9 @@ csqrtl(long double complex z) * csqrt(-inf + y i) = 0 + inf i */ if (signbit(a)) - return (cpackl(fabsl(b - b), copysignl(a, b))); + return (cpack(fabs(b - b), copysign(a, b))); else - return (cpackl(a, copysignl(b - b, b))); + return (cpack(a, copysign(b - b, b))); } /* * The remaining special case (b is NaN) is handled just fine by @@ -91,7 +82,7 @@ csqrtl(long double complex z) */ /* Scale to avoid overflow. */ - if (fabsl(a) >= THRESH || fabsl(b) >= THRESH) { + if (fabs(a) >= THRESH || fabs(b) >= THRESH) { a *= 0.25; b *= 0.25; scale = 1; @@ -101,11 +92,11 @@ csqrtl(long double complex z) /* Algorithm 312, CACM vol 10, Oct 1967. */ if (a >= 0) { - t = sqrtl((a + hypotl(a, b)) * 0.5); - result = cpackl(t, b / (2 * t)); + t = sqrt((a + hypot(a, b)) * 0.5); + result = cpack(t, b / (2 * t)); } else { - t = sqrtl((-a + hypotl(a, b)) * 0.5); - result = cpackl(fabsl(b) / (2 * t), copysignl(t, b)); + t = sqrt((-a + hypot(a, b)) * 0.5); + result = cpack(fabs(b) / (2 * t), copysign(t, b)); } /* Rescale. */ @@ -114,3 +105,7 @@ csqrtl(long double complex z) else return (result); } + +#if LDBL_MANT_DIG == 53 +__weak_reference(csqrt, csqrtl); +#endif diff --git a/lib/libm/complex/s_csqrtl.c b/lib/libm/src/s_csqrtf.c similarity index 56% copy from lib/libm/complex/s_csqrtl.c copy to lib/libm/src/s_csqrtf.c index a67023c4c3..539954f7f3 100644 --- a/lib/libm/complex/s_csqrtl.c +++ b/lib/libm/src/s_csqrtf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007-2008 David Schultz + * Copyright (c) 2007 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,14 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181402 (2008-08-08) + * $FreeBSD: head/lib/msun/src/s_csqrtf.c 181402 2008-08-08 00:15:16Z das $ */ #include -#include #include -#include "../src/math_private.h" +#include "math_private.h" /* * gcc doesn't implement complex multiplication or division correctly, @@ -38,79 +37,51 @@ * notify conforming c99 compilers that the fast-but-incorrect code that * gcc generates is acceptable, since the special cases have already been * handled. - * - * IGNORED BY DRAGONFLY BASE COMPILER, MASK TO AVOID WARNING=ERROR - * #pragma STDC CX_LIMITED_RANGE ON - */ - -/* - * XXX: gcc47 really shouldn't warn here on i386, exclude from -Werror for now */ -#if defined(__i386__) && __GNUC_PREREQ__(4, 7) -#pragma GCC diagnostic warning "-Woverflow" -#endif - -/* We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). */ -#define THRESH (LDBL_MAX / 2.414213562373095048801688724209698L) +#pragma STDC CX_LIMITED_RANGE ON -long double complex -csqrtl(long double complex z) +float complex +csqrtf(float complex z) { - long double complex result; - long double a, b; - long double t; - int scale; - - a = creall(z); - b = cimagl(z); + float a = crealf(z), b = cimagf(z); + double t; /* Handle special cases. */ if (z == 0) - return (cpackl(0, b)); + return (cpackf(0, b)); if (isinf(b)) - return (cpackl(INFINITY, b)); + return (cpackf(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 */ + return (cpackf(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 + * 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 (cpackl(fabsl(b - b), copysignl(a, b))); + return (cpackf(fabsf(b - b), copysignf(a, b))); else - return (cpackl(a, copysignl(b - b, b))); + return (cpackf(a, copysignf(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. */ + /* + * 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 = sqrtl((a + hypotl(a, b)) * 0.5); - result = cpackl(t, b / (2 * t)); + t = sqrt((a + hypot(a, b)) * 0.5); + return (cpackf(t, b / (2.0 * t))); } else { - t = sqrtl((-a + hypotl(a, b)) * 0.5); - result = cpackl(fabsl(b) / (2 * t), copysignl(t, b)); + t = sqrt((-a + hypot(a, b)) * 0.5); + return (cpackf(fabsf(b) / (2.0 * t), copysignf(t, b))); } - - /* Rescale. */ - if (scale) - return (result * 2); - else - return (result); } diff --git a/lib/libm/complex/s_csqrtl.c b/lib/libm/src/s_csqrtl.c similarity index 95% rename from lib/libm/complex/s_csqrtl.c rename to lib/libm/src/s_csqrtl.c index a67023c4c3..990b106569 100644 --- a/lib/libm/complex/s_csqrtl.c +++ b/lib/libm/src/s_csqrtl.c @@ -23,14 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181402 (2008-08-08) + * $FreeBSD: head/lib/msun/src/s_csqrtl.c 181402 2008-08-08 00:15:16Z das $ */ #include #include #include -#include "../src/math_private.h" +#include "math_private.h" /* * gcc doesn't implement complex multiplication or division correctly, @@ -38,10 +38,8 @@ * notify conforming c99 compilers that the fast-but-incorrect code that * gcc generates is acceptable, since the special cases have already been * handled. - * - * IGNORED BY DRAGONFLY BASE COMPILER, MASK TO AVOID WARNING=ERROR - * #pragma STDC CX_LIMITED_RANGE ON */ +#pragma STDC CX_LIMITED_RANGE ON /* * XXX: gcc47 really shouldn't warn here on i386, exclude from -Werror for now diff --git a/lib/libm/src/s_ctanh.c b/lib/libm/src/s_ctanh.c new file mode 100644 index 0000000000..84970f2bdc --- /dev/null +++ b/lib/libm/src/s_ctanh.c @@ -0,0 +1,143 @@ +/*- + * 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. + * + * $FreeBSD: head/lib/msun/src/s_ctanh.c 226600 2011-10-21 06:30:16Z das $ + */ + +/* + * 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 +#include + +#include "math_private.h" + +double complex +ctanh(double complex z) +{ + double x, y; + double t, beta, s, rho, denom; + uint32_t hx, ix, lx; + + x = creal(z); + y = cimag(z); + + EXTRACT_WORDS(hx, lx, x); + ix = hx & 0x7fffffff; + + /* + * ctanh(NaN + i 0) = NaN + i 0 + * + * ctanh(NaN + i y) = NaN + i NaN for y != 0 + * + * The imaginary part has the sign of x*sin(2*y), but there's no + * special effort to get this right. + * + * ctanh(+-Inf +- i Inf) = +-1 +- 0 + * + * ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite + * + * The imaginary part of the sign is unspecified. This special + * case is only needed to avoid a spurious invalid exception when + * y is infinite. + */ + if (ix >= 0x7ff00000) { + if ((ix & 0xfffff) | lx) /* x is NaN */ + return (cpack(x, (y == 0 ? y : x * y))); + SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */ + return (cpack(x, copysign(0, isinf(y) ? y : sin(y) * cos(y)))); + } + + /* + * ctanh(x + i NAN) = NaN + i NaN + * ctanh(x +- i Inf) = NaN + i NaN + */ + if (!isfinite(y)) + return (cpack(y - y, y - y)); + + /* + * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the + * approximation sinh^2(huge) ~= exp(2*huge) / 4. + * We use a modified formula to avoid spurious overflow. + */ + if (ix >= 0x40360000) { /* x >= 22 */ + double exp_mx = exp(-fabs(x)); + return (cpack(copysign(1, x), + 4 * sin(y) * cos(y) * exp_mx * exp_mx)); + } + + /* Kahan's algorithm */ + t = tan(y); + beta = 1.0 + t * t; /* = 1 / cos^2(y) */ + s = sinh(x); + rho = sqrt(1 + s * s); /* = cosh(x) */ + denom = 1 + beta * s * s; + return (cpack((beta * rho * s) / denom, t / denom)); +} + +double complex +ctan(double complex z) +{ + + /* ctan(z) = -I * ctanh(I * z) */ + z = ctanh(cpack(-cimag(z), creal(z))); + return (cpack(cimag(z), -creal(z))); +} diff --git a/lib/libm/src/s_tanl.c b/lib/libm/src/s_ctanhf.c similarity index 55% copy from lib/libm/src/s_tanl.c copy to lib/libm/src/s_ctanhf.c index e9b6ab7d2b..ad9717565a 100644 --- a/lib/libm/src/s_tanl.c +++ b/lib/libm/src/s_ctanhf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2007 Steven G. Kargl + * Copyright (c) 2011 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,61 +23,61 @@ * (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 SVN: 222508 (2011-05-30) + * $FreeBSD: head/lib/msun/src/s_ctanhf.c 226600 2011-10-21 06:30:16Z das $ */ /* - * 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%). + * Hyperbolic tangent of a complex argument z. See s_ctanh.c for details. */ -#include - +#include #include + #include "math_private.h" -#include "e_rem_pio2l.h" -long double -tanl(long double x) +float complex +ctanhf(float complex z) { - union IEEEl2bits z; - int e0, s; - long double y[2]; - long double hi, lo; + float x, y; + float t, beta, s, rho, denom; + uint32_t hx, ix; - z.e = x; - s = z.bits.sign; - z.bits.sign = 0; + x = crealf(z); + y = cimagf(z); - /* If x = +-0 or x is subnormal, then tan(x) = x. */ - if (z.bits.exp == 0) - return (x); + GET_FLOAT_WORD(hx, x); + ix = hx & 0x7fffffff; - /* If x = NaN or Inf, then tan(x) = NaN. */ - if (z.bits.exp == 32767) - return ((x - x) / (x - x)); - - /* Optimize the case where x is already within range. */ - if (z.e < M_PI_4) { - hi = __kernel_tanl(z.e, 0, 0); - return (s ? -hi : hi); + 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)))); } - e0 = __libm_rem_pio2l(x, y); - hi = y[0]; - lo = y[1]; + if (!isfinite(y)) + return (cpackf(y - y, y - y)); - 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; + 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)); } - return (hi); + 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/lib/libm/src/s_erf.c b/lib/libm/src/s_erf.c index 3064a00ab6..fb0204d60f 100644 --- a/lib/libm/src/s_erf.c +++ b/lib/libm/src/s_erf.c @@ -1,4 +1,5 @@ /* @(#)s_erf.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_erf.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_erf.c,v 1.11 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_erf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* double erf(double x) @@ -108,7 +106,7 @@ */ -#include +#include "math.h" #include "math_private.h" static const double @@ -234,7 +232,7 @@ erf(double x) } z = x; SET_LOW_WORD(z,0); - r = exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S); + r = __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S); if(hx>=0) return one-r/x; else return r/x-one; } @@ -292,8 +290,8 @@ erfc(double x) } z = x; SET_LOW_WORD(z,0); - r = exp(-z*z-0.5625)* - exp((z-x)*(z+x)+R/S); + r = __ieee754_exp(-z*z-0.5625)* + __ieee754_exp((z-x)*(z+x)+R/S); if(hx>0) return r/x; else return two-r/x; } else { if(hx>0) return tiny*tiny; else return two-tiny; diff --git a/lib/libm/src/s_erff.c b/lib/libm/src/s_erff.c index 273a068972..e0f180de54 100644 --- a/lib/libm/src/s_erff.c +++ b/lib/libm/src/s_erff.c @@ -12,11 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: s_erff.c,v 1.7 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_erff.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_erff.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float @@ -143,7 +142,7 @@ erff(float x) } GET_FLOAT_WORD(ix,x); SET_FLOAT_WORD(z,ix&0xfffff000); - r = expf(-z*z-(float)0.5625)*expf((z-x)*(z+x)+R/S); + 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; } @@ -201,8 +200,8 @@ erfcf(float x) } GET_FLOAT_WORD(ix,x); SET_FLOAT_WORD(z,ix&0xfffff000); - r = expf(-z*z-(float)0.5625)* - expf((z-x)*(z+x)+R/S); + 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/lib/libm/src/s_exp2.c b/lib/libm/src/s_exp2.c index 833e44f3e1..edb3718e5f 100644 --- a/lib/libm/src/s_exp2.c +++ b/lib/libm/src/s_exp2.c @@ -23,19 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_exp2.c,v 1.2 2010/01/11 23:38:24 christos Exp $ + * $FreeBSD: head/lib/msun/src/s_exp2.c 251024 2013-05-27 08:50:10Z das $ */ #include -#include +#include "math.h" #include "math_private.h" #define TBLBITS 8 #define TBLSIZE (1 << TBLBITS) static const double - huge = 0x1p1000, redux = 0x1.8p52 / TBLSIZE, P1 = 0x1.62e42fefa39efp-1, P2 = 0x1.ebfbdff82c575p-3, @@ -43,7 +42,9 @@ static const double P4 = 0x1.3b2ab88f70400p-7, P5 = 0x1.5d88003875c74p-10; -static volatile double twom1000 = 0x1p-1000; +static volatile double + huge = 0x1p1000, + twom1000 = 0x1p-1000; static const double tbl[TBLSIZE * 2] = { /* exp2(z + eps) eps */ @@ -351,7 +352,7 @@ exp2(double x) GET_LOW_WORD(lx,x); if(((ix & 0xfffff) | lx) != 0 || (hx & 0x80000000) == 0) return (x + x); /* x is NaN or +Inf */ - else + else return (0.0); /* x is -Inf */ } if(x >= 0x1.0p10) @@ -390,8 +391,6 @@ exp2(double x) } } -#ifdef notyet #if (LDBL_MANT_DIG == 53) __weak_reference(exp2, exp2l); #endif -#endif diff --git a/lib/libm/src/s_exp2f.c b/lib/libm/src/s_exp2f.c index ab3e3c1eb1..df3a23d692 100644 --- a/lib/libm/src/s_exp2f.c +++ b/lib/libm/src/s_exp2f.c @@ -23,26 +23,27 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_exp2f.c,v 1.1 2010/01/11 16:28:39 christos Exp $ + * $FreeBSD: head/lib/msun/src/s_exp2f.c 251024 2013-05-27 08:50:10Z das $ */ #include -#include +#include "math.h" #include "math_private.h" #define TBLBITS 4 #define TBLSIZE (1 << TBLBITS) static const float - huge = 0x1p100f, redux = 0x1.8p23f / TBLSIZE, P1 = 0x1.62e430p-1f, P2 = 0x1.ebfbe0p-3f, P3 = 0x1.c6b348p-5f, P4 = 0x1.3b2c9cp-7f; -static volatile float twom100 = 0x1p-100f; +static volatile float + huge = 0x1p100f, + twom100 = 0x1p-100f; static const double exp2ft[TBLSIZE] = { 0x1.6a09e667f3bcdp-1, @@ -62,7 +63,7 @@ static const double exp2ft[TBLSIZE] = { 0x1.4bfdad5362a27p+0, 0x1.5ab07dd485429p+0, }; - + /* * exp2f(x): compute the base 2 exponential of x * @@ -104,7 +105,7 @@ exp2f(float x) if(ix >= 0x7f800000) { if ((ix & 0x7fffff) != 0 || (hx & 0x80000000) == 0) return (x + x); /* x is NaN or +Inf */ - else + else return (0.0); /* x is -Inf */ } if(x >= 0x1.0p7f) diff --git a/lib/libm/src/s_expm1.c b/lib/libm/src/s_expm1.c index aa32143f43..dfae2af85b 100644 --- a/lib/libm/src/s_expm1.c +++ b/lib/libm/src/s_expm1.c @@ -1,4 +1,5 @@ /* @(#)s_expm1.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_expm1.c 251024 2013-05-27 08:50:10Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_expm1.c,v 1.12 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_expm1.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* expm1(x) @@ -45,7 +43,7 @@ * 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 @@ -108,32 +106,34 @@ * to produce the hexadecimal values shown. */ -#include +#include + +#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; - c = 0; GET_HIGH_WORD(hx,x); xsb = hx&0x80000000; /* sign bit of x */ hx &= 0x7fffffff; /* high word of |x| */ @@ -169,7 +169,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 */ @@ -186,34 +186,30 @@ 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; diff --git a/lib/libm/src/s_expm1f.c b/lib/libm/src/s_expm1f.c index aace9f0c34..052b467d58 100644 --- a/lib/libm/src/s_expm1f.c +++ b/lib/libm/src/s_expm1f.c @@ -11,37 +11,38 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_expm1f.c,v 1.10 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_expm1f.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_expm1f.c 251024 2013-05-27 08:50:10Z das $ */ -#include -#include "math_private.h" +#include -static const float huge = 1.0e+30, tiny = 1.0e-30; +#include "math.h" +#include "math_private.h" static const float one = 1.0, +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; - c = 0; GET_FLOAT_WORD(hx,x); xsb = hx&0x80000000; /* sign bit of x */ hx &= 0x7fffffff; /* high word of |x| */ @@ -74,7 +75,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 */ @@ -86,38 +87,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/lib/libm/src/s_fabs.c b/lib/libm/src/s_fabs.c index 4d54bb2b1a..a2d237331e 100644 --- a/lib/libm/src/s_fabs.c +++ b/lib/libm/src/s_fabs.c @@ -1,4 +1,5 @@ /* @(#)s_fabs.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_fabs.c 97413 2002-05-28 18:15:04Z alfred $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,15 +9,13 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 97413 (2002-05-28) */ /* * fabs(x) returns the absolute value of x. */ -#include +#include "math.h" #include "math_private.h" double diff --git a/lib/libm/src/s_fabsf.c b/lib/libm/src/s_fabsf.c index 8d81c3d536..81f33eb59f 100644 --- a/lib/libm/src/s_fabsf.c +++ b/lib/libm/src/s_fabsf.c @@ -12,15 +12,14 @@ * is preserved. * ==================================================== * - * $NetBSD: s_fabsf.c,v 1.7 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_fabsf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_fabsf.c 176451 2008-02-22 02:30:36Z das $ */ /* * fabsf(x) returns the absolute value of x. */ -#include +#include "math.h" #include "math_private.h" float diff --git a/lib/libm/src/s_fabsl.c b/lib/libm/src/s_fabsl.c index 1a0b4d176c..9d350e7a49 100644 --- a/lib/libm/src/s_fabsl.c +++ b/lib/libm/src/s_fabsl.c @@ -1,49 +1,43 @@ -/* $NetBSD: s_fabsl.c,v 1.2 2010/09/17 20:39:39 christos Exp $ */ - /*- - * Copyright (c) 2010 The NetBSD Foundation, 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. 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 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 ``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. * - * $NetBSD: s_fabsl.c,v 1.2 2010/09/17 20:39:39 christos Exp $ + * $FreeBSD: head/lib/msun/src/s_fabsl.c 234685 2012-04-25 18:07:35Z des $ */ #include -#include -/* - * fabsl(long double x) - * This function returns the absolute value of its argumetn x, |x|. - */ -#ifdef EXT_EXP_INFNAN +#include "fpmath.h" + long double fabsl(long double x) { - union ieee_ext_u ux; - - ux.extu_ld = x; - ux.extu_ext.ext_sign = 0; + union IEEEl2bits u; - return (ux.extu_ld); + u.e = x; + u.bits.sign = 0; + return (u.e); } -#endif diff --git a/lib/libm/src/s_fdim.c b/lib/libm/src/s_fdim.c index 9c43300b65..95f7a9868d 100644 --- a/lib/libm/src/s_fdim.c +++ b/lib/libm/src/s_fdim.c @@ -22,6 +22,8 @@ * 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: head/lib/msun/src/s_fdim.c 131320 2004-06-30 07:04:01Z das $ */ #include diff --git a/lib/libm/src/s_finite.c b/lib/libm/src/s_finite.c index 1c05415d62..1aa790bcab 100644 --- a/lib/libm/src/s_finite.c +++ b/lib/libm/src/s_finite.c @@ -1,4 +1,5 @@ /* @(#)s_finite.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_finite.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_finite.c,v 1.11 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_finite.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* @@ -18,11 +16,10 @@ * no branching! */ -#include +#include "math.h" #include "math_private.h" -int -finite(double x) + int finite(double x) { int32_t hx; GET_HIGH_WORD(hx,x); diff --git a/lib/libm/src/s_finitef.c b/lib/libm/src/s_finitef.c index fd788dd7e8..893689793c 100644 --- a/lib/libm/src/s_finitef.c +++ b/lib/libm/src/s_finitef.c @@ -12,8 +12,7 @@ * is preserved. * ==================================================== * - * $NetBSD: s_finitef.c,v 1.7 2002/05/26 22:01:55 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_finitef.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_finitef.c 176451 2008-02-22 02:30:36Z das $ */ /* @@ -21,11 +20,10 @@ * no branching! */ -#include +#include "math.h" #include "math_private.h" -int -finitef(float x) + int finitef(float x) { int32_t ix; GET_FLOAT_WORD(ix,x); diff --git a/lib/libm/src/s_floor.c b/lib/libm/src/s_floor.c index 971d37f497..4427ab3614 100644 --- a/lib/libm/src/s_floor.c +++ b/lib/libm/src/s_floor.c @@ -1,4 +1,5 @@ /* @(#)s_floor.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_floor.c 176305 2008-02-15 07:01:40Z bde $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_floor.c,v 1.13 2009/02/16 01:27:36 lukem Exp $ */ /* @@ -21,7 +20,9 @@ * Inexact flag raised if x not equal to floor(x). */ -#include +#include + +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; @@ -29,37 +30,37 @@ static const double huge = 1.0e300; double floor(double x) { - int32_t i0,i1,jj0; + int32_t i0,i1,j0; u_int32_t i,j; EXTRACT_WORDS(i0,i1,x); - jj0 = ((i0>>20)&0x7ff)-0x3ff; - if(jj0<20) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ if(i0>=0) {i0=i1=0;} else if(((i0&0x7fffffff)|i1)!=0) { i0=0xbff00000;i1=0;} } } else { - i = (0x000fffff)>>jj0; + i = (0x000fffff)>>j0; if(((i0&i)|i1)==0) return x; /* x is integral */ if(huge+x>0.0) { /* raise inexact flag */ - if(i0<0) i0 += (0x00100000)>>jj0; + if(i0<0) i0 += (0x00100000)>>j0; i0 &= (~i); i1=0; } } - } else if (jj0>51) { - if(jj0==0x400) return x+x; /* inf or NaN */ + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ else return x; /* x is integral */ } else { - i = ((u_int32_t)(0xffffffff))>>(jj0-20); + i = ((u_int32_t)(0xffffffff))>>(j0-20); if((i1&i)==0) return x; /* x is integral */ if(huge+x>0.0) { /* raise inexact flag */ if(i0<0) { - if(jj0==20) i0+=1; + if(j0==20) i0+=1; else { - j = i1+(1<<(52-jj0)); - if(j<(u_int32_t)i1) i0 +=1 ; /* got a carry */ + j = i1+(1<<(52-j0)); + if(j +#include "math.h" #include "math_private.h" static const float huge = 1.0e30; @@ -32,27 +32,27 @@ static const float huge = 1.0e30; float floorf(float x) { - int32_t i0,jj0; + int32_t i0,j0; u_int32_t i; GET_FLOAT_WORD(i0,x); - jj0 = ((i0>>23)&0xff)-0x7f; - if(jj0<23) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ if(i0>=0) {i0=0;} else if((i0&0x7fffffff)!=0) { i0=0xbf800000;} } } else { - i = (0x007fffff)>>jj0; + i = (0x007fffff)>>j0; if((i0&i)==0) return x; /* x is integral */ if(huge+x>(float)0.0) { /* raise inexact flag */ - if(i0<0) i0 += (0x00800000)>>jj0; + if(i0<0) i0 += (0x00800000)>>j0; i0 &= (~i); } } } else { - if(jj0==0x80) return x+x; /* inf or NaN */ + if(j0==0x80) return x+x; /* inf or NaN */ else return x; /* x is integral */ } SET_FLOAT_WORD(x,i0); diff --git a/lib/libm/src/s_floorl.c b/lib/libm/src/s_floorl.c index c9fd28b64c..0da138dcf8 100644 --- a/lib/libm/src/s_floorl.c +++ b/lib/libm/src/s_floorl.c @@ -9,7 +9,7 @@ * ==================================================== * * From: @(#)s_floor.c 5.1 93/09/24 - * FreeBSD SVN: 176280 (2008-02-14) + * $FreeBSD: head/lib/msun/src/s_floorl.c 176280 2008-02-14 15:10:34Z bde $ */ /* diff --git a/lib/libm/src/s_fma.c b/lib/libm/src/s_fma.c index 043b9b3e1c..13338128d3 100644 --- a/lib/libm/src/s_fma.c +++ b/lib/libm/src/s_fma.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 226601 (2011-10-21) + * $FreeBSD: head/lib/msun/src/s_fma.c 251024 2013-05-27 08:50:10Z das $ */ #include @@ -116,7 +116,7 @@ add_and_denormalize(double a, double b, int scale) if (sum.lo != 0) { EXTRACT_WORD64(hibits, sum.hi); bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1; - if ((bits_lost != 1) ^ (int)(hibits & 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); @@ -215,17 +215,17 @@ fma(double x, double y, double z) case FE_TONEAREST: return (z); case FE_TOWARDZERO: - if ((x > 0.0) ^ (y < 0.0) ^ (z < 0.0)) + 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)) + if (x > 0.0 ^ y < 0.0) return (z); else return (nextafter(z, -INFINITY)); default: /* FE_UPWARD */ - if ((x > 0.0) ^ (y < 0.0)) + if (x > 0.0 ^ y < 0.0) return (nextafter(z, INFINITY)); else return (z); @@ -237,6 +237,8 @@ fma(double x, double y, double z) zs = copysign(DBL_MIN, zs); fesetround(FE_TONEAREST); + /* work around clang bug 8100 */ + volatile double vxs = xs; /* * Basic approach for round-to-nearest: @@ -246,7 +248,7 @@ fma(double x, double y, double z) * adj = xy.lo + r.lo (inexact; low bit is sticky) * result = r.hi + adj (correctly rounded) */ - xy = dd_mul(xs, ys); + xy = dd_mul(vxs, ys); r = dd_add(xy.hi, zs); spread = ex + ey; @@ -267,7 +269,9 @@ fma(double x, double y, double z) * rounding modes. */ fesetround(oround); - adj = r.lo + xy.lo; + /* work around clang bug 8100 */ + volatile double vrlo = r.lo; + adj = vrlo + xy.lo; return (ldexp(r.hi + adj, spread)); } diff --git a/lib/libm/src/s_fmaf.c b/lib/libm/src/s_fmaf.c index e589d51278..f70ebb645a 100644 --- a/lib/libm/src/s_fmaf.c +++ b/lib/libm/src/s_fmaf.c @@ -23,11 +23,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 226371 (2011-10-15) + * $FreeBSD: head/lib/msun/src/s_fmaf.c 226371 2011-10-15 04:16:58Z das $ */ #include -#include + +#include "math.h" #include "math_private.h" /* diff --git a/lib/libm/src/s_fmal.c b/lib/libm/src/s_fmal.c index 90c2cc8131..d728f22bcd 100644 --- a/lib/libm/src/s_fmal.c +++ b/lib/libm/src/s_fmal.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 226601 (2011-10-21) + * $FreeBSD: head/lib/msun/src/s_fmal.c 251024 2013-05-27 08:50:10Z das $ */ #include @@ -112,7 +112,7 @@ add_and_denormalize(long double a, long double b, int scale) if (sum.lo != 0) { u.e = sum.hi; bits_lost = -u.bits.exp - scale + 1; - if ((bits_lost != 1) ^ (int)(u.bits.manl & 1)) + if (bits_lost != 1 ^ (int)(u.bits.manl & 1)) sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); } return (ldexp(sum.hi, scale)); @@ -203,17 +203,17 @@ fmal(long double x, long double y, long double z) case FE_TONEAREST: return (z); case FE_TOWARDZERO: - if ((x > 0.0) ^ (y < 0.0) ^ (z < 0.0)) + 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)) + if (x > 0.0 ^ y < 0.0) return (z); else return (nextafterl(z, -INFINITY)); default: /* FE_UPWARD */ - if ((x > 0.0) ^ (y < 0.0)) + if (x > 0.0 ^ y < 0.0) return (nextafterl(z, INFINITY)); else return (z); @@ -225,6 +225,8 @@ fmal(long double x, long double y, long double z) zs = copysignl(LDBL_MIN, zs); fesetround(FE_TONEAREST); + /* work around clang bug 8100 */ + volatile long double vxs = xs; /* * Basic approach for round-to-nearest: @@ -234,7 +236,7 @@ fmal(long double x, long double y, long double z) * adj = xy.lo + r.lo (inexact; low bit is sticky) * result = r.hi + adj (correctly rounded) */ - xy = dd_mul(xs, ys); + xy = dd_mul(vxs, ys); r = dd_add(xy.hi, zs); spread = ex + ey; @@ -255,7 +257,9 @@ fmal(long double x, long double y, long double z) * rounding modes. */ fesetround(oround); - adj = r.lo + xy.lo; + /* work around clang bug 8100 */ + volatile long double vrlo = r.lo; + adj = vrlo + xy.lo; return (ldexpl(r.hi + adj, spread)); } diff --git a/lib/libm/src/s_fmax.c b/lib/libm/src/s_fmax.c index bff356ffef..95782eec69 100644 --- a/lib/libm/src/s_fmax.c +++ b/lib/libm/src/s_fmax.c @@ -23,32 +23,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fmax.c,v 1.2 2010/03/08 01:05:20 snj Exp $ + * $FreeBSD: head/lib/msun/src/s_fmax.c 131320 2004-06-30 07:04:01Z das $ */ #include -#include +#include "fpmath.h" double fmax(double x, double y) { - union ieee_double_u u[2]; + union IEEEd2bits u[2]; - u[0].dblu_d = x; - u[1].dblu_d = y; + u[0].d = x; + u[1].d = y; /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u[0].dblu_dbl.dbl_frach | u[0].dblu_dbl.dbl_fracl) != 0) + if (u[0].bits.exp == 2047 && (u[0].bits.manh | u[0].bits.manl) != 0) return (y); - if (u[1].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u[1].dblu_dbl.dbl_frach | u[1].dblu_dbl.dbl_fracl) != 0) + if (u[1].bits.exp == 2047 && (u[1].bits.manh | u[1].bits.manl) != 0) return (x); /* Handle comparisons of signed zeroes. */ - if (u[0].dblu_dbl.dbl_sign != u[1].dblu_dbl.dbl_sign) - return (u[u[0].dblu_dbl.dbl_sign].dblu_d); + if (u[0].bits.sign != u[1].bits.sign) + return (u[u[0].bits.sign].d); return (x > y ? x : y); } diff --git a/lib/libm/src/s_fmaxf.c b/lib/libm/src/s_fmaxf.c index d724f77bb1..bb214cdfb9 100644 --- a/lib/libm/src/s_fmaxf.c +++ b/lib/libm/src/s_fmaxf.c @@ -23,32 +23,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fmaxf.c,v 1.2 2010/03/08 01:05:20 snj Exp $ + * $FreeBSD: head/lib/msun/src/s_fmaxf.c 131320 2004-06-30 07:04:01Z das $ */ #include -#include +#include "fpmath.h" float fmaxf(float x, float y) { - union ieee_single_u u[2]; + union IEEEf2bits u[2]; - u[0].sngu_f = x; - u[1].sngu_f = y; + u[0].f = x; + u[1].f = y; /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].sngu_sng.sng_exp == SNG_EXP_INFNAN && - u[0].sngu_sng.sng_frac != 0) + if (u[0].bits.exp == 255 && u[0].bits.man != 0) return (y); - if (u[1].sngu_sng.sng_exp == SNG_EXP_INFNAN && - u[1].sngu_sng.sng_frac != 0) + if (u[1].bits.exp == 255 && u[1].bits.man != 0) return (x); - /* Handle comparisons of sng_signed zeroes. */ - if (u[0].sngu_sng.sng_sign != u[1].sngu_sng.sng_sign) - return (u[u[0].sngu_sng.sng_sign].sngu_f); + /* Handle comparisons of signed zeroes. */ + if (u[0].bits.sign != u[1].bits.sign) + return (u[u[0].bits.sign].f); return (x > y ? x : y); } diff --git a/lib/libm/src/s_fmaxl.c b/lib/libm/src/s_fmaxl.c index 57685e0a6f..4d2c4841d7 100644 --- a/lib/libm/src/s_fmaxl.c +++ b/lib/libm/src/s_fmaxl.c @@ -23,37 +23,32 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fmaxl.c,v 1.3 2011/07/04 11:46:41 mrg Exp $ + * $FreeBSD: head/lib/msun/src/s_fmaxl.c 131320 2004-06-30 07:04:01Z das $ */ -#include #include -#include -#ifdef EXT_EXP_INFNAN +#include "fpmath.h" + long double fmaxl(long double x, long double y) { - union ieee_ext_u u[2]; + union IEEEl2bits u[2]; - memset(&u, 0, sizeof u); - u[0].extu_ld = x; - u[0].extu_ext.ext_frach &= ~0x80000000; - u[1].extu_ld = y; - u[1].extu_ext.ext_frach &= ~0x80000000; + u[0].e = x; + mask_nbit_l(u[0]); + u[1].e = y; + mask_nbit_l(u[1]); /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].extu_ext.ext_exp == EXT_EXP_INFNAN && - (u[0].extu_ext.ext_frach | u[0].extu_ext.ext_fracl) != 0) + if (u[0].bits.exp == 32767 && (u[0].bits.manh | u[0].bits.manl) != 0) return (y); - if (u[1].extu_ext.ext_exp == EXT_EXP_INFNAN && - (u[1].extu_ext.ext_frach | u[1].extu_ext.ext_fracl) != 0) + if (u[1].bits.exp == 32767 && (u[1].bits.manh | u[1].bits.manl) != 0) return (x); - /* Handle comparisons of ext_signed zeroes. */ - if (u[0].extu_ext.ext_sign != u[1].extu_ext.ext_sign) - return (u[0].extu_ext.ext_sign ? y : x); + /* Handle comparisons of signed zeroes. */ + if (u[0].bits.sign != u[1].bits.sign) + return (u[0].bits.sign ? y : x); return (x > y ? x : y); } -#endif diff --git a/lib/libm/src/s_fmin.c b/lib/libm/src/s_fmin.c index 7d11fa0b7e..9770d5a30c 100644 --- a/lib/libm/src/s_fmin.c +++ b/lib/libm/src/s_fmin.c @@ -23,32 +23,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fmin.c,v 1.1 2009/10/04 22:04:30 christos Exp $ + * $FreeBSD: head/lib/msun/src/s_fmin.c 131320 2004-06-30 07:04:01Z das $ */ #include -#include +#include "fpmath.h" double fmin(double x, double y) { - union ieee_double_u u[2]; + union IEEEd2bits u[2]; - u[0].dblu_d = x; - u[1].dblu_d = y; + u[0].d = x; + u[1].d = y; /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u[0].dblu_dbl.dbl_frach | u[0].dblu_dbl.dbl_fracl) != 0) + if (u[0].bits.exp == 2047 && (u[0].bits.manh | u[0].bits.manl) != 0) return (y); - if (u[1].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && - (u[1].dblu_dbl.dbl_frach | u[1].dblu_dbl.dbl_fracl) != 0) + if (u[1].bits.exp == 2047 && (u[1].bits.manh | u[1].bits.manl) != 0) return (x); /* Handle comparisons of signed zeroes. */ - if (u[0].dblu_dbl.dbl_sign != u[1].dblu_dbl.dbl_sign) - return (u[u[1].dblu_dbl.dbl_sign].dblu_d); + if (u[0].bits.sign != u[1].bits.sign) + return (u[u[1].bits.sign].d); return (x < y ? x : y); } diff --git a/lib/libm/src/s_fminf.c b/lib/libm/src/s_fminf.c index 779bd7d027..5e49971f17 100644 --- a/lib/libm/src/s_fminf.c +++ b/lib/libm/src/s_fminf.c @@ -23,32 +23,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fminf.c,v 1.2 2010/03/08 01:05:20 snj Exp $ + * $FreeBSD: head/lib/msun/src/s_fminf.c 131320 2004-06-30 07:04:01Z das $ */ #include -#include +#include "fpmath.h" float fminf(float x, float y) { - union ieee_single_u u[2]; + union IEEEf2bits u[2]; - u[0].sngu_f = x; - u[1].sngu_f = y; + u[0].f = x; + u[1].f = y; /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].sngu_sng.sng_exp == SNG_EXP_INFNAN && - u[0].sngu_sng.sng_frac != 0) + if (u[0].bits.exp == 255 && u[0].bits.man != 0) return (y); - if (u[1].sngu_sng.sng_exp == SNG_EXP_INFNAN && - u[1].sngu_sng.sng_frac != 0) + if (u[1].bits.exp == 255 && u[1].bits.man != 0) return (x); - /* Handle comparisons of sng_singed zeroes. */ - if (u[0].sngu_sng.sng_sign != u[1].sngu_sng.sng_sign) - return (u[u[1].sngu_sng.sng_sign].sngu_f); + /* Handle comparisons of signed zeroes. */ + if (u[0].bits.sign != u[1].bits.sign) + return (u[u[1].bits.sign].f); return (x < y ? x : y); } diff --git a/lib/libm/src/s_fminl.c b/lib/libm/src/s_fminl.c index 2e1befe9db..07167b188c 100644 --- a/lib/libm/src/s_fminl.c +++ b/lib/libm/src/s_fminl.c @@ -23,37 +23,32 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $NetBSD: s_fminl.c,v 1.3 2011/07/04 11:46:41 mrg Exp $ + * $FreeBSD: head/lib/msun/src/s_fminl.c 131320 2004-06-30 07:04:01Z das $ */ #include -#include -#include -#ifdef EXT_EXP_INFNAN +#include "fpmath.h" + long double fminl(long double x, long double y) { - union ieee_ext_u u[2]; + union IEEEl2bits u[2]; - memset(&u, 0, sizeof u); - u[0].extu_ld = x; - u[0].extu_ext.ext_frach &= ~0x80000000; - u[1].extu_ld = y; - u[1].extu_ext.ext_frach &= ~0x80000000; + u[0].e = x; + mask_nbit_l(u[0]); + u[1].e = y; + mask_nbit_l(u[1]); /* Check for NaNs to avoid raising spurious exceptions. */ - if (u[0].extu_ext.ext_exp == EXT_EXP_INFNAN && - (u[0].extu_ext.ext_frach | u[0].extu_ext.ext_fracl) != 0) + if (u[0].bits.exp == 32767 && (u[0].bits.manh | u[0].bits.manl) != 0) return (y); - if (u[1].extu_ext.ext_exp == EXT_EXP_INFNAN && - (u[1].extu_ext.ext_frach | u[1].extu_ext.ext_fracl) != 0) + if (u[1].bits.exp == 32767 && (u[1].bits.manh | u[1].bits.manl) != 0) return (x); - /* Handle comparisons of ext_signed zeroes. */ - if (u[0].extu_ext.ext_sign != u[1].extu_ext.ext_sign) - return (u[1].extu_ext.ext_sign ? y : x); + /* Handle comparisons of signed zeroes. */ + if (u[0].bits.sign != u[1].bits.sign) + return (u[1].bits.sign ? y : x); return (x < y ? x : y); } -#endif diff --git a/lib/libm/src/s_frexp.c b/lib/libm/src/s_frexp.c index 4f9c5bbac8..b1fe6d7fd5 100644 --- a/lib/libm/src/s_frexp.c +++ b/lib/libm/src/s_frexp.c @@ -1,4 +1,5 @@ /* @(#)s_frexp.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_frexp.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_frexp.c,v 1.13 2008/09/28 18:54:55 christos Exp $ */ /* @@ -22,7 +21,9 @@ * with *exp=0. */ -#include +#include + +#include "math.h" #include "math_private.h" static const double @@ -42,8 +43,12 @@ frexp(double x, int *eptr) ix = hx&0x7fffffff; *eptr = -54; } - *eptr += ((uint32_t)ix>>20)-1022; + *eptr += (ix>>20)-1022; hx = (hx&0x800fffff)|0x3fe00000; SET_HIGH_WORD(x,hx); return x; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(frexp, frexpl); +#endif diff --git a/lib/libm/src/s_frexpf.c b/lib/libm/src/s_frexpf.c index ef625fde1b..5ac32afeec 100644 --- a/lib/libm/src/s_frexpf.c +++ b/lib/libm/src/s_frexpf.c @@ -12,10 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: s_frexpf.c,v 1.10 2007/08/21 20:12:27 drochner Exp $ + * $FreeBSD: head/lib/msun/src/s_frexpf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float diff --git a/lib/libm/src/s_frexpl.c b/lib/libm/src/s_frexpl.c index 20b316706f..6d7c7d284d 100644 --- a/lib/libm/src/s_frexpl.c +++ b/lib/libm/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: head/lib/msun/src/s_frexpl.c 143213 2005-03-07 04:54:51Z das $ */ #include diff --git a/lib/libm/src/s_ilogb.c b/lib/libm/src/s_ilogb.c index c19669da69..ad4272de8e 100644 --- a/lib/libm/src/s_ilogb.c +++ b/lib/libm/src/s_ilogb.c @@ -1,4 +1,5 @@ /* @(#)s_ilogb.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_ilogb.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,30 +9,29 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_ilogb.c,v 1.13 2011/07/28 22:32:29 joerg Exp $ */ /* ilogb(double x) * return the binary exponent of non-zero x - * ilogb(0) = 0x80000001 - * ilogb(inf/NaN) = 0x7fffffff (no signal is raised) + * ilogb(0) = FP_ILOGB0 + * ilogb(NaN) = FP_ILOGBNAN (no signal is raised) + * ilogb(inf) = INT_MAX (no signal is raised) */ -#include +#include + +#include "math.h" #include "math_private.h" -int -ilogb(double x) + int ilogb(double x) { int32_t hx,lx,ix; - GET_HIGH_WORD(hx,x); + EXTRACT_WORDS(hx,lx,x); hx &= 0x7fffffff; if(hx<0x00100000) { - GET_LOW_WORD(lx,x); if((hx|lx)==0) - return 0x80000001; /* ilogb(0) = 0x80000001 */ + return FP_ILOGB0; else /* subnormal x */ if(hx==0) { for (ix = -1043; lx>0; lx<<=1) ix -=1; @@ -41,5 +41,6 @@ ilogb(double x) return ix; } else if (hx<0x7ff00000) return (hx>>20)-1023; - else return 0x7fffffff; + else if (hx>0x7ff00000 || lx!=0) return FP_ILOGBNAN; + else return INT_MAX; } diff --git a/lib/libm/src/s_ilogbf.c b/lib/libm/src/s_ilogbf.c index 85b24537f5..e325f59a0c 100644 --- a/lib/libm/src/s_ilogbf.c +++ b/lib/libm/src/s_ilogbf.c @@ -12,15 +12,15 @@ * is preserved. * ==================================================== * - * $NetBSD: s_ilogbf.c,v 1.7 2002/05/26 22:01:56 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_ilogbf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_ilogbf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include + +#include "math.h" #include "math_private.h" -int -ilogbf(float x) + int ilogbf(float x) { int32_t hx,ix; @@ -28,11 +28,12 @@ ilogbf(float x) hx &= 0x7fffffff; if(hx<0x00800000) { if(hx==0) - return 0x80000001; /* ilogb(0) = 0x80000001 */ + return FP_ILOGB0; else /* subnormal x */ for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1; return ix; } else if (hx<0x7f800000) return (hx>>23)-127; - else return 0x7fffffff; + else if (hx>0x7f800000) return FP_ILOGBNAN; + else return INT_MAX; } diff --git a/lib/libm/src/s_ilogbl.c b/lib/libm/src/s_ilogbl.c index 780a8e5caa..38a1cf40cc 100644 --- a/lib/libm/src/s_ilogbl.c +++ b/lib/libm/src/s_ilogbl.c @@ -1,71 +1,51 @@ -/* $NetBSD: s_ilogbl.c,v 1.1 2011/07/28 22:32:29 joerg Exp $ */ - -/*- - * Copyright (c) 2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Joerg Sonnenberger. +/* + * From: @(#)s_ilogb.c 5.1 93/09/24 + * $FreeBSD: head/lib/msun/src/s_ilogbl.c 176451 2008-02-22 02:30:36Z das $ + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, 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. + * 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 +#include #include -#include -#ifdef __HAVE_LONG_DOUBLE - -#if LDBL_MANT_DIG == 64 -#define FROM_UNDERFLOW 0x1p65L -#elif LDBL_MANT_DIG == 113 -#define FROM_UNDERFLOW 0x1p114L -#else -#error Unsupported long double format -#endif +#include "fpmath.h" int ilogbl(long double x) { - union ieee_ext_u u; - - if (x == 0.0L) - return 0x80000001; /* ilogbl(0) = 0x80000001 */ - - u.extu_ld = x; - - if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) - return 0x7fffffff; - - if (u.extu_ext.ext_exp == 0) { - /* - * Scale denormalized numbers slightly, - * so that they are normal. - */ - u.extu_ld *= FROM_UNDERFLOW; - return u.extu_ext.ext_exp - EXT_EXP_BIAS - LDBL_MANT_DIG - 1; - } - return u.extu_ext.ext_exp - EXT_EXP_BIAS; - -} - + union IEEEl2bits u; + unsigned long m; + int b; + + u.e = x; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_ILOGB0); + /* 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 (LDBL_MIN_EXP - b - 1); + } else if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) + return (u.bits.exp - LDBL_MAX_EXP + 1); + else if (u.bits.manl != 0 || u.bits.manh != 0) + return (FP_ILOGBNAN); + else + return (INT_MAX); +} diff --git a/lib/libm/src/s_fdim.c b/lib/libm/src/s_isfinite.c similarity index 78% copy from lib/libm/src/s_fdim.c copy to lib/libm/src/s_isfinite.c index 9c43300b65..85d94025f4 100644 --- a/lib/libm/src/s_fdim.c +++ b/lib/libm/src/s_isfinite.c @@ -22,22 +22,37 @@ * 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: head/lib/msun/src/s_isfinite.c 131852 2004-07-09 03:32:40Z das $ */ #include -#define DECL(type, fn) \ -type \ -fn(type x, type y) \ -{ \ - \ - if (isnan(x)) \ - return (x); \ - if (isnan(y)) \ - return (y); \ - return (x > y ? x - y : 0.0); \ +#include "fpmath.h" + +int +__isfinite(double d) +{ + union IEEEd2bits u; + + u.d = d; + return (u.bits.exp != 2047); +} + +int +__isfinitef(float f) +{ + union IEEEf2bits u; + + u.f = f; + return (u.bits.exp != 255); } -DECL(double, fdim) -DECL(float, fdimf) -DECL(long double, fdiml) +int +__isfinitel(long double e) +{ + union IEEEl2bits u; + + u.e = e; + return (u.bits.exp != 32767); +} diff --git a/lib/libc/gen/frexp.c b/lib/libm/src/s_isnan.c similarity index 73% copy from lib/libc/gen/frexp.c copy to lib/libm/src/s_isnan.c index 24e10697e5..eb731ba490 100644 --- a/lib/libc/gen/frexp.c +++ b/lib/libm/src/s_isnan.c @@ -23,35 +23,43 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/gen/frexp.c,v 1.1 2004/07/18 21:23:39 das Exp $ + * $FreeBSD: head/lib/msun/src/s_isnan.c 242879 2012-11-10 21:22:10Z dim $ */ #include #include "fpmath.h" -double -frexp(double d, int *ex) +/* Provided by libc.so */ +#ifndef PIC +#undef isnan +int +isnan(double d) { union IEEEd2bits u; u.d = d; - switch (u.bits.exp) { - case 0: /* 0 or subnormal */ - if ((u.bits.manl | u.bits.manh) == 0) { - *ex = 0; - } else { - u.d *= 0x1.0p514; - *ex = u.bits.exp - 1536; - u.bits.exp = 1022; - } - break; - case 2047: /* infinity or NaN; value of *ex is unspecified */ - break; - default: /* normal */ - *ex = u.bits.exp - 1022; - u.bits.exp = 1022; - break; - } - return (u.d); + return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); } +#endif /* !PIC */ + +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)); +} + +__weak_reference(__isnanf, isnanf); diff --git a/lib/libm/src/s_fdim.c b/lib/libm/src/s_isnormal.c similarity index 76% copy from lib/libm/src/s_fdim.c copy to lib/libm/src/s_isnormal.c index 9c43300b65..aaaab63761 100644 --- a/lib/libm/src/s_fdim.c +++ b/lib/libm/src/s_isnormal.c @@ -22,22 +22,37 @@ * 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: head/lib/msun/src/s_isnormal.c 131852 2004-07-09 03:32:40Z das $ */ #include -#define DECL(type, fn) \ -type \ -fn(type x, type y) \ -{ \ - \ - if (isnan(x)) \ - return (x); \ - if (isnan(y)) \ - return (y); \ - return (x > y ? x - y : 0.0); \ +#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); } -DECL(double, fdim) -DECL(float, fdimf) -DECL(long double, fdiml) +int +__isnormall(long double e) +{ + union IEEEl2bits u; + + u.e = e; + return (u.bits.exp != 0 && u.bits.exp != 32767); +} diff --git a/lib/libm/src/s_llrint.c b/lib/libm/src/s_llrint.c deleted file mode 100644 index edc631a16a..0000000000 --- a/lib/libm/src/s_llrint.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * FreeBSD SVN: 140088 (2005-01-11) - */ - -#define type double -#define roundit rint -#define dtype long long -#define fn llrint - -#include "s_lrint.c" diff --git a/lib/libm/src/s_llrintf.c b/lib/libm/src/s_llrintf.c deleted file mode 100644 index a684b7bed6..0000000000 --- a/lib/libm/src/s_llrintf.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * FreeBSD SVN: 140088 (2005-01-11) - */ - -#define type float -#define roundit rintf -#define dtype long long -#define fn llrintf - -#include "s_lrint.c" diff --git a/lib/libm/src/s_llrintl.c b/lib/libm/src/s_llrintl.c deleted file mode 100644 index 0b01b3da4e..0000000000 --- a/lib/libm/src/s_llrintl.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * FreeBSD SVN: 175309 (2008-01-14) - */ - -#define type long double -#define roundit rintl -#define dtype long long -#define fn llrintl - -#include "s_lrint.c" diff --git a/lib/libm/src/s_llround.c b/lib/libm/src/s_llround.c index 43507bfdab..f64ba465bc 100644 --- a/lib/libm/src/s_llround.c +++ b/lib/libm/src/s_llround.c @@ -1,6 +1,4 @@ -/* - * FreeBSD SVN: 144771 (2005-04-08) - */ +/* $FreeBSD: head/lib/msun/src/s_llround.c 144771 2005-04-08 00:52:27Z das $ */ #define type double #define roundit round diff --git a/lib/libm/src/s_llroundf.c b/lib/libm/src/s_llroundf.c index ba4d4f97f0..54a5ffd67d 100644 --- a/lib/libm/src/s_llroundf.c +++ b/lib/libm/src/s_llroundf.c @@ -1,6 +1,4 @@ -/* - * FreeBSD SVN: 144771 (2005-04-08) - */ +/* $FreeBSD: head/lib/msun/src/s_llroundf.c 144771 2005-04-08 00:52:27Z das $ */ #define type float #define roundit roundf diff --git a/lib/libm/src/s_llroundl.c b/lib/libm/src/s_llroundl.c index 2ab12557d1..18be454331 100644 --- a/lib/libm/src/s_llroundl.c +++ b/lib/libm/src/s_llroundl.c @@ -1,6 +1,4 @@ -/* - * FreeBSD SVN: 144772 (2005-04-08) - */ +/* $FreeBSD: head/lib/msun/src/s_llroundl.c 144772 2005-04-08 01:24:08Z das $ */ #define type long double #define roundit roundl diff --git a/lib/libm/src/s_log1p.c b/lib/libm/src/s_log1p.c index 835c830298..7d68280be5 100644 --- a/lib/libm/src/s_log1p.c +++ b/lib/libm/src/s_log1p.c @@ -1,4 +1,5 @@ /* @(#)s_log1p.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_log1p.c 251024 2013-05-27 08:50:10Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_log1p.c,v 1.12 2002/05/26 22:01:57 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_log1p.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* double log1p(double x) @@ -78,7 +76,9 @@ * See HP-15C Advanced Functions Handbook, p.193. */ -#include +#include + +#include "math.h" #include "math_private.h" static const double @@ -94,6 +94,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) @@ -101,15 +102,13 @@ log1p(double x) double hfsq,f,c,s,z,R,u; int32_t k,hx,hu,ax; - f = c = 0; - hu = 0; GET_HIGH_WORD(hx,x); ax = hx&0x7fffffff; k = 1; - if (hx < 0x3FDA827A) { /* x < 0.41422 */ + 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 */ @@ -119,13 +118,13 @@ log1p(double x) else return x - x*x*0.5; } - if(hx>0||hx<=((int32_t)0xbfd2bec3)) { - k=0;f=x;hu=1;} /* -0.29290||hx<=((int32_t)0xbfd2bec4)) { + k=0;f=x;hu=1;} /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ } 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 */ @@ -137,7 +136,14 @@ log1p(double x) c = 0; } hu &= 0x000fffff; - if(hu<0x6a09e) { + /* + * The approximation to sqrt(2) used in thresholds is not + * critical. However, the ones used above must give less + * strict bounds than the one here so that the k==0 case is + * never reached from here, since here we have committed to + * using the correction term but don't use it if k==0. + */ + if(hu<0x6a09e) { /* u ~< sqrt(2) */ SET_HIGH_WORD(u,hu|0x3ff00000); /* normalize u */ } else { k += 1; @@ -148,8 +154,13 @@ 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 diff --git a/lib/libm/src/s_log1pf.c b/lib/libm/src/s_log1pf.c index 091eb686a9..49c4ab9aa3 100644 --- a/lib/libm/src/s_log1pf.c +++ b/lib/libm/src/s_log1pf.c @@ -11,12 +11,12 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_log1pf.c,v 1.8 2002/05/26 22:01:57 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_log1pf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_log1pf.c 251024 2013-05-27 08:50:10Z das $ */ -#include +#include + +#include "math.h" #include "math_private.h" static const float @@ -32,6 +32,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) @@ -39,31 +40,29 @@ log1pf(float x) float hfsq,f,c,s,z,R,u; int32_t k,hx,hu,ax; - f = c = 0; - hu = 0; GET_FLOAT_WORD(hx,x); ax = hx&0x7fffffff; k = 1; - if (hx < 0x3ed413d7) { /* x < 0.41422 */ + 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; } - if(hx>0||hx<=((int32_t)0xbe95f61f)) { - k=0;f=x;hu=1;} /* -0.29290||hx<=((int32_t)0xbe95f619)) { + k=0;f=x;hu=1;} /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ } if (hx >= 0x7f800000) return x+x; if(k!=0) { if(hx<0x5a000000) { - u = (float)1.0+x; + STRICT_ASSIGN(float,u,(float)1.0+x); GET_FLOAT_WORD(hu,u); k = (hu>>23)-127; /* correction term */ @@ -76,7 +75,14 @@ log1pf(float x) c = 0; } hu &= 0x007fffff; - if(hu<0x3504f7) { + /* + * The approximation to sqrt(2) used in thresholds is not + * critical. However, the ones used above must give less + * strict bounds than the one here so that the k==0 case is + * never reached from here, since here we have committed to + * using the correction term but don't use it if k==0. + */ + if(hu<0x3504f4) { /* u < sqrt(2) */ SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */ } else { k += 1; @@ -87,8 +93,13 @@ 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 diff --git a/lib/libm/src/s_logb.c b/lib/libm/src/s_logb.c index 82c89f5bae..49ca3ed05d 100644 --- a/lib/libm/src/s_logb.c +++ b/lib/libm/src/s_logb.c @@ -1,4 +1,5 @@ /* @(#)s_logb.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_logb.c 176101 2008-02-08 01:22:13Z bde $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_logb.c,v 1.12 2011/08/03 14:13:07 joerg Exp $ */ /* @@ -18,9 +17,14 @@ * Use ilogb instead. */ -#include +#include + +#include "math.h" #include "math_private.h" +static const double +two54 = 1.80143985094819840000e+16; /* 43500000 00000000 */ + double logb(double x) { @@ -29,8 +33,15 @@ logb(double x) ix &= 0x7fffffff; /* high |x| */ if((ix|lx)==0) return -1.0/fabs(x); if(ix>=0x7ff00000) return x*x; - if((ix>>=20)==0) /* IEEE 754 logb */ - return -1022.0; - else - return (double) (ix-1023); + if(ix<0x00100000) { + x *= two54; /* convert subnormal x to normal */ + GET_HIGH_WORD(ix,x); + ix &= 0x7fffffff; + return (double) ((ix>>20)-1023-54); + } else + return (double) ((ix>>20)-1023); } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(logb, logbl); +#endif diff --git a/lib/libm/src/s_logbf.c b/lib/libm/src/s_logbf.c index 73e43be95f..6333f6f980 100644 --- a/lib/libm/src/s_logbf.c +++ b/lib/libm/src/s_logbf.c @@ -12,13 +12,15 @@ * is preserved. * ==================================================== * - * $NetBSD: s_logbf.c,v 1.7 2002/05/26 22:01:57 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_logbf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_logbf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" +static const float +two25 = 3.355443200e+07; /* 0x4c000000 */ + float logbf(float x) { @@ -27,8 +29,11 @@ logbf(float x) ix &= 0x7fffffff; /* high |x| */ if(ix==0) return (float)-1.0/fabsf(x); if(ix>=0x7f800000) return x*x; - if((ix>>=23)==0) /* IEEE 754 logb */ - return -126.0; - else - return (float) (ix-127); + if(ix<0x00800000) { + x *= two25; /* convert subnormal x to normal */ + GET_FLOAT_WORD(ix,x); + ix &= 0x7fffffff; + return (float) ((ix>>23)-127-25); + } else + return (float) ((ix>>23)-127); } diff --git a/lib/libm/src/s_logbl.c b/lib/libm/src/s_logbl.c deleted file mode 100644 index 4dfc2e50af..0000000000 --- a/lib/libm/src/s_logbl.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $NetBSD: s_logbl.c,v 1.1 2011/08/03 14:13:07 joerg Exp $ */ - -/*- - * Copyright (c) 2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Joerg Sonnenberger. - * - * 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. - */ - -#include -#include -#include - -#ifdef __HAVE_LONG_DOUBLE - -#if LDBL_MANT_DIG == 64 -#define FROM_UNDERFLOW 0x1p65L -#elif LDBL_MANT_DIG == 113 -#define FROM_UNDERFLOW 0x1p114L -#else -#error Unsupported long double format -#endif - -long double -logbl(long double x) -{ - union ieee_ext_u u; - - if (x == 0.0L) - return -1.0L / fabsl(x); /* -HUGE_VALL + exception */ - - u.extu_ld = x; - - if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) - return fabsl(x); /* NaN or +Inf */ - - if (u.extu_ext.ext_exp == 0) { - /* - * Scale denormalized numbers slightly, - * so that they are normal. - */ - u.extu_ld *= FROM_UNDERFLOW; - return u.extu_ext.ext_exp - EXT_EXP_BIAS - LDBL_MANT_DIG - 1; - } - return u.extu_ext.ext_exp - EXT_EXP_BIAS; - -} - -#endif diff --git a/lib/libm/src/s_lrint.c b/lib/libm/src/s_lrint.c deleted file mode 100644 index 4242912334..0000000000 --- a/lib/libm/src/s_lrint.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 2005 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * FreeBSD SVN: 140088 (2005-01-11) - */ - -#include -#include - -#ifndef type -#define type double -#define roundit rint -#define dtype long -#define fn lrint -#endif - -/* - * C99 says we should not raise a spurious inexact exception when an - * invalid exception is raised. Unfortunately, the set of inputs - * that overflows depends on the rounding mode when 'dtype' has more - * significant bits than 'type'. Hence, we bend over backwards for the - * sake of correctness; an MD implementation could be more efficient. - */ -dtype -fn(type x) -{ - fenv_t env; - dtype d; - - feholdexcept(&env); - d = (dtype)roundit(x); - if (fetestexcept(FE_INVALID)) - feclearexcept(FE_INEXACT); - feupdateenv(&env); - return (d); -} diff --git a/lib/libm/src/s_lrintf.c b/lib/libm/src/s_lrintf.c deleted file mode 100644 index e791538ab6..0000000000 --- a/lib/libm/src/s_lrintf.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * FreeBSD SVN: 153017 (2005-12-02) - */ - -#define type float -#define roundit rintf -#define dtype long -#define fn lrintf - -#include "s_lrint.c" diff --git a/lib/libm/src/s_lrintl.c b/lib/libm/src/s_lrintl.c deleted file mode 100644 index aabdde8b61..0000000000 --- a/lib/libm/src/s_lrintl.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * FreeBSD SVN: 175309 (2008-01-14) - */ - -#define type long double -#define roundit rintl -#define dtype long -#define fn lrintl - -#include "s_lrint.c" diff --git a/lib/libm/src/s_lround.c b/lib/libm/src/s_lround.c index 2f9bc002e2..dd90494c11 100644 --- a/lib/libm/src/s_lround.c +++ b/lib/libm/src/s_lround.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 144770 (2005-04-08) + * $FreeBSD: head/lib/msun/src/s_lround.c 144770 2005-04-08 00:52:16Z das $ */ #include diff --git a/lib/libm/src/s_lroundf.c b/lib/libm/src/s_lroundf.c index 00deeb50b5..54d39d9525 100644 --- a/lib/libm/src/s_lroundf.c +++ b/lib/libm/src/s_lroundf.c @@ -1,6 +1,4 @@ -/* - * FreeBSD SVN: 144771 (2005-04-08) - */ +/* $FreeBSD: head/lib/msun/src/s_lroundf.c 144771 2005-04-08 00:52:27Z das $ */ #define type float #define roundit roundf diff --git a/lib/libm/src/s_lroundl.c b/lib/libm/src/s_lroundl.c index b68fbfc79f..157bc0d596 100644 --- a/lib/libm/src/s_lroundl.c +++ b/lib/libm/src/s_lroundl.c @@ -1,6 +1,4 @@ -/* - * FreeBSD SVN: 144772 (2005-04-08) - */ +/* $FreeBSD: head/lib/msun/src/s_lroundl.c 144772 2005-04-08 01:24:08Z das $ */ #define type long double #define roundit roundl diff --git a/lib/libm/src/s_modf.c b/lib/libm/src/s_modf.c index aab8d0a19e..b16516d1b7 100644 --- a/lib/libm/src/s_modf.c +++ b/lib/libm/src/s_modf.c @@ -1,4 +1,5 @@ /* @(#)s_modf.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_modf.c 165838 2007-01-06 21:22:38Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * FreeBSD SVN: 165838 (2007-01-06) */ /* @@ -22,7 +21,7 @@ * No exception. */ -#include +#include "math.h" #include "math_private.h" static const double one = 1.0; diff --git a/lib/libm/src/s_modff.c b/lib/libm/src/s_modff.c index f3bc269133..9c8ee73f10 100644 --- a/lib/libm/src/s_modff.c +++ b/lib/libm/src/s_modff.c @@ -12,10 +12,10 @@ * is preserved. * ==================================================== * - * $NetBSD: s_modff.c,v 1.9 2010/01/27 14:07:41 drochner Exp $ $ + * $FreeBSD: head/lib/msun/src/s_modff.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" static const float one = 1.0; @@ -23,16 +23,16 @@ static const float one = 1.0; float modff(float x, float *iptr) { - int32_t i0,jj0; + int32_t i0,j0; u_int32_t i; GET_FLOAT_WORD(i0,x); - jj0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */ - if(jj0<23) { /* integer part in x */ - if(jj0<0) { /* |x|<1 */ + j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */ + if(j0<23) { /* integer part in x */ + if(j0<0) { /* |x|<1 */ SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */ return x; } else { - i = (0x007fffff)>>jj0; + i = (0x007fffff)>>j0; if((i0&i)==0) { /* x is integral */ u_int32_t ix; *iptr = x; @@ -47,8 +47,8 @@ modff(float x, float *iptr) } else { /* no fraction part */ u_int32_t ix; *iptr = x*one; - if (jj0 == 0x80) /* +-inf or NaN */ - return 0.0 / x; /* +-0 or NaN */ + if (x != x) /* NaN */ + return x; GET_FLOAT_WORD(ix,x); SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ return x; diff --git a/lib/libm/src/s_modfl.c b/lib/libm/src/s_modfl.c index fb9f75d731..0fcb8f950f 100644 --- a/lib/libm/src/s_modfl.c +++ b/lib/libm/src/s_modfl.c @@ -33,7 +33,7 @@ * is preserved. * ==================================================== * - * FreeBSD SVN: 165855 (2007-01-06) + * $FreeBSD: head/lib/msun/src/s_modfl.c 165855 2007-01-07 07:54:21Z das $ */ #include diff --git a/lib/libm/src/s_nan.c b/lib/libm/src/s_nan.c new file mode 100644 index 0000000000..bd1ab0681c --- /dev/null +++ b/lib/libm/src/s_nan.c @@ -0,0 +1,121 @@ +/*- + * 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: head/lib/msun/src/s_nan.c 174759 2007-12-18 23:46:32Z das $ + */ + +#include +#include +#include +#include +#include +#include + +#include "math_private.h" + +static int +digittoint(char c) +{ + + if (isdigit(c)) + return (c - '0'); + if (islower(c)) + return (c - 'a' + 10); + return (c - 'A' + 10); +} + +/* + * Scan a string of hexadecimal digits (the format nan(3) expects) and + * make a bit array (using the local endianness). We stop when we + * encounter an invalid character, NUL, etc. If we overflow, we do + * the same as gcc's __builtin_nan(), namely, discard the high order bits. + * + * The format this routine accepts needs to be compatible with what is used + * in contrib/gdtoa/hexnan.c (for strtod/scanf) and what is used in + * __builtin_nan(). In fact, we're only 100% compatible for strings we + * consider valid, so we might be violating the C standard. But it's + * impossible to use nan(3) portably anyway, so this seems good enough. + */ +void +_scan_nan(uint32_t *words, int num_words, const char *s) +{ + int si; /* index into s */ + int bitpos; /* index into words (in bits) */ + + bzero(words, num_words * sizeof(uint32_t)); + + /* Allow a leading '0x'. (It's expected, but redundant.) */ + if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) + s += 2; + + /* Scan forwards in the string, looking for the end of the sequence. */ + for (si = 0; isxdigit(s[si]); si++) + ; + + /* Scan backwards, filling in the bits in words[] as we go. */ +#if _BYTE_ORDER == _LITTLE_ENDIAN + for (bitpos = 0; bitpos < 32 * num_words; bitpos += 4) { +#else + for (bitpos = 32 * num_words - 4; bitpos >= 0; bitpos -= 4) { +#endif + if (--si < 0) + break; + words[bitpos / 32] |= digittoint(s[si]) << (bitpos % 32); + } +} + +double +nan(const char *s) +{ + union { + double d; + uint32_t bits[2]; + } u; + + _scan_nan(u.bits, 2, s); +#if _BYTE_ORDER == _LITTLE_ENDIAN + u.bits[1] |= 0x7ff80000; +#else + u.bits[0] |= 0x7ff80000; +#endif + return (u.d); +} + +float +nanf(const char *s) +{ + union { + float f; + uint32_t bits[1]; + } u; + + _scan_nan(u.bits, 1, s); + u.bits[0] |= 0x7fc00000; + return (u.f); +} + +#if (LDBL_MANT_DIG == 53) +__weak_reference(nan, nanl); +#endif diff --git a/lib/libm/src/s_nearbyint.c b/lib/libm/src/s_nearbyint.c index 1bd3ad19ca..33b0cefeee 100644 --- a/lib/libm/src/s_nearbyint.c +++ b/lib/libm/src/s_nearbyint.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 175309 (2008-01-14) + * $FreeBSD: head/lib/msun/src/s_nearbyint.c 251024 2013-05-27 08:50:10Z das $ */ #include @@ -35,12 +35,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); \ diff --git a/lib/libm/src/s_nextafter.c b/lib/libm/src/s_nextafter.c index 61b1f87cc5..271279f05b 100644 --- a/lib/libm/src/s_nextafter.c +++ b/lib/libm/src/s_nextafter.c @@ -1,4 +1,5 @@ /* @(#)s_nextafter.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_nextafter.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_nextafter.c,v 1.12 2011/04/18 15:59:09 drochner Exp $ */ /* IEEE functions @@ -19,12 +18,15 @@ * Special cases: */ -#include +#include + +#include "math.h" #include "math_private.h" double nextafter(double x, double y) { + volatile double t; int32_t hx,hy,ix,iy; u_int32_t lx,ly; @@ -39,8 +41,8 @@ nextafter(double x, double y) if(x==y) return y; /* x=y, return y */ if((ix|lx)==0) { /* x == 0 */ INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ - y = x*x; - if(y==x) return y; else return x; /* raise underflow flag */ + t = x*x; + if(t==x) return t; else return x; /* raise underflow flag */ } if(hx>=0) { /* x > 0 */ if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */ @@ -62,8 +64,8 @@ nextafter(double x, double y) hy = hx&0x7ff00000; if(hy>=0x7ff00000) return x+x; /* overflow */ if(hy<0x00100000) { /* underflow */ - y = x*x; - if(y!=x) { /* raise underflow flag */ + t = x*x; + if(t!=x) { /* raise underflow flag */ INSERT_WORDS(y,hx,lx); return y; } @@ -71,3 +73,9 @@ nextafter(double x, double y) INSERT_WORDS(x,hx,lx); return x; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(nextafter, nexttoward); +__weak_reference(nextafter, nexttowardl); +__weak_reference(nextafter, nextafterl); +#endif diff --git a/lib/libm/src/s_nextafterf.c b/lib/libm/src/s_nextafterf.c index a9f19533ef..e4ae7ef4c1 100644 --- a/lib/libm/src/s_nextafterf.c +++ b/lib/libm/src/s_nextafterf.c @@ -12,15 +12,16 @@ * is preserved. * ==================================================== * - * $NetBSD: s_nextafterf.c,v 1.8 2011/04/18 15:59:09 drochner Exp $ + * $FreeBSD: head/lib/msun/src/s_nextafterf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" float nextafterf(float x, float y) { + volatile float t; int32_t hx,hy,ix,iy; GET_FLOAT_WORD(hx,x); @@ -34,8 +35,8 @@ nextafterf(float x, float y) if(x==y) return y; /* x=y, return y */ if(ix==0) { /* x == 0 */ SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */ - y = x*x; - if(y==x) return y; else return x; /* raise underflow flag */ + t = x*x; + if(t==x) return t; else return x; /* raise underflow flag */ } if(hx>=0) { /* x > 0 */ if(hx>hy) { /* x > y, x -= ulp */ @@ -53,8 +54,8 @@ nextafterf(float x, float y) hy = hx&0x7f800000; if(hy>=0x7f800000) return x+x; /* overflow */ if(hy<0x00800000) { /* underflow */ - y = x*x; - if(y!=x) { /* raise underflow flag */ + t = x*x; + if(t!=x) { /* raise underflow flag */ SET_FLOAT_WORD(y,hx); return y; } diff --git a/lib/libm/src/s_nextafterl.c b/lib/libm/src/s_nextafterl.c index e48d1ff83d..988fa29149 100644 --- a/lib/libm/src/s_nextafterl.c +++ b/lib/libm/src/s_nextafterl.c @@ -1,6 +1,5 @@ -/* $NetBSD: s_nextafterl.c,v 1.2 2010/09/17 20:39:39 christos Exp $ */ - /* @(#)s_nextafter.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_nextafterl.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -12,80 +11,68 @@ * ==================================================== */ +/* IEEE functions + * nextafter(x,y) + * return the next machine floating-point number of x in the + * direction toward y. + * Special cases: + */ + #include -#include -#include -#ifdef EXT_EXP_INFNAN +#include "fpmath.h" +#include "math.h" +#include "math_private.h" + #if LDBL_MAX_EXP != 0x4000 #error "Unsupported long double format" #endif -/* - * IEEE functions - * nextafterl(x,y) - * return the next machine floating-point number of x in the - * direction toward y. - * Special cases: - * If x == y, y shall be returned - * If x or y is NaN, a NaN shall be returned - */ long double nextafterl(long double x, long double y) { volatile long double t; - union ieee_ext_u ux, uy; + union IEEEl2bits ux, uy; - ux.extu_ld = x; - uy.extu_ld = y; + ux.e = x; + uy.e = y; - if ((ux.extu_exp == EXT_EXP_NAN && - ((ux.extu_frach &~ LDBL_NBIT)|ux.extu_fracl) != 0) || - (uy.extu_exp == EXT_EXP_NAN && - ((uy.extu_frach &~ LDBL_NBIT)|uy.extu_fracl) != 0)) - return x+y; /* x or y is nan */ - - if (x == y) return y; /* x=y, return y */ - - if (x == 0.0) { - ux.extu_frach = 0; /* return +-minsubnormal */ - ux.extu_fracl = 1; - ux.extu_sign = uy.extu_sign; - t = ux.extu_ld * ux.extu_ld; - if (t == ux.extu_ld) - return t; - else - return ux.extu_ld; /* raise underflow flag */ + if ((ux.bits.exp == 0x7fff && + ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl) != 0) || + (uy.bits.exp == 0x7fff && + ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0)) + return x+y; /* x or y is nan */ + if(x==y) return y; /* x=y, return y */ + if(x==0.0) { + ux.bits.manh = 0; /* return +-minsubnormal */ + ux.bits.manl = 1; + ux.bits.sign = uy.bits.sign; + t = ux.e*ux.e; + if(t==ux.e) return t; else return ux.e; /* raise underflow flag */ } - - if ((x>0.0) ^ (x0.0 ^ x -#include -#include +#include "fpmath.h" +#include "math.h" #include "math_private.h" #if LDBL_MAX_EXP != 0x4000 #error "Unsupported long double format" #endif -/* - * The nexttoward() function is equivalent to nextafter() function, - * except that the second parameter shall have type long double and - * the functions shall return y converted to the type of the function - * if x equals y. - * - * Special cases: XXX - */ double nexttoward(double x, long double y) { - union ieee_ext_u uy; + union IEEEl2bits uy; volatile double t; - int32_t hx, ix; - uint32_t lx; + int32_t hx,ix; + u_int32_t lx; - EXTRACT_WORDS(hx, lx, x); - ix = hx & 0x7fffffff; /* |x| */ - uy.extu_ld = y; + EXTRACT_WORDS(hx,lx,x); + ix = hx&0x7fffffff; /* |x| */ + uy.e = y; - if (((ix >= 0x7ff00000) && ((ix - 0x7ff00000) | lx) != 0) || - (uy.extu_exp == 0x7fff && - ((uy.extu_frach & ~LDBL_NBIT) | uy.extu_fracl) != 0)) - return x+y; /* x or y is nan */ - - if (x == y) - return (double)y; /* x=y, return y */ - - if (x == 0.0) { - INSERT_WORDS(x, uy.extu_sign<<31, 1); /* return +-minsubnormal */ - t = x*x; - if (t == x) - return t; - else - return x; /* raise underflow flag */ + if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || + (uy.bits.exp == 0x7fff && + ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl) != 0)) + return x+y; /* x or y is nan */ + if(x==y) return (double)y; /* x=y, return y */ + if(x==0.0) { + INSERT_WORDS(x,uy.bits.sign<<31,1); /* return +-minsubnormal */ + t = x*x; + if(t==x) return t; else return x; /* raise underflow flag */ } - - if ((hx > 0.0) ^ (x < y)) { /* x -= ulp */ - if (lx == 0) hx -= 1; - lx -= 1; + if(hx>0.0 ^ x < y) { /* x -= ulp */ + if(lx==0) hx -= 1; + lx -= 1; } else { /* x += ulp */ - lx += 1; - if (lx == 0) hx += 1; + lx += 1; + if(lx==0) hx += 1; } - ix = hx & 0x7ff00000; - if (ix >= 0x7ff00000) return x+x; /* overflow */ - if (ix < 0x00100000) { /* underflow */ - t = x*x; - if (t != x) { /* raise underflow flag */ - INSERT_WORDS(y, hx, lx); - return y; - } + ix = hx&0x7ff00000; + if(ix>=0x7ff00000) return x+x; /* overflow */ + if(ix<0x00100000) { /* underflow */ + t = x*x; + if(t!=x) { /* raise underflow flag */ + INSERT_WORDS(x,hx,lx); + return x; + } } - INSERT_WORDS(x, hx, lx); - + INSERT_WORDS(x,hx,lx); return x; } diff --git a/lib/libm/src/s_nexttowardf.c b/lib/libm/src/s_nexttowardf.c index 025bcbc468..4be74334a7 100644 --- a/lib/libm/src/s_nexttowardf.c +++ b/lib/libm/src/s_nexttowardf.c @@ -8,13 +8,13 @@ * is preserved. * ==================================================== * - * FreeBSD SVN: 218511 (2011-02-10) + * $FreeBSD: head/lib/msun/src/s_nexttowardf.c 218511 2011-02-10 07:38:38Z das $ */ #include -#include #include "fpmath.h" +#include "math.h" #include "math_private.h" #define LDBL_INFNAN_EXP (LDBL_MAX_EXP * 2 - 1) @@ -40,7 +40,7 @@ nexttowardf(float x, long double y) t = x*x; if(t==x) return t; else return x; /* raise underflow flag */ } - if((hx>=0) ^ (x < y)) /* x -= ulp */ + if(hx>=0 ^ x < y) /* x -= ulp */ hx -= 1; else /* x += ulp */ hx += 1; diff --git a/lib/libm/src/s_remquo.c b/lib/libm/src/s_remquo.c deleted file mode 100644 index 6f23bae3dc..0000000000 --- a/lib/libm/src/s_remquo.c +++ /dev/null @@ -1,153 +0,0 @@ -/* @(#)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 - -#include - -#include -#include "math_private.h" - -static const double Zero[] = {0.0, -0.0,}; - -/* - * 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. - */ -double -remquo(double x, double y, int *quo) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - u_int32_t lx,ly,lz,q,sxy; - - EXTRACT_WORDS(hx,lx,x); - EXTRACT_WORDS(hy,ly,y); - sxy = (hx ^ hy) & 0x80000000; - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ - ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ - return (x*y)/(x*y); - if(hx<=hy) { - if((hx>31]; /* |x|=|y| return x*0*/ - } - } - - /* determine ix = ilogb(x) */ - if(hx<0x00100000) { /* subnormal x */ - if(hx==0) { - for (ix = -1043, i=lx; i>0; i<<=1) ix -=1; - } else { - for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1; - } - } else ix = (hx>>20)-1023; - - /* determine iy = ilogb(y) */ - if(hy<0x00100000) { /* subnormal y */ - if(hy==0) { - for (iy = -1043, i=ly; i>0; i<<=1) iy -=1; - } else { - for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1; - } - } else iy = (hy>>20)-1023; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -1022) - hx = 0x00100000|(0x000fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -1022-ix; - if(n<=31) { - hx = (hx<>(32-n)); - lx <<= n; - } else { - hx = lx<<(n-32); - lx = 0; - } - } - if(iy >= -1022) - hy = 0x00100000|(0x000fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -1022-iy; - if(n<=31) { - hy = (hy<>(32-n)); - ly <<= n; - } else { - hy = ly<<(n-32); - ly = 0; - } - } - - /* fix point fmod */ - n = ix - iy; - q = 0; - while(n--) { - hz=hx-hy;lz=lx-ly; if(lx>31); lx = lx+lx;} - else {hx = hz+hz+(lz>>31); lx = lz+lz; q++;} - q <<= 1; - } - hz=hx-hy;lz=lx-ly; if(lx=0) {hx=hz;lx=lz;q++;} - - /* convert back to floating value and restore the sign */ - if((hx|lx)==0) { /* return sign(x)*0 */ - *quo = (sxy ? -q : q); - return Zero[(u_int32_t)sx>>31]; - } - while(hx<0x00100000) { /* normalize x */ - hx = hx+hx+(lx>>31); lx = lx+lx; - iy -= 1; - } - if(iy>= -1022) { /* normalize output */ - hx = ((hx-0x00100000)|((iy+1023)<<20)); - } else { /* subnormal output */ - n = -1022 - iy; - if(n<=20) { - lx = (lx>>n)|((u_int32_t)hx<<(32-n)); - hx >>= n; - } else if (n<=31) { - lx = (hx<<(32-n))|(lx>>n); hx = sx; - } else { - lx = hx>>(n-32); hx = sx; - } - } -fixup: - INSERT_WORDS(x,hx,lx); - y = fabs(y); - if (y < 0x1p-1021) { - 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; - } - GET_HIGH_WORD(hx,x); - SET_HIGH_WORD(x,hx^sx); - q &= 0x7fffffff; - *quo = (sxy ? -q : q); - return x; -} diff --git a/lib/libm/src/s_remquof.c b/lib/libm/src/s_remquof.c deleted file mode 100644 index 37a6cbc562..0000000000 --- a/lib/libm/src/s_remquof.c +++ /dev/null @@ -1,120 +0,0 @@ -/* @(#)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 - -#include -#include "math_private.h" - -static const float Zero[] = {0.0, -0.0,}; - -/* - * 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. - */ -float -remquof(float x, float y, int *quo) -{ - int32_t n,hx,hy,hz,ix,iy,sx,i; - u_int32_t q,sxy; - - GET_FLOAT_WORD(hx,x); - GET_FLOAT_WORD(hy,y); - sxy = (hx ^ hy) & 0x80000000; - sx = hx&0x80000000; /* sign of x */ - hx ^=sx; /* |x| */ - hy &= 0x7fffffff; /* |y| */ - - /* purge off exception values */ - if(hy==0||hx>=0x7f800000||hy>0x7f800000) /* y=0,NaN;or x not finite */ - return (x*y)/(x*y); - if(hx>31]; /* |x|=|y| return x*0*/ - } - - /* determine ix = ilogb(x) */ - if(hx<0x00800000) { /* subnormal x */ - for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1; - } else ix = (hx>>23)-127; - - /* determine iy = ilogb(y) */ - if(hy<0x00800000) { /* subnormal y */ - for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1; - } else iy = (hy>>23)-127; - - /* set up {hx,lx}, {hy,ly} and align y to x */ - if(ix >= -126) - hx = 0x00800000|(0x007fffff&hx); - else { /* subnormal x, shift x to normal */ - n = -126-ix; - hx <<= n; - } - if(iy >= -126) - hy = 0x00800000|(0x007fffff&hy); - else { /* subnormal y, shift y to normal */ - n = -126-iy; - hy <<= n; - } - - /* fix point fmod */ - n = ix - iy; - q = 0; - while(n--) { - hz=hx-hy; - if(hz<0) hx = hx << 1; - else {hx = hz << 1; q++;} - q <<= 1; - } - hz=hx-hy; - if(hz>=0) {hx=hz;q++;} - - /* convert back to floating value and restore the sign */ - if(hx==0) { /* return sign(x)*0 */ - *quo = (sxy ? -q : q); - return Zero[(u_int32_t)sx>>31]; - } - while(hx<0x00800000) { /* normalize x */ - hx <<= 1; - iy -= 1; - } - if(iy>= -126) { /* normalize output */ - hx = ((hx-0x00800000)|((iy+127)<<23)); - } else { /* subnormal output */ - n = -126 - iy; - hx >>= n; - } -fixup: - SET_FLOAT_WORD(x,hx); - y = fabsf(y); - if (y < 0x1p-125f) { - if (x+x>y || (x+x==y && (q & 1))) { - q++; - x-=y; - } - } else if (x>0.5f*y || (x==0.5f*y && (q & 1))) { - q++; - x-=y; - } - GET_FLOAT_WORD(hx,x); - SET_FLOAT_WORD(x,hx^sx); - q &= 0x7fffffff; - *quo = (sxy ? -q : q); - return x; -} diff --git a/lib/libm/src/s_remquol.c b/lib/libm/src/s_remquol.c deleted file mode 100644 index 2515b85bc3..0000000000 --- a/lib/libm/src/s_remquol.c +++ /dev/null @@ -1,175 +0,0 @@ -/* @(#)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. - * ==================================================== - * FreeBSD SVN: 177764 (2008-03-30) - */ - -#include -#include - -#include -#include "fpmath.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>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=0) {hx=hz;lx=lz;q++;} - - /* convert back to floating value and restore the sign */ - if((hx|lx)==0) { /* return sign(x)*0 */ - *quo = (sxy ? -q : q); - return Zero[sx]; - } - while(hx<(1ULL<>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/lib/libm/src/s_rint.c b/lib/libm/src/s_rint.c index b990927bd3..113c256e8b 100644 --- a/lib/libm/src/s_rint.c +++ b/lib/libm/src/s_rint.c @@ -1,4 +1,5 @@ /* @(#)s_rint.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_rint.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_rint.c,v 1.12 2008/04/25 22:21:53 christos Exp $ */ /* @@ -22,7 +21,9 @@ * Inexact flag raised if x not equal to rint(x). */ -#include +#include + +#include "math.h" #include "math_private.h" static const double @@ -34,43 +35,56 @@ TWO52[2]={ double rint(double x) { - int32_t i0,jj0,sx; + int32_t i0,j0,sx; u_int32_t i,i1; double w,t; EXTRACT_WORDS(i0,i1,x); sx = (i0>>31)&1; - jj0 = ((i0>>20)&0x7ff)-0x3ff; - if(jj0<20) { - if(jj0<0) { + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { if(((i0&0x7fffffff)|i1)==0) return x; i1 |= (i0&0x0fffff); 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)); return t; } else { - i = (0x000fffff)>>jj0; + i = (0x000fffff)>>j0; if(((i0&i)|i1)==0) return x; /* x is integral */ i>>=1; if(((i0&i)|i1)!=0) { - if(jj0==19) i1 = 0x40000000; else - i0 = (i0&(~i))|((0x20000)>>jj0); + /* + * Some bit is set after the 0.5 bit. To avoid the + * possibility of errors from double rounding in + * w = TWO52[sx]+x, adjust the 0.25 bit to a lower + * guard bit. We do this for all j0<=51. The + * adjustment is trickiest for j0==18 and j0==19 + * since then it spans the word boundary. + */ + if(j0==19) i1 = 0x40000000; else + if(j0==18) i1 = 0x80000000; else + i0 = (i0&(~i))|((0x20000)>>j0); } } - } else if (jj0>51) { - if(jj0==0x400) return x+x; /* inf or NaN */ + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ else return x; /* x is integral */ } else { - i = ((u_int32_t)(0xffffffff))>>(jj0-20); + i = ((u_int32_t)(0xffffffff))>>(j0-20); if((i1&i)==0) return x; /* x is integral */ i>>=1; - if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(jj0-20)); + if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20)); } INSERT_WORDS(x,i0,i1); - w = TWO52[sx]+x; + STRICT_ASSIGN(double,w,TWO52[sx]+x); return w-TWO52[sx]; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(rint, rintl); +#endif diff --git a/lib/libm/src/s_rintf.c b/lib/libm/src/s_rintf.c index 6a3e1120de..bc1f39f13c 100644 --- a/lib/libm/src/s_rintf.c +++ b/lib/libm/src/s_rintf.c @@ -12,10 +12,13 @@ * is preserved. * ==================================================== * - * $NetBSD: s_rintf.c,v 1.9 2008/04/25 22:21:53 christos Exp $ + * $FreeBSD: head/lib/msun/src/s_rintf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include +#include + +#include "math.h" #include "math_private.h" static const float @@ -27,39 +30,23 @@ TWO23[2]={ float rintf(float x) { - int32_t i0,jj0,sx; - u_int32_t i,i1; -#ifdef __i386__ /* XXX gcc4 will omit the rounding otherwise */ - volatile -#endif - float w; - float t; + int32_t i0,j0,sx; + float w,t; GET_FLOAT_WORD(i0,x); sx = (i0>>31)&1; - jj0 = ((i0>>23)&0xff)-0x7f; - if(jj0<23) { - if(jj0<0) { + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { if((i0&0x7fffffff)==0) return x; - i1 = (i0&0x07fffff); - i0 &= 0xfff00000; - i0 |= ((i1|-i1)>>9)&0x400000; - SET_FLOAT_WORD(x,i0); - 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; - } else { - i = (0x007fffff)>>jj0; - if((i0&i)==0) return x; /* x is integral */ - i>>=1; - if((i0&i)!=0) i0 = (i0&(~i))|((0x100000)>>jj0); } - } else { - if(jj0==0x80) return x+x; /* inf or NaN */ - else return x; /* x is integral */ + STRICT_ASSIGN(float,w,TWO23[sx]+x); + return w-TWO23[sx]; } - SET_FLOAT_WORD(x,i0); - w = TWO23[sx]+x; - return w-TWO23[sx]; + if(j0==0x80) return x+x; /* inf or NaN */ + else return x; /* x is integral */ } diff --git a/lib/libm/src/s_round.c b/lib/libm/src/s_round.c index 5977e913f2..3bdc7c7204 100644 --- a/lib/libm/src/s_round.c +++ b/lib/libm/src/s_round.c @@ -23,7 +23,7 @@ * (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 SVN: 153017 (2005-12-02) + * $FreeBSD: head/lib/msun/src/s_round.c 153017 2005-12-02 13:45:06Z bde $ */ #include diff --git a/lib/libm/src/s_roundf.c b/lib/libm/src/s_roundf.c index 257287254d..c602f78689 100644 --- a/lib/libm/src/s_roundf.c +++ b/lib/libm/src/s_roundf.c @@ -23,7 +23,7 @@ * (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 SVN: 153017 (2005-12-02) + * $FreeBSD: head/lib/msun/src/s_roundf.c 153017 2005-12-02 13:45:06Z bde $ */ #include diff --git a/lib/libm/src/s_roundl.c b/lib/libm/src/s_roundl.c index 07383f5892..07bba131e3 100644 --- a/lib/libm/src/s_roundl.c +++ b/lib/libm/src/s_roundl.c @@ -23,7 +23,7 @@ * (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 SVN: 153017 (2005-12-02) + * $FreeBSD: head/lib/msun/src/s_roundl.c 153017 2005-12-02 13:45:06Z bde $ */ #include diff --git a/lib/libm/src/s_scalbln.c b/lib/libm/src/s_scalbln.c index dcaa1401ae..655a9d019d 100644 --- a/lib/libm/src/s_scalbln.c +++ b/lib/libm/src/s_scalbln.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 143219 (2005-03-07) + * $FreeBSD: head/lib/msun/src/s_scalbln.c 143219 2005-03-07 04:57:50Z das $ */ #include diff --git a/lib/libm/src/s_scalbn.c b/lib/libm/src/s_scalbn.c deleted file mode 100644 index 69e8aa5bc0..0000000000 --- a/lib/libm/src/s_scalbn.c +++ /dev/null @@ -1,57 +0,0 @@ -/* @(#)s_scalbn.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. - * ==================================================== - * - * $NetBSD: s_scalbn.c,v 1.15 2011/07/26 16:10:16 joerg Exp $ - */ - -/* - * scalbn (double x, int n) - * scalbn(x,n) returns x* 2**n computed by exponent - * manipulation rather than by actually performing an - * exponentiation or a multiplication. - */ - -#include -#include "math_private.h" - -static const double -two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ -twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ -huge = 1.0e+300, -tiny = 1.0e-300; - -double -scalbn(double x, int n) -{ - int32_t k,hx,lx; - EXTRACT_WORDS(hx,lx,x); - k = ((uint32_t)hx&0x7ff00000)>>20; /* extract exponent */ - if (k==0) { /* 0 or subnormal x */ - if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ - x *= two54; - GET_HIGH_WORD(hx,x); - k = (((uint32_t)hx&0x7ff00000)>>20) - 54; - if (n< -50000) return tiny*x; /*underflow*/ - } - if (k==0x7ff) return x+x; /* NaN or Inf */ - k = k+n; - if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ - if (k > 0) /* normal result */ - {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} - if (k <= -54) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysign(huge,x); /*overflow*/ - else return tiny*copysign(tiny,x); /*underflow*/ - } - k += 54; /* subnormal result */ - SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); - return x*twom54; -} diff --git a/lib/libm/src/s_scalbnf.c b/lib/libm/src/s_scalbnf.c deleted file mode 100644 index 33d314a58a..0000000000 --- a/lib/libm/src/s_scalbnf.c +++ /dev/null @@ -1,53 +0,0 @@ -/* s_scalbnf.c -- float version of s_scalbn.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. - * ==================================================== - * - * $NetBSD: s_scalbnf.c,v 1.9 2010/04/23 19:17:07 drochner Exp $ - */ - -#include -#include "math_private.h" - -static const float -two25 = 3.355443200e+07, /* 0x4c000000 */ -twom25 = 2.9802322388e-08, /* 0x33000000 */ -huge = 1.0e+30, -tiny = 1.0e-30; - -float -scalbnf(float x, int n) -{ - int32_t k,ix; - GET_FLOAT_WORD(ix,x); - k = (ix&0x7f800000)>>23; /* extract exponent */ - if (k==0) { /* 0 or subnormal x */ - if ((ix&0x7fffffff)==0) return x; /* +-0 */ - x *= two25; - GET_FLOAT_WORD(ix,x); - k = ((ix&0x7f800000)>>23) - 25; - if (n< -50000) return tiny*x; /*underflow*/ - } - if (k==0xff) return x+x; /* NaN or Inf */ - k = k+n; - if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */ - if (k > 0) /* normal result */ - {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} - if (k <= -25) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysignf(huge,x); /*overflow*/ - else return tiny*copysignf(tiny,x); /*underflow*/ - } - k += 25; /* subnormal result */ - SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); - return x*twom25; -} diff --git a/lib/libm/src/s_scalbnl.c b/lib/libm/src/s_scalbnl.c deleted file mode 100644 index c052140452..0000000000 --- a/lib/libm/src/s_scalbnl.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $NetBSD: s_scalbnl.c,v 1.1 2011/07/26 16:10:16 joerg Exp $ */ - -/*- - * Copyright (c) 2011 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Joerg Sonnenberger. - * - * 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. - */ - -#include -#include -#include - -#ifdef __HAVE_LONG_DOUBLE - -#if LDBL_MANT_DIG == 64 -#define FROM_UNDERFLOW 0x1p65L -#define TO_UNDERFLOW 0x1p-65L -#elif LDBL_MANT_DIG == 113 -#define FROM_UNDERFLOW 0x1p114L -#define TO_UNDERFLOW 0x1p-114L -#else -#error Unsupported long double format -#endif - -long double -scalbnl(long double x, int n) -{ - union ieee_ext_u u; - - /* Trivial cases first */ - if (n == 0 || x == 0.0L) - return x; - - u.extu_ld = x; - - /* NaN and infinite don't change either, but trigger exception */ - if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) - return x + x; - - /* Protect against integer overflow in calculation of new exponent */ - if (n > LDBL_MAX_EXP - LDBL_MIN_EXP + LDBL_MANT_DIG) - goto overflow; - if (n < LDBL_MAX_EXP - LDBL_MIN_EXP + LDBL_MANT_DIG) - goto underflow; - - /* Scale denormalized numbers slightly, so that they are normal */ - if (u.extu_ext.ext_exp == 0) { - u.extu_ld *= FROM_UNDERFLOW; - n -= LDBL_MANT_DIG + 1; - } - - n += u.extu_ext.ext_exp; - if (n >= LDBL_MAX_EXP + EXT_EXP_BIAS) - goto overflow; - /* Positive exponent (incl. bias) means normal result */ - if (n > 0) { - u.extu_ext.ext_exp = n; - return u.extu_ld; - } - /* Shift the exponent and let the multiply below handle subnormal */ - n += LDBL_MANT_DIG + 1; - if (n <= 0) - goto underflow; - u.extu_ext.ext_exp = n; - return u.extu_ld * TO_UNDERFLOW; - -underflow: - return LDBL_MIN * copysignl(LDBL_MIN, x); - -overflow: - return LDBL_MAX * copysignl(LDBL_MAX, x); -} - -#endif diff --git a/lib/libm/complex/s_cargl.c b/lib/libm/src/s_signbit.c similarity index 76% rename from lib/libm/complex/s_cargl.c rename to lib/libm/src/s_signbit.c index e0cbd7aeda..3b298a8b10 100644 --- a/lib/libm/complex/s_cargl.c +++ b/lib/libm/src/s_signbit.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2003 Mike Barcroft * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,15 +23,36 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 181074 (2008-07-31) + * $FreeBSD: head/lib/msun/src/s_signbit.c 132382 2004-07-19 08:16:10Z das $ */ -#include #include -long double -cargl(long double complex z) +#include "fpmath.h" + +int +__signbit(double d) +{ + union IEEEd2bits u; + + u.d = d; + return (u.bits.sign); +} + +int +__signbitf(float f) +{ + union IEEEf2bits u; + + u.f = f; + return (u.bits.sign); +} + +int +__signbitl(long double e) { + union IEEEl2bits u; - return (atan2l(cimagl(z), creall(z))); + u.e = e; + return (u.bits.sign); } diff --git a/lib/libm/src/s_signgam.c b/lib/libm/src/s_signgam.c index 4d6345119b..d67d5918ec 100644 --- a/lib/libm/src/s_signgam.c +++ b/lib/libm/src/s_signgam.c @@ -1,7 +1,3 @@ -/* $NetBSD: s_signgam.c,v 1.4 1998/01/09 03:15:46 perry Exp $ */ -/* $DragonFly: src/lib/libm/src/s_signgam.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ - -#include +#include "math.h" #include "math_private.h" - int signgam = 0; diff --git a/lib/libm/src/s_significand.c b/lib/libm/src/s_significand.c index 85f3d7a07d..669ac6cbd8 100644 --- a/lib/libm/src/s_significand.c +++ b/lib/libm/src/s_significand.c @@ -1,4 +1,5 @@ /* @(#)s_signif.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_significand.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_significand.c,v 1.9 2002/05/26 22:01:58 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_significand.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* @@ -19,11 +17,11 @@ * for exercising the fraction-part(F) IEEE 754-1985 test vector. */ -#include +#include "math.h" #include "math_private.h" double significand(double x) { - return scalb(x,(double) -ilogb(x)); + return __ieee754_scalb(x,(double) -ilogb(x)); } diff --git a/lib/libm/src/s_significandf.c b/lib/libm/src/s_significandf.c index cb90887a3f..47d5a44193 100644 --- a/lib/libm/src/s_significandf.c +++ b/lib/libm/src/s_significandf.c @@ -12,15 +12,14 @@ * is preserved. * ==================================================== * - * $NetBSD: s_significandf.c,v 1.6 2002/05/26 22:01:58 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_significandf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_significandf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" float significandf(float x) { - return scalbf(x,(float) -ilogbf(x)); + return __ieee754_scalbf(x,(float) -ilogbf(x)); } diff --git a/lib/libm/src/s_sin.c b/lib/libm/src/s_sin.c index df4bf47606..f64fed7520 100644 --- a/lib/libm/src/s_sin.c +++ b/lib/libm/src/s_sin.c @@ -1,4 +1,5 @@ /* @(#)s_sin.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_sin.c 218509 2011-02-10 07:37:50Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_sin.c,v 1.11 2007/08/20 16:01:39 drochner Exp $ */ /* sin(x) @@ -18,7 +17,7 @@ * kernel function: * __kernel_sin ... sine function on [-pi/4,pi/4] * __kernel_cos ... cose function on [-pi/4,pi/4] - * __libm_rem_pio2 ... argument reduction routine + * __ieee754_rem_pio2 ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on @@ -43,8 +42,12 @@ * TRIG(x) returns trig(x) nearly rounded */ -#include +#include + +#include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double sin(double x) @@ -57,14 +60,18 @@ sin(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0); + if(ix <= 0x3fe921fb) { + if(ix<0x3e500000) /* |x| < 2**-26 */ + {if((int)x==0) return x;} /* generate inexact */ + return __kernel_sin(x,z,0); + } /* sin(Inf or NaN) is NaN */ else if (ix>=0x7ff00000) return x-x; /* argument reduction needed */ else { - n = __libm_rem_pio2(x,y); + n = __ieee754_rem_pio2(x,y); switch(n&3) { case 0: return __kernel_sin(y[0],y[1],1); case 1: return __kernel_cos(y[0],y[1]); @@ -74,3 +81,7 @@ sin(double x) } } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(sin, sinl); +#endif diff --git a/lib/libm/src/s_sinf.c b/lib/libm/src/s_sinf.c index fe530f498a..78695bb9e6 100644 --- a/lib/libm/src/s_sinf.c +++ b/lib/libm/src/s_sinf.c @@ -12,10 +12,13 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176569 (2008-02-25) + * + * $FreeBSD: head/lib/msun/src/s_sinf.c 176569 2008-02-25 22:19:17Z bde $ */ -#include +#include + +#include "math.h" #define INLINE_KERNEL_COSDF #define INLINE_KERNEL_SINDF #define INLINE_REM_PIO2F @@ -69,7 +72,7 @@ sinf(float x) /* general argument reduction needed */ else { - n = __libm_rem_pio2f(x,&y); + n = __ieee754_rem_pio2f(x,&y); switch(n&3) { case 0: return __kernel_sindf(y); case 1: return __kernel_cosdf(y); diff --git a/lib/libm/src/s_sinl.c b/lib/libm/src/s_sinl.c index 9bbe6a7475..d865f868fc 100644 --- a/lib/libm/src/s_sinl.c +++ b/lib/libm/src/s_sinl.c @@ -23,12 +23,23 @@ * (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 SVN: 222508 (2011-05-30) + * $FreeBSD: head/lib/msun/src/s_sinl.c 240828 2012-09-22 15:38:29Z kargl $ */ -#include +#include +#ifdef __i386__ +#include +#endif + +#include "math.h" #include "math_private.h" -#include "e_rem_pio2l.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) @@ -50,13 +61,15 @@ sinl(long double x) 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); - return (s ? -hi : hi); + RETURNI(s ? -hi : hi); } - e0 = __libm_rem_pio2l(x, y); + e0 = __ieee754_rem_pio2l(x, y); hi = y[0]; lo = y[1]; @@ -74,6 +87,6 @@ sinl(long double x) hi = - __kernel_cosl(hi, lo); break; } - - return (hi); + + RETURNI(hi); } diff --git a/lib/libm/src/s_tan.c b/lib/libm/src/s_tan.c index d39bcb707f..c2d3712f9f 100644 --- a/lib/libm/src/s_tan.c +++ b/lib/libm/src/s_tan.c @@ -1,4 +1,5 @@ /* @(#)s_tan.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_tan.c 218509 2011-02-10 07:37:50Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_tan.c,v 1.10 2002/05/26 22:01:58 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_tan.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* tan(x) @@ -18,7 +16,7 @@ * * kernel function: * __kernel_tan ... tangent function on [-pi/4,pi/4] - * __libm_rem_pio2 ... argument reduction routine + * __ieee754_rem_pio2 ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on @@ -43,8 +41,12 @@ * TRIG(x) returns trig(x) nearly rounded */ -#include +#include + +#include "math.h" +#define INLINE_REM_PIO2 #include "math_private.h" +#include "e_rem_pio2.c" double tan(double x) @@ -57,15 +59,23 @@ tan(double x) /* |x| ~< pi/4 */ ix &= 0x7fffffff; - if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); + if(ix <= 0x3fe921fb) { + if(ix<0x3e400000) /* x < 2**-27 */ + if((int)x==0) return x; /* generate inexact */ + return __kernel_tan(x,z,1); + } /* tan(Inf or NaN) is NaN */ else if (ix>=0x7ff00000) return x-x; /* NaN */ /* argument reduction needed */ else { - n = __libm_rem_pio2(x,y); + n = __ieee754_rem_pio2(x,y); return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even -1 -- n odd */ } } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(tan, tanl); +#endif diff --git a/lib/libm/src/s_tanf.c b/lib/libm/src/s_tanf.c index 2531ba8a36..7330301947 100644 --- a/lib/libm/src/s_tanf.c +++ b/lib/libm/src/s_tanf.c @@ -12,10 +12,13 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * FreeBSD SVN: 176569 (2008-02-25) + * + * $FreeBSD: head/lib/msun/src/s_tanf.c 176569 2008-02-25 22:19:17Z bde $ */ -#include +#include + +#include "math.h" #define INLINE_KERNEL_TANDF #define INLINE_REM_PIO2F #include "math_private.h" @@ -61,7 +64,7 @@ tanf(float x) /* general argument reduction needed */ else { - n = __libm_rem_pio2f(x,&y); + n = __ieee754_rem_pio2f(x,&y); /* integer parameter: 1 -- n even; -1 -- n odd */ return __kernel_tandf(y,1-((n&1)<<1)); } diff --git a/lib/libm/src/s_tanh.c b/lib/libm/src/s_tanh.c index 88eb29491e..1514b35692 100644 --- a/lib/libm/src/s_tanh.c +++ b/lib/libm/src/s_tanh.c @@ -1,4 +1,5 @@ /* @(#)s_tanh.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_tanh.c 176451 2008-02-22 02:30:36Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,9 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_tanh.c,v 1.10 2002/05/26 22:01:59 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_tanh.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ /* Tanh(x) @@ -23,24 +21,24 @@ * 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; * only tanh(0)=0 is exact for finite argument. */ -#include +#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) @@ -48,7 +46,6 @@ tanh(double x) double t,z; int32_t jx,ix; - /* High word of |x|. */ GET_HIGH_WORD(jx,x); ix = jx&0x7fffffff; @@ -60,8 +57,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); @@ -69,9 +67,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/lib/libm/src/s_tanhf.c b/lib/libm/src/s_tanhf.c index 9673e7df7e..acbdf3fc54 100644 --- a/lib/libm/src/s_tanhf.c +++ b/lib/libm/src/s_tanhf.c @@ -12,15 +12,13 @@ * is preserved. * ==================================================== * - * $NetBSD: s_tanhf.c,v 1.7 2002/05/26 22:01:59 wiz Exp $ - * $DragonFly: src/lib/libm/src/s_tanhf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ + * $FreeBSD: head/lib/msun/src/s_tanhf.c 176451 2008-02-22 02:30:36Z das $ */ -#include +#include "math.h" #include "math_private.h" -static const float one=1.0, two=2.0, tiny = 1.0e-30; - +static const float one=1.0, two=2.0, tiny = 1.0e-30, huge = 1.0e30; float tanhf(float x) { @@ -36,10 +34,11 @@ tanhf(float x) else return one/x-one; /* tanh(NaN) = NaN */ } - /* |x| < 22 */ - if (ix < 0x41b00000) { /* |x|<22 */ - if (ix<0x24000000) /* |x|<2**-55 */ - return x*(one+x); /* tanh(small) = small */ + /* |x| < 9 */ + if (ix < 0x41100000) { /* |x|<9 */ + if (ix<0x39800000) { /* |x|<2**-12 */ + if(huge+x>one) return x; /* tanh(tiny) = tiny with inexact */ + } if (ix>=0x3f800000) { /* |x|>=1 */ t = expm1f(two*fabsf(x)); z = one - two/(t+two); @@ -47,9 +46,9 @@ tanhf(float x) t = expm1f(-two*fabsf(x)); z= -t/(t+two); } - /* |x| > 22, return +-1 */ + /* |x| >= 9, return +-1 */ } else { - z = one - tiny; /* raised inexact flag */ + z = one - tiny; /* raise inexact flag */ } return (jx>=0)? z: -z; } diff --git a/lib/libm/src/s_tanl.c b/lib/libm/src/s_tanl.c index e9b6ab7d2b..02d3b99ad2 100644 --- a/lib/libm/src/s_tanl.c +++ b/lib/libm/src/s_tanl.c @@ -23,7 +23,7 @@ * (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 SVN: 222508 (2011-05-30) + * $FreeBSD: head/lib/msun/src/s_tanl.c 240828 2012-09-22 15:38:29Z kargl $ */ /* @@ -33,10 +33,19 @@ */ #include +#ifdef __i386__ +#include +#endif -#include +#include "math.h" #include "math_private.h" -#include "e_rem_pio2l.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) @@ -58,13 +67,15 @@ tanl(long double x) 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); - return (s ? -hi : hi); + RETURNI(s ? -hi : hi); } - e0 = __libm_rem_pio2l(x, y); + e0 = __ieee754_rem_pio2l(x, y); hi = y[0]; lo = y[1]; @@ -79,5 +90,5 @@ tanl(long double x) break; } - return (hi); + RETURNI(hi); } diff --git a/lib/libm/src/s_tgammaf.c b/lib/libm/src/s_tgammaf.c index 457a521e85..eb12e5136c 100644 --- a/lib/libm/src/s_tgammaf.c +++ b/lib/libm/src/s_tgammaf.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 176388 (2008-02-18) + * $FreeBSD: head/lib/msun/src/s_tgammaf.c 176388 2008-02-18 17:27:11Z das $ */ #include diff --git a/lib/libm/src/s_trunc.c b/lib/libm/src/s_trunc.c index a1caf40244..f296d7229a 100644 --- a/lib/libm/src/s_trunc.c +++ b/lib/libm/src/s_trunc.c @@ -1,4 +1,5 @@ /* @(#)s_floor.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_trunc.c 176450 2008-02-22 02:27:34Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_trunc.c,v 1.3 2008/04/25 22:21:53 christos Exp $ */ /* @@ -21,7 +20,9 @@ * Inexact flag raised if x not equal to trunc(x). */ -#include +#include + +#include "math.h" #include "math_private.h" static const double huge = 1.0e300; @@ -29,28 +30,28 @@ static const double huge = 1.0e300; double trunc(double x) { - int32_t i0,i1,jj0; - uint32_t i; + int32_t i0,i1,j0; + u_int32_t i; EXTRACT_WORDS(i0,i1,x); - jj0 = ((i0>>20)&0x7ff)-0x3ff; - if(jj0<20) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>20)&0x7ff)-0x3ff; + if(j0<20) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>0.0) {/* |x|<1, so return 0*sign(x) */ i0 &= 0x80000000U; i1 = 0; } } else { - i = (0x000fffff)>>jj0; + i = (0x000fffff)>>j0; if(((i0&i)|i1)==0) return x; /* x is integral */ if(huge+x>0.0) { /* raise inexact flag */ i0 &= (~i); i1=0; } } - } else if (jj0>51) { - if(jj0==0x400) return x+x; /* inf or NaN */ + } else if (j0>51) { + if(j0==0x400) return x+x; /* inf or NaN */ else return x; /* x is integral */ } else { - i = ((u_int32_t)(0xffffffff))>>(jj0-20); + i = ((u_int32_t)(0xffffffff))>>(j0-20); if((i1&i)==0) return x; /* x is integral */ if(huge+x>0.0) /* raise inexact flag */ i1 &= (~i); @@ -58,3 +59,7 @@ trunc(double x) INSERT_WORDS(x,i0,i1); return x; } + +#if LDBL_MANT_DIG == 53 +__weak_reference(trunc, truncl); +#endif diff --git a/lib/libm/src/s_truncf.c b/lib/libm/src/s_truncf.c index a8a58247eb..26adf6853e 100644 --- a/lib/libm/src/s_truncf.c +++ b/lib/libm/src/s_truncf.c @@ -1,4 +1,5 @@ /* @(#)s_floor.c 5.1 93/09/24 */ +/* $FreeBSD: head/lib/msun/src/s_truncf.c 130767 2004-06-20 09:25:43Z das $ */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. @@ -8,8 +9,6 @@ * software is freely granted, provided that this notice * is preserved. * ==================================================== - * - * $NetBSD: s_truncf.c,v 1.4 2008/04/25 22:21:53 christos Exp $ */ /* @@ -21,7 +20,7 @@ * Inexact flag raised if x not equal to truncf(x). */ -#include +#include "math.h" #include "math_private.h" static const float huge = 1.0e30F; @@ -29,22 +28,22 @@ static const float huge = 1.0e30F; float truncf(float x) { - int32_t i0,jj0; - uint32_t i; + int32_t i0,j0; + u_int32_t i; GET_FLOAT_WORD(i0,x); - jj0 = ((i0>>23)&0xff)-0x7f; - if(jj0<23) { - if(jj0<0) { /* raise inexact if x != 0 */ + j0 = ((i0>>23)&0xff)-0x7f; + if(j0<23) { + if(j0<0) { /* raise inexact if x != 0 */ if(huge+x>0.0F) /* |x|<1, so return 0*sign(x) */ i0 &= 0x80000000; } else { - i = (0x007fffff)>>jj0; + i = (0x007fffff)>>j0; if((i0&i)==0) return x; /* x is integral */ if(huge+x>0.0F) /* raise inexact flag */ i0 &= (~i); } } else { - if(jj0==0x80) return x+x; /* inf or NaN */ + if(j0==0x80) return x+x; /* inf or NaN */ else return x; /* x is integral */ } SET_FLOAT_WORD(x,i0); diff --git a/lib/libm/src/s_truncl.c b/lib/libm/src/s_truncl.c index c79bb542ec..0d789733c8 100644 --- a/lib/libm/src/s_truncl.c +++ b/lib/libm/src/s_truncl.c @@ -9,7 +9,7 @@ * ==================================================== * * From: @(#)s_floor.c 5.1 93/09/24 - * FreeBSD SVN: 176280 (2008-02-14) + * $FreeBSD: head/lib/msun/src/s_truncl.c 176280 2008-02-14 15:10:34Z bde $ */ /* diff --git a/lib/libm/src/w_cabs.c b/lib/libm/src/w_cabs.c new file mode 100644 index 0000000000..45196d3e14 --- /dev/null +++ b/lib/libm/src/w_cabs.c @@ -0,0 +1,22 @@ +/* + * cabs() wrapper for hypot(). + * + * Written by J.T. Conklin, + * Placed into the Public Domain, 1994. + * + * $FreeBSD: head/lib/msun/src/w_cabs.c 177758 2008-03-30 20:03:06Z das $ + */ + +#include +#include +#include + +double +cabs(double complex z) +{ + return hypot(creal(z), cimag(z)); +} + +#if LDBL_MANT_DIG == 53 +__weak_reference(cabs, cabsl); +#endif diff --git a/lib/libm/src/w_cabsf.c b/lib/libm/src/w_cabsf.c new file mode 100644 index 0000000000..809f042f74 --- /dev/null +++ b/lib/libm/src/w_cabsf.c @@ -0,0 +1,20 @@ +/* + * cabsf() wrapper for hypotf(). + * + * Written by J.T. Conklin, + * Placed into the Public Domain, 1994. + * + * $FreeBSD: head/lib/msun/src/w_cabsf.c 78172 2001-06-13 15:16:30Z ru $ + */ + +#include +#include +#include "math_private.h" + +float +cabsf(z) + float complex z; +{ + + return hypotf(crealf(z), cimagf(z)); +} diff --git a/lib/libm/complex/w_cabsl.c b/lib/libm/src/w_cabsl.c similarity index 80% rename from lib/libm/complex/w_cabsl.c rename to lib/libm/src/w_cabsl.c index aebed20d4d..a3f4419806 100644 --- a/lib/libm/complex/w_cabsl.c +++ b/lib/libm/src/w_cabsl.c @@ -6,7 +6,7 @@ * * Modified by Steven G. Kargl for the long double type. * - * FreeBSD SVN: 177757 (2008-03-30) + * $FreeBSD: head/lib/msun/src/w_cabsl.c 177757 2008-03-30 20:02:03Z das $ */ #include diff --git a/lib/libm/src/w_drem.c b/lib/libm/src/w_drem.c index 6dcaee1f20..0f6840934f 100644 --- a/lib/libm/src/w_drem.c +++ b/lib/libm/src/w_drem.c @@ -3,15 +3,13 @@ * * Written by J.T. Conklin, * Placed into the Public Domain, 1994. - * - * $NetBSD: w_drem.c,v 1.4 2004/06/25 15:57:38 drochner Exp $ - * $DragonFly: src/lib/libm/src/w_drem.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ #include double -drem(double x, double y) +drem(x, y) + double x, y; { return remainder(x, y); } diff --git a/lib/libm/src/w_dremf.c b/lib/libm/src/w_dremf.c index 7cb50fdd48..1955f82187 100644 --- a/lib/libm/src/w_dremf.c +++ b/lib/libm/src/w_dremf.c @@ -3,12 +3,10 @@ * * Written by J.T. Conklin, * Placed into the Public Domain, 1994. - * - * $NetBSD: w_dremf.c,v 1.4 2004/06/25 15:57:38 drochner Exp $ - * $DragonFly: src/lib/libm/src/w_dremf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ */ +/* $FreeBSD: head/lib/msun/src/w_dremf.c 132760 2004-07-28 05:53:18Z kan $ */ -#include +#include "math.h" #include "math_private.h" float diff --git a/lib/libm/src/w_gamma.c b/lib/libm/src/w_gamma.c deleted file mode 100644 index e9ab9bd99a..0000000000 --- a/lib/libm/src/w_gamma.c +++ /dev/null @@ -1,29 +0,0 @@ -/* @(#)w_gamma.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. - * ==================================================== - * - * $NetBSD: w_gamma.c,v 1.11 2002/05/26 22:02:00 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_gamma.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -/* double gamma(double x) - * Return the logarithm of the Gamma function of x. - * - * Method: call gamma_r - */ - -#include -#include "math_private.h" - -double -gamma(double x) -{ - return lgamma_r(x,&signgam); -} diff --git a/lib/libm/src/w_gamma_r.c b/lib/libm/src/w_gamma_r.c deleted file mode 100644 index e294e1181c..0000000000 --- a/lib/libm/src/w_gamma_r.c +++ /dev/null @@ -1,27 +0,0 @@ -/* @(#)wr_gamma.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. - * ==================================================== - * - * $NetBSD: w_gamma_r.c,v 1.11 2002/05/26 22:02:00 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_gamma_r.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -/* - * wrapper double gamma_r(double x, int *signgamp) - */ - -#include -#include "math_private.h" - -double -gamma_r(double x, int *signgamp) /* wrapper lgamma_r */ -{ - return lgamma_r(x,signgamp); -} diff --git a/lib/libm/src/w_lgamma.c b/lib/libm/src/w_lgamma.c deleted file mode 100644 index df79712ab8..0000000000 --- a/lib/libm/src/w_lgamma.c +++ /dev/null @@ -1,28 +0,0 @@ -/* @(#)w_lgamma.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. - * ==================================================== - * - * $NetBSD: w_lgamma.c,v 1.10 2002/05/26 22:02:02 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_lgamma.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -/* - * double lgamma(double x) - * Return the logarithm of the Gamma function of x. - */ - -#include -#include "math_private.h" - -double -lgamma(double x) -{ - return lgamma_r(x,&signgam); -} diff --git a/lib/libm/src/w_lgammaf.c b/lib/libm/src/w_lgammaf.c deleted file mode 100644 index 13b3041dbd..0000000000 --- a/lib/libm/src/w_lgammaf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* w_lgammaf.c -- float version of w_lgamma.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. - * ==================================================== - * - * $NetBSD: w_lgammaf.c,v 1.7 2002/05/26 22:02:02 wiz Exp $ - * $DragonFly: src/lib/libm/src/w_lgammaf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $ - */ - -#include -#include "math_private.h" - -float -lgammaf(float x) -{ - return lgammaf_r(x,&signgam); -} diff --git a/lib/libm/x86_64/Makefile.inc b/lib/libm/x86_64/Makefile.inc new file mode 100644 index 0000000000..abd2e850fa --- /dev/null +++ b/lib/libm/x86_64/Makefile.inc @@ -0,0 +1,8 @@ +# $FreeBSD: head/lib/msun/amd64/Makefile.inc 177768 2008-03-30 21:21:53Z das $ + +ARCH_SRCS = e_remainder.S e_remainderf.S e_remainderl.S \ + e_sqrt.S e_sqrtf.S e_sqrtl.S \ + s_llrint.S s_llrintf.S s_llrintl.S \ + s_logbl.S s_lrint.S s_lrintf.S s_lrintl.S \ + s_remquo.S s_remquof.S s_remquol.S \ + s_rintl.S s_scalbn.S s_scalbnf.S s_scalbnl.S diff --git a/lib/libm/arch/i386/e_remainderl.S b/lib/libm/x86_64/e_remainder.S similarity index 86% copy from lib/libm/arch/i386/e_remainderl.S copy to lib/libm/x86_64/e_remainder.S index 3781ba941b..8023fe9073 100644 --- a/lib/libm/arch/i386/e_remainderl.S +++ b/lib/libm/x86_64/e_remainder.S @@ -26,36 +26,30 @@ * 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: head/lib/msun/amd64/e_remainder.S 217108 2011-01-07 16:13:12Z kib $ */ /* - * Written by: + * Based on the i387 version written by: * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remainderl) -#ifdef __i386__ - fldt 16(%esp) - fldt 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret -#else - fldt 24(%rsp) - fldt 8(%rsp) +ENTRY(remainder) + movsd %xmm0,-8(%rsp) + movsd %xmm1,-16(%rsp) + fldl -16(%rsp) + fldl -8(%rsp) 1: fprem1 fstsw %ax testw $0x400,%ax jne 1b - fstp %st(1) + fstpl -8(%rsp) + movsd -8(%rsp),%xmm0 + fstp %st ret -#endif -END(remainderl) +END(remainder) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/x86_64/e_remainderf.S b/lib/libm/x86_64/e_remainderf.S new file mode 100644 index 0000000000..e7137a7afe --- /dev/null +++ b/lib/libm/x86_64/e_remainderf.S @@ -0,0 +1,26 @@ +/* + * Based on the i387 version written by J.T. Conklin . + * Public domain. + * + * $NetBSD: e_remainderf.S,v 1.2 1995/05/08 23:49:47 jtc Exp $ + * $FreeBSD: head/lib/msun/amd64/e_remainderf.S 217108 2011-01-07 16:13:12Z kib $ + */ + +#include + +ENTRY(remainderf) + movss %xmm0,-4(%rsp) + movss %xmm1,-8(%rsp) + flds -8(%rsp) + flds -4(%rsp) +1: fprem1 + fstsw %ax + testw $0x400,%ax + jne 1b + fstps -4(%rsp) + movss -4(%rsp),%xmm0 + fstp %st + ret +END(remainderf) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_remainderl.S b/lib/libm/x86_64/e_remainderl.S similarity index 92% rename from lib/libm/arch/i386/e_remainderl.S rename to lib/libm/x86_64/e_remainderl.S index 3781ba941b..2ae74911f6 100644 --- a/lib/libm/arch/i386/e_remainderl.S +++ b/lib/libm/x86_64/e_remainderl.S @@ -26,27 +26,18 @@ * 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: head/lib/msun/amd64/e_remainderl.S 217108 2011-01-07 16:13:12Z kib $ */ /* - * Written by: + * Based on the i387 version written by: * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. - * FreeBSD SVN: 217108 (2011-01-07) */ #include ENTRY(remainderl) -#ifdef __i386__ - fldt 16(%esp) - fldt 4(%esp) -1: fprem1 - fstsw %ax - sahf - jp 1b - fstp %st(1) - ret -#else fldt 24(%rsp) fldt 8(%rsp) 1: fprem1 @@ -55,7 +46,6 @@ ENTRY(remainderl) jne 1b fstp %st(1) ret -#endif END(remainderl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/x86_64/e_sqrt.S similarity index 89% copy from lib/libm/arch/i386/s_lrint.S copy to lib/libm/x86_64/e_sqrt.S index 17cef8998d..bd054576ae 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/x86_64/e_sqrt.S @@ -23,22 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/e_sqrt.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrint) -#ifdef __i386__ - fldl 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax +ENTRY(sqrt) + sqrtsd %xmm0, %xmm0 ret -#else - cvtsd2si %xmm0, %rax - ret -#endif -END(lrint) +END(sqrt) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/x86_64/e_sqrtf.S similarity index 89% copy from lib/libm/arch/i386/s_lrint.S copy to lib/libm/x86_64/e_sqrtf.S index 17cef8998d..828a93a107 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/x86_64/e_sqrtf.S @@ -23,22 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/e_sqrtf.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrint) -#ifdef __i386__ - fldl 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax +ENTRY(sqrtf) + sqrtss %xmm0, %xmm0 ret -#else - cvtsd2si %xmm0, %rax - ret -#endif -END(lrint) +END(sqrtf) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/src/e_remainderl.c b/lib/libm/x86_64/e_sqrtl.S similarity index 87% rename from lib/libm/src/e_remainderl.c rename to lib/libm/x86_64/e_sqrtl.S index 7d70e2e847..dec456d048 100644 --- a/lib/libm/src/e_remainderl.c +++ b/lib/libm/x86_64/e_sqrtl.S @@ -23,15 +23,15 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 177765 (2008-03-30) + * $FreeBSD: head/lib/msun/amd64/e_sqrtl.S 217108 2011-01-07 16:13:12Z kib $ */ -#include +#include -long double -remainderl(long double x, long double y) -{ - int quo; +ENTRY(sqrtl) + fldt 8(%rsp) + fsqrt + ret +END(sqrtl) - return (remquol(x, y, &quo)); -} + .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/x86_64/fenv.c b/lib/libm/x86_64/fenv.c similarity index 83% rename from lib/libm/arch/x86_64/fenv.c rename to lib/libm/x86_64/fenv.c index e20a52294e..d2e3cfd5cd 100644 --- a/lib/libm/arch/x86_64/fenv.c +++ b/lib/libm/x86_64/fenv.c @@ -23,13 +23,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/msun/amd64/fenv.c,v 1.5 2010/02/03 20:23:47 kib Exp $ + * $FreeBSD: head/lib/msun/amd64/fenv.c 226594 2011-10-21 06:25:31Z das $ */ #include #include + +#define __fenv_static #include "fenv.h" +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = { { 0xffff0000 | __INITIAL_FPUCW__, 0xffff0000, @@ -40,6 +46,9 @@ const fenv_t __fe_dfl_env = { __INITIAL_MXCSR__ }; +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { @@ -68,6 +77,10 @@ feraiseexcept(int excepts) return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { @@ -97,6 +110,8 @@ feholdexcept(fenv_t *envp) return (0); } +extern inline int fesetenv(const fenv_t *__envp); + int feupdateenv(const fenv_t *envp) { @@ -119,12 +134,12 @@ __feenableexcept(int mask) mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); - return (~omask); + return (omask); } int @@ -136,12 +151,12 @@ __fedisableexcept(int mask) mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); - omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; + omask = ~(control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); - return (~omask); + return (omask); } __weak_reference(__feenableexcept, feenableexcept); diff --git a/lib/libm/x86_64/s_llrint.S b/lib/libm/x86_64/s_llrint.S new file mode 100644 index 0000000000..035bdd4600 --- /dev/null +++ b/lib/libm/x86_64/s_llrint.S @@ -0,0 +1,6 @@ +/* $FreeBSD: head/lib/msun/amd64/s_llrint.S 218305 2011-02-04 21:54:06Z kib $ */ +#include + +/* sizeof(long) == sizeof(long long) */ +#define fn llrint +#include "s_lrint.S" diff --git a/lib/libm/x86_64/s_llrintf.S b/lib/libm/x86_64/s_llrintf.S new file mode 100644 index 0000000000..7b75c26818 --- /dev/null +++ b/lib/libm/x86_64/s_llrintf.S @@ -0,0 +1,6 @@ +/* $FreeBSD: head/lib/msun/amd64/s_llrintf.S 218305 2011-02-04 21:54:06Z kib $ */ +#include + +/* sizeof(long) == sizeof(long long) */ +#define fn llrintf +#include "s_lrintf.S" diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/x86_64/s_llrintl.S similarity index 89% copy from lib/libm/arch/i386/s_lrint.S copy to lib/libm/x86_64/s_llrintl.S index 17cef8998d..8e26631a32 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/x86_64/s_llrintl.S @@ -23,22 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_llrintl.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrint) -#ifdef __i386__ - fldl 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax +ENTRY(llrintl) + fldt 8(%rsp) + subq $8,%rsp + fistpll (%rsp) + popq %rax ret -#else - cvtsd2si %xmm0, %rax - ret -#endif -END(lrint) +END(llrintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/x86_64/s_logbl.S similarity index 93% copy from lib/libm/arch/i386/e_sqrtl.S copy to lib/libm/x86_64/s_logbl.S index 769e66060b..7a1fabd9f3 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/x86_64/s_logbl.S @@ -14,7 +14,7 @@ * 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. + * 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 @@ -26,6 +26,8 @@ * 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: head/lib/msun/amd64/s_logbl.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,11 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else +ENTRY(logbl) fldt 8(%rsp) - fsqrt + fxtract + fstp %st ret -#endif -END(sqrtl) +END(logbl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrint.S b/lib/libm/x86_64/s_lrint.S similarity index 91% rename from lib/libm/arch/i386/s_lrint.S rename to lib/libm/x86_64/s_lrint.S index 17cef8998d..69ca4cd88c 100644 --- a/lib/libm/arch/i386/s_lrint.S +++ b/lib/libm/x86_64/s_lrint.S @@ -23,22 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_lrint.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrint) -#ifdef __i386__ - fldl 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax - ret -#else +#ifndef fn +#define fn lrint +#endif + +ENTRY(fn) cvtsd2si %xmm0, %rax ret -#endif -END(lrint) +END(fn) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/x86_64/s_lrintf.S similarity index 91% copy from lib/libm/arch/i386/s_lrintf.S copy to lib/libm/x86_64/s_lrintf.S index 975d1b00ef..3eb38c4926 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/x86_64/s_lrintf.S @@ -23,22 +23,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_lrintf.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrintf) -#ifdef __i386__ - flds 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax - ret -#else +#ifndef fn +#define fn lrintf +#endif + +ENTRY(fn) cvtss2si %xmm0, %rax ret -#endif -END(lrintf) +END(fn) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintl.S b/lib/libm/x86_64/s_lrintl.S similarity index 92% rename from lib/libm/arch/i386/s_lrintl.S rename to lib/libm/x86_64/s_lrintl.S index 6550d3881d..5e408397a3 100644 --- a/lib/libm/arch/i386/s_lrintl.S +++ b/lib/libm/x86_64/s_lrintl.S @@ -23,25 +23,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_lrintl.S 217108 2011-01-07 16:13:12Z kib $ */ #include ENTRY(lrintl) -#ifdef __i386__ - fldt 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax - ret -#else fldt 8(%rsp) subq $8,%rsp fistpll (%rsp) popq %rax ret -#endif END(lrintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/x86_64/s_remquo.S similarity index 70% copy from lib/libm/arch/i386/s_remquol.S copy to lib/libm/x86_64/s_remquo.S index 312d1dca05..bea075edf4 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/x86_64/s_remquo.S @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,49 +22,21 @@ * 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: head/lib/msun/amd64/s_remquo.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remquol) -#ifdef __i386__ - fldt 16(%esp) - fldt 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 24(%esp),%ecx - xorl 12(%esp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl 28(%esp),%ecx - movl %eax,(%ecx) - ret -#else - fldt 24(%rsp) - fldt 8(%rsp) +ENTRY(remquo) + movsd %xmm0,-8(%rsp) + movsd %xmm1,-16(%rsp) + fldl -16(%rsp) + fldl -8(%rsp) 1: fprem1 fstsw %ax btw $10,%ax @@ -80,9 +52,8 @@ ENTRY(remquol) orl %ecx,%eax andl $7,%eax /* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 32(%rsp),%ecx - xorl 16(%rsp),%ecx - movsx %cx,%ecx + movl -12(%rsp),%ecx + xorl -4(%rsp),%ecx sarl $16,%ecx sarl $16,%ecx xorl %ecx,%eax @@ -90,8 +61,9 @@ ENTRY(remquol) addl %ecx,%eax /* Store the quotient and return. */ movl %eax,(%rdi) + fstpl -8(%rsp) + movsd -8(%rsp),%xmm0 ret -#endif -END(remquol) +END(remquo) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/x86_64/s_remquof.S similarity index 70% copy from lib/libm/arch/i386/s_remquol.S copy to lib/libm/x86_64/s_remquof.S index 312d1dca05..8215643343 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/x86_64/s_remquof.S @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2008 David Schultz + * Copyright (c) 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,49 +22,21 @@ * 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: head/lib/msun/amd64/s_remquof.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include -ENTRY(remquol) -#ifdef __i386__ - fldt 16(%esp) - fldt 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 24(%esp),%ecx - xorl 12(%esp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl 28(%esp),%ecx - movl %eax,(%ecx) - ret -#else - fldt 24(%rsp) - fldt 8(%rsp) +ENTRY(remquof) + movss %xmm0,-4(%rsp) + movss %xmm1,-8(%rsp) + flds -8(%rsp) + flds -4(%rsp) 1: fprem1 fstsw %ax btw $10,%ax @@ -80,9 +52,8 @@ ENTRY(remquol) orl %ecx,%eax andl $7,%eax /* Negate the quotient bits if x*y<0. Avoid using an unpredictable branch. */ - movl 32(%rsp),%ecx - xorl 16(%rsp),%ecx - movsx %cx,%ecx + movl -8(%rsp),%ecx + xorl -4(%rsp),%ecx sarl $16,%ecx sarl $16,%ecx xorl %ecx,%eax @@ -90,8 +61,9 @@ ENTRY(remquol) addl %ecx,%eax /* Store the quotient and return. */ movl %eax,(%rdi) + fstps -4(%rsp) + movss -4(%rsp),%xmm0 ret -#endif -END(remquol) +END(remquof) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_remquol.S b/lib/libm/x86_64/s_remquol.S similarity index 77% rename from lib/libm/arch/i386/s_remquol.S rename to lib/libm/x86_64/s_remquol.S index 312d1dca05..1751a46623 100644 --- a/lib/libm/arch/i386/s_remquol.S +++ b/lib/libm/x86_64/s_remquol.S @@ -22,47 +22,17 @@ * 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: head/lib/msun/amd64/s_remquol.S 217108 2011-01-07 16:13:12Z kib $ */ /* * Based on public-domain remainder routine by J.T. Conklin . - * FreeBSD SVN: 217108 (2011-01-07) */ #include ENTRY(remquol) -#ifdef __i386__ - fldt 16(%esp) - fldt 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 24(%esp),%ecx - xorl 12(%esp),%ecx - movsx %cx,%ecx - sarl $16,%ecx - sarl $16,%ecx - xorl %ecx,%eax - andl $1,%ecx - addl %ecx,%eax -/* Store the quotient and return. */ - movl 28(%esp),%ecx - movl %eax,(%ecx) - ret -#else fldt 24(%rsp) fldt 8(%rsp) 1: fprem1 @@ -91,7 +61,6 @@ ENTRY(remquol) /* Store the quotient and return. */ movl %eax,(%rdi) ret -#endif END(remquol) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/e_sqrtl.S b/lib/libm/x86_64/s_rintl.S similarity index 94% rename from lib/libm/arch/i386/e_sqrtl.S rename to lib/libm/x86_64/s_rintl.S index 769e66060b..0e496a074a 100644 --- a/lib/libm/arch/i386/e_sqrtl.S +++ b/lib/libm/x86_64/s_rintl.S @@ -26,6 +26,8 @@ * 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: head/lib/msun/amd64/s_rintl.S 217108 2011-01-07 16:13:12Z kib $ */ /* @@ -35,16 +37,10 @@ #include -ENTRY(sqrtl) -#ifdef __i386__ - fldt 4(%esp) - fsqrt - ret -#else +ENTRY(rintl) fldt 8(%rsp) - fsqrt + frndint ret -#endif -END(sqrtl) +END(rintl) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/x86_64/s_scalbn.S similarity index 85% copy from lib/libm/arch/i386/s_lrintf.S copy to lib/libm/x86_64/s_scalbn.S index 975d1b00ef..f3c9a6226d 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/x86_64/s_scalbn.S @@ -23,22 +23,21 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_scalbn.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrintf) -#ifdef __i386__ - flds 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax +ENTRY(scalbn) + movsd %xmm0,-8(%rsp) + movl %edi,-12(%rsp) + fildl -12(%rsp) + fldl -8(%rsp) + fscale + fstp %st(1) + fstpl -8(%rsp) + movsd -8(%rsp),%xmm0 ret -#else - cvtss2si %xmm0, %rax - ret -#endif -END(lrintf) +END(scalbn) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_lrintf.S b/lib/libm/x86_64/s_scalbnf.S similarity index 83% rename from lib/libm/arch/i386/s_lrintf.S rename to lib/libm/x86_64/s_scalbnf.S index 975d1b00ef..1acbebf240 100644 --- a/lib/libm/arch/i386/s_lrintf.S +++ b/lib/libm/x86_64/s_scalbnf.S @@ -23,22 +23,24 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * FreeBSD SVN: 217108 (2011-01-07) + * $FreeBSD: head/lib/msun/amd64/s_scalbnf.S 217108 2011-01-07 16:13:12Z kib $ */ #include -ENTRY(lrintf) -#ifdef __i386__ - flds 4(%esp) - subl $4,%esp - fistpl (%esp) - popl %eax +ENTRY(scalbnf) + movss %xmm0,-8(%rsp) + movl %edi,-4(%rsp) + fildl -4(%rsp) + flds -8(%rsp) + fscale + fstp %st(1) + fstps -8(%rsp) + movss -8(%rsp),%xmm0 ret -#else - cvtss2si %xmm0, %rax - ret -#endif -END(lrintf) +END(scalbnf) + +.globl CNAME(ldexpf) +.set CNAME(ldexpf),CNAME(scalbnf) .section .note.GNU-stack,"",%progbits diff --git a/lib/libm/arch/i386/s_scalbnl.S b/lib/libm/x86_64/s_scalbnl.S similarity index 54% rename from lib/libm/arch/i386/s_scalbnl.S rename to lib/libm/x86_64/s_scalbnl.S index 56a03b35ff..478ac4ca94 100644 --- a/lib/libm/arch/i386/s_scalbnl.S +++ b/lib/libm/x86_64/s_scalbnl.S @@ -1,25 +1,19 @@ /* - * Written by J.T. Conklin . + * Based on code written by J.T. Conklin . * Public domain. * - * $NetBSD: s_scalbnl.S,v 1.1 2011/07/26 17:03:23 joerg Exp $ + * $NetBSD: s_scalbnf.S,v 1.4 1999/01/02 05:15:40 kristerw Exp $ + * $FreeBSD: head/lib/msun/amd64/s_scalbnl.S 217108 2011-01-07 16:13:12Z kib $ */ #include ENTRY(scalbnl) -#ifdef __x86_64__ movl %edi,-4(%rsp) fildl -4(%rsp) fldt 8(%rsp) fscale fstp %st(1) -#else - fildl 16(%esp) - fldt 4(%esp) - fscale - fstp %st(1) /* clean up stack */ -#endif ret END(scalbnl) diff --git a/sys/cpu/i386/include/float.h b/sys/cpu/i386/include/float.h deleted file mode 100644 index ec664e0c63..0000000000 --- a/sys/cpu/i386/include/float.h +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * Copyright (c) 1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)float.h 7.1 (Berkeley) 5/8/90 - * $FreeBSD: src/sys/i386/include/float.h,v 1.17 2008/03/05 11:17:20 bde Exp $ - */ - -#ifndef _CPU_FLOAT_H_ -#define _CPU_FLOAT_H_ - -#include - -__BEGIN_DECLS -extern int __flt_rounds(void); -__END_DECLS - -#define FLT_RADIX 2 /* b */ -#define FLT_ROUNDS __flt_rounds() -#if __ISO_C_VISIBLE >= 1999 -#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ -#define DECIMAL_DIG 21 /* max precision in decimal digits */ -#endif - -#define FLT_MANT_DIG 24 /* p */ -#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ -#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ -#define FLT_MIN_EXP (-125) /* emin */ -#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ -#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ -#define FLT_MAX_EXP 128 /* emax */ -#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ -#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ - -#define DBL_MANT_DIG 53 -#define DBL_EPSILON 2.2204460492503131E-16 -#define DBL_DIG 15 -#define DBL_MIN_EXP (-1021) -#define DBL_MIN 2.2250738585072014E-308 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_EXP 1024 -#define DBL_MAX 1.7976931348623157E+308 -#define DBL_MAX_10_EXP 308 - -#define LDBL_MANT_DIG 64 -#define LDBL_EPSILON 1.0842021724855044340E-19L -#define LDBL_DIG 18 -#define LDBL_MIN_EXP (-16381) -#define LDBL_MIN 3.3621031431120935063E-4932L -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_EXP 16384 -#define LDBL_MAX 1.1897314953572317650E+4932L -#define LDBL_MAX_10_EXP 4932 - -#define __GDTOA_IEEE_8087 1 -#define __GDTOA_F_QNAN 0xffc00000 -#define __GDTOA_D_QNAN0 0x0 -#define __GDTOA_D_QNAN1 0xfff80000 -#define __GDTOA_LD_QNAN0 0x0 -#define __GDTOA_LD_QNAN1 0xc0000000 -#define __GDTOA_LD_QNAN2 0xffff -#define __GDTOA_LD_QNAN3 0x0 -#define __GDTOA_LDUS_QNAN0 0x0 -#define __GDTOA_LDUS_QNAN1 0x0 -#define __GDTOA_LDUS_QNAN2 0x0 -#define __GDTOA_LDUS_QNAN3 0xc000 -#define __GDTOA_LDUS_QNAN4 0xffff - -/* #undef __GDTOA_INACCURATE_DIVIDE */ -/* #undef __GDTOA_ROUND_BIASED */ -/* #undef __GDTOA_SUDDEN_UNDERFLOW */ - -#endif /* _CPU_FLOAT_H_ */ diff --git a/sys/cpu/i386/include/floatingpoint.h b/sys/cpu/i386/include/floatingpoint.h deleted file mode 100644 index 44df111a25..0000000000 --- a/sys/cpu/i386/include/floatingpoint.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 1993 Andrew Moore, Talke Studio - * 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: @(#) floatingpoint.h 1.0 (Berkeley) 9/23/93 - * $FreeBSD: src/sys/i386/include/floatingpoint.h,v 1.14 2005/04/02 17:31:42 netchild Exp $ - */ - -#ifndef _CPU_FLOATINGPOINT_H_ -#define _CPU_FLOATINGPOINT_H_ - -#include -#include - -#endif /* !_CPU_FLOATINGPOINT_H_ */ diff --git a/sys/cpu/i386/include/ieee.h b/sys/cpu/i386/include/ieee.h deleted file mode 100644 index aab28026c7..0000000000 --- a/sys/cpu/i386/include/ieee.h +++ /dev/null @@ -1,112 +0,0 @@ -/* $NetBSD: ieee.h,v 1.7 2003/10/26 21:46:46 kleink Exp $ */ -/* $DragonFly: src/sys/cpu/i386/include/ieee.h,v 1.2 2006/11/07 17:51:21 dillon Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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, Lawrence Berkeley Laboratory. - * - * 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. 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. - * - * @(#)ieee.h 8.1 (Berkeley) 6/11/93 - */ - -#ifndef _CPU_IEEE_H_ -#define _CPU_IEEE_H_ - -/* - * ieee.h defines the machine-dependent layout of the machine's IEEE - * floating point. It does *not* define (yet?) any of the rounding - * mode bits, exceptions, and so forth. - */ - -#include - -#define EXT_EXPBITS 15 -#define EXT_FRACBITS 64 - -/* - * struct ieee_ext is the raw storage layout of the 80-bit - * extended-precision type as implemented by the FPU. Per the - * respective ABI specifications, it is followed by a tail padding of - * - * x86_64: 48 bits, - * i386: 16 bits. - */ -struct ieee_ext { - u_int ext_fracl; - u_int ext_frach:31; - u_int ext_int:1; - u_int ext_exp:15; - u_int ext_sign:1; -}; - -/* - * Floats whose exponent is in [1..INFNAN) (of whatever type) are - * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. - * Floats whose exponent is zero are either zero (iff all fraction - * bits are zero) or subnormal values. - * - * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its - * high fraction; if the bit is set, it is a `quiet NaN'. - */ -#define EXT_EXP_INFNAN 0x7fff -#define EXT_EXP_INF 0x7fff -#define EXT_EXP_NAN 0x7fff - -#if 0 -#define EXT_QUIETNAN (1 << 30) -#endif - -/* - * Exponent biases. - */ -#define EXT_EXP_BIAS 16383 - -/* - * Convenience data structures. - */ -union ieee_ext_u { - long double extu_ld; - struct ieee_ext extu_ext; -}; - -#define extu_exp extu_ext.ext_exp -#define extu_sign extu_ext.ext_sign -#define extu_fracl extu_ext.ext_fracl -#define extu_frach extu_ext.ext_frach - -#define LDBL_NBIT 0x80000000 -#define mask_nbit_l(u) ((u).extu_frach &= ~LDBL_NBIT) - -#endif diff --git a/sys/cpu/i386/include/ieeefp.h b/sys/cpu/i386/include/ieeefp.h index b3840501cf..ad820bf670 100644 --- a/sys/cpu/i386/include/ieeefp.h +++ b/sys/cpu/i386/include/ieeefp.h @@ -32,17 +32,23 @@ * SUCH DAMAGE. * * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93 - * $FreeBSD: src/sys/i386/include/ieeefp.h,v 1.14 2008/01/11 18:59:35 bde Exp $ + * $FreeBSD: head/sys/i386/include/ieeefp.h 226607 2011-10-21 06:41:46Z das $ */ #ifndef _CPU_IEEEFP_H_ #define _CPU_IEEEFP_H_ /* + * Deprecated historical FPU control interface + * * IEEE floating point type, constant and function definitions. * XXX: FP*FLD and FP*OFF are undocumented pollution. */ +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + /* * Rounding modes. */ @@ -102,12 +108,12 @@ typedef enum { #ifdef __GNUC__ -#define _fldcw(addr) __asm __volatile("fldcw %0" : : "m" (*(addr))) -#define _fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) -#define _fnclex() __asm __volatile("fnclex") -#define _fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) -#define _fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) -#define _fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) +#define __fldcw(addr) __asm __volatile("fldcw %0" : : "m" (*(addr))) +#define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) +#define __fnclex() __asm __volatile("fnclex") +#define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) +#define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) +#define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) /* * Load the control word. Be careful not to trap if there is a currently @@ -117,7 +123,7 @@ typedef enum { * is very inefficient, so only do it when necessary. */ static __inline void -_fnldcw(unsigned short _cw, unsigned short _newcw) +__fnldcw(unsigned short _cw, unsigned short _newcw) { struct { unsigned _cw; @@ -126,15 +132,15 @@ _fnldcw(unsigned short _cw, unsigned short _newcw) unsigned short _sw; if ((_cw & FP_MSKS_FLD) != FP_MSKS_FLD) { - _fnstsw(&_sw); + __fnstsw(&_sw); if (((_sw & ~_cw) & FP_STKY_FLD) != 0) { - _fnstenv(&_env); + __fnstenv(&_env); _env._cw = _newcw; - _fldenv(&_env); + __fldenv(&_env); return; } } - _fldcw(&_newcw); + __fldcw(&_newcw); } static __inline fp_rnd_t @@ -142,7 +148,7 @@ fpgetround(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF)); } @@ -152,11 +158,11 @@ fpsetround(fp_rnd_t _m) fp_rnd_t _p; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF); _newcw = _cw & ~FP_RND_FLD; _newcw |= (_m << FP_RND_OFF) & FP_RND_FLD; - _fnldcw(_cw, _newcw); + __fnldcw(_cw, _newcw); return (_p); } @@ -165,7 +171,7 @@ fpgetprec(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF)); } @@ -175,11 +181,11 @@ fpsetprec(fp_prec_t _m) fp_prec_t _p; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF); _newcw = _cw & ~FP_PRC_FLD; _newcw |= (_m << FP_PRC_OFF) & FP_PRC_FLD; - _fnldcw(_cw, _newcw); + __fnldcw(_cw, _newcw); return (_p); } @@ -194,7 +200,7 @@ fpgetmask(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF); } @@ -204,11 +210,11 @@ fpsetmask(fp_except_t _m) fp_except_t _p; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF; _newcw = _cw & ~FP_MSKS_FLD; _newcw |= (~_m << FP_MSKS_OFF) & FP_MSKS_FLD; - _fnldcw(_cw, _newcw); + __fnldcw(_cw, _newcw); return (_p); } @@ -218,7 +224,7 @@ fpgetsticky(void) unsigned _ex; unsigned short _sw; - _fnstsw(&_sw); + __fnstsw(&_sw); _ex = (_sw & FP_STKY_FLD) >> FP_STKY_OFF; return ((fp_except_t)_ex); } @@ -238,18 +244,15 @@ fpresetsticky(fp_except_t _m) if ((_p & ~_m) == _p) return (_p); if ((_p & ~_m) == 0) { - _fnclex(); + __fnclex(); return (_p); } - _fnstenv(&_env); + __fnstenv(&_env); _env._sw &= ~_m; - _fldenv(&_env); + __fldenv(&_env); return (_p); } #endif /* __GNUC__ */ -/* Suppress prototypes in the MI header. */ -#define _IEEEFP_INLINED_ 1 - #endif /* !_CPU_IEEEFP_H_ */ diff --git a/sys/cpu/i386/include/math.h b/sys/cpu/i386/include/math.h deleted file mode 100644 index 070df5b7c2..0000000000 --- a/sys/cpu/i386/include/math.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * $NetBSD: math.h,v 1.2 2003/10/28 00:55:28 kleink Exp $ - * $DragonFly: src/sys/cpu/i386/include/math.h,v 1.3 2008/04/09 06:44:37 hasso Exp $ - */ - -#ifndef _CPU_MATH_H_ -#define _CPU_MATH_H_ - -#define __HAVE_LONG_DOUBLE -#define __HAVE_NANF - -#if __ISO_C_VISIBLE >= 1999 -/* 7.12#2 float_t, double_t */ -typedef long double float_t; -typedef long double double_t; -#endif - -#endif diff --git a/sys/cpu/x86_64/include/floatingpoint.h b/sys/cpu/x86_64/include/floatingpoint.h deleted file mode 100644 index f9059a5219..0000000000 --- a/sys/cpu/x86_64/include/floatingpoint.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 1993 Andrew Moore, Talke Studio - * 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: @(#) floatingpoint.h 1.0 (Berkeley) 9/23/93 - * $FreeBSD: src/sys/amd64/include/floatingpoint.h,v 1.14 2005/04/02 17:31:42 netchild Exp $ - */ - -#ifndef _CPU_FLOATINGPOINT_H_ -#define _CPU_FLOATINGPOINT_H_ - -#include -#include - -#endif /* !_CPU_FLOATINGPOINT_H_ */ diff --git a/sys/cpu/x86_64/include/ieee.h b/sys/cpu/x86_64/include/ieee.h deleted file mode 100644 index 45b0c1cec9..0000000000 --- a/sys/cpu/x86_64/include/ieee.h +++ /dev/null @@ -1,106 +0,0 @@ -/* $NetBSD: ieee.h,v 1.7 2003/10/26 21:46:46 kleink Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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, Lawrence Berkeley Laboratory. - * - * 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. 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. - * - * @(#)ieee.h 8.1 (Berkeley) 6/11/93 - */ - -/* - * ieee.h defines the machine-dependent layout of the machine's IEEE - * floating point. It does *not* define (yet?) any of the rounding - * mode bits, exceptions, and so forth. - */ - -#include - -#define EXT_EXPBITS 15 -#define EXT_FRACBITS 64 - -/* - * struct ieee_ext is the raw storage layout of the 80-bit - * extended-precision type as implemented by the FPU. Per the - * respective ABI specifications, it is followed by a tail padding of - * - * x86_64: 48 bits, - * i386: 16 bits. - */ -struct ieee_ext { - u_int ext_fracl; - u_int ext_frach:31; - u_int ext_int:1; - u_int ext_exp:15; - u_int ext_sign:1; -}; - -/* - * Floats whose exponent is in [1..INFNAN) (of whatever type) are - * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. - * Floats whose exponent is zero are either zero (iff all fraction - * bits are zero) or subnormal values. - * - * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its - * high fraction; if the bit is set, it is a `quiet NaN'. - */ -#define EXT_EXP_INFNAN 0x7fff -#define EXT_EXP_INF 0x7fff -#define EXT_EXP_NAN 0x7fff - -#if 0 -#define EXT_QUIETNAN (1 << 30) -#endif - -/* - * Exponent biases. - */ -#define EXT_EXP_BIAS 16383 - -/* - * Convenience data structures. - */ -union ieee_ext_u { - long double extu_ld; - struct ieee_ext extu_ext; -}; - -#define extu_exp extu_ext.ext_exp -#define extu_sign extu_ext.ext_sign -#define extu_fracl extu_ext.ext_fracl -#define extu_frach extu_ext.ext_frach - -#define LDBL_NBIT 0x80000000 -#define mask_nbit_l(u) ((u).extu_frach &= ~LDBL_NBIT) diff --git a/sys/cpu/x86_64/include/ieeefp.h b/sys/cpu/x86_64/include/ieeefp.h index b8d952fdba..b179b826ad 100644 --- a/sys/cpu/x86_64/include/ieeefp.h +++ b/sys/cpu/x86_64/include/ieeefp.h @@ -32,17 +32,23 @@ * SUCH DAMAGE. * * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93 - * $FreeBSD: src/sys/amd64/include/ieeefp.h,v 1.19 2008/01/11 17:11:32 bde Exp $ + * $FreeBSD: head/sys/amd64/include/ieeefp.h 226607 2011-10-21 06:41:46Z das $ */ #ifndef _CPU_IEEEFP_H_ #define _CPU_IEEEFP_H_ /* + * Deprecated historical FPU control interface + * * IEEE floating point type, constant and function definitions. * XXX: {FP,SSE}*FLD and {FP,SSE}*OFF are undocumented pollution. */ +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif + /* * Rounding modes. */ @@ -118,15 +124,15 @@ typedef enum { #define SSE_RND_OFF 13 /* rounding control offset */ #define SSE_FZ_OFF 15 /* flush to zero offset */ -#if defined(__GNUC__) && !defined(__cplusplus) +#ifdef __GNUC__ -#define _fldcw(addr) __asm __volatile("fldcw %0" : : "m" (*(addr))) -#define _fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) -#define _fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) -#define _fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) -#define _fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) -#define _ldmxcsr(addr) __asm __volatile("ldmxcsr %0" : : "m" (*(addr))) -#define _stmxcsr(addr) __asm __volatile("stmxcsr %0" : "=m" (*(addr))) +#define __fldcw(addr) __asm __volatile("fldcw %0" : : "m" (*(addr))) +#define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) +#define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) +#define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) +#define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) +#define __ldmxcsr(addr) __asm __volatile("ldmxcsr %0" : : "m" (*(addr))) +#define __stmxcsr(addr) __asm __volatile("stmxcsr %0" : "=m" (*(addr))) /* * Load the control word. Be careful not to trap if there is a currently @@ -136,7 +142,7 @@ typedef enum { * is very inefficient, so only do it when necessary. */ static __inline void -_fnldcw(unsigned short _cw, unsigned short _newcw) +__fnldcw(unsigned short _cw, unsigned short _newcw) { struct { unsigned _cw; @@ -145,15 +151,15 @@ _fnldcw(unsigned short _cw, unsigned short _newcw) unsigned short _sw; if ((_cw & FP_MSKS_FLD) != FP_MSKS_FLD) { - _fnstsw(&_sw); + __fnstsw(&_sw); if (((_sw & ~_cw) & FP_STKY_FLD) != 0) { - _fnstenv(&_env); + __fnstenv(&_env); _env._cw = _newcw; - _fldenv(&_env); + __fldenv(&_env); return; } } - _fldcw(&_newcw); + __fldcw(&_newcw); } /* @@ -168,30 +174,30 @@ _fnldcw(unsigned short _cw, unsigned short _newcw) */ static __inline fp_rnd_t -_fpgetround(void) +__fpgetround(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF)); } static __inline fp_rnd_t -_fpsetround(fp_rnd_t _m) +__fpsetround(fp_rnd_t _m) { fp_rnd_t _p; unsigned _mxcsr; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF); _newcw = _cw & ~FP_RND_FLD; _newcw |= (_m << FP_RND_OFF) & FP_RND_FLD; - _fnldcw(_cw, _newcw); - _stmxcsr(&_mxcsr); + __fnldcw(_cw, _newcw); + __stmxcsr(&_mxcsr); _mxcsr &= ~SSE_RND_FLD; _mxcsr |= (_m << SSE_RND_OFF) & SSE_RND_FLD; - _ldmxcsr(&_mxcsr); + __ldmxcsr(&_mxcsr); return (_p); } @@ -201,25 +207,25 @@ _fpsetround(fp_rnd_t _m) */ static __inline fp_prec_t -_fpgetprec(void) +__fpgetprec(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF)); } static __inline fp_prec_t -_fpsetprec(fp_prec_t _m) +__fpsetprec(fp_prec_t _m) { fp_prec_t _p; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF); _newcw = _cw & ~FP_PRC_FLD; _newcw |= (_m << FP_PRC_OFF) & FP_PRC_FLD; - _fnldcw(_cw, _newcw); + __fnldcw(_cw, _newcw); return (_p); } @@ -230,70 +236,73 @@ _fpsetprec(fp_prec_t _m) */ static __inline fp_except_t -_fpgetmask(void) +__fpgetmask(void) { unsigned short _cw; - _fnstcw(&_cw); + __fnstcw(&_cw); return ((~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF); } static __inline fp_except_t -_fpsetmask(fp_except_t _m) +__fpsetmask(fp_except_t _m) { fp_except_t _p; unsigned _mxcsr; unsigned short _cw, _newcw; - _fnstcw(&_cw); + __fnstcw(&_cw); _p = (~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF; _newcw = _cw & ~FP_MSKS_FLD; _newcw |= (~_m << FP_MSKS_OFF) & FP_MSKS_FLD; - _fnldcw(_cw, _newcw); - _stmxcsr(&_mxcsr); + __fnldcw(_cw, _newcw); + __stmxcsr(&_mxcsr); /* XXX should we clear non-ieee SSE_DAZ_FLD and SSE_FZ_FLD ? */ _mxcsr &= ~SSE_MSKS_FLD; _mxcsr |= (~_m << SSE_MSKS_OFF) & SSE_MSKS_FLD; - _ldmxcsr(&_mxcsr); + __ldmxcsr(&_mxcsr); return (_p); } static __inline fp_except_t -_fpgetsticky(void) +__fpgetsticky(void) { unsigned _ex, _mxcsr; unsigned short _sw; - _fnstsw(&_sw); + __fnstsw(&_sw); _ex = (_sw & FP_STKY_FLD) >> FP_STKY_OFF; - _stmxcsr(&_mxcsr); + __stmxcsr(&_mxcsr); _ex |= (_mxcsr & SSE_STKY_FLD) >> SSE_STKY_OFF; return ((fp_except_t)_ex); } -#endif /* __GNUC__ && !__cplusplus */ - -#if !defined(__IEEEFP_NOINLINES__) && !defined(__cplusplus) && defined(__GNUC__) +#endif /* __GNUC__ */ -#define fpgetmask() _fpgetmask() -#define fpgetprec() _fpgetprec() -#define fpgetround() _fpgetround() -#define fpgetsticky() _fpgetsticky() -#define fpsetmask(m) _fpsetmask(m) -#define fpsetprec(m) _fpsetprec(m) -#define fpsetround(m) _fpsetround(m) +#if !defined(__IEEEFP_NOINLINES__) && defined(__GNUC__) -/* Suppress prototypes in the MI header. */ -#define _IEEEFP_INLINED_ 1 +#define fpgetmask() __fpgetmask() +#define fpgetprec() __fpgetprec() +#define fpgetround() __fpgetround() +#define fpgetsticky() __fpgetsticky() +#define fpsetmask(m) __fpsetmask(m) +#define fpsetprec(m) __fpsetprec(m) +#define fpsetround(m) __fpsetround(m) -#else /* !__IEEEFP_NOINLINES__ && !__cplusplus && __GNUC__ */ +#else /* !(!__IEEEFP_NOINLINES__ && __GNUC__) */ /* Augment the userland declarations. */ __BEGIN_DECLS +extern fp_rnd_t fpgetround(void); +extern fp_rnd_t fpsetround(fp_rnd_t); +extern fp_except_t fpgetmask(void); +extern fp_except_t fpsetmask(fp_except_t); +extern fp_except_t fpgetsticky(void); +extern fp_except_t fpsetsticky(fp_except_t); fp_prec_t fpgetprec(void); fp_prec_t fpsetprec(fp_prec_t); __END_DECLS -#endif /* !__IEEEFP_NOINLINES__ && !__cplusplus && __GNUC__ */ +#endif /* !__IEEEFP_NOINLINES__ && __GNUC__ */ #endif /* !_CPU_IEEEFP_H_ */ diff --git a/sys/cpu/x86_64/include/math.h b/sys/cpu/x86_64/include/math.h deleted file mode 100644 index 1e5e5e2b04..0000000000 --- a/sys/cpu/x86_64/include/math.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * $NetBSD: math.h,v 1.2 2003/10/28 00:55:28 kleink Exp $ - */ - -#ifndef _CPU_MATH_H_ -#define _CPU_MATH_H_ - -#define __HAVE_LONG_DOUBLE -#define __HAVE_NANF - -#if __ISO_C_VISIBLE >= 1999 -/* 7.12#2 float_t, double_t */ -typedef float float_t; -typedef double double_t; -#endif - -#endif diff --git a/sys/sys/param.h b/sys/sys/param.h index bfd029c0fc..eb3d5b20de 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -99,9 +99,10 @@ * 300304 - Update to dialog-1.2-20121230 * 300400 - 3.4 release * 300500 - 3.5 master + * 300501 - Convert libm to FreeBSD's version */ #undef __DragonFly_version -#define __DragonFly_version 300500 /* propagated to newvers */ +#define __DragonFly_version 300501 /* propagated to newvers */ #include -- 2.41.0