Merge "Upgrade libm."
diff --git a/libc/arch-arm/include/machine/_types.h b/libc/arch-arm/include/machine/_types.h
index 1521a4c..0a8b610 100644
--- a/libc/arch-arm/include/machine/_types.h
+++ b/libc/arch-arm/include/machine/_types.h
@@ -87,6 +87,8 @@
 /* Standard system types */
 typedef int			__clock_t;
 typedef int			__clockid_t;
+typedef double			__double_t;
+typedef float			__float_t;
 typedef long			__ptrdiff_t;
 typedef	int			__time_t;
 typedef int			__timer_t;
diff --git a/libc/arch-x86/include/machine/_types.h b/libc/arch-x86/include/machine/_types.h
index d217822..3806f78 100644
--- a/libc/arch-x86/include/machine/_types.h
+++ b/libc/arch-x86/include/machine/_types.h
@@ -87,6 +87,8 @@
 /* Standard system types */
 typedef int			__clock_t;
 typedef int			__clockid_t;
+typedef double			__double_t;
+typedef float			__float_t;
 typedef long			__ptrdiff_t;
 typedef	int			__time_t;
 typedef int			__timer_t;
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index ca81cb6..937abe0 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -177,6 +177,8 @@
 #define	__unused	/* delete */
 #endif
 
+#define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */
+
 #if __GNUC_PREREQ__(3, 1)
 #define	__used		__attribute__((__used__))
 #else
@@ -313,6 +315,12 @@
 #define __purefunc
 #endif
 
+#if __GNUC_PREREQ__(3, 1)
+#define __always_inline __attribute__((__always_inline__))
+#else
+#define __always_inline
+#endif
+
 /*
  * Macros for manipulating "link sets".  Link sets are arrays of pointers
  * to objects, which are gathered up by the linker.
@@ -510,4 +518,11 @@
 #define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
 #endif
 
+/* Android-added: for FreeBSD's libm. */
+#define __weak_reference(sym,alias) \
+    __asm__(".weak " #alias); \
+    __asm__(".equ "  #alias ", " #sym)
+#define __strong_reference(sym,aliassym) \
+    extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
+
 #endif /* !_SYS_CDEFS_H_ */
diff --git a/libc/tools/check-symbols.py b/libc/tools/check-symbols.py
new file mode 100755
index 0000000..0922548
--- /dev/null
+++ b/libc/tools/check-symbols.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+import glob
+import os
+import re
+import string
+import subprocess
+import sys
+
+toolchain = os.environ['ANDROID_TOOLCHAIN']
+arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain)
+
+sys.stderr.write('Checking symbols for arch "%s"...\n' % arch)
+
+def GetSymbols(library, functions_or_variables):
+  api = '9'
+  if library == 'libm' and arch == 'arm':
+    api = '3'
+  path = '%s/development/ndk/platforms/android-%s/arch-%s/symbols/%s.so.%s.txt' % (os.environ['ANDROID_BUILD_TOP'], api, arch, library, functions_or_variables)
+  symbols = set()
+  for line in open(path, 'r'):
+    symbols.add(line.rstrip())
+  #sys.stdout.write('%d %s in %s for %s\n' % (len(symbols), functions_or_variables, library, arch))
+  return symbols
+
+def CheckSymbols(library, functions_or_variables):
+  expected_symbols = GetSymbols(library, functions_or_variables)
+
+  so_file = '%s/system/lib/%s.so' % (os.environ['ANDROID_PRODUCT_OUT'], library)
+
+  # Example readelf output:
+  #   264: 0001623c     4 FUNC    GLOBAL DEFAULT    8 cabsf
+  #   266: 00016244     4 FUNC    GLOBAL DEFAULT    8 dremf
+  #   267: 00019018     4 OBJECT  GLOBAL DEFAULT   11 __fe_dfl_env
+  #   268: 00000000     0 FUNC    GLOBAL DEFAULT  UND __aeabi_dcmplt
+
+
+  r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)')
+
+  actual_symbols = set()
+  for line in subprocess.check_output(['readelf', '--dyn-syms', so_file]).split('\n'):
+    m = r.match(line)
+    if m:
+      if m.group(1) == 'FUNC' and functions_or_variables == 'functions':
+        actual_symbols.add(m.group(2))
+      elif m.group(1) == 'OBJECT' and functions_or_variables == 'variables':
+        actual_symbols.add(m.group(2))
+    #else:
+      #print 'ignoring: ' % line
+
+  missing = expected_symbols - actual_symbols
+  if len(missing) > 0:
+    sys.stderr.write('%d missing %s in %s for %s:\n' % (len(missing), functions_or_variables, library, arch))
+    for miss in sorted(missing):
+      sys.stderr.write('  %s\n' % miss)
+
+  return len(missing) == 0
+
+CheckSymbols("libc", "functions")
+CheckSymbols("libc", "variables")
+CheckSymbols("libm", "functions")
+CheckSymbols("libm", "variables")
+
+sys.exit(0)
diff --git a/libm/Android.mk b/libm/Android.mk
index 9c88798..0d2c843 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -1,229 +1,254 @@
 LOCAL_PATH:= $(call my-dir)
 
-libm_common_src_files:= \
-	isinf.c  \
-	fpclassify.c \
-	sincos.c \
-	bsdsrc/b_exp.c \
-	bsdsrc/b_log.c \
-	bsdsrc/b_tgamma.c \
-	src/e_acos.c \
-	src/e_acosf.c \
-	src/e_acosh.c \
-	src/e_acoshf.c \
-	src/e_asin.c \
-	src/e_asinf.c \
-	src/e_atan2.c \
-	src/e_atan2f.c \
-	src/e_atanh.c \
-	src/e_atanhf.c \
-	src/e_cosh.c \
-	src/e_coshf.c \
-	src/e_exp.c \
-	src/e_expf.c \
-	src/e_fmod.c \
-	src/e_fmodf.c \
-	src/e_gamma.c \
-	src/e_gamma_r.c \
-	src/e_gammaf.c \
-	src/e_gammaf_r.c \
-	src/e_hypot.c \
-	src/e_hypotf.c \
-	src/e_j0.c \
-	src/e_j0f.c \
-	src/e_j1.c \
-	src/e_j1f.c \
-	src/e_jn.c \
-	src/e_jnf.c \
-	src/e_lgamma.c \
-	src/e_lgamma_r.c \
-	src/e_lgammaf.c \
-	src/e_lgammaf_r.c \
-	src/e_log.c \
-	src/e_log10.c \
-	src/e_log10f.c \
-	src/e_logf.c \
-	src/e_pow.c \
-	src/e_powf.c \
-	src/e_rem_pio2.c \
-	src/e_rem_pio2f.c \
-	src/e_remainder.c \
-	src/e_remainderf.c \
-	src/e_scalb.c \
-	src/e_scalbf.c \
-	src/e_sinh.c \
-	src/e_sinhf.c \
-	src/e_sqrt.c \
-	src/k_cos.c \
-	src/k_cosf.c \
-	src/k_rem_pio2.c \
-	src/k_sin.c \
-	src/k_sinf.c \
-	src/k_tan.c \
-	src/k_tanf.c \
-	src/s_asinh.c \
-	src/s_asinhf.c \
-	src/s_atan.c \
-	src/s_atanf.c \
-	src/s_cbrt.c \
-	src/s_cbrtf.c \
-	src/s_ceil.c \
-	src/s_ceilf.c \
-	src/s_ceill.c \
-	src/s_copysign.c \
-	src/s_copysignf.c \
-	src/s_cos.c \
-	src/s_cosf.c \
-	src/s_erf.c \
-	src/s_erff.c \
-	src/s_exp2.c \
-	src/s_exp2f.c \
-	src/s_expm1.c \
-	src/s_expm1f.c \
-	src/s_fabsf.c \
-	src/s_fdim.c \
-	src/s_finite.c \
-	src/s_finitef.c \
-	src/s_floor.c \
-	src/s_floorf.c \
-	src/s_floorl.c \
-	src/s_fma.c \
-	src/s_fmaf.c \
-	src/s_fmax.c \
-	src/s_fmaxf.c \
-	src/s_fmaxl.c \
-	src/s_fmin.c \
-	src/s_fminf.c \
-	src/s_fminl.c \
-	src/s_frexpf.c \
-	src/s_ilogb.c \
-	src/s_ilogbf.c \
-	src/s_ilogbl.c \
-	src/s_isfinite.c \
-	src/s_isnormal.c \
-	src/s_llrint.c \
-	src/s_llrintf.c \
-	src/s_llround.c \
-	src/s_llroundf.c \
-	src/s_llroundl.c \
-	src/s_log1p.c \
-	src/s_log1pf.c \
-	src/s_logb.c \
-	src/s_logbf.c \
-	src/s_lrint.c \
-	src/s_lrintf.c \
-	src/s_lround.c \
-	src/s_lroundf.c \
-	src/s_lroundl.c \
-	src/s_modff.c \
-	src/s_nan.c \
-	src/s_nearbyint.c \
-	src/s_nextafter.c \
-	src/s_nextafterf.c \
-	src/s_nexttowardf.c \
-	src/s_remquo.c \
-	src/s_remquof.c \
-	src/s_rint.c \
-	src/s_rintf.c \
-	src/s_round.c \
-	src/s_roundf.c \
-	src/s_roundl.c \
-	src/s_signbit.c \
-	src/s_signgam.c \
-	src/s_significand.c \
-	src/s_significandf.c \
-	src/s_sin.c \
-	src/s_sinf.c \
-	src/s_tan.c \
-	src/s_tanf.c \
-	src/s_tanh.c \
-	src/s_tanhf.c \
-	src/s_tgammaf.c \
-	src/s_trunc.c \
-	src/s_truncf.c \
-	src/s_truncl.c \
-	src/w_drem.c \
-	src/w_dremf.c \
-	src/s_copysignl.c \
-	src/s_fabsl.c \
-	src/s_fabs.c \
-	src/s_frexp.c \
-	src/s_isnan.c \
-	src/s_modf.c
+# TODO: these come from from upstream's libc, not libm!
+libm_common_src_files := \
+    digittoint.c  \
+    fpclassify.c \
+    isinf.c  \
 
-libm_common_cflags :=
+# TODO: this is not in the BSDs.
+libm_common_src_files += \
+    sincos.c \
 
-ifeq ($(TARGET_ARCH),arm)
-  libm_common_src_files += \
-	arm/fenv.c \
-	src/e_ldexpf.c \
-	src/s_scalbln.c \
-	src/s_scalbn.c \
-	src/s_scalbnf.c \
-	src/e_sqrtf.c
+libm_common_src_files += \
+    upstream-freebsd/lib/msun/bsdsrc/b_exp.c \
+    upstream-freebsd/lib/msun/bsdsrc/b_log.c \
+    upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c \
+    upstream-freebsd/lib/msun/src/e_acos.c \
+    upstream-freebsd/lib/msun/src/e_acosf.c \
+    upstream-freebsd/lib/msun/src/e_acosh.c \
+    upstream-freebsd/lib/msun/src/e_acoshf.c \
+    upstream-freebsd/lib/msun/src/e_asin.c \
+    upstream-freebsd/lib/msun/src/e_asinf.c \
+    upstream-freebsd/lib/msun/src/e_atan2.c \
+    upstream-freebsd/lib/msun/src/e_atan2f.c \
+    upstream-freebsd/lib/msun/src/e_atanh.c \
+    upstream-freebsd/lib/msun/src/e_atanhf.c \
+    upstream-freebsd/lib/msun/src/e_cosh.c \
+    upstream-freebsd/lib/msun/src/e_coshf.c \
+    upstream-freebsd/lib/msun/src/e_exp.c \
+    upstream-freebsd/lib/msun/src/e_expf.c \
+    upstream-freebsd/lib/msun/src/e_fmod.c \
+    upstream-freebsd/lib/msun/src/e_fmodf.c \
+    upstream-freebsd/lib/msun/src/e_gamma.c \
+    upstream-freebsd/lib/msun/src/e_gammaf.c \
+    upstream-freebsd/lib/msun/src/e_gammaf_r.c \
+    upstream-freebsd/lib/msun/src/e_gamma_r.c \
+    upstream-freebsd/lib/msun/src/e_hypot.c \
+    upstream-freebsd/lib/msun/src/e_hypotf.c \
+    upstream-freebsd/lib/msun/src/e_j0.c \
+    upstream-freebsd/lib/msun/src/e_j0f.c \
+    upstream-freebsd/lib/msun/src/e_j1.c \
+    upstream-freebsd/lib/msun/src/e_j1f.c \
+    upstream-freebsd/lib/msun/src/e_jn.c \
+    upstream-freebsd/lib/msun/src/e_jnf.c \
+    upstream-freebsd/lib/msun/src/e_lgamma.c \
+    upstream-freebsd/lib/msun/src/e_lgammaf.c \
+    upstream-freebsd/lib/msun/src/e_lgammaf_r.c \
+    upstream-freebsd/lib/msun/src/e_lgamma_r.c \
+    upstream-freebsd/lib/msun/src/e_log10.c \
+    upstream-freebsd/lib/msun/src/e_log10f.c \
+    upstream-freebsd/lib/msun/src/e_log2.c \
+    upstream-freebsd/lib/msun/src/e_log2f.c \
+    upstream-freebsd/lib/msun/src/e_log.c \
+    upstream-freebsd/lib/msun/src/e_logf.c \
+    upstream-freebsd/lib/msun/src/e_pow.c \
+    upstream-freebsd/lib/msun/src/e_powf.c \
+    upstream-freebsd/lib/msun/src/e_remainder.c \
+    upstream-freebsd/lib/msun/src/e_remainderf.c \
+    upstream-freebsd/lib/msun/src/e_rem_pio2.c \
+    upstream-freebsd/lib/msun/src/e_rem_pio2f.c \
+    upstream-freebsd/lib/msun/src/e_scalb.c \
+    upstream-freebsd/lib/msun/src/e_scalbf.c \
+    upstream-freebsd/lib/msun/src/e_sinh.c \
+    upstream-freebsd/lib/msun/src/e_sinhf.c \
+    upstream-freebsd/lib/msun/src/e_sqrt.c \
+    upstream-freebsd/lib/msun/src/e_sqrtf.c \
+    upstream-freebsd/lib/msun/src/k_cos.c \
+    upstream-freebsd/lib/msun/src/k_cosf.c \
+    upstream-freebsd/lib/msun/src/k_exp.c \
+    upstream-freebsd/lib/msun/src/k_expf.c \
+    upstream-freebsd/lib/msun/src/k_rem_pio2.c \
+    upstream-freebsd/lib/msun/src/k_sin.c \
+    upstream-freebsd/lib/msun/src/k_sinf.c \
+    upstream-freebsd/lib/msun/src/k_tan.c \
+    upstream-freebsd/lib/msun/src/k_tanf.c \
+    upstream-freebsd/lib/msun/src/s_asinh.c \
+    upstream-freebsd/lib/msun/src/s_asinhf.c \
+    upstream-freebsd/lib/msun/src/s_atan.c \
+    upstream-freebsd/lib/msun/src/s_atanf.c \
+    upstream-freebsd/lib/msun/src/s_carg.c \
+    upstream-freebsd/lib/msun/src/s_cargf.c \
+    upstream-freebsd/lib/msun/src/s_cbrt.c \
+    upstream-freebsd/lib/msun/src/s_cbrtf.c \
+    upstream-freebsd/lib/msun/src/s_ccosh.c \
+    upstream-freebsd/lib/msun/src/s_ccoshf.c \
+    upstream-freebsd/lib/msun/src/s_ceil.c \
+    upstream-freebsd/lib/msun/src/s_ceilf.c \
+    upstream-freebsd/lib/msun/src/s_cexp.c \
+    upstream-freebsd/lib/msun/src/s_cexpf.c \
+    upstream-freebsd/lib/msun/src/s_cimag.c \
+    upstream-freebsd/lib/msun/src/s_cimagf.c \
+    upstream-freebsd/lib/msun/src/s_conj.c \
+    upstream-freebsd/lib/msun/src/s_conjf.c \
+    upstream-freebsd/lib/msun/src/s_copysign.c \
+    upstream-freebsd/lib/msun/src/s_copysignf.c \
+    upstream-freebsd/lib/msun/src/s_cos.c \
+    upstream-freebsd/lib/msun/src/s_cosf.c \
+    upstream-freebsd/lib/msun/src/s_cproj.c \
+    upstream-freebsd/lib/msun/src/s_cprojf.c \
+    upstream-freebsd/lib/msun/src/s_creal.c \
+    upstream-freebsd/lib/msun/src/s_crealf.c \
+    upstream-freebsd/lib/msun/src/s_csinh.c \
+    upstream-freebsd/lib/msun/src/s_csinhf.c \
+    upstream-freebsd/lib/msun/src/s_csqrt.c \
+    upstream-freebsd/lib/msun/src/s_csqrtf.c \
+    upstream-freebsd/lib/msun/src/s_ctanh.c \
+    upstream-freebsd/lib/msun/src/s_ctanhf.c \
+    upstream-freebsd/lib/msun/src/s_erf.c \
+    upstream-freebsd/lib/msun/src/s_erff.c \
+    upstream-freebsd/lib/msun/src/s_exp2.c \
+    upstream-freebsd/lib/msun/src/s_exp2f.c \
+    upstream-freebsd/lib/msun/src/s_expm1.c \
+    upstream-freebsd/lib/msun/src/s_expm1f.c \
+    upstream-freebsd/lib/msun/src/s_fabs.c \
+    upstream-freebsd/lib/msun/src/s_fabsf.c \
+    upstream-freebsd/lib/msun/src/s_fdim.c \
+    upstream-freebsd/lib/msun/src/s_finite.c \
+    upstream-freebsd/lib/msun/src/s_finitef.c \
+    upstream-freebsd/lib/msun/src/s_floor.c \
+    upstream-freebsd/lib/msun/src/s_floorf.c \
+    upstream-freebsd/lib/msun/src/s_fma.c \
+    upstream-freebsd/lib/msun/src/s_fmaf.c \
+    upstream-freebsd/lib/msun/src/s_fmax.c \
+    upstream-freebsd/lib/msun/src/s_fmaxf.c \
+    upstream-freebsd/lib/msun/src/s_fmin.c \
+    upstream-freebsd/lib/msun/src/s_fminf.c \
+    upstream-freebsd/lib/msun/src/s_frexp.c \
+    upstream-freebsd/lib/msun/src/s_frexpf.c \
+    upstream-freebsd/lib/msun/src/s_ilogb.c \
+    upstream-freebsd/lib/msun/src/s_ilogbf.c \
+    upstream-freebsd/lib/msun/src/s_isfinite.c \
+    upstream-freebsd/lib/msun/src/s_isnan.c \
+    upstream-freebsd/lib/msun/src/s_isnormal.c \
+    upstream-freebsd/lib/msun/src/s_llrint.c \
+    upstream-freebsd/lib/msun/src/s_llrintf.c \
+    upstream-freebsd/lib/msun/src/s_llround.c \
+    upstream-freebsd/lib/msun/src/s_llroundf.c \
+    upstream-freebsd/lib/msun/src/s_log1p.c \
+    upstream-freebsd/lib/msun/src/s_log1pf.c \
+    upstream-freebsd/lib/msun/src/s_logb.c \
+    upstream-freebsd/lib/msun/src/s_logbf.c \
+    upstream-freebsd/lib/msun/src/s_lrint.c \
+    upstream-freebsd/lib/msun/src/s_lrintf.c \
+    upstream-freebsd/lib/msun/src/s_lround.c \
+    upstream-freebsd/lib/msun/src/s_lroundf.c \
+    upstream-freebsd/lib/msun/src/s_modf.c \
+    upstream-freebsd/lib/msun/src/s_modff.c \
+    upstream-freebsd/lib/msun/src/s_nan.c \
+    upstream-freebsd/lib/msun/src/s_nearbyint.c \
+    upstream-freebsd/lib/msun/src/s_nextafter.c \
+    upstream-freebsd/lib/msun/src/s_nextafterf.c \
+    upstream-freebsd/lib/msun/src/s_nexttowardf.c \
+    upstream-freebsd/lib/msun/src/s_remquo.c \
+    upstream-freebsd/lib/msun/src/s_remquof.c \
+    upstream-freebsd/lib/msun/src/s_rint.c \
+    upstream-freebsd/lib/msun/src/s_rintf.c \
+    upstream-freebsd/lib/msun/src/s_round.c \
+    upstream-freebsd/lib/msun/src/s_roundf.c \
+    upstream-freebsd/lib/msun/src/s_scalbln.c \
+    upstream-freebsd/lib/msun/src/s_scalbn.c \
+    upstream-freebsd/lib/msun/src/s_scalbnf.c \
+    upstream-freebsd/lib/msun/src/s_signbit.c \
+    upstream-freebsd/lib/msun/src/s_signgam.c \
+    upstream-freebsd/lib/msun/src/s_significand.c \
+    upstream-freebsd/lib/msun/src/s_significandf.c \
+    upstream-freebsd/lib/msun/src/s_sin.c \
+    upstream-freebsd/lib/msun/src/s_sinf.c \
+    upstream-freebsd/lib/msun/src/s_tan.c \
+    upstream-freebsd/lib/msun/src/s_tanf.c \
+    upstream-freebsd/lib/msun/src/s_tanh.c \
+    upstream-freebsd/lib/msun/src/s_tanhf.c \
+    upstream-freebsd/lib/msun/src/s_tgammaf.c \
+    upstream-freebsd/lib/msun/src/s_trunc.c \
+    upstream-freebsd/lib/msun/src/s_truncf.c \
+    upstream-freebsd/lib/msun/src/w_cabs.c \
+    upstream-freebsd/lib/msun/src/w_cabsf.c \
+    upstream-freebsd/lib/msun/src/w_drem.c \
+    upstream-freebsd/lib/msun/src/w_dremf.c \
 
-  libm_common_includes = $(LOCAL_PATH)/arm
-endif
+libm_common_src_files += fake_long_double.c
 
-ifeq ($(TARGET_OS)-$(TARGET_ARCH),linux-x86)
-  libm_common_src_files += \
-	i387/fenv.c \
-	i387/s_scalbnl.S \
-	i387/s_scalbn.S \
-	i387/s_scalbnf.S \
-	i387/e_sqrtf.S
+# TODO: on Android, "long double" is "double".
+#    upstream-freebsd/lib/msun/src/e_acosl.c \
+#    upstream-freebsd/lib/msun/src/e_asinl.c \
+#    upstream-freebsd/lib/msun/src/e_atan2l.c \
+#    upstream-freebsd/lib/msun/src/e_fmodl.c \
+#    upstream-freebsd/lib/msun/src/e_hypotl.c \
+#    upstream-freebsd/lib/msun/src/e_remainderl.c \
+#    upstream-freebsd/lib/msun/src/e_sqrtl.c \
+#    upstream-freebsd/lib/msun/src/s_atanl.c \
+#    upstream-freebsd/lib/msun/src/s_cbrtl.c \
+#    upstream-freebsd/lib/msun/src/s_ceill.c \
+#    upstream-freebsd/lib/msun/src/s_copysignl.c \
+#    upstream-freebsd/lib/msun/src/s_cosl.c \
+#    upstream-freebsd/lib/msun/src/s_fabsl.c \
+#    upstream-freebsd/lib/msun/src/s_floorl.c \
+#    upstream-freebsd/lib/msun/src/s_fmal.c \
+#    upstream-freebsd/lib/msun/src/s_fmaxl.c \
+#    upstream-freebsd/lib/msun/src/s_fminl.c \
+#    upstream-freebsd/lib/msun/src/s_frexpl.c \
+#    upstream-freebsd/lib/msun/src/s_ilogbl.c \
+#    upstream-freebsd/lib/msun/src/s_llrintl.c \
+#    upstream-freebsd/lib/msun/src/s_llroundl.c \
+#    upstream-freebsd/lib/msun/src/s_logbl.c \
+#    upstream-freebsd/lib/msun/src/s_lrintl.c \
+#    upstream-freebsd/lib/msun/src/s_lroundl.c \
+#    upstream-freebsd/lib/msun/src/s_modfl.c \
+#    upstream-freebsd/lib/msun/src/s_nextafterl.c \
+#    upstream-freebsd/lib/msun/src/s_nexttoward.c \
+#    upstream-freebsd/lib/msun/src/s_remquol.c \
+#    upstream-freebsd/lib/msun/src/s_rintl.c \
+#    upstream-freebsd/lib/msun/src/s_roundl.c \
+#    upstream-freebsd/lib/msun/src/s_scalbnl.c \
+#    upstream-freebsd/lib/msun/src/s_sinl.c \
+#    upstream-freebsd/lib/msun/src/s_tanl.c \
+#    upstream-freebsd/lib/msun/src/s_truncl.c \
 
-  libm_common_includes = $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387
-endif
-ifeq ($(TARGET_ARCH),mips)
-  libm_common_src_files += \
-	mips/fenv.c \
-	src/e_ldexpf.c \
-	src/s_scalbln.c \
-	src/s_scalbn.c \
-	src/s_scalbnf.c \
-	src/e_sqrtf.c
+# TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
 
-  libm_common_includes = $(LOCAL_PATH)/mips
-  # Need to build *rint* functions
-  libm_common_cflags += -fno-builtin-rintf -fno-builtin-rint
-endif
+libm_common_cflags := -DFLT_EVAL_METHOD=0
+libm_common_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
 
-# libm.a
-# ========================================================
+libm_arm_includes := $(LOCAL_PATH)/arm
+libm_arm_src_files := arm/fenv.c
 
+libm_x86_includes := $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387
+libm_x86_src_files := i387/fenv.c
+
+libm_mips_cflags := -fno-builtin-rintf -fno-builtin-rint
+libm_mips_includes := $(LOCAL_PATH)/mips
+libm_mips_src_files := mips/fenv.c
+
+#
+# libm.a for target.
+#
 include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    $(libm_common_src_files)
-
-LOCAL_ARM_MODE := arm
-LOCAL_C_INCLUDES += $(libm_common_includes)
-LOCAL_CFLAGS := $(libm_common_cflags)
-
 LOCAL_MODULE:= libm
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS := $(libm_common_cflags) $(libm_$(TARGET_ARCH)_cflags)
+LOCAL_C_INCLUDES += $(libm_common_includes) $(libm_$(TARGET_ARCH)_includes)
+LOCAL_SRC_FILES := $(libm_common_src_files) $(libm_$(TARGET_ARCH)_src_files)
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
 include $(BUILD_STATIC_LIBRARY)
 
-# libm.so
-# ========================================================
-
+#
+# libm.so for target.
+#
 include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    $(libm_common_src_files)
-
-LOCAL_ARM_MODE := arm
-
-LOCAL_C_INCLUDES += $(libm_common_includes)
-LOCAL_CFLAGS := $(libm_common_cflags)
-
 LOCAL_MODULE:= libm
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
+LOCAL_WHOLE_STATIC_LIBRARIES := libm
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libm/arm/_fpmath.h b/libm/arm/_fpmath.h
index 79e4346..4c18945 100644
--- a/libm/arm/_fpmath.h
+++ b/libm/arm/_fpmath.h
@@ -23,18 +23,29 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libc/arm/_fpmath.h,v 1.4 2005/03/20 00:53:52 cognet Exp $
+ * $FreeBSD$
  */
 
+#if defined(__VFP_FP__)
+#define	_IEEE_WORD_ORDER	_BYTE_ORDER
+#else
+#define	_IEEE_WORD_ORDER	_BIG_ENDIAN
+#endif
+
 union IEEEl2bits {
 	long double	e;
 	struct {
-#ifndef __ARMEB__
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+#if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
 		unsigned int	manl	:32;
+#endif
 		unsigned int	manh	:20;
 		unsigned int	exp	:11;
 		unsigned int	sign	:1;
-#else
+#if _IEEE_WORD_ORDER == _BIG_ENDIAN
+		unsigned int	manl	:32;
+#endif
+#else	/* _BYTE_ORDER == _LITTLE_ENDIAN */
 		unsigned int		sign	:1;
 		unsigned int		exp	:11;
 		unsigned int		manh	:20;
@@ -44,9 +55,10 @@
 };
 
 #define	LDBL_NBIT	0
+#define	LDBL_IMPLICIT_NBIT
 #define	mask_nbit_l(u)	((void)0)
 
-#define	LDBL_MANH_SIZE	32
+#define	LDBL_MANH_SIZE	20
 #define	LDBL_MANL_SIZE	32
 
 #define	LDBL_TO_ARRAY32(u, a) do {			\
diff --git a/libm/src/s_creall.c b/libm/digittoint.c
similarity index 75%
copy from libm/src/s_creall.c
copy to libm/digittoint.c
index 1531d16..1824788 100644
--- a/libm/src/s_creall.c
+++ b/libm/digittoint.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,13 +23,24 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_creall.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
-#include <complex.h>
+#include <sys/cdefs.h>
 
-long double
-creall(long double complex z)
-{
-	return z;
+/* digittoint is in the FreeBSD C library, but implemented in terms of locale stuff. */
+__LIBC_HIDDEN__ int digittoint(char ch) {
+  int d = ch - '0';
+  if ((unsigned) d < 10) {
+    return d;
+  }
+  d = ch - 'a';
+  if ((unsigned) d < 6) {
+    return d + 10;
+  }
+  d = ch - 'A';
+  if ((unsigned) d < 6) {
+    return d + 10;
+  }
+  return -1;
 }
diff --git a/libm/fake_long_double.c b/libm/fake_long_double.c
new file mode 100644
index 0000000..8152033
--- /dev/null
+++ b/libm/fake_long_double.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <float.h>
+#include <math.h>
+
+extern int __isinf(double); /* isinf.c */
+int (isinf)(double a1) { return __isinf(a1); }
+
+/*
+ * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double).
+ * Android works around those cases by replacing the broken functions with our own trivial stubs
+ * that call the regular "double" function.
+ */
+
+int __fpclassifyl(long double a1) { return __fpclassifyd(a1); }
+int __isfinitel(long double a1) { return __isfinite(a1); }
+int __isinfl(long double a1) { return __isinf(a1); }
+int __isnanl(long double a1) { return isnan(a1); }
+int __isnormall(long double a1) { return __isnormal(a1); }
+int __signbitl(long double a1) { return __signbit(a1); }
+
+long double acoshl(long double a1) { return acosh(a1); }
+long double asinhl(long double a1) { return asinh(a1); }
+long double atanhl(long double a1) { return atanh(a1); }
+long double cbrtl(long double a1) { return cbrt(a1); }
+long double copysignl(long double a1, long double a2) { return copysign(a1, a2); }
+long double coshl(long double a1) { return cosh(a1); }
+long double erfcl(long double a1) { return erfc(a1); }
+long double erfl(long double a1) { return erf(a1); }
+long double expm1l(long double a1) { return expm1(a1); }
+long double fabsl(long double a1) { return fabs(a1); }
+long double fmaxl(long double a1, long double a2) { return fmax(a1, a2); }
+long double fmodl(long double a1, long double a2) { return fmod(a1, a2); }
+long double fminl(long double a1, long double a2) { return fmin(a1, a2); }
+int ilogbl(long double a1) { return ilogb(a1); }
+long double lgammal(long double a1) { return lgamma(a1); }
+long long llrintl(long double a1) { return llrint(a1); }
+long double log10l(long double a1) { return log10(a1); }
+long double log1pl(long double a1) { return log1p(a1); }
+long double log2l(long double a1) { return log2(a1); }
+long double logl(long double a1) { return log(a1); }
+long lrintl(long double a1) { return lrint(a1); }
+long long llroundl(long double a1) { return llround(a1); }
+long lroundl(long double a1) { return lround(a1); }
+long double modfl(long double a1, long double* a2) { return modf(a1, (double*) a2); }
+long double powl(long double a1, long double a2) { return pow(a1, a2); }
+long double rintl(long double a1) { return rint(a1); }
+long double roundl(long double a1) { return round(a1); }
+long double scalbnl(long double a1, int a2) { return scalbn(a1, a2); }
+long double significandl(long double a1) { return significand(a1); }
+long double sinhl(long double a1) { return sinh(a1); }
+long double sqrtl(long double a1) { return sqrt(a1); }
+long double tanhl(long double a1) { return tanh(a1); }
+long double tgammal(long double a1) { return tgamma(a1); }
diff --git a/libm/fpclassify.c b/libm/fpclassify.c
index baf116c..a039138 100644
--- a/libm/fpclassify.c
+++ b/libm/fpclassify.c
@@ -32,7 +32,7 @@
 #include <math.h>
 #include <stdint.h>
 
-#include "src/fpmath.h"
+#include "fpmath.h"
 
 int
 __fpclassifyf(float f)
diff --git a/libm/src/fpmath.h b/libm/fpmath.h
similarity index 82%
rename from libm/src/fpmath.h
rename to libm/fpmath.h
index 879bd7b..f3753c1 100644
--- a/libm/src/fpmath.h
+++ b/libm/fpmath.h
@@ -57,7 +57,7 @@
 		unsigned int	exp	:11;
 		unsigned int	sign	:1;
 		unsigned int	manl	:32;
-#elif  __BYTE_ORDER == __LITTLE_ENDIAN 
+#elif  __BYTE_ORDER == __LITTLE_ENDIAN
 		unsigned int	manl	:32;
 		unsigned int	manh	:20;
 		unsigned int	exp	:11;
@@ -70,3 +70,15 @@
 #endif
 	} bits;
 };
+
+/*
+ * The BSD "long double" functions are broken when sizeof(long double) == sizeof(double).
+ * Android works around those cases by replacing the broken functions with our own trivial stubs
+ * that call the regular "double" function.
+ */
+#define __fpclassifyl __broken__fpclassify
+#define __isfinitel __broken__isfinitel
+#define __isinfl __broken__isinfl
+#define __isnanl __broken__isnanl
+#define __isnormall __broken__isnormall
+#define __signbitl __broken_signbitl
diff --git a/libm/i386/_fpmath.h b/libm/i386/_fpmath.h
index 92719d9..4f1f5f4 100644
--- a/libm/i386/_fpmath.h
+++ b/libm/i386/_fpmath.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libc/i386/_fpmath.h,v 1.5 2005/03/07 04:55:22 das Exp $
+ * $FreeBSD$
  */
 
 union IEEEl2bits {
@@ -35,6 +35,11 @@
 		unsigned int	sign	:1;
 		unsigned int	junk	:16;
 	} bits;
+	struct {
+		unsigned long long man	:64;
+		unsigned int 	expsign	:16;
+		unsigned int	junk	:16;
+	} xbits;
 };
 
 #define	LDBL_NBIT	0x80000000
@@ -46,4 +51,4 @@
 #define	LDBL_TO_ARRAY32(u, a) do {			\
 	(a)[0] = (uint32_t)(u).bits.manl;		\
 	(a)[1] = (uint32_t)(u).bits.manh;		\
-} while(0)
+} while (0)
diff --git a/libm/include/complex.h b/libm/include/complex.h
new file mode 100644
index 0000000..0702541
--- /dev/null
+++ b/libm/include/complex.h
@@ -0,0 +1,92 @@
+/*-
+ * Copyright (c) 2001-2011 The FreeBSD Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _COMPLEX_H
+#define	_COMPLEX_H
+
+#include <sys/cdefs.h>
+
+#ifdef __GNUC__
+#if __STDC_VERSION__ < 199901
+#define	_Complex	__complex__
+#endif
+#define	_Complex_I	((float _Complex)1.0i)
+#endif
+
+#ifdef __generic
+_Static_assert(__generic(_Complex_I, float _Complex, 1, 0),
+    "_Complex_I must be of type float _Complex");
+#endif
+
+#define	complex		_Complex
+#define	I		_Complex_I
+
+__BEGIN_DECLS
+
+double		cabs(double complex);
+float		cabsf(float complex);
+long double	cabsl(long double complex);
+double		carg(double complex);
+float		cargf(float complex);
+long double	cargl(long double complex);
+double complex	ccos(double complex);
+float complex	ccosf(float complex);
+double complex	ccosh(double complex);
+float complex	ccoshf(float complex);
+double complex	cexp(double complex);
+float complex	cexpf(float complex);
+double		cimag(double complex) __pure2;
+float		cimagf(float complex) __pure2;
+long double	cimagl(long double complex) __pure2;
+double complex	conj(double complex) __pure2;
+float complex	conjf(float complex) __pure2;
+long double complex
+		conjl(long double complex) __pure2;
+float complex	cprojf(float complex) __pure2;
+double complex	cproj(double complex) __pure2;
+long double complex
+		cprojl(long double complex) __pure2;
+double		creal(double complex) __pure2;
+float		crealf(float complex) __pure2;
+long double	creall(long double complex) __pure2;
+double complex	csin(double complex);
+float complex	csinf(float complex);
+double complex	csinh(double complex);
+float complex	csinhf(float complex);
+double complex	csqrt(double complex);
+float complex	csqrtf(float complex);
+long double complex
+		csqrtl(long double complex);
+double complex	ctan(double complex);
+float complex	ctanf(float complex);
+double complex	ctanh(double complex);
+float complex	ctanhf(float complex);
+
+__END_DECLS
+
+#endif /* _COMPLEX_H */
diff --git a/libm/include/math.h b/libm/include/math.h
index a86a16f..b13eca9 100644
--- a/libm/include/math.h
+++ b/libm/include/math.h
@@ -11,18 +11,16 @@
 
 /*
  * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD: src/lib/msun/src/math.h,v 1.61 2005/04/16 21:12:47 das Exp $
+ * $FreeBSD$
  */
 
 #ifndef _MATH_H_
 #define	_MATH_H_
 
 #include <sys/cdefs.h>
-#include <sys/types.h>
+#include <sys/_types.h>
 #include <limits.h>
 
-#define __pure2
-
 /*
  * ANSI/POSIX
  */
@@ -36,37 +34,29 @@
 	float		__uf;
 } __nan;
 
-/* #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) */
-#if 1
+#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
 #define	__MATH_BUILTIN_CONSTANTS
 #endif
 
-/* #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER) */
-#if 1
+#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
 #define	__MATH_BUILTIN_RELOPS
 #endif
 
-/* #ifdef __MATH_BUILTIN_CONSTANTS */
-#if 1
+#ifdef __MATH_BUILTIN_CONSTANTS
 #define	HUGE_VAL	__builtin_huge_val()
 #else
 #define	HUGE_VAL	(__infinity.__ud)
 #endif
 
-/* #if __ISO_C_VISIBLE >= 1999 */
-#if 0
-#define	FP_ILOGB0	(-__INT_MAX)
-#define	FP_ILOGBNAN	__INT_MAX
-#else
-#define	FP_ILOGB0	(-INT_MAX)
-#define	FP_ILOGBNAN	INT_MAX
-#endif
+#if __ISO_C_VISIBLE >= 1999
+#define	FP_ILOGB0	(-INT_MAX) /* Android-changed */
+#define	FP_ILOGBNAN	INT_MAX /* Android-changed */
 
 #ifdef __MATH_BUILTIN_CONSTANTS
 #define	HUGE_VALF	__builtin_huge_valf()
 #define	HUGE_VALL	__builtin_huge_vall()
-#define	INFINITY	__builtin_inf()
-#define	NAN		__builtin_nan("")
+#define	INFINITY	__builtin_inff()
+#define	NAN		__builtin_nanf("")
 #else
 #define	HUGE_VALF	(float)HUGE_VAL
 #define	HUGE_VALL	(long double)HUGE_VAL
@@ -78,14 +68,11 @@
 #define	MATH_ERREXCEPT	2
 #define	math_errhandling	MATH_ERREXCEPT
 
-/* XXX We need a <machine/math.h>. */
-#if defined(__ia64__) || defined(__sparc64__)
-#define	FP_FAST_FMA
-#endif
+#define	FP_FAST_FMAF	1
 #ifdef __ia64__
-#define	FP_FAST_FMAL
+#define	FP_FAST_FMA	1
+#define	FP_FAST_FMAL	1
 #endif
-#define	FP_FAST_FMAF
 
 /* Symbolic constants to classify floating point numbers. */
 #define	FP_INFINITE	0x01
@@ -104,10 +91,10 @@
     : __isfinitel(x))
 #define	isinf(x)					\
     ((sizeof (x) == sizeof (float)) ? __isinff(x)	\
-    : (sizeof (x) == sizeof (double)) ? __isinf(x)	\
+    : (sizeof (x) == sizeof (double)) ? isinf(x)	\
     : __isinfl(x))
 #define	isnan(x)					\
-    ((sizeof (x) == sizeof (float)) ? isnanf(x)		\
+    ((sizeof (x) == sizeof (float)) ? __isnanf(x)	\
     : (sizeof (x) == sizeof (double)) ? isnan(x)	\
     : __isnanl(x))
 #define	isnormal(x)					\
@@ -137,16 +124,14 @@
     : (sizeof (x) == sizeof (double)) ? __signbit(x)	\
     : __signbitl(x))
 
-#if 0
 typedef	__double_t	double_t;
 typedef	__float_t	float_t;
-#endif 
-/* #endif */ /* __ISO_C_VISIBLE >= 1999 */
+#endif /* __ISO_C_VISIBLE >= 1999 */
 
 /*
  * XOPEN/SVID
  */
-/* #if __BSD_VISIBLE || __XSI_VISIBLE */
+#if __BSD_VISIBLE || __XSI_VISIBLE
 #define	M_E		2.7182818284590452354	/* e */
 #define	M_LOG2E		1.4426950408889634074	/* log 2e */
 #define	M_LOG10E	0.43429448190325182765	/* log 10e */
@@ -163,7 +148,7 @@
 
 #define	MAXFLOAT	((float)3.40282346638528860e+38)
 extern int signgam;
-/* #endif */ /* __BSD_VISIBLE || __XSI_VISIBLE */
+#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
 
 #if __BSD_VISIBLE
 #if 0
@@ -190,8 +175,8 @@
 int	__isfinite(double) __pure2;
 int	__isfinitel(long double) __pure2;
 int	__isinff(float) __pure2;
-int     __isinf(double) __pure2;
 int	__isinfl(long double) __pure2;
+int	__isnanf(float) __pure2;
 int	__isnanl(long double) __pure2;
 int	__isnormalf(float) __pure2;
 int	__isnormal(double) __pure2;
@@ -230,7 +215,7 @@
 /*
  * These functions are not in C90.
  */
-/* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
 double	acosh(double);
 double	asinh(double);
 double	atanh(double);
@@ -242,12 +227,13 @@
 double	fma(double, double, double);
 double	hypot(double, double);
 int	ilogb(double) __pure2;
-/* int	(isinf)(double) __pure2; */
+int	(isinf)(double) __pure2;
 int	(isnan)(double) __pure2;
 double	lgamma(double);
 long long llrint(double);
 long long llround(double);
 double	log1p(double);
+double	log2(double);
 double	logb(double);
 long	lrint(double);
 long	lround(double);
@@ -256,23 +242,26 @@
 double	remainder(double, double);
 double	remquo(double, double, int *);
 double	rint(double);
-/* #endif */ /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
+#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
 
-/* #if __BSD_VISIBLE || __XSI_VISIBLE */
+#if __BSD_VISIBLE || __XSI_VISIBLE
 double	j0(double);
 double	j1(double);
 double	jn(int, double);
-double	scalb(double, double);
 double	y0(double);
 double	y1(double);
 double	yn(int, double);
 
-/* #if __XSI_VISIBLE <= 500 || __BSD_VISIBLE */
+#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE
 double	gamma(double);
-/* #endif */
-/* #endif */ /* __BSD_VISIBLE || __XSI_VISIBLE */
+#endif
 
-/* #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 */
+#if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
+double	scalb(double, double);
+#endif
+#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
+
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
 double	copysign(double, double) __pure2;
 double	fdim(double, double);
 double	fmax(double, double) __pure2;
@@ -283,12 +272,12 @@
 double	scalbn(double, int);
 double	tgamma(double);
 double	trunc(double);
-/* #endif */
+#endif
 
 /*
  * BSD math library entry points
  */
-/* #if __BSD_VISIBLE */
+#if __BSD_VISIBLE
 double	drem(double, double);
 int	finite(double) __pure2;
 int	isnanf(float) __pure2;
@@ -304,10 +293,10 @@
  * IEEE Test Vector
  */
 double	significand(double);
-/* #endif */ /* __BSD_VISIBLE */
+#endif /* __BSD_VISIBLE */
 
 /* float versions of ANSI/POSIX functions */
-/*#if __ISO_C_VISIBLE >= 1999 */
+#if __ISO_C_VISIBLE >= 1999
 float	acosf(float);
 float	asinf(float);
 float	atanf(float);
@@ -328,6 +317,7 @@
 float	ldexpf(float, int);
 float	log10f(float);
 float	log1pf(float);
+float	log2f(float);
 float	logf(float);
 float	modff(float, float *);	/* fundamentally !__pure2 */
 
@@ -370,12 +360,12 @@
 float	fmaf(float, float, float);
 float	fmaxf(float, float) __pure2;
 float	fminf(float, float) __pure2;
-/* #endif */
+#endif
 
 /*
  * float versions of BSD math library entry points
  */
-/* #if __BSD_VISIBLE */
+#if __BSD_VISIBLE
 float	dremf(float, float);
 int	finitef(float) __pure2;
 float	gammaf(float);
@@ -399,98 +389,92 @@
  * float version of IEEE Test Vector
  */
 float	significandf(float);
-/* #endif */	/* __BSD_VISIBLE */ 
+#endif	/* __BSD_VISIBLE */
 
 /*
  * long double versions of ISO/POSIX math functions
  */
-/* #if __ISO_C_VISIBLE >= 1999 */
-#if 0
-long double	acoshl(long double);
+#if __ISO_C_VISIBLE >= 1999
 long double	acosl(long double);
-long double	asinhl(long double);
 long double	asinl(long double);
 long double	atan2l(long double, long double);
-long double	atanhl(long double);
 long double	atanl(long double);
 long double	cbrtl(long double);
-#endif
 long double	ceill(long double);
 long double	copysignl(long double, long double) __pure2;
-#if 0
-long double	coshl(long double);
 long double	cosl(long double);
-long double	erfcl(long double);
-long double	erfl(long double);
 long double	exp2l(long double);
 long double	expl(long double);
-long double	expm1l(long double);
-#endif
 long double	fabsl(long double) __pure2;
 long double	fdiml(long double, long double);
 long double	floorl(long double);
 long double	fmal(long double, long double, long double);
 long double	fmaxl(long double, long double) __pure2;
 long double	fminl(long double, long double) __pure2;
-#if 0
 long double	fmodl(long double, long double);
-#endif
 long double	frexpl(long double value, int *); /* fundamentally !__pure2 */
-#if 0
 long double	hypotl(long double, long double);
-#endif
 int		ilogbl(long double) __pure2;
 long double	ldexpl(long double, int);
-#if 0
-long double	lgammal(long double);
 long long	llrintl(long double);
-#endif
 long long	llroundl(long double);
-#if 0
-long double	log10l(long double);
-long double	log1pl(long double);
-long double	log2l(long double);
 long double	logbl(long double);
-long double	logl(long double);
 long		lrintl(long double);
-#endif
 long		lroundl(long double);
-#if 0
 long double	modfl(long double, long double *); /* fundamentally !__pure2 */
 long double	nanl(const char *) __pure2;
 long double	nearbyintl(long double);
-#endif
 long double	nextafterl(long double, long double);
 double		nexttoward(double, long double);
 float		nexttowardf(float, long double);
 long double	nexttowardl(long double, long double);
-#if 0
-long double	powl(long double, long double);
 long double	remainderl(long double, long double);
 long double	remquol(long double, long double, int *);
 long double	rintl(long double);
-#endif
 long double	roundl(long double);
 long double	scalblnl(long double, long);
 long double	scalbnl(long double, int);
-#if 0
-long double	sinhl(long double);
 long double	sinl(long double);
 long double	sqrtl(long double);
-long double	tanhl(long double);
 long double	tanl(long double);
-long double	tgammal(long double);
-#endif
 long double	truncl(long double);
 
-/* BIONIC: GLibc compatibility - required by the ARM toolchain */
-#ifdef _GNU_SOURCE
-void  sincos(double x, double *sin, double *cos);
-void  sincosf(float x, float *sin, float *cos);
-void  sincosl(long double x, long double *sin, long double *cos);
-#endif
-
-/* #endif */ /* __ISO_C_VISIBLE >= 1999 */
+#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/libm/isinf.c b/libm/isinf.c
index 2da8f58..c917f16 100644
--- a/libm/isinf.c
+++ b/libm/isinf.c
@@ -28,7 +28,7 @@
 
 #include <math.h>
 #include <sys/cdefs.h>
-#include "src/fpmath.h"
+#include "fpmath.h"
 
 /*
  * XXX These routines belong in libm, but they must remain in libc for
@@ -66,4 +66,3 @@
 	return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0);
 #endif
 }
-
diff --git a/libm/man/acos.3 b/libm/man/acos.3
deleted file mode 100644
index 9f03d60..0000000
--- a/libm/man/acos.3
+++ /dev/null
@@ -1,92 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)acos.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/acos.3,v 1.13 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt ACOS 3
-.Os
-.Sh NAME
-.Nm acos ,
-.Nm acosf
-.Nd arc cosine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn acos "double x"
-.Ft float
-.Fn acosf "float x"
-.Sh DESCRIPTION
-The
-.Fn acos
-and the
-.Fn acosf
-functions compute the principal value of the arc cosine of
-.Fa x .
-A domain error occurs for arguments not in the range
-.Bq -1 , +1 .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn acos
-and the
-.Fn acosf
-functions return the arc cosine in the range
-.Bq 0 , \*(Pi
-radians.
-If:
-.Bd -unfilled -offset indent
-.Pf \&| Ns Ar x Ns \&| > 1 ,
-.Ed
-.Pp
-.Fn acos x
-raises an invalid exception and returns an \*(Na.
-.Sh SEE ALSO
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr fenv 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn acos
-function conforms to
-.St -isoC .
diff --git a/libm/man/acosh.3 b/libm/man/acosh.3
deleted file mode 100644
index 62534ab..0000000
--- a/libm/man/acosh.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)acosh.3	5.2 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/acosh.3,v 1.11 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt ACOSH 3
-.Os
-.Sh NAME
-.Nm acosh ,
-.Nm acoshf
-.Nd inverse hyperbolic cosine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn acosh "double x"
-.Ft float
-.Fn acoshf "float x"
-.Sh DESCRIPTION
-The
-.Fn acosh
-and the
-.Fn acoshf
-functions compute the inverse hyperbolic cosine
-of the real
-argument
-.Ar x .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn acosh
-and the
-.Fn acoshf
-functions
-return the inverse hyperbolic cosine of
-.Ar x .
-If the argument is less than 1,
-.Fn acosh
-raises an invalid exception and returns an \*(Na.
-.Sh SEE ALSO
-.Xr asinh 3 ,
-.Xr atanh 3 ,
-.Xr exp 3 ,
-.Xr fenv 3 ,
-.Xr math 3
-.Sh HISTORY
-The
-.Fn acosh
-function appeared in
-.Bx 4.3 .
diff --git a/libm/man/asin.3 b/libm/man/asin.3
deleted file mode 100644
index 1018990..0000000
--- a/libm/man/asin.3
+++ /dev/null
@@ -1,94 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)asin.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/asin.3,v 1.15 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt ASIN 3
-.Os
-.Sh NAME
-.Nm asin ,
-.Nm asinf
-.Nd arc sine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn asin "double x"
-.Ft float
-.Fn asinf "float x"
-.Sh DESCRIPTION
-The
-.Fn asin
-and the
-.Fn asinf
-functions compute the principal value of the arc sine of
-.Fa x .
-A domain error occurs for arguments not in the range
-.Bq -1 , +1 .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn asin
-and the
-.Fn asinf
-functions return the arc sine in the range
-.Bk -words
-.Bq -\*(Pi/2 , +\*(Pi/2
-.Ek
-radians.
-If:
-.Bd -unfilled -offset indent
-.Pf \&| Ns Ar x Ns \&| > 1
-.Ed
-.Pp
-.Fn asin x
-raises an invalid exception and returns an \*(Na.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr fenv 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn asin
-function conforms to
-.St -isoC .
diff --git a/libm/man/asinh.3 b/libm/man/asinh.3
deleted file mode 100644
index 6a0d9a0..0000000
--- a/libm/man/asinh.3
+++ /dev/null
@@ -1,78 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)asinh.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/asinh.3,v 1.10 2001/10/13 12:23:22 bde Exp $
-.\"
-.Dd May 6, 1991
-.Dt ASINH 3
-.Os
-.Sh NAME
-.Nm asinh ,
-.Nm asinhf
-.Nd inverse hyperbolic sine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn asinh "double x"
-.Ft float
-.Fn asinhf "float x"
-.Sh DESCRIPTION
-The
-.Fn asinh
-and the
-.Fn asinhf
-functions compute the inverse hyperbolic sine
-of the real
-argument
-.Ar x .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn asinh
-and the
-.Fn asinhf
-functions
-return the inverse hyperbolic sine of
-.Ar x .
-.Sh SEE ALSO
-.Xr acosh 3 ,
-.Xr atanh 3 ,
-.Xr exp 3 ,
-.Xr math 3
-.Sh HISTORY
-The
-.Fn asinh
-function appeared in
-.Bx 4.3 .
diff --git a/libm/man/atan.3 b/libm/man/atan.3
deleted file mode 100644
index c4cefed..0000000
--- a/libm/man/atan.3
+++ /dev/null
@@ -1,84 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)atan.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/atan.3,v 1.10 2001/10/13 12:23:22 bde Exp $
-.\"
-.Dd May 2, 1991
-.Dt ATAN 3
-.Os
-.Sh NAME
-.Nm atan ,
-.Nm atanf
-.Nd arc tangent functions of one variable
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn atan "double x"
-.Ft float
-.Fn atanf "float x"
-.Sh DESCRIPTION
-The
-.Fn atan
-and the
-.Fn atanf
-functions compute the principal value of the arc tangent of
-.Fa x .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn atan
-and the
-.Fn atanf
-function returns the arc tangent in the range
-.Bk -words
-.Bq -\*(Pi/2 , +\*(Pi/2
-.Ek
-radians.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn atan
-function conforms to
-.St -isoC .
diff --git a/libm/man/atan2.3 b/libm/man/atan2.3
deleted file mode 100644
index 421e17d..0000000
--- a/libm/man/atan2.3
+++ /dev/null
@@ -1,187 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)atan2.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/atan2.3,v 1.14 2005/01/28 21:13:34 ru Exp $
-.\"
-.Dd January 14, 2005
-.Dt ATAN2 3
-.Os
-.Sh NAME
-.Nm atan2 ,
-.Nm atan2f
-.Nd arc tangent functions of two variables
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn atan2 "double y" "double x"
-.Ft float
-.Fn atan2f "float y" "float x"
-.Sh DESCRIPTION
-The
-.Fn atan2
-and the
-.Fn atan2f
-functions compute the principal value of the arc tangent of
-.Fa y/ Ns Ar x ,
-using the signs of both arguments to determine the quadrant of
-the return value.
-.Sh RETURN VALUES
-The
-.Fn atan2
-and the
-.Fn atan2f
-functions, if successful,
-return the arc tangent of
-.Fa y/ Ns Ar x
-in the range
-.Bk -words
-.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
-.Ek
-radians.
-Here are some of the special cases:
-.Bl -column atan_(y,x)_:=____  sign(y)_(Pi_atan2(Xy_xX))___
-.It Fn atan2 y x No := Ta
-.Fn atan y/x Ta
-if
-.Ar x
-> 0,
-.It Ta sign( Ns Ar y Ns )*(\*(Pi -
-.Fn atan "\\*(Bay/x\\*(Ba" ) Ta
-if
-.Ar x
-< 0,
-.It Ta
-.No 0 Ta
-if x = y = 0, or
-.It Ta
-.Pf sign( Ar y Ns )*\\*(Pi/2 Ta
-if
-.Ar x
-= 0 \(!=
-.Ar y .
-.El
-.Sh NOTES
-The function
-.Fn atan2
-defines "if x > 0,"
-.Fn atan2 0 0
-= 0 despite that previously
-.Fn atan2 0 0
-may have generated an error message.
-The reasons for assigning a value to
-.Fn atan2 0 0
-are these:
-.Bl -enum -offset indent
-.It
-Programs that test arguments to avoid computing
-.Fn atan2 0 0
-must be indifferent to its value.
-Programs that require it to be invalid are vulnerable
-to diverse reactions to that invalidity on diverse computer systems.
-.It
-The
-.Fn atan2
-function is used mostly to convert from rectangular (x,y)
-to polar
-.if n\
-(r,theta)
-.if t\
-(r,\(*h)
-coordinates that must satisfy x =
-.if n\
-r\(**cos theta
-.if t\
-r\(**cos\(*h
-and y =
-.if n\
-r\(**sin theta.
-.if t\
-r\(**sin\(*h.
-These equations are satisfied when (x=0,y=0)
-is mapped to
-.if n \
-(r=0,theta=0).
-.if t \
-(r=0,\(*h=0).
-In general, conversions to polar coordinates
-should be computed thus:
-.Bd -unfilled -offset indent
-.if n \{\
-r	:= hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
-theta	:= atan2(y,x).
-.\}
-.if t \{\
-r	:= hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
-\(*h	:= atan2(y,x).
-.\}
-.Ed
-.It
-The foregoing formulas need not be altered to cope in a
-reasonable way with signed zeros and infinities
-on a machine that conforms to
-.Tn IEEE 754 ;
-the versions of
-.Xr hypot 3
-and
-.Fn atan2
-provided for
-such a machine are designed to handle all cases.
-That is why
-.Fn atan2 \(+-0 \-0
-= \(+-\*(Pi
-for instance.
-In general the formulas above are equivalent to these:
-.Bd -unfilled -offset indent
-.if n \
-r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
-.if t \
-r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
-.Ed
-.El
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn atan2
-function conforms to
-.St -isoC .
diff --git a/libm/man/atanh.3 b/libm/man/atanh.3
deleted file mode 100644
index 3dcc01a..0000000
--- a/libm/man/atanh.3
+++ /dev/null
@@ -1,85 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)atanh.3	5.2 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/atanh.3,v 1.13 2005/01/28 21:14:16 ru Exp $
-.\"
-.Dd January 14, 2005
-.Dt ATANH 3
-.Os
-.Sh NAME
-.Nm atanh ,
-.Nm atanhf
-.Nd inverse hyperbolic tangent functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn atanh "double x"
-.Ft float
-.Fn atanhf "float x"
-.Sh DESCRIPTION
-The
-.Fn atanh
-and the
-.Fn atanhf
-functions compute the inverse hyperbolic tangent
-of the real
-argument
-.Ar x .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn atanh
-and the
-.Fn atanhf
-functions
-return the inverse hyperbolic tangent of
-.Ar x
-if successful.
-If the argument has absolute value 1, a divide-by-zero exception
-is raised and an infinity is returned.
-If
-.Ar |x|
-> 1, an invalid exception is raised and an \*(Na is returned.
-.Sh SEE ALSO
-.Xr acosh 3 ,
-.Xr asinh 3 ,
-.Xr exp 3 ,
-.Xr fenv 3 ,
-.Xr math 3
-.Sh HISTORY
-The
-.Fn atanh
-function appeared in
-.Bx 4.3 .
diff --git a/libm/man/ceil.3 b/libm/man/ceil.3
deleted file mode 100644
index 557903e..0000000
--- a/libm/man/ceil.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ceil.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/ceil.3,v 1.15 2005/01/13 20:33:42 stefanf Exp $
-.\"
-.Dd January 13, 2005
-.Dt CEIL 3
-.Os
-.Sh NAME
-.Nm ceil ,
-.Nm ceilf ,
-.Nm ceill
-.Nd smallest integral value greater than or equal to x
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn ceil "double x"
-.Ft float
-.Fn ceilf "float x"
-.Ft "long double"
-.Fn ceill "long double x"
-.Sh DESCRIPTION
-The
-.Fn ceil ,
-.Fn ceilf
-and
-.Fn ceill
-functions return the smallest integral value
-greater than or equal to
-.Fa x ,
-expressed as a floating-point number.
-.Sh SEE ALSO
-.Xr abs 3 ,
-.Xr fabs 3 ,
-.Xr floor 3 ,
-.Xr ieee 3 ,
-.Xr math 3 ,
-.Xr rint 3 ,
-.Xr round 3 ,
-.Xr trunc 3
-.Sh STANDARDS
-The
-.Fn ceil
-function conforms to
-.St -isoC .
-The
-.Fn ceilf
-and
-.Fn ceill
-functions conform to
-.St -isoC-99 .
diff --git a/libm/man/cimag.3 b/libm/man/cimag.3
deleted file mode 100644
index 069e848..0000000
--- a/libm/man/cimag.3
+++ /dev/null
@@ -1,96 +0,0 @@
-.\" Copyright (c) 2004 Stefan Farfeleder
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/cimag.3,v 1.2 2005/01/13 10:43:01 ru Exp $
-.\"
-.Dd August 7, 2004
-.Dt CIMAG 3
-.Os
-.Sh NAME
-.Nm cimag , cimagf , cimagl ,
-.Nm conj , conjf , conjl ,
-.Nm creal , crealf , creall
-.Nd "functions to manipulate complex numbers"
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In complex.h
-.Ft double
-.Fn cimag "double complex z"
-.Ft float
-.Fn cimagf "float complex z"
-.Ft "long double"
-.Fn cimagl "long double complex z"
-.Ft "double complex"
-.Fn conj "double complex z"
-.Ft "float complex"
-.Fn conjf "float complex z"
-.Ft "long double complex"
-.Fn conjl "long double complex z"
-.Ft double
-.Fn creal "double complex z"
-.Ft float
-.Fn crealf "float complex z"
-.Ft "long double"
-.Fn creall "long double complex z"
-.Sh DESCRIPTION
-Let
-.Sm off
-.Fa a + b * Em i
-.Sm on
-denote the complex number
-.Fa z .
-.Pp
-The
-.Fn cimag
-functions return the imaginary part
-.Fa b .
-.Pp
-The
-.Fn conj
-functions return the complex conjugate
-.Sm off
-.Fa a - b * Em i .
-.Sm on
-.Pp
-The
-.Fn creal
-functions return the real part
-.Fa a .
-.Sh STANDARDS
-The
-.Fn cimag ,
-.Fn conj
-and
-.Fn creal
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-The
-.Fn cimag ,
-.Fn conj
-and
-.Fn creal
-functions first appeared in
-.Fx 5.3 .
diff --git a/libm/man/copysign.3 b/libm/man/copysign.3
deleted file mode 100644
index c3ce3dc..0000000
--- a/libm/man/copysign.3
+++ /dev/null
@@ -1,90 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/copysign.3,v 1.1 2005/01/27 05:46:16 das Exp $
-.\"
-.Dd January 26, 2005
-.Dt COPYSIGN 3
-.Os
-.Sh NAME
-.Nm copysign ,
-.Nm copysignf ,
-.Nm copysignl
-.Nd copy sign
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn copysign "double x" "double y"
-.Ft float
-.Fn copysignf "float x" "float y"
-.Ft long double
-.Fn copysignl "long double x" "long double y"
-.Sh DESCRIPTION
-The
-.Fn copysign ,
-.Fn copysignf
-and
-.Fn copysignl
-functions
-return
-.Fa x
-with its sign changed to
-.Fa y Ns 's .
-.Sh SEE ALSO
-.Xr fabs 3 ,
-.Xr fdim 3 ,
-.Xr ieee 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn copysign ,
-.Fn copysignf ,
-and
-.Fn copysignl
-routines conform to
-.St -isoC-99 .
-They implement the Copysign function recommended by
-.St -ieee754 .
-.Sh HISTORY
-The
-.Fn copysign ,
-.Fn copysignf ,
-and
-.Fn copysignl
-functions appeared in
-.Bx 4.3 ,
-.Fx 2.0 ,
-and
-.Fx 5.3 ,
-respectively.
diff --git a/libm/man/cos.3 b/libm/man/cos.3
deleted file mode 100644
index 8e0bd91..0000000
--- a/libm/man/cos.3
+++ /dev/null
@@ -1,83 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)cos.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/cos.3,v 1.11 2001/10/13 12:23:23 bde Exp $
-.\"
-.Dd May 2, 1991
-.Dt COS 3
-.Os
-.Sh NAME
-.Nm cos ,
-.Nm cosf
-.Nd cosine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn cos "double x"
-.Ft float
-.Fn cosf "float x"
-.Sh DESCRIPTION
-The
-.Fn cos
-and the
-.Fn cosf
-functions compute the cosine of
-.Fa x
-(measured in radians).
-A large magnitude argument may yield a result with little or no
-significance.
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn cos
-and the
-.Fn cosf
-functions return the cosine value.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn cos
-function conforms to
-.St -isoC .
diff --git a/libm/man/cosh.3 b/libm/man/cosh.3
deleted file mode 100644
index 947c33e..0000000
--- a/libm/man/cosh.3
+++ /dev/null
@@ -1,72 +0,0 @@
-.\" Copyright (c) 1989, 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)cosh.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/cosh.3,v 1.12 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt COSH 3
-.Os
-.Sh NAME
-.Nm cosh ,
-.Nm coshf
-.Nd hyperbolic cosine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn cosh "double x"
-.Ft float
-.Fn coshf "float x"
-.Sh DESCRIPTION
-The
-.Fn cosh
-and the
-.Fn coshf
-functions compute the hyperbolic cosine of
-.Fa x .
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn cosh
-function conforms to
-.St -isoC .
diff --git a/libm/man/erf.3 b/libm/man/erf.3
deleted file mode 100644
index 824787f..0000000
--- a/libm/man/erf.3
+++ /dev/null
@@ -1,97 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)erf.3	6.4 (Berkeley) 4/20/91
-.\" $FreeBSD: src/lib/msun/man/erf.3,v 1.11 2004/07/02 23:52:20 ru Exp $
-.\"
-.Dd April 20, 1991
-.Dt ERF 3
-.Os
-.Sh NAME
-.Nm erf ,
-.Nm erff ,
-.Nm erfc ,
-.Nm erfcf
-.Nd error function operators
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn erf "double x"
-.Ft float
-.Fn erff "float x"
-.Ft double
-.Fn erfc "double x"
-.Ft float
-.Fn erfcf "float x"
-.Sh DESCRIPTION
-These functions calculate the error function of
-.Fa x .
-.Pp
-The
-.Fn erf
-and the
-.Fn erff
-functions calculate the error function of x; where
-.Bd -ragged -offset indent
-.if n \{\
-erf(x) = 2/sqrt(pi)\(**\|integral from 0 to x of exp(\-t\(**t) dt.
-\}
-.if t \{\
-erf\|(x) :=
-(2/\(sr\(*p)\|\(is\d\s8\z0\s10\u\u\s8x\s10\d\|exp(\-t\u\s82\s10\d)\|dt.
-\}
-.Ed
-.Pp
-The
-.Fn erfc
-and the
-.Fn erfcf
-functions calculate the complementary error function of
-.Fa x ;
-that is
-.Fn erfc
-subtracts the result of the error function
-.Fn erf x
-from 1.0.
-This is useful, since for large
-.Fa x
-places disappear.
-.Sh SEE ALSO
-.Xr math 3
-.Sh HISTORY
-The
-.Fn erf
-and
-.Fn erfc
-functions appeared in
-.Bx 4.3 .
diff --git a/libm/man/exp.3 b/libm/man/exp.3
deleted file mode 100644
index f6aed8f..0000000
--- a/libm/man/exp.3
+++ /dev/null
@@ -1,236 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
-.\" $FreeBSD: src/lib/msun/man/exp.3,v 1.22 2005/04/05 02:57:28 das Exp $
-.\"
-.Dd April 5, 2005
-.Dt EXP 3
-.Os
-.Sh NAME
-.Nm exp ,
-.Nm expf ,
-.\" The sorting error is intentional.  exp and expf should be adjacent.
-.Nm exp2 ,
-.Nm exp2f ,
-.Nm expm1 ,
-.Nm expm1f ,
-.Nm log ,
-.Nm logf ,
-.Nm log10 ,
-.Nm log10f ,
-.Nm log1p ,
-.Nm log1pf ,
-.Nm pow ,
-.Nm powf
-.Nd exponential, logarithm, power functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn exp "double x"
-.Ft float
-.Fn expf "float x"
-.Ft double
-.Fn exp2 "double x"
-.Ft float
-.Fn exp2f "float x"
-.Ft double
-.Fn expm1 "double x"
-.Ft float
-.Fn expm1f "float x"
-.Ft double
-.Fn log "double x"
-.Ft float
-.Fn logf "float x"
-.Ft double
-.Fn log10 "double x"
-.Ft float
-.Fn log10f "float x"
-.Ft double
-.Fn log1p "double x"
-.Ft float
-.Fn log1pf "float x"
-.Ft double
-.Fn pow "double x" "double y"
-.Ft float
-.Fn powf "float x" "float y"
-.Sh DESCRIPTION
-The
-.Fn exp
-and the
-.Fn expf
-functions compute the base
-.Ms e
-exponential value of the given argument
-.Fa x .
-.Pp
-The
-.Fn exp2
-and the
-.Fn exp2f
-functions compute the base 2 exponential of the given argument
-.Fa x .
-.Pp
-The
-.Fn expm1
-and the
-.Fn expm1f
-functions compute the value exp(x)\-1 accurately even for tiny argument
-.Fa x .
-.Pp
-The
-.Fn log
-and the
-.Fn logf
-functions compute the value of the natural logarithm of argument
-.Fa x .
-.Pp
-The
-.Fn log10
-and the
-.Fn log10f
-functions compute the value of the logarithm of argument
-.Fa x
-to base 10.
-.Pp
-The
-.Fn log1p
-and the
-.Fn log1pf
-functions compute
-the value of log(1+x) accurately even for tiny argument
-.Fa x .
-.Pp
-The
-.Fn pow
-and the
-.Fn powf
-functions compute the value
-of
-.Ar x
-to the exponent
-.Ar y .
-.Sh ERROR (due to Roundoff etc.)
-The values of
-.Fn exp 0 ,
-.Fn expm1 0 ,
-.Fn exp2 integer ,
-and
-.Fn pow integer integer
-are exact provided that they are representable.
-.\" XXX Is this really true for pow()?
-Otherwise the error in these functions is generally below one
-.Em ulp .
-.Sh RETURN VALUES
-These functions will return the appropriate computation unless an error
-occurs or an argument is out of range.
-The functions
-.Fn pow x y
-and
-.Fn powf x y
-raise an invalid exception and return an \*(Na if
-.Fa x
-< 0 and
-.Fa y
-is not an integer.
-An attempt to take the logarithm of \*(Pm0 will result in
-a divide-by-zero exception, and an infinity will be returned.
-An attempt to take the logarithm of a negative number will
-result in an invalid exception, and an \*(Na will be generated.
-.Sh NOTES
-The functions exp(x)\-1 and log(1+x) are called
-expm1 and logp1 in
-.Tn BASIC
-on the Hewlett\-Packard
-.Tn HP Ns \-71B
-and
-.Tn APPLE
-Macintosh,
-.Tn EXP1
-and
-.Tn LN1
-in Pascal, exp1 and log1 in C
-on
-.Tn APPLE
-Macintoshes, where they have been provided to make
-sure financial calculations of ((1+x)**n\-1)/x, namely
-expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
-They also provide accurate inverse hyperbolic functions.
-.Pp
-The function
-.Fn pow x 0
-returns x**0 = 1 for all x including x = 0, \*(If, and \*(Na .
-Previous implementations of pow may
-have defined x**0 to be undefined in some or all of these
-cases.
-Here are reasons for returning x**0 = 1 always:
-.Bl -enum -width indent
-.It
-Any program that already tests whether x is zero (or
-infinite or \*(Na) before computing x**0 cannot care
-whether 0**0 = 1 or not.
-Any program that depends
-upon 0**0 to be invalid is dubious anyway since that
-expression's meaning and, if invalid, its consequences
-vary from one computer system to another.
-.It
-Some Algebra texts (e.g.\& Sigler's) define x**0 = 1 for
-all x, including x = 0.
-This is compatible with the convention that accepts a[0]
-as the value of polynomial
-.Bd -literal -offset indent
-p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
-.Ed
-.Pp
-at x = 0 rather than reject a[0]\(**0**0 as invalid.
-.It
-Analysts will accept 0**0 = 1 despite that x**y can
-approach anything or nothing as x and y approach 0
-independently.
-The reason for setting 0**0 = 1 anyway is this:
-.Bd -ragged -offset indent
-If x(z) and y(z) are
-.Em any
-functions analytic (expandable
-in power series) in z around z = 0, and if there
-x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
-.Ed
-.It
-If 0**0 = 1, then
-\*(If**0 = 1/0**0 = 1 too; and
-then \*(Na**0 = 1 too because x**0 = 1 for all finite
-and infinite x, i.e., independently of x.
-.El
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr math 3
diff --git a/libm/man/fabs.3 b/libm/man/fabs.3
deleted file mode 100644
index 56b3a23..0000000
--- a/libm/man/fabs.3
+++ /dev/null
@@ -1,87 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\"	@(#)fabs.3	5.1 (Berkeley) 5/2/91
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)fabs.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/fabs.3,v 1.11 2004/07/01 18:20:57 ru Exp $
-.\"
-.Dd October 25, 2003
-.Dt FABS 3
-.Os
-.Sh NAME
-.Nm fabs ,
-.Nm fabsf ,
-.Nm fabsl
-.Nd floating-point absolute value functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn fabs "double x"
-.Ft float
-.Fn fabsf "float x"
-.Ft long double
-.Fn fabsl "long double x"
-.Sh DESCRIPTION
-The
-.Fn fabs ,
-.Fn fabsf
-and
-.Fn fabsl
-functions compute the absolute value of a floating-point number
-.Fa x .
-.Sh RETURN VALUES
-The
-.Fn fabs ,
-.Fn fabsf
-and
-.Fn fabsl
-functions return the absolute value of
-.Fa x .
-.Sh SEE ALSO
-.Xr abs 3 ,
-.Xr ceil 3 ,
-.Xr floor 3 ,
-.Xr ieee 3 ,
-.Xr math 3 ,
-.Xr rint 3
-.Sh STANDARDS
-The
-.Fn fabs
-function conforms to
-.St -isoC .
-The
-.Fn fabsf
-and
-.Fn fabsl
-functions conform to
-.St -isoC-99 .
diff --git a/libm/man/fdim.3 b/libm/man/fdim.3
deleted file mode 100644
index ca4e5ec..0000000
--- a/libm/man/fdim.3
+++ /dev/null
@@ -1,86 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fdim.3,v 1.1 2004/06/30 07:04:01 das Exp $
-.\"
-.Dd June 29, 2004
-.Dt FDIM 3
-.Os
-.Sh NAME
-.Nm fdim ,
-.Nm fdimf ,
-.Nm fdiml
-.Nd positive difference functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn fdim "double x" "double y"
-.Ft float
-.Fn fdimf "float x" "float y"
-.Ft long double
-.Fn fdiml "long double x" "long double y"
-.Sh DESCRIPTION
-The
-.Fn fdim ,
-.Fn fdimf ,
-and
-.Fn fdiml
-functions return the positive difference between
-.Fa x
-and
-.Fa y .
-That is, if
-.Fa x\- Ns Fa y
-is positive, then
-.Fa x\- Ns Fa y
-is returned.
-If either
-.Fa x
-or
-.Fa y
-is an \*(Na, then an \*(Na is returned.
-Otherwise, the result is
-.Li +0.0 .
-.Pp
-Overflow or underflow may occur iff the exact result is not
-representable in the return type.
-No other exceptions are raised.
-.Sh SEE ALSO
-.Xr fabs 3 ,
-.Xr fmax 3 ,
-.Xr fmin 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn fdim ,
-.Fn fdimf ,
-and
-.Fn fdiml
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.3 .
diff --git a/libm/man/feclearexcept.3 b/libm/man/feclearexcept.3
deleted file mode 100644
index 073de67..0000000
--- a/libm/man/feclearexcept.3
+++ /dev/null
@@ -1,139 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/feclearexcept.3,v 1.3 2005/01/14 09:12:05 ru Exp $
-.\"
-.Dd May 8, 2004
-.Dt FECLEAREXCEPT 3
-.Os
-.Sh NAME
-.Nm feclearexcept ,
-.Nm fegetexceptflag ,
-.Nm feraiseexcept ,
-.Nm fesetexceptflag ,
-.Nm fetestexcept
-.Nd floating-point exception flag manipulation
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In fenv.h
-.Fd "#pragma STDC FENV_ACCESS ON"
-.Ft int
-.Fn feclearexcept "int excepts"
-.Ft int
-.Fn fegetexceptflag "fexcept_t *flagp" "int excepts"
-.Ft int
-.Fn feraiseexcept "int excepts"
-.Ft int
-.Fn fesetexceptflag "const fexcept_t *flagp" "int excepts"
-.Ft int
-.Fn fetestexcept "int excepts"
-.Sh DESCRIPTION
-The
-.Fn feclearexcept
-routine clears the floating-point exception flags specified by
-.Fa excepts ,
-whereas
-.Fn feraiseexcept
-raises the specified exceptions.
-Raising an exception causes the corresponding flag to be set,
-and a
-.Dv SIGFPE
-is delivered to the process if the exception is unmasked.
-.Pp
-The
-.Fn fetestexcept
-function determines which flags are currently set, of those specified by
-.Fa excepts .
-.Pp
-The
-.Fn fegetexceptflag
-function stores the state of the exception flags specified in
-.Fa excepts
-in the opaque object pointed to by
-.Fa flagp .
-Similarly,
-.Fn fesetexceptflag
-changes the specified exception flags to reflect the state stored in
-the object pointed to by
-.Fa flagp .
-Note that the flags restored with
-.Fn fesetexceptflag
-must be a (not necessarily proper) subset of the flags recorded by
-a prior call to
-.Fn fegetexceptflag .
-.Pp
-For all of these functions, the possible types of exceptions
-include those described in
-.Xr fenv 3 .
-Some architectures may define other types of floating-point exceptions.
-.Sh IMPLEMENTATION NOTES
-On some architectures, raising an overflow or underflow exception
-also causes an inexact exception to be raised.
-In these cases, the overflow or underflow will be raised first.
-.Pp
-The
-.Fn fegetexceptflag
-and
-.Fn fesetexceptflag
-routines are preferred to
-.Fn fetestexcept
-and
-.Fn feraiseexcept ,
-respectively, for saving and restoring exception flags.
-The latter do not re-raise exceptions and may preserve
-architecture-specific information such as addresses where
-exceptions occurred.
-.Sh RETURN VALUES
-The
-.Fn feclearexcept ,
-.Fn fegetexceptflag ,
-.Fn feraiseexcept ,
-and
-.Fn fesetexceptflag
-functions return 0 upon success, and non-zero otherwise.
-The
-.Fn fetestexcept
-function returns the bitwise OR of the values of the current exception
-flags that were requested.
-.Sh SEE ALSO
-.Xr sigaction 2 ,
-.Xr feholdexcept 3 ,
-.Xr fenv 3 ,
-.Xr feupdateenv 3 ,
-.Xr fpgetsticky 3 ,
-.Xr fpresetsticky 3
-.Sh STANDARDS
-The
-.Fn feclearexcept ,
-.Fn fegetexceptflag ,
-.Fn feraiseexcept ,
-.Fn fesetexceptflag ,
-and
-.Fn fetestexcept
-routines conform to
-.St -isoC-99 .
-.Sh HISTORY
-These functions first appeared in
-.Fx 5.3 .
diff --git a/libm/man/feenableexcept.3 b/libm/man/feenableexcept.3
deleted file mode 100644
index 0b790e7..0000000
--- a/libm/man/feenableexcept.3
+++ /dev/null
@@ -1,98 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/feenableexcept.3,v 1.1 2005/03/16 19:04:28 das Exp $
-.\"
-.Dd March 16, 2005
-.Dt FEENABLEEXCEPT 3
-.Os
-.Sh NAME
-.Nm feenableexcept ,
-.Nm fedisableexcept ,
-.Nm fegetexcept
-.Nd floating-point exception masking
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In fenv.h
-.Fd "#pragma STDC FENV_ACCESS ON"
-.Ft int
-.Fn feenableexcept "int excepts"
-.Ft int
-.Fn fedisableexcept "int excepts"
-.Ft int
-.Fn fegetexcept "void"
-.Sh DESCRIPTION
-The
-.Fn feenableexcept
-and
-.Fn fedisableexcept
-functions
-unmask and mask (respectively) exceptions specified in
-.Fa excepts .
-The
-.Fn fegetexcept
-function
-returns the current exception mask.
-All exceptions are masked by default.
-.Pp
-Floating-point operations that produce unmasked exceptions will trap, and a
-.Dv SIGFPE
-will be delivered to the process.
-By installing a signal handler for
-.Dv SIGFPE ,
-applications can take appropriate action immediately without
-testing the exception flags after every operation.
-Note that the trap may not be immediate, but it should occur
-before the next floating-point instruction is executed.
-.Pp
-For all of these functions, the possible types of exceptions
-include those described in
-.Xr fenv 3 .
-Some architectures may define other types of floating-point exceptions.
-.Sh RETURN VALUES
-The
-.Fn feenableexcept ,
-.Fn fedisableexcept ,
-and
-.Fn fegetexcept
-functions return a bitmap of the exceptions that were unmasked
-prior to the call.
-.Sh SEE ALSO
-.Xr sigaction 2 ,
-.Xr feclearexcept 3 ,
-.Xr feholdexcept 3 ,
-.Xr fenv 3 ,
-.Xr feupdateenv 3
-.Sh BUGS
-Functions in the standard library may trigger exceptions multiple
-times as a result of intermediate computations;
-however, they generally do not trigger spurious exceptions.
-.Pp
-No interface is provided to permit exceptions to be handled in
-nontrivial ways.
-There is no uniform way for an exception handler to access
-information about the exception-causing instruction, or
-to determine whether that instruction should be reexecuted
-after returning from the handler.
diff --git a/libm/man/fegetenv.3 b/libm/man/fegetenv.3
deleted file mode 100644
index 2e386ad..0000000
--- a/libm/man/fegetenv.3
+++ /dev/null
@@ -1,113 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fegetenv.3,v 1.1 2004/06/06 10:06:26 das Exp $
-.\"
-.Dd May 8, 2004
-.Dt FEGETENV 3
-.Os
-.Sh NAME
-.Nm fegetenv ,
-.Nm feholdexcept ,
-.Nm fesetenv ,
-.Nm feupdateenv
-.Nd floating-point environment save and restore
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In fenv.h
-.Fd "#pragma STDC FENV_ACCESS ON"
-.Ft int
-.Fn fegetenv "fenv_t *envp"
-.Ft int
-.Fn feholdexcept "fenv_t *envp"
-.Ft int
-.Fn fesetenv "const fenv_t *envp"
-.Ft int
-.Fn feupdateenv "const fenv_t *envp"
-.Sh DESCRIPTION
-The floating-point environment includes exception flags and masks, the
-current rounding mode, and other architecture-specific settings.
-However, it does not include the floating-point register file.
-.Pp
-The
-.Fn fegetenv
-function stores the current floating-point environment in the object
-pointed to by
-.Fa envp ,
-whereas
-.Fn feholdexcept
-saves the current environment, then clears all exception flags
-and masks all floating-point exceptions.
-.Pp
-The
-.Fn fesetenv
-function restores a previously saved environment.
-The
-.Fn feupdateenv
-function restores a saved environment as well, but it also
-raises any exceptions that were set in the environment it
-replaces.
-.Pp
-The
-.Fn feholdexcept
-function is often used with
-.Fn feupdateenv
-or
-.Fn fesetenv
-to suppress spurious exceptions that occur as a result of
-intermediate computations.
-An example in
-.Xr fenv 3
-demonstrates how to do this.
-.Sh RETURN VALUES
-The
-.Fn fegetenv ,
-.Fn feholdexcept ,
-.Fn fesetenv ,
-and
-.Fn feupdateenv
-functions return 0 if they succeed, and non-zero otherwise.
-.Sh SEE ALSO
-.Xr feclearexcept 3 ,
-.Xr fenv 3 ,
-.Xr feraiseexcept 3 ,
-.Xr fesetenv 3 ,
-.Xr fetestexcept 3 ,
-.Xr fpgetmask 3 ,
-.Xr fpgetprec 3 ,
-.Xr fpsetmask 3 ,
-.Xr fpsetprec 3
-.Sh STANDARDS
-The
-.Fn fegetenv ,
-.Fn feholdexcept ,
-.Fn fesetenv ,
-and
-.Fn feupdateenv
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.3 .
diff --git a/libm/man/fegetround.3 b/libm/man/fegetround.3
deleted file mode 100644
index 9384158..0000000
--- a/libm/man/fegetround.3
+++ /dev/null
@@ -1,83 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fegetround.3,v 1.2 2005/01/14 09:12:05 ru Exp $
-.\"
-.Dd May 8, 2004
-.Dt FEGETROUND 3
-.Os
-.Sh NAME
-.Nm fegetround ,
-.Nm fesetround
-.Nd floating-point rounding control
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In fenv.h
-.Fd "#pragma STDC FENV_ACCESS ON"
-.Ft int
-.Fn fegetround void
-.Ft int
-.Fn fesetround "int round"
-.Sh DESCRIPTION
-The
-.Fn fegetround
-function determines the current floating-point rounding mode,
-and the
-.Fn fesetround
-function sets the current rounding mode to
-.Fa round .
-The rounding mode is one of
-.Dv FE_TONEAREST , FE_DOWNWARD , FE_UPWARD ,
-or
-.Dv FE_TOWARDZERO ,
-as described in
-.Xr fenv 3 .
-.Sh RETURN VALUES
-The
-.Fn fegetround
-routine returns the current rounding mode.
-The
-.Fn fesetround
-function returns 0 on success and non-zero otherwise;
-however, the present implementation always succeeds.
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr fpgetround 3 ,
-.Xr fpsetround 3
-.Sh STANDARDS
-The
-.Fn fegetround
-and
-.Fn fesetround
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.3 .
-They supersede the non-standard
-.Xr fpgetround 3
-and
-.Xr fpsetround 3
-functions.
diff --git a/libm/man/fenv.3 b/libm/man/fenv.3
deleted file mode 100644
index 33ad541..0000000
--- a/libm/man/fenv.3
+++ /dev/null
@@ -1,289 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fenv.3,v 1.5 2005/06/15 19:04:04 ru Exp $
-.\"
-.Dd March 16, 2005
-.Dt FENV 3
-.Os
-.Sh NAME
-.Nm feclearexcept ,
-.Nm fegetexceptflag ,
-.Nm feraiseexcept ,
-.Nm fesetexceptflag ,
-.Nm fetestexcept ,
-.Nm fegetround ,
-.Nm fesetround ,
-.Nm fegetenv ,
-.Nm feholdexcept ,
-.Nm fesetenv ,
-.Nm feupdateenv ,
-.Nm feenableexcept ,
-.Nm fedisableexcept ,
-.Nm fegetexcept
-.Nd floating-point environment control
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In fenv.h
-.Fd "#pragma STDC FENV_ACCESS ON"
-.Ft int
-.Fn feclearexcept "int excepts"
-.Ft int
-.Fn fegetexceptflag "fexcept_t *flagp" "int excepts"
-.Ft int
-.Fn feraiseexcept "int excepts"
-.Ft int
-.Fn fesetexceptflag "const fexcept_t *flagp" "int excepts"
-.Ft int
-.Fn fetestexcept "int excepts"
-.Ft int
-.Fn fegetround void
-.Ft int
-.Fn fesetround "int round"
-.Ft int
-.Fn fegetenv "fenv_t *envp"
-.Ft int
-.Fn feholdexcept "fenv_t *envp"
-.Ft int
-.Fn fesetenv "const fenv_t *envp"
-.Ft int
-.Fn feupdateenv "const fenv_t *envp"
-.Ft int
-.Fn feenableexcept "int excepts"
-.Ft int
-.Fn fedisableexcept "int excepts"
-.Ft int
-.Fn fegetexcept void
-.Sh DESCRIPTION
-The
-.In fenv.h
-routines manipulate the floating-point environment,
-which includes the exception flags and rounding modes defined in
-.St -ieee754 .
-.Ss Exceptions
-Exception flags are set as side-effects of floating-point arithmetic
-operations and math library routines, and they remain set until
-explicitly cleared.
-The following macros expand to bit flags of type
-.Vt int
-representing the five standard floating-point exceptions.
-.Bl -tag -width ".Dv FE_DIVBYZERO"
-.It Dv FE_DIVBYZERO
-A divide-by-zero exception occurs when the program attempts to
-divide a finite non-zero number by zero.
-.It Dv FE_INEXACT
-An inexact exception is raised whenever there is a loss of precision
-due to rounding.
-.It Dv FE_INVALID
-Invalid operation exceptions occur when a program attempts to
-perform calculations for which there is no reasonable representable
-answer.
-For instance, subtraction of infinities, division of zero by zero,
-ordered comparison involving \*(Nas, and taking the square root of a
-negative number are all invalid operations.
-.It Dv FE_OVERFLOW
-An overflow exception occurs when the magnitude of the result of a
-computation is too large to fit in the destination type.
-.It Dv FE_UNDERFLOW
-Underflow occurs when the result of a computation is too close to zero
-to be represented as a non-zero value in the destination type.
-.El
-.Pp
-Additionally, the
-.Dv FE_ALL_EXCEPT
-macro expands to the bitwise OR of the above flags and any
-architecture-specific flags.
-Combinations of these flags are passed to the
-.Fn feclearexcept ,
-.Fn fegetexceptflag ,
-.Fn feraiseexcept ,
-.Fn fesetexceptflag ,
-and
-.Fn fetestexcept
-functions to clear, save, raise, restore, and examine the
-processor's floating-point exception flags, respectively.
-.Pp
-Exceptions may be
-.Em unmasked
-with
-.Fn feenableexcept
-and masked with
-.Fn fedisableexcept .
-Unmasked exceptions cause a trap when they are produced, and
-all exceptions are masked by default.
-The current mask can be tested with
-.Fn fegetexcept .
-.Ss Rounding Modes
-.St -ieee754
-specifies four rounding modes.
-These modes control the direction in which results are rounded
-from their exact values in order to fit them into binary
-floating-point variables.
-The four modes correspond with the following symbolic constants.
-.Bl -tag -width ".Dv FE_TOWARDZERO"
-.It Dv FE_TONEAREST
-Results are rounded to the closest representable value.
-If the exact result is exactly half way between two representable
-values, the value whose last binary digit is even (zero) is chosen.
-This is the default mode.
-.It Dv FE_DOWNWARD
-Results are rounded towards negative \*[If].
-.It Dv FE_UPWARD
-Results are rounded towards positive \*[If].
-.It Dv FE_TOWARDZERO
-Results are rounded towards zero.
-.El
-.Pp
-The
-.Fn fegetround
-and
-.Fn fesetround
-functions query and set the rounding mode.
-.Ss Environment Control
-The
-.Fn fegetenv
-and
-.Fn fesetenv
-functions save and restore the floating-point environment,
-which includes exception flags, the current exception mask,
-the rounding mode, and possibly other implementation-specific
-state.
-The
-.Fn feholdexcept
-function behaves like
-.Fn fegetenv ,
-but with the additional effect of clearing the exception flags and
-installing a
-.Em non-stop
-mode.
-In non-stop mode, floating-point operations will set exception flags
-as usual, but no
-.Dv SIGFPE
-signals will be generated as a result.
-Non-stop mode is the default, but it may be altered by
-non-standard mechanisms.
-.\" XXX Mention fe[gs]etmask() here after the interface is finalized
-.\" XXX and ready to be officially documented.
-The
-.Fn feupdateenv
-function restores a saved environment similarly to
-.Fn fesetenv ,
-but it also re-raises any floating-point exceptions from the old
-environment.
-.Pp
-The macro
-.Dv FE_DFL_ENV
-expands to a pointer to the default environment.
-.Sh CAVEATS
-The FENV_ACCESS pragma can be enabled with
-.Dl "#pragma STDC FENV_ACCESS ON"
-and disabled with the
-.Dl "#pragma STDC FENV_ACCESS OFF"
-directive.
-This lexically-scoped annotation tells the compiler that the program
-may access the floating-point environment, so optimizations that would
-violate strict IEEE-754 semantics are disabled.
-If execution reaches a block of code for which
-.Dv FENV_ACCESS
-is off, the floating-point environment will become undefined.
-.Sh EXAMPLES
-The following routine computes the square root function.
-It explicitly raises an invalid exception on appropriate inputs using
-.Fn feraiseexcept .
-It also defers inexact exceptions while it computes intermediate
-values, and then it allows an inexact exception to be raised only if
-the final answer is inexact.
-.Bd -literal -offset indent
-#pragma STDC FENV_ACCESS ON
-double sqrt(double n) {
-	double x = 1.0;
-	fenv_t env;
-
-	if (isnan(n) || n < 0.0) {
-		feraiseexcept(FE_INVALID);
-		return (NAN);
-	}
-	if (isinf(n) || n == 0.0)
-		return (n);
-	feholdexcept(&env);
-	while (fabs((x * x) - n) > DBL_EPSILON * 2 * x)
-		x = (x / 2) + (n / (2 * x));
-	if (x * x == n)
-		feclearexcept(FE_INEXACT);
-	feupdateenv(&env);
-	return (x);
-}
-.Ed
-.Sh SEE ALSO
-.Xr cc 1 ,
-.Xr feclearexcept 3 ,
-.Xr fedisableexcept 3 ,
-.Xr feenableexcept 3 ,
-.Xr fegetenv 3 ,
-.Xr fegetexcept 3 ,
-.Xr fegetexceptflag 3 ,
-.Xr fegetround 3 ,
-.Xr feholdexcept 3 ,
-.Xr feraiseexcept 3 ,
-.Xr fesetenv 3 ,
-.Xr fesetexceptflag 3 ,
-.Xr fesetround 3 ,
-.Xr fetestexcept 3 ,
-.Xr feupdateenv 3 ,
-.Xr fpgetprec 3 ,
-.Xr fpsetprec 3
-.Sh STANDARDS
-Except as noted below,
-.In fenv.h
-conforms to
-.St -isoC-99 .
-The
-.Fn feenableexcept ,
-.Fn fedisableexcept ,
-and
-.Fn fegetexcept
-routines are extensions.
-.Sh HISTORY
-The
-.In fenv.h
-header first appeared in
-.Fx 5.3 .
-It supersedes the non-standard routines defined in
-.In ieeefp.h
-and documented in
-.Xr fpgetround 3 .
-.Sh BUGS
-The
-.Dv FENV_ACCESS
-pragma is unimplemented in the system compiler.
-However, non-constant expressions generally produce the correct
-side-effects at low optimization levels.
-.Pp
-On the Alpha platform,
-.Xr cc 1
-must be passed the
-.Fl mieee-with-inexact mfp-rounding-mode=d
-options in order to generate code that has the standard
-side-effects and uses the specified rounding modes.
diff --git a/libm/man/floor.3 b/libm/man/floor.3
deleted file mode 100644
index 1f02daf..0000000
--- a/libm/man/floor.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1985, 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)floor.3	6.5 (Berkeley) 4/19/91
-.\" $FreeBSD: src/lib/msun/man/floor.3,v 1.17 2005/01/13 09:35:47 ru Exp $
-.\"
-.Dd January 13, 2005
-.Dt FLOOR 3
-.Os
-.Sh NAME
-.Nm floor ,
-.Nm floorf ,
-.Nm floorl
-.Nd largest integral value less than or equal to x
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn floor "double x"
-.Ft float
-.Fn floorf "float x"
-.Ft "long double"
-.Fn floorl "long double x"
-.Sh DESCRIPTION
-The
-.Fn floor ,
-.Fn floorf
-and
-.Fn floorl
-functions return the largest integral value
-less than or equal to
-.Fa x ,
-expressed as a floating-point number.
-.Sh SEE ALSO
-.Xr abs 3 ,
-.Xr ceil 3 ,
-.Xr fabs 3 ,
-.Xr ieee 3 ,
-.Xr math 3 ,
-.Xr rint 3 ,
-.Xr round 3 ,
-.Xr trunc 3
-.Sh STANDARDS
-The
-.Fn floor
-function conforms to
-.St -isoC .
-The
-.Fn floorf
-and
-.Fn floorl
-functions conform to
-.St -isoC-99 .
diff --git a/libm/man/fma.3 b/libm/man/fma.3
deleted file mode 100644
index 078a6e2..0000000
--- a/libm/man/fma.3
+++ /dev/null
@@ -1,116 +0,0 @@
-.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fma.3,v 1.3 2005/11/24 09:25:10 joel Exp $
-.\"
-.Dd January 22, 2005
-.Dt FMA 3
-.Os
-.Sh NAME
-.Nm fma ,
-.Nm fmaf ,
-.Nm fmal
-.Nd fused multiply-add
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn fma "double x" "double y" "double z"
-.Ft float
-.Fn fmaf "float x" "float y" "float z"
-.Ft long double
-.Fn fmal "long double x" "long double y" "long double z"
-.Sh DESCRIPTION
-The
-.Fn fma ,
-.Fn fmaf ,
-and
-.Fn fmal
-functions return
-.No "(x * y) + z" ,
-computed with only one rounding error.
-Using the ordinary multiplication and addition operators, by contrast,
-results in two roundings: one for the intermediate product and one for
-the final result.
-.Pp
-For instance, the expression
-.No "1.2e100 * 2.0e208 - 1.4e308"
-produces \*(If due to overflow in the intermediate product, whereas
-.No "fma(1.2e100, 2.0e208, -1.4e308)"
-returns approximately 1.0e308.
-.Pp
-The fused multiply-add operation is often used to improve the
-accuracy of calculations such as dot products.
-It may also be used to improve performance on machines that implement
-it natively.
-The macros
-.Dv FP_FAST_FMA ,
-.Dv FP_FAST_FMAF
-and
-.Dv FP_FAST_FMAL
-may be defined in
-.In math.h
-to indicate that
-.Fn fma ,
-.Fn fmaf ,
-and
-.Fn fmal
-(respectively) have comparable or faster speed than a multiply
-operation followed by an add operation.
-.Sh IMPLEMENTATION NOTES
-In general, these routines will behave as one would expect if
-.No "x * y + z"
-were computed with unbounded precision and range,
-then rounded to the precision of the return type.
-However, on some platforms, if
-.Fa z
-is \*(Na, these functions may not raise an exception even
-when the computation of
-.No "x * y"
-would have otherwise generated an invalid exception.
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn fma ,
-.Fn fmaf ,
-and
-.Fn fmal
-functions conform to
-.St -isoC-99 .
-A fused multiply-add operation with virtually identical
-characteristics appears in IEEE draft standard 754R.
-.Sh HISTORY
-The
-.Fn fma
-and
-.Fn fmaf
-routines first appeared in
-.Fx 5.4 ,
-and
-.Fn fmal
-appeared in
-.Fx 6.0 .
diff --git a/libm/man/fmax.3 b/libm/man/fmax.3
deleted file mode 100644
index 03249a3..0000000
--- a/libm/man/fmax.3
+++ /dev/null
@@ -1,97 +0,0 @@
-.\" Copyright (c) 2004 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/fmax.3,v 1.2 2005/01/14 09:12:05 ru Exp $
-.\"
-.Dd June 29, 2004
-.Dt FMAX 3
-.Os
-.Sh NAME
-.Nm fmax ,
-.Nm fmaxf ,
-.Nm fmaxl ,
-.Nm fmin ,
-.Nm fminf ,
-.Nm fminl
-.Nd floating-point maximum and minimum functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn fmax "double x" "double y"
-.Ft float
-.Fn fmaxf "float x" "float y"
-.Ft "long double"
-.Fn fmaxl "long double x" "long double y"
-.Ft double
-.Fn fmin "double x" "double y"
-.Ft float
-.Fn fminf "float x" "float y"
-.Ft "long double"
-.Fn fminl "long double x" "long double y"
-.Sh DESCRIPTION
-The
-.Fn fmax ,
-.Fn fmaxf ,
-and
-.Fn fmaxl
-functions return the larger of
-.Fa x
-and
-.Fa y ,
-and likewise, the
-.Fn fmin ,
-.Fn fminf ,
-and
-.Fn fminl
-functions return the smaller of
-.Fa x
-and
-.Fa y .
-They treat
-.Li +0.0
-as being larger than
-.Li -0.0 .
-If one argument is an \*(Na, then the other argument is returned.
-If both arguments are \*(Nas, then the result is an \*(Na.
-These routines do not raise any floating-point exceptions.
-.Sh SEE ALSO
-.Xr fabs 3 ,
-.Xr fdim 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn fmax ,
-.Fn fmaxf ,
-.Fn fmaxl ,
-.Fn fmin ,
-.Fn fminf ,
-and
-.Fn fminl
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.3 .
diff --git a/libm/man/fmod.3 b/libm/man/fmod.3
deleted file mode 100644
index c0d4ed8..0000000
--- a/libm/man/fmod.3
+++ /dev/null
@@ -1,87 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)fmod.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/fmod.3,v 1.8 2001/10/13 12:23:23 bde Exp $
-.\"
-.Dd May 2, 1991
-.Dt FMOD 3
-.Os
-.Sh NAME
-.Nm fmod ,
-.Nm fmodf
-.Nd floating-point remainder functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn fmod "double x" "double y"
-.Ft float
-.Fn fmodf "float x" "float y"
-.Sh DESCRIPTION
-The
-.Fn fmod
-and the
-.Fn fmodf
-functions compute the floating-point remainder of
-.Fa x Ns / Fa y .
-.Sh RETURN VALUES
-The
-.Fn fmod
-and the
-.Fn fmodf
-functions return the value
-.Sm off
-.Fa x - Em i * Fa y ,
-.Sm on
-for some integer
-.Em i
-such that, if
-.Fa y
-is non-zero, the result has the same sign as
-.Fa x
-and magnitude less than the magnitude of
-.Fa y .
-If
-.Fa y
-is zero, whether a domain error occurs or the
-.Fn fmod
-and the
-.Fn fmodf
-function returns zero is implementation-defined.
-.Sh SEE ALSO
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn fmod
-function conforms to
-.St -isoC .
diff --git a/libm/man/hypot.3 b/libm/man/hypot.3
deleted file mode 100644
index a92a2a6..0000000
--- a/libm/man/hypot.3
+++ /dev/null
@@ -1,134 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)hypot.3	6.7 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/hypot.3,v 1.13 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt HYPOT 3
-.Os
-.Sh NAME
-.Nm hypot ,
-.Nm hypotf ,
-.Nm cabs ,
-.Nm cabsf
-.Nd Euclidean distance and complex absolute value functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn hypot "double x" "double y"
-.Ft float
-.Fn hypotf "float x" "float y"
-.In complex.h
-.Ft double
-.Fn cabs "double complex z"
-.Ft float
-.Fn cabsf "float complex z"
-.Sh DESCRIPTION
-The
-.Fn hypot
-and
-.Fn hypotf
-functions
-compute the
-sqrt(x*x+y*y)
-in such a way that underflow will not happen, and overflow
-occurs only if the final result deserves it.
-The
-.Fn cabs
-and
-.Fn cabsf
-functions compute the complex absolute value of
-.Fa z .
-.Pp
-.Fn hypot "\*(If" "v"
-=
-.Fn hypot "v" "\*(If"
-= +\*(If for all
-.Fa v ,
-including \*(Na.
-.Sh ERROR (due to Roundoff, etc.)
-Below 0.97
-.Em ulps .
-Consequently
-.Fn hypot "5.0" "12.0"
-= 13.0
-exactly;
-in general, hypot and cabs return an integer whenever an
-integer might be expected.
-.Pp
-The same cannot be said for the shorter and faster version of hypot
-and cabs that is provided in the comments in cabs.c; its error can
-exceed 1.2
-.Em ulps .
-.Sh NOTES
-As might be expected,
-.Fn hypot "v" "\*(Na"
-and
-.Fn hypot "\*(Na" "v"
-are \*(Na for all
-.Em finite
-.Fa v .
-But programmers
-might be surprised at first to discover that
-.Fn hypot "\(+-\*(If" "\*(Na"
-= +\*(If.
-This is intentional; it happens because
-.Fn hypot "\*(If" "v"
-= +\*(If
-for
-.Em all
-.Fa v ,
-finite or infinite.
-Hence
-.Fn hypot "\*(If" "v"
-is independent of
-.Fa v .
-Unlike the reserved operand fault on a
-.Tn VAX ,
-the
-.Tn IEEE
-\*(Na is designed to
-disappear when it turns out to be irrelevant, as it does in
-.Fn hypot "\*(If" "\*(Na" .
-.Sh SEE ALSO
-.Xr math 3 ,
-.Xr sqrt 3
-.Sh HISTORY
-Both a
-.Fn hypot
-function and a
-.Fn cabs
-function
-appeared in
-.At v7 .
diff --git a/libm/man/ieee.3 b/libm/man/ieee.3
deleted file mode 100644
index 3b7087d..0000000
--- a/libm/man/ieee.3
+++ /dev/null
@@ -1,448 +0,0 @@
-.\" Copyright (c) 1985 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/ieee.3,v 1.22 2005/06/16 21:55:45 ru Exp $
-.\"
-.Dd January 26, 2005
-.Dt IEEE 3
-.Os
-.Sh NAME
-.Nm ieee
-.Nd IEEE standard 754 for floating-point arithmetic
-.Sh DESCRIPTION
-The IEEE Standard 754 for Binary Floating-Point Arithmetic
-defines representations of floating-point numbers and abstract
-properties of arithmetic operations relating to precision,
-rounding, and exceptional cases, as described below.
-.Ss IEEE STANDARD 754 Floating-Point Arithmetic
-Radix: Binary.
-.Pp
-Overflow and underflow:
-.Bd -ragged -offset indent -compact
-Overflow goes by default to a signed \*(If.
-Underflow is
-.Em gradual .
-.Ed
-.Pp
-Zero is represented ambiguously as +0 or \-0.
-.Bd -ragged -offset indent -compact
-Its sign transforms correctly through multiplication or
-division, and is preserved by addition of zeros
-with like signs; but x\-x yields +0 for every
-finite x.
-The only operations that reveal zero's
-sign are division by zero and
-.Fn copysign x \(+-0 .
-In particular, comparison (x > y, x \(>= y, etc.)\&
-cannot be affected by the sign of zero; but if
-finite x = y then \*(If = 1/(x\-y) \(!= \-1/(y\-x) = \-\*(If.
-.Ed
-.Pp
-Infinity is signed.
-.Bd -ragged -offset indent -compact
-It persists when added to itself
-or to any finite number.
-Its sign transforms
-correctly through multiplication and division, and
-(finite)/\(+-\*(If\0=\0\(+-0
-(nonzero)/0 = \(+-\*(If.
-But
-\*(If\-\*(If, \*(If\(**0 and \*(If/\*(If
-are, like 0/0 and sqrt(\-3),
-invalid operations that produce \*(Na. ...
-.Ed
-.Pp
-Reserved operands (\*(Nas):
-.Bd -ragged -offset indent -compact
-An \*(Na is
-.Em ( N Ns ot Em a N Ns umber ) .
-Some \*(Nas, called Signaling \*(Nas, trap any floating-point operation
-performed upon them; they are used to mark missing
-or uninitialized values, or nonexistent elements
-of arrays.
-The rest are Quiet \*(Nas; they are
-the default results of Invalid Operations, and
-propagate through subsequent arithmetic operations.
-If x \(!= x then x is \*(Na; every other predicate
-(x > y, x = y, x < y, ...) is FALSE if \*(Na is involved.
-.Ed
-.Pp
-Rounding:
-.Bd -ragged -offset indent -compact
-Every algebraic operation (+, \-, \(**, /,
-\(sr)
-is rounded by default to within half an
-.Em ulp ,
-and when the rounding error is exactly half an
-.Em ulp
-then
-the rounded value's least significant bit is zero.
-(An
-.Em ulp
-is one
-.Em U Ns nit
-in the
-.Em L Ns ast
-.Em P Ns lace . )
-This kind of rounding is usually the best kind,
-sometimes provably so; for instance, for every
-x = 1.0, 2.0, 3.0, 4.0, ..., 2.0**52, we find
-(x/3.0)\(**3.0 == x and (x/10.0)\(**10.0 == x and ...
-despite that both the quotients and the products
-have been rounded.
-Only rounding like IEEE 754 can do that.
-But no single kind of rounding can be
-proved best for every circumstance, so IEEE 754
-provides rounding towards zero or towards
-+\*(If or towards \-\*(If
-at the programmer's option.
-.Ed
-.Pp
-Exceptions:
-.Bd -ragged -offset indent -compact
-IEEE 754 recognizes five kinds of floating-point exceptions,
-listed below in declining order of probable importance.
-.Bl -column -offset indent "Invalid Operation" "Gradual Underflow"
-.Em "Exception	Default Result"
-Invalid Operation	\*(Na, or FALSE
-Overflow	\(+-\*(If
-Divide by Zero	\(+-\*(If
-Underflow	Gradual Underflow
-Inexact	Rounded value
-.El
-.Pp
-NOTE: An Exception is not an Error unless handled
-badly.
-What makes a class of exceptions exceptional
-is that no single default response can be satisfactory
-in every instance.
-On the other hand, if a default
-response will serve most instances satisfactorily,
-the unsatisfactory instances cannot justify aborting
-computation every time the exception occurs.
-.Ed
-.Ss Data Formats
-Single-precision:
-.Bd -ragged -offset indent -compact
-Type name:
-.Vt float
-.Pp
-Wordsize: 32 bits.
-.Pp
-Precision: 24 significant bits,
-roughly like 7 significant decimals.
-.Bd -ragged -offset indent -compact
-If x and x' are consecutive positive single-precision
-numbers (they differ by 1
-.Em ulp ) ,
-then
-.Bd -ragged -compact
-5.9e\-08 < 0.5**24 < (x'\-x)/x \(<= 0.5**23 < 1.2e\-07.
-.Ed
-.Ed
-.Pp
-.Bl -column "XXX" -compact
-Range:	Overflow threshold  = 2.0**128 = 3.4e38
-	Underflow threshold = 0.5**126 = 1.2e\-38
-.El
-.Bd -ragged -offset indent -compact
-Underflowed results round to the nearest
-integer multiple of 0.5**149 = 1.4e\-45.
-.Ed
-.Ed
-.Pp
-Double-precision:
-.Bd -ragged -offset indent -compact
-Type name:
-.Vt double
-.Bd -ragged -offset indent -compact
-On some architectures,
-.Vt long double
-is the the same as
-.Vt double .
-.Ed
-.Pp
-Wordsize: 64 bits.
-.Pp
-Precision: 53 significant bits,
-roughly like 16 significant decimals.
-.Bd -ragged -offset indent -compact
-If x and x' are consecutive positive double-precision
-numbers (they differ by 1
-.Em ulp ) ,
-then
-.Bd -ragged -compact
-1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16.
-.Ed
-.Ed
-.Pp
-.Bl -column "XXX" -compact
-Range:	Overflow threshold  = 2.0**1024 = 1.8e308
-	Underflow threshold = 0.5**1022 = 2.2e\-308
-.El
-.Bd -ragged -offset indent -compact
-Underflowed results round to the nearest
-integer multiple of 0.5**1074 = 4.9e\-324.
-.Ed
-.Ed
-.Pp
-Extended-precision:
-.Bd -ragged -offset indent -compact
-Type name:
-.Vt long double
-(when supported by the hardware)
-.Pp
-Wordsize: 96 bits.
-.Pp
-Precision: 64 significant bits,
-roughly like 19 significant decimals.
-.Bd -ragged -offset indent -compact
-If x and x' are consecutive positive double-precision
-numbers (they differ by 1
-.Em ulp ) ,
-then
-.Bd -ragged -compact
-1.0e\-19 < 0.5**63 < (x'\-x)/x \(<= 0.5**62 < 2.2e\-19.
-.Ed
-.Ed
-.Pp
-.Bl -column "XXX" -compact
-Range:	Overflow threshold  = 2.0**16384 = 1.2e4932
-	Underflow threshold = 0.5**16382 = 3.4e\-4932
-.El
-.Bd -ragged -offset indent -compact
-Underflowed results round to the nearest
-integer multiple of 0.5**16445 = 5.7e\-4953.
-.Ed
-.Ed
-.Pp
-Quad-extended-precision:
-.Bd -ragged -offset indent -compact
-Type name:
-.Vt long double
-(when supported by the hardware)
-.Pp
-Wordsize: 128 bits.
-.Pp
-Precision: 113 significant bits,
-roughly like 34 significant decimals.
-.Bd -ragged -offset indent -compact
-If x and x' are consecutive positive double-precision
-numbers (they differ by 1
-.Em ulp ) ,
-then
-.Bd -ragged -compact
-9.6e\-35 < 0.5**113 < (x'\-x)/x \(<= 0.5**112 < 2.0e\-34.
-.Ed
-.Ed
-.Pp
-.Bl -column "XXX" -compact
-Range:	Overflow threshold  = 2.0**16384 = 1.2e4932
-	Underflow threshold = 0.5**16382 = 3.4e\-4932
-.El
-.Bd -ragged -offset indent -compact
-Underflowed results round to the nearest
-integer multiple of 0.5**16494 = 6.5e\-4966.
-.Ed
-.Ed
-.Ss Additional Information Regarding Exceptions
-.Pp
-For each kind of floating-point exception, IEEE 754
-provides a Flag that is raised each time its exception
-is signaled, and stays raised until the program resets
-it.
-Programs may also test, save and restore a flag.
-Thus, IEEE 754 provides three ways by which programs
-may cope with exceptions for which the default result
-might be unsatisfactory:
-.Bl -enum
-.It
-Test for a condition that might cause an exception
-later, and branch to avoid the exception.
-.It
-Test a flag to see whether an exception has occurred
-since the program last reset its flag.
-.It
-Test a result to see whether it is a value that only
-an exception could have produced.
-.Pp
-CAUTION: The only reliable ways to discover
-whether Underflow has occurred are to test whether
-products or quotients lie closer to zero than the
-underflow threshold, or to test the Underflow
-flag.
-(Sums and differences cannot underflow in
-IEEE 754; if x \(!= y then x\-y is correct to
-full precision and certainly nonzero regardless of
-how tiny it may be.)
-Products and quotients that
-underflow gradually can lose accuracy gradually
-without vanishing, so comparing them with zero
-(as one might on a VAX) will not reveal the loss.
-Fortunately, if a gradually underflowed value is
-destined to be added to something bigger than the
-underflow threshold, as is almost always the case,
-digits lost to gradual underflow will not be missed
-because they would have been rounded off anyway.
-So gradual underflows are usually
-.Em provably
-ignorable.
-The same cannot be said of underflows flushed to 0.
-.El
-.Pp
-At the option of an implementor conforming to IEEE 754,
-other ways to cope with exceptions may be provided:
-.Bl -enum
-.It
-ABORT.
-This mechanism classifies an exception in
-advance as an incident to be handled by means
-traditionally associated with error-handling
-statements like "ON ERROR GO TO ...".
-Different
-languages offer different forms of this statement,
-but most share the following characteristics:
-.Bl -dash
-.It
-No means is provided to substitute a value for
-the offending operation's result and resume
-computation from what may be the middle of an
-expression.
-An exceptional result is abandoned.
-.It
-In a subprogram that lacks an error-handling
-statement, an exception causes the subprogram to
-abort within whatever program called it, and so
-on back up the chain of calling subprograms until
-an error-handling statement is encountered or the
-whole task is aborted and memory is dumped.
-.El
-.It
-STOP.
-This mechanism, requiring an interactive
-debugging environment, is more for the programmer
-than the program.
-It classifies an exception in
-advance as a symptom of a programmer's error; the
-exception suspends execution as near as it can to
-the offending operation so that the programmer can
-look around to see how it happened.
-Quite often
-the first several exceptions turn out to be quite
-unexceptionable, so the programmer ought ideally
-to be able to resume execution after each one as if
-execution had not been stopped.
-.It
-\&... Other ways lie beyond the scope of this document.
-.El
-.Pp
-Ideally, each
-elementary function should act as if it were indivisible, or
-atomic, in the sense that ...
-.Bl -enum
-.It
-No exception should be signaled that is not deserved by
-the data supplied to that function.
-.It
-Any exception signaled should be identified with that
-function rather than with one of its subroutines.
-.It
-The internal behavior of an atomic function should not
-be disrupted when a calling program changes from
-one to another of the five or so ways of handling
-exceptions listed above, although the definition
-of the function may be correlated intentionally
-with exception handling.
-.El
-.Pp
-The functions in
-.Nm libm
-are only approximately atomic.
-They signal no inappropriate exception except possibly ...
-.Bl -tag -width indent -offset indent -compact
-.It Xo
-Over/Underflow
-.Xc
-when a result, if properly computed, might have lain barely within range, and
-.It Xo
-Inexact in
-.Fn cabs ,
-.Fn cbrt ,
-.Fn hypot ,
-.Fn log10
-and
-.Fn pow
-.Xc
-when it happens to be exact, thanks to fortuitous cancellation of errors.
-.El
-Otherwise, ...
-.Bl -tag -width indent -offset indent -compact
-.It Xo
-Invalid Operation is signaled only when
-.Xc
-any result but \*(Na would probably be misleading.
-.It Xo
-Overflow is signaled only when
-.Xc
-the exact result would be finite but beyond the overflow threshold.
-.It Xo
-Divide-by-Zero is signaled only when
-.Xc
-a function takes exactly infinite values at finite operands.
-.It Xo
-Underflow is signaled only when
-.Xc
-the exact result would be nonzero but tinier than the underflow threshold.
-.It Xo
-Inexact is signaled only when
-.Xc
-greater range or precision would be needed to represent the exact result.
-.El
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr ieee_test 3 ,
-.Xr math 3
-.Pp
-An explanation of IEEE 754 and its proposed extension p854
-was published in the IEEE magazine MICRO in August 1984 under
-the title "A Proposed Radix- and Word-length-independent
-Standard for Floating-point Arithmetic" by
-.An "W. J. Cody"
-et al.
-The manuals for Pascal, C and BASIC on the Apple Macintosh
-document the features of IEEE 754 pretty well.
-Articles in the IEEE magazine COMPUTER vol.\& 14 no.\& 3 (Mar.\&
-1981), and in the ACM SIGNUM Newsletter Special Issue of
-Oct.\& 1979, may be helpful although they pertain to
-superseded drafts of the standard.
-.Sh STANDARDS
-.St -ieee754
diff --git a/libm/man/ieee_test.3 b/libm/man/ieee_test.3
deleted file mode 100644
index debb6c8..0000000
--- a/libm/man/ieee_test.3
+++ /dev/null
@@ -1,93 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/ieee_test.3,v 1.13 2005/11/17 13:00:00 ru Exp $
-.\"
-.Dd November 6, 2005
-.Dt IEEE_TEST 3
-.Os
-.Sh NAME
-.Nm scalb ,
-.Nm scalbf ,
-.Nm significand ,
-.Nm significandf
-.Nd IEEE test functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn scalb "double x" "double n"
-.Ft float
-.Fn scalbf "float x" "float n"
-.Ft double
-.Fn significand "double x"
-.Ft float
-.Fn significandf "float x"
-.Sh DESCRIPTION
-These functions allow users to test conformance to
-.St -ieee754 .
-Their use is not otherwise recommended.
-.Pp
-.Fn scalb x n
-and
-.Fn scalbf x n
-return
-.Fa x Ns \(**(2** Ns Fa n )
-computed by exponent manipulation.
-If
-.Fa n
-is not an integer, \*(Pm\*(If, or an \*(Na, the result is unspecified.
-.Pp
-.Fn significand x
-and
-.Fn significandf x
-return
-.Fa sig ,
-where
-.Fa x
-:=
-.Fa sig No \(** 2** Ns Fa n
-with 1 \(<=
-.Fa sig
-< 2.
-.Fn significand x
-and
-.Fn significandf x
-are not defined when
-.Fa x
-is 0, \*(Pm\*(If, or \*(Na.
-.Sh SEE ALSO
-.Xr ieee 3 ,
-.Xr math 3
-.Sh STANDARDS
-.St -ieee754
diff --git a/libm/man/ilogb.3 b/libm/man/ilogb.3
deleted file mode 100644
index 00ac754..0000000
--- a/libm/man/ilogb.3
+++ /dev/null
@@ -1,127 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/ilogb.3,v 1.3 2005/11/17 13:00:00 ru Exp $
-.\"
-.Dd November 6, 2005
-.Dt ILOGB 3
-.Os
-.Sh NAME
-.Nm ilogb ,
-.Nm ilogbf ,
-.Nm ilogbl ,
-.Nm logb ,
-.Nm logbf
-.Nd extract exponent
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft int
-.Fn ilogb "double x"
-.Ft int
-.Fn ilogbf "float x"
-.Ft int
-.Fn ilogbl "long double x"
-.Ft double
-.Fn logb "double x"
-.Ft float
-.Fn logbf "float x"
-.Sh DESCRIPTION
-.Fn ilogb ,
-.Fn ilogbf
-and
-.Fn ilogbl
-return
-.Fa x Ns 's exponent
-in integer format.
-.Fn ilogb \*(Pm\*(If
-returns
-.Dv INT_MAX ,
-.Fn ilogb \*(Pm\*(Na
-returns
-.Dv FP_ILOGBNAN ,
-and
-.Fn ilogb 0
-returns
-.Dv FP_ILOGB0 .
-.Pp
-.Fn logb x
-and
-.Fn logbf x
-return
-.Fa x Ns 's exponent
-in floating\-point format with the same precision as
-.Fa x .
-.Fn logb \*(Pm\*(If
-returns +\*(If, and
-.Fn logb 0
-returns -\*(If with a division by zero exception.
-.Sh SEE ALSO
-.Xr frexp 3 ,
-.Xr ieee 3 ,
-.Xr math 3 ,
-.Xr scalbn 3
-.Sh STANDARDS
-The
-.Fn ilogb ,
-.Fn ilogbf ,
-.Fn ilogbl ,
-.Fn logb
-and
-.Fn logbf
-routines conform to
-.St -isoC-99 .
-.Fn logb
-and
-.Fn logbf
-implement the logb function recommended by
-.St -ieee754 .
-.Sh HISTORY
-The
-.Fn logb
-function appeared in
-.Bx 4.3 .
-The
-.Fn ilogb
-function appeared in
-.Fx 1.1.5 .
-The
-.Fn ilogbf
-and
-.Fn logbf
-functions appeared in
-.Fx 2.0 .
-The
-.Fn ilogbl
-function appeared in
-.Fx 5.4 .
diff --git a/libm/man/j0.3 b/libm/man/j0.3
deleted file mode 100644
index 76cd51c..0000000
--- a/libm/man/j0.3
+++ /dev/null
@@ -1,142 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)j0.3	6.7 (Berkeley) 4/19/91
-.\" $FreeBSD: src/lib/msun/man/j0.3,v 1.13 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd January 14, 2005
-.Dt J0 3
-.Os
-.Sh NAME
-.Nm j0 ,
-.Nm j0f ,
-.Nm j1 ,
-.Nm j1f ,
-.Nm jn ,
-.Nm jnf ,
-.Nm y0 ,
-.Nm y0f ,
-.Nm y1 ,
-.Nm y1f ,
-.Nm yn ,
-.Nm ynf
-.Nd Bessel functions of first and second kind
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn j0 "double x"
-.Ft float
-.Fn j0f "float x"
-.Ft double
-.Fn j1 "double x"
-.Ft float
-.Fn j1f "float x"
-.Ft double
-.Fn jn "int n" "double x"
-.Ft float
-.Fn jnf "int n" "float x"
-.Ft double
-.Fn y0 "double x"
-.Ft float
-.Fn y0f "float x"
-.Ft double
-.Fn y1 "double x"
-.Ft float
-.Fn y1f "float x"
-.Ft double
-.Fn yn "int n" "double x"
-.Ft float
-.Fn ynf "int n" "float x"
-.Sh DESCRIPTION
-The functions
-.Fn j0 ,
-.Fn j0f ,
-.Fn j1
-and
-.Fn j1f
-compute the
-.Em Bessel function of the first kind of the order
-0 and the
-.Em order
-1, respectively,
-for the
-real value
-.Fa x ;
-the functions
-.Fn jn
-and
-.Fn jnf
-compute the
-.Em Bessel function of the first kind of the integer
-.Em order
-.Fa n
-for the real value
-.Fa x .
-.Pp
-The functions
-.Fn y0 ,
-.Fn y0f ,
-.Fn y1 ,
-and
-.Fn y1f
-compute the linearly independent
-.Em Bessel function of the second kind of the order
-0 and the
-.Em order
-1, respectively,
-for the
-positive
-.Em real
-value
-.Fa x ;
-the functions
-.Fn yn
-and
-.Fn ynf
-compute the
-.Em Bessel function of the second kind for the integer
-.Em order
-.Fa n
-for the positive
-.Em real
-value
-.Fa x .
-.Sh RETURN VALUES
-If these functions are successful,
-the computed value is returned.
-.Sh SEE ALSO
-.Xr math 3
-.Sh HISTORY
-This set of functions
-appeared in
-.At v7 .
diff --git a/libm/man/lgamma.3 b/libm/man/lgamma.3
deleted file mode 100644
index 0064a48..0000000
--- a/libm/man/lgamma.3
+++ /dev/null
@@ -1,185 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)lgamma.3	6.6 (Berkeley) 12/3/92
-.\" $FreeBSD: src/lib/msun/man/lgamma.3,v 1.22 2005/01/16 16:46:14 ru Exp $
-.\"
-.Dd January 14, 2005
-.Dt LGAMMA 3
-.Os
-.Sh NAME
-.Nm lgamma ,
-.Nm lgamma_r ,
-.Nm lgammaf ,
-.Nm lgammaf_r ,
-.Nm gamma ,
-.Nm gamma_r ,
-.Nm gammaf ,
-.Nm gammaf_r ,
-.Nm tgamma
-.Nd log gamma functions, gamma function
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft extern int
-.Fa signgam ;
-.sp
-.Ft double
-.Fn lgamma "double x"
-.Ft double
-.Fn lgamma_r "double x" "int *signgamp"
-.Ft float
-.Fn lgammaf "float x"
-.Ft float
-.Fn lgammaf_r "float x" "int *signgamp"
-.Ft double
-.Fn gamma "double x"
-.Ft double
-.Fn gamma_r "double x" "int *signgamp"
-.Ft float
-.Fn gammaf "float x"
-.Ft float
-.Fn gammaf_r "float x" "int *signgamp"
-.Ft double
-.Fn tgamma "double x"
-.Sh DESCRIPTION
-.Fn lgamma x
-and
-.Fn lgammaf x
-.if t \{\
-return ln\||\(*G(x)| where
-.Bd -unfilled -offset indent
-\(*G(x) = \(is\d\s8\z0\s10\u\u\s8\(if\s10\d t\u\s8x\-1\s10\d e\u\s8\-t\s10\d dt	for x > 0 and
-\(*G(x) = \(*p/(\(*G(1\-x)\|sin(\(*px))	for x < 1.
-.Ed
-.\}
-.if n \
-return ln\||\(*G(x)|.
-.Pp
-The external integer
-.Fa signgam
-returns the sign of \(*G(x).
-.Pp
-.Fn lgamma_r x signgamp
-and
-.Fn lgammaf_r x signgamp
-provide the same functionality as
-.Fn lgamma x
-and
-.Fn lgammaf x
-but the caller must provide an integer to store the sign of \(*G(x).
-.Pp
-.Fn gamma ,
-.Fn gammaf ,
-.Fn gamma_r ,
-and
-.Fn gammaf_r
-are deprecated aliases for
-.Fn lgamma ,
-.Fn lgammaf ,
-.Fn lgamma_r ,
-and
-.Fn lgammaf_r ,
-respectively.
-.Fn tgamma x
-returns \(*G(x), with no effect on
-.Fa signgam .
-.Sh IDIOSYNCRASIES
-Do not use the expression
-.Dq Li signgam\(**exp(lgamma(x))
-to compute g := \(*G(x).
-Instead use a program like this (in C):
-.Bd -literal -offset indent
-lg = lgamma(x); g = signgam\(**exp(lg);
-.Ed
-.Pp
-Only after
-.Fn lgamma
-or
-.Fn lgammaf
-has returned can signgam be correct.
-.Pp
-For arguments in its range,
-.Fn tgamma
-is preferred, as for positive arguments
-it is accurate to within one unit in the last place.
-Exponentiation of
-.Fn lgamma
-will lose up to 10 significant bits.
-.Sh RETURN VALUES
-.Fn gamma ,
-.Fn gamma_r ,
-.Fn gammaf ,
-.Fn gammaf_r ,
-.Fn lgamma ,
-.Fn lgamma_r ,
-.Fn lgammaf ,
-and
-.Fn lgammaf_r
-return appropriate values unless an argument is out of range.
-Overflow will occur for sufficiently large positive values, and
-non-positive integers.
-For large non-integer negative values,
-.Fn tgamma
-will underflow.
-.Sh SEE ALSO
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn lgamma
-and
-.Fn tgamma
-functions are expected to conform to
-.St -isoC-99 .
-.Sh HISTORY
-The
-.Fn lgamma
-function appeared in
-.Bx 4.3 .
-The
-.Fn gamma
-function appeared in
-.Bx 4.4
-as a function which computed \(*G(x).
-This version was used in
-.Fx 1.1 .
-The name
-.Fn gamma
-was originally dedicated to the
-.Fn lgamma
-function,
-and that usage was restored by switching to Sun's fdlibm in
-.Fx 1.1.5 .
-The
-.Fn tgamma
-function appeared in
-.Fx 5.0 .
diff --git a/libm/man/lrint.3 b/libm/man/lrint.3
deleted file mode 100644
index d7de093..0000000
--- a/libm/man/lrint.3
+++ /dev/null
@@ -1,94 +0,0 @@
-.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/lrint.3,v 1.2 2005/01/13 10:43:01 ru Exp $
-.\"
-.Dd January 11, 2005
-.Dt LRINT 3
-.Os
-.Sh NAME
-.Nm llrint ,
-.Nm llrintf ,
-.Nm lrint ,
-.Nm lrintf
-.Nd "convert to integer"
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft "long long"
-.Fn llrint "double x"
-.Ft "long long"
-.Fn llrintf "float x"
-.Ft long
-.Fn lrint "double x"
-.Ft long
-.Fn lrintf "float x"
-.Sh DESCRIPTION
-The
-.Fn lrint
-function returns the integer nearest to its argument
-.Fa x
-according to the current rounding mode.
-If the rounded result is too large to be represented as a
-.Vt long
-value, an invalid exception is raised and the return value is undefined.
-Otherwise, if
-.Fa x
-is not an integer,
-.Fn lrint
-raises an inexact exception.
-When the rounded result is representable as a
-.Vt long ,
-the expression
-.Fn lrint x
-is equivalent to
-.Po Vt long Pc Ns Fn rint x
-(although the former may be more efficient).
-.Pp
-The
-.Fn llrint ,
-.Fn llrintf ,
-and
-.Fn lrintf
-functions differ from
-.Fn lrint
-only in their input and output types.
-.Sh SEE ALSO
-.Xr lround 3 ,
-.Xr math 3 ,
-.Xr rint 3 ,
-.Xr round 3
-.Sh STANDARDS
-The
-.Fn llrint ,
-.Fn llrintf ,
-.Fn lrint ,
-and
-.Fn lrintf
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.4 .
diff --git a/libm/man/lround.3 b/libm/man/lround.3
deleted file mode 100644
index d3e53c2..0000000
--- a/libm/man/lround.3
+++ /dev/null
@@ -1,112 +0,0 @@
-.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/lround.3,v 1.4 2005/06/15 19:04:04 ru Exp $
-.\"
-.Dd April 7, 2005
-.Dt LROUND 3
-.Os
-.Sh NAME
-.Nm llround ,
-.Nm llroundf ,
-.Nm llroundl ,
-.Nm lround ,
-.Nm lroundf ,
-.Nm lroundl
-.Nd "convert to nearest integral value"
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft "long long"
-.Fn llround "double x"
-.Ft "long long"
-.Fn llroundf "float x"
-.Ft "long long"
-.Fn llroundl "long double x"
-.Ft long
-.Fn lround "double x"
-.Ft long
-.Fn lroundf "float x"
-.Ft long
-.Fn lroundl "long double x"
-.Sh DESCRIPTION
-The
-.Fn lround
-function returns the integer nearest to its argument
-.Fa x ,
-rounding away from zero in halfway cases.
-If the rounded result is too large to be represented as a
-.Vt long
-value, an invalid exception is raised and the return value is undefined.
-Otherwise, if
-.Fa x
-is not an integer,
-.Fn lround
-may raise an inexact exception.
-When the rounded result is representable as a
-.Vt long ,
-the expression
-.Fn lround x
-is equivalent to
-.Po Vt long Pc Ns Fn round x
-(although the former may be more efficient).
-.Pp
-The
-.Fn llround ,
-.Fn llroundf ,
-.Fn llroundl ,
-.Fn lroundf
-and
-.Fn lroundl
-functions differ from
-.Fn lround
-only in their input and output types.
-.Sh SEE ALSO
-.Xr lrint 3 ,
-.Xr math 3 ,
-.Xr rint 3 ,
-.Xr round 3
-.Sh STANDARDS
-The
-.Fn llround ,
-.Fn llroundf ,
-.Fn llroundl ,
-.Fn lround ,
-.Fn lroundf ,
-and
-.Fn lroundl
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-The
-.Vt float
-and
-.Vt double
-versions of these routines first appeared in
-.Fx 5.4 .
-The
-.Vt "long double"
-versions appeared in
-.Fx 6.0 .
diff --git a/libm/man/math.3 b/libm/man/math.3
deleted file mode 100644
index 828b5e0..0000000
--- a/libm/man/math.3
+++ /dev/null
@@ -1,242 +0,0 @@
-.\" Copyright (c) 1985 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"	from: @(#)math.3	6.10 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/math.3,v 1.27 2005/11/17 13:00:00 ru Exp $
-.\"
-.Dd November 6, 2005
-.Dt MATH 3
-.Os
-.if n \{\
-.char \[sr] "sqrt
-.\}
-.Sh NAME
-.Nm math
-.Nd "floating-point mathematical library"
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Sh DESCRIPTION
-These functions constitute the C math library.
-.Sh "LIST OF FUNCTIONS"
-Each of the following
-.Vt double
-functions has a
-.Vt float
-counterpart with an
-.Ql f
-appended to the name and a
-.Vt "long double"
-counterpart with an
-.Ql l
-appended.
-As an example, the
-.Vt float
-and
-.Vt "long double"
-counterparts of
-.Ft double
-.Fn acos "double x"
-are
-.Ft float
-.Fn acosf "float x"
-and
-.Ft "long double"
-.Fn acosl "long double x" ,
-respectively.
-.de Cl
-.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0"
-.Em "Name	Description"
-..
-.Ss Algebraic Functions
-.Cl
-cbrt	cube root
-fma	fused multiply-add
-hypot	Euclidean distance
-sqrt	square root
-.El
-.Ss Classification Functions
-.Cl
-fpclassify	classify a floating-point value
-isfinite	determine whether a value is finite
-isinf	determine whether a value is infinite
-isnan	determine whether a value is \*(Na
-isnormal	determine whether a value is normalized
-.El
-.Ss Exponent Manipulation Functions
-.Cl
-frexp	extract exponent and mantissa
-ilogb	extract exponent
-ldexp	multiply by power of 2
-logb	extract exponent
-scalbln	adjust exponent
-scalbn	adjust exponent
-.El
-.Ss Extremum- and Sign-Related Functions
-.Cl
-copysign	copy sign bit
-fabs	absolute value
-fdim	positive difference
-fmax	maximum function
-fmin	minimum function
-signbit	extract sign bit
-.El
-.\" .Ss Not a Number
-.\" .Cl
-.\" nan	return quiet \*(Na)	0
-.\" .El
-.Ss Residue and Rounding Functions
-.Cl
-ceil	integer no less than
-floor	integer no greater than
-fmod	positive remainder
-llrint	round to integer in fixed-point format
-llround	round to nearest integer in fixed-point format
-lrint	round to integer in fixed-point format
-lround	round to nearest integer in fixed-point format
-modf	extract integer and fractional parts
-nearbyint	round to integer (silent)
-nextafter	next representable value
-nexttoward	next representable value
-remainder	remainder
-remquo	remainder with partial quotient
-rint	round to integer
-round	round to nearest integer
-trunc	integer no greater in magnitude than
-.El
-.Pp
-The
-.Fn ceil ,
-.Fn floor ,
-.Fn llround ,
-.Fn lround ,
-.Fn round ,
-and
-.Fn trunc
-functions round in predetermined directions, whereas
-.Fn llrint ,
-.Fn lrint ,
-and
-.Fn rint
-round according to the current (dynamic) rounding mode.
-For more information on controlling the dynamic rounding mode, see
-.Xr fenv 3
-and
-.Xr fesetround 3 .
-.Ss Silent Order Predicates
-.Cl
-isgreater	greater than relation
-isgreaterequal	greater than or equal to relation
-isless	less than relation
-islessequal	less than or equal to relation
-islessgreater	less than or greater than relation
-isunordered	unordered relation
-.El
-.Ss Transcendental Functions
-.Cl
-acos	inverse cosine
-acosh	inverse hyperbolic cosine
-asin	inverse sine
-asinh	inverse hyperbolic sine
-atan	inverse tangent
-atanh	inverse hyperbolic tangent
-atan2	atan(y/x); complex argument
-cos	cosine
-cosh	hyperbolic cosine
-erf	error function
-erfc	complementary error function
-exp	exponential base e
-exp2	exponential base 2
-expm1	exp(x)\-1
-j0	Bessel function of the first kind of the order 0
-j1	Bessel function of the first kind of the order 1
-jn	Bessel function of the first kind of the order n
-lgamma	log gamma function
-log	natural logarithm
-log10	logarithm to base 10
-log1p	log(1+x)
-.\" log2	base 2 logarithm
-pow	exponential x**y
-sin	trigonometric function
-sinh	hyperbolic function
-tan	trigonometric function
-tanh	hyperbolic function
-tgamma	gamma function
-y0	Bessel function of the second kind of the order 0
-y1	Bessel function of the second kind of the order 1
-yn	Bessel function of the second kind of the order n
-.El
-.Pp
-Unlike the algebraic functions listed earlier, the routines
-in this section may not produce a result that is correctly rounded,
-so reproducible results cannot be guaranteed across platforms.
-For most of these functions, however, incorrect rounding occurs
-rarely, and then only in very-close-to-halfway cases.
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr ieee 3
-.Sh HISTORY
-A math library with many of the present functions appeared in
-.At v7 .
-The library was substantially rewritten for
-.Bx 4.3
-to provide
-better accuracy and speed on machines supporting either VAX
-or IEEE 754 floating-point.
-Most of this library was replaced with FDLIBM, developed at Sun
-Microsystems, in
-.Fx 1.1.5 .
-Additional routines, including ones for
-.Vt float
-and
-.Vt long double
-values, were written for or imported into subsequent versions of FreeBSD.
-.Sh BUGS
-The
-.Fn log2
-and
-.Fn nan
-functions are missing, and many functions are not available in their
-.Vt "long double"
-variants.
-.Pp
-Many of the routines to compute transcendental functions produce
-inaccurate results in other than the default rounding mode.
-.Pp
-On some architectures, trigonometric argument reduction is not
-performed accurately, resulting in errors greater than 1
-.Em ulp
-for large arguments to
-.Fn cos ,
-.Fn sin ,
-and
-.Fn tan .
diff --git a/libm/man/nextafter.3 b/libm/man/nextafter.3
deleted file mode 100644
index 1c94fb7..0000000
--- a/libm/man/nextafter.3
+++ /dev/null
@@ -1,100 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/nextafter.3,v 1.2 2005/03/07 05:00:29 das Exp $
-.\"
-.Dd May 4, 2005
-.Dt NEXTAFTER 3
-.Os
-.Sh NAME
-.Nm nextafter ,
-.Nm nextafterf ,
-.Nm nextafterl ,
-.Nm nexttoward ,
-.Nm nexttowardf ,
-.Nm nexttowardl
-.Nd next representable value
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn nextafter "double x" "double y"
-.Ft float
-.Fn nextafterf "float x" "float y"
-.Ft long double
-.Fn nextafterl "long double x" "long double y"
-.Ft double
-.Fn nexttoward "double x" "long double y"
-.Ft float
-.Fn nexttowardf "float x" "long double y"
-.Ft long double
-.Fn nexttowardl "long double x" "long double y"
-.Sh DESCRIPTION
-These functions
-return the next machine representable number from
-.Fa x
-in direction
-.Fa y .
-.Sh SEE ALSO
-.Xr ieee 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn nextafter ,
-.Fn nextafterf ,
-.Fn nextafterl ,
-.Fn nexttoward ,
-.Fn nexttowardf ,
-and
-.Fn nexttowardl
-routines conform to
-.St -isoC-99 .
-They implement the Nextafter function recommended by
-.St -ieee754 ,
-with the extension that
-.Fn nextafter +0.0, -0.0
-returns
-.Li -0.0 ,
-and
-.Fn nextafter -0.0, +0.0
-returns
-.Li +0.0 .
-.Sh HISTORY
-The
-.Fn nextafter
-function appeared in
-.Bx 4.3 ,
-and
-.Fn nextafterf
-appeared in
-.Fx 2.0 .
diff --git a/libm/man/remainder.3 b/libm/man/remainder.3
deleted file mode 100644
index 9b621e3..0000000
--- a/libm/man/remainder.3
+++ /dev/null
@@ -1,146 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/remainder.3,v 1.4 2005/11/24 09:25:10 joel Exp $
-.\"
-.Dd March 24, 2005
-.Dt REMAINDER 3
-.Os
-.Sh NAME
-.Nm remainder ,
-.Nm remainderf ,
-.Nm remquo ,
-.Nm remquof
-.Nd minimal residue functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn remainder "double x" "double y"
-.Ft float
-.Fn remainderf "float x" "float y"
-.Ft double
-.Fn remquo "double x" "double y" "int *quo"
-.Ft float
-.Fn remquof "float x" "float y" "int *quo"
-.Sh DESCRIPTION
-.Fn remainder ,
-.Fn remainderf ,
-.Fn remquo ,
-and
-.Fn remquof
-return the remainder
-.Fa r
-:=
-.Fa x
-\-
-.Fa n\(**y
-where
-.Fa n
-is the integer nearest the exact value of
-.Bk -words
-.Fa x Ns / Ns Fa y ;
-.Ek
-moreover if
-.Pf \\*(Ba Fa n
-\-
-.Sm off
-.Fa x No / Fa y No \\*(Ba
-.Sm on
-=
-1/2
-then
-.Fa n
-is even.
-Consequently
-the remainder is computed exactly and
-.Sm off
-.Pf \\*(Ba Fa r No \\*(Ba
-.Sm on
-\*(Le
-.Sm off
-.Pf \\*(Ba Fa y No \\*(Ba/2 .
-.Sm on
-But attempting to take the remainder when
-.Fa y
-is 0 or
-.Fa x
-is \*(Pm\*(If is an invalid operation that produces a \*(Na.
-.Pp
-The
-.Fn remquo
-and
-.Fn remquof
-functions also store the last
-.Va k
-bits of
-.Fa n
-in the location pointed to by
-.Fa quo ,
-provided that
-.Fa n
-exists.
-The number of bits
-.Va k
-is platform-specific, but is guaranteed to be at least 3.
-.Sh SEE ALSO
-.Xr fmod 3 ,
-.Xr ieee 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn remainder ,
-.Fn remainderf ,
-.Fn remquo ,
-and
-.Fn remquof
-routines conform to
-.St -isoC-99 .
-The remainder is as defined in
-.St -ieee754 .
-.Sh HISTORY
-The
-.Fn remainder
-and
-.Fn remainderf
-functions appeared in
-.Bx 4.3
-and
-.Fx 2.0 ,
-respectively.
-The
-.Fn remquo
-and
-.Fn remquof
-functions were added in
-.Fx 6.0 .
diff --git a/libm/man/rint.3 b/libm/man/rint.3
deleted file mode 100644
index ee55fea..0000000
--- a/libm/man/rint.3
+++ /dev/null
@@ -1,103 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)rint.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/rint.3,v 1.11 2005/01/11 23:12:17 das Exp $
-.\"
-.Dd July 5, 2004
-.Dt RINT 3
-.Os
-.Sh NAME
-.Nm nearbyint ,
-.Nm nearbyintf ,
-.Nm rint ,
-.Nm rintf
-.Nd round to integral value in floating-point format
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn nearbyint "double x"
-.Ft float
-.Fn nearbyintf "float x"
-.Ft double
-.Fn rint "double x"
-.Ft float
-.Fn rintf "float x"
-.Sh DESCRIPTION
-The
-.Fn rint
-and the
-.Fn rintf
-functions return the integral value nearest to
-.Fa x
-according to the prevailing rounding mode.
-These functions raise an inexact exception when the original argument
-is not an exact integer.
-.Pp
-The
-.Fn nearbyint
-and
-.Fn nearbyintf
-functions perform the same operation, except that they do not raise
-an inexact exception.
-.Sh SEE ALSO
-.Xr abs 3 ,
-.Xr ceil 3 ,
-.Xr fabs 3 ,
-.Xr fenv 3 ,
-.Xr floor 3 ,
-.Xr ieee 3 ,
-.Xr lrint 3 ,
-.Xr lround 3 ,
-.Xr math 3 ,
-.Xr round 3
-.Sh STANDARDS
-The
-.Fn nearbyint ,
-.Fn nearbyintf ,
-.Fn rint ,
-and
-.Fn rintf
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-A
-.Fn rint
-function appeared in
-.At v6 .
-The
-.Fn nearbyint
-and
-.Fn nearbyintf
-functions appeared in
-.Fx 5.3 .
diff --git a/libm/man/round.3 b/libm/man/round.3
deleted file mode 100644
index b077d77..0000000
--- a/libm/man/round.3
+++ /dev/null
@@ -1,80 +0,0 @@
-.\" Copyright (c) 2003, Steven G. Kargl
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/round.3,v 1.6 2005/06/15 19:04:04 ru Exp $
-.\"
-.Dd April 7, 2005
-.Dt ROUND 3
-.Os
-.Sh NAME
-.Nm round ,
-.Nm roundf ,
-.Nm roundl
-.Nd round to nearest integral value
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn round "double x"
-.Ft float
-.Fn roundf "float x"
-.Ft "long double"
-.Fn roundl "long double x"
-.Sh DESCRIPTION
-The
-.Fn round ,
-.Fn roundf ,
-and
-.Fn roundl
-functions return the nearest integral value to
-.Fa x ;
-if
-.Fa x
-lies halfway between two integral values, then these
-functions return the integral value with the larger
-absolute value (i.e., they round away from zero).
-.Sh SEE ALSO
-.Xr ceil 3 ,
-.Xr floor 3 ,
-.Xr ieee 3 ,
-.Xr lrint 3 ,
-.Xr lround 3 ,
-.Xr math 3 ,
-.Xr rint 3 ,
-.Xr trunc 3
-.Sh STANDARDS
-These functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-The
-.Fn round
-and
-.Fn roundf
-functions appeared in
-.Fx 5.3 .
-The
-.Fn roundl
-function appeared in
-.Fx 6.0 .
diff --git a/libm/man/scalbn.3 b/libm/man/scalbn.3
deleted file mode 100644
index 923caab..0000000
--- a/libm/man/scalbn.3
+++ /dev/null
@@ -1,95 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)ieee.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/scalbn.3,v 1.3 2005/11/24 09:25:10 joel Exp $
-.\"
-.Dd March 4, 2005
-.Dt SCALBN 3
-.Os
-.Sh NAME
-.Nm scalbln ,
-.Nm scalblnf ,
-.Nm scalblnl ,
-.Nm scalbn ,
-.Nm scalbnf ,
-.Nm scalbnl
-.Nd adjust exponent
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn scalbln "double x" "long n"
-.Ft float
-.Fn scalblnf "float x" "long n"
-.Ft long double
-.Fn scalblnl "long double x" "long n"
-.Ft double
-.Fn scalbn "double x" "int n"
-.Ft float
-.Fn scalbnf "float x" "int n"
-.Ft long double
-.Fn scalbnl "long double x" "int n"
-.Sh DESCRIPTION
-These routines return
-.Fa x Ns \(**(2** Ns Fa n )
-computed by exponent manipulation.
-.Sh SEE ALSO
-.Xr ieee 3 ,
-.Xr math 3
-.Sh STANDARDS
-These routines conform to
-.St -isoC-99 ,
-and they implement the Scalb function recommended by
-.St -ieee754 .
-.Sh HISTORY
-The
-.Fn scalbn
-and
-.Fn scalbnf
-functions appeared in
-.Bx 4.3
-and
-.Fx 2.0 ,
-respectively.
-The
-.Fn scalbln
-and
-.Fn scalblnf
-functions first appeared in
-.Fx 5.3 ,
-and
-.Fn scalblnl
-and
-.Fn scalbln
-in
-.Fx 6.0 .
diff --git a/libm/man/signbit.3 b/libm/man/signbit.3
deleted file mode 100644
index b749671..0000000
--- a/libm/man/signbit.3
+++ /dev/null
@@ -1,57 +0,0 @@
-.\" Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/signbit.3,v 1.1 2004/07/19 08:16:10 das Exp $
-.\"
-.Dd July 18, 2004
-.Dt SIGNBIT 3
-.Os
-.Sh NAME
-.Nm signbit
-.Nd "determine whether a floating-point number's sign is negative"
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft int
-.Fn signbit "real-floating x"
-.Sh DESCRIPTION
-The
-.Fn signbit
-macro takes an argument of
-.Fa x
-and returns non-zero if the value of its sign is negative, otherwise 0.
-.Sh SEE ALSO
-.Xr fpclassify 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn signbit
-macro conforms to
-.St -isoC-99 .
-.Sh HISTORY
-The
-.Fn signbit
-macro was added in
-.Fx 5.1 .
diff --git a/libm/man/sin.3 b/libm/man/sin.3
deleted file mode 100644
index 3a408a7..0000000
--- a/libm/man/sin.3
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\"	@(#)sin.3	6.7 (Berkeley) 4/19/91
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)sin.3	6.7 (Berkeley) 4/19/91
-.\" $FreeBSD: src/lib/msun/man/sin.3,v 1.9 2001/10/13 12:23:23 bde Exp $
-.\"
-.Dd April 19, 1991
-.Dt SIN 3
-.Os
-.Sh NAME
-.Nm sin ,
-.Nm sinf
-.Nd sine functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn sin "double x"
-.Ft float
-.Fn sinf "float x"
-.Sh DESCRIPTION
-The
-.Fn sin
-and the
-.Fn sinf
-functions compute the sine of
-.Fa x
-(measured in radians).
-A large magnitude argument may yield a result with little
-or no significance.
-.Sh RETURN VALUES
-The
-.Fn sin
-and the
-.Fn sinf
-functions return the sine value.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sinh 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn sin
-function conforms to
-.St -isoC .
diff --git a/libm/man/sinh.3 b/libm/man/sinh.3
deleted file mode 100644
index 8347862..0000000
--- a/libm/man/sinh.3
+++ /dev/null
@@ -1,71 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"	from: @(#)sinh.3	6.6 (Berkeley) 4/19/91
-.\" $FreeBSD: src/lib/msun/man/sinh.3,v 1.12 2005/01/14 23:28:28 das Exp $
-.Dd January 14, 2005
-.Dt SINH 3
-.Os
-.Sh NAME
-.Nm sinh ,
-.Nm sinhf
-.Nd hyperbolic sine function
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn sinh "double x"
-.Ft float
-.Fn sinhf "float x"
-.Sh DESCRIPTION
-The
-.Fn sinh
-and the
-.Fn sinhf
-functions compute the hyperbolic sine of
-.Fa x .
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr tan 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn sinh
-function conforms to
-.St -isoC .
diff --git a/libm/man/sqrt.3 b/libm/man/sqrt.3
deleted file mode 100644
index 22f8b7b..0000000
--- a/libm/man/sqrt.3
+++ /dev/null
@@ -1,100 +0,0 @@
-.\" Copyright (c) 1985, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)sqrt.3	6.4 (Berkeley) 5/6/91
-.\" $FreeBSD: src/lib/msun/man/sqrt.3,v 1.12 2005/01/14 23:28:28 das Exp $
-.\"
-.Dd May 6, 1991
-.Dt SQRT 3
-.Os
-.Sh NAME
-.Nm cbrt ,
-.Nm cbrtf ,
-.Nm sqrt ,
-.Nm sqrtf
-.Nd cube root and square root functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn cbrt "double x"
-.Ft float
-.Fn cbrtf "float x"
-.Ft double
-.Fn sqrt "double x"
-.Ft float
-.Fn sqrtf "float x"
-.Sh DESCRIPTION
-The
-.Fn cbrt
-and the
-.Fn cbrtf
-functions compute
-the cube root of
-.Ar x .
-.Pp
-The
-.Fn sqrt
-and the
-.Fn sqrtf
-functions compute the
-non-negative square root of x.
-.Sh RETURN VALUES
-The
-.Fn cbrt
-and the
-.Fn cbrtf
-functions return the requested cube root.
-The
-.Fn sqrt
-and the
-.Fn sqrtf
-functions return the requested square root
-unless an error occurs.
-An attempt to take the
-.Fn sqrt
-of negative
-.Fa x
-raises an invalid exception and causes an \*(Na to be returned.
-.Sh SEE ALSO
-.Xr fenv 3 ,
-.Xr math 3
-.Sh STANDARDS
-The
-.Fn sqrt
-function conforms to
-.St -isoC .
-.Sh HISTORY
-The
-.Fn cbrt
-function appeared in
-.Bx 4.3 .
diff --git a/libm/man/tan.3 b/libm/man/tan.3
deleted file mode 100644
index 5995a3b..0000000
--- a/libm/man/tan.3
+++ /dev/null
@@ -1,81 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)tan.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/tan.3,v 1.9 2001/10/13 12:23:23 bde Exp $
-.\"
-.Dd May 2, 1991
-.Dt TAN 3
-.Os
-.Sh NAME
-.Nm tan ,
-.Nm tanf
-.Nd tangent functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn tan "double x"
-.Ft float
-.Fn tanf "float x"
-.Sh DESCRIPTION
-The
-.Fn tan
-and the
-.Fn tanf
-functions compute the tangent of
-.Fa x
-(measured in radians).
-A large magnitude argument may yield a result
-with little or no significance.
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn tan
-function returns the tangent value.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tanh 3
-.Sh STANDARDS
-The
-.Fn tan
-function conforms to
-.St -isoC .
diff --git a/libm/man/tanh.3 b/libm/man/tanh.3
deleted file mode 100644
index 391bc15..0000000
--- a/libm/man/tanh.3
+++ /dev/null
@@ -1,80 +0,0 @@
-.\" Copyright (c) 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"	This product includes software developed by the University of
-.\"	California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     from: @(#)tanh.3	5.1 (Berkeley) 5/2/91
-.\" $FreeBSD: src/lib/msun/man/tanh.3,v 1.10 2001/10/13 12:23:23 bde Exp $
-.\"
-.Dd May 2, 1991
-.Dt TANH 3
-.Os
-.Sh NAME
-.Nm tanh ,
-.Nm tanhf
-.Nd hyperbolic tangent functions
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn tanh "double x"
-.Ft float
-.Fn tanhf "float x"
-.Sh DESCRIPTION
-The
-.Fn tanh
-and the
-.Fn tanhf
-functions compute the hyperbolic tangent of
-.Fa x .
-For a discussion of error due to roundoff, see
-.Xr math 3 .
-.Sh RETURN VALUES
-The
-.Fn tanh
-and the
-.Fn tanhf
-functions return the hyperbolic tangent value.
-.Sh SEE ALSO
-.Xr acos 3 ,
-.Xr asin 3 ,
-.Xr atan 3 ,
-.Xr atan2 3 ,
-.Xr cos 3 ,
-.Xr cosh 3 ,
-.Xr math 3 ,
-.Xr sin 3 ,
-.Xr sinh 3 ,
-.Xr tan 3
-.Sh STANDARDS
-The
-.Fn tanh
-function conforms to
-.St -isoC .
diff --git a/libm/man/trunc.3 b/libm/man/trunc.3
deleted file mode 100644
index cb6c26f..0000000
--- a/libm/man/trunc.3
+++ /dev/null
@@ -1,80 +0,0 @@
-.\" Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.org>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" $FreeBSD: src/lib/msun/man/trunc.3,v 1.3 2005/06/15 19:04:04 ru Exp $
-.\"
-.Dd April 16, 2005
-.Dt TRUNC 3
-.Os
-.Sh NAME
-.Nm trunc ,
-.Nm truncf ,
-.Nm truncl
-.Nd nearest integral value with magnitude less than or equal to |x|
-.Sh LIBRARY
-.Lb libm
-.Sh SYNOPSIS
-.In math.h
-.Ft double
-.Fn trunc "double x"
-.Ft float
-.Fn truncf "float x"
-.Ft "long double"
-.Fn truncl "long double x"
-.Sh DESCRIPTION
-The
-.Fn trunc ,
-.Fn truncf ,
-and
-.Fn truncl
-functions return the nearest integral value with magnitude less than
-or equal to
-.Pf | Fa x Ns | .
-They are equivalent to
-.Fn rint ,
-.Fn rintf ,
-and
-.Fn rintl ,
-respectively, in the
-.Dv FE_TOWARDZERO
-rounding mode.
-.Sh SEE ALSO
-.Xr ceil 3 ,
-.Xr fesetround 3 ,
-.Xr floor 3 ,
-.Xr math 3 ,
-.Xr nextafter 3 ,
-.Xr rint 3 ,
-.Xr round 3
-.Sh STANDARDS
-The
-.Fn trunc ,
-.Fn truncf ,
-and
-.Fn truncl
-functions conform to
-.St -isoC-99 .
-.Sh HISTORY
-These routines first appeared in
-.Fx 5.3 .
diff --git a/libm/mips/_fpmath.h b/libm/mips/_fpmath.h
index cb6e8c0..f006a58 100644
--- a/libm/mips/_fpmath.h
+++ b/libm/mips/_fpmath.h
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libc/mips/_fpmath.h,v 1.1 2008/04/26 12:07:59 imp Exp $
+ * $FreeBSD$
  */
 
 union IEEEl2bits {
diff --git a/libm/src/e_acosf.c b/libm/src/e_acosf.c
deleted file mode 100644
index a11f48e..0000000
--- a/libm/src/e_acosf.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* e_acosf.c -- float version of e_acos.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosf.c,v 1.7 2002/05/28 17:03:12 alfred Exp $";
-#endif
-
-#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 */
-
-float
-__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 */
-	    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*/
-	    z = x*x;
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    r = p/q;
-	    return pio2_hi - (x - (pio2_lo-x*r));
-	} else  if (hx<0) {		/* x < -0.5 */
-	    z = (one+x)*(float)0.5;
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    s = __ieee754_sqrtf(z);
-	    r = p/q;
-	    w = r*s-pio2_lo;
-	    return pi - (float)2.0*(s+w);
-	} else {			/* x > 0.5 */
-	    int32_t idf;
-	    z = (one-x)*(float)0.5;
-	    s = __ieee754_sqrtf(z);
-	    df = s;
-	    GET_FLOAT_WORD(idf,df);
-	    SET_FLOAT_WORD(df,idf&0xfffff000);
-	    c  = (z-df*df)/(s+df);
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    r = p/q;
-	    w = r*s+c;
-	    return (float)2.0*(df+w);
-	}
-}
diff --git a/libm/src/e_asinf.c b/libm/src/e_asinf.c
deleted file mode 100644
index 1405faf..0000000
--- a/libm/src/e_asinf.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* e_asinf.c -- float version of e_asin.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_asinf.c,v 1.9 2005/12/04 13:52:46 bde Exp $";
-#endif
-
-#include "math.h"
-#include "math_private.h"
-
-static const float
-one =  1.0000000000e+00, /* 0x3F800000 */
-huge =  1.000e+30,
-pio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
-pio2_lo =  7.5497894159e-08, /* 0x33a22168 */
-pio4_hi =  7.8539812565e-01, /* 0x3f490fda */
-	/* coefficient for R(x^2) */
-pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
-pS1 = -3.2556581497e-01, /* 0xbea6b090 */
-pS2 =  2.0121252537e-01, /* 0x3e4e0aa8 */
-pS3 = -4.0055535734e-02, /* 0xbd241146 */
-pS4 =  7.9153501429e-04, /* 0x3a4f7f04 */
-pS5 =  3.4793309169e-05, /* 0x3811ef08 */
-qS1 = -2.4033949375e+00, /* 0xc019d139 */
-qS2 =  2.0209457874e+00, /* 0x4001572d */
-qS3 = -6.8828397989e-01, /* 0xbf303361 */
-qS4 =  7.7038154006e-02; /* 0x3d9dc62e */
-
-float
-__ieee754_asinf(float x)
-{
-	float t=0.0,w,p,q,c,r,s;
-	int32_t hx,ix;
-	GET_FLOAT_WORD(hx,x);
-	ix = hx&0x7fffffff;
-	if(ix==0x3f800000) {
-		/* asin(1)=+-pi/2 with inexact */
-	    return x*pio2_hi+x*pio2_lo;
-	} else if(ix> 0x3f800000) {	/* |x|>= 1 */
-	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */
-	} else if (ix<0x3f000000) {	/* |x|<0.5 */
-	    if(ix<0x32000000) {		/* if |x| < 2**-27 */
-		if(huge+x>one) return x;/* return x with inexact if x!=0*/
-	    } else
-		t = x*x;
-		p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
-		q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
-		w = p/q;
-		return x+x*w;
-	}
-	/* 1> |x|>= 0.5 */
-	w = one-fabsf(x);
-	t = w*(float)0.5;
-	p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
-	q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
-	s = __ieee754_sqrtf(t);
-	if(ix>=0x3F79999A) { 	/* if |x| > 0.975 */
-	    w = p/q;
-	    t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
-	} else {
-	    int32_t iw;
-	    w  = s;
-	    GET_FLOAT_WORD(iw,w);
-	    SET_FLOAT_WORD(w,iw&0xfffff000);
-	    c  = (t-w*w)/(s+w);
-	    r  = p/q;
-	    p  = (float)2.0*s*r-(pio2_lo-(float)2.0*c);
-	    q  = pio4_hi-(float)2.0*w;
-	    t  = pio4_hi-(p-q);
-	}
-	if(hx>0) return t; else return -t;
-}
diff --git a/libm/src/e_ldexpf.c b/libm/src/e_ldexpf.c
deleted file mode 100644
index 86297fc..0000000
--- a/libm/src/e_ldexpf.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* e_scalbf.c -- float version of e_scalb.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-#include "math.h"
-#include "math_private.h"
-
-float
-__ieee754_ldexpf(float x, int fn)
-{
-    return __ieee754_scalbf(x,fn);
-}
diff --git a/libm/src/e_log10.c b/libm/src/e_log10.c
deleted file mode 100644
index e84c0c7..0000000
--- a/libm/src/e_log10.c
+++ /dev/null
@@ -1,87 +0,0 @@
-
-/* @(#)e_log10.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log10.c,v 1.11 2005/02/04 18:26:06 das Exp $";
-#endif
-
-/* __ieee754_log10(x)
- * Return the base 10 logarithm of x
- * 
- * Method :
- *	Let log10_2hi = leading 40 bits of log10(2) and
- *	    log10_2lo = log10(2) - log10_2hi,
- *	    ivln10   = 1/log(10) rounded.
- *	Then
- *		n = ilogb(x), 
- *		if(n<0)  n = n+1;
- *		x = scalbn(x,-n);
- *		log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
- *
- * Note 1:
- *	To guarantee log10(10**n)=n, where 10**n is normal, the rounding 
- *	mode must set to Round-to-Nearest.
- * Note 2:
- *	[1/log(10)] rounded to 53 bits has error  .198   ulps;
- *	log10 is monotonic at all binary break points.
- *
- * Special cases:
- *	log10(x) is NaN with signal if x < 0; 
- *	log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
- *	log10(NaN) is that NaN with no signal;
- *	log10(10**N) = N  for N=0,1,...,22.
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following constants.
- * The decimal values may be used, provided that the compiler will convert
- * from decimal to binary accurately enough to produce the hexadecimal values
- * shown.
- */
-
-#include "math.h"
-#include "math_private.h"
-
-static const double
-two54      =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
-ivln10     =  4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
-log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
-log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
-
-static const double zero   =  0.0;
-
-double
-__ieee754_log10(double x)
-{
-	double y,z;
-	int32_t i,k,hx;
-	u_int32_t lx;
-
-	EXTRACT_WORDS(hx,lx,x);
-
-        k=0;
-        if (hx < 0x00100000) {                  /* x < 2**-1022  */
-            if (((hx&0x7fffffff)|lx)==0)
-                return -two54/zero;             /* log(+-0)=-inf */
-            if (hx<0) return (x-x)/zero;        /* log(-#) = NaN */
-            k -= 54; x *= two54; /* subnormal number, scale up x */
-	    GET_HIGH_WORD(hx,x);
-        }
-	if (hx >= 0x7ff00000) return x+x;
-	k += (hx>>20)-1023;
-	i  = ((u_int32_t)k&0x80000000)>>31;
-        hx = (hx&0x000fffff)|((0x3ff-i)<<20);
-        y  = (double)(k+i);
-	SET_HIGH_WORD(x,hx);
-	z  = y*log10_2lo + ivln10*__ieee754_log(x);
-	return  z+y*log10_2hi;
-}
diff --git a/libm/src/e_log10f.c b/libm/src/e_log10f.c
deleted file mode 100644
index 3473088..0000000
--- a/libm/src/e_log10f.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* e_log10f.c -- float version of e_log10.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log10f.c,v 1.8 2002/05/28 18:15:04 alfred Exp $";
-#endif
-
-#include "math.h"
-#include "math_private.h"
-
-static const float
-two25      =  3.3554432000e+07, /* 0x4c000000 */
-ivln10     =  4.3429449201e-01, /* 0x3ede5bd9 */
-log10_2hi  =  3.0102920532e-01, /* 0x3e9a2080 */
-log10_2lo  =  7.9034151668e-07; /* 0x355427db */
-
-static const float zero   =  0.0;
-
-float
-__ieee754_log10f(float x)
-{
-	float y,z;
-	int32_t i,k,hx;
-
-	GET_FLOAT_WORD(hx,x);
-
-        k=0;
-        if (hx < 0x00800000) {                  /* x < 2**-126  */
-            if ((hx&0x7fffffff)==0)
-                return -two25/zero;             /* log(+-0)=-inf */
-            if (hx<0) return (x-x)/zero;        /* log(-#) = NaN */
-            k -= 25; x *= two25; /* subnormal number, scale up x */
-	    GET_FLOAT_WORD(hx,x);
-        }
-	if (hx >= 0x7f800000) return x+x;
-	k += (hx>>23)-127;
-	i  = ((u_int32_t)k&0x80000000)>>31;
-        hx = (hx&0x007fffff)|((0x7f-i)<<23);
-        y  = (float)(k+i);
-	SET_FLOAT_WORD(x,hx);
-	z  = y*log10_2lo + ivln10*__ieee754_logf(x);
-	return  z+y*log10_2hi;
-}
diff --git a/libm/src/e_rem_pio2.c b/libm/src/e_rem_pio2.c
deleted file mode 100644
index 121ba29..0000000
--- a/libm/src/e_rem_pio2.c
+++ /dev/null
@@ -1,168 +0,0 @@
-
-/* @(#)e_rem_pio2.c 1.4 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_rem_pio2.c,v 1.8 2005/02/04 18:26:06 das Exp $";
-#endif
-
-/* __ieee754_rem_pio2(x,y)
- * 
- * return the remainder of x rem pi/2 in y[0]+y[1] 
- * use __kernel_rem_pio2()
- */
-
-#include "math.h"
-#include "math_private.h"
-
-/*
- * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi 
- */
-static const int32_t two_over_pi[] = {
-0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 
-0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, 
-0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 
-0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, 
-0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, 
-0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, 
-0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, 
-0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 
-0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 
-0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 
-0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, 
-};
-
-static const int32_t npio2_hw[] = {
-0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
-0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
-0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
-0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
-0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
-0x404858EB, 0x404921FB,
-};
-
-/*
- * invpio2:  53 bits of 2/pi
- * pio2_1:   first  33 bit of pi/2
- * pio2_1t:  pi/2 - pio2_1
- * pio2_2:   second 33 bit of pi/2
- * pio2_2t:  pi/2 - (pio2_1+pio2_2)
- * pio2_3:   third  33 bit of pi/2
- * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
- */
-
-static const double
-zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-half =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
-two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
-invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
-pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
-pio2_1t =  6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
-pio2_2  =  6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
-pio2_2t =  2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
-pio2_3  =  2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
-pio2_3t =  8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
-
-	int32_t __ieee754_rem_pio2(double x, double *y)
-{
-	double z,w,t,r,fn;
-	double tx[3];
-	int32_t e0,i,j,nx,n,ix,hx;
-	u_int32_t low;
-
-	GET_HIGH_WORD(hx,x);		/* high word of x */
-	ix = hx&0x7fffffff;
-	if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
-	    {y[0] = x; y[1] = 0; return 0;}
-	if(ix<0x4002d97c) {  /* |x| < 3pi/4, special case with n=+-1 */
-	    if(hx>0) { 
-		z = x - pio2_1;
-		if(ix!=0x3ff921fb) { 	/* 33+53 bit pi is good enough */
-		    y[0] = z - pio2_1t;
-		    y[1] = (z-y[0])-pio2_1t;
-		} else {		/* near pi/2, use 33+33+53 bit pi */
-		    z -= pio2_2;
-		    y[0] = z - pio2_2t;
-		    y[1] = (z-y[0])-pio2_2t;
-		}
-		return 1;
-	    } else {	/* negative x */
-		z = x + pio2_1;
-		if(ix!=0x3ff921fb) { 	/* 33+53 bit pi is good enough */
-		    y[0] = z + pio2_1t;
-		    y[1] = (z-y[0])+pio2_1t;
-		} else {		/* near pi/2, use 33+33+53 bit pi */
-		    z += pio2_2;
-		    y[0] = z + pio2_2t;
-		    y[1] = (z-y[0])+pio2_2t;
-		}
-		return -1;
-	    }
-	}
-	if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
-	    t  = fabs(x);
-	    n  = (int32_t) (t*invpio2+half);
-	    fn = (double)n;
-	    r  = t-fn*pio2_1;
-	    w  = fn*pio2_1t;	/* 1st round good to 85 bit */
-	    if(n<32&&ix!=npio2_hw[n-1]) {	
-		y[0] = r-w;	/* quick check no cancellation */
-	    } else {
-	        u_int32_t high;
-	        j  = ix>>20;
-	        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;	
-		    r  = t-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;	
-		    	r  = t-w;
-		    	w  = fn*pio2_3t-((t-r)-w);	
-		    	y[0] = r-w;
-		    }
-		}
-	    }
-	    y[1] = (r-y[0])-w;
-	    if(hx<0) 	{y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	    else	 return n;
-	}
-    /* 
-     * all other (large) arguments
-     */
-	if(ix>=0x7ff00000) {		/* x is inf or NaN */
-	    y[0]=y[1]=x-x; return 0;
-	}
-    /* set z = scalbn(|x|,ilogb(x)-23) */
-	GET_LOW_WORD(low,x);
-	SET_LOW_WORD(z,low);
-	e0 	= (ix>>20)-1046;	/* e0 = ilogb(z)-23; */
-	SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
-	for(i=0;i<2;i++) {
-		tx[i] = (double)((int32_t)(z));
-		z     = (z-tx[i])*two24;
-	}
-	tx[2] = z;
-	nx = 3;
-	while(tx[nx-1]==zero) nx--;	/* skip zero term */
-	n  =  __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
-	if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	return n;
-}
diff --git a/libm/src/e_rem_pio2f.c b/libm/src/e_rem_pio2f.c
deleted file mode 100644
index 5231cd4..0000000
--- a/libm/src/e_rem_pio2f.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* e_rem_pio2f.c -- float version of e_rem_pio2.c
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- * Debugged and optimized by Bruce D. Evans.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_rem_pio2f.c,v 1.19 2005/11/23 03:03:09 bde Exp $";
-#endif
-
-/* __ieee754_rem_pio2f(x,y)
- *
- * return the remainder of x rem pi/2 in y[0]+y[1]
- * use double precision internally
- * use __kernel_rem_pio2() for large x
- */
-
-#include "math.h"
-#include "math_private.h"
-
-/*
- * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
- */
-static const int32_t two_over_pi[] = {
-0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 
-0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, 
-0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 
-0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, 
-0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, 
-0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, 
-0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, 
-0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 
-0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 
-0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 
-0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, 
-};
-
-/*
- * invpio2:  53 bits of 2/pi
- * pio2_1:   first  33 bit of pi/2
- * pio2_1t:  pi/2 - pio2_1
- */
-
-static const double
-zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-half =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
-two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
-invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
-pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
-pio2_1t =  6.07710050650619224932e-11; /* 0x3DD0B461, 0x1A626331 */
-
-	int32_t __ieee754_rem_pio2f(float x, float *y)
-{
-	double w,t,r,fn;
-	double tx[1],ty[2];
-	float z;
-	int32_t e0,n,ix,hx;
-
-	GET_FLOAT_WORD(hx,x);
-	ix = hx&0x7fffffff;
-    /* 33+53 bit pi is good enough for medium size */
-	if(ix<=0x49490f80) {		/* |x| ~<= 2^19*(pi/2), medium size */
-	    t  = fabsf(x);
-	    n  = (int32_t) (t*invpio2+half);
-	    fn = (double)n;
-	    r  = t-fn*pio2_1;
-	    w  = fn*pio2_1t;
-	    y[0] = r-w;
-	    y[1] = (r-y[0])-w;
-	    if(hx<0) 	{y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	    else	 return n;
-	}
-    /*
-     * all other (large) arguments
-     */
-	if(ix>=0x7f800000) {		/* x is inf or NaN */
-	    y[0]=y[1]=x-x; return 0;
-	}
-    /* set z = scalbn(|x|,ilogb(|x|)-23) */
-	e0 = (ix>>23)-150;		/* e0 = ilogb(|x|)-23; */
-	SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23)));
-	tx[0] = z;
-	n  =  __kernel_rem_pio2(tx,ty,e0,1,1,two_over_pi);
-	y[0] = ty[0];
-	y[1] = ty[0] - y[0];
-	if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	return n;
-}
diff --git a/libm/src/k_rem_pio2.c b/libm/src/k_rem_pio2.c
deleted file mode 100644
index 7116f31..0000000
--- a/libm/src/k_rem_pio2.c
+++ /dev/null
@@ -1,304 +0,0 @@
-
-/* @(#)k_rem_pio2.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_rem_pio2.c,v 1.7 2005/02/04 18:26:06 das Exp $";
-#endif
-
-/*
- * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
- * double x[],y[]; int e0,nx,prec; int ipio2[];
- * 
- * __kernel_rem_pio2 return the last three digits of N with 
- *		y = x - N*pi/2
- * so that |y| < pi/2.
- *
- * The method is to compute the integer (mod 8) and fraction parts of 
- * (2/pi)*x without doing the full multiplication. In general we
- * skip the part of the product that are known to be a huge integer (
- * more accurately, = 0 mod 8 ). Thus the number of operations are
- * independent of the exponent of the input.
- *
- * (2/pi) is represented by an array of 24-bit integers in ipio2[].
- *
- * Input parameters:
- * 	x[]	The input value (must be positive) is broken into nx 
- *		pieces of 24-bit integers in double precision format.
- *		x[i] will be the i-th 24 bit of x. The scaled exponent 
- *		of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 
- *		match x's up to 24 bits.
- *
- *		Example of breaking a double positive z into x[0]+x[1]+x[2]:
- *			e0 = ilogb(z)-23
- *			z  = scalbn(z,-e0)
- *		for i = 0,1,2
- *			x[i] = floor(z)
- *			z    = (z-x[i])*2**24
- *
- *
- *	y[]	ouput result in an array of double precision numbers.
- *		The dimension of y[] is:
- *			24-bit  precision	1
- *			53-bit  precision	2
- *			64-bit  precision	2
- *			113-bit precision	3
- *		The actual value is the sum of them. Thus for 113-bit
- *		precison, one may have to do something like:
- *
- *		long double t,w,r_head, r_tail;
- *		t = (long double)y[2] + (long double)y[1];
- *		w = (long double)y[0];
- *		r_head = t+w;
- *		r_tail = w - (r_head - t);
- *
- *	e0	The exponent of x[0]
- *
- *	nx	dimension of x[]
- *
- *  	prec	an integer indicating the precision:
- *			0	24  bits (single)
- *			1	53  bits (double)
- *			2	64  bits (extended)
- *			3	113 bits (quad)
- *
- *	ipio2[]
- *		integer array, contains the (24*i)-th to (24*i+23)-th 
- *		bit of 2/pi after binary point. The corresponding 
- *		floating value is
- *
- *			ipio2[i] * 2^(-24(i+1)).
- *
- * External function:
- *	double scalbn(), floor();
- *
- *
- * Here is the description of some local variables:
- *
- * 	jk	jk+1 is the initial number of terms of ipio2[] needed
- *		in the computation. The recommended value is 2,3,4,
- *		6 for single, double, extended,and quad.
- *
- * 	jz	local integer variable indicating the number of 
- *		terms of ipio2[] used. 
- *
- *	jx	nx - 1
- *
- *	jv	index for pointing to the suitable ipio2[] for the
- *		computation. In general, we want
- *			( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
- *		is an integer. Thus
- *			e0-3-24*jv >= 0 or (e0-3)/24 >= jv
- *		Hence jv = max(0,(e0-3)/24).
- *
- *	jp	jp+1 is the number of terms in PIo2[] needed, jp = jk.
- *
- * 	q[]	double array with integral value, representing the
- *		24-bits chunk of the product of x and 2/pi.
- *
- *	q0	the corresponding exponent of q[0]. Note that the
- *		exponent for q[i] would be q0-24*i.
- *
- *	PIo2[]	double precision array, obtained by cutting pi/2
- *		into 24 bits chunks. 
- *
- *	f[]	ipio2[] in floating point 
- *
- *	iq[]	integer array by breaking up q[] in 24-bits chunk.
- *
- *	fq[]	final product of x*(2/pi) in fq[0],..,fq[jk]
- *
- *	ih	integer. If >0 it indicates q[] is >= 0.5, hence
- *		it also indicates the *sign* of the result.
- *
- */
-
-
-/*
- * Constants:
- * The hexadecimal values are the intended ones for the following 
- * constants. The decimal values may be used, provided that the 
- * compiler will convert from decimal to binary accurately enough 
- * to produce the hexadecimal values shown.
- */
-
-#include "math.h"
-#include "math_private.h"
-
-static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
-
-static const double PIo2[] = {
-  1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
-  7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
-  5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
-  3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
-  1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
-  1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
-  2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
-  2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
-};
-
-static const double			
-zero   = 0.0,
-one    = 1.0,
-two24   =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
-twon24  =  5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
-
-	int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
-{
-	int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
-	double z,fw,f[20],fq[20],q[20];
-
-    /* initialize jk*/
-	jk = init_jk[prec];
-	jp = jk;
-
-    /* determine jx,jv,q0, note that 3>q0 */
-	jx =  nx-1;
-	jv = (e0-3)/24; if(jv<0) jv=0;
-	q0 =  e0-24*(jv+1);
-
-    /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
-	j = jv-jx; m = jx+jk;
-	for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
-
-    /* compute q[0],q[1],...q[jk] */
-	for (i=0;i<=jk;i++) {
-	    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
-	}
-
-	jz = jk;
-recompute:
-    /* distill q[] into iq[] reversingly */
-	for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
-	    fw    =  (double)((int32_t)(twon24* z));
-	    iq[i] =  (int32_t)(z-two24*fw);
-	    z     =  q[j-1]+fw;
-	}
-
-    /* compute n */
-	z  = scalbn(z,q0);		/* actual value of z */
-	z -= 8.0*floor(z*0.125);		/* trim off integer >= 8 */
-	n  = (int32_t) z;
-	z -= (double)n;
-	ih = 0;
-	if(q0>0) {	/* need iq[jz-1] to determine n */
-	    i  = (iq[jz-1]>>(24-q0)); n += i;
-	    iq[jz-1] -= i<<(24-q0);
-	    ih = iq[jz-1]>>(23-q0);
-	} 
-	else if(q0==0) ih = iq[jz-1]>>23;
-	else if(z>=0.5) ih=2;
-
-	if(ih>0) {	/* q > 0.5 */
-	    n += 1; carry = 0;
-	    for(i=0;i<jz ;i++) {	/* compute 1-q */
-		j = iq[i];
-		if(carry==0) {
-		    if(j!=0) {
-			carry = 1; iq[i] = 0x1000000- j;
-		    }
-		} else  iq[i] = 0xffffff - j;
-	    }
-	    if(q0>0) {		/* rare case: chance is 1 in 12 */
-	        switch(q0) {
-	        case 1:
-	    	   iq[jz-1] &= 0x7fffff; break;
-	    	case 2:
-	    	   iq[jz-1] &= 0x3fffff; break;
-	        }
-	    }
-	    if(ih==2) {
-		z = one - z;
-		if(carry!=0) z -= scalbn(one,q0);
-	    }
-	}
-
-    /* check if recomputation is needed */
-	if(z==zero) {
-	    j = 0;
-	    for (i=jz-1;i>=jk;i--) j |= iq[i];
-	    if(j==0) { /* need recomputation */
-		for(k=1;iq[jk-k]==0;k++);   /* k = no. of terms needed */
-
-		for(i=jz+1;i<=jz+k;i++) {   /* add q[jz+1] to q[jz+k] */
-		    f[jx+i] = (double) ipio2[jv+i];
-		    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
-		    q[i] = fw;
-		}
-		jz += k;
-		goto recompute;
-	    }
-	}
-
-    /* chop off zero terms */
-	if(z==0.0) {
-	    jz -= 1; q0 -= 24;
-	    while(iq[jz]==0) { jz--; q0-=24;}
-	} else { /* break z into 24-bit if necessary */
-	    z = scalbn(z,-q0);
-	    if(z>=two24) { 
-		fw = (double)((int32_t)(twon24*z));
-		iq[jz] = (int32_t)(z-two24*fw);
-		jz += 1; q0 += 24;
-		iq[jz] = (int32_t) fw;
-	    } else iq[jz] = (int32_t) z ;
-	}
-
-    /* convert integer "bit" chunk to floating-point value */
-	fw = scalbn(one,q0);
-	for(i=jz;i>=0;i--) {
-	    q[i] = fw*(double)iq[i]; fw*=twon24;
-	}
-
-    /* compute PIo2[0,...,jp]*q[jz,...,0] */
-	for(i=jz;i>=0;i--) {
-	    for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
-	    fq[jz-i] = fw;
-	}
-
-    /* compress fq[] into y[] */
-	switch(prec) {
-	    case 0:
-		fw = 0.0;
-		for (i=jz;i>=0;i--) fw += fq[i];
-		y[0] = (ih==0)? fw: -fw; 
-		break;
-	    case 1:
-	    case 2:
-		fw = 0.0;
-		for (i=jz;i>=0;i--) fw += fq[i]; 
-		y[0] = (ih==0)? fw: -fw; 
-		fw = fq[0]-fw;
-		for (i=1;i<=jz;i++) fw += fq[i];
-		y[1] = (ih==0)? fw: -fw; 
-		break;
-	    case 3:	/* painful */
-		for (i=jz;i>0;i--) {
-		    fw      = fq[i-1]+fq[i]; 
-		    fq[i]  += fq[i-1]-fw;
-		    fq[i-1] = fw;
-		}
-		for (i=jz;i>1;i--) {
-		    fw      = fq[i-1]+fq[i]; 
-		    fq[i]  += fq[i-1]-fw;
-		    fq[i-1] = fw;
-		}
-		for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; 
-		if(ih==0) {
-		    y[0] =  fq[0]; y[1] =  fq[1]; y[2] =  fw;
-		} else {
-		    y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
-		}
-	}
-	return n&7;
-}
diff --git a/libm/src/k_rem_pio2f.c b/libm/src/k_rem_pio2f.c
deleted file mode 100644
index 35c28f5..0000000
--- a/libm/src/k_rem_pio2f.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/* k_rem_pio2f.c -- float version of k_rem_pio2.c
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_rem_pio2f.c,v 1.8 2005/10/11 07:56:05 bde Exp $";
-#endif
-
-#include "math.h"
-#include "math_private.h"
-
-/* In the float version, the input parameter x contains 8 bit
-   integers, not 24 bit integers.  113 bit precision is not supported.  */
-
-static const int init_jk[] = {4,7,9}; /* initial value for jk */
-
-static const float PIo2[] = {
-  1.5703125000e+00, /* 0x3fc90000 */
-  4.5776367188e-04, /* 0x39f00000 */
-  2.5987625122e-05, /* 0x37da0000 */
-  7.5437128544e-08, /* 0x33a20000 */
-  6.0026650317e-11, /* 0x2e840000 */
-  7.3896444519e-13, /* 0x2b500000 */
-  5.3845816694e-15, /* 0x27c20000 */
-  5.6378512969e-18, /* 0x22d00000 */
-  8.3009228831e-20, /* 0x1fc40000 */
-  3.2756352257e-22, /* 0x1bc60000 */
-  6.3331015649e-25, /* 0x17440000 */
-};
-
-static const float
-zero   = 0.0,
-one    = 1.0,
-two8   =  2.5600000000e+02, /* 0x43800000 */
-twon8  =  3.9062500000e-03; /* 0x3b800000 */
-
-	int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const int32_t *ipio2)
-{
-	int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
-	float z,fw,f[20],fq[20],q[20];
-
-    /* initialize jk*/
-	jk = init_jk[prec];
-	jp = jk;
-
-    /* determine jx,jv,q0, note that 3>q0 */
-	jx =  nx-1;
-	jv = (e0-3)/8; if(jv<0) jv=0;
-	q0 =  e0-8*(jv+1);
-
-    /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
-	j = jv-jx; m = jx+jk;
-	for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j];
-
-    /* compute q[0],q[1],...q[jk] */
-	for (i=0;i<=jk;i++) {
-	    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
-	}
-
-	jz = jk;
-recompute:
-    /* distill q[] into iq[] reversingly */
-	for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
-	    fw    =  (float)((int32_t)(twon8* z));
-	    iq[i] =  (int32_t)(z-two8*fw);
-	    z     =  q[j-1]+fw;
-	}
-
-    /* compute n */
-	z  = scalbnf(z,q0);		/* actual value of z */
-	z -= (float)8.0*floorf(z*(float)0.125);	/* trim off integer >= 8 */
-	n  = (int32_t) z;
-	z -= (float)n;
-	ih = 0;
-	if(q0>0) {	/* need iq[jz-1] to determine n */
-	    i  = (iq[jz-1]>>(8-q0)); n += i;
-	    iq[jz-1] -= i<<(8-q0);
-	    ih = iq[jz-1]>>(7-q0);
-	}
-	else if(q0==0) ih = iq[jz-1]>>7;
-	else if(z>=(float)0.5) ih=2;
-
-	if(ih>0) {	/* q > 0.5 */
-	    n += 1; carry = 0;
-	    for(i=0;i<jz ;i++) {	/* compute 1-q */
-		j = iq[i];
-		if(carry==0) {
-		    if(j!=0) {
-			carry = 1; iq[i] = 0x100- j;
-		    }
-		} else  iq[i] = 0xff - j;
-	    }
-	    if(q0>0) {		/* rare case: chance is 1 in 12 */
-	        switch(q0) {
-	        case 1:
-	    	   iq[jz-1] &= 0x7f; break;
-	    	case 2:
-	    	   iq[jz-1] &= 0x3f; break;
-	        }
-	    }
-	    if(ih==2) {
-		z = one - z;
-		if(carry!=0) z -= scalbnf(one,q0);
-	    }
-	}
-
-    /* check if recomputation is needed */
-	if(z==zero) {
-	    j = 0;
-	    for (i=jz-1;i>=jk;i--) j |= iq[i];
-	    if(j==0) { /* need recomputation */
-		for(k=1;iq[jk-k]==0;k++);   /* k = no. of terms needed */
-
-		for(i=jz+1;i<=jz+k;i++) {   /* add q[jz+1] to q[jz+k] */
-		    f[jx+i] = (float) ipio2[jv+i];
-		    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
-		    q[i] = fw;
-		}
-		jz += k;
-		goto recompute;
-	    }
-	}
-
-    /* chop off zero terms */
-	if(z==(float)0.0) {
-	    jz -= 1; q0 -= 8;
-	    while(iq[jz]==0) { jz--; q0-=8;}
-	} else { /* break z into 8-bit if necessary */
-	    z = scalbnf(z,-q0);
-	    if(z>=two8) {
-		fw = (float)((int32_t)(twon8*z));
-		iq[jz] = (int32_t)(z-two8*fw);
-		jz += 1; q0 += 8;
-		iq[jz] = (int32_t) fw;
-	    } else iq[jz] = (int32_t) z ;
-	}
-
-    /* convert integer "bit" chunk to floating-point value */
-	fw = scalbnf(one,q0);
-	for(i=jz;i>=0;i--) {
-	    q[i] = fw*(float)iq[i]; fw*=twon8;
-	}
-
-    /* compute PIo2[0,...,jp]*q[jz,...,0] */
-	for(i=jz;i>=0;i--) {
-	    for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
-	    fq[jz-i] = fw;
-	}
-
-    /* compress fq[] into y[] */
-	switch(prec) {
-	    case 0:
-		fw = 0.0;
-		for (i=jz;i>=0;i--) fw += fq[i];
-		y[0] = (ih==0)? fw: -fw;
-		break;
-	    case 1:
-	    case 2:
-		fw = 0.0;
-		for (i=jz;i>=0;i--) fw += fq[i];
-		fw = *(volatile float *)&fw;	/* clip any extra precision */
-		y[0] = (ih==0)? fw: -fw;
-		fw = fq[0]-fw;
-		for (i=1;i<=jz;i++) fw += fq[i];
-		y[1] = (ih==0)? fw: -fw;
-		break;
-	    case 3:	/* painful */
-		for (i=jz;i>0;i--) {
-		    fw      = fq[i-1]+fq[i];
-		    fq[i]  += fq[i-1]-fw;
-		    fq[i-1] = fw;
-		}
-		for (i=jz;i>1;i--) {
-		    fw      = fq[i-1]+fq[i];
-		    fq[i]  += fq[i-1]-fw;
-		    fq[i-1] = fw;
-		}
-		for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
-		if(ih==0) {
-		    y[0] =  fq[0]; y[1] =  fq[1]; y[2] =  fw;
-		} else {
-		    y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
-		}
-	}
-	return n&7;
-}
diff --git a/libm/src/math_private.h b/libm/src/math_private.h
deleted file mode 100644
index 5f6e088..0000000
--- a/libm/src/math_private.h
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-/*
- * from: @(#)fdlibm.h 5.1 93/09/24
- * $FreeBSD: src/lib/msun/src/math_private.h,v 1.20 2005/11/28 04:58:57 bde Exp $
- */
-
-#ifndef _MATH_PRIVATE_H_
-#define	_MATH_PRIVATE_H_
-
-#include <sys/types.h>
-#include <endian.h>
-
-/*
- * The original fdlibm code used statements like:
- *	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
- *	ix0 = *(n0+(int*)&x);			* high word of x *
- *	ix1 = *((1-n0)+(int*)&x);		* low word of x *
- * to dig two 32 bit words out of the 64 bit IEEE floating point
- * value.  That is non-ANSI, and, moreover, the gcc instruction
- * scheduler gets it wrong.  We instead use the following macros.
- * Unlike the original code, we determine the endianness at compile
- * time, not at run time; I don't see much benefit to selecting
- * endianness at run time.
- */
-
-/*
- * A union which permits us to convert between a double and two 32 bit
- * ints.
- */
-
-#if (__BYTE_ORDER == __BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__))
-
-typedef union
-{
-  double value;
-  struct
-  {
-    u_int32_t msw;
-    u_int32_t lsw;
-  } parts;
-} ieee_double_shape_type;
-
-#endif
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN  && !(defined(__arm__) && !defined(__VFP_FP__))
-
-typedef union
-{
-  double value;
-  struct
-  {
-    u_int32_t lsw;
-    u_int32_t msw;
-  } parts;
-} ieee_double_shape_type;
-
-#endif
-
-/* Get two 32 bit ints from a double.  */
-
-#define EXTRACT_WORDS(ix0,ix1,d)				\
-do {								\
-  ieee_double_shape_type ew_u;					\
-  ew_u.value = (d);						\
-  (ix0) = ew_u.parts.msw;					\
-  (ix1) = ew_u.parts.lsw;					\
-} while (0)
-
-/* Get the more significant 32 bit int from a double.  */
-
-#define GET_HIGH_WORD(i,d)					\
-do {								\
-  ieee_double_shape_type gh_u;					\
-  gh_u.value = (d);						\
-  (i) = gh_u.parts.msw;						\
-} while (0)
-
-/* Get the less significant 32 bit int from a double.  */
-
-#define GET_LOW_WORD(i,d)					\
-do {								\
-  ieee_double_shape_type gl_u;					\
-  gl_u.value = (d);						\
-  (i) = gl_u.parts.lsw;						\
-} while (0)
-
-/* Set a double from two 32 bit ints.  */
-
-#define INSERT_WORDS(d,ix0,ix1)					\
-do {								\
-  ieee_double_shape_type iw_u;					\
-  iw_u.parts.msw = (ix0);					\
-  iw_u.parts.lsw = (ix1);					\
-  (d) = iw_u.value;						\
-} while (0)
-
-/* Set the more significant 32 bits of a double from an int.  */
-
-#define SET_HIGH_WORD(d,v)					\
-do {								\
-  ieee_double_shape_type sh_u;					\
-  sh_u.value = (d);						\
-  sh_u.parts.msw = (v);						\
-  (d) = sh_u.value;						\
-} while (0)
-
-/* Set the less significant 32 bits of a double from an int.  */
-
-#define SET_LOW_WORD(d,v)					\
-do {								\
-  ieee_double_shape_type sl_u;					\
-  sl_u.value = (d);						\
-  sl_u.parts.lsw = (v);						\
-  (d) = sl_u.value;						\
-} while (0)
-
-/*
- * A union which permits us to convert between a float and a 32 bit
- * int.
- */
-
-typedef union
-{
-  float value;
-  /* FIXME: Assumes 32 bit int.  */
-  unsigned int word;
-} ieee_float_shape_type;
-
-/* Get a 32 bit int from a float.  */
-
-#define GET_FLOAT_WORD(i,d)					\
-do {								\
-  ieee_float_shape_type gf_u;					\
-  gf_u.value = (d);						\
-  (i) = gf_u.word;						\
-} while (0)
-
-/* Set a float from a 32 bit int.  */
-
-#define SET_FLOAT_WORD(d,i)					\
-do {								\
-  ieee_float_shape_type sf_u;					\
-  sf_u.word = (i);						\
-  (d) = sf_u.value;						\
-} while (0)
-
-#ifdef _COMPLEX_H
-/*
- * Inline functions that can be used to construct complex values.
- *
- * The C99 standard intends x+I*y to be used for this, but x+I*y is
- * currently unusable in general since gcc introduces many overflow,
- * underflow, sign and efficiency bugs by rewriting I*y as
- * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
- * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
- * to -0.0+I*0.0.
- */
-static __inline float complex
-cpackf(float x, float y)
-{
-	float complex z;
-
-	__real__ z = x;
-	__imag__ z = y;
-	return (z);
-}
-
-static __inline double complex
-cpack(double x, double y)
-{
-	double complex z;
-
-	__real__ z = x;
-	__imag__ z = y;
-	return (z);
-}
-
-static __inline long double complex
-cpackl(long double x, long double y)
-{
-	long double complex z;
-
-	__real__ z = x;
-	__imag__ z = y;
-	return (z);
-}
-#endif /* _COMPLEX_H */
- 
-/*
- * ieee style elementary functions
- *
- * We rename functions here to improve other sources' diffability
- * against fdlibm.
- */
-#define	__ieee754_sqrt	sqrt
-#define	__ieee754_acos	acos
-#define	__ieee754_acosh	acosh
-#define	__ieee754_log	log
-#define	__ieee754_atanh	atanh
-#define	__ieee754_asin	asin
-#define	__ieee754_atan2	atan2
-#define	__ieee754_exp	exp
-#define	__ieee754_cosh	cosh
-#define	__ieee754_fmod	fmod
-#define	__ieee754_pow	pow
-#define	__ieee754_lgamma lgamma
-#define	__ieee754_gamma	gamma
-#define	__ieee754_lgamma_r lgamma_r
-#define	__ieee754_gamma_r gamma_r
-#define	__ieee754_log10	log10
-#define	__ieee754_sinh	sinh
-#define	__ieee754_hypot	hypot
-#define	__ieee754_j0	j0
-#define	__ieee754_j1	j1
-#define	__ieee754_y0	y0
-#define	__ieee754_y1	y1
-#define	__ieee754_jn	jn
-#define	__ieee754_yn	yn
-#define	__ieee754_remainder remainder
-#define	__ieee754_scalb	scalb
-#define	__ieee754_sqrtf	sqrtf
-#define	__ieee754_acosf	acosf
-#define	__ieee754_acoshf acoshf
-#define	__ieee754_logf	logf
-#define	__ieee754_atanhf atanhf
-#define	__ieee754_asinf	asinf
-#define	__ieee754_atan2f atan2f
-#define	__ieee754_expf	expf
-#define	__ieee754_coshf	coshf
-#define	__ieee754_fmodf	fmodf
-#define	__ieee754_powf	powf
-#define	__ieee754_lgammaf lgammaf
-#define	__ieee754_gammaf gammaf
-#define	__ieee754_lgammaf_r lgammaf_r
-#define	__ieee754_gammaf_r gammaf_r
-#define	__ieee754_log10f log10f
-#define	__ieee754_sinhf	sinhf
-#define	__ieee754_hypotf hypotf
-#define	__ieee754_j0f	j0f
-#define	__ieee754_j1f	j1f
-#define	__ieee754_y0f	y0f
-#define	__ieee754_y1f	y1f
-#define	__ieee754_jnf	jnf
-#define	__ieee754_ynf	ynf
-#define	__ieee754_remainderf remainderf
-#define	__ieee754_scalbf scalbf
-#define __ieee754_ldexpf ldexpf
-
-/* fdlibm kernel function */
-int	__ieee754_rem_pio2(double,double*);
-double	__kernel_sin(double,double,int);
-double	__kernel_cos(double,double);
-double	__kernel_tan(double,double,int);
-int	__kernel_rem_pio2(double*,double*,int,int,int,const int*);
-
-/* float versions of fdlibm kernel functions */
-int	__ieee754_rem_pio2f(float,float*);
-float	__kernel_sindf(double);
-float	__kernel_cosdf(double);
-float	__kernel_tandf(double,int);
-int	__kernel_rem_pio2f(float*,float*,int,int,int,const int*);
-
-#endif /* !_MATH_PRIVATE_H_ */
diff --git a/libm/src/s_cbrt.c b/libm/src/s_cbrt.c
deleted file mode 100644
index b600677..0000000
--- a/libm/src/s_cbrt.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/* @(#)s_cbrt.c 5.1 93/09/24 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- *
- * Optimized by Bruce D. Evans.
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cbrt.c,v 1.10 2005/12/13 20:17:23 bde Exp $";
-#endif
-
-#include "math.h"
-#include "math_private.h"
-
-/* cbrt(x)
- * Return cube root of x
- */
-static const u_int32_t
-	B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */
-	B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */
-
-static const double
-C =  5.42857142857142815906e-01, /* 19/35     = 0x3FE15F15, 0xF15F15F1 */
-D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
-E =  1.41428571428571436819e+00, /* 99/70     = 0x3FF6A0EA, 0x0EA0EA0F */
-F =  1.60714285714285720630e+00, /* 45/28     = 0x3FF9B6DB, 0x6DB6DB6E */
-G =  3.57142857142857150787e-01; /* 5/14      = 0x3FD6DB6D, 0xB6DB6DB7 */
-
-double
-cbrt(double x)
-{
-	int32_t	hx;
-	double r,s,t=0.0,w;
-	u_int32_t sign;
-	u_int32_t high,low;
-
-	GET_HIGH_WORD(hx,x);
-	sign=hx&0x80000000; 		/* sign= sign(x) */
-	hx  ^=sign;
-	if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
-	GET_LOW_WORD(low,x);
-	if((hx|low)==0)
-	    return(x);		/* cbrt(0) is itself */
-
-    /*
-     * Rough cbrt to 5 bits:
-     *    cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3)
-     * where e is integral and >= 0, m is real and in [0, 1), and "/" and
-     * "%" are integer division and modulus with rounding towards minus
-     * infinity.  The RHS is always >= the LHS and has a maximum relative
-     * error of about 1 in 16.  Adding a bias of -0.03306235651 to the
-     * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE
-     * floating point representation, for finite positive normal values,
-     * ordinary integer divison of the value in bits magically gives
-     * almost exactly the RHS of the above provided we first subtract the
-     * exponent bias (1023 for doubles) and later add it back.  We do the
-     * subtraction virtually to keep e >= 0 so that ordinary integer
-     * division rounds towards minus infinity; this is also efficient.
-     */
-	if(hx<0x00100000) { 		/* subnormal number */
-	    SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */
-	    t*=x;
-	    GET_HIGH_WORD(high,t);
-	    SET_HIGH_WORD(t,sign|((high&0x7fffffff)/3+B2));
-	} else
-	    SET_HIGH_WORD(t,sign|(hx/3+B1));
-
-    /* new cbrt to 23 bits; may be implemented in single precision */
-	r=t*t/x;
-	s=C+r*t;
-	t*=G+F/(s+E+D/s);
-
-    /* chop t to 20 bits and make it larger in magnitude than cbrt(x) */
-	GET_HIGH_WORD(high,t);
-	INSERT_WORDS(t,high+0x00000001,0);
-
-    /* one step Newton iteration to 53 bits with error less than 0.667 ulps */
-	s=t*t;		/* t*t is exact */
-	r=x/s;
-	w=t+t;
-	r=(r-t)/(w+r);	/* r-t is exact */
-	t=t+t*r;
-
-	return(t);
-}
diff --git a/libm/src/s_cbrtf.c b/libm/src/s_cbrtf.c
deleted file mode 100644
index 75569a2..0000000
--- a/libm/src/s_cbrtf.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/* s_cbrtf.c -- float version of s_cbrt.c.
- * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- * Debugged and optimized by Bruce D. Evans.
- */
-
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cbrtf.c,v 1.12 2005/12/13 20:17:23 bde Exp $";
-#endif
-
-#include "math.h"
-#include "math_private.h"
-
-/* cbrtf(x)
- * Return cube root of x
- */
-static const unsigned
-	B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
-	B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
-
-static const float
-C =  5.4285717010e-01, /* 19/35     = 0x3f0af8b0 */
-D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
-E =  1.4142856598e+00, /* 99/70     = 0x3fb50750 */
-F =  1.6071428061e+00, /* 45/28     = 0x3fcdb6db */
-G =  3.5714286566e-01; /* 5/14      = 0x3eb6db6e */
-
-float
-cbrtf(float x)
-{
-	float r,s,t,w;
-	int32_t hx;
-	u_int32_t sign;
-	u_int32_t high;
-
-	GET_FLOAT_WORD(hx,x);
-	sign=hx&0x80000000; 		/* sign= sign(x) */
-	hx  ^=sign;
-	if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
-	if(hx==0)
-	    return(x);		/* cbrt(0) is itself */
-
-    /* rough cbrt to 5 bits */
-	if(hx<0x00800000) { 		/* subnormal number */
-	    SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
-	    t*=x;
-	    GET_FLOAT_WORD(high,t);
-	    SET_FLOAT_WORD(t,sign|((high&0x7fffffff)/3+B2));
-	} else
-	    SET_FLOAT_WORD(t,sign|(hx/3+B1));
-
-    /* new cbrt to 23 bits */
-	r=t*t/x;
-	s=C+r*t;
-	t*=G+F/(s+E+D/s);
-
-    /* chop t to 12 bits and make it larger in magnitude than cbrt(x) */
-	GET_FLOAT_WORD(high,t);
-	SET_FLOAT_WORD(t,(high&0xfffff000)+0x00001000);
-
-    /* one step Newton iteration to 24 bits with error less than 0.667 ulps */
-	s=t*t;		/* t*t is exact */
-	r=x/s;
-	w=t+t;
-	r=(r-t)/(w+r);	/* r-t is exact */
-	t=t+t*r;
-
-	return(t);
-}
diff --git a/libm/src/s_fma.c b/libm/src/s_fma.c
deleted file mode 100644
index 1fcc26c..0000000
--- a/libm/src/s_fma.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*-
- * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fma.c,v 1.4 2005/03/18 02:27:59 das Exp $"); */
-
-#include <fenv.h>
-#include <float.h>
-#include <math.h>
-
-/*
- * Fused multiply-add: Compute x * y + z with a single rounding error.
- *
- * We use scaling to avoid overflow/underflow, along with the
- * canonical precision-doubling technique adapted from:
- *
- *	Dekker, T.  A Floating-Point Technique for Extending the
- *	Available Precision.  Numer. Math. 18, 224-242 (1971).
- *
- * This algorithm is sensitive to the rounding precision.  FPUs such
- * as the i387 must be set in double-precision mode if variables are
- * to be stored in FP registers in order to avoid incorrect results.
- * This is the default on FreeBSD, but not on many other systems.
- *
- * Hardware instructions should be used on architectures that support it,
- * since this implementation will likely be several times slower.
- */
-#if LDBL_MANT_DIG != 113
-double
-fma(double x, double y, double z)
-{
-	static const double split = 0x1p27 + 1.0;
-	double xs, ys, zs;
-	double c, cc, hx, hy, p, q, tx, ty;
-	double r, rr, s;
-	int oround;
-	int ex, ey, ez;
-	int spread;
-
-	if (z == 0.0)
-		return (x * y);
-	if (x == 0.0 || y == 0.0)
-		return (x * y + z);
-
-	/* Results of frexp() are undefined for these cases. */
-	if (!isfinite(x) || !isfinite(y) || !isfinite(z))
-		return (x * y + z);
-
-	xs = frexp(x, &ex);
-	ys = frexp(y, &ey);
-	zs = frexp(z, &ez);
-	oround = fegetround();
-	spread = ex + ey - ez;
-
-	/*
-	 * If x * y and z are many orders of magnitude apart, the scaling
-	 * will overflow, so we handle these cases specially.  Rounding
-	 * modes other than FE_TONEAREST are painful.
-	 */
-	if (spread > DBL_MANT_DIG * 2) {
-		fenv_t env;
-		feraiseexcept(FE_INEXACT);
-		switch(oround) {
-		case FE_TONEAREST:
-			return (x * y);
-		case FE_TOWARDZERO:
-			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafter(r, 0);
-			feupdateenv(&env);
-			return (r);
-		case FE_DOWNWARD:
-			if (z > 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafter(r, -INFINITY);
-			feupdateenv(&env);
-			return (r);
-		default:	/* FE_UPWARD */
-			if (z < 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafter(r, INFINITY);
-			feupdateenv(&env);
-			return (r);
-		}
-	}
-	if (spread < -DBL_MANT_DIG) {
-		feraiseexcept(FE_INEXACT);
-		if (!isnormal(z))
-			feraiseexcept(FE_UNDERFLOW);
-		switch (oround) {
-		case FE_TONEAREST:
-			return (z);
-		case FE_TOWARDZERO:
-			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
-				return (z);
-			else
-				return (nextafter(z, 0));
-		case FE_DOWNWARD:
-			if (x > 0.0 ^ y < 0.0)
-				return (z);
-			else
-				return (nextafter(z, -INFINITY));
-		default:	/* FE_UPWARD */
-			if (x > 0.0 ^ y < 0.0)
-				return (nextafter(z, INFINITY));
-			else
-				return (z);
-		}
-	}
-
-	/*
-	 * Use Dekker's algorithm to perform the multiplication and
-	 * subsequent addition in twice the machine precision.
-	 * Arrange so that x * y = c + cc, and x * y + z = r + rr.
-	 */
-	fesetround(FE_TONEAREST);
-
-	p = xs * split;
-	hx = xs - p;
-	hx += p;
-	tx = xs - hx;
-
-	p = ys * split;
-	hy = ys - p;
-	hy += p;
-	ty = ys - hy;
-
-	p = hx * hy;
-	q = hx * ty + tx * hy;
-	c = p + q;
-	cc = p - c + q + tx * ty;
-
-	zs = ldexp(zs, -spread);
-	r = c + zs;
-	s = r - c;
-	rr = (c - (r - s)) + (zs - s) + cc;
-
-	spread = ex + ey;
-	if (spread + ilogb(r) > -1023) {
-		fesetround(oround);
-		r = r + rr;
-	} else {
-		/*
-		 * The result is subnormal, so we round before scaling to
-		 * avoid double rounding.
-		 */
-		p = ldexp(copysign(0x1p-1022, r), -spread);
-		c = r + p;
-		s = c - r;
-		cc = (r - (c - s)) + (p - s) + rr;
-		fesetround(oround);
-		r = (c + cc) - p;
-	}
-	return (ldexp(r, spread));
-}
-#else	/* LDBL_MANT_DIG == 113 */
-/*
- * 113 bits of precision is more than twice the precision of a double,
- * so it is enough to represent the intermediate product exactly.
- */
-double
-fma(double x, double y, double z)
-{
-	return ((long double)x * y + z);
-}
-#endif	/* LDBL_MANT_DIG != 113 */
-
-#if (LDBL_MANT_DIG == 53)
-__weak_reference(fma, fmal);
-#endif
diff --git a/libm/src/s_fmaf.c b/libm/src/s_fmaf.c
deleted file mode 100644
index 31aaaa9..0000000
--- a/libm/src/s_fmaf.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaf.c,v 1.1 2005/01/22 09:53:18 das Exp $"); */
-
-/*
- * Fused multiply-add: Compute x * y + z with a single rounding error.
- *
- * A double has more than twice as much precision than a float, so
- * direct double-precision arithmetic suffices.
- *
- * XXX We are relying on the compiler to convert from double to float
- *     using the current rounding mode and with the appropriate
- *     side-effects.  But on at least one platform (gcc 3.4.2/sparc64),
- *     this appears to be too much to ask for.  The precision
- *     reduction should be done manually.
- */
-float
-fmaf(float x, float y, float z)
-{
-
-	return ((double)x * y + z);
-}
diff --git a/libm/src/s_fmal.c b/libm/src/s_fmal.c
deleted file mode 100644
index f1736fa..0000000
--- a/libm/src/s_fmal.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*-
- * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmal.c,v 1.2 2005/03/18 02:27:59 das Exp $"); */
-
-#include <fenv.h>
-#include <float.h>
-#include <math.h>
-
-/*
- * Fused multiply-add: Compute x * y + z with a single rounding error.
- *
- * We use scaling to avoid overflow/underflow, along with the
- * canonical precision-doubling technique adapted from:
- *
- *	Dekker, T.  A Floating-Point Technique for Extending the
- *	Available Precision.  Numer. Math. 18, 224-242 (1971).
- */
-long double
-fmal(long double x, long double y, long double z)
-{
-#if LDBL_MANT_DIG == 64
-	static const long double split = 0x1p32L + 1.0;
-#elif LDBL_MANT_DIG == 113
-	static const long double split = 0x1p57L + 1.0;
-#endif
-	long double xs, ys, zs;
-	long double c, cc, hx, hy, p, q, tx, ty;
-	long double r, rr, s;
-	int oround;
-	int ex, ey, ez;
-	int spread;
-
-	if (z == 0.0)
-		return (x * y);
-	if (x == 0.0 || y == 0.0)
-		return (x * y + z);
-
-	/* Results of frexp() are undefined for these cases. */
-	if (!isfinite(x) || !isfinite(y) || !isfinite(z))
-		return (x * y + z);
-
-	xs = frexpl(x, &ex);
-	ys = frexpl(y, &ey);
-	zs = frexpl(z, &ez);
-	oround = fegetround();
-	spread = ex + ey - ez;
-
-	/*
-	 * If x * y and z are many orders of magnitude apart, the scaling
-	 * will overflow, so we handle these cases specially.  Rounding
-	 * modes other than FE_TONEAREST are painful.
-	 */
-	if (spread > LDBL_MANT_DIG * 2) {
-		fenv_t env;
-		feraiseexcept(FE_INEXACT);
-		switch(oround) {
-		case FE_TONEAREST:
-			return (x * y);
-		case FE_TOWARDZERO:
-			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafterl(r, 0);
-			feupdateenv(&env);
-			return (r);
-		case FE_DOWNWARD:
-			if (z > 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafterl(r, -INFINITY);
-			feupdateenv(&env);
-			return (r);
-		default:	/* FE_UPWARD */
-			if (z < 0.0)
-				return (x * y);
-			feholdexcept(&env);
-			r = x * y;
-			if (!fetestexcept(FE_INEXACT))
-				r = nextafterl(r, INFINITY);
-			feupdateenv(&env);
-			return (r);
-		}
-	}
-	if (spread < -LDBL_MANT_DIG) {
-		feraiseexcept(FE_INEXACT);
-		if (!isnormal(z))
-			feraiseexcept(FE_UNDERFLOW);
-		switch (oround) {
-		case FE_TONEAREST:
-			return (z);
-		case FE_TOWARDZERO:
-			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
-				return (z);
-			else
-				return (nextafterl(z, 0));
-		case FE_DOWNWARD:
-			if (x > 0.0 ^ y < 0.0)
-				return (z);
-			else
-				return (nextafterl(z, -INFINITY));
-		default:	/* FE_UPWARD */
-			if (x > 0.0 ^ y < 0.0)
-				return (nextafterl(z, INFINITY));
-			else
-				return (z);
-		}
-	}
-
-	/*
-	 * Use Dekker's algorithm to perform the multiplication and
-	 * subsequent addition in twice the machine precision.
-	 * Arrange so that x * y = c + cc, and x * y + z = r + rr.
-	 */
-	fesetround(FE_TONEAREST);
-
-	p = xs * split;
-	hx = xs - p;
-	hx += p;
-	tx = xs - hx;
-
-	p = ys * split;
-	hy = ys - p;
-	hy += p;
-	ty = ys - hy;
-
-	p = hx * hy;
-	q = hx * ty + tx * hy;
-	c = p + q;
-	cc = p - c + q + tx * ty;
-
-	zs = ldexpl(zs, -spread);
-	r = c + zs;
-	s = r - c;
-	rr = (c - (r - s)) + (zs - s) + cc;
-
-	spread = ex + ey;
-	if (spread + ilogbl(r) > -16383) {
-		fesetround(oround);
-		r = r + rr;
-	} else {
-		/*
-		 * The result is subnormal, so we round before scaling to
-		 * avoid double rounding.
-		 */
-		p = ldexpl(copysignl(0x1p-16382L, r), -spread);
-		c = r + p;
-		s = c - r;
-		cc = (r - (c - s)) + (p - s) + rr;
-		fesetround(oround);
-		r = (c + cc) - p;
-	}
-	return (ldexpl(r, spread));
-}
diff --git a/libm/src/s_llrint.c b/libm/src/s_llrint.c
deleted file mode 100644
index 8a67f3a..0000000
--- a/libm/src/s_llrint.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */
-
-#define type		double
-#define	roundit		rint
-#define dtype		long long
-#define	fn		llrint
-
-#include "s_lrint.c"
diff --git a/libm/src/s_llrintf.c b/libm/src/s_llrintf.c
deleted file mode 100644
index 4d75e38..0000000
--- a/libm/src/s_llrintf.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */
-
-#define type		float
-#define	roundit		rintf
-#define dtype		long long
-#define	fn		llrintf
-
-#include "s_lrint.c"
diff --git a/libm/src/s_llround.c b/libm/src/s_llround.c
deleted file mode 100644
index 28ab13e..0000000
--- a/libm/src/s_llround.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llround.c,v 1.2 2005/04/08 00:52:27 das Exp $"); */
-
-#define type		double
-#define	roundit		round
-#define dtype		long long
-#define	DTYPE_MIN	LONGLONG_MIN
-#define	DTYPE_MAX	LONGLONG_MAX
-#define	fn		llround
-
-#include "s_lround.c"
diff --git a/libm/src/s_llroundf.c b/libm/src/s_llroundf.c
deleted file mode 100644
index 3dd6905..0000000
--- a/libm/src/s_llroundf.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llroundf.c,v 1.2 2005/04/08 00:52:27 das Exp $"); */
-
-#define type		float
-#define	roundit		roundf
-#define dtype		long long
-#define	DTYPE_MIN	LONGLONG_MIN
-#define	DTYPE_MAX	LONGLONG_MAX
-#define	fn		llroundf
-
-#include "s_lround.c"
diff --git a/libm/src/s_llroundl.c b/libm/src/s_llroundl.c
deleted file mode 100644
index 89bae54..0000000
--- a/libm/src/s_llroundl.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_llroundl.c,v 1.1 2005/04/08 01:24:08 das Exp $"); */
-
-#define type		long double
-#define	roundit		roundl
-#define dtype		long long
-#define	DTYPE_MIN	LONGLONG_MIN
-#define	DTYPE_MAX	LONGLONG_MAX
-#define	fn		llroundl
-
-#include "s_lround.c"
diff --git a/libm/src/s_lrintf.c b/libm/src/s_lrintf.c
deleted file mode 100644
index f258e03..0000000
--- a/libm/src/s_lrintf.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lrintf.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */
-
-#define type		float
-#define	roundit		rintf
-#define dtype		long
-#define	fn		lrintf
-
-#include "s_lrint.c"
diff --git a/libm/src/w_cabs.c b/libm/src/w_cabs.c
deleted file mode 100644
index 577e5e0..0000000
--- a/libm/src/w_cabs.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * cabs() wrapper for hypot().
- *
- * Written by J.T. Conklin, <jtc@wimsey.com>
- * Placed into the Public Domain, 1994.
- */
-
-#ifndef lint
-static const char rcsid[] =
-  "$FreeBSD: src/lib/msun/src/w_cabs.c,v 1.4 2001/06/13 15:16:30 ru Exp $";
-#endif /* not lint */
-
-#include <complex.h>
-#include <math.h>
-
-double
-cabs(z)
-	double complex z;
-{
-	return hypot(creal(z), cimag(z));
-}
-
-double
-z_abs(z)
-	double complex *z;
-{
-	return hypot(creal(*z), cimag(*z));
-}
diff --git a/libm/bsdsrc/b_exp.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
similarity index 96%
rename from libm/bsdsrc/b_exp.c
rename to libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
index 107bc89..4400992 100644
--- a/libm/bsdsrc/b_exp.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_exp.c
@@ -31,11 +31,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef lint
-static char sccsid[] = "@(#)exp.c	8.1 (Berkeley) 6/4/93";
-#endif /* not lint */
+/* @(#)exp.c	8.1 (Berkeley) 6/4/93 */
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_exp.c,v 1.7 2004/12/16 20:40:37 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 
 /* EXP(X)
diff --git a/libm/bsdsrc/b_log.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
similarity index 98%
rename from libm/bsdsrc/b_log.c
rename to libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
index d4e5f65..5a4b964 100644
--- a/libm/bsdsrc/b_log.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_log.c
@@ -31,11 +31,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef lint
-static char sccsid[] = "@(#)log.c	8.2 (Berkeley) 11/30/93";
-#endif /* not lint */
+/* @(#)log.c	8.2 (Berkeley) 11/30/93 */
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_log.c,v 1.8 2005/09/19 11:28:19 bde Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 #include <errno.h>
diff --git a/libm/bsdsrc/b_tgamma.c b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
similarity index 91%
rename from libm/bsdsrc/b_tgamma.c
rename to libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
index ff6c5ac..1d0af44 100644
--- a/libm/bsdsrc/b_tgamma.c
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/b_tgamma.c
@@ -31,11 +31,9 @@
  * SUCH DAMAGE.
  */
 
-#ifndef lint
-static char sccsid[] = "@(#)gamma.c	8.1 (Berkeley) 6/4/93";
-#endif /* not lint */
+/* @(#)gamma.c	8.1 (Berkeley) 6/4/93 */
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/bsdsrc/b_tgamma.c,v 1.7 2005/09/19 11:28:19 bde Exp $"); */
+__FBSDID("$FreeBSD$");
 
 /*
  * This code by P. McIlroy, Oct 1992;
@@ -44,14 +42,12 @@
  * acknowledged.
  */
 
-//#include <math.h>
-#include "../include/math.h"
+#include <math.h>
 #include "mathimpl.h"
-#include <errno.h>
 
 /* METHOD:
  * x < 0: Use reflection formula, G(x) = pi/(sin(pi*x)*x*G(x))
- * 	At negative integers, return +Inf, and set errno.
+ * 	At negative integers, return NaN and raise invalid.
  *
  * x < 6.5:
  *	Use argument reduction G(x+1) = xG(x) to reach the
@@ -68,11 +64,15 @@
  *	avoid premature round-off.
  *
  * Special values:
- *	non-positive integer:	Set overflow trap; return +Inf;
- *	x > 171.63:		Set overflow trap; return +Inf;
- *	NaN: 			Set invalid trap;  return NaN
+ *	-Inf:			return NaN and raise invalid;
+ *	negative integer:	return NaN and raise invalid;
+ *	other x ~< 177.79:	return +-0 and raise underflow;
+ *	+-0:			return +-Inf and raise divide-by-zero;
+ *	finite x ~> 171.63:	return +Inf and raise overflow;
+ *	+Inf:			return +Inf;
+ *	NaN: 			return NaN.
  *
- * Accuracy: Gamma(x) is accurate to within
+ * Accuracy: tgamma(x) is accurate to within
  *	x > 0:  error provably < 0.9ulp.
  *	Maximum observed in 1,000,000 trials was .87ulp.
  *	x < 0:
@@ -133,7 +133,7 @@
 
 	if (x >= 6) {
 		if(x > 171.63)
-			return(one/zero);
+			return (x / zero);
 		u = large_gam(x);
 		return(__exp__D(u.a, u.b));
 	} else if (x >= 1.0 + LEFT + x0)
@@ -141,12 +141,11 @@
 	else if (x > 1.e-17)
 		return (smaller_gam(x));
 	else if (x > -1.e-17) {
-		if (x == 0.0)
-			return (one/x);
-		one+1e-20;		/* Raise inexact flag. */
+		if (x != 0.0)
+			u.a = one - tiny;	/* raise inexact */
 		return (one/x);
 	} else if (!finite(x))
-		return (x*x);		/* x = NaN, -Inf */
+		return (x - x);		/* x is NaN or -Inf */
 	else
 		return (neg_gam(x));
 }
@@ -280,11 +279,13 @@
 	struct Double lg, lsine;
 	double y, z;
 
-	y = floor(x + .5);
+	y = ceil(x);
 	if (y == x)		/* Negative integer. */
-		return (one/zero);
-	z = fabs(x - y);
-	y = .5*ceil(x);
+		return ((x - x) / zero);
+	z = y - x;
+	if (z > 0.5)
+		z = one - z;
+	y = 0.5 * y;
 	if (y == ceil(y))
 		sgn = -1;
 	if (z < .25)
diff --git a/libm/bsdsrc/mathimpl.h b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
similarity index 96%
rename from libm/bsdsrc/mathimpl.h
rename to libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
index 2a3b246..04a4b6e 100644
--- a/libm/bsdsrc/mathimpl.h
+++ b/libm/upstream-freebsd/lib/msun/bsdsrc/mathimpl.h
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)mathimpl.h	8.1 (Berkeley) 6/4/93
- * $FreeBSD: src/lib/msun/bsdsrc/mathimpl.h,v 1.7 2005/11/18 05:03:12 bde Exp $
+ * $FreeBSD$
  */
 
 #ifndef _MATHIMPL_H_
diff --git a/libm/src/e_acos.c b/libm/upstream-freebsd/lib/msun/src/e_acos.c
similarity index 91%
rename from libm/src/e_acos.c
rename to libm/upstream-freebsd/lib/msun/src/e_acos.c
index 8ba672a..1f6dca5 100644
--- a/libm/src/e_acos.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_acos.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acos.c,v 1.10 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_acos(x)
  * Method :                  
@@ -39,14 +38,18 @@
  * Function needed: sqrt
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
 static const double
 one=  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
 pi =  3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
-pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
-pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
+pio2_hi =  1.57079632679489655800e+00; /* 0x3FF921FB, 0x54442D18 */
+static volatile double
+pio2_lo =  6.12323399573676603587e-17; /* 0x3C91A626, 0x33145C07 */
+static const double
 pS0 =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
 pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
 pS2 =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
@@ -102,3 +105,7 @@
 	    return 2.0*(df+w);
 	}
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(acos, acosl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/e_acosf.c b/libm/upstream-freebsd/lib/msun/src/e_acosf.c
new file mode 100644
index 0000000..c9f62cc
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_acosf.c
@@ -0,0 +1,77 @@
+/* e_acosf.c -- float version of e_acos.c.
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "math.h"
+#include "math_private.h"
+
+static const float
+one =  1.0000000000e+00, /* 0x3F800000 */
+pi =  3.1415925026e+00, /* 0x40490fda */
+pio2_hi =  1.5707962513e+00; /* 0x3fc90fda */
+static volatile float
+pio2_lo =  7.5497894159e-08; /* 0x33a22168 */
+static const float
+pS0 =  1.6666586697e-01,
+pS1 = -4.2743422091e-02,
+pS2 = -8.6563630030e-03,
+qS1 = -7.0662963390e-01;
+
+float
+__ieee754_acosf(float x)
+{
+	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(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<=0x32800000) return pio2_hi+pio2_lo;/*if|x|<2**-26*/
+	    z = x*x;
+	    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));
+	    q = one+z*qS1;
+	    s = sqrtf(z);
+	    r = p/q;
+	    w = r*s-pio2_lo;
+	    return pi - (float)2.0*(s+w);
+	} else {			/* x > 0.5 */
+	    int32_t idf;
+	    z = (one-x)*(float)0.5;
+	    s = sqrtf(z);
+	    df = s;
+	    GET_FLOAT_WORD(idf,df);
+	    SET_FLOAT_WORD(df,idf&0xfffff000);
+	    c  = (z-df*df)/(s+df);
+	    p = z*(pS0+z*(pS1+z*pS2));
+	    q = one+z*qS1;
+	    r = p/q;
+	    w = r*s+c;
+	    return (float)2.0*(df+w);
+	}
+}
diff --git a/libm/src/e_acosh.c b/libm/upstream-freebsd/lib/msun/src/e_acosh.c
similarity index 92%
rename from libm/src/e_acosh.c
rename to libm/upstream-freebsd/lib/msun/src/e_acosh.c
index ccb1521..a0cc6cb 100644
--- a/libm/src/e_acosh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_acosh.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acosh.c,v 1.8 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_acosh(x)
  * Method :
diff --git a/libm/src/e_acoshf.c b/libm/upstream-freebsd/lib/msun/src/e_acoshf.c
similarity index 90%
rename from libm/src/e_acoshf.c
rename to libm/upstream-freebsd/lib/msun/src/e_acoshf.c
index 5257914..f529b20 100644
--- a/libm/src/e_acoshf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_acoshf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_acoshf.c,v 1.7 2002/05/28 17:03:12 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/upstream-freebsd/lib/msun/src/e_acosl.c b/libm/upstream-freebsd/lib/msun/src/e_acosl.c
new file mode 100644
index 0000000..d33c8fe
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_acosl.c
@@ -0,0 +1,87 @@
+
+/* @(#)e_acos.c 1.3 95/01/18 */
+/* FreeBSD: head/lib/msun/src/e_acos.c 176451 2008-02-22 02:30:36Z das */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See comments in e_acos.c.
+ * Converted to long double by David Schultz <das@FreeBSD.ORG>.
+ */
+
+#include <float.h>
+
+#include "invtrig.h"
+#include "math.h"
+#include "math_private.h"
+
+static const long double
+one=  1.00000000000000000000e+00;
+
+#ifdef __i386__
+/* XXX Work around the fact that gcc truncates long double constants on i386 */
+static volatile double
+pi1 =  3.14159265358979311600e+00,	/*  0x1.921fb54442d18p+1  */
+pi2 =  1.22514845490862001043e-16;	/*  0x1.1a80000000000p-53 */
+#define	pi	((long double)pi1 + pi2)
+#else
+static const long double
+pi =  3.14159265358979323846264338327950280e+00L;
+#endif
+
+long double
+acosl(long double x)
+{
+	union IEEEl2bits u;
+	long double z,p,q,r,w,s,c,df;
+	int16_t expsign, expt;
+	u.e = x;
+	expsign = u.xbits.expsign;
+	expt = expsign & 0x7fff;
+	if(expt >= BIAS) {	/* |x| >= 1 */
+	    if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0) {
+		if (expsign>0) return 0.0;	/* acos(1) = 0  */
+		else return pi+2.0*pio2_lo;	/* acos(-1)= pi */
+	    }
+	    return (x-x)/(x-x);		/* acos(|x|>1) is NaN */
+	}
+	if(expt<BIAS-1) {	/* |x| < 0.5 */
+	    if(expt<ACOS_CONST) return pio2_hi+pio2_lo;/*x tiny: acosl=pi/2*/
+	    z = x*x;
+	    p = P(z);
+	    q = Q(z);
+	    r = p/q;
+	    return pio2_hi - (x - (pio2_lo-x*r));
+	} else  if (expsign<0) {	/* x < -0.5 */
+	    z = (one+x)*0.5;
+	    p = P(z);
+	    q = Q(z);
+	    s = sqrtl(z);
+	    r = p/q;
+	    w = r*s-pio2_lo;
+	    return pi - 2.0*(s+w);
+	} else {			/* x > 0.5 */
+	    z = (one-x)*0.5;
+	    s = sqrtl(z);
+	    u.e = s;
+	    u.bits.manl = 0;
+	    df = u.e;
+	    c  = (z-df*df)/(s+df);
+	    p = P(z);
+	    q = Q(z);
+	    r = p/q;
+	    w = r*s+c;
+	    return 2.0*(df+w);
+	}
+}
diff --git a/libm/src/e_asin.c b/libm/upstream-freebsd/lib/msun/src/e_asin.c
similarity index 90%
rename from libm/src/e_asin.c
rename to libm/upstream-freebsd/lib/msun/src/e_asin.c
index 1ba7026..27de207 100644
--- a/libm/src/e_asin.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_asin.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_asin.c,v 1.11 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_asin(x)
  * Method :                  
@@ -45,6 +44,7 @@
  *
  */
 
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -82,14 +82,14 @@
 		return x*pio2_hi+x*pio2_lo;	
 	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */   
 	} else if (ix<0x3fe00000) {	/* |x|<0.5 */
-	    if(ix<0x3e400000) {		/* if |x| < 2**-27 */
+	    if(ix<0x3e500000) {		/* if |x| < 2**-26 */
 		if(huge+x>one) return x;/* return x with inexact if x!=0*/
-	    } else 
-		t = x*x;
-		p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
-		q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
-		w = p/q;
-		return x+x*w;
+	    }
+	    t = x*x;
+	    p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
+	    q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
+	    w = p/q;
+	    return x+x*w;
 	}
 	/* 1> |x|>= 0.5 */
 	w = one-fabs(x);
@@ -111,3 +111,7 @@
 	}    
 	if(hx>0) return t; else return -t;    
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(asin, asinl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/e_asinf.c b/libm/upstream-freebsd/lib/msun/src/e_asinf.c
new file mode 100644
index 0000000..deaabb6
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_asinf.c
@@ -0,0 +1,65 @@
+/* e_asinf.c -- float version of e_asin.c.
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "math.h"
+#include "math_private.h"
+
+static const float
+one =  1.0000000000e+00, /* 0x3F800000 */
+huge =  1.000e+30,
+	/* coefficient for R(x^2) */
+pS0 =  1.6666586697e-01,
+pS1 = -4.2743422091e-02,
+pS2 = -8.6563630030e-03,
+qS1 = -7.0662963390e-01;
+
+static const double
+pio2 =  1.570796326794896558e+00;
+
+float
+__ieee754_asinf(float x)
+{
+	double s;
+	float t,w,p,q;
+	int32_t hx,ix;
+	GET_FLOAT_WORD(hx,x);
+	ix = hx&0x7fffffff;
+	if(ix>=0x3f800000) {		/* |x| >= 1 */
+	    if(ix==0x3f800000)		/* |x| == 1 */
+		return x*pio2;		/* asin(+-1) = +-pi/2 with inexact */
+	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */
+	} else if (ix<0x3f000000) {	/* |x|<0.5 */
+	    if(ix<0x39800000) {		/* |x| < 2**-12 */
+		if(huge+x>one) return x;/* return x with inexact if x!=0*/
+	    }
+	    t = x*x;
+	    p = t*(pS0+t*(pS1+t*pS2));
+	    q = one+t*qS1;
+	    w = p/q;
+	    return x+x*w;
+	}
+	/* 1> |x|>= 0.5 */
+	w = one-fabsf(x);
+	t = w*(float)0.5;
+	p = t*(pS0+t*(pS1+t*pS2));
+	q = one+t*qS1;
+	s = sqrt(t);
+	w = p/q;
+	t = pio2-2.0*(s+s*w);
+	if(hx>0) return t; else return -t;
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_asinl.c b/libm/upstream-freebsd/lib/msun/src/e_asinl.c
new file mode 100644
index 0000000..a85765f
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_asinl.c
@@ -0,0 +1,77 @@
+
+/* @(#)e_asin.c 1.3 95/01/18 */
+/* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See comments in e_asin.c.
+ * Converted to long double by David Schultz <das@FreeBSD.ORG>.
+ */
+
+#include <float.h>
+
+#include "invtrig.h"
+#include "math.h"
+#include "math_private.h"
+
+static const long double
+one =  1.00000000000000000000e+00,
+huge = 1.000e+300;
+
+long double
+asinl(long double x)
+{
+	union IEEEl2bits u;
+	long double t=0.0,w,p,q,c,r,s;
+	int16_t expsign, expt;
+	u.e = x;
+	expsign = u.xbits.expsign;
+	expt = expsign & 0x7fff;
+	if(expt >= BIAS) {		/* |x|>= 1 */
+		if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0)
+		    /* asin(1)=+-pi/2 with inexact */
+		    return x*pio2_hi+x*pio2_lo;	
+	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */   
+	} else if (expt<BIAS-1) {	/* |x|<0.5 */
+	    if(expt<ASIN_LINEAR) {	/* if |x| is small, asinl(x)=x */
+		if(huge+x>one) return x;/* return x with inexact if x!=0*/
+	    }
+	    t = x*x;
+	    p = P(t);
+	    q = Q(t);
+	    w = p/q;
+	    return x+x*w;
+	}
+	/* 1> |x|>= 0.5 */
+	w = one-fabsl(x);
+	t = w*0.5;
+	p = P(t);
+	q = Q(t);
+	s = sqrtl(t);
+	if(u.bits.manh>=THRESH) { 	/* if |x| is close to 1 */
+	    w = p/q;
+	    t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
+	} else {
+	    u.e = s;
+	    u.bits.manl = 0;
+	    w = u.e;
+	    c  = (t-w*w)/(s+w);
+	    r  = p/q;
+	    p  = 2.0*s*r-(pio2_lo-2.0*c);
+	    q  = pio4_hi-2.0*w;
+	    t  = pio4_hi-(p-q);
+	}    
+	if(expsign>0) return t; else return -t;    
+}
diff --git a/libm/src/e_atan2.c b/libm/upstream-freebsd/lib/msun/src/e_atan2.c
similarity index 86%
rename from libm/src/e_atan2.c
rename to libm/upstream-freebsd/lib/msun/src/e_atan2.c
index 56c05a5..a4a985b 100644
--- a/libm/src/e_atan2.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atan2.c,v 1.10 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_atan2(y,x)
  * Method :
@@ -43,15 +42,19 @@
  * to produce the hexadecimal values shown.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
+static volatile double
+tiny  = 1.0e-300;
 static const double
-tiny  = 1.0e-300,
 zero  = 0.0,
 pi_o_4  = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
 pi_o_2  = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
-pi      = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
+pi      = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */
+static volatile double
 pi_lo   = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
 
 double
@@ -68,7 +71,7 @@
 	if(((ix|((lx|-lx)>>31))>0x7ff00000)||
 	   ((iy|((ly|-ly)>>31))>0x7ff00000))	/* x or y is NaN */
 	   return x+y;
-	if(((hx-0x3ff00000) | lx)==0) return atan(y);   /* x=1.0 */
+	if((hx-0x3ff00000|lx)==0) return atan(y);   /* x=1.0 */
 	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
 
     /* when y = 0 */
@@ -106,19 +109,21 @@
 
     /* compute y/x */
 	k = (iy-ix)>>20;
-	if(k > 60) z=pi_o_2+0.5*pi_lo; 	/* |y/x| >  2**60 */
-	else if(hx<0&&k<-60) z=0.0; 	/* |y|/x < -2**60 */
+	if(k > 60) {		 	/* |y/x| >  2**60 */
+	    z=pi_o_2+0.5*pi_lo;
+	    m&=1;
+	}
+	else if(hx<0&&k<-60) z=0.0; 	/* 0 > |y|/x > -2**-60 */
 	else z=atan(fabs(y/x));		/* safe to do y/x */
 	switch (m) {
 	    case 0: return       z  ;	/* atan(+,+) */
-	    case 1: {
-	    	      u_int32_t zh;
-		      GET_HIGH_WORD(zh,z);
-		      SET_HIGH_WORD(z,zh ^ 0x80000000);
-		    }
-		    return       z  ;	/* atan(-,+) */
+	    case 1: return      -z  ;	/* atan(-,+) */
 	    case 2: return  pi-(z-pi_lo);/* atan(+,-) */
 	    default: /* case 3 */
 	    	    return  (z-pi_lo)-pi;/* atan(-,-) */
 	}
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(atan2, atan2l);
+#endif
diff --git a/libm/src/e_atan2f.c b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c
similarity index 83%
rename from libm/src/e_atan2f.c
rename to libm/upstream-freebsd/lib/msun/src/e_atan2f.c
index 466d5d4..fc77bff 100644
--- a/libm/src/e_atan2f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2f.c
@@ -13,19 +13,20 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atan2f.c,v 1.7 2004/06/02 17:09:05 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
 
+static volatile float
+tiny  = 1.0e-30;
 static const float
-tiny  = 1.0e-30,
 zero  = 0.0,
 pi_o_4  = 7.8539818525e-01, /* 0x3f490fdb */
 pi_o_2  = 1.5707963705e+00, /* 0x3fc90fdb */
-pi      = 3.1415927410e+00, /* 0x40490fdb */
+pi      = 3.1415927410e+00; /* 0x40490fdb */
+static volatile float
 pi_lo   = -8.7422776573e-08; /* 0xb3bbbd2e */
 
 float
@@ -79,17 +80,15 @@
 
     /* compute y/x */
 	k = (iy-ix)>>23;
-	if(k > 60) z=pi_o_2+(float)0.5*pi_lo; 	/* |y/x| >  2**60 */
-	else if(hx<0&&k<-60) z=0.0; 	/* |y|/x < -2**60 */
+	if(k > 26) {			/* |y/x| >  2**26 */
+	    z=pi_o_2+(float)0.5*pi_lo;
+	    m&=1;
+	}
+	else if(k<-26&&hx<0) z=0.0; 	/* 0 > |y|/x > -2**-26 */
 	else z=atanf(fabsf(y/x));	/* safe to do y/x */
 	switch (m) {
 	    case 0: return       z  ;	/* atan(+,+) */
-	    case 1: {
-	    	      u_int32_t zh;
-		      GET_FLOAT_WORD(zh,z);
-		      SET_FLOAT_WORD(z,zh ^ 0x80000000);
-		    }
-		    return       z  ;	/* atan(-,+) */
+	    case 1: return      -z  ;	/* atan(-,+) */
 	    case 2: return  pi-(z-pi_lo);/* atan(+,-) */
 	    default: /* case 3 */
 	    	    return  (z-pi_lo)-pi;/* atan(-,-) */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_atan2l.c b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c
new file mode 100644
index 0000000..0326482
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_atan2l.c
@@ -0,0 +1,120 @@
+
+/* @(#)e_atan2.c 1.3 95/01/18 */
+/* FreeBSD: head/lib/msun/src/e_atan2.c 176451 2008-02-22 02:30:36Z das */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See comments in e_atan2.c.
+ * Converted to long double by David Schultz <das@FreeBSD.ORG>.
+ */
+
+#include <float.h>
+
+#include "invtrig.h"
+#include "math.h"
+#include "math_private.h"
+
+static volatile long double
+tiny  = 1.0e-300;
+static const long double
+zero  = 0.0;
+
+#ifdef __i386__
+/* XXX Work around the fact that gcc truncates long double constants on i386 */
+static volatile double
+pi1 =  3.14159265358979311600e+00,	/*  0x1.921fb54442d18p+1  */
+pi2 =  1.22514845490862001043e-16;	/*  0x1.1a80000000000p-53 */
+#define	pi	((long double)pi1 + pi2)
+#else
+static const long double
+pi =  3.14159265358979323846264338327950280e+00L;
+#endif
+
+long double
+atan2l(long double y, long double x)
+{
+	union IEEEl2bits ux, uy;
+	long double z;
+	int32_t k,m;
+	int16_t exptx, expsignx, expty, expsigny;
+
+	uy.e = y;
+	expsigny = uy.xbits.expsign;
+	expty = expsigny & 0x7fff;
+	ux.e = x;
+	expsignx = ux.xbits.expsign;
+	exptx = expsignx & 0x7fff;
+
+	if ((exptx==BIAS+LDBL_MAX_EXP &&
+	     ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)!=0) ||	/* x is NaN */
+	    (expty==BIAS+LDBL_MAX_EXP &&
+	     ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0))	/* y is NaN */
+	    return x+y;
+	if (expsignx==BIAS && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0)
+	    return atanl(y);					/* x=1.0 */
+	m = ((expsigny>>15)&1)|((expsignx>>14)&2);	/* 2*sign(x)+sign(y) */
+
+    /* when y = 0 */
+	if(expty==0 && ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)==0) {
+	    switch(m) {
+		case 0: 
+		case 1: return y; 	/* atan(+-0,+anything)=+-0 */
+		case 2: return  pi+tiny;/* atan(+0,-anything) = pi */
+		case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
+	    }
+	}
+    /* when x = 0 */
+	if(exptx==0 && ((ux.bits.manh&~LDBL_NBIT)|ux.bits.manl)==0)
+	    return (expsigny<0)?  -pio2_hi-tiny: pio2_hi+tiny;
+
+    /* when x is INF */
+	if(exptx==BIAS+LDBL_MAX_EXP) {
+	    if(expty==BIAS+LDBL_MAX_EXP) {
+		switch(m) {
+		    case 0: return  pio2_hi*0.5+tiny;/* atan(+INF,+INF) */
+		    case 1: return -pio2_hi*0.5-tiny;/* atan(-INF,+INF) */
+		    case 2: return  1.5*pio2_hi+tiny;/*atan(+INF,-INF)*/
+		    case 3: return -1.5*pio2_hi-tiny;/*atan(-INF,-INF)*/
+		}
+	    } else {
+		switch(m) {
+		    case 0: return  zero  ;	/* atan(+...,+INF) */
+		    case 1: return -zero  ;	/* atan(-...,+INF) */
+		    case 2: return  pi+tiny  ;	/* atan(+...,-INF) */
+		    case 3: return -pi-tiny  ;	/* atan(-...,-INF) */
+		}
+	    }
+	}
+    /* when y is INF */
+	if(expty==BIAS+LDBL_MAX_EXP)
+	    return (expsigny<0)? -pio2_hi-tiny: pio2_hi+tiny;
+
+    /* compute y/x */
+	k = expty-exptx;
+	if(k > LDBL_MANT_DIG+2) {			/* |y/x| huge */
+	    z=pio2_hi+pio2_lo;
+	    m&=1;
+	}
+	else if(expsignx<0&&k<-LDBL_MANT_DIG-2) z=0.0; 	/* |y/x| tiny, x<0 */
+	else z=atanl(fabsl(y/x));		/* safe to do y/x */
+	switch (m) {
+	    case 0: return       z  ;	/* atan(+,+) */
+	    case 1: return      -z  ;	/* atan(-,+) */
+	    case 2: return  pi-(z-pi_lo);/* atan(+,-) */
+	    default: /* case 3 */
+	    	    return  (z-pi_lo)-pi;/* atan(-,-) */
+	}
+}
diff --git a/libm/src/e_atanh.c b/libm/upstream-freebsd/lib/msun/src/e_atanh.c
similarity index 92%
rename from libm/src/e_atanh.c
rename to libm/upstream-freebsd/lib/msun/src/e_atanh.c
index 604875c..ab8a2e1 100644
--- a/libm/src/e_atanh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atanh.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atanh.c,v 1.7 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_atanh(x)
  * Method :
diff --git a/libm/src/e_atanhf.c b/libm/upstream-freebsd/lib/msun/src/e_atanhf.c
similarity index 89%
rename from libm/src/e_atanhf.c
rename to libm/upstream-freebsd/lib/msun/src/e_atanhf.c
index 64ebd3d..4bd6a8f 100644
--- a/libm/src/e_atanhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_atanhf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_atanhf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/e_cosh.c b/libm/upstream-freebsd/lib/msun/src/e_cosh.c
similarity index 86%
rename from libm/src/e_cosh.c
rename to libm/upstream-freebsd/lib/msun/src/e_cosh.c
index 40a943a..a363695 100644
--- a/libm/src/e_cosh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_cosh.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_cosh.c,v 1.8 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_cosh(x)
  * Method : 
@@ -46,7 +45,6 @@
 {
 	double t,w;
 	int32_t ix;
-	u_int32_t lx;
 
     /* High word of |x|. */
 	GET_HIGH_WORD(ix,x);
@@ -73,13 +71,8 @@
 	if (ix < 0x40862E42)  return half*__ieee754_exp(fabs(x));
 
     /* |x| in [log(maxdouble), overflowthresold] */
-	GET_LOW_WORD(lx,x);
-	if (ix<0x408633CE ||
-	      ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
-	    w = __ieee754_exp(half*fabs(x));
-	    t = half*w;
-	    return t*w;
-	}
+	if (ix<=0x408633CE)
+	    return __ldexp_exp(fabs(x), -1);
 
     /* |x| > overflowthresold, cosh(x) overflow */
 	return huge*huge;
diff --git a/libm/src/e_coshf.c b/libm/upstream-freebsd/lib/msun/src/e_coshf.c
similarity index 86%
rename from libm/src/e_coshf.c
rename to libm/upstream-freebsd/lib/msun/src/e_coshf.c
index f9df9b0..95a0d6e 100644
--- a/libm/src/e_coshf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_coshf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_coshf.c,v 1.7 2005/11/13 00:08:23 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -52,11 +51,8 @@
 	if (ix < 0x42b17217)  return half*__ieee754_expf(fabsf(x));
 
     /* |x| in [log(maxfloat), overflowthresold] */
-	if (ix<=0x42b2d4fc) {
-	    w = __ieee754_expf(half*fabsf(x));
-	    t = half*w;
-	    return t*w;
-	}
+	if (ix<=0x42b2d4fc)
+	    return __ldexp_expf(fabsf(x), -1);
 
     /* |x| > overflowthresold, cosh(x) overflow */
 	return huge*huge;
diff --git a/libm/src/e_exp.c b/libm/upstream-freebsd/lib/msun/src/e_exp.c
similarity index 89%
rename from libm/src/e_exp.c
rename to libm/upstream-freebsd/lib/msun/src/e_exp.c
index e261895..e432bc8 100644
--- a/libm/src/e_exp.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_exp.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_exp.c,v 1.10 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_exp(x)
  * Returns the exponential of x.
@@ -77,6 +76,8 @@
  * to produce the hexadecimal values shown.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -84,7 +85,6 @@
 one	= 1.0,
 halF[2]	= {0.5,-0.5,},
 huge	= 1.0e+300,
-twom1000= 9.33263618503218878990e-302,     /* 2**-1000=0x01700000,0*/
 o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */
 u_threshold= -7.45133219101941108420e+02,  /* 0xc0874910, 0xD52D3051 */
 ln2HI[2]   ={ 6.93147180369123816490e-01,  /* 0x3fe62e42, 0xfee00000 */
@@ -98,11 +98,13 @@
 P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
 P5   =  4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
 
+static volatile double
+twom1000= 9.33263618503218878990e-302;     /* 2**-1000=0x01700000,0*/
 
 double
 __ieee754_exp(double x)	/* default IEEE double exp */
 {
-	double y,hi=0.0,lo=0.0,c,t;
+	double y,hi=0.0,lo=0.0,c,t,twopk;
 	int32_t k=0,xsb;
 	u_int32_t hx;
 
@@ -133,7 +135,7 @@
 		hi = x - t*ln2HI[0];	/* t*ln2HI is exact here */
 		lo = t*ln2LO[0];
 	    }
-	    x  = hi - lo;
+	    STRICT_ASSIGN(double, x, hi - lo);
 	} 
 	else if(hx < 0x3e300000)  {	/* when |x|<2**-28 */
 	    if(huge+x>one) return one+x;/* trigger inexact */
@@ -142,18 +144,21 @@
 
     /* x is now in primary range */
 	t  = x*x;
+	if(k >= -1021)
+	    INSERT_WORDS(twopk,0x3ff00000+(k<<20), 0);
+	else
+	    INSERT_WORDS(twopk,0x3ff00000+((k+1000)<<20), 0);
 	c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
 	if(k==0) 	return one-((x*c)/(c-2.0)-x); 
 	else 		y = one-((lo-(x*c)/(2.0-c))-hi);
 	if(k >= -1021) {
-	    u_int32_t hy;
-	    GET_HIGH_WORD(hy,y);
-	    SET_HIGH_WORD(y,hy+(k<<20));	/* add k to y's exponent */
-	    return y;
+	    if (k==1024) return y*2.0*0x1p1023;
+	    return y*twopk;
 	} else {
-	    u_int32_t hy;
-	    GET_HIGH_WORD(hy,y);
-	    SET_HIGH_WORD(y,hy+((k+1000)<<20));	/* add k to y's exponent */
-	    return y*twom1000;
+	    return y*twopk*twom1000;
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(exp, expl);
+#endif
diff --git a/libm/src/e_expf.c b/libm/upstream-freebsd/lib/msun/src/e_expf.c
similarity index 70%
rename from libm/src/e_expf.c
rename to libm/upstream-freebsd/lib/msun/src/e_expf.c
index 4e06556..a479076 100644
--- a/libm/src/e_expf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_expf.c
@@ -13,9 +13,10 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_expf.c,v 1.10 2005/11/30 04:56:49 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -24,7 +25,6 @@
 one	= 1.0,
 halF[2]	= {0.5,-0.5,},
 huge	= 1.0e+30,
-twom100 = 7.8886090522e-31,      /* 2**-100=0x0d800000 */
 o_threshold=  8.8721679688e+01,  /* 0x42b17180 */
 u_threshold= -1.0397208405e+02,  /* 0xc2cff1b5 */
 ln2HI[2]   ={ 6.9314575195e-01,		/* 0x3f317200 */
@@ -32,16 +32,19 @@
 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 twom100 = 7.8886090522e-31;      /* 2**-100=0x0d800000 */
 
 float
-__ieee754_expf(float x)	/* default IEEE double exp */
+__ieee754_expf(float x)
 {
-	float y,hi=0.0,lo=0.0,c,t;
+	float y,hi=0.0,lo=0.0,c,t,twopk;
 	int32_t k=0,xsb;
 	u_int32_t hx;
 
@@ -69,27 +72,26 @@
 		hi = x - t*ln2HI[0];	/* t*ln2HI is exact here */
 		lo = t*ln2LO[0];
 	    }
-	    x  = hi - lo;
+	    STRICT_ASSIGN(float, x, hi - lo);
 	}
-	else if(hx < 0x31800000)  {	/* when |x|<2**-28 */
+	else if(hx < 0x39000000)  {	/* when |x|<2**-14 */
 	    if(huge+x>one) return one+x;/* trigger inexact */
 	}
 	else k = 0;
 
     /* x is now in primary range */
 	t  = x*x;
-	c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
+	if(k >= -125)
+	    SET_FLOAT_WORD(twopk,0x3f800000+(k<<23));
+	else
+	    SET_FLOAT_WORD(twopk,0x3f800000+((k+100)<<23));
+	c  = x - t*(P1+t*P2);
 	if(k==0) 	return one-((x*c)/(c-(float)2.0)-x);
 	else 		y = one-((lo-(x*c)/((float)2.0-c))-hi);
 	if(k >= -125) {
-	    u_int32_t hy;
-	    GET_FLOAT_WORD(hy,y);
-	    SET_FLOAT_WORD(y,hy+(k<<23));	/* add k to y's exponent */
-	    return y;
+	    if(k==128) return y*2.0F*0x1p127F;
+	    return y*twopk;
 	} else {
-	    u_int32_t hy;
-	    GET_FLOAT_WORD(hy,y);
-	    SET_FLOAT_WORD(y,hy+((k+100)<<23));	/* add k to y's exponent */
-	    return y*twom100;
+	    return y*twopk*twom100;
 	}
 }
diff --git a/libm/src/e_fmod.c b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
similarity index 96%
rename from libm/src/e_fmod.c
rename to libm/upstream-freebsd/lib/msun/src/e_fmod.c
index 3b3c169..720aa03 100644
--- a/libm/src/e_fmod.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmod.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_fmod.c,v 1.9 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* 
  * __ieee754_fmod(x,y)
diff --git a/libm/src/e_fmodf.c b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
similarity index 95%
rename from libm/src/e_fmodf.c
rename to libm/upstream-freebsd/lib/msun/src/e_fmodf.c
index 8b487ac..52ce373 100644
--- a/libm/src/e_fmodf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmodf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_fmodf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * __ieee754_fmodf(x,y)
diff --git a/libm/upstream-freebsd/lib/msun/src/e_fmodl.c b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c
new file mode 100644
index 0000000..e315f76
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_fmodl.c
@@ -0,0 +1,149 @@
+/* @(#)e_fmod.c 1.3 95/01/18 */
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	BIAS (LDBL_MAX_EXP - 1)
+
+#if LDBL_MANL_SIZE > 32
+typedef	uint64_t manl_t;
+#else
+typedef	uint32_t manl_t;
+#endif
+
+#if LDBL_MANH_SIZE > 32
+typedef	uint64_t manh_t;
+#else
+typedef	uint32_t manh_t;
+#endif
+
+/*
+ * These macros add and remove an explicit integer bit in front of the
+ * fractional mantissa, if the architecture doesn't have such a bit by
+ * default already.
+ */
+#ifdef LDBL_IMPLICIT_NBIT
+#define	SET_NBIT(hx)	((hx) | (1ULL << LDBL_MANH_SIZE))
+#define	HFRAC_BITS	LDBL_MANH_SIZE
+#else
+#define	SET_NBIT(hx)	(hx)
+#define	HFRAC_BITS	(LDBL_MANH_SIZE - 1)
+#endif
+
+#define	MANL_SHIFT	(LDBL_MANL_SIZE - 1)
+
+static const long double one = 1.0, Zero[] = {0.0, -0.0,};
+
+/*
+ * fmodl(x,y)
+ * Return x mod y in exact arithmetic
+ * Method: shift and subtract
+ *
+ * Assumptions:
+ * - The low part of the mantissa fits in a manl_t exactly.
+ * - The high part of the mantissa fits in an int64_t with enough room
+ *   for an explicit integer bit in front of the fractional bits.
+ */
+long double
+fmodl(long double x, long double y)
+{
+	union IEEEl2bits ux, uy;
+	int64_t hx,hz;	/* We need a carry bit even if LDBL_MANH_SIZE is 32. */
+	manh_t hy;
+	manl_t lx,ly,lz;
+	int ix,iy,n,sx;
+
+	ux.e = x;
+	uy.e = y;
+	sx = ux.bits.sign;
+
+    /* purge off exception values */
+	if((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */
+	   (ux.bits.exp == BIAS + LDBL_MAX_EXP) ||	 /* or x not finite */
+	   (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
+	    ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */
+	    return (x*y)/(x*y);
+	if(ux.bits.exp<=uy.bits.exp) {
+	    if((ux.bits.exp<uy.bits.exp) ||
+	       (ux.bits.manh<=uy.bits.manh &&
+		(ux.bits.manh<uy.bits.manh ||
+		 ux.bits.manl<uy.bits.manl))) {
+		return x;		/* |x|<|y| return x or x-y */
+	    }
+	    if(ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl) {
+		return Zero[sx];	/* |x|=|y| return x*0*/
+	    }
+	}
+
+    /* determine ix = ilogb(x) */
+	if(ux.bits.exp == 0) {	/* subnormal x */
+	    ux.e *= 0x1.0p512;
+	    ix = ux.bits.exp - (BIAS + 512);
+	} else {
+	    ix = ux.bits.exp - BIAS;
+	}
+
+    /* determine iy = ilogb(y) */
+	if(uy.bits.exp == 0) {	/* subnormal y */
+	    uy.e *= 0x1.0p512;
+	    iy = uy.bits.exp - (BIAS + 512);
+	} else {
+	    iy = uy.bits.exp - BIAS;
+	}
+
+    /* set up {hx,lx}, {hy,ly} and align y to x */
+	hx = SET_NBIT(ux.bits.manh);
+	hy = SET_NBIT(uy.bits.manh);
+	lx = ux.bits.manl;
+	ly = uy.bits.manl;
+
+    /* fix point fmod */
+	n = ix - iy;
+
+	while(n--) {
+	    hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	    if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;}
+	    else {
+		if ((hz|lz)==0)		/* return sign(x)*0 */
+		    return Zero[sx];
+		hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz;
+	    }
+	}
+	hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	if(hz>=0) {hx=hz;lx=lz;}
+
+    /* convert back to floating value and restore the sign */
+	if((hx|lx)==0)			/* return sign(x)*0 */
+	    return Zero[sx];
+	while(hx<(1ULL<<HFRAC_BITS)) {	/* normalize x */
+	    hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;
+	    iy -= 1;
+	}
+	ux.bits.manh = hx; /* The mantissa is truncated here if needed. */
+	ux.bits.manl = lx;
+	if (iy < LDBL_MIN_EXP) {
+	    ux.bits.exp = iy + (BIAS + 512);
+	    ux.e *= 0x1p-512;
+	} else {
+	    ux.bits.exp = iy + BIAS;
+	}
+	x = ux.e * one;		/* create necessary signal */
+	return x;		/* exact output */
+}
diff --git a/libm/src/e_gamma.c b/libm/upstream-freebsd/lib/msun/src/e_gamma.c
similarity index 84%
rename from libm/src/e_gamma.c
rename to libm/upstream-freebsd/lib/msun/src/e_gamma.c
index f52ff17..28fb5cc 100644
--- a/libm/src/e_gamma.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_gamma.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gamma.c,v 1.7 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_gamma(x)
  * Return the logarithm of the Gamma function of x.
diff --git a/libm/src/e_gamma_r.c b/libm/upstream-freebsd/lib/msun/src/e_gamma_r.c
similarity index 85%
rename from libm/src/e_gamma_r.c
rename to libm/upstream-freebsd/lib/msun/src/e_gamma_r.c
index be8339d..2c423dc 100644
--- a/libm/src/e_gamma_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_gamma_r.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gamma_r.c,v 1.7 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_gamma_r(x, signgamp)
  * Reentrant version of the logarithm of the Gamma function 
diff --git a/libm/src/e_gammaf.c b/libm/upstream-freebsd/lib/msun/src/e_gammaf.c
similarity index 85%
rename from libm/src/e_gammaf.c
rename to libm/upstream-freebsd/lib/msun/src/e_gammaf.c
index b5c2ec1..c1b1668 100644
--- a/libm/src/e_gammaf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_gammaf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gammaf.c,v 1.6 2002/05/28 17:03:12 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_gammaf(x)
  * Return the logarithm of the Gamma function of x.
diff --git a/libm/src/e_gammaf_r.c b/libm/upstream-freebsd/lib/msun/src/e_gammaf_r.c
similarity index 86%
rename from libm/src/e_gammaf_r.c
rename to libm/upstream-freebsd/lib/msun/src/e_gammaf_r.c
index d4300c3..9d7831b 100644
--- a/libm/src/e_gammaf_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_gammaf_r.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_gammaf_r.c,v 1.7 2002/05/28 18:15:03 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_gammaf_r(x, signgamp)
  * Reentrant version of the logarithm of the Gamma function
diff --git a/libm/src/e_hypot.c b/libm/upstream-freebsd/lib/msun/src/e_hypot.c
similarity index 91%
rename from libm/src/e_hypot.c
rename to libm/upstream-freebsd/lib/msun/src/e_hypot.c
index 11385f5..2398e98 100644
--- a/libm/src/e_hypot.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypot.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypot.c,v 1.9 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_hypot(x,y)
  *
@@ -47,13 +46,15 @@
  * 	than 1 ulps (units in the last place) 
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
 double
 __ieee754_hypot(double x, double y)
 {
-	double a=x,b=y,t1,t2,y1,y2,w;
+	double a,b,t1,t2,y1,y2,w;
 	int32_t j,k,ha,hb;
 
 	GET_HIGH_WORD(ha,x);
@@ -61,14 +62,15 @@
 	GET_HIGH_WORD(hb,y);
 	hb &= 0x7fffffff;
 	if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
-	SET_HIGH_WORD(a,ha);	/* a <- |a| */
-	SET_HIGH_WORD(b,hb);	/* b <- |b| */
+	a = fabs(a);
+	b = fabs(b);
 	if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */
 	k=0;
 	if(ha > 0x5f300000) {	/* a>2**500 */
 	   if(ha >= 0x7ff00000) {	/* Inf or NaN */
 	       u_int32_t low;
-	       w = a+b;			/* for sNaN */
+	       /* Use original arg order iff result is NaN; quieten sNaNs. */
+	       w = fabs(x+0.0)-fabs(y+0.0);
 	       GET_LOW_WORD(low,a);
 	       if(((ha&0xfffff)|low)==0) w = a;
 	       GET_LOW_WORD(low,b);
@@ -123,3 +125,7 @@
 	    return t1*w;
 	} else return w;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(hypot, hypotl);
+#endif
diff --git a/libm/src/e_hypotf.c b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c
similarity index 86%
rename from libm/src/e_hypotf.c
rename to libm/upstream-freebsd/lib/msun/src/e_hypotf.c
index 354075a..6d083e4 100644
--- a/libm/src/e_hypotf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypotf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_hypotf.c,v 1.9 2002/05/28 18:15:03 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -23,7 +22,7 @@
 float
 __ieee754_hypotf(float x, float y)
 {
-	float a=x,b=y,t1,t2,y1,y2,w;
+	float a,b,t1,t2,y1,y2,w;
 	int32_t j,k,ha,hb;
 
 	GET_FLOAT_WORD(ha,x);
@@ -31,13 +30,14 @@
 	GET_FLOAT_WORD(hb,y);
 	hb &= 0x7fffffff;
 	if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
-	SET_FLOAT_WORD(a,ha);	/* a <- |a| */
-	SET_FLOAT_WORD(b,hb);	/* b <- |b| */
+	a = fabsf(a);
+	b = fabsf(b);
 	if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
 	k=0;
 	if(ha > 0x58800000) {	/* a>2**50 */
 	   if(ha >= 0x7f800000) {	/* Inf or NaN */
-	       w = a+b;			/* for sNaN */
+	       /* Use original arg order iff result is NaN; quieten sNaNs. */
+	       w = fabsf(x+0.0F)-fabsf(y+0.0F);
 	       if(ha == 0x7f800000) w = a;
 	       if(hb == 0x7f800000) w = b;
 	       return w;
@@ -72,7 +72,7 @@
 	    a  = a+a;
 	    SET_FLOAT_WORD(y1,hb&0xfffff000);
 	    y2 = b - y1;
-	    SET_FLOAT_WORD(t1,ha+0x00800000);
+	    SET_FLOAT_WORD(t1,(ha+0x00800000)&0xfffff000);
 	    t2 = a - t1;
 	    w  = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
 	}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_hypotl.c b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c
new file mode 100644
index 0000000..7b5ab89
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_hypotl.c
@@ -0,0 +1,124 @@
+/* From: @(#)e_hypot.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* long double version of hypot().  See e_hypot.c for most comments. */
+
+#include <float.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	GET_LDBL_MAN(h, l, v) do {	\
+	union IEEEl2bits uv;		\
+					\
+	uv.e = v;			\
+	h = uv.bits.manh;		\
+	l = uv.bits.manl;		\
+} while (0)
+
+#undef GET_HIGH_WORD
+#define	GET_HIGH_WORD(i, v)	GET_LDBL_EXPSIGN(i, v)
+#undef SET_HIGH_WORD
+#define	SET_HIGH_WORD(v, i)	SET_LDBL_EXPSIGN(v, i)
+
+#define	DESW(exp)	(exp)		/* delta expsign word */
+#define	ESW(exp)	(MAX_EXP - 1 + (exp))	/* expsign word */
+#define	MANT_DIG	LDBL_MANT_DIG
+#define	MAX_EXP		LDBL_MAX_EXP
+
+#if LDBL_MANL_SIZE > 32
+typedef	uint64_t man_t;
+#else
+typedef	uint32_t man_t;
+#endif
+
+long double
+hypotl(long double x, long double y)
+{
+	long double a=x,b=y,t1,t2,y1,y2,w;
+	int32_t j,k,ha,hb;
+
+	GET_HIGH_WORD(ha,x);
+	ha &= 0x7fff;
+	GET_HIGH_WORD(hb,y);
+	hb &= 0x7fff;
+	if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
+	a = fabsl(a);
+	b = fabsl(b);
+	if((ha-hb)>DESW(MANT_DIG+7)) {return a+b;} /* x/y > 2**(MANT_DIG+7) */
+	k=0;
+	if(ha > ESW(MAX_EXP/2-12)) {	/* a>2**(MAX_EXP/2-12) */
+	   if(ha >= ESW(MAX_EXP)) {	/* Inf or NaN */
+	       man_t manh, manl;
+	       /* Use original arg order iff result is NaN; quieten sNaNs. */
+	       w = fabsl(x+0.0)-fabsl(y+0.0);
+	       GET_LDBL_MAN(manh,manl,a);
+	       if (manh == LDBL_NBIT && manl == 0) w = a;
+	       GET_LDBL_MAN(manh,manl,b);
+	       if (hb >= ESW(MAX_EXP) && manh == LDBL_NBIT && manl == 0) w = b;
+	       return w;
+	   }
+	   /* scale a and b by 2**-(MAX_EXP/2+88) */
+	   ha -= DESW(MAX_EXP/2+88); hb -= DESW(MAX_EXP/2+88);
+	   k += MAX_EXP/2+88;
+	   SET_HIGH_WORD(a,ha);
+	   SET_HIGH_WORD(b,hb);
+	}
+	if(hb < ESW(-(MAX_EXP/2-12))) {	/* b < 2**-(MAX_EXP/2-12) */
+	    if(hb <= 0) {		/* subnormal b or 0 */
+	        man_t manh, manl;
+		GET_LDBL_MAN(manh,manl,b);
+		if((manh|manl)==0) return a;
+		t1=0;
+		SET_HIGH_WORD(t1,ESW(MAX_EXP-2));	/* t1=2^(MAX_EXP-2) */
+		b *= t1;
+		a *= t1;
+		k -= MAX_EXP-2;
+	    } else {		/* scale a and b by 2^(MAX_EXP/2+88) */
+		ha += DESW(MAX_EXP/2+88);
+		hb += DESW(MAX_EXP/2+88);
+		k -= MAX_EXP/2+88;
+		SET_HIGH_WORD(a,ha);
+		SET_HIGH_WORD(b,hb);
+	    }
+	}
+    /* medium size a and b */
+	w = a-b;
+	if (w>b) {
+	    t1 = a;
+	    union IEEEl2bits uv;
+	    uv.e = t1; uv.bits.manl = 0; t1 = uv.e;
+	    t2 = a-t1;
+	    w  = sqrtl(t1*t1-(b*(-b)-t2*(a+t1)));
+	} else {
+	    a  = a+a;
+	    y1 = b;
+	    union IEEEl2bits uv;
+	    uv.e = y1; uv.bits.manl = 0; y1 = uv.e;
+	    y2 = b - y1;
+	    t1 = a;
+	    uv.e = t1; uv.bits.manl = 0; t1 = uv.e;
+	    t2 = a - t1;
+	    w  = sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b)));
+	}
+	if(k!=0) {
+	    u_int32_t high;
+	    t1 = 1.0;
+	    GET_HIGH_WORD(high,t1);
+	    SET_HIGH_WORD(t1,high+DESW(k));
+	    return t1*w;
+	} else return w;
+}
diff --git a/libm/src/e_j0.c b/libm/upstream-freebsd/lib/msun/src/e_j0.c
similarity index 98%
rename from libm/src/e_j0.c
rename to libm/upstream-freebsd/lib/msun/src/e_j0.c
index d99bf11..8320f25 100644
--- a/libm/src/e_j0.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j0.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j0.c,v 1.8 2005/02/04 18:26:05 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_j0(x), __ieee754_y0(x)
  * Bessel function of the first and second kinds of order zero.
diff --git a/libm/src/e_j0f.c b/libm/upstream-freebsd/lib/msun/src/e_j0f.c
similarity index 96%
rename from libm/src/e_j0f.c
rename to libm/upstream-freebsd/lib/msun/src/e_j0f.c
index 6b566bf..c45faf3 100644
--- a/libm/src/e_j0f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j0f.c
@@ -1,6 +1,5 @@
 /* e_j0f.c -- float version of e_j0.c.
  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- * Bugs in __ieee754_j0f and __ieee754_y0f fixed by Scott Turner 01/16/2010
  */
 
 /*
@@ -14,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j0f.c,v 1.7 2002/05/28 18:15:03 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -64,7 +62,7 @@
 	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
 	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
 	 */
-		if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*cc)/sqrtf(x);
+		if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(x);
 		else {
 		    u = pzerof(x); v = qzerof(x);
 		    z = invsqrtpi*(u*cc-v*ss)/sqrtf(x);
@@ -108,7 +106,7 @@
 	int32_t hx,ix;
 
 	GET_FLOAT_WORD(hx,x);
-        ix = hx&0x7fffffff;
+        ix = 0x7fffffff&hx;
     /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0  */
 	if(ix>=0x7f800000) return  one/(x+x*x);
         if(ix==0) return -one/zero;
@@ -138,7 +136,7 @@
                     if ((s*c)<zero) cc = z/ss;
                     else            ss = z/cc;
                 }
-                if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*ss)/sqrtf(x);
+                if(ix>0x80000000) z = (invsqrtpi*ss)/sqrtf(x);
                 else {
                     u = pzerof(x); v = qzerof(x);
                     z = invsqrtpi*(u*ss+v*cc)/sqrtf(x);
diff --git a/libm/src/e_j1.c b/libm/upstream-freebsd/lib/msun/src/e_j1.c
similarity index 98%
rename from libm/src/e_j1.c
rename to libm/upstream-freebsd/lib/msun/src/e_j1.c
index 4dbf222..63800ad 100644
--- a/libm/src/e_j1.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j1.c,v 1.8 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_j1(x), __ieee754_y1(x)
  * Bessel function of the first and second kinds of order zero.
diff --git a/libm/src/e_j1f.c b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
similarity index 97%
rename from libm/src/e_j1f.c
rename to libm/upstream-freebsd/lib/msun/src/e_j1f.c
index ea05774..88e2d83 100644
--- a/libm/src/e_j1f.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_j1f.c
@@ -1,6 +1,5 @@
 /* e_j1f.c -- float version of e_j1.c.
  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
- * Bug in __ieee754_j1f fixed by Scott Turner 1/16/2010
  */
 
 /*
@@ -14,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_j1f.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -65,7 +63,7 @@
 	 * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
 	 * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
 	 */
-		if(((uint32_t)hx)>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
+		if(ix>0x80000000) z = (invsqrtpi*cc)/sqrtf(y);
 		else {
 		    u = ponef(y); v = qonef(y);
 		    z = invsqrtpi*(u*cc-v*ss)/sqrtf(y);
diff --git a/libm/src/e_jn.c b/libm/upstream-freebsd/lib/msun/src/e_jn.c
similarity index 97%
rename from libm/src/e_jn.c
rename to libm/upstream-freebsd/lib/msun/src/e_jn.c
index 413b22d..8b0bc62 100644
--- a/libm/src/e_jn.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_jn.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_jn.c,v 1.9 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * __ieee754_jn(n, x), __ieee754_yn(n, x)
@@ -201,7 +200,12 @@
 			}
 	     	    }
 		}
-	    	b = (t*__ieee754_j0(x)/b);
+		z = __ieee754_j0(x);
+		w = __ieee754_j1(x);
+		if (fabs(z) >= fabs(w))
+		    b = (t*z/b);
+		else
+		    b = (t*w/a);
 	    }
 	}
 	if(sgn==1) return -b; else return b;
diff --git a/libm/src/e_jnf.c b/libm/upstream-freebsd/lib/msun/src/e_jnf.c
similarity index 94%
rename from libm/src/e_jnf.c
rename to libm/upstream-freebsd/lib/msun/src/e_jnf.c
index a61fb68..f564aec 100644
--- a/libm/src/e_jnf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_jnf.c
@@ -13,15 +13,13 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_jnf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
 
 static const float
-invsqrtpi=  5.6418961287e-01, /* 0x3f106ebb */
 two   =  2.0000000000e+00, /* 0x40000000 */
 one   =  1.0000000000e+00; /* 0x3F800000 */
 
@@ -154,7 +152,12 @@
 			}
 	     	    }
 		}
-	    	b = (t*__ieee754_j0f(x)/b);
+		z = __ieee754_j0f(x);
+		w = __ieee754_j1f(x);
+		if (fabsf(z) >= fabsf(w))
+		    b = (t*z/b);
+		else
+		    b = (t*w/a);
 	    }
 	}
 	if(sgn==1) return -b; else return b;
@@ -186,7 +189,7 @@
 	b = __ieee754_y1f(x);
 	/* quit if b is -inf */
 	GET_FLOAT_WORD(ib,b);
-	for(i=1; i<n && (((uint32_t)ib) != 0xff800000); i++){
+	for(i=1;i<n&&ib!=0xff800000;i++){
 	    temp = b;
 	    b = ((float)(i+i)/x)*b - a;
 	    GET_FLOAT_WORD(ib,b);
diff --git a/libm/src/e_lgamma.c b/libm/upstream-freebsd/lib/msun/src/e_lgamma.c
similarity index 84%
rename from libm/src/e_lgamma.c
rename to libm/upstream-freebsd/lib/msun/src/e_lgamma.c
index 87ad41a..4674d9b 100644
--- a/libm/src/e_lgamma.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgamma.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgamma.c,v 1.8 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_lgamma(x)
  * Return the logarithm of the Gamma function of x.
diff --git a/libm/src/e_lgamma_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
similarity index 96%
rename from libm/src/e_lgamma_r.c
rename to libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
index 68dbfd0..1cff592 100644
--- a/libm/src/e_lgamma_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
@@ -12,9 +12,8 @@
  *
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgamma_r.c,v 1.8 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_lgamma_r(x, signgamp)
  * Reentrant version of the logarithm of the Gamma function 
@@ -76,10 +75,11 @@
  *		
  *   5. Special Cases
  *		lgamma(2+s) ~ s*(1-Euler) for tiny s
- *		lgamma(1)=lgamma(2)=0
- *		lgamma(x) ~ -log(x) for tiny x
- *		lgamma(0) = lgamma(inf) = inf
- *	 	lgamma(-integer) = +-inf
+ *		lgamma(1) = lgamma(2) = 0
+ *		lgamma(x) ~ -log(|x|) for tiny x
+ *		lgamma(0) = lgamma(neg.integer) = inf and raise divide-by-zero
+ *		lgamma(inf) = inf
+ *		lgamma(-inf) = inf (bug for bug compatible with C99!?)
  *	
  */
 
@@ -205,11 +205,12 @@
 __ieee754_lgamma_r(double x, int *signgamp)
 {
 	double t,y,z,nadj,p,p1,p2,p3,q,r,w;
-	int i,hx,lx,ix;
+	int32_t hx;
+	int i,lx,ix;
 
 	EXTRACT_WORDS(hx,lx,x);
 
-    /* purge off +-inf, NaN, +-0, and negative arguments */
+    /* purge off +-inf, NaN, +-0, tiny and negative arguments */
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7ff00000) return x*x;
@@ -268,7 +269,6 @@
 	}
 	else if(ix<0x40200000) { 			/* x < 8.0 */
 	    i = (int)x;
-	    t = zero;
 	    y = x-(double)i;
 	    p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
 	    q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
diff --git a/libm/src/e_lgammaf.c b/libm/upstream-freebsd/lib/msun/src/e_lgammaf.c
similarity index 85%
rename from libm/src/e_lgammaf.c
rename to libm/upstream-freebsd/lib/msun/src/e_lgammaf.c
index b1f48d5..1e2c552 100644
--- a/libm/src/e_lgammaf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgammaf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgammaf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_lgammaf(x)
  * Return the logarithm of the Gamma function of x.
diff --git a/libm/src/e_lgammaf_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
similarity index 96%
rename from libm/src/e_lgammaf_r.c
rename to libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
index 3b55208..e2d90ef 100644
--- a/libm/src/e_lgammaf_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_lgammaf_r.c,v 1.9 2005/11/28 08:32:15 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -139,11 +138,12 @@
 __ieee754_lgammaf_r(float x, int *signgamp)
 {
 	float t,y,z,nadj,p,p1,p2,p3,q,r,w;
-	int i,hx,ix;
+	int32_t hx;
+	int i,ix;
 
 	GET_FLOAT_WORD(hx,x);
 
-    /* purge off +-inf, NaN, +-0, and negative arguments */
+    /* purge off +-inf, NaN, +-0, tiny and negative arguments */
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7f800000) return x*x;
@@ -202,7 +202,6 @@
 	}
 	else if(ix<0x41000000) { 			/* x < 8.0 */
 	    i = (int)x;
-	    t = zero;
 	    y = x-(float)i;
 	    p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
 	    q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
diff --git a/libm/src/e_log.c b/libm/upstream-freebsd/lib/msun/src/e_log.c
similarity index 93%
rename from libm/src/e_log.c
rename to libm/upstream-freebsd/lib/msun/src/e_log.c
index 2dbf057..204fb48 100644
--- a/libm/src/e_log.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_log.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log.c,v 1.10 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_log(x)
  * Return the logrithm of x
@@ -107,9 +106,15 @@
 	SET_HIGH_WORD(x,hx|(i^0x3ff00000));	/* normalize x or x/2 */
 	k += (i>>20);
 	f = x-1.0;
-	if((0x000fffff&(2+hx))<3) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;  else {dk=(double)k;
-				 return dk*ln2_hi+dk*ln2_lo;}
+	if((0x000fffff&(2+hx))<3) {	/* -2**-20 <= f < 2**-20 */
+	    if(f==zero) {
+		if(k==0) {
+		    return zero;
+		} else {
+		    dk=(double)k;
+		    return dk*ln2_hi+dk*ln2_lo;
+		}
+	    }
 	    R = f*f*(0.5-0.33333333333333333*f);
 	    if(k==0) return f-R; else {dk=(double)k;
 	    	     return dk*ln2_hi-((R-dk*ln2_lo)-f);}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_log10.c b/libm/upstream-freebsd/lib/msun/src/e_log10.c
new file mode 100644
index 0000000..104d257
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_log10.c
@@ -0,0 +1,87 @@
+
+/* @(#)e_log10.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Return the base 10 logarithm of x.  See e_log.c and k_log.h for most
+ * comments.
+ *
+ *    log10(x) = (f - 0.5*f*f + k_log1p(f)) / ln10 + k * log10(2)
+ * in not-quite-routine extra precision.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_log.h"
+
+static const double
+two54      =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+ivln10hi   =  4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */
+ivln10lo   =  2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */
+log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
+log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+
+static const double zero   =  0.0;
+
+double
+__ieee754_log10(double x)
+{
+	double f,hfsq,hi,lo,r,val_hi,val_lo,w,y,y2;
+	int32_t i,k,hx;
+	u_int32_t lx;
+
+	EXTRACT_WORDS(hx,lx,x);
+
+	k=0;
+	if (hx < 0x00100000) {			/* x < 2**-1022  */
+	    if (((hx&0x7fffffff)|lx)==0)
+		return -two54/zero;		/* log(+-0)=-inf */
+	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
+	    k -= 54; x *= two54; /* subnormal number, scale up x */
+	    GET_HIGH_WORD(hx,x);
+	}
+	if (hx >= 0x7ff00000) return x+x;
+	if (hx == 0x3ff00000 && lx == 0)
+	    return zero;			/* log(1) = +0 */
+	k += (hx>>20)-1023;
+	hx &= 0x000fffff;
+	i = (hx+0x95f64)&0x100000;
+	SET_HIGH_WORD(x,hx|(i^0x3ff00000));	/* normalize x or x/2 */
+	k += (i>>20);
+	y = (double)k;
+	f = x - 1.0;
+	hfsq = 0.5*f*f;
+	r = k_log1p(f);
+
+	/* 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/libm/upstream-freebsd/lib/msun/src/e_log10f.c b/libm/upstream-freebsd/lib/msun/src/e_log10f.c
new file mode 100644
index 0000000..c876594
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_log10f.c
@@ -0,0 +1,71 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Float version of e_log10.c.  See the latter for most comments.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_logf.h"
+
+static const float
+two25      =  3.3554432000e+07, /* 0x4c000000 */
+ivln10hi   =  4.3432617188e-01, /* 0x3ede6000 */
+ivln10lo   = -3.1689971365e-05, /* 0xb804ead9 */
+log10_2hi  =  3.0102920532e-01, /* 0x3e9a2080 */
+log10_2lo  =  7.9034151668e-07; /* 0x355427db */
+
+static const float zero   =  0.0;
+
+float
+__ieee754_log10f(float x)
+{
+	float f,hfsq,hi,lo,r,y;
+	int32_t i,k,hx;
+
+	GET_FLOAT_WORD(hx,x);
+
+	k=0;
+	if (hx < 0x00800000) {			/* x < 2**-126  */
+	    if ((hx&0x7fffffff)==0)
+		return -two25/zero;		/* log(+-0)=-inf */
+	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
+	    k -= 25; x *= two25; /* subnormal number, scale up x */
+	    GET_FLOAT_WORD(hx,x);
+	}
+	if (hx >= 0x7f800000) return x+x;
+	if (hx == 0x3f800000)
+	    return zero;			/* log(1) = +0 */
+	k += (hx>>23)-127;
+	hx &= 0x007fffff;
+	i = (hx+(0x4afb0d))&0x800000;
+	SET_FLOAT_WORD(x,hx|(i^0x3f800000));	/* normalize x or x/2 */
+	k += (i>>23);
+	y = (float)k;
+	f = x - (float)1.0;
+	hfsq = (float)0.5*f*f;
+	r = k_log1pf(f);
+
+	/* See e_log2f.c and e_log2.c for details. */
+	if (sizeof(float_t) > sizeof(float))
+		return (r - hfsq + f) * ((float_t)ivln10lo + ivln10hi) +
+		    y * ((float_t)log10_2lo + log10_2hi);
+	hi = f - hfsq;
+	GET_FLOAT_WORD(hx,hi);
+	SET_FLOAT_WORD(hi,hx&0xfffff000);
+	lo = (f - hi) - hfsq + r;
+	return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi +
+	    y*log10_2hi;
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_log2.c b/libm/upstream-freebsd/lib/msun/src/e_log2.c
new file mode 100644
index 0000000..1fc44a5
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_log2.c
@@ -0,0 +1,110 @@
+
+/* @(#)e_log10.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Return the base 2 logarithm of x.  See e_log.c and k_log.h for most
+ * comments.
+ *
+ * This reduces x to {k, 1+f} exactly as in e_log.c, then calls the kernel,
+ * then does the combining and scaling steps
+ *    log2(x) = (f - 0.5*f*f + k_log1p(f)) / ln2 + k
+ * in not-quite-routine extra precision.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_log.h"
+
+static const double
+two54      =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+ivln2hi    =  1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */
+ivln2lo    =  1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */
+
+static const double zero   =  0.0;
+
+double
+__ieee754_log2(double x)
+{
+	double f,hfsq,hi,lo,r,val_hi,val_lo,w,y;
+	int32_t i,k,hx;
+	u_int32_t lx;
+
+	EXTRACT_WORDS(hx,lx,x);
+
+	k=0;
+	if (hx < 0x00100000) {			/* x < 2**-1022  */
+	    if (((hx&0x7fffffff)|lx)==0)
+		return -two54/zero;		/* log(+-0)=-inf */
+	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
+	    k -= 54; x *= two54; /* subnormal number, scale up x */
+	    GET_HIGH_WORD(hx,x);
+	}
+	if (hx >= 0x7ff00000) return x+x;
+	if (hx == 0x3ff00000 && lx == 0)
+	    return zero;			/* log(1) = +0 */
+	k += (hx>>20)-1023;
+	hx &= 0x000fffff;
+	i = (hx+0x95f64)&0x100000;
+	SET_HIGH_WORD(x,hx|(i^0x3ff00000));	/* normalize x or x/2 */
+	k += (i>>20);
+	y = (double)k;
+	f = x - 1.0;
+	hfsq = 0.5*f*f;
+	r = k_log1p(f);
+
+	/*
+	 * f-hfsq must (for args near 1) be evaluated in extra precision
+	 * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2).
+	 * This is fairly efficient since f-hfsq only depends on f, so can
+	 * be evaluated in parallel with R.  Not combining hfsq with R also
+	 * keeps R small (though not as small as a true `lo' term would be),
+	 * so that extra precision is not needed for terms involving R.
+	 *
+	 * Compiler bugs involving extra precision used to break Dekker's
+	 * theorem for spitting f-hfsq as hi+lo, unless double_t was used
+	 * or the multi-precision calculations were avoided when double_t
+	 * has extra precision.  These problems are now automatically
+	 * avoided as a side effect of the optimization of combining the
+	 * Dekker splitting step with the clear-low-bits step.
+	 *
+	 * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra
+	 * precision to avoid a very large cancellation when x is very near
+	 * these values.  Unlike the above cancellations, this problem is
+	 * specific to base 2.  It is strange that adding +-1 is so much
+	 * harder than adding +-ln2 or +-log10_2.
+	 *
+	 * This uses Dekker's theorem to normalize y+val_hi, so the
+	 * compiler bugs are back in some configurations, sigh.  And I
+	 * don't want to used double_t to avoid them, since that gives a
+	 * pessimization and the support for avoiding the pessimization
+	 * is not yet available.
+	 *
+	 * The multi-precision calculations for the multiplications are
+	 * routine.
+	 */
+	hi = f - hfsq;
+	SET_LOW_WORD(hi,0);
+	lo = (f - hi) - hfsq + r;
+	val_hi = hi*ivln2hi;
+	val_lo = (lo+hi)*ivln2lo + lo*ivln2hi;
+
+	/* spadd(val_hi, val_lo, y), except for not using double_t: */
+	w = y + val_hi;
+	val_lo += (y - w) + val_hi;
+	val_hi = w;
+
+	return val_lo + val_hi;
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_log2f.c b/libm/upstream-freebsd/lib/msun/src/e_log2f.c
new file mode 100644
index 0000000..7166346
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_log2f.c
@@ -0,0 +1,81 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Float version of e_log2.c.  See the latter for most comments.
+ */
+
+#include "math.h"
+#include "math_private.h"
+#include "k_logf.h"
+
+static const float
+two25      =  3.3554432000e+07, /* 0x4c000000 */
+ivln2hi    =  1.4428710938e+00, /* 0x3fb8b000 */
+ivln2lo    = -1.7605285393e-04; /* 0xb9389ad4 */
+
+static const float zero   =  0.0;
+
+float
+__ieee754_log2f(float x)
+{
+	float f,hfsq,hi,lo,r,y;
+	int32_t i,k,hx;
+
+	GET_FLOAT_WORD(hx,x);
+
+	k=0;
+	if (hx < 0x00800000) {			/* x < 2**-126  */
+	    if ((hx&0x7fffffff)==0)
+		return -two25/zero;		/* log(+-0)=-inf */
+	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
+	    k -= 25; x *= two25; /* subnormal number, scale up x */
+	    GET_FLOAT_WORD(hx,x);
+	}
+	if (hx >= 0x7f800000) return x+x;
+	if (hx == 0x3f800000)
+	    return zero;			/* log(1) = +0 */
+	k += (hx>>23)-127;
+	hx &= 0x007fffff;
+	i = (hx+(0x4afb0d))&0x800000;
+	SET_FLOAT_WORD(x,hx|(i^0x3f800000));	/* normalize x or x/2 */
+	k += (i>>23);
+	y = (float)k;
+	f = x - (float)1.0;
+	hfsq = (float)0.5*f*f;
+	r = k_log1pf(f);
+
+	/*
+	 * We no longer need to avoid falling into the multi-precision
+	 * calculations due to compiler bugs breaking Dekker's theorem.
+	 * Keep avoiding this as an optimization.  See e_log2.c for more
+	 * details (some details are here only because the optimization
+	 * is not yet available in double precision).
+	 *
+	 * Another compiler bug turned up.  With gcc on i386,
+	 * (ivln2lo + ivln2hi) would be evaluated in float precision
+	 * despite runtime evaluations using double precision.  So we
+	 * must cast one of its terms to float_t.  This makes the whole
+	 * expression have type float_t, so return is forced to waste
+	 * time clobbering its extra precision.
+	 */
+	if (sizeof(float_t) > sizeof(float))
+		return (r - hfsq + f) * ((float_t)ivln2lo + ivln2hi) + y;
+
+	hi = f - hfsq;
+	GET_FLOAT_WORD(hx,hi);
+	SET_FLOAT_WORD(hi,hx&0xfffff000);
+	lo = (f - hi) - hfsq + r;
+	return (lo+hi)*ivln2lo + lo*ivln2hi + hi*ivln2hi + y;
+}
diff --git a/libm/src/e_logf.c b/libm/upstream-freebsd/lib/msun/src/e_logf.c
similarity index 88%
rename from libm/src/e_logf.c
rename to libm/upstream-freebsd/lib/msun/src/e_logf.c
index 7cee2ab..c3be6ed 100644
--- a/libm/src/e_logf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_logf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_logf.c,v 1.8 2005/11/12 18:20:09 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -55,9 +54,15 @@
 	SET_FLOAT_WORD(x,ix|(i^0x3f800000));	/* normalize x or x/2 */
 	k += (i>>23);
 	f = x-(float)1.0;
-	if((0x007fffff&(15+ix))<16) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;  else {dk=(float)k;
-				 return dk*ln2_hi+dk*ln2_lo;}
+	if((0x007fffff&(0x8000+ix))<0xc000) {	/* -2**-9 <= f < 2**-9 */
+	    if(f==zero) {
+		if(k==0) {
+		    return zero;
+		} else {
+		    dk=(float)k;
+		    return dk*ln2_hi+dk*ln2_lo;
+		}
+	    }
 	    R = f*f*((float)0.5-(float)0.33333333333333333*f);
 	    if(k==0) return f-R; else {dk=(float)k;
 	    	     return dk*ln2_hi-((R-dk*ln2_lo)-f);}
diff --git a/libm/src/e_pow.c b/libm/upstream-freebsd/lib/msun/src/e_pow.c
similarity index 96%
rename from libm/src/e_pow.c
rename to libm/upstream-freebsd/lib/msun/src/e_pow.c
index d213132..7607a4a 100644
--- a/libm/src/e_pow.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_pow.c
@@ -9,9 +9,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_pow.c,v 1.11 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_pow(x,y) return x**y
  *
@@ -110,10 +109,13 @@
     /* y==zero: x**0 = 1 */
 	if((iy|ly)==0) return one; 	
 
-    /* +-NaN return x+y */
+    /* x==1: 1**y = 1, even if y is NaN */
+	if (hx==0x3ff00000 && lx == 0) return one;
+
+    /* y!=zero: result is NaN if either arg is NaN */
 	if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
 	   iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) 
-		return x+y;	
+		return (x+0.0)+(y+0.0);
 
     /* determine if y is an odd int when x < 0
      * yisint = 0	... y is not an integer
@@ -139,7 +141,7 @@
 	if(ly==0) { 	
 	    if (iy==0x7ff00000) {	/* y is +-inf */
 	        if(((ix-0x3ff00000)|lx)==0)
-		    return  y - y;	/* inf**+-1 is NaN */
+		    return  one;	/* (-1)**+-inf is NaN */
 	        else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
 		    return (hy>=0)? y: zero;
 	        else			/* (|x|<1)**-,+inf = inf,0 */
diff --git a/libm/src/e_powf.c b/libm/upstream-freebsd/lib/msun/src/e_powf.c
similarity index 94%
rename from libm/src/e_powf.c
rename to libm/upstream-freebsd/lib/msun/src/e_powf.c
index 41f08dd..5c46478 100644
--- a/libm/src/e_powf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_powf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_powf.c,v 1.12 2004/06/01 19:33:30 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -47,8 +46,8 @@
 lg2_l  =  1.42860654e-06, /* 0x35bfbe8c */
 ovt =  4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */
 cp    =  9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */
-cp_h  =  9.6179199219e-01, /* 0x3f763800 =head of cp */
-cp_l  =  4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */
+cp_h  =  9.6191406250e-01, /* 0x3f764000 =12b cp */
+cp_l  = -1.1736857402e-04, /* 0xb8f623c6 =tail of cp_h */
 ivln2    =  1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */
 ivln2_h  =  1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/
 ivln2_l  =  7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/
@@ -68,10 +67,13 @@
     /* y==zero: x**0 = 1 */
 	if(iy==0) return one;
 
-    /* +-NaN return x+y */
+    /* x==1: 1**y = 1, even if y is NaN */
+	if (hx==0x3f800000) return one;
+
+    /* y!=zero: result is NaN if either arg is NaN */
 	if(ix > 0x7f800000 ||
 	   iy > 0x7f800000)
-		return x+y;
+		return (x+0.0F)+(y+0.0F);
 
     /* determine if y is an odd int when x < 0
      * yisint = 0	... y is not an integer
@@ -91,7 +93,7 @@
     /* special value of y */
 	if (iy==0x7f800000) {	/* y is +-inf */
 	    if (ix==0x3f800000)
-	        return  y - y;	/* inf**+-1 is NaN */
+	        return  one;	/* (-1)**+-inf is NaN */
 	    else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */
 	        return (hy>=0)? y: zero;
 	    else			/* (|x|<1)**-,+inf = inf,0 */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_rem_pio2.c b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2.c
new file mode 100644
index 0000000..be2630b
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2.c
@@ -0,0 +1,186 @@
+
+/* @(#)e_rem_pio2.c 1.4 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.
+ * ====================================================
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* __ieee754_rem_pio2(x,y)
+ * 
+ * return the remainder of x rem pi/2 in y[0]+y[1] 
+ * use __kernel_rem_pio2()
+ */
+
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+
+/*
+ * invpio2:  53 bits of 2/pi
+ * pio2_1:   first  33 bit of pi/2
+ * pio2_1t:  pi/2 - pio2_1
+ * pio2_2:   second 33 bit of pi/2
+ * pio2_2t:  pi/2 - (pio2_1+pio2_2)
+ * pio2_3:   third  33 bit of pi/2
+ * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
+ */
+
+static const double
+zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
+two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
+pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
+pio2_1t =  6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
+pio2_2  =  6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
+pio2_2t =  2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
+pio2_3  =  2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
+pio2_3t =  8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
+
+#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];
+	int32_t e0,i,j,nx,n,ix,hx;
+	u_int32_t low;
+
+	GET_HIGH_WORD(hx,x);		/* high word of x */
+	ix = hx&0x7fffffff;
+#if 0 /* Must be handled in caller. */
+	if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
+	    {y[0] = x; y[1] = 0; return 0;}
+#endif
+	if (ix <= 0x400f6a7a) {		/* |x| ~<= 5pi/4 */
+	    if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
+		goto medium;		/* cancellation -- use medium case */
+	    if (ix <= 0x4002d97c) {	/* |x| ~<= 3pi/4 */
+		if (hx > 0) {
+		    z = x - pio2_1;	/* one round good to 85 bits */
+		    y[0] = z - pio2_1t;
+		    y[1] = (z-y[0])-pio2_1t;
+		    return 1;
+		} else {
+		    z = x + pio2_1;
+		    y[0] = z + pio2_1t;
+		    y[1] = (z-y[0])+pio2_1t;
+		    return -1;
+		}
+	    } else {
+		if (hx > 0) {
+		    z = x - 2*pio2_1;
+		    y[0] = z - 2*pio2_1t;
+		    y[1] = (z-y[0])-2*pio2_1t;
+		    return 2;
+		} else {
+		    z = x + 2*pio2_1;
+		    y[0] = z + 2*pio2_1t;
+		    y[1] = (z-y[0])+2*pio2_1t;
+		    return -2;
+		}
+	    }
+	}
+	if (ix <= 0x401c463b) {		/* |x| ~<= 9pi/4 */
+	    if (ix <= 0x4015fdbc) {	/* |x| ~<= 7pi/4 */
+		if (ix == 0x4012d97c)	/* |x| ~= 3pi/2 */
+		    goto medium;
+		if (hx > 0) {
+		    z = x - 3*pio2_1;
+		    y[0] = z - 3*pio2_1t;
+		    y[1] = (z-y[0])-3*pio2_1t;
+		    return 3;
+		} else {
+		    z = x + 3*pio2_1;
+		    y[0] = z + 3*pio2_1t;
+		    y[1] = (z-y[0])+3*pio2_1t;
+		    return -3;
+		}
+	    } else {
+		if (ix == 0x401921fb)	/* |x| ~= 4pi/2 */
+		    goto medium;
+		if (hx > 0) {
+		    z = x - 4*pio2_1;
+		    y[0] = z - 4*pio2_1t;
+		    y[1] = (z-y[0])-4*pio2_1t;
+		    return 4;
+		} else {
+		    z = x + 4*pio2_1;
+		    y[0] = z + 4*pio2_1t;
+		    y[1] = (z-y[0])+4*pio2_1t;
+		    return -4;
+		}
+	    }
+	}
+	if(ix<0x413921fb) {	/* |x| ~< 2^20*(pi/2), medium size */
+medium:
+	    /* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	    STRICT_ASSIGN(double,fn,x*invpio2+0x1.8p52);
+	    fn = fn-0x1.8p52;
+#ifdef HAVE_EFFICIENT_IRINT
+	    n  = irint(fn);
+#else
+	    n  = (int32_t)fn;
+#endif
+	    r  = x-fn*pio2_1;
+	    w  = fn*pio2_1t;	/* 1st round good to 85 bit */
+	    {
+	        u_int32_t high;
+	        j  = ix>>20;
+	        y[0] = r-w; 
+		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;	
+		    r  = t-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;	
+		    	r  = t-w;
+		    	w  = fn*pio2_3t-((t-r)-w);	
+		    	y[0] = r-w;
+		    }
+		}
+	    }
+	    y[1] = (r-y[0])-w;
+	    return n;
+	}
+    /* 
+     * all other (large) arguments
+     */
+	if(ix>=0x7ff00000) {		/* x is inf or NaN */
+	    y[0]=y[1]=x-x; return 0;
+	}
+    /* set z = scalbn(|x|,ilogb(x)-23) */
+	GET_LOW_WORD(low,x);
+	e0 	= (ix>>20)-1046;	/* e0 = ilogb(z)-23; */
+	INSERT_WORDS(z, ix - ((int32_t)(e0<<20)), low);
+	for(i=0;i<2;i++) {
+		tx[i] = (double)((int32_t)(z));
+		z     = (z-tx[i])*two24;
+	}
+	tx[2] = z;
+	nx = 3;
+	while(tx[nx-1]==zero) nx--;	/* skip zero term */
+	n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
+	if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
+	y[0] = ty[0]; y[1] = ty[1]; return n;
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c
new file mode 100644
index 0000000..f1ee7a0
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_rem_pio2f.c
@@ -0,0 +1,84 @@
+/* e_rem_pio2f.c -- float version of e_rem_pio2.c
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
+ * Debugged and optimized by Bruce D. Evans.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/* __ieee754_rem_pio2f(x,y)
+ *
+ * return the remainder of x rem pi/2 in *y
+ * use double precision for everything except passing x
+ * use __kernel_rem_pio2() for large x
+ */
+
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+
+/*
+ * invpio2:  53 bits of 2/pi
+ * pio2_1:   first 25 bits of pi/2
+ * pio2_1t:  pi/2 - pio2_1
+ */
+
+static const double
+invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
+pio2_1  =  1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */
+pio2_1t =  1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */
+
+#ifdef INLINE_REM_PIO2F
+static __inline __always_inline
+#endif
+int
+__ieee754_rem_pio2f(float x, double *y)
+{
+	double w,r,fn;
+	double tx[1],ty[1];
+	float z;
+	int32_t e0,n,ix,hx;
+
+	GET_FLOAT_WORD(hx,x);
+	ix = hx&0x7fffffff;
+    /* 33+53 bit pi is good enough for medium size */
+	if(ix<0x4dc90fdb) {		/* |x| ~< 2^28*(pi/2), medium size */
+	    /* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+	    STRICT_ASSIGN(double,fn,x*invpio2+0x1.8p52);
+	    fn = fn-0x1.8p52;
+#ifdef HAVE_EFFICIENT_IRINT
+	    n  = irint(fn);
+#else
+	    n  = (int32_t)fn;
+#endif
+	    r  = x-fn*pio2_1;
+	    w  = fn*pio2_1t;
+	    *y = r-w;
+	    return n;
+	}
+    /*
+     * all other (large) arguments
+     */
+	if(ix>=0x7f800000) {		/* x is inf or NaN */
+	    *y=x-x; return 0;
+	}
+    /* set z = scalbn(|x|,ilogb(|x|)-23) */
+	e0 = (ix>>23)-150;		/* e0 = ilogb(|x|)-23; */
+	SET_FLOAT_WORD(z, ix - ((int32_t)(e0<<23)));
+	tx[0] = z;
+	n  =  __kernel_rem_pio2(tx,ty,e0,1,0);
+	if(hx<0) {*y = -ty[0]; return -n;}
+	*y = ty[0]; return n;
+}
diff --git a/libm/src/e_remainder.c b/libm/upstream-freebsd/lib/msun/src/e_remainder.c
similarity index 87%
rename from libm/src/e_remainder.c
rename to libm/upstream-freebsd/lib/msun/src/e_remainder.c
index 46932a2..9be513b 100644
--- a/libm/src/e_remainder.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_remainder.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_remainder.c,v 1.10 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_remainder(x,p)
  * Return :                  
@@ -24,6 +23,8 @@
  *	Based on fmod() return x-[x/p]chopped*p exactlp.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -48,7 +49,7 @@
 	if((hx>=0x7ff00000)||			/* x not finite */
 	  ((hp>=0x7ff00000)&&			/* p is NaN */
 	  (((hp-0x7ff00000)|lp)!=0)))
-	    return (x*p)/(x*p);
+	    return ((long double)x*p)/((long double)x*p);
 
 
 	if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p);	/* now x < 2p */
@@ -68,6 +69,11 @@
 	    }
 	}
 	GET_HIGH_WORD(hx,x);
+	if ((hx&0x7fffffff)==0) hx = 0;
 	SET_HIGH_WORD(x,hx^sx);
 	return x;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(remainder, remainderl);
+#endif
diff --git a/libm/src/e_remainderf.c b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c
similarity index 89%
rename from libm/src/e_remainderf.c
rename to libm/upstream-freebsd/lib/msun/src/e_remainderf.c
index 4045088..b0014ae 100644
--- a/libm/src/e_remainderf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_remainderf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_remainderf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -40,7 +39,7 @@
 	if(hp==0) return (x*p)/(x*p);	 	/* p = 0 */
 	if((hx>=0x7f800000)||			/* x not finite */
 	  ((hp>0x7f800000)))			/* p is NaN */
-	    return (x*p)/(x*p);
+	    return ((long double)x*p)/((long double)x*p);
 
 
 	if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p);	/* now x < 2p */
@@ -60,6 +59,7 @@
 	    }
 	}
 	GET_FLOAT_WORD(hx,x);
+	if ((hx&0x7fffffff)==0) hx = 0;
 	SET_FLOAT_WORD(x,hx^sx);
 	return x;
 }
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/e_remainderl.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/e_remainderl.c
index 6a347c1..03327b8 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_remainderl.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,14 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
-#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);	\
-}
+long double
+remainderl(long double x, long double y)
+{
+	int quo;
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+	return (remquol(x, y, &quo));
+}
diff --git a/libm/src/e_scalb.c b/libm/upstream-freebsd/lib/msun/src/e_scalb.c
similarity index 89%
rename from libm/src/e_scalb.c
rename to libm/upstream-freebsd/lib/msun/src/e_scalb.c
index b81666e..c0a7b5b 100644
--- a/libm/src/e_scalb.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_scalb.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_scalb.c,v 1.12 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * __ieee754_scalb(x, fn) is provide for
diff --git a/libm/src/e_scalbf.c b/libm/upstream-freebsd/lib/msun/src/e_scalbf.c
similarity index 86%
rename from libm/src/e_scalbf.c
rename to libm/upstream-freebsd/lib/msun/src/e_scalbf.c
index 07ac1f4..d49e904 100644
--- a/libm/src/e_scalbf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_scalbf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_scalbf.c,v 1.10 2005/12/06 20:12:38 obrien Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -42,5 +41,3 @@
 	return scalbnf(x,(int)fn);
 #endif
 }
-
-__weak_reference(scalbf, ldexpf);
diff --git a/libm/src/e_sinh.c b/libm/upstream-freebsd/lib/msun/src/e_sinh.c
similarity index 85%
rename from libm/src/e_sinh.c
rename to libm/upstream-freebsd/lib/msun/src/e_sinh.c
index 7584b27..17442d0 100644
--- a/libm/src/e_sinh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_sinh.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sinh.c,v 1.9 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_sinh(x)
  * Method : 
@@ -41,9 +40,8 @@
 double
 __ieee754_sinh(double x)
 {
-	double t,w,h;
+	double t,h;
 	int32_t ix,jx;
-	u_int32_t lx;
 
     /* High word of |x|. */
 	GET_HIGH_WORD(jx,x);
@@ -67,12 +65,8 @@
 	if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
 
     /* |x| in [log(maxdouble), overflowthresold] */
-	GET_LOW_WORD(lx,x);
-	if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
-	    w = __ieee754_exp(0.5*fabs(x));
-	    t = h*w;
-	    return t*w;
-	}
+	if (ix<=0x408633CE)
+	    return h*2.0*__ldexp_exp(fabs(x), -1);
 
     /* |x| > overflowthresold, sinh(x) overflow */
 	return x*shuge;
diff --git a/libm/src/e_sinhf.c b/libm/upstream-freebsd/lib/msun/src/e_sinhf.c
similarity index 84%
rename from libm/src/e_sinhf.c
rename to libm/upstream-freebsd/lib/msun/src/e_sinhf.c
index 02e753f..1be2dc3 100644
--- a/libm/src/e_sinhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_sinhf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sinhf.c,v 1.8 2005/11/13 00:41:46 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -25,7 +24,7 @@
 float
 __ieee754_sinhf(float x)
 {
-	float t,w,h;
+	float t,h;
 	int32_t ix,jx;
 
 	GET_FLOAT_WORD(jx,x);
@@ -49,11 +48,8 @@
 	if (ix < 0x42b17217)  return h*__ieee754_expf(fabsf(x));
 
     /* |x| in [logf(maxfloat), overflowthresold] */
-	if (ix<=0x42b2d4fc) {
-	    w = __ieee754_expf((float)0.5*fabsf(x));
-	    t = h*w;
-	    return t*w;
-	}
+	if (ix<=0x42b2d4fc)
+	    return h*2.0F*__ldexp_expf(fabsf(x), -1);
 
     /* |x| > overflowthresold, sinh(x) overflow */
 	return x*shuge;
diff --git a/libm/src/e_sqrt.c b/libm/upstream-freebsd/lib/msun/src/e_sqrt.c
similarity index 98%
rename from libm/src/e_sqrt.c
rename to libm/upstream-freebsd/lib/msun/src/e_sqrt.c
index d75cb10..12fb56e 100644
--- a/libm/src/e_sqrt.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_sqrt.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrt.c,v 1.10 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __ieee754_sqrt(x)
  * Return correctly rounded sqrt.
@@ -85,6 +84,8 @@
  *---------------
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -187,6 +188,10 @@
 	return z;
 }
 
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(sqrt, sqrtl);
+#endif
+
 /*
 Other methods  (use floating-point arithmetic)
 -------------
diff --git a/libm/src/e_sqrtf.c b/libm/upstream-freebsd/lib/msun/src/e_sqrtf.c
similarity index 94%
rename from libm/src/e_sqrtf.c
rename to libm/upstream-freebsd/lib/msun/src/e_sqrtf.c
index edc9ef2..7eba4d0 100644
--- a/libm/src/e_sqrtf.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_sqrtf.c
@@ -14,7 +14,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_sqrtf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 #include "math.h"
diff --git a/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c b/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c
new file mode 100644
index 0000000..92b84de
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/e_sqrtl.c
@@ -0,0 +1,159 @@
+/*-
+ * Copyright (c) 2007 Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fenv.h>
+#include <float.h>
+
+#include "fpmath.h"
+#include "math.h"
+
+/* Return (x + ulp) for normal positive x. Assumes no overflow. */
+static inline long double
+inc(long double x)
+{
+	union IEEEl2bits u;
+
+	u.e = x;
+	if (++u.bits.manl == 0) {
+		if (++u.bits.manh == 0) {
+			u.bits.exp++;
+			u.bits.manh |= LDBL_NBIT;
+		}
+	}
+	return (u.e);
+}
+
+/* Return (x - ulp) for normal positive x. Assumes no underflow. */
+static inline long double
+dec(long double x)
+{
+	union IEEEl2bits u;
+
+	u.e = x;
+	if (u.bits.manl-- == 0) {
+		if (u.bits.manh-- == LDBL_NBIT) {
+			u.bits.exp--;
+			u.bits.manh |= LDBL_NBIT;
+		}
+	}
+	return (u.e);
+}
+
+#pragma STDC FENV_ACCESS ON
+
+/*
+ * This is slow, but simple and portable. You should use hardware sqrt
+ * if possible.
+ */
+
+long double
+sqrtl(long double x)
+{
+	union IEEEl2bits u;
+	int k, r;
+	long double lo, xn;
+	fenv_t env;
+
+	u.e = x;
+
+	/* If x = NaN, then sqrt(x) = NaN. */
+	/* If x = Inf, then sqrt(x) = Inf. */
+	/* If x = -Inf, then sqrt(x) = NaN. */
+	if (u.bits.exp == LDBL_MAX_EXP * 2 - 1)
+		return (x * x + x);
+
+	/* If x = +-0, then sqrt(x) = +-0. */
+	if ((u.bits.manh | u.bits.manl | u.bits.exp) == 0)
+		return (x);
+
+	/* If x < 0, then raise invalid and return NaN */
+	if (u.bits.sign)
+		return ((x - x) / (x - x));
+
+	feholdexcept(&env);
+
+	if (u.bits.exp == 0) {
+		/* Adjust subnormal numbers. */
+		u.e *= 0x1.0p514;
+		k = -514;
+	} else {
+		k = 0;
+	}
+	/*
+	 * u.e is a normal number, so break it into u.e = e*2^n where
+	 * u.e = (2*e)*2^2k for odd n and u.e = (4*e)*2^2k for even n.
+	 */
+	if ((u.bits.exp - 0x3ffe) & 1) {	/* n is odd.     */
+		k += u.bits.exp - 0x3fff;	/* 2k = n - 1.   */
+		u.bits.exp = 0x3fff;		/* u.e in [1,2). */
+	} else {
+		k += u.bits.exp - 0x4000;	/* 2k = n - 2.   */
+		u.bits.exp = 0x4000;		/* u.e in [2,4). */
+	}
+
+	/*
+	 * Newton's iteration.
+	 * Split u.e into a high and low part to achieve additional precision.
+	 */
+	xn = sqrt(u.e);			/* 53-bit estimate of sqrtl(x). */
+#if LDBL_MANT_DIG > 100
+	xn = (xn + (u.e / xn)) * 0.5;	/* 106-bit estimate. */
+#endif
+	lo = u.e;
+	u.bits.manl = 0;		/* Zero out lower bits. */
+	lo = (lo - u.e) / xn;		/* Low bits divided by xn. */
+	xn = xn + (u.e / xn);		/* High portion of estimate. */
+	u.e = xn + lo;			/* Combine everything. */
+	u.bits.exp += (k >> 1) - 1;
+
+	feclearexcept(FE_INEXACT);
+	r = fegetround();
+	fesetround(FE_TOWARDZERO);	/* Set to round-toward-zero. */
+	xn = x / u.e;			/* Chopped quotient (inexact?). */
+
+	if (!fetestexcept(FE_INEXACT)) { /* Quotient is exact. */
+		if (xn == u.e) {
+			fesetenv(&env);
+			return (u.e);
+		}
+		/* Round correctly for inputs like x = y**2 - ulp. */
+		xn = dec(xn);		/* xn = xn - ulp. */
+	}
+
+	if (r == FE_TONEAREST) {
+		xn = inc(xn);		/* xn = xn + ulp. */
+	} else if (r == FE_UPWARD) {
+		u.e = inc(u.e);		/* u.e = u.e + ulp. */
+		xn = inc(xn);		/* xn  = xn + ulp. */
+	}
+	u.e = u.e + xn;				/* Chopped sum. */
+	feupdateenv(&env);	/* Restore env and raise inexact */
+	u.bits.exp--;
+	return (u.e);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h b/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h
new file mode 100644
index 0000000..02d2a2c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/fenv-softfloat.h
@@ -0,0 +1,184 @@
+/*-
+ * Copyright (c) 2004-2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	_FENV_H_
+#error "This file is meant to be included only by <fenv.h>."
+#endif
+
+/*
+ * This file implements the functionality of <fenv.h> on platforms that
+ * lack an FPU and use softfloat in libc for floating point.  To use it,
+ * you must write an <fenv.h> that provides the following:
+ *
+ *   - a typedef for fenv_t, which may be an integer or struct type
+ *   - a typedef for fexcept_t (XXX This file assumes fexcept_t is a
+ *     simple integer type containing the exception mask.)
+ *   - definitions of FE_* constants for the five exceptions and four
+ *     rounding modes in IEEE 754, as described in fenv(3)
+ *   - a definition, and the corresponding external symbol, for FE_DFL_ENV
+ *   - a macro __set_env(env, flags, mask, rnd), which sets the given fenv_t
+ *     from the exception flags, mask, and rounding mode
+ *   - macros __env_flags(env), __env_mask(env), and __env_round(env), which
+ *     extract fields from an fenv_t
+ *   - a definition of __fenv_static
+ *
+ * If the architecture supports an optional FPU, it's recommended that you
+ * define fenv_t and fexcept_t to match the hardware ABI.  Otherwise, it
+ * doesn't matter how you define them.
+ */
+
+extern int __softfloat_float_exception_flags;
+extern int __softfloat_float_exception_mask;
+extern int __softfloat_float_rounding_mode;
+void __softfloat_float_raise(int);
+
+__fenv_static inline int
+feclearexcept(int __excepts)
+{
+
+	__softfloat_float_exception_flags &= ~__excepts;
+	return (0);
+}
+
+__fenv_static inline int
+fegetexceptflag(fexcept_t *__flagp, int __excepts)
+{
+
+	*__flagp = __softfloat_float_exception_flags & __excepts;
+	return (0);
+}
+
+__fenv_static inline int
+fesetexceptflag(const fexcept_t *__flagp, int __excepts)
+{
+
+	__softfloat_float_exception_flags &= ~__excepts;
+	__softfloat_float_exception_flags |= *__flagp & __excepts;
+	return (0);
+}
+
+__fenv_static inline int
+feraiseexcept(int __excepts)
+{
+
+	__softfloat_float_raise(__excepts);
+	return (0);
+}
+
+__fenv_static inline int
+fetestexcept(int __excepts)
+{
+
+	return (__softfloat_float_exception_flags & __excepts);
+}
+
+__fenv_static inline int
+fegetround(void)
+{
+
+	return (__softfloat_float_rounding_mode);
+}
+
+__fenv_static inline int
+fesetround(int __round)
+{
+
+	__softfloat_float_rounding_mode = __round;
+	return (0);
+}
+
+__fenv_static inline int
+fegetenv(fenv_t *__envp)
+{
+
+	__set_env(*__envp, __softfloat_float_exception_flags,
+	    __softfloat_float_exception_mask, __softfloat_float_rounding_mode);
+	return (0);
+}
+
+__fenv_static inline int
+feholdexcept(fenv_t *__envp)
+{
+	fenv_t __env;
+
+	fegetenv(__envp);
+	__softfloat_float_exception_flags = 0;
+	__softfloat_float_exception_mask = 0;
+	return (0);
+}
+
+__fenv_static inline int
+fesetenv(const fenv_t *__envp)
+{
+
+	__softfloat_float_exception_flags = __env_flags(*__envp);
+	__softfloat_float_exception_mask = __env_mask(*__envp);
+	__softfloat_float_rounding_mode = __env_round(*__envp);
+	return (0);
+}
+
+__fenv_static inline int
+feupdateenv(const fenv_t *__envp)
+{
+	int __oflags = __softfloat_float_exception_flags;
+
+	fesetenv(__envp);
+	feraiseexcept(__oflags);
+	return (0);
+}
+
+#if __BSD_VISIBLE
+
+/* We currently provide no external definitions of the functions below. */
+
+static inline int
+feenableexcept(int __mask)
+{
+	int __omask = __softfloat_float_exception_mask;
+
+	__softfloat_float_exception_mask |= __mask;
+	return (__omask);
+}
+
+static inline int
+fedisableexcept(int __mask)
+{
+	int __omask = __softfloat_float_exception_mask;
+
+	__softfloat_float_exception_mask &= ~__mask;
+	return (__omask);
+}
+
+static inline int
+fegetexcept(void)
+{
+
+	return (__softfloat_float_exception_mask);
+}
+
+#endif /* __BSD_VISIBLE */
diff --git a/libm/src/k_cos.c b/libm/upstream-freebsd/lib/msun/src/k_cos.c
similarity index 93%
rename from libm/src/k_cos.c
rename to libm/upstream-freebsd/lib/msun/src/k_cos.c
index 00916d7..c4702e6 100644
--- a/libm/src/k_cos.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_cos.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_cos.c,v 1.10 2005/10/26 12:36:18 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * __kernel_cos( x,  y )
@@ -72,8 +71,9 @@
 	double hz,z,r,w;
 
 	z  = x*x;
-	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
-	hz = (float)0.5*z;
+	w  = z*z;
+	r  = z*(C1+z*(C2+z*C3)) + w*w*(C4+z*(C5+z*C6));
+	hz = 0.5*z;
 	w  = one-hz;
 	return w + (((one-w)-hz) + (z*r-x*y));
 }
diff --git a/libm/src/k_cosf.c b/libm/upstream-freebsd/lib/msun/src/k_cosf.c
similarity index 89%
rename from libm/src/k_cosf.c
rename to libm/upstream-freebsd/lib/msun/src/k_cosf.c
index ff08d5f..f7a2c0a 100644
--- a/libm/src/k_cosf.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_cosf.c
@@ -15,9 +15,8 @@
  */
 
 #ifndef INLINE_KERNEL_COSDF
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_cosf.c,v 1.15 2005/11/30 11:51:17 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 #endif
 
 #include "math.h"
@@ -32,7 +31,7 @@
 C3  =  0x199342e0ee5069.0p-68;	/*  0.0000243904487962774090654 */
 
 #ifdef INLINE_KERNEL_COSDF
-extern inline
+static __inline
 #endif
 float
 __kernel_cosdf(double x)
diff --git a/libm/upstream-freebsd/lib/msun/src/k_exp.c b/libm/upstream-freebsd/lib/msun/src/k_exp.c
new file mode 100644
index 0000000..f592f69
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/k_exp.c
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+
+#include "math.h"
+#include "math_private.h"
+
+static const uint32_t k = 1799;		/* constant for reduction */
+static const double kln2 =  1246.97177782734161156;	/* k * ln2 */
+
+/*
+ * Compute exp(x), scaled to avoid spurious overflow.  An exponent is
+ * returned separately in 'expt'.
+ *
+ * Input:  ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91
+ * Output: 2**1023 <= y < 2**1024
+ */
+static double
+__frexp_exp(double x, int *expt)
+{
+	double exp_x;
+	uint32_t hx;
+
+	/*
+	 * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to
+	 * minimize |exp(kln2) - 2**k|.  We also scale the exponent of
+	 * exp_x to MAX_EXP so that the result can be multiplied by
+	 * a tiny number without losing accuracy due to denormalization.
+	 */
+	exp_x = exp(x - kln2);
+	GET_HIGH_WORD(hx, exp_x);
+	*expt = (hx >> 20) - (0x3ff + 1023) + k;
+	SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20));
+	return (exp_x);
+}
+
+/*
+ * __ldexp_exp(x, expt) and __ldexp_cexp(x, expt) compute exp(x) * 2**expt.
+ * They are intended for large arguments (real part >= ln(DBL_MAX))
+ * where care is needed to avoid overflow.
+ *
+ * The present implementation is narrowly tailored for our hyperbolic and
+ * exponential functions.  We assume expt is small (0 or -1), and the caller
+ * has filtered out very large x, for which overflow would be inevitable.
+ */
+
+double
+__ldexp_exp(double x, int expt)
+{
+	double exp_x, scale;
+	int ex_expt;
+
+	exp_x = __frexp_exp(x, &ex_expt);
+	expt += ex_expt;
+	INSERT_WORDS(scale, (0x3ff + expt) << 20, 0);
+	return (exp_x * scale);
+}
+
+double complex
+__ldexp_cexp(double complex z, int expt)
+{
+	double x, y, exp_x, scale1, scale2;
+	int ex_expt, half_expt;
+
+	x = creal(z);
+	y = cimag(z);
+	exp_x = __frexp_exp(x, &ex_expt);
+	expt += ex_expt;
+
+	/*
+	 * Arrange so that scale1 * scale2 == 2**expt.  We use this to
+	 * compensate for scalbn being horrendously slow.
+	 */
+	half_expt = expt / 2;
+	INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0);
+	half_expt = expt - half_expt;
+	INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0);
+
+	return (cpack(cos(y) * exp_x * scale1 * scale2,
+	    sin(y) * exp_x * scale1 * scale2));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/k_expf.c b/libm/upstream-freebsd/lib/msun/src/k_expf.c
new file mode 100644
index 0000000..548a008
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/k_expf.c
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+
+#include "math.h"
+#include "math_private.h"
+
+static const uint32_t k = 235;			/* constant for reduction */
+static const float kln2 =  162.88958740F;	/* k * ln2 */
+
+/*
+ * See k_exp.c for details.
+ *
+ * Input:  ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7
+ * Output: 2**127 <= y < 2**128
+ */
+static float
+__frexp_expf(float x, int *expt)
+{
+	float exp_x;
+	uint32_t hx;
+
+	exp_x = expf(x - kln2);
+	GET_FLOAT_WORD(hx, exp_x);
+	*expt = (hx >> 23) - (0x7f + 127) + k;
+	SET_FLOAT_WORD(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23));
+	return (exp_x);
+}
+
+float
+__ldexp_expf(float x, int expt)
+{
+	float exp_x, scale;
+	int ex_expt;
+
+	exp_x = __frexp_expf(x, &ex_expt);
+	expt += ex_expt;
+	SET_FLOAT_WORD(scale, (0x7f + expt) << 23);
+	return (exp_x * scale);
+}
+
+float complex
+__ldexp_cexpf(float complex z, int expt)
+{
+	float x, y, exp_x, scale1, scale2;
+	int ex_expt, half_expt;
+
+	x = crealf(z);
+	y = cimagf(z);
+	exp_x = __frexp_expf(x, &ex_expt);
+	expt += ex_expt;
+
+	half_expt = expt / 2;
+	SET_FLOAT_WORD(scale1, (0x7f + half_expt) << 23);
+	half_expt = expt - half_expt;
+	SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23);
+
+	return (cpackf(cosf(y) * exp_x * scale1 * scale2,
+	    sinf(y) * exp_x * scale1 * scale2));
+}
diff --git a/libm/src/e_log.c b/libm/upstream-freebsd/lib/msun/src/k_log.h
similarity index 61%
copy from libm/src/e_log.c
copy to libm/upstream-freebsd/lib/msun/src/k_log.h
index 2dbf057..aaff8bd 100644
--- a/libm/src/e_log.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_log.h
@@ -11,12 +11,17 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/e_log.c,v 1.10 2005/02/04 18:26:06 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
-/* __ieee754_log(x)
- * Return the logrithm of x
+/*
+ * k_log1p(f):
+ * Return log(1+f) - f for 1+f in ~[sqrt(2)/2, sqrt(2)].
+ *
+ * The following describes the overall strategy for computing
+ * logarithms in base e.  The argument reduction and adding the final
+ * term of the polynomial are done by the caller for increased accuracy
+ * when different bases are used.
  *
  * Method :                  
  *   1. Argument Reduction: find k and f such that 
@@ -66,13 +71,7 @@
  * to produce the hexadecimal values shown.
  */
 
-#include "math.h"
-#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 */
@@ -81,55 +80,21 @@
 Lg6 = 1.531383769920937332e-01,  /* 3FC39A09 D078C69F */
 Lg7 = 1.479819860511658591e-01;  /* 3FC2F112 DF3E5244 */
 
-static const double zero   =  0.0;
-
-double
-__ieee754_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;
+	double hfsq,s,z,R,w,t1,t2;
 
-	EXTRACT_WORDS(hx,lx,x);
-
-	k=0;
-	if (hx < 0x00100000) {			/* x < 2**-1022  */
-	    if (((hx&0x7fffffff)|lx)==0) 
-		return -two54/zero;		/* log(+-0)=-inf */
-	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
-	    k -= 54; x *= two54; /* subnormal number, scale up x */
-	    GET_HIGH_WORD(hx,x);
-	} 
-	if (hx >= 0x7ff00000) return x+x;
-	k += (hx>>20)-1023;
-	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) {	/* |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;
+ 	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;
+	t1= w*(Lg2+w*(Lg4+w*Lg6));
+	t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
 	R = t2+t1;
-	if(i>0) {
-	    hfsq=0.5*f*f;
-	    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/libm/upstream-freebsd/lib/msun/src/k_logf.h b/libm/upstream-freebsd/lib/msun/src/k_logf.h
new file mode 100644
index 0000000..71c547e
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/k_logf.h
@@ -0,0 +1,39 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Float version of k_log.h.  See the latter for most comments.
+ */
+
+static const float
+/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
+Lg1 =      0xaaaaaa.0p-24,	/* 0.66666662693 */
+Lg2 =      0xccce13.0p-25,	/* 0.40000972152 */
+Lg3 =      0x91e9ee.0p-25,	/* 0.28498786688 */
+Lg4 =      0xf89e26.0p-26;	/* 0.24279078841 */
+
+static inline float
+k_log1pf(float f)
+{
+	float hfsq,s,z,R,w,t1,t2;
+
+ 	s = f/((float)2.0+f);
+	z = s*s;
+	w = z*z;
+	t1= w*(Lg2+w*Lg4);
+	t2= z*(Lg1+w*Lg3);
+	R = t2+t1;
+	hfsq=(float)0.5*f*f;
+	return s*(hfsq+R);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c b/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c
new file mode 100644
index 0000000..3942441
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/k_rem_pio2.c
@@ -0,0 +1,443 @@
+
+/* @(#)k_rem_pio2.c 1.3 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * __kernel_rem_pio2(x,y,e0,nx,prec)
+ * double x[],y[]; int e0,nx,prec;
+ * 
+ * __kernel_rem_pio2 return the last three digits of N with 
+ *		y = x - N*pi/2
+ * so that |y| < pi/2.
+ *
+ * The method is to compute the integer (mod 8) and fraction parts of 
+ * (2/pi)*x without doing the full multiplication. In general we
+ * skip the part of the product that are known to be a huge integer (
+ * more accurately, = 0 mod 8 ). Thus the number of operations are
+ * independent of the exponent of the input.
+ *
+ * (2/pi) is represented by an array of 24-bit integers in ipio2[].
+ *
+ * Input parameters:
+ * 	x[]	The input value (must be positive) is broken into nx 
+ *		pieces of 24-bit integers in double precision format.
+ *		x[i] will be the i-th 24 bit of x. The scaled exponent 
+ *		of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 
+ *		match x's up to 24 bits.
+ *
+ *		Example of breaking a double positive z into x[0]+x[1]+x[2]:
+ *			e0 = ilogb(z)-23
+ *			z  = scalbn(z,-e0)
+ *		for i = 0,1,2
+ *			x[i] = floor(z)
+ *			z    = (z-x[i])*2**24
+ *
+ *
+ *	y[]	output result in an array of double precision numbers.
+ *		The dimension of y[] is:
+ *			24-bit  precision	1
+ *			53-bit  precision	2
+ *			64-bit  precision	2
+ *			113-bit precision	3
+ *		The actual value is the sum of them. Thus for 113-bit
+ *		precison, one may have to do something like:
+ *
+ *		long double t,w,r_head, r_tail;
+ *		t = (long double)y[2] + (long double)y[1];
+ *		w = (long double)y[0];
+ *		r_head = t+w;
+ *		r_tail = w - (r_head - t);
+ *
+ *	e0	The exponent of x[0]. Must be <= 16360 or you need to
+ *              expand the ipio2 table.
+ *
+ *	nx	dimension of x[]
+ *
+ *  	prec	an integer indicating the precision:
+ *			0	24  bits (single)
+ *			1	53  bits (double)
+ *			2	64  bits (extended)
+ *			3	113 bits (quad)
+ *
+ * External function:
+ *	double scalbn(), floor();
+ *
+ *
+ * Here is the description of some local variables:
+ *
+ * 	jk	jk+1 is the initial number of terms of ipio2[] needed
+ *		in the computation. The minimum and recommended value
+ *		for jk is 3,4,4,6 for single, double, extended, and quad.
+ *		jk+1 must be 2 larger than you might expect so that our
+ *		recomputation test works. (Up to 24 bits in the integer
+ *		part (the 24 bits of it that we compute) and 23 bits in
+ *		the fraction part may be lost to cancelation before we
+ *		recompute.)
+ *
+ * 	jz	local integer variable indicating the number of 
+ *		terms of ipio2[] used. 
+ *
+ *	jx	nx - 1
+ *
+ *	jv	index for pointing to the suitable ipio2[] for the
+ *		computation. In general, we want
+ *			( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
+ *		is an integer. Thus
+ *			e0-3-24*jv >= 0 or (e0-3)/24 >= jv
+ *		Hence jv = max(0,(e0-3)/24).
+ *
+ *	jp	jp+1 is the number of terms in PIo2[] needed, jp = jk.
+ *
+ * 	q[]	double array with integral value, representing the
+ *		24-bits chunk of the product of x and 2/pi.
+ *
+ *	q0	the corresponding exponent of q[0]. Note that the
+ *		exponent for q[i] would be q0-24*i.
+ *
+ *	PIo2[]	double precision array, obtained by cutting pi/2
+ *		into 24 bits chunks. 
+ *
+ *	f[]	ipio2[] in floating point 
+ *
+ *	iq[]	integer array by breaking up q[] in 24-bits chunk.
+ *
+ *	fq[]	final product of x*(2/pi) in fq[0],..,fq[jk]
+ *
+ *	ih	integer. If >0 it indicates q[] is >= 0.5, hence
+ *		it also indicates the *sign* of the result.
+ *
+ */
+
+
+/*
+ * Constants:
+ * The hexadecimal values are the intended ones for the following 
+ * constants. The decimal values may be used, provided that the 
+ * compiler will convert from decimal to binary accurately enough 
+ * to produce the hexadecimal values shown.
+ */
+
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+
+static const int init_jk[] = {3,4,4,6}; /* initial value for jk */
+
+/*
+ * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
+ *
+ *		integer array, contains the (24*i)-th to (24*i+23)-th 
+ *		bit of 2/pi after binary point. The corresponding 
+ *		floating value is
+ *
+ *			ipio2[i] * 2^(-24(i+1)).
+ *
+ * NB: This table must have at least (e0-3)/24 + jk terms.
+ *     For quad precision (e0 <= 16360, jk = 6), this is 686.
+ */
+static const int32_t ipio2[] = {
+0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 
+0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, 
+0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 
+0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, 
+0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, 
+0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, 
+0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, 
+0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 
+0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 
+0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 
+0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, 
+
+#if LDBL_MAX_EXP > 1024
+#if LDBL_MAX_EXP > 16384
+#error "ipio2 table needs to be expanded"
+#endif
+0x47C419, 0xC367CD, 0xDCE809, 0x2A8359, 0xC4768B, 0x961CA6,
+0xDDAF44, 0xD15719, 0x053EA5, 0xFF0705, 0x3F7E33, 0xE832C2,
+0xDE4F98, 0x327DBB, 0xC33D26, 0xEF6B1E, 0x5EF89F, 0x3A1F35,
+0xCAF27F, 0x1D87F1, 0x21907C, 0x7C246A, 0xFA6ED5, 0x772D30,
+0x433B15, 0xC614B5, 0x9D19C3, 0xC2C4AD, 0x414D2C, 0x5D000C,
+0x467D86, 0x2D71E3, 0x9AC69B, 0x006233, 0x7CD2B4, 0x97A7B4,
+0xD55537, 0xF63ED7, 0x1810A3, 0xFC764D, 0x2A9D64, 0xABD770,
+0xF87C63, 0x57B07A, 0xE71517, 0x5649C0, 0xD9D63B, 0x3884A7,
+0xCB2324, 0x778AD6, 0x23545A, 0xB91F00, 0x1B0AF1, 0xDFCE19,
+0xFF319F, 0x6A1E66, 0x615799, 0x47FBAC, 0xD87F7E, 0xB76522,
+0x89E832, 0x60BFE6, 0xCDC4EF, 0x09366C, 0xD43F5D, 0xD7DE16,
+0xDE3B58, 0x929BDE, 0x2822D2, 0xE88628, 0x4D58E2, 0x32CAC6,
+0x16E308, 0xCB7DE0, 0x50C017, 0xA71DF3, 0x5BE018, 0x34132E,
+0x621283, 0x014883, 0x5B8EF5, 0x7FB0AD, 0xF2E91E, 0x434A48,
+0xD36710, 0xD8DDAA, 0x425FAE, 0xCE616A, 0xA4280A, 0xB499D3,
+0xF2A606, 0x7F775C, 0x83C2A3, 0x883C61, 0x78738A, 0x5A8CAF,
+0xBDD76F, 0x63A62D, 0xCBBFF4, 0xEF818D, 0x67C126, 0x45CA55,
+0x36D9CA, 0xD2A828, 0x8D61C2, 0x77C912, 0x142604, 0x9B4612,
+0xC459C4, 0x44C5C8, 0x91B24D, 0xF31700, 0xAD43D4, 0xE54929,
+0x10D5FD, 0xFCBE00, 0xCC941E, 0xEECE70, 0xF53E13, 0x80F1EC,
+0xC3E7B3, 0x28F8C7, 0x940593, 0x3E71C1, 0xB3092E, 0xF3450B,
+0x9C1288, 0x7B20AB, 0x9FB52E, 0xC29247, 0x2F327B, 0x6D550C,
+0x90A772, 0x1FE76B, 0x96CB31, 0x4A1679, 0xE27941, 0x89DFF4,
+0x9794E8, 0x84E6E2, 0x973199, 0x6BED88, 0x365F5F, 0x0EFDBB,
+0xB49A48, 0x6CA467, 0x427271, 0x325D8D, 0xB8159F, 0x09E5BC,
+0x25318D, 0x3974F7, 0x1C0530, 0x010C0D, 0x68084B, 0x58EE2C,
+0x90AA47, 0x02E774, 0x24D6BD, 0xA67DF7, 0x72486E, 0xEF169F,
+0xA6948E, 0xF691B4, 0x5153D1, 0xF20ACF, 0x339820, 0x7E4BF5,
+0x6863B2, 0x5F3EDD, 0x035D40, 0x7F8985, 0x295255, 0xC06437,
+0x10D86D, 0x324832, 0x754C5B, 0xD4714E, 0x6E5445, 0xC1090B,
+0x69F52A, 0xD56614, 0x9D0727, 0x50045D, 0xDB3BB4, 0xC576EA,
+0x17F987, 0x7D6B49, 0xBA271D, 0x296996, 0xACCCC6, 0x5414AD,
+0x6AE290, 0x89D988, 0x50722C, 0xBEA404, 0x940777, 0x7030F3,
+0x27FC00, 0xA871EA, 0x49C266, 0x3DE064, 0x83DD97, 0x973FA3,
+0xFD9443, 0x8C860D, 0xDE4131, 0x9D3992, 0x8C70DD, 0xE7B717,
+0x3BDF08, 0x2B3715, 0xA0805C, 0x93805A, 0x921110, 0xD8E80F,
+0xAF806C, 0x4BFFDB, 0x0F9038, 0x761859, 0x15A562, 0xBBCB61,
+0xB989C7, 0xBD4010, 0x04F2D2, 0x277549, 0xF6B6EB, 0xBB22DB,
+0xAA140A, 0x2F2689, 0x768364, 0x333B09, 0x1A940E, 0xAA3A51,
+0xC2A31D, 0xAEEDAF, 0x12265C, 0x4DC26D, 0x9C7A2D, 0x9756C0,
+0x833F03, 0xF6F009, 0x8C402B, 0x99316D, 0x07B439, 0x15200C,
+0x5BC3D8, 0xC492F5, 0x4BADC6, 0xA5CA4E, 0xCD37A7, 0x36A9E6,
+0x9492AB, 0x6842DD, 0xDE6319, 0xEF8C76, 0x528B68, 0x37DBFC,
+0xABA1AE, 0x3115DF, 0xA1AE00, 0xDAFB0C, 0x664D64, 0xB705ED,
+0x306529, 0xBF5657, 0x3AFF47, 0xB9F96A, 0xF3BE75, 0xDF9328,
+0x3080AB, 0xF68C66, 0x15CB04, 0x0622FA, 0x1DE4D9, 0xA4B33D,
+0x8F1B57, 0x09CD36, 0xE9424E, 0xA4BE13, 0xB52333, 0x1AAAF0,
+0xA8654F, 0xA5C1D2, 0x0F3F0B, 0xCD785B, 0x76F923, 0x048B7B,
+0x721789, 0x53A6C6, 0xE26E6F, 0x00EBEF, 0x584A9B, 0xB7DAC4,
+0xBA66AA, 0xCFCF76, 0x1D02D1, 0x2DF1B1, 0xC1998C, 0x77ADC3,
+0xDA4886, 0xA05DF7, 0xF480C6, 0x2FF0AC, 0x9AECDD, 0xBC5C3F,
+0x6DDED0, 0x1FC790, 0xB6DB2A, 0x3A25A3, 0x9AAF00, 0x9353AD,
+0x0457B6, 0xB42D29, 0x7E804B, 0xA707DA, 0x0EAA76, 0xA1597B,
+0x2A1216, 0x2DB7DC, 0xFDE5FA, 0xFEDB89, 0xFDBE89, 0x6C76E4,
+0xFCA906, 0x70803E, 0x156E85, 0xFF87FD, 0x073E28, 0x336761,
+0x86182A, 0xEABD4D, 0xAFE7B3, 0x6E6D8F, 0x396795, 0x5BBF31,
+0x48D784, 0x16DF30, 0x432DC7, 0x356125, 0xCE70C9, 0xB8CB30,
+0xFD6CBF, 0xA200A4, 0xE46C05, 0xA0DD5A, 0x476F21, 0xD21262,
+0x845CB9, 0x496170, 0xE0566B, 0x015299, 0x375550, 0xB7D51E,
+0xC4F133, 0x5F6E13, 0xE4305D, 0xA92E85, 0xC3B21D, 0x3632A1,
+0xA4B708, 0xD4B1EA, 0x21F716, 0xE4698F, 0x77FF27, 0x80030C,
+0x2D408D, 0xA0CD4F, 0x99A520, 0xD3A2B3, 0x0A5D2F, 0x42F9B4,
+0xCBDA11, 0xD0BE7D, 0xC1DB9B, 0xBD17AB, 0x81A2CA, 0x5C6A08,
+0x17552E, 0x550027, 0xF0147F, 0x8607E1, 0x640B14, 0x8D4196,
+0xDEBE87, 0x2AFDDA, 0xB6256B, 0x34897B, 0xFEF305, 0x9EBFB9,
+0x4F6A68, 0xA82A4A, 0x5AC44F, 0xBCF82D, 0x985AD7, 0x95C7F4,
+0x8D4D0D, 0xA63A20, 0x5F57A4, 0xB13F14, 0x953880, 0x0120CC,
+0x86DD71, 0xB6DEC9, 0xF560BF, 0x11654D, 0x6B0701, 0xACB08C,
+0xD0C0B2, 0x485551, 0x0EFB1E, 0xC37295, 0x3B06A3, 0x3540C0,
+0x7BDC06, 0xCC45E0, 0xFA294E, 0xC8CAD6, 0x41F3E8, 0xDE647C,
+0xD8649B, 0x31BED9, 0xC397A4, 0xD45877, 0xC5E369, 0x13DAF0,
+0x3C3ABA, 0x461846, 0x5F7555, 0xF5BDD2, 0xC6926E, 0x5D2EAC,
+0xED440E, 0x423E1C, 0x87C461, 0xE9FD29, 0xF3D6E7, 0xCA7C22,
+0x35916F, 0xC5E008, 0x8DD7FF, 0xE26A6E, 0xC6FDB0, 0xC10893,
+0x745D7C, 0xB2AD6B, 0x9D6ECD, 0x7B723E, 0x6A11C6, 0xA9CFF7,
+0xDF7329, 0xBAC9B5, 0x5100B7, 0x0DB2E2, 0x24BA74, 0x607DE5,
+0x8AD874, 0x2C150D, 0x0C1881, 0x94667E, 0x162901, 0x767A9F,
+0xBEFDFD, 0xEF4556, 0x367ED9, 0x13D9EC, 0xB9BA8B, 0xFC97C4,
+0x27A831, 0xC36EF1, 0x36C594, 0x56A8D8, 0xB5A8B4, 0x0ECCCF,
+0x2D8912, 0x34576F, 0x89562C, 0xE3CE99, 0xB920D6, 0xAA5E6B,
+0x9C2A3E, 0xCC5F11, 0x4A0BFD, 0xFBF4E1, 0x6D3B8E, 0x2C86E2,
+0x84D4E9, 0xA9B4FC, 0xD1EEEF, 0xC9352E, 0x61392F, 0x442138,
+0xC8D91B, 0x0AFC81, 0x6A4AFB, 0xD81C2F, 0x84B453, 0x8C994E,
+0xCC2254, 0xDC552A, 0xD6C6C0, 0x96190B, 0xB8701A, 0x649569,
+0x605A26, 0xEE523F, 0x0F117F, 0x11B5F4, 0xF5CBFC, 0x2DBC34,
+0xEEBC34, 0xCC5DE8, 0x605EDD, 0x9B8E67, 0xEF3392, 0xB817C9,
+0x9B5861, 0xBC57E1, 0xC68351, 0x103ED8, 0x4871DD, 0xDD1C2D,
+0xA118AF, 0x462C21, 0xD7F359, 0x987AD9, 0xC0549E, 0xFA864F,
+0xFC0656, 0xAE79E5, 0x362289, 0x22AD38, 0xDC9367, 0xAAE855,
+0x382682, 0x9BE7CA, 0xA40D51, 0xB13399, 0x0ED7A9, 0x480569,
+0xF0B265, 0xA7887F, 0x974C88, 0x36D1F9, 0xB39221, 0x4A827B,
+0x21CF98, 0xDC9F40, 0x5547DC, 0x3A74E1, 0x42EB67, 0xDF9DFE,
+0x5FD45E, 0xA4677B, 0x7AACBA, 0xA2F655, 0x23882B, 0x55BA41,
+0x086E59, 0x862A21, 0x834739, 0xE6E389, 0xD49EE5, 0x40FB49,
+0xE956FF, 0xCA0F1C, 0x8A59C5, 0x2BFA94, 0xC5C1D3, 0xCFC50F,
+0xAE5ADB, 0x86C547, 0x624385, 0x3B8621, 0x94792C, 0x876110,
+0x7B4C2A, 0x1A2C80, 0x12BF43, 0x902688, 0x893C78, 0xE4C4A8,
+0x7BDBE5, 0xC23AC4, 0xEAF426, 0x8A67F7, 0xBF920D, 0x2BA365,
+0xB1933D, 0x0B7CBD, 0xDC51A4, 0x63DD27, 0xDDE169, 0x19949A,
+0x9529A8, 0x28CE68, 0xB4ED09, 0x209F44, 0xCA984E, 0x638270,
+0x237C7E, 0x32B90F, 0x8EF5A7, 0xE75614, 0x08F121, 0x2A9DB5,
+0x4D7E6F, 0x5119A5, 0xABF9B5, 0xD6DF82, 0x61DD96, 0x023616,
+0x9F3AC4, 0xA1A283, 0x6DED72, 0x7A8D39, 0xA9B882, 0x5C326B,
+0x5B2746, 0xED3400, 0x7700D2, 0x55F4FC, 0x4D5901, 0x8071E0,
+#endif
+
+};
+
+static const double PIo2[] = {
+  1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
+  7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
+  5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
+  3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
+  1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
+  1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
+  2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
+  2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
+};
+
+static const double			
+zero   = 0.0,
+one    = 1.0,
+two24   =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+twon24  =  5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
+
+int
+__kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec)
+{
+	int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
+	double z,fw,f[20],fq[20],q[20];
+
+    /* initialize jk*/
+	jk = init_jk[prec];
+	jp = jk;
+
+    /* determine jx,jv,q0, note that 3>q0 */
+	jx =  nx-1;
+	jv = (e0-3)/24; if(jv<0) jv=0;
+	q0 =  e0-24*(jv+1);
+
+    /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
+	j = jv-jx; m = jx+jk;
+	for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
+
+    /* compute q[0],q[1],...q[jk] */
+	for (i=0;i<=jk;i++) {
+	    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
+	}
+
+	jz = jk;
+recompute:
+    /* distill q[] into iq[] reversingly */
+	for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
+	    fw    =  (double)((int32_t)(twon24* z));
+	    iq[i] =  (int32_t)(z-two24*fw);
+	    z     =  q[j-1]+fw;
+	}
+
+    /* compute n */
+	z  = scalbn(z,q0);		/* actual value of z */
+	z -= 8.0*floor(z*0.125);		/* trim off integer >= 8 */
+	n  = (int32_t) z;
+	z -= (double)n;
+	ih = 0;
+	if(q0>0) {	/* need iq[jz-1] to determine n */
+	    i  = (iq[jz-1]>>(24-q0)); n += i;
+	    iq[jz-1] -= i<<(24-q0);
+	    ih = iq[jz-1]>>(23-q0);
+	} 
+	else if(q0==0) ih = iq[jz-1]>>23;
+	else if(z>=0.5) ih=2;
+
+	if(ih>0) {	/* q > 0.5 */
+	    n += 1; carry = 0;
+	    for(i=0;i<jz ;i++) {	/* compute 1-q */
+		j = iq[i];
+		if(carry==0) {
+		    if(j!=0) {
+			carry = 1; iq[i] = 0x1000000- j;
+		    }
+		} else  iq[i] = 0xffffff - j;
+	    }
+	    if(q0>0) {		/* rare case: chance is 1 in 12 */
+	        switch(q0) {
+	        case 1:
+	    	   iq[jz-1] &= 0x7fffff; break;
+	    	case 2:
+	    	   iq[jz-1] &= 0x3fffff; break;
+	        }
+	    }
+	    if(ih==2) {
+		z = one - z;
+		if(carry!=0) z -= scalbn(one,q0);
+	    }
+	}
+
+    /* check if recomputation is needed */
+	if(z==zero) {
+	    j = 0;
+	    for (i=jz-1;i>=jk;i--) j |= iq[i];
+	    if(j==0) { /* need recomputation */
+		for(k=1;iq[jk-k]==0;k++);   /* k = no. of terms needed */
+
+		for(i=jz+1;i<=jz+k;i++) {   /* add q[jz+1] to q[jz+k] */
+		    f[jx+i] = (double) ipio2[jv+i];
+		    for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
+		    q[i] = fw;
+		}
+		jz += k;
+		goto recompute;
+	    }
+	}
+
+    /* chop off zero terms */
+	if(z==0.0) {
+	    jz -= 1; q0 -= 24;
+	    while(iq[jz]==0) { jz--; q0-=24;}
+	} else { /* break z into 24-bit if necessary */
+	    z = scalbn(z,-q0);
+	    if(z>=two24) { 
+		fw = (double)((int32_t)(twon24*z));
+		iq[jz] = (int32_t)(z-two24*fw);
+		jz += 1; q0 += 24;
+		iq[jz] = (int32_t) fw;
+	    } else iq[jz] = (int32_t) z ;
+	}
+
+    /* convert integer "bit" chunk to floating-point value */
+	fw = scalbn(one,q0);
+	for(i=jz;i>=0;i--) {
+	    q[i] = fw*(double)iq[i]; fw*=twon24;
+	}
+
+    /* compute PIo2[0,...,jp]*q[jz,...,0] */
+	for(i=jz;i>=0;i--) {
+	    for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
+	    fq[jz-i] = fw;
+	}
+
+    /* compress fq[] into y[] */
+	switch(prec) {
+	    case 0:
+		fw = 0.0;
+		for (i=jz;i>=0;i--) fw += fq[i];
+		y[0] = (ih==0)? fw: -fw; 
+		break;
+	    case 1:
+	    case 2:
+		fw = 0.0;
+		for (i=jz;i>=0;i--) fw += fq[i]; 
+		STRICT_ASSIGN(double,fw,fw);
+		y[0] = (ih==0)? fw: -fw; 
+		fw = fq[0]-fw;
+		for (i=1;i<=jz;i++) fw += fq[i];
+		y[1] = (ih==0)? fw: -fw; 
+		break;
+	    case 3:	/* painful */
+		for (i=jz;i>0;i--) {
+		    fw      = fq[i-1]+fq[i]; 
+		    fq[i]  += fq[i-1]-fw;
+		    fq[i-1] = fw;
+		}
+		for (i=jz;i>1;i--) {
+		    fw      = fq[i-1]+fq[i]; 
+		    fq[i]  += fq[i-1]-fw;
+		    fq[i-1] = fw;
+		}
+		for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; 
+		if(ih==0) {
+		    y[0] =  fq[0]; y[1] =  fq[1]; y[2] =  fw;
+		} else {
+		    y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
+		}
+	}
+	return n&7;
+}
diff --git a/libm/src/k_sin.c b/libm/upstream-freebsd/lib/msun/src/k_sin.c
similarity index 92%
rename from libm/src/k_sin.c
rename to libm/upstream-freebsd/lib/msun/src/k_sin.c
index ae06a9d..12ee8c1 100644
--- a/libm/src/k_sin.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_sin.c
@@ -11,9 +11,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_sin.c,v 1.10 2005/11/02 13:06:49 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __kernel_sin( x, y, iy)
  * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
@@ -60,11 +59,12 @@
 double
 __kernel_sin(double x, double y, int iy)
 {
-	double z,r,v;
+	double z,r,v,w;
 
 	z	=  x*x;
+	w	=  z*z;
+	r	=  S2+z*(S3+z*S4) + z*w*(S5+z*S6);
 	v	=  z*x;
-	r	=  S2+z*(S3+z*(S4+z*(S5+z*S6)));
 	if(iy==0) return x+v*(S1+z*r);
 	else      return x-((z*(half*y-v*r)-y)-v*S1);
 }
diff --git a/libm/src/k_sinf.c b/libm/upstream-freebsd/lib/msun/src/k_sinf.c
similarity index 89%
rename from libm/src/k_sinf.c
rename to libm/upstream-freebsd/lib/msun/src/k_sinf.c
index e45dc42..0841759 100644
--- a/libm/src/k_sinf.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_sinf.c
@@ -15,9 +15,8 @@
  */
 
 #ifndef INLINE_KERNEL_SINDF
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_sinf.c,v 1.13 2005/11/30 11:51:17 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 #endif
 
 #include "math.h"
@@ -31,7 +30,7 @@
 S4 =  0x16cd878c3b46a7.0p-71;	/*  0.0000027183114939898219064 */
 
 #ifdef INLINE_KERNEL_SINDF
-extern inline
+static __inline
 #endif
 float
 __kernel_sindf(double x)
diff --git a/libm/src/k_tan.c b/libm/upstream-freebsd/lib/msun/src/k_tan.c
similarity index 96%
rename from libm/src/k_tan.c
rename to libm/upstream-freebsd/lib/msun/src/k_tan.c
index 82fe155..2e86c3b 100644
--- a/libm/src/k_tan.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_tan.c
@@ -11,9 +11,8 @@
  */
 
 /* INDENT OFF */
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_tan.c,v 1.12 2005/11/02 14:01:45 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* __kernel_tan( x, y, k )
  * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
diff --git a/libm/src/k_tanf.c b/libm/upstream-freebsd/lib/msun/src/k_tanf.c
similarity index 93%
rename from libm/src/k_tanf.c
rename to libm/upstream-freebsd/lib/msun/src/k_tanf.c
index 6574030..52f1aaa 100644
--- a/libm/src/k_tanf.c
+++ b/libm/upstream-freebsd/lib/msun/src/k_tanf.c
@@ -14,9 +14,8 @@
  */
 
 #ifndef INLINE_KERNEL_TANDF
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/k_tanf.c,v 1.20 2005/11/28 11:46:20 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 #endif
 
 #include "math.h"
@@ -34,7 +33,7 @@
 };
 
 #ifdef INLINE_KERNEL_TANDF
-extern inline
+static __inline
 #endif
 float
 __kernel_tandf(double x, int iy)
diff --git a/libm/upstream-freebsd/lib/msun/src/math_private.h b/libm/upstream-freebsd/lib/msun/src/math_private.h
new file mode 100644
index 0000000..5662df0
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/math_private.h
@@ -0,0 +1,472 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * from: @(#)fdlibm.h 5.1 93/09/24
+ * $FreeBSD$
+ */
+
+#ifndef _MATH_PRIVATE_H_
+#define	_MATH_PRIVATE_H_
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+/*
+ * The original fdlibm code used statements like:
+ *	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
+ *	ix0 = *(n0+(int*)&x);			* high word of x *
+ *	ix1 = *((1-n0)+(int*)&x);		* low word of x *
+ * to dig two 32 bit words out of the 64 bit IEEE floating point
+ * value.  That is non-ANSI, and, moreover, the gcc instruction
+ * scheduler gets it wrong.  We instead use the following macros.
+ * Unlike the original code, we determine the endianness at compile
+ * time, not at run time; I don't see much benefit to selecting
+ * endianness at run time.
+ */
+
+/*
+ * A union which permits us to convert between a double and two 32 bit
+ * ints.
+ */
+
+#ifdef __arm__
+#if defined(__VFP_FP__)
+#define	IEEE_WORD_ORDER	BYTE_ORDER
+#else
+#define	IEEE_WORD_ORDER	BIG_ENDIAN
+#endif
+#else /* __arm__ */
+#define	IEEE_WORD_ORDER	BYTE_ORDER
+#endif
+
+#if IEEE_WORD_ORDER == BIG_ENDIAN
+
+typedef union
+{
+  double value;
+  struct
+  {
+    u_int32_t msw;
+    u_int32_t lsw;
+  } parts;
+  struct
+  {
+    u_int64_t w;
+  } xparts;
+} ieee_double_shape_type;
+
+#endif
+
+#if IEEE_WORD_ORDER == LITTLE_ENDIAN
+
+typedef union
+{
+  double value;
+  struct
+  {
+    u_int32_t lsw;
+    u_int32_t msw;
+  } parts;
+  struct
+  {
+    u_int64_t w;
+  } xparts;
+} ieee_double_shape_type;
+
+#endif
+
+/* Get two 32 bit ints from a double.  */
+
+#define EXTRACT_WORDS(ix0,ix1,d)				\
+do {								\
+  ieee_double_shape_type ew_u;					\
+  ew_u.value = (d);						\
+  (ix0) = ew_u.parts.msw;					\
+  (ix1) = ew_u.parts.lsw;					\
+} while (0)
+
+/* Get a 64-bit int from a double. */
+#define EXTRACT_WORD64(ix,d)					\
+do {								\
+  ieee_double_shape_type ew_u;					\
+  ew_u.value = (d);						\
+  (ix) = ew_u.xparts.w;						\
+} while (0)
+
+/* Get the more significant 32 bit int from a double.  */
+
+#define GET_HIGH_WORD(i,d)					\
+do {								\
+  ieee_double_shape_type gh_u;					\
+  gh_u.value = (d);						\
+  (i) = gh_u.parts.msw;						\
+} while (0)
+
+/* Get the less significant 32 bit int from a double.  */
+
+#define GET_LOW_WORD(i,d)					\
+do {								\
+  ieee_double_shape_type gl_u;					\
+  gl_u.value = (d);						\
+  (i) = gl_u.parts.lsw;						\
+} while (0)
+
+/* Set a double from two 32 bit ints.  */
+
+#define INSERT_WORDS(d,ix0,ix1)					\
+do {								\
+  ieee_double_shape_type iw_u;					\
+  iw_u.parts.msw = (ix0);					\
+  iw_u.parts.lsw = (ix1);					\
+  (d) = iw_u.value;						\
+} while (0)
+
+/* Set a double from a 64-bit int. */
+#define INSERT_WORD64(d,ix)					\
+do {								\
+  ieee_double_shape_type iw_u;					\
+  iw_u.xparts.w = (ix);						\
+  (d) = iw_u.value;						\
+} while (0)
+
+/* Set the more significant 32 bits of a double from an int.  */
+
+#define SET_HIGH_WORD(d,v)					\
+do {								\
+  ieee_double_shape_type sh_u;					\
+  sh_u.value = (d);						\
+  sh_u.parts.msw = (v);						\
+  (d) = sh_u.value;						\
+} while (0)
+
+/* Set the less significant 32 bits of a double from an int.  */
+
+#define SET_LOW_WORD(d,v)					\
+do {								\
+  ieee_double_shape_type sl_u;					\
+  sl_u.value = (d);						\
+  sl_u.parts.lsw = (v);						\
+  (d) = sl_u.value;						\
+} while (0)
+
+/*
+ * A union which permits us to convert between a float and a 32 bit
+ * int.
+ */
+
+typedef union
+{
+  float value;
+  /* FIXME: Assumes 32 bit int.  */
+  unsigned int word;
+} ieee_float_shape_type;
+
+/* Get a 32 bit int from a float.  */
+
+#define GET_FLOAT_WORD(i,d)					\
+do {								\
+  ieee_float_shape_type gf_u;					\
+  gf_u.value = (d);						\
+  (i) = gf_u.word;						\
+} while (0)
+
+/* Set a float from a 32 bit int.  */
+
+#define SET_FLOAT_WORD(d,i)					\
+do {								\
+  ieee_float_shape_type sf_u;					\
+  sf_u.word = (i);						\
+  (d) = sf_u.value;						\
+} while (0)
+
+/* Get expsign as a 16 bit int from a long double.  */
+
+#define	GET_LDBL_EXPSIGN(i,d)					\
+do {								\
+  union IEEEl2bits ge_u;					\
+  ge_u.e = (d);							\
+  (i) = ge_u.xbits.expsign;					\
+} while (0)
+
+/* Set expsign of a long double from a 16 bit int.  */
+
+#define	SET_LDBL_EXPSIGN(d,v)					\
+do {								\
+  union IEEEl2bits se_u;					\
+  se_u.e = (d);							\
+  se_u.xbits.expsign = (v);					\
+  (d) = se_u.e;							\
+} while (0)
+
+#ifdef __i386__
+/* Long double constants are broken on i386. */
+#define	LD80C(m, ex, v) {						\
+	.xbits.man = __CONCAT(m, ULL),					\
+	.xbits.expsign = (0x3fff + (ex)) | ((v) < 0 ? 0x8000 : 0),	\
+}
+#else
+/* The above works on non-i386 too, but we use this to check v. */
+#define	LD80C(m, ex, v)	{ .e = (v), }
+#endif
+
+#ifdef FLT_EVAL_METHOD
+/*
+ * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
+ */
+#if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
+#define	STRICT_ASSIGN(type, lval, rval)	((lval) = (rval))
+#else
+#define	STRICT_ASSIGN(type, lval, rval) do {	\
+	volatile type __lval;			\
+						\
+	if (sizeof(type) >= sizeof(long double))	\
+		(lval) = (rval);		\
+	else {					\
+		__lval = (rval);		\
+		(lval) = __lval;		\
+	}					\
+} while (0)
+#endif
+#endif /* FLT_EVAL_METHOD */
+
+/* Support switching the mode to FP_PE if necessary. */
+#if defined(__i386__) && !defined(NO_FPSETPREC)
+#define	ENTERI()				\
+	long double __retval;			\
+	fp_prec_t __oprec;			\
+						\
+	if ((__oprec = fpgetprec()) != FP_PE)	\
+		fpsetprec(FP_PE)
+#define	RETURNI(x) do {				\
+	__retval = (x);				\
+	if (__oprec != FP_PE)			\
+		fpsetprec(__oprec);		\
+	RETURNF(__retval);			\
+} while (0)
+#else
+#define	ENTERI(x)
+#define	RETURNI(x)	RETURNF(x)
+#endif
+
+/* Default return statement if hack*_t() is not used. */
+#define      RETURNF(v)      return (v)
+
+/*
+ * Common routine to process the arguments to nan(), nanf(), and nanl().
+ */
+void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
+
+#ifdef _COMPLEX_H
+
+/*
+ * C99 specifies that complex numbers have the same representation as
+ * an array of two elements, where the first element is the real part
+ * and the second element is the imaginary part.
+ */
+typedef union {
+	float complex f;
+	float a[2];
+} float_complex;
+typedef union {
+	double complex f;
+	double a[2];
+} double_complex;
+typedef union {
+	long double complex f;
+	long double a[2];
+} long_double_complex;
+#define	REALPART(z)	((z).a[0])
+#define	IMAGPART(z)	((z).a[1])
+
+/*
+ * Inline functions that can be used to construct complex values.
+ *
+ * The C99 standard intends x+I*y to be used for this, but x+I*y is
+ * currently unusable in general since gcc introduces many overflow,
+ * underflow, sign and efficiency bugs by rewriting I*y as
+ * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
+ * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
+ * to -0.0+I*0.0.
+ */
+static __inline float complex
+cpackf(float x, float y)
+{
+	float_complex z;
+
+	REALPART(z) = x;
+	IMAGPART(z) = y;
+	return (z.f);
+}
+
+static __inline double complex
+cpack(double x, double y)
+{
+	double_complex z;
+
+	REALPART(z) = x;
+	IMAGPART(z) = y;
+	return (z.f);
+}
+
+static __inline long double complex
+cpackl(long double x, long double y)
+{
+	long_double_complex z;
+
+	REALPART(z) = x;
+	IMAGPART(z) = y;
+	return (z.f);
+}
+#endif /* _COMPLEX_H */
+ 
+#ifdef __GNUCLIKE_ASM
+
+/* Asm versions of some functions. */
+
+#ifdef __amd64__
+static __inline int
+irint(double x)
+{
+	int n;
+
+	asm("cvtsd2si %1,%0" : "=r" (n) : "x" (x));
+	return (n);
+}
+#define	HAVE_EFFICIENT_IRINT
+#endif
+
+#ifdef __i386__
+static __inline int
+irint(double x)
+{
+	int n;
+
+	asm("fistl %0" : "=m" (n) : "t" (x));
+	return (n);
+}
+#define	HAVE_EFFICIENT_IRINT
+#endif
+
+#if defined(__amd64__) || defined(__i386__)
+static __inline int
+irintl(long double x)
+{
+	int n;
+
+	asm("fistl %0" : "=m" (n) : "t" (x));
+	return (n);
+}
+#define	HAVE_EFFICIENT_IRINTL
+#endif
+
+#endif /* __GNUCLIKE_ASM */
+
+/*
+ * ieee style elementary functions
+ *
+ * We rename functions here to improve other sources' diffability
+ * against fdlibm.
+ */
+#define	__ieee754_sqrt	sqrt
+#define	__ieee754_acos	acos
+#define	__ieee754_acosh	acosh
+#define	__ieee754_log	log
+#define	__ieee754_log2	log2
+#define	__ieee754_atanh	atanh
+#define	__ieee754_asin	asin
+#define	__ieee754_atan2	atan2
+#define	__ieee754_exp	exp
+#define	__ieee754_cosh	cosh
+#define	__ieee754_fmod	fmod
+#define	__ieee754_pow	pow
+#define	__ieee754_lgamma lgamma
+#define	__ieee754_gamma	gamma
+#define	__ieee754_lgamma_r lgamma_r
+#define	__ieee754_gamma_r gamma_r
+#define	__ieee754_log10	log10
+#define	__ieee754_sinh	sinh
+#define	__ieee754_hypot	hypot
+#define	__ieee754_j0	j0
+#define	__ieee754_j1	j1
+#define	__ieee754_y0	y0
+#define	__ieee754_y1	y1
+#define	__ieee754_jn	jn
+#define	__ieee754_yn	yn
+#define	__ieee754_remainder remainder
+#define	__ieee754_scalb	scalb
+#define	__ieee754_sqrtf	sqrtf
+#define	__ieee754_acosf	acosf
+#define	__ieee754_acoshf acoshf
+#define	__ieee754_logf	logf
+#define	__ieee754_atanhf atanhf
+#define	__ieee754_asinf	asinf
+#define	__ieee754_atan2f atan2f
+#define	__ieee754_expf	expf
+#define	__ieee754_coshf	coshf
+#define	__ieee754_fmodf	fmodf
+#define	__ieee754_powf	powf
+#define	__ieee754_lgammaf lgammaf
+#define	__ieee754_gammaf gammaf
+#define	__ieee754_lgammaf_r lgammaf_r
+#define	__ieee754_gammaf_r gammaf_r
+#define	__ieee754_log10f log10f
+#define	__ieee754_log2f log2f
+#define	__ieee754_sinhf	sinhf
+#define	__ieee754_hypotf hypotf
+#define	__ieee754_j0f	j0f
+#define	__ieee754_j1f	j1f
+#define	__ieee754_y0f	y0f
+#define	__ieee754_y1f	y1f
+#define	__ieee754_jnf	jnf
+#define	__ieee754_ynf	ynf
+#define	__ieee754_remainderf remainderf
+#define	__ieee754_scalbf scalbf
+
+/* fdlibm kernel function */
+int	__kernel_rem_pio2(double*,double*,int,int,int);
+
+/* double precision kernel functions */
+#ifndef INLINE_REM_PIO2
+int	__ieee754_rem_pio2(double,double*);
+#endif
+double	__kernel_sin(double,double,int);
+double	__kernel_cos(double,double);
+double	__kernel_tan(double,double,int);
+double	__ldexp_exp(double,int);
+#ifdef _COMPLEX_H
+double complex __ldexp_cexp(double complex,int);
+#endif
+
+/* float precision kernel functions */
+#ifndef INLINE_REM_PIO2F
+int	__ieee754_rem_pio2f(float,double*);
+#endif
+#ifndef INLINE_KERNEL_SINDF
+float	__kernel_sindf(double);
+#endif
+#ifndef INLINE_KERNEL_COSDF
+float	__kernel_cosdf(double);
+#endif
+#ifndef INLINE_KERNEL_TANDF
+float	__kernel_tandf(double,int);
+#endif
+float	__ldexp_expf(float,int);
+#ifdef _COMPLEX_H
+float complex __ldexp_cexpf(float complex,int);
+#endif
+
+/* long double precision kernel functions */
+long double __kernel_sinl(long double, long double, int);
+long double __kernel_cosl(long double, long double);
+long double __kernel_tanl(long double, long double, int);
+
+#endif /* !_MATH_PRIVATE_H_ */
diff --git a/libm/src/s_asinh.c b/libm/upstream-freebsd/lib/msun/src/s_asinh.c
similarity index 92%
rename from libm/src/s_asinh.c
rename to libm/upstream-freebsd/lib/msun/src/s_asinh.c
index 079007f..f3fdf74 100644
--- a/libm/src/s_asinh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_asinh.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_asinh.c,v 1.8 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* asinh(x)
  * Method :
diff --git a/libm/src/s_asinhf.c b/libm/upstream-freebsd/lib/msun/src/s_asinhf.c
similarity index 91%
rename from libm/src/s_asinhf.c
rename to libm/upstream-freebsd/lib/msun/src/s_asinhf.c
index 73dc798..c1620dd 100644
--- a/libm/src/s_asinhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_asinhf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_asinhf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_atan.c b/libm/upstream-freebsd/lib/msun/src/s_atan.c
similarity index 92%
rename from libm/src/s_atan.c
rename to libm/upstream-freebsd/lib/msun/src/s_atan.c
index 23d7aa8..566f5dc 100644
--- a/libm/src/s_atan.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_atan.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atan.c,v 1.9 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* atan(x)
  * Method
@@ -34,6 +33,8 @@
  * to produce the hexadecimal values shown.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -83,10 +84,10 @@
 	    if(ix>0x7ff00000||
 		(ix==0x7ff00000&&(low!=0)))
 		return x+x;		/* NaN */
-	    if(hx>0) return  atanhi[3]+atanlo[3];
-	    else     return -atanhi[3]-atanlo[3];
+	    if(hx>0) return  atanhi[3]+*(volatile double *)&atanlo[3];
+	    else     return -atanhi[3]-*(volatile double *)&atanlo[3];
 	} if (ix < 0x3fdc0000) {	/* |x| < 0.4375 */
-	    if (ix < 0x3e200000) {	/* |x| < 2^-29 */
+	    if (ix < 0x3e400000) {	/* |x| < 2^-27 */
 		if(huge+x>one) return x;	/* raise inexact */
 	    }
 	    id = -1;
@@ -117,3 +118,7 @@
 	    return (hx<0)? -z:z;
 	}
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(atan, atanl);
+#endif
diff --git a/libm/src/s_atanf.c b/libm/upstream-freebsd/lib/msun/src/s_atanf.c
similarity index 69%
rename from libm/src/s_atanf.c
rename to libm/upstream-freebsd/lib/msun/src/s_atanf.c
index f90b35d..b3a371f 100644
--- a/libm/src/s_atanf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_atanf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atanf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -35,20 +34,14 @@
 };
 
 static const float aT[] = {
-  3.3333334327e-01, /* 0x3eaaaaaa */
- -2.0000000298e-01, /* 0xbe4ccccd */
-  1.4285714924e-01, /* 0x3e124925 */
- -1.1111110449e-01, /* 0xbde38e38 */
-  9.0908870101e-02, /* 0x3dba2e6e */
- -7.6918758452e-02, /* 0xbd9d8795 */
-  6.6610731184e-02, /* 0x3d886b35 */
- -5.8335702866e-02, /* 0xbd6ef16b */
-  4.9768779427e-02, /* 0x3d4bda59 */
- -3.6531571299e-02, /* 0xbd15a221 */
-  1.6285819933e-02, /* 0x3c8569d7 */
+  3.3333328366e-01,
+ -1.9999158382e-01,
+  1.4253635705e-01,
+ -1.0648017377e-01,
+  6.1687607318e-02,
 };
 
-	static const float
+static const float
 one   = 1.0,
 huge   = 1.0e30;
 
@@ -60,13 +53,13 @@
 
 	GET_FLOAT_WORD(hx,x);
 	ix = hx&0x7fffffff;
-	if(ix>=0x50800000) {	/* if |x| >= 2^34 */
+	if(ix>=0x4c800000) {	/* if |x| >= 2**26 */
 	    if(ix>0x7f800000)
 		return x+x;		/* NaN */
-	    if(hx>0) return  atanhi[3]+atanlo[3];
-	    else     return -atanhi[3]-atanlo[3];
+	    if(hx>0) return  atanhi[3]+*(volatile float *)&atanlo[3];
+	    else     return -atanhi[3]-*(volatile float *)&atanlo[3];
 	} if (ix < 0x3ee00000) {	/* |x| < 0.4375 */
-	    if (ix < 0x31000000) {	/* |x| < 2^-29 */
+	    if (ix < 0x39800000) {	/* |x| < 2**-12 */
 		if(huge+x>one) return x;	/* raise inexact */
 	    }
 	    id = -1;
@@ -81,7 +74,7 @@
 	} else {
 	    if (ix < 0x401c0000) {	/* |x| < 2.4375 */
 		id = 2; x  = (x-(float)1.5)/(one+(float)1.5*x);
-	    } else {			/* 2.4375 <= |x| < 2^66 */
+	    } else {			/* 2.4375 <= |x| < 2**26 */
 		id = 3; x  = -(float)1.0/x;
 	    }
 	}}
@@ -89,8 +82,8 @@
 	z = x*x;
 	w = z*z;
     /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
-	s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));
-	s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));
+	s1 = z*(aT[0]+w*(aT[2]+w*aT[4]));
+	s2 = w*(aT[1]+w*aT[3]);
 	if (id<0) return x - x*(s1+s2);
 	else {
 	    z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_atanl.c b/libm/upstream-freebsd/lib/msun/src/s_atanl.c
new file mode 100644
index 0000000..ff29c3c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_atanl.c
@@ -0,0 +1,85 @@
+/* @(#)s_atan.c 5.1 93/09/24 */
+/* FreeBSD: head/lib/msun/src/s_atan.c 176451 2008-02-22 02:30:36Z das */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * See comments in s_atan.c.
+ * Converted to long double by David Schultz <das@FreeBSD.ORG>.
+ */
+
+#include <float.h>
+
+#include "invtrig.h"
+#include "math.h"
+#include "math_private.h"
+
+static const long double
+one   = 1.0,
+huge   = 1.0e300;
+
+long double
+atanl(long double x)
+{
+	union IEEEl2bits u;
+	long double w,s1,s2,z;
+	int id;
+	int16_t expsign, expt;
+	int32_t expman;
+
+	u.e = x;
+	expsign = u.xbits.expsign;
+	expt = expsign & 0x7fff;
+	if(expt >= ATAN_CONST) {	/* if |x| is large, atan(x)~=pi/2 */
+	    if(expt == BIAS + LDBL_MAX_EXP &&
+	       ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)!=0)
+		return x+x;		/* NaN */
+	    if(expsign>0) return  atanhi[3]+atanlo[3];
+	    else     return -atanhi[3]-atanlo[3];
+	}
+	/* Extract the exponent and the first few bits of the mantissa. */
+	/* XXX There should be a more convenient way to do this. */
+	expman = (expt << 8) | ((u.bits.manh >> (MANH_SIZE - 9)) & 0xff);
+	if (expman < ((BIAS - 2) << 8) + 0xc0) {	/* |x| < 0.4375 */
+	    if (expt < ATAN_LINEAR) {	/* if |x| is small, atanl(x)~=x */
+		if(huge+x>one) return x;	/* raise inexact */
+	    }
+	    id = -1;
+	} else {
+	x = fabsl(x);
+	if (expman < (BIAS << 8) + 0x30) {		/* |x| < 1.1875 */
+	    if (expman < ((BIAS - 1) << 8) + 0x60) {	/* 7/16 <=|x|<11/16 */
+		id = 0; x = (2.0*x-one)/(2.0+x);
+	    } else {			/* 11/16<=|x|< 19/16 */
+		id = 1; x  = (x-one)/(x+one);
+	    }
+	} else {
+	    if (expman < ((BIAS + 1) << 8) + 0x38) {	/* |x| < 2.4375 */
+		id = 2; x  = (x-1.5)/(one+1.5*x);
+	    } else {			/* 2.4375 <= |x| < 2^ATAN_CONST */
+		id = 3; x  = -1.0/x;
+	    }
+	}}
+    /* end of argument reduction */
+	z = x*x;
+	w = z*z;
+    /* break sum aT[i]z**(i+1) into odd and even poly */
+	s1 = z*T_even(w);
+	s2 = w*T_odd(w);
+	if (id<0) return x - x*(s1+s2);
+	else {
+	    z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
+	    return (expsign<0)? -z:z;
+	}
+}
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_carg.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_carg.c
index 6a347c1..ea1a0d7 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_carg.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,14 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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);	\
-}
+double
+carg(double complex z)
+{
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+	return (atan2(cimag(z), creal(z)));
+}
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_cargf.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_cargf.c
index 6a347c1..90232d0 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cargf.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,14 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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);	\
-}
+float
+cargf(float complex z)
+{
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+	return (atan2f(cimagf(z), crealf(z)));
+}
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_cargl.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_cargl.c
index 6a347c1..0555083 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cargl.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,14 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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);	\
-}
+long double
+cargl(long double complex z)
+{
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+	return (atan2l(cimagl(z), creall(z)));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrt.c b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c
new file mode 100644
index 0000000..910f75b
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrt.c
@@ -0,0 +1,117 @@
+/* @(#)s_cbrt.c 5.1 93/09/24 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "math.h"
+#include "math_private.h"
+
+/* cbrt(x)
+ * Return cube root of x
+ */
+static const u_int32_t
+	B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */
+	B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */
+
+/* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */
+static const double
+P0 =  1.87595182427177009643,		/* 0x3ffe03e6, 0x0f61e692 */
+P1 = -1.88497979543377169875,		/* 0xbffe28e0, 0x92f02420 */
+P2 =  1.621429720105354466140,		/* 0x3ff9f160, 0x4a49d6c2 */
+P3 = -0.758397934778766047437,		/* 0xbfe844cb, 0xbee751d9 */
+P4 =  0.145996192886612446982;		/* 0x3fc2b000, 0xd4e4edd7 */
+
+double
+cbrt(double x)
+{
+	int32_t	hx;
+	union {
+	    double value;
+	    uint64_t bits;
+	} u;
+	double r,s,t=0.0,w;
+	u_int32_t sign;
+	u_int32_t high,low;
+
+	EXTRACT_WORDS(hx,low,x);
+	sign=hx&0x80000000; 		/* sign= sign(x) */
+	hx  ^=sign;
+	if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
+
+    /*
+     * Rough cbrt to 5 bits:
+     *    cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3)
+     * where e is integral and >= 0, m is real and in [0, 1), and "/" and
+     * "%" are integer division and modulus with rounding towards minus
+     * infinity.  The RHS is always >= the LHS and has a maximum relative
+     * error of about 1 in 16.  Adding a bias of -0.03306235651 to the
+     * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE
+     * floating point representation, for finite positive normal values,
+     * ordinary integer divison of the value in bits magically gives
+     * almost exactly the RHS of the above provided we first subtract the
+     * exponent bias (1023 for doubles) and later add it back.  We do the
+     * subtraction virtually to keep e >= 0 so that ordinary integer
+     * division rounds towards minus infinity; this is also efficient.
+     */
+	if(hx<0x00100000) { 		/* zero or subnormal? */
+	    if((hx|low)==0)
+		return(x);		/* cbrt(0) is itself */
+	    SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */
+	    t*=x;
+	    GET_HIGH_WORD(high,t);
+	    INSERT_WORDS(t,sign|((high&0x7fffffff)/3+B2),0);
+	} else
+	    INSERT_WORDS(t,sign|(hx/3+B1),0);
+
+    /*
+     * New cbrt to 23 bits:
+     *    cbrt(x) = t*cbrt(x/t**3) ~= t*P(t**3/x)
+     * where P(r) is a polynomial of degree 4 that approximates 1/cbrt(r)
+     * to within 2**-23.5 when |r - 1| < 1/10.  The rough approximation
+     * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this
+     * gives us bounds for r = t**3/x.
+     *
+     * Try to optimize for parallel evaluation as in k_tanf.c.
+     */
+	r=(t*t)*(t/x);
+	t=t*((P0+r*(P1+r*P2))+((r*r)*r)*(P3+r*P4));
+
+    /*
+     * Round t away from zero to 23 bits (sloppily except for ensuring that
+     * the result is larger in magnitude than cbrt(x) but not much more than
+     * 2 23-bit ulps larger).  With rounding towards zero, the error bound
+     * would be ~5/6 instead of ~4/6.  With a maximum error of 2 23-bit ulps
+     * in the rounded t, the infinite-precision error in the Newton
+     * approximation barely affects third digit in the final error
+     * 0.667; the error in the rounded t can be up to about 3 23-bit ulps
+     * before the final error is larger than 0.667 ulps.
+     */
+	u.value=t;
+	u.bits=(u.bits+0x80000000)&0xffffffffc0000000ULL;
+	t=u.value;
+
+    /* one step Newton iteration to 53 bits with error < 0.667 ulps */
+	s=t*t;				/* t*t is exact */
+	r=x/s;				/* error <= 0.5 ulps; |r| < |t| */
+	w=t+t;				/* t+t is exact */
+	r=(r-t)/(w+r);			/* r-t is exact; w+r ~= 3*t */
+	t=t+t*r;			/* error <= 0.5 + 0.5/3 + epsilon */
+
+	return(t);
+}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(cbrt, cbrtl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c
new file mode 100644
index 0000000..454f974
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtf.c
@@ -0,0 +1,73 @@
+/* s_cbrtf.c -- float version of s_cbrt.c.
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
+ * Debugged and optimized by Bruce D. Evans.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "math.h"
+#include "math_private.h"
+
+/* cbrtf(x)
+ * Return cube root of x
+ */
+static const unsigned
+	B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */
+	B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
+
+float
+cbrtf(float x)
+{
+	double r,T;
+	float t;
+	int32_t hx;
+	u_int32_t sign;
+	u_int32_t high;
+
+	GET_FLOAT_WORD(hx,x);
+	sign=hx&0x80000000; 		/* sign= sign(x) */
+	hx  ^=sign;
+	if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
+
+    /* rough cbrt to 5 bits */
+	if(hx<0x00800000) { 		/* zero or subnormal? */
+	    if(hx==0)
+		return(x);		/* cbrt(+-0) is itself */
+	    SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
+	    t*=x;
+	    GET_FLOAT_WORD(high,t);
+	    SET_FLOAT_WORD(t,sign|((high&0x7fffffff)/3+B2));
+	} else
+	    SET_FLOAT_WORD(t,sign|(hx/3+B1));
+
+    /*
+     * First step Newton iteration (solving t*t-x/t == 0) to 16 bits.  In
+     * double precision so that its terms can be arranged for efficiency
+     * without causing overflow or underflow.
+     */
+	T=t;
+	r=T*T*T;
+	T=T*((double)x+x+r)/(x+r+r);
+
+    /*
+     * Second step Newton iteration to 47 bits.  In double precision for
+     * efficiency and accuracy.
+     */
+	r=T*T*T;
+	T=T*((double)x+x+r)/(x+r+r);
+
+    /* rounding to 24 bits is perfect in round-to-nearest mode */
+	return(T);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c
new file mode 100644
index 0000000..2236c0f
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cbrtl.c
@@ -0,0 +1,143 @@
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * The argument reduction and testing for exceptional cases was
+ * written by Steven G. Kargl with input from Bruce D. Evans
+ * and David A. Schultz.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"    
+#include "math.h"
+#include "math_private.h"
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const unsigned
+    B1 = 709958130;	/* B1 = (127-127.0/3-0.03306235651)*2**23 */
+
+long double
+cbrtl(long double x)
+{
+	union IEEEl2bits u, v;
+	long double r, s, t, w;
+	double dr, dt, dx;
+	float ft, fx;
+	uint32_t hx;
+	uint16_t expsign;
+	int k;
+
+	u.e = x;
+	expsign = u.xbits.expsign;
+	k = expsign & 0x7fff;
+
+	/*
+	 * If x = +-Inf, then cbrt(x) = +-Inf.
+	 * If x = NaN, then cbrt(x) = NaN.
+	 */
+	if (k == BIAS + LDBL_MAX_EXP)
+		return (x + x);
+
+	ENTERI();
+	if (k == 0) {
+		/* If x = +-0, then cbrt(x) = +-0. */
+		if ((u.bits.manh | u.bits.manl) == 0)
+			RETURNI(x);
+		/* Adjust subnormal numbers. */
+		u.e *= 0x1.0p514;
+		k = u.bits.exp;
+		k -= BIAS + 514;
+ 	} else
+		k -= BIAS;
+	u.xbits.expsign = BIAS;
+	v.e = 1; 
+
+	x = u.e;
+	switch (k % 3) {
+	case 1:
+	case -2:
+		x = 2*x;
+		k--;
+		break;
+	case 2:
+	case -1:
+		x = 4*x;
+		k -= 2;
+		break;
+	}
+	v.xbits.expsign = (expsign & 0x8000) | (BIAS + k / 3);
+
+	/*
+	 * The following is the guts of s_cbrtf, with the handling of
+	 * special values removed and extra care for accuracy not taken,
+	 * but with most of the extra accuracy not discarded.
+	 */
+
+	/* ~5-bit estimate: */
+	fx = x;
+	GET_FLOAT_WORD(hx, fx);
+	SET_FLOAT_WORD(ft, ((hx & 0x7fffffff) / 3 + B1));
+
+	/* ~16-bit estimate: */
+	dx = x;
+	dt = ft;
+	dr = dt * dt * dt;
+	dt = dt * (dx + dx + dr) / (dx + dr + dr);
+
+	/* ~47-bit estimate: */
+	dr = dt * dt * dt;
+	dt = dt * (dx + dx + dr) / (dx + dr + dr);
+
+#if LDBL_MANT_DIG == 64
+	/*
+	 * dt is cbrtl(x) to ~47 bits (after x has been reduced to 1 <= x < 8).
+	 * Round it away from zero to 32 bits (32 so that t*t is exact, and
+	 * away from zero for technical reasons).
+	 */
+	volatile double vd2 = 0x1.0p32;
+	volatile double vd1 = 0x1.0p-31;
+	#define vd ((long double)vd2 + vd1)
+
+	t = dt + vd - 0x1.0p32;
+#elif LDBL_MANT_DIG == 113
+	/*
+	 * Round dt away from zero to 47 bits.  Since we don't trust the 47,
+	 * add 2 47-bit ulps instead of 1 to round up.  Rounding is slow and
+	 * might be avoidable in this case, since on most machines dt will
+	 * have been evaluated in 53-bit precision and the technical reasons
+	 * for rounding up might not apply to either case in cbrtl() since
+	 * dt is much more accurate than needed.
+	 */
+	t = dt + 0x2.0p-46 + 0x1.0p60L - 0x1.0p60;
+#else
+#error "Unsupported long double format"
+#endif
+
+	/*
+     	 * Final step Newton iteration to 64 or 113 bits with
+	 * error < 0.667 ulps
+	 */
+	s=t*t;				/* t*t is exact */
+	r=x/s;				/* error <= 0.5 ulps; |r| < |t| */
+	w=t+t;				/* t+t is exact */
+	r=(r-t)/(w+r);			/* r-t is exact; w+r ~= 3*t */
+	t=t+t*r;			/* error <= 0.5 + 0.5/3 + epsilon */
+
+	t *= v.e;
+	RETURNI(t);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccosh.c b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
new file mode 100644
index 0000000..9ea962b
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccosh.c
@@ -0,0 +1,155 @@
+/*-
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic cosine of a complex argument z = x + i y.
+ *
+ * cosh(z) = cosh(x+iy)
+ *         = cosh(x) cos(y) + i sinh(x) sin(y).
+ *
+ * Exceptional values are noted in the comments within the source code.
+ * These values and the return value were taken from n1124.pdf.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const double huge = 0x1p1023;
+
+double complex
+ccosh(double complex z)
+{
+	double x, y, h;
+	int32_t hx, hy, ix, iy, lx, ly;
+
+	x = creal(z);
+	y = cimag(z);
+
+	EXTRACT_WORDS(hx, lx, x);
+	EXTRACT_WORDS(hy, ly, y);
+
+	ix = 0x7fffffff & hx;
+	iy = 0x7fffffff & hy;
+
+	/* Handle the nearly-non-exceptional cases where x and y are finite. */
+	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
+		if ((iy | ly) == 0)
+			return (cpack(cosh(x), x * y));
+		if (ix < 0x40360000)	/* small x: normal case */
+			return (cpack(cosh(x) * cos(y), sinh(x) * sin(y)));
+
+		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
+		if (ix < 0x40862e42) {
+			/* x < 710: exp(|x|) won't overflow */
+			h = exp(fabs(x)) * 0.5;
+			return (cpack(h * cos(y), copysign(h, x) * sin(y)));
+		} else if (ix < 0x4096bbaa) {
+			/* x < 1455: scale to avoid overflow */
+			z = __ldexp_cexp(cpack(fabs(x), y), -1);
+			return (cpack(creal(z), cimag(z) * copysign(1, x)));
+		} else {
+			/* x >= 1455: the result always overflows */
+			h = huge * x;
+			return (cpack(h * h * cos(y), h * sin(y)));
+		}
+	}
+
+	/*
+	 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0.
+	 * The sign of 0 in the result is unspecified.  Choice = normally
+	 * the same as dNaN.  Raise the invalid floating-point exception.
+	 *
+	 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0.
+	 * The sign of 0 in the result is unspecified.  Choice = normally
+	 * the same as d(NaN).
+	 */
+	if ((ix | lx) == 0 && iy >= 0x7ff00000)
+		return (cpack(y - y, copysign(0, x * (y - y))));
+
+	/*
+	 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
+	 *
+	 * cosh(NaN +- I 0)   = d(NaN) + I sign(d(NaN, +-0))0.
+	 * The sign of 0 in the result is unspecified.
+	 */
+	if ((iy | ly) == 0 && ix >= 0x7ff00000) {
+		if (((hx & 0xfffff) | lx) == 0)
+			return (cpack(x * x, copysign(0, x) * y));
+		return (cpack(x * x, copysign(0, (x + x) * y)));
+	}
+
+	/*
+	 * cosh(x +- I Inf) = dNaN + I dNaN.
+	 * Raise the invalid floating-point exception for finite nonzero x.
+	 *
+	 * cosh(x + I NaN) = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception for finite
+	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
+	 */
+	if (ix < 0x7ff00000 && iy >= 0x7ff00000)
+		return (cpack(y - y, x * (y - y)));
+
+	/*
+	 * cosh(+-Inf + I NaN)  = +Inf + I d(NaN).
+	 *
+	 * cosh(+-Inf +- I Inf) = +Inf + I dNaN.
+	 * The sign of Inf in the result is unspecified.  Choice = always +.
+	 * Raise the invalid floating-point exception.
+	 *
+	 * cosh(+-Inf + I y)   = +Inf cos(y) +- I Inf sin(y)
+	 */
+	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
+		if (iy >= 0x7ff00000)
+			return (cpack(x * x, x * (y - y)));
+		return (cpack((x * x) * cos(y), x * sin(y)));
+	}
+
+	/*
+	 * cosh(NaN + I NaN)  = d(NaN) + I d(NaN).
+	 *
+	 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception.
+	 * Choice = raise.
+	 *
+	 * cosh(NaN + I y)    = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception for finite
+	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
+	 */
+	return (cpack((x * x) * (y - y), (x + x) * (y - y)));
+}
+
+double complex
+ccos(double complex z)
+{
+
+	/* ccos(z) = ccosh(I * z) */
+	return (ccosh(cpack(-cimag(z), creal(z))));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
new file mode 100644
index 0000000..1de9ad4
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_ccoshf.c
@@ -0,0 +1,104 @@
+/*-
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic cosine of a complex argument.  See s_ccosh.c for details.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const float huge = 0x1p127;
+
+float complex
+ccoshf(float complex z)
+{
+	float x, y, h;
+	int32_t hx, hy, ix, iy;
+
+	x = crealf(z);
+	y = cimagf(z);
+
+	GET_FLOAT_WORD(hx, x);
+	GET_FLOAT_WORD(hy, y);
+
+	ix = 0x7fffffff & hx;
+	iy = 0x7fffffff & hy;
+
+	if (ix < 0x7f800000 && iy < 0x7f800000) {
+		if (iy == 0)
+			return (cpackf(coshf(x), x * y));
+		if (ix < 0x41100000)	/* small x: normal case */
+			return (cpackf(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
+
+		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
+		if (ix < 0x42b17218) {
+			/* x < 88.7: expf(|x|) won't overflow */
+			h = expf(fabsf(x)) * 0.5f;
+			return (cpackf(h * cosf(y), copysignf(h, x) * sinf(y)));
+		} else if (ix < 0x4340b1e7) {
+			/* x < 192.7: scale to avoid overflow */
+			z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
+			return (cpackf(crealf(z), cimagf(z) * copysignf(1, x)));
+		} else {
+			/* x >= 192.7: the result always overflows */
+			h = huge * x;
+			return (cpackf(h * h * cosf(y), h * sinf(y)));
+		}
+	}
+
+	if (ix == 0 && iy >= 0x7f800000)
+		return (cpackf(y - y, copysignf(0, x * (y - y))));
+
+	if (iy == 0 && ix >= 0x7f800000) {
+		if ((hx & 0x7fffff) == 0)
+			return (cpackf(x * x, copysignf(0, x) * y));
+		return (cpackf(x * x, copysignf(0, (x + x) * y)));
+	}
+
+	if (ix < 0x7f800000 && iy >= 0x7f800000)
+		return (cpackf(y - y, x * (y - y)));
+
+	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
+		if (iy >= 0x7f800000)
+			return (cpackf(x * x, x * (y - y)));
+		return (cpackf((x * x) * cosf(y), x * sinf(y)));
+	}
+
+	return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
+}
+
+float complex
+ccosf(float complex z)
+{
+
+	return (ccoshf(cpackf(-cimagf(z), crealf(z))));
+}
diff --git a/libm/src/s_ceil.c b/libm/upstream-freebsd/lib/msun/src/s_ceil.c
similarity index 92%
rename from libm/src/s_ceil.c
rename to libm/upstream-freebsd/lib/msun/src/s_ceil.c
index e5440e2..929f813 100644
--- a/libm/src/s_ceil.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ceil.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceil.c,v 1.9 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * ceil(x)
@@ -23,6 +22,8 @@
  *	Inexact flag raised if x not equal to ceil(x).
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -70,3 +71,7 @@
 	INSERT_WORDS(x,i0,i1);
 	return x;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(ceil, ceill);
+#endif
diff --git a/libm/src/s_ceilf.c b/libm/upstream-freebsd/lib/msun/src/s_ceilf.c
similarity index 90%
rename from libm/src/s_ceilf.c
rename to libm/upstream-freebsd/lib/msun/src/s_ceilf.c
index 5c465b3..23bfe04 100644
--- a/libm/src/s_ceilf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ceilf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceilf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_ceill.c b/libm/upstream-freebsd/lib/msun/src/s_ceill.c
similarity index 93%
rename from libm/src/s_ceill.c
rename to libm/upstream-freebsd/lib/msun/src/s_ceill.c
index 7e8817c..2d1045f 100644
--- a/libm/src/s_ceill.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ceill.c
@@ -11,9 +11,8 @@
  * From: @(#)s_ceil.c 5.1 93/09/24
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ceill.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * ceill(x)
@@ -63,7 +62,7 @@
 			if (huge + x > 0.0)
 				if (u.bits.exp > 0 ||
 				    (u.bits.manh | u.bits.manl) != 0)
-					u.e = u.bits.sign ? 0.0 : 1.0;
+					u.e = u.bits.sign ? -0.0 : 1.0;
 		} else {
 			uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
 			if (((u.bits.manh & m) | u.bits.manl) == 0)
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cexp.c b/libm/upstream-freebsd/lib/msun/src/s_cexp.c
new file mode 100644
index 0000000..abe178f
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cexp.c
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const uint32_t
+exp_ovfl  = 0x40862e42,			/* high bits of MAX_EXP * ln2 ~= 710 */
+cexp_ovfl = 0x4096b8e4;			/* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
+
+double complex
+cexp(double complex z)
+{
+	double x, y, exp_x;
+	uint32_t hx, hy, lx, ly;
+
+	x = creal(z);
+	y = cimag(z);
+
+	EXTRACT_WORDS(hy, ly, y);
+	hy &= 0x7fffffff;
+
+	/* cexp(x + I 0) = exp(x) + I 0 */
+	if ((hy | ly) == 0)
+		return (cpack(exp(x), y));
+	EXTRACT_WORDS(hx, lx, x);
+	/* cexp(0 + I y) = cos(y) + I sin(y) */
+	if (((hx & 0x7fffffff) | lx) == 0)
+		return (cpack(cos(y), sin(y)));
+
+	if (hy >= 0x7ff00000) {
+		if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) {
+			/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
+			return (cpack(y - y, y - y));
+		} else if (hx & 0x80000000) {
+			/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
+			return (cpack(0.0, 0.0));
+		} else {
+			/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
+			return (cpack(x, y - y));
+		}
+	}
+
+	if (hx >= exp_ovfl && hx <= cexp_ovfl) {
+		/*
+		 * x is between 709.7 and 1454.3, so we must scale to avoid
+		 * overflow in exp(x).
+		 */
+		return (__ldexp_cexp(z, 0));
+	} else {
+		/*
+		 * Cases covered here:
+		 *  -  x < exp_ovfl and exp(x) won't overflow (common case)
+		 *  -  x > cexp_ovfl, so exp(x) * s overflows for all s > 0
+		 *  -  x = +-Inf (generated by exp())
+		 *  -  x = NaN (spurious inexact exception from y)
+		 */
+		exp_x = exp(x);
+		return (cpack(exp_x * cos(y), exp_x * sin(y)));
+	}
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cexpf.c b/libm/upstream-freebsd/lib/msun/src/s_cexpf.c
new file mode 100644
index 0000000..0e30d08
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cexpf.c
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const uint32_t
+exp_ovfl  = 0x42b17218,		/* MAX_EXP * ln2 ~= 88.722839355 */
+cexp_ovfl = 0x43400074;		/* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
+
+float complex
+cexpf(float complex z)
+{
+	float x, y, exp_x;
+	uint32_t hx, hy;
+
+	x = crealf(z);
+	y = cimagf(z);
+
+	GET_FLOAT_WORD(hy, y);
+	hy &= 0x7fffffff;
+
+	/* cexp(x + I 0) = exp(x) + I 0 */
+	if (hy == 0)
+		return (cpackf(expf(x), y));
+	GET_FLOAT_WORD(hx, x);
+	/* cexp(0 + I y) = cos(y) + I sin(y) */
+	if ((hx & 0x7fffffff) == 0)
+		return (cpackf(cosf(y), sinf(y)));
+
+	if (hy >= 0x7f800000) {
+		if ((hx & 0x7fffffff) != 0x7f800000) {
+			/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
+			return (cpackf(y - y, y - y));
+		} else if (hx & 0x80000000) {
+			/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
+			return (cpackf(0.0, 0.0));
+		} else {
+			/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
+			return (cpackf(x, y - y));
+		}
+	}
+
+	if (hx >= exp_ovfl && hx <= cexp_ovfl) {
+		/*
+		 * x is between 88.7 and 192, so we must scale to avoid
+		 * overflow in expf(x).
+		 */
+		return (__ldexp_cexpf(z, 0));
+	} else {
+		/*
+		 * Cases covered here:
+		 *  -  x < exp_ovfl and exp(x) won't overflow (common case)
+		 *  -  x > cexp_ovfl, so exp(x) * s overflows for all s > 0
+		 *  -  x = +-Inf (generated by exp())
+		 *  -  x = NaN (spurious inexact exception from y)
+		 */
+		exp_x = expf(x);
+		return (cpackf(exp_x * cosf(y), exp_x * sinf(y)));
+	}
+}
diff --git a/libm/src/s_cimag.c b/libm/upstream-freebsd/lib/msun/src/s_cimag.c
similarity index 92%
rename from libm/src/s_cimag.c
rename to libm/upstream-freebsd/lib/msun/src/s_cimag.c
index e4be0b3..cbf6720 100644
--- a/libm/src/s_cimag.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cimag.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_cimag.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
+#include "math_private.h"
 
 double
 cimag(double complex z)
 {
-	return -z * I;
+	const double_complex z1 = { .f = z };
+
+	return (IMAGPART(z1));
 }
diff --git a/libm/src/s_cimagf.c b/libm/upstream-freebsd/lib/msun/src/s_cimagf.c
similarity index 92%
rename from libm/src/s_cimagf.c
rename to libm/upstream-freebsd/lib/msun/src/s_cimagf.c
index 1e0f53f..4e483a2 100644
--- a/libm/src/s_cimagf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cimagf.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_cimagf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
+#include "math_private.h"
 
 float
 cimagf(float complex z)
 {
-	return -z * I;
+	const float_complex z1 = { .f = z };
+
+	return (IMAGPART(z1));
 }
diff --git a/libm/src/s_cimagl.c b/libm/upstream-freebsd/lib/msun/src/s_cimagl.c
similarity index 92%
rename from libm/src/s_cimagl.c
rename to libm/upstream-freebsd/lib/msun/src/s_cimagl.c
index a87677e..c50e967 100644
--- a/libm/src/s_cimagl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cimagl.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_cimagl.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
+#include "math_private.h"
 
 long double
 cimagl(long double complex z)
 {
-	return -z * I;
+	const long_double_complex z1 = { .f = z };
+
+	return (IMAGPART(z1));
 }
diff --git a/libm/src/s_conj.c b/libm/upstream-freebsd/lib/msun/src/s_conj.c
similarity index 92%
rename from libm/src/s_conj.c
rename to libm/upstream-freebsd/lib/msun/src/s_conj.c
index d47a15d..5770c29 100644
--- a/libm/src/s_conj.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_conj.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_conj.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
 
+#include "math_private.h"
+
 double complex
 conj(double complex z)
 {
-	return creal(z) - I * cimag(z);
+
+	return (cpack(creal(z), -cimag(z)));
 }
diff --git a/libm/src/s_conjf.c b/libm/upstream-freebsd/lib/msun/src/s_conjf.c
similarity index 92%
rename from libm/src/s_conjf.c
rename to libm/upstream-freebsd/lib/msun/src/s_conjf.c
index 24e0398..b090760 100644
--- a/libm/src/s_conjf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_conjf.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_conjf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
 
+#include "math_private.h"
+
 float complex
 conjf(float complex z)
 {
-	return crealf(z) - I * cimagf(z);
+
+	return (cpackf(crealf(z), -cimagf(z)));
 }
diff --git a/libm/src/s_conjl.c b/libm/upstream-freebsd/lib/msun/src/s_conjl.c
similarity index 92%
rename from libm/src/s_conjl.c
rename to libm/upstream-freebsd/lib/msun/src/s_conjl.c
index 13d80c2..0e431ef 100644
--- a/libm/src/s_conjl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_conjl.c
@@ -23,13 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_conjl.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
 
+#include "math_private.h"
+
 long double complex
 conjl(long double complex z)
 {
-	return creall(z) - I * cimagl(z);
+
+	return (cpackl(creall(z), -cimagl(z)));
 }
diff --git a/libm/src/s_copysign.c b/libm/upstream-freebsd/lib/msun/src/s_copysign.c
similarity index 85%
rename from libm/src/s_copysign.c
rename to libm/upstream-freebsd/lib/msun/src/s_copysign.c
index f37be0d..a5f3870 100644
--- a/libm/src/s_copysign.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_copysign.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_copysign.c,v 1.9 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * copysign(double x, double y)
diff --git a/libm/src/s_copysignf.c b/libm/upstream-freebsd/lib/msun/src/s_copysignf.c
similarity index 87%
rename from libm/src/s_copysignf.c
rename to libm/upstream-freebsd/lib/msun/src/s_copysignf.c
index 79c4480..05ca1e3 100644
--- a/libm/src/s_copysignf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_copysignf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_copysignf.c,v 1.9 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * copysignf(float x, float y)
diff --git a/libm/src/s_copysignl.c b/libm/upstream-freebsd/lib/msun/src/s_copysignl.c
similarity index 94%
rename from libm/src/s_copysignl.c
rename to libm/upstream-freebsd/lib/msun/src/s_copysignl.c
index 5c5bd39..8d39f84 100644
--- a/libm/src/s_copysignl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_copysignl.c
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_copysignl.c,v 1.1 2004/05/07 18:56:31 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <math.h>
diff --git a/libm/src/s_cos.c b/libm/upstream-freebsd/lib/msun/src/s_cos.c
similarity index 89%
rename from libm/src/s_cos.c
rename to libm/upstream-freebsd/lib/msun/src/s_cos.c
index 0faf91e..29804f4 100644
--- a/libm/src/s_cos.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cos.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cos.c,v 1.10 2005/10/24 14:08:36 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* cos(x)
  * Return cosine function of x.
@@ -45,8 +44,12 @@
  *	TRIG(x) returns trig(x) nearly rounded
  */
 
+#include <float.h>
+
 #include "math.h"
+#define INLINE_REM_PIO2
 #include "math_private.h"
+#include "e_rem_pio2.c"
 
 double
 cos(double x)
@@ -60,7 +63,7 @@
     /* |x| ~< pi/4 */
 	ix &= 0x7fffffff;
 	if(ix <= 0x3fe921fb) {
-	    if(ix<0x3e400000)			/* if x < 2**-27 */
+	    if(ix<0x3e46a09e)			/* if x < 2**-27 * sqrt(2) */
 		if(((int)x)==0) return 1.0;	/* generate inexact */
 	    return __kernel_cos(x,z);
 	}
@@ -80,3 +83,7 @@
 	    }
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(cos, cosl);
+#endif
diff --git a/libm/src/s_cosf.c b/libm/upstream-freebsd/lib/msun/src/s_cosf.c
similarity index 83%
rename from libm/src/s_cosf.c
rename to libm/upstream-freebsd/lib/msun/src/s_cosf.c
index 31adade..b701fd2 100644
--- a/libm/src/s_cosf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cosf.c
@@ -14,14 +14,17 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_cosf.c,v 1.15 2005/11/30 06:47:18 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #define	INLINE_KERNEL_COSDF
 #define	INLINE_KERNEL_SINDF
+#define INLINE_REM_PIO2F
 #include "math_private.h"
+#include "e_rem_pio2f.c"
 #include "k_cosf.c"
 #include "k_sinf.c"
 
@@ -35,7 +38,7 @@
 float
 cosf(float x)
 {
-	float y[2];
+	double y;
 	int32_t n, hx, ix;
 
 	GET_FLOAT_WORD(hx,x);
@@ -72,13 +75,13 @@
 
     /* general argument reduction needed */
 	else {
-	    n = __ieee754_rem_pio2f(x,y);
+	    n = __ieee754_rem_pio2f(x,&y);
 	    switch(n&3) {
-		case 0: return  __kernel_cosdf((double)y[0]+y[1]);
-		case 1: return  __kernel_sindf(-(double)y[0]-y[1]);
-		case 2: return -__kernel_cosdf((double)y[0]+y[1]);
+		case 0: return  __kernel_cosdf(y);
+		case 1: return  __kernel_sindf(-y);
+		case 2: return -__kernel_cosdf(y);
 		default:
-		        return  __kernel_sindf((double)y[0]+y[1]);
+		        return  __kernel_sindf(y);
 	    }
 	}
 }
diff --git a/libm/upstream-freebsd/lib/msun/src/s_cosl.c b/libm/upstream-freebsd/lib/msun/src/s_cosl.c
new file mode 100644
index 0000000..22e74cf
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_cosl.c
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2007 Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Limited testing on pseudorandom numbers drawn within [-2e8:4e8] shows
+ * an accuracy of <= 0.7412 ULP.
+ */
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "math.h"
+#include "math_private.h"
+#if LDBL_MANT_DIG == 64
+#include "../ld80/e_rem_pio2l.h"
+#elif LDBL_MANT_DIG == 113
+#include "../ld128/e_rem_pio2l.h"
+#else
+#error "Unsupported long double format"
+#endif
+
+long double
+cosl(long double x)
+{
+	union IEEEl2bits z;
+	int e0;
+	long double y[2];
+	long double hi, lo;
+
+	z.e = x;
+	z.bits.sign = 0;
+
+	/* If x = +-0 or x is a subnormal number, then cos(x) = 1 */
+	if (z.bits.exp == 0)
+		return (1.0);
+
+	/* If x = NaN or Inf, then cos(x) = NaN. */
+	if (z.bits.exp == 32767)
+		return ((x - x) / (x - x));
+
+	ENTERI();
+
+	/* Optimize the case where x is already within range. */
+	if (z.e < M_PI_4)
+		RETURNI(__kernel_cosl(z.e, 0));
+
+	e0 = __ieee754_rem_pio2l(x, y);
+	hi = y[0];
+	lo = y[1];
+
+	switch (e0 & 3) {
+	case 0:
+	    hi = __kernel_cosl(hi, lo);
+	    break;
+	case 1:
+	    hi = - __kernel_sinl(hi, lo, 1);
+	    break;
+	case 2:
+	    hi = - __kernel_cosl(hi, lo);
+	    break;
+	case 3:
+	    hi = __kernel_sinl(hi, lo, 1);
+	    break;
+	}
+	
+	RETURNI(hi);
+}
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_cproj.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_cproj.c
index 6a347c1..8e9404c 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cproj.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,23 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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 "math_private.h"
+
+double complex
+cproj(double complex z)
+{
+
+	if (!isinf(creal(z)) && !isinf(cimag(z)))
+		return (z);
+	else
+		return (cpack(INFINITY, copysign(0.0, cimag(z))));
 }
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+#if LDBL_MANT_DIG == 53
+__weak_reference(cproj, cprojl);
+#endif
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_cprojf.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_cprojf.c
index 6a347c1..68ea77b 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cprojf.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,19 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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 "math_private.h"
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+float complex
+cprojf(float complex z)
+{
+
+	if (!isinf(crealf(z)) && !isinf(cimagf(z)))
+		return (z);
+	else
+		return (cpackf(INFINITY, copysignf(0.0, cimagf(z))));
+}
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_cprojl.c
similarity index 77%
copy from libm/src/s_fdim.c
copy to libm/upstream-freebsd/lib/msun/src/s_cprojl.c
index 6a347c1..07385bc 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_cprojl.c
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,22 +25,19 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
+#include <complex.h>
 #include <math.h>
 
-#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 "math_private.h"
 
-DECL(double, fdim)
-DECL(float, fdimf)
-DECL(long double, fdiml)
+long double complex
+cprojl(long double complex z)
+{
+
+	if (!isinf(creall(z)) && !isinf(cimagl(z)))
+		return (z);
+	else
+		return (cpackl(INFINITY, copysignl(0.0, cimagl(z))));
+}
diff --git a/libm/src/s_creal.c b/libm/upstream-freebsd/lib/msun/src/s_creal.c
similarity index 94%
rename from libm/src/s_creal.c
rename to libm/upstream-freebsd/lib/msun/src/s_creal.c
index ad14cdf..3295ff2 100644
--- a/libm/src/s_creal.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_creal.c
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_creal.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
diff --git a/libm/src/s_crealf.c b/libm/upstream-freebsd/lib/msun/src/s_crealf.c
similarity index 94%
rename from libm/src/s_crealf.c
rename to libm/upstream-freebsd/lib/msun/src/s_crealf.c
index a5c1562..5819b86 100644
--- a/libm/src/s_crealf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_crealf.c
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_crealf.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
diff --git a/libm/src/s_creall.c b/libm/upstream-freebsd/lib/msun/src/s_creall.c
similarity index 94%
rename from libm/src/s_creall.c
rename to libm/upstream-freebsd/lib/msun/src/s_creall.c
index 1531d16..e4946f9 100644
--- a/libm/src/s_creall.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_creall.c
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_creall.c,v 1.1 2004/05/30 09:21:56 stefanf Exp $
+ * $FreeBSD$
  */
 
 #include <complex.h>
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinh.c b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
new file mode 100644
index 0000000..c192f30
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinh.c
@@ -0,0 +1,157 @@
+/*-
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic sine of a complex argument z = x + i y.
+ *
+ * sinh(z) = sinh(x+iy)
+ *         = sinh(x) cos(y) + i cosh(x) sin(y).
+ *
+ * Exceptional values are noted in the comments within the source code.
+ * These values and the return value were taken from n1124.pdf.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const double huge = 0x1p1023;
+
+double complex
+csinh(double complex z)
+{
+	double x, y, h;
+	int32_t hx, hy, ix, iy, lx, ly;
+
+	x = creal(z);
+	y = cimag(z);
+
+	EXTRACT_WORDS(hx, lx, x);
+	EXTRACT_WORDS(hy, ly, y);
+
+	ix = 0x7fffffff & hx;
+	iy = 0x7fffffff & hy;
+
+	/* Handle the nearly-non-exceptional cases where x and y are finite. */
+	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
+		if ((iy | ly) == 0)
+			return (cpack(sinh(x), y));
+		if (ix < 0x40360000)	/* small x: normal case */
+			return (cpack(sinh(x) * cos(y), cosh(x) * sin(y)));
+
+		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
+		if (ix < 0x40862e42) {
+			/* x < 710: exp(|x|) won't overflow */
+			h = exp(fabs(x)) * 0.5;
+			return (cpack(copysign(h, x) * cos(y), h * sin(y)));
+		} else if (ix < 0x4096bbaa) {
+			/* x < 1455: scale to avoid overflow */
+			z = __ldexp_cexp(cpack(fabs(x), y), -1);
+			return (cpack(creal(z) * copysign(1, x), cimag(z)));
+		} else {
+			/* x >= 1455: the result always overflows */
+			h = huge * x;
+			return (cpack(h * cos(y), h * h * sin(y)));
+		}
+	}
+
+	/*
+	 * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN.
+	 * The sign of 0 in the result is unspecified.  Choice = normally
+	 * the same as dNaN.  Raise the invalid floating-point exception.
+	 *
+	 * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN).
+	 * The sign of 0 in the result is unspecified.  Choice = normally
+	 * the same as d(NaN).
+	 */
+	if ((ix | lx) == 0 && iy >= 0x7ff00000)
+		return (cpack(copysign(0, x * (y - y)), y - y));
+
+	/*
+	 * sinh(+-Inf +- I 0) = +-Inf + I +-0.
+	 *
+	 * sinh(NaN +- I 0)   = d(NaN) + I +-0.
+	 */
+	if ((iy | ly) == 0 && ix >= 0x7ff00000) {
+		if (((hx & 0xfffff) | lx) == 0)
+			return (cpack(x, y));
+		return (cpack(x, copysign(0, y)));
+	}
+
+	/*
+	 * sinh(x +- I Inf) = dNaN + I dNaN.
+	 * Raise the invalid floating-point exception for finite nonzero x.
+	 *
+	 * sinh(x + I NaN) = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception for finite
+	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
+	 */
+	if (ix < 0x7ff00000 && iy >= 0x7ff00000)
+		return (cpack(y - y, x * (y - y)));
+
+	/*
+	 * sinh(+-Inf + I NaN)  = +-Inf + I d(NaN).
+	 * The sign of Inf in the result is unspecified.  Choice = normally
+	 * the same as d(NaN).
+	 *
+	 * sinh(+-Inf +- I Inf) = +Inf + I dNaN.
+	 * The sign of Inf in the result is unspecified.  Choice = always +.
+	 * Raise the invalid floating-point exception.
+	 *
+	 * sinh(+-Inf + I y)   = +-Inf cos(y) + I Inf sin(y)
+	 */
+	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
+		if (iy >= 0x7ff00000)
+			return (cpack(x * x, x * (y - y)));
+		return (cpack(x * cos(y), INFINITY * sin(y)));
+	}
+
+	/*
+	 * sinh(NaN + I NaN)  = d(NaN) + I d(NaN).
+	 *
+	 * sinh(NaN +- I Inf) = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception.
+	 * Choice = raise.
+	 *
+	 * sinh(NaN + I y)    = d(NaN) + I d(NaN).
+	 * Optionally raises the invalid floating-point exception for finite
+	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
+	 */
+	return (cpack((x * x) * (y - y), (x + x) * (y - y)));
+}
+
+double complex
+csin(double complex z)
+{
+
+	/* csin(z) = -I * csinh(I * z) */
+	z = csinh(cpack(-cimag(z), creal(z)));
+	return (cpack(cimag(z), -creal(z)));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csinhf.c b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
new file mode 100644
index 0000000..c523125
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_csinhf.c
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic sine of a complex argument z.  See s_csinh.c for details.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+static const float huge = 0x1p127;
+
+float complex
+csinhf(float complex z)
+{
+	float x, y, h;
+	int32_t hx, hy, ix, iy;
+
+	x = crealf(z);
+	y = cimagf(z);
+
+	GET_FLOAT_WORD(hx, x);
+	GET_FLOAT_WORD(hy, y);
+
+	ix = 0x7fffffff & hx;
+	iy = 0x7fffffff & hy;
+
+	if (ix < 0x7f800000 && iy < 0x7f800000) {
+		if (iy == 0)
+			return (cpackf(sinhf(x), y));
+		if (ix < 0x41100000)	/* small x: normal case */
+			return (cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
+
+		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
+		if (ix < 0x42b17218) {
+			/* x < 88.7: expf(|x|) won't overflow */
+			h = expf(fabsf(x)) * 0.5f;
+			return (cpackf(copysignf(h, x) * cosf(y), h * sinf(y)));
+		} else if (ix < 0x4340b1e7) {
+			/* x < 192.7: scale to avoid overflow */
+			z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
+			return (cpackf(crealf(z) * copysignf(1, x), cimagf(z)));
+		} else {
+			/* x >= 192.7: the result always overflows */
+			h = huge * x;
+			return (cpackf(h * cosf(y), h * h * sinf(y)));
+		}
+	}
+
+	if (ix == 0 && iy >= 0x7f800000)
+		return (cpackf(copysignf(0, x * (y - y)), y - y));
+
+	if (iy == 0 && ix >= 0x7f800000) {
+		if ((hx & 0x7fffff) == 0)
+			return (cpackf(x, y));
+		return (cpackf(x, copysignf(0, y)));
+	}
+
+	if (ix < 0x7f800000 && iy >= 0x7f800000)
+		return (cpackf(y - y, x * (y - y)));
+
+	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
+		if (iy >= 0x7f800000)
+			return (cpackf(x * x, x * (y - y)));
+		return (cpackf(x * cosf(y), INFINITY * sinf(y)));
+	}
+
+	return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
+}
+
+float complex
+csinf(float complex z)
+{
+
+	z = csinhf(cpackf(-cimagf(z), crealf(z)));
+	return (cpackf(cimagf(z), -crealf(z)));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrt.c b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c
new file mode 100644
index 0000000..18a7ae3
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrt.c
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <float.h>
+#include <math.h>
+
+#include "math_private.h"
+
+/*
+ * gcc doesn't implement complex multiplication or division correctly,
+ * so we need to handle infinities specially. We turn on this pragma to
+ * notify conforming c99 compilers that the fast-but-incorrect code that
+ * gcc generates is acceptable, since the special cases have already been
+ * handled.
+ */
+#pragma	STDC CX_LIMITED_RANGE	ON
+
+/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */
+#define	THRESH	0x1.a827999fcef32p+1022
+
+double complex
+csqrt(double complex z)
+{
+	double complex result;
+	double a, b;
+	double t;
+	int scale;
+
+	a = creal(z);
+	b = cimag(z);
+
+	/* Handle special cases. */
+	if (z == 0)
+		return (cpack(0, b));
+	if (isinf(b))
+		return (cpack(INFINITY, b));
+	if (isnan(a)) {
+		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
+		return (cpack(a, t));	/* return NaN + NaN i */
+	}
+	if (isinf(a)) {
+		/*
+		 * csqrt(inf + NaN i)  = inf +  NaN i
+		 * csqrt(inf + y i)    = inf +  0 i
+		 * csqrt(-inf + NaN i) = NaN +- inf i
+		 * csqrt(-inf + y i)   = 0   +  inf i
+		 */
+		if (signbit(a))
+			return (cpack(fabs(b - b), copysign(a, b)));
+		else
+			return (cpack(a, copysign(b - b, b)));
+	}
+	/*
+	 * The remaining special case (b is NaN) is handled just fine by
+	 * the normal code path below.
+	 */
+
+	/* Scale to avoid overflow. */
+	if (fabs(a) >= THRESH || fabs(b) >= THRESH) {
+		a *= 0.25;
+		b *= 0.25;
+		scale = 1;
+	} else {
+		scale = 0;
+	}
+
+	/* Algorithm 312, CACM vol 10, Oct 1967. */
+	if (a >= 0) {
+		t = sqrt((a + hypot(a, b)) * 0.5);
+		result = cpack(t, b / (2 * t));
+	} else {
+		t = sqrt((-a + hypot(a, b)) * 0.5);
+		result = cpack(fabs(b) / (2 * t), copysign(t, b));
+	}
+
+	/* Rescale. */
+	if (scale)
+		return (result * 2);
+	else
+		return (result);
+}
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(csqrt, csqrtl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
new file mode 100644
index 0000000..da7fe18
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtf.c
@@ -0,0 +1,88 @@
+/*-
+ * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+/*
+ * gcc doesn't implement complex multiplication or division correctly,
+ * so we need to handle infinities specially. We turn on this pragma to
+ * notify conforming c99 compilers that the fast-but-incorrect code that
+ * gcc generates is acceptable, since the special cases have already been
+ * handled.
+ */
+#pragma	STDC CX_LIMITED_RANGE	ON
+
+float complex
+csqrtf(float complex z)
+{
+	float a = crealf(z), b = cimagf(z);
+	double t;
+
+	/* Handle special cases. */
+	if (z == 0)
+		return (cpackf(0, b));
+	if (isinf(b))
+		return (cpackf(INFINITY, b));
+	if (isnan(a)) {
+		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
+		return (cpackf(a, t));	/* return NaN + NaN i */
+	}
+	if (isinf(a)) {
+		/*
+		 * csqrtf(inf + NaN i)  = inf +  NaN i
+		 * csqrtf(inf + y i)    = inf +  0 i
+		 * csqrtf(-inf + NaN i) = NaN +- inf i
+		 * csqrtf(-inf + y i)   = 0   +  inf i
+		 */
+		if (signbit(a))
+			return (cpackf(fabsf(b - b), copysignf(a, b)));
+		else
+			return (cpackf(a, copysignf(b - b, b)));
+	}
+	/*
+	 * The remaining special case (b is NaN) is handled just fine by
+	 * the normal code path below.
+	 */
+
+	/*
+	 * We compute t in double precision to avoid overflow and to
+	 * provide correct rounding in nearly all cases.
+	 * This is Algorithm 312, CACM vol 10, Oct 1967.
+	 */
+	if (a >= 0) {
+		t = sqrt((a + hypot(a, b)) * 0.5);
+		return (cpackf(t, b / (2.0 * t)));
+	} else {
+		t = sqrt((-a + hypot(a, b)) * 0.5);
+		return (cpackf(fabsf(b) / (2.0 * t), copysignf(t, b)));
+	}
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c
new file mode 100644
index 0000000..dd18e1e
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_csqrtl.c
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2007-2008 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <float.h>
+#include <math.h>
+
+#include "math_private.h"
+
+/*
+ * gcc doesn't implement complex multiplication or division correctly,
+ * so we need to handle infinities specially. We turn on this pragma to
+ * notify conforming c99 compilers that the fast-but-incorrect code that
+ * gcc generates is acceptable, since the special cases have already been
+ * handled.
+ */
+#pragma	STDC CX_LIMITED_RANGE	ON
+
+/* We risk spurious overflow for components >= LDBL_MAX / (1 + sqrt(2)). */
+#define	THRESH	(LDBL_MAX / 2.414213562373095048801688724209698L)
+
+long double complex
+csqrtl(long double complex z)
+{
+	long double complex result;
+	long double a, b;
+	long double t;
+	int scale;
+
+	a = creall(z);
+	b = cimagl(z);
+
+	/* Handle special cases. */
+	if (z == 0)
+		return (cpackl(0, b));
+	if (isinf(b))
+		return (cpackl(INFINITY, b));
+	if (isnan(a)) {
+		t = (b - b) / (b - b);	/* raise invalid if b is not a NaN */
+		return (cpackl(a, t));	/* return NaN + NaN i */
+	}
+	if (isinf(a)) {
+		/*
+		 * csqrt(inf + NaN i)  = inf +  NaN i
+		 * csqrt(inf + y i)    = inf +  0 i
+		 * csqrt(-inf + NaN i) = NaN +- inf i
+		 * csqrt(-inf + y i)   = 0   +  inf i
+		 */
+		if (signbit(a))
+			return (cpackl(fabsl(b - b), copysignl(a, b)));
+		else
+			return (cpackl(a, copysignl(b - b, b)));
+	}
+	/*
+	 * The remaining special case (b is NaN) is handled just fine by
+	 * the normal code path below.
+	 */
+
+	/* Scale to avoid overflow. */
+	if (fabsl(a) >= THRESH || fabsl(b) >= THRESH) {
+		a *= 0.25;
+		b *= 0.25;
+		scale = 1;
+	} else {
+		scale = 0;
+	}
+
+	/* Algorithm 312, CACM vol 10, Oct 1967. */
+	if (a >= 0) {
+		t = sqrtl((a + hypotl(a, b)) * 0.5);
+		result = cpackl(t, b / (2 * t));
+	} else {
+		t = sqrtl((-a + hypotl(a, b)) * 0.5);
+		result = cpackl(fabsl(b) / (2 * t), copysignl(t, b));
+	}
+
+	/* Rescale. */
+	if (scale)
+		return (result * 2);
+	else
+		return (result);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
new file mode 100644
index 0000000..d427e28
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 2011 David Schultz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic tangent of a complex argument z = x + i y.
+ *
+ * The algorithm is from:
+ *
+ *   W. Kahan.  Branch Cuts for Complex Elementary Functions or Much
+ *   Ado About Nothing's Sign Bit.  In The State of the Art in
+ *   Numerical Analysis, pp. 165 ff.  Iserles and Powell, eds., 1987.
+ *
+ * Method:
+ *
+ *   Let t    = tan(x)
+ *       beta = 1/cos^2(y)
+ *       s    = sinh(x)
+ *       rho  = cosh(x)
+ *
+ *   We have:
+ *
+ *   tanh(z) = sinh(z) / cosh(z)
+ *
+ *             sinh(x) cos(y) + i cosh(x) sin(y)
+ *           = ---------------------------------
+ *             cosh(x) cos(y) + i sinh(x) sin(y)
+ *
+ *             cosh(x) sinh(x) / cos^2(y) + i tan(y)
+ *           = -------------------------------------
+ *                    1 + sinh^2(x) / cos^2(y)
+ *
+ *             beta rho s + i t
+ *           = ----------------
+ *               1 + beta s^2
+ *
+ * Modifications:
+ *
+ *   I omitted the original algorithm's handling of overflow in tan(x) after
+ *   verifying with nearpi.c that this can't happen in IEEE single or double
+ *   precision.  I also handle large x differently.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+double complex
+ctanh(double complex z)
+{
+	double x, y;
+	double t, beta, s, rho, denom;
+	uint32_t hx, ix, lx;
+
+	x = creal(z);
+	y = cimag(z);
+
+	EXTRACT_WORDS(hx, lx, x);
+	ix = hx & 0x7fffffff;
+
+	/*
+	 * ctanh(NaN + i 0) = NaN + i 0
+	 *
+	 * ctanh(NaN + i y) = NaN + i NaN		for y != 0
+	 *
+	 * The imaginary part has the sign of x*sin(2*y), but there's no
+	 * special effort to get this right.
+	 *
+	 * ctanh(+-Inf +- i Inf) = +-1 +- 0
+	 *
+	 * ctanh(+-Inf + i y) = +-1 + 0 sin(2y)		for y finite
+	 *
+	 * The imaginary part of the sign is unspecified.  This special
+	 * case is only needed to avoid a spurious invalid exception when
+	 * y is infinite.
+	 */
+	if (ix >= 0x7ff00000) {
+		if ((ix & 0xfffff) | lx)	/* x is NaN */
+			return (cpack(x, (y == 0 ? y : x * y)));
+		SET_HIGH_WORD(x, hx - 0x40000000);	/* x = copysign(1, x) */
+		return (cpack(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
+	}
+
+	/*
+	 * ctanh(x + i NAN) = NaN + i NaN
+	 * ctanh(x +- i Inf) = NaN + i NaN
+	 */
+	if (!isfinite(y))
+		return (cpack(y - y, y - y));
+
+	/*
+	 * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
+	 * approximation sinh^2(huge) ~= exp(2*huge) / 4.
+	 * We use a modified formula to avoid spurious overflow.
+	 */
+	if (ix >= 0x40360000) {	/* x >= 22 */
+		double exp_mx = exp(-fabs(x));
+		return (cpack(copysign(1, x),
+		    4 * sin(y) * cos(y) * exp_mx * exp_mx));
+	}
+
+	/* Kahan's algorithm */
+	t = tan(y);
+	beta = 1.0 + t * t;	/* = 1 / cos^2(y) */
+	s = sinh(x);
+	rho = sqrt(1 + s * s);	/* = cosh(x) */
+	denom = 1 + beta * s * s;
+	return (cpack((beta * rho * s) / denom, t / denom));
+}
+
+double complex
+ctan(double complex z)
+{
+
+	/* ctan(z) = -I * ctanh(I * z) */
+	z = ctanh(cpack(-cimag(z), creal(z)));
+	return (cpack(cimag(z), -creal(z)));
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c b/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c
new file mode 100644
index 0000000..4be28d8
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_ctanhf.c
@@ -0,0 +1,84 @@
+/*-
+ * Copyright (c) 2011 David Schultz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Hyperbolic tangent of a complex argument z.  See s_ctanh.c for details.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+#include "math_private.h"
+
+float complex
+ctanhf(float complex z)
+{
+	float x, y;
+	float t, beta, s, rho, denom;
+	uint32_t hx, ix;
+
+	x = crealf(z);
+	y = cimagf(z);
+
+	GET_FLOAT_WORD(hx, x);
+	ix = hx & 0x7fffffff;
+
+	if (ix >= 0x7f800000) {
+		if (ix & 0x7fffff)
+			return (cpackf(x, (y == 0 ? y : x * y)));
+		SET_FLOAT_WORD(x, hx - 0x40000000);
+		return (cpackf(x,
+		    copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))));
+	}
+
+	if (!isfinite(y))
+		return (cpackf(y - y, y - y));
+
+	if (ix >= 0x41300000) {	/* x >= 11 */
+		float exp_mx = expf(-fabsf(x));
+		return (cpackf(copysignf(1, x),
+		    4 * sinf(y) * cosf(y) * exp_mx * exp_mx));
+	}
+
+	t = tanf(y);
+	beta = 1.0 + t * t;
+	s = sinhf(x);
+	rho = sqrtf(1 + s * s);
+	denom = 1 + beta * s * s;
+	return (cpackf((beta * rho * s) / denom, t / denom));
+}
+
+float complex
+ctanf(float complex z)
+{
+
+	z = ctanhf(cpackf(-cimagf(z), crealf(z)));
+	return (cpackf(cimagf(z), -crealf(z)));
+}
+
diff --git a/libm/src/s_erf.c b/libm/upstream-freebsd/lib/msun/src/s_erf.c
similarity index 98%
rename from libm/src/s_erf.c
rename to libm/upstream-freebsd/lib/msun/src/s_erf.c
index f33a2a5..0886e5e 100644
--- a/libm/src/s_erf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_erf.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_erf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* double erf(double x)
  * double erfc(double x)
diff --git a/libm/src/s_erff.c b/libm/upstream-freebsd/lib/msun/src/s_erff.c
similarity index 97%
rename from libm/src/s_erff.c
rename to libm/upstream-freebsd/lib/msun/src/s_erff.c
index 24e053c..a44e135 100644
--- a/libm/src/s_erff.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_erff.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_erff.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_exp2.c b/libm/upstream-freebsd/lib/msun/src/s_exp2.c
similarity index 95%
rename from libm/src/s_exp2.c
rename to libm/upstream-freebsd/lib/msun/src/s_exp2.c
index addef04..485b4e3 100644
--- a/libm/src/s_exp2.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_exp2.c
@@ -25,7 +25,9 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_exp2.c,v 1.1 2005/04/05 02:57:15 das Exp $"); */
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -35,7 +37,6 @@
 
 static const double
     huge     = 0x1p1000,
-    twom1000 = 0x1p-1000,
     redux    = 0x1.8p52 / TBLSIZE,
     P1	     = 0x1.62e42fefa39efp-1,
     P2	     = 0x1.ebfbdff82c575p-3,
@@ -43,6 +44,8 @@
     P4	     = 0x1.3b2ab88f70400p-7,
     P5	     = 0x1.5d88003875c74p-10;
 
+static volatile double twom1000 = 0x1p-1000;
+
 static const double tbl[TBLSIZE * 2] = {
 /*	exp2(z + eps)		eps	*/
 	0x1.6a09e667f3d5dp-1,	 0x1.9880p-44,
@@ -337,8 +340,8 @@
 double
 exp2(double x)
 {
-	double r, t, z;
-	uint32_t hx, hr, ix, lx, i0;
+	double r, t, twopk, twopkp1000, z;
+	uint32_t hx, ix, lx, i0;
 	int k;
 
 	/* Filter out exceptional cases. */
@@ -348,7 +351,7 @@
 		if(ix >= 0x7ff00000) {
 			GET_LOW_WORD(lx,x);
 			if(((ix & 0xfffff) | lx) != 0 || (hx & 0x80000000) == 0)
-				return (x); 	/* x is NaN or +Inf */
+				return (x + x);	/* x is NaN or +Inf */
 			else 
 				return (0.0);	/* x is -Inf */
 		}
@@ -361,7 +364,7 @@
 	}
 
 	/* Reduce x, computing z, i0, and k. */
-	t = x + redux;
+	STRICT_ASSIGN(double, t, x + redux);
 	GET_LOW_WORD(i0, t);
 	i0 += TBLSIZE / 2;
 	k = (i0 >> TBLBITS) << 20;
@@ -372,18 +375,22 @@
 	/* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */
 	t = tbl[i0];		/* exp2t[i0] */
 	z -= tbl[i0 + 1];	/* eps[i0]   */
+	if (k >= -1021 << 20)
+		INSERT_WORDS(twopk, 0x3ff00000 + k, 0);
+	else
+		INSERT_WORDS(twopkp1000, 0x3ff00000 + k + (1000 << 20), 0);
 	r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
 
 	/* Scale by 2**(k>>20). */
 	if(k >= -1021 << 20) {
-		if (k != 0) {
-			GET_HIGH_WORD(hr, r);
-			SET_HIGH_WORD(r, hr + k);
-		}
-		return (r);
+		if (k == 1024 << 20)
+			return (r * 2.0 * 0x1p1023);
+		return (r * twopk);
 	} else {
-		GET_HIGH_WORD(hr, r);
-		SET_HIGH_WORD(r, hr + (k + (1000 << 20)));
-		return (r * twom1000);
+		return (r * twopkp1000 * twom1000);
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(exp2, exp2l);
+#endif
diff --git a/libm/src/s_exp2f.c b/libm/upstream-freebsd/lib/msun/src/s_exp2f.c
similarity index 83%
rename from libm/src/s_exp2f.c
rename to libm/upstream-freebsd/lib/msun/src/s_exp2f.c
index 5e98e8a..0a97bf6 100644
--- a/libm/src/s_exp2f.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_exp2f.c
@@ -25,7 +25,9 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_exp2f.c,v 1.1 2005/04/05 02:57:15 das Exp $"); */
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -35,13 +37,14 @@
 
 static const float
     huge    = 0x1p100f,
-    twom100 = 0x1p-100f,
     redux   = 0x1.8p23f / TBLSIZE,
     P1	    = 0x1.62e430p-1f,
     P2	    = 0x1.ebfbe0p-3f,
     P3	    = 0x1.c6b348p-5f,
     P4	    = 0x1.3b2c9cp-7f;
 
+static volatile float twom100 = 0x1p-100f;
+
 static const double exp2ft[TBLSIZE] = {
 	0x1.6a09e667f3bcdp-1,
 	0x1.7a11473eb0187p-1,
@@ -79,7 +82,8 @@
  *
  *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a
  *   degree-4 minimax polynomial with maximum error under 1.4 * 2**-33.
- *   Using double precision in the final calculation avoids roundoff error.
+ *   Using double precision for everything except the reduction makes
+ *   roundoff error insignificant and simplifies the scaling step.
  *
  *   This method is due to Tang, but I do not use his suggested parameters:
  *
@@ -89,19 +93,18 @@
 float
 exp2f(float x)
 {
-	double tv;
-	float r, z;
-	volatile float t;	/* prevent gcc from using too much precision */
-	uint32_t hx, hr, ix, i0;
+	double tv, twopk, u, z;
+	float t;
+	uint32_t hx, ix, i0;
 	int32_t k;
 
 	/* Filter out exceptional cases. */
-	GET_FLOAT_WORD(hx,x);
+	GET_FLOAT_WORD(hx, x);
 	ix = hx & 0x7fffffff;		/* high word of |x| */
 	if(ix >= 0x43000000) {			/* |x| >= 128 */
 		if(ix >= 0x7f800000) {
 			if ((ix & 0x7fffff) != 0 || (hx & 0x80000000) == 0)
-				return (x); 	/* x is NaN or +Inf */
+				return (x + x);	/* x is NaN or +Inf */
 			else 
 				return (0.0);	/* x is -Inf */
 		}
@@ -114,28 +117,20 @@
 	}
 
 	/* Reduce x, computing z, i0, and k. */
-	t = x + redux;
+	STRICT_ASSIGN(float, t, x + redux);
 	GET_FLOAT_WORD(i0, t);
 	i0 += TBLSIZE / 2;
-	k = (i0 >> TBLBITS) << 23;
+	k = (i0 >> TBLBITS) << 20;
 	i0 &= TBLSIZE - 1;
 	t -= redux;
 	z = x - t;
+	INSERT_WORDS(twopk, 0x3ff00000 + k, 0);
 
 	/* Compute r = exp2(y) = exp2ft[i0] * p(z). */
 	tv = exp2ft[i0];
-	r = tv + tv * (z * (P1 + z * (P2 + z * (P3 + z * P4))));
+	u = tv * z;
+	tv = tv + u * (P1 + z * P2) + u * (z * z) * (P3 + z * P4);
 
-	/* Scale by 2**(k>>23). */
-	if(k >= -125 << 23) {
-		if (k != 0) {
-			GET_FLOAT_WORD(hr, r);
-			SET_FLOAT_WORD(r, hr + k);
-		}
-		return (r);
-	} else {
-		GET_FLOAT_WORD(hr, r);
-		SET_FLOAT_WORD(r, hr + (k + (100 << 23)));
-		return (r * twom100);
-	}
+	/* Scale by 2**(k>>20). */
+	return (tv * twopk);
 }
diff --git a/libm/src/s_expm1.c b/libm/upstream-freebsd/lib/msun/src/s_expm1.c
similarity index 90%
rename from libm/src/s_expm1.c
rename to libm/upstream-freebsd/lib/msun/src/s_expm1.c
index 57aa3f2..5aa1917 100644
--- a/libm/src/s_expm1.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_expm1.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* expm1(x)
  * Returns exp(x)-1, the exponential of x minus 1.
@@ -46,7 +45,7 @@
  * 		Q3  =  -9.9206344733435987357E-6,
  * 		Q4  =   2.5051361420808517002E-7,
  * 		Q5  =  -6.2843505682382617102E-9;
- *  	(where z=r*r, and the values of Q1 to Q5 are listed below)
+ *		z   =  r*r,
  *	with error bounded by
  *	    |                  5           |     -61
  *	    | 1.0+Q1*z+...+Q5*z   -  R1(z) | <= 2
@@ -109,6 +108,8 @@
  * to produce the hexadecimal values shown.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -120,7 +121,7 @@
 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 */
@@ -130,13 +131,12 @@
 double
 expm1(double x)
 {
-	double y,hi,lo,c,t,e,hxs,hfx,r1;
+	double y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
 	int32_t k,xsb;
 	u_int32_t hx;
 
 	GET_HIGH_WORD(hx,x);
 	xsb = hx&0x80000000;		/* sign bit of x */
-	if(xsb==0) y=x; else y= -x;	/* y = |x| */
 	hx &= 0x7fffffff;		/* high word of |x| */
 
     /* filter out huge and non-finite argument */
@@ -170,7 +170,7 @@
 		hi = x - t*ln2_hi;	/* t*ln2_hi is exact here */
 		lo = t*ln2_lo;
 	    }
-	    x  = hi - lo;
+	    STRICT_ASSIGN(double, x, hi - lo);
 	    c  = (hi-x)-lo;
 	}
 	else if(hx < 0x3c900000) {  	/* when |x|<2**-54, return x */
@@ -187,33 +187,30 @@
 	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/libm/src/s_expm1f.c b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c
similarity index 76%
rename from libm/src/s_expm1f.c
rename to libm/upstream-freebsd/lib/msun/src/s_expm1f.c
index a670a72..fb37494 100644
--- a/libm/src/s_expm1f.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_expm1f.c
@@ -13,9 +13,10 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_expm1f.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -28,23 +29,23 @@
 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 */
 
 float
 expm1f(float x)
 {
-	float y,hi,lo,c,t,e,hxs,hfx,r1;
+	float y,hi,lo,c,t,e,hxs,hfx,r1,twopk;
 	int32_t k,xsb;
 	u_int32_t hx;
 
 	GET_FLOAT_WORD(hx,x);
 	xsb = hx&0x80000000;		/* sign bit of x */
-	if(xsb==0) y=x; else y= -x;	/* y = |x| */
 	hx &= 0x7fffffff;		/* high word of |x| */
 
     /* filter out huge and non-finite argument */
@@ -75,7 +76,7 @@
 		hi = x - t*ln2_hi;	/* t*ln2_hi is exact here */
 		lo = t*ln2_lo;
 	    }
-	    x  = hi - lo;
+	    STRICT_ASSIGN(float, x, hi - lo);
 	    c  = (hi-x)-lo;
 	}
 	else if(hx < 0x33000000) {  	/* when |x|<2**-25, return x */
@@ -87,38 +88,35 @@
     /* x is now in primary range */
 	hfx = (float)0.5*x;
 	hxs = x*hfx;
-	r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
+	r1 = one+hxs*(Q1+hxs*Q2);
 	t  = (float)3.0-r1*hfx;
 	e  = hxs*((r1-t)/((float)6.0 - x*t));
 	if(k==0) return x - (x*e-hxs);		/* c is 0 */
 	else {
+	    SET_FLOAT_WORD(twopk,0x3f800000+(k<<23));	/* 2^k */
 	    e  = (x*(e-c)-c);
 	    e -= hxs;
 	    if(k== -1) return (float)0.5*(x-e)-(float)0.5;
-	    if(k==1)
+	    if(k==1) {
 	       	if(x < (float)-0.25) return -(float)2.0*(e-(x+(float)0.5));
 	       	else 	      return  one+(float)2.0*(x-e);
+	    }
 	    if (k <= -2 || k>56) {   /* suffice to return exp(x)-1 */
-	        int32_t i;
 	        y = one-(e-x);
-		GET_FLOAT_WORD(i,y);
-		SET_FLOAT_WORD(y,i+(k<<23));	/* add k to y's exponent */
+		if (k == 128) y = y*2.0F*0x1p127F;
+		else y = y*twopk;
 	        return y-one;
 	    }
 	    t = one;
 	    if(k<23) {
-	        int32_t i;
 	        SET_FLOAT_WORD(t,0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */
 	       	y = t-(e-x);
-		GET_FLOAT_WORD(i,y);
-		SET_FLOAT_WORD(y,i+(k<<23));	/* add k to y's exponent */
+		y = y*twopk;
 	   } else {
-	        int32_t i;
 		SET_FLOAT_WORD(t,((0x7f-k)<<23));	/* 2^-k */
 	       	y = x-(e+t);
 	       	y += one;
-		GET_FLOAT_WORD(i,y);
-		SET_FLOAT_WORD(y,i+(k<<23));	/* add k to y's exponent */
+		y = y*twopk;
 	    }
 	}
 	return y;
diff --git a/libm/src/s_fabs.c b/libm/upstream-freebsd/lib/msun/src/s_fabs.c
similarity index 86%
rename from libm/src/s_fabs.c
rename to libm/upstream-freebsd/lib/msun/src/s_fabs.c
index 0dfa940..15529e5 100644
--- a/libm/src/s_fabs.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fabs.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_fabs.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 /*
diff --git a/libm/src/s_fabsf.c b/libm/upstream-freebsd/lib/msun/src/s_fabsf.c
similarity index 85%
rename from libm/src/s_fabsf.c
rename to libm/upstream-freebsd/lib/msun/src/s_fabsf.c
index 2200705..e9383d0 100644
--- a/libm/src/s_fabsf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fabsf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_fabsf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * fabsf(x) returns the absolute value of x.
diff --git a/libm/src/s_fabsl.c b/libm/upstream-freebsd/lib/msun/src/s_fabsl.c
similarity index 100%
rename from libm/src/s_fabsl.c
rename to libm/upstream-freebsd/lib/msun/src/s_fabsl.c
diff --git a/libm/src/s_fdim.c b/libm/upstream-freebsd/lib/msun/src/s_fdim.c
similarity index 94%
rename from libm/src/s_fdim.c
rename to libm/upstream-freebsd/lib/msun/src/s_fdim.c
index 6a347c1..2f347fd 100644
--- a/libm/src/s_fdim.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fdim.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_finite.c b/libm/upstream-freebsd/lib/msun/src/s_finite.c
similarity index 84%
rename from libm/src/s_finite.c
rename to libm/upstream-freebsd/lib/msun/src/s_finite.c
index 704d1d8..4c51352 100644
--- a/libm/src/s_finite.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_finite.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_finite.c,v 1.8 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * finite(x) returns 1 is x is finite, else 0;
diff --git a/libm/src/s_finitef.c b/libm/upstream-freebsd/lib/msun/src/s_finitef.c
similarity index 85%
rename from libm/src/s_finitef.c
rename to libm/upstream-freebsd/lib/msun/src/s_finitef.c
index b430639..c62239e 100644
--- a/libm/src/s_finitef.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_finitef.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_finitef.c,v 1.6 2002/05/28 17:51:46 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * finitef(x) returns 1 is x is finite, else 0;
diff --git a/libm/src/s_floor.c b/libm/upstream-freebsd/lib/msun/src/s_floor.c
similarity index 92%
rename from libm/src/s_floor.c
rename to libm/upstream-freebsd/lib/msun/src/s_floor.c
index acc3214..65f696a 100644
--- a/libm/src/s_floor.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_floor.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floor.c,v 1.9 2003/07/23 04:53:46 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * floor(x)
@@ -23,6 +22,8 @@
  *	Inexact flag raised if x not equal to floor(x).
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -71,3 +72,7 @@
 	INSERT_WORDS(x,i0,i1);
 	return x;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(floor, floorl);
+#endif
diff --git a/libm/src/s_floorf.c b/libm/upstream-freebsd/lib/msun/src/s_floorf.c
similarity index 91%
rename from libm/src/s_floorf.c
rename to libm/upstream-freebsd/lib/msun/src/s_floorf.c
index 70a71f3..6b510de 100644
--- a/libm/src/s_floorf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_floorf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floorf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * floorf(x)
diff --git a/libm/src/s_floorl.c b/libm/upstream-freebsd/lib/msun/src/s_floorl.c
similarity index 94%
rename from libm/src/s_floorl.c
rename to libm/upstream-freebsd/lib/msun/src/s_floorl.c
index 2ef0acc..6cec3e7 100644
--- a/libm/src/s_floorl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_floorl.c
@@ -11,9 +11,8 @@
  * From: @(#)s_floor.c 5.1 93/09/24
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_floorl.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * floorl(x)
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fma.c b/libm/upstream-freebsd/lib/msun/src/s_fma.c
new file mode 100644
index 0000000..dfbd13c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_fma.c
@@ -0,0 +1,284 @@
+/*-
+ * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+
+#include "math_private.h"
+
+/*
+ * A struct dd represents a floating-point number with twice the precision
+ * of a double.  We maintain the invariant that "hi" stores the 53 high-order
+ * bits of the result.
+ */
+struct dd {
+	double hi;
+	double lo;
+};
+
+/*
+ * Compute a+b exactly, returning the exact result in a struct dd.  We assume
+ * that both a and b are finite, but make no assumptions about their relative
+ * magnitudes.
+ */
+static inline struct dd
+dd_add(double a, double b)
+{
+	struct dd ret;
+	double s;
+
+	ret.hi = a + b;
+	s = ret.hi - a;
+	ret.lo = (a - (ret.hi - s)) + (b - s);
+	return (ret);
+}
+
+/*
+ * Compute a+b, with a small tweak:  The least significant bit of the
+ * result is adjusted into a sticky bit summarizing all the bits that
+ * were lost to rounding.  This adjustment negates the effects of double
+ * rounding when the result is added to another number with a higher
+ * exponent.  For an explanation of round and sticky bits, see any reference
+ * on FPU design, e.g.,
+ *
+ *     J. Coonen.  An Implementation Guide to a Proposed Standard for
+ *     Floating-Point Arithmetic.  Computer, vol. 13, no. 1, Jan 1980.
+ */
+static inline double
+add_adjusted(double a, double b)
+{
+	struct dd sum;
+	uint64_t hibits, lobits;
+
+	sum = dd_add(a, b);
+	if (sum.lo != 0) {
+		EXTRACT_WORD64(hibits, sum.hi);
+		if ((hibits & 1) == 0) {
+			/* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
+			EXTRACT_WORD64(lobits, sum.lo);
+			hibits += 1 - ((hibits ^ lobits) >> 62);
+			INSERT_WORD64(sum.hi, hibits);
+		}
+	}
+	return (sum.hi);
+}
+
+/*
+ * Compute ldexp(a+b, scale) with a single rounding error. It is assumed
+ * that the result will be subnormal, and care is taken to ensure that
+ * double rounding does not occur.
+ */
+static inline double
+add_and_denormalize(double a, double b, int scale)
+{
+	struct dd sum;
+	uint64_t hibits, lobits;
+	int bits_lost;
+
+	sum = dd_add(a, b);
+
+	/*
+	 * If we are losing at least two bits of accuracy to denormalization,
+	 * then the first lost bit becomes a round bit, and we adjust the
+	 * lowest bit of sum.hi to make it a sticky bit summarizing all the
+	 * bits in sum.lo. With the sticky bit adjusted, the hardware will
+	 * break any ties in the correct direction.
+	 *
+	 * If we are losing only one bit to denormalization, however, we must
+	 * break the ties manually.
+	 */
+	if (sum.lo != 0) {
+		EXTRACT_WORD64(hibits, sum.hi);
+		bits_lost = -((int)(hibits >> 52) & 0x7ff) - scale + 1;
+		if (bits_lost != 1 ^ (int)(hibits & 1)) {
+			/* hibits += (int)copysign(1.0, sum.hi * sum.lo) */
+			EXTRACT_WORD64(lobits, sum.lo);
+			hibits += 1 - (((hibits ^ lobits) >> 62) & 2);
+			INSERT_WORD64(sum.hi, hibits);
+		}
+	}
+	return (ldexp(sum.hi, scale));
+}
+
+/*
+ * Compute a*b exactly, returning the exact result in a struct dd.  We assume
+ * that both a and b are normalized, so no underflow or overflow will occur.
+ * The current rounding mode must be round-to-nearest.
+ */
+static inline struct dd
+dd_mul(double a, double b)
+{
+	static const double split = 0x1p27 + 1.0;
+	struct dd ret;
+	double ha, hb, la, lb, p, q;
+
+	p = a * split;
+	ha = a - p;
+	ha += p;
+	la = a - ha;
+
+	p = b * split;
+	hb = b - p;
+	hb += p;
+	lb = b - hb;
+
+	p = ha * hb;
+	q = ha * lb + la * hb;
+
+	ret.hi = p + q;
+	ret.lo = p - ret.hi + q + la * lb;
+	return (ret);
+}
+
+/*
+ * Fused multiply-add: Compute x * y + z with a single rounding error.
+ *
+ * We use scaling to avoid overflow/underflow, along with the
+ * canonical precision-doubling technique adapted from:
+ *
+ *	Dekker, T.  A Floating-Point Technique for Extending the
+ *	Available Precision.  Numer. Math. 18, 224-242 (1971).
+ *
+ * This algorithm is sensitive to the rounding precision.  FPUs such
+ * as the i387 must be set in double-precision mode if variables are
+ * to be stored in FP registers in order to avoid incorrect results.
+ * This is the default on FreeBSD, but not on many other systems.
+ *
+ * Hardware instructions should be used on architectures that support it,
+ * since this implementation will likely be several times slower.
+ */
+double
+fma(double x, double y, double z)
+{
+	double xs, ys, zs, adj;
+	struct dd xy, r;
+	int oround;
+	int ex, ey, ez;
+	int spread;
+
+	/*
+	 * Handle special cases. The order of operations and the particular
+	 * return values here are crucial in handling special cases involving
+	 * infinities, NaNs, overflows, and signed zeroes correctly.
+	 */
+	if (x == 0.0 || y == 0.0)
+		return (x * y + z);
+	if (z == 0.0)
+		return (x * y);
+	if (!isfinite(x) || !isfinite(y))
+		return (x * y + z);
+	if (!isfinite(z))
+		return (z);
+
+	xs = frexp(x, &ex);
+	ys = frexp(y, &ey);
+	zs = frexp(z, &ez);
+	oround = fegetround();
+	spread = ex + ey - ez;
+
+	/*
+	 * If x * y and z are many orders of magnitude apart, the scaling
+	 * will overflow, so we handle these cases specially.  Rounding
+	 * modes other than FE_TONEAREST are painful.
+	 */
+	if (spread < -DBL_MANT_DIG) {
+		feraiseexcept(FE_INEXACT);
+		if (!isnormal(z))
+			feraiseexcept(FE_UNDERFLOW);
+		switch (oround) {
+		case FE_TONEAREST:
+			return (z);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (z);
+			else
+				return (nextafter(z, 0));
+		case FE_DOWNWARD:
+			if (x > 0.0 ^ y < 0.0)
+				return (z);
+			else
+				return (nextafter(z, -INFINITY));
+		default:	/* FE_UPWARD */
+			if (x > 0.0 ^ y < 0.0)
+				return (nextafter(z, INFINITY));
+			else
+				return (z);
+		}
+	}
+	if (spread <= DBL_MANT_DIG * 2)
+		zs = ldexp(zs, -spread);
+	else
+		zs = copysign(DBL_MIN, zs);
+
+	fesetround(FE_TONEAREST);
+
+	/*
+	 * Basic approach for round-to-nearest:
+	 *
+	 *     (xy.hi, xy.lo) = x * y		(exact)
+	 *     (r.hi, r.lo)   = xy.hi + z	(exact)
+	 *     adj = xy.lo + r.lo		(inexact; low bit is sticky)
+	 *     result = r.hi + adj		(correctly rounded)
+	 */
+	xy = dd_mul(xs, ys);
+	r = dd_add(xy.hi, zs);
+
+	spread = ex + ey;
+
+	if (r.hi == 0.0) {
+		/*
+		 * When the addends cancel to 0, ensure that the result has
+		 * the correct sign.
+		 */
+		fesetround(oround);
+		volatile double vzs = zs; /* XXX gcc CSE bug workaround */
+		return (xy.hi + vzs + ldexp(xy.lo, spread));
+	}
+
+	if (oround != FE_TONEAREST) {
+		/*
+		 * There is no need to worry about double rounding in directed
+		 * rounding modes.
+		 */
+		fesetround(oround);
+		adj = r.lo + xy.lo;
+		return (ldexp(r.hi + adj, spread));
+	}
+
+	adj = add_adjusted(r.lo, xy.lo);
+	if (spread + ilogb(r.hi) > -1023)
+		return (ldexp(r.hi + adj, spread));
+	else
+		return (add_and_denormalize(r.hi, adj, spread));
+}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(fma, fmal);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fmaf.c b/libm/upstream-freebsd/lib/msun/src/s_fmaf.c
new file mode 100644
index 0000000..3695823
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmaf.c
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fenv.h>
+
+#include "math.h"
+#include "math_private.h"
+
+/*
+ * Fused multiply-add: Compute x * y + z with a single rounding error.
+ *
+ * A double has more than twice as much precision than a float, so
+ * direct double-precision arithmetic suffices, except where double
+ * rounding occurs.
+ */
+float
+fmaf(float x, float y, float z)
+{
+	double xy, result;
+	uint32_t hr, lr;
+
+	xy = (double)x * y;
+	result = xy + z;
+	EXTRACT_WORDS(hr, lr, result);
+	/* Common case: The double precision result is fine. */
+	if ((lr & 0x1fffffff) != 0x10000000 ||	/* not a halfway case */
+	    (hr & 0x7ff00000) == 0x7ff00000 ||	/* NaN */
+	    result - xy == z ||			/* exact */
+	    fegetround() != FE_TONEAREST)	/* not round-to-nearest */
+		return (result);
+
+	/*
+	 * If result is inexact, and exactly halfway between two float values,
+	 * we need to adjust the low-order bit in the direction of the error.
+	 */
+	fesetround(FE_TOWARDZERO);
+	volatile double vxy = xy;  /* XXX work around gcc CSE bug */
+	double adjusted_result = vxy + z;
+	fesetround(FE_TONEAREST);
+	if (result == adjusted_result)
+		SET_LOW_WORD(adjusted_result, lr + 1);
+	return (adjusted_result);
+}
diff --git a/libm/upstream-freebsd/lib/msun/src/s_fmal.c b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
new file mode 100644
index 0000000..c2a6913
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmal.c
@@ -0,0 +1,268 @@
+/*-
+ * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+/*
+ * A struct dd represents a floating-point number with twice the precision
+ * of a long double.  We maintain the invariant that "hi" stores the high-order
+ * bits of the result.
+ */
+struct dd {
+	long double hi;
+	long double lo;
+};
+
+/*
+ * Compute a+b exactly, returning the exact result in a struct dd.  We assume
+ * that both a and b are finite, but make no assumptions about their relative
+ * magnitudes.
+ */
+static inline struct dd
+dd_add(long double a, long double b)
+{
+	struct dd ret;
+	long double s;
+
+	ret.hi = a + b;
+	s = ret.hi - a;
+	ret.lo = (a - (ret.hi - s)) + (b - s);
+	return (ret);
+}
+
+/*
+ * Compute a+b, with a small tweak:  The least significant bit of the
+ * result is adjusted into a sticky bit summarizing all the bits that
+ * were lost to rounding.  This adjustment negates the effects of double
+ * rounding when the result is added to another number with a higher
+ * exponent.  For an explanation of round and sticky bits, see any reference
+ * on FPU design, e.g.,
+ *
+ *     J. Coonen.  An Implementation Guide to a Proposed Standard for
+ *     Floating-Point Arithmetic.  Computer, vol. 13, no. 1, Jan 1980.
+ */
+static inline long double
+add_adjusted(long double a, long double b)
+{
+	struct dd sum;
+	union IEEEl2bits u;
+
+	sum = dd_add(a, b);
+	if (sum.lo != 0) {
+		u.e = sum.hi;
+		if ((u.bits.manl & 1) == 0)
+			sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
+	}
+	return (sum.hi);
+}
+
+/*
+ * Compute ldexp(a+b, scale) with a single rounding error. It is assumed
+ * that the result will be subnormal, and care is taken to ensure that
+ * double rounding does not occur.
+ */
+static inline long double
+add_and_denormalize(long double a, long double b, int scale)
+{
+	struct dd sum;
+	int bits_lost;
+	union IEEEl2bits u;
+
+	sum = dd_add(a, b);
+
+	/*
+	 * If we are losing at least two bits of accuracy to denormalization,
+	 * then the first lost bit becomes a round bit, and we adjust the
+	 * lowest bit of sum.hi to make it a sticky bit summarizing all the
+	 * bits in sum.lo. With the sticky bit adjusted, the hardware will
+	 * break any ties in the correct direction.
+	 *
+	 * If we are losing only one bit to denormalization, however, we must
+	 * break the ties manually.
+	 */
+	if (sum.lo != 0) {
+		u.e = sum.hi;
+		bits_lost = -u.bits.exp - scale + 1;
+		if (bits_lost != 1 ^ (int)(u.bits.manl & 1))
+			sum.hi = nextafterl(sum.hi, INFINITY * sum.lo);
+	}
+	return (ldexp(sum.hi, scale));
+}
+
+/*
+ * Compute a*b exactly, returning the exact result in a struct dd.  We assume
+ * that both a and b are normalized, so no underflow or overflow will occur.
+ * The current rounding mode must be round-to-nearest.
+ */
+static inline struct dd
+dd_mul(long double a, long double b)
+{
+#if LDBL_MANT_DIG == 64
+	static const long double split = 0x1p32L + 1.0;
+#elif LDBL_MANT_DIG == 113
+	static const long double split = 0x1p57L + 1.0;
+#endif
+	struct dd ret;
+	long double ha, hb, la, lb, p, q;
+
+	p = a * split;
+	ha = a - p;
+	ha += p;
+	la = a - ha;
+
+	p = b * split;
+	hb = b - p;
+	hb += p;
+	lb = b - hb;
+
+	p = ha * hb;
+	q = ha * lb + la * hb;
+
+	ret.hi = p + q;
+	ret.lo = p - ret.hi + q + la * lb;
+	return (ret);
+}
+
+/*
+ * Fused multiply-add: Compute x * y + z with a single rounding error.
+ *
+ * We use scaling to avoid overflow/underflow, along with the
+ * canonical precision-doubling technique adapted from:
+ *
+ *	Dekker, T.  A Floating-Point Technique for Extending the
+ *	Available Precision.  Numer. Math. 18, 224-242 (1971).
+ */
+long double
+fmal(long double x, long double y, long double z)
+{
+	long double xs, ys, zs, adj;
+	struct dd xy, r;
+	int oround;
+	int ex, ey, ez;
+	int spread;
+
+	/*
+	 * Handle special cases. The order of operations and the particular
+	 * return values here are crucial in handling special cases involving
+	 * infinities, NaNs, overflows, and signed zeroes correctly.
+	 */
+	if (x == 0.0 || y == 0.0)
+		return (x * y + z);
+	if (z == 0.0)
+		return (x * y);
+	if (!isfinite(x) || !isfinite(y))
+		return (x * y + z);
+	if (!isfinite(z))
+		return (z);
+
+	xs = frexpl(x, &ex);
+	ys = frexpl(y, &ey);
+	zs = frexpl(z, &ez);
+	oround = fegetround();
+	spread = ex + ey - ez;
+
+	/*
+	 * If x * y and z are many orders of magnitude apart, the scaling
+	 * will overflow, so we handle these cases specially.  Rounding
+	 * modes other than FE_TONEAREST are painful.
+	 */
+	if (spread < -LDBL_MANT_DIG) {
+		feraiseexcept(FE_INEXACT);
+		if (!isnormal(z))
+			feraiseexcept(FE_UNDERFLOW);
+		switch (oround) {
+		case FE_TONEAREST:
+			return (z);
+		case FE_TOWARDZERO:
+			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
+				return (z);
+			else
+				return (nextafterl(z, 0));
+		case FE_DOWNWARD:
+			if (x > 0.0 ^ y < 0.0)
+				return (z);
+			else
+				return (nextafterl(z, -INFINITY));
+		default:	/* FE_UPWARD */
+			if (x > 0.0 ^ y < 0.0)
+				return (nextafterl(z, INFINITY));
+			else
+				return (z);
+		}
+	}
+	if (spread <= LDBL_MANT_DIG * 2)
+		zs = ldexpl(zs, -spread);
+	else
+		zs = copysignl(LDBL_MIN, zs);
+
+	fesetround(FE_TONEAREST);
+
+	/*
+	 * Basic approach for round-to-nearest:
+	 *
+	 *     (xy.hi, xy.lo) = x * y		(exact)
+	 *     (r.hi, r.lo)   = xy.hi + z	(exact)
+	 *     adj = xy.lo + r.lo		(inexact; low bit is sticky)
+	 *     result = r.hi + adj		(correctly rounded)
+	 */
+	xy = dd_mul(xs, ys);
+	r = dd_add(xy.hi, zs);
+
+	spread = ex + ey;
+
+	if (r.hi == 0.0) {
+		/*
+		 * When the addends cancel to 0, ensure that the result has
+		 * the correct sign.
+		 */
+		fesetround(oround);
+		volatile long double vzs = zs; /* XXX gcc CSE bug workaround */
+		return (xy.hi + vzs + ldexpl(xy.lo, spread));
+	}
+
+	if (oround != FE_TONEAREST) {
+		/*
+		 * There is no need to worry about double rounding in directed
+		 * rounding modes.
+		 */
+		fesetround(oround);
+		adj = r.lo + xy.lo;
+		return (ldexpl(r.hi + adj, spread));
+	}
+
+	adj = add_adjusted(r.lo, xy.lo);
+	if (spread + ilogbl(r.hi) > -16383)
+		return (ldexpl(r.hi + adj, spread));
+	else
+		return (add_and_denormalize(r.hi, adj, spread));
+}
diff --git a/libm/src/s_fmax.c b/libm/upstream-freebsd/lib/msun/src/s_fmax.c
similarity index 95%
rename from libm/src/s_fmax.c
rename to libm/upstream-freebsd/lib/msun/src/s_fmax.c
index 3345f67..b51b865 100644
--- a/libm/src/s_fmax.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmax.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmax.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_fmaxf.c b/libm/upstream-freebsd/lib/msun/src/s_fmaxf.c
similarity index 94%
rename from libm/src/s_fmaxf.c
rename to libm/upstream-freebsd/lib/msun/src/s_fmaxf.c
index b67f654..423da54 100644
--- a/libm/src/s_fmaxf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmaxf.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_fmaxl.c b/libm/upstream-freebsd/lib/msun/src/s_fmaxl.c
similarity index 95%
rename from libm/src/s_fmaxl.c
rename to libm/upstream-freebsd/lib/msun/src/s_fmaxl.c
index c1a9dbe..0ac48a9 100644
--- a/libm/src/s_fmaxl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmaxl.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_fmin.c b/libm/upstream-freebsd/lib/msun/src/s_fmin.c
similarity index 95%
rename from libm/src/s_fmin.c
rename to libm/upstream-freebsd/lib/msun/src/s_fmin.c
index 49b9cc4..3500c84 100644
--- a/libm/src/s_fmin.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fmin.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fmin.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_fminf.c b/libm/upstream-freebsd/lib/msun/src/s_fminf.c
similarity index 94%
rename from libm/src/s_fminf.c
rename to libm/upstream-freebsd/lib/msun/src/s_fminf.c
index a6fb575..76a5c76 100644
--- a/libm/src/s_fminf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fminf.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fminf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_fminl.c b/libm/upstream-freebsd/lib/msun/src/s_fminl.c
similarity index 95%
rename from libm/src/s_fminl.c
rename to libm/upstream-freebsd/lib/msun/src/s_fminl.c
index 5f8c50e..f9d3ebb 100644
--- a/libm/src/s_fminl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_fminl.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_fminl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_frexp.c b/libm/upstream-freebsd/lib/msun/src/s_frexp.c
similarity index 91%
rename from libm/src/s_frexp.c
rename to libm/upstream-freebsd/lib/msun/src/s_frexp.c
index d89e135..318a991 100644
--- a/libm/src/s_frexp.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_frexp.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexp.c,v 1.10 2005/03/07 21:27:37 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * for non-zero x
@@ -24,7 +23,6 @@
  * with *exp=0.
  */
 
-#include <sys/cdefs.h>
 #include <float.h>
 
 #include "math.h"
diff --git a/libm/src/s_frexpf.c b/libm/upstream-freebsd/lib/msun/src/s_frexpf.c
similarity index 88%
rename from libm/src/s_frexpf.c
rename to libm/upstream-freebsd/lib/msun/src/s_frexpf.c
index c18cd54..5a7c486 100644
--- a/libm/src/s_frexpf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_frexpf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_frexpf.c,v 1.8 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_frexpl.c b/libm/upstream-freebsd/lib/msun/src/s_frexpl.c
similarity index 95%
rename from libm/src/s_frexpl.c
rename to libm/upstream-freebsd/lib/msun/src/s_frexpl.c
index 20b3167..d34f55d 100644
--- a/libm/src/s_frexpl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_frexpl.c
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_frexpl.c,v 1.1 2005/03/07 04:54:51 das Exp $
+ * $FreeBSD$
  */
 
 #include <float.h>
diff --git a/libm/src/s_ilogb.c b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c
similarity index 89%
rename from libm/src/s_ilogb.c
rename to libm/upstream-freebsd/lib/msun/src/s_ilogb.c
index bd4a44b..a930bc9 100644
--- a/libm/src/s_ilogb.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ilogb.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogb.c,v 1.9 2004/10/09 17:14:28 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* ilogb(double x)
  * return the binary exponent of non-zero x
diff --git a/libm/src/s_ilogbf.c b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
similarity index 87%
rename from libm/src/s_ilogbf.c
rename to libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
index 3c9c4de..93fe295 100644
--- a/libm/src/s_ilogbf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ilogbf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogbf.c,v 1.7 2004/10/09 17:14:28 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include <limits.h>
 
diff --git a/libm/src/s_ilogbl.c b/libm/upstream-freebsd/lib/msun/src/s_ilogbl.c
similarity index 90%
rename from libm/src/s_ilogbl.c
rename to libm/upstream-freebsd/lib/msun/src/s_ilogbl.c
index 406ad56..3211f44 100644
--- a/libm/src/s_ilogbl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ilogbl.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.1 2004/10/11 18:13:52 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include <float.h>
 #include <limits.h>
diff --git a/libm/src/s_isfinite.c b/libm/upstream-freebsd/lib/msun/src/s_isfinite.c
similarity index 95%
rename from libm/src/s_isfinite.c
rename to libm/upstream-freebsd/lib/msun/src/s_isfinite.c
index 394505d..c9d1bd7 100644
--- a/libm/src/s_isfinite.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_isfinite.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_isfinite.c,v 1.1 2004/07/09 03:32:39 das Exp $
+ * $FreeBSD$
  */
 
 #include <math.h>
diff --git a/libm/src/s_isnan.c b/libm/upstream-freebsd/lib/msun/src/s_isnan.c
similarity index 91%
rename from libm/src/s_isnan.c
rename to libm/upstream-freebsd/lib/msun/src/s_isnan.c
index f76352d..a54ded3 100644
--- a/libm/src/s_isnan.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_isnan.c
@@ -23,27 +23,28 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/msun/src/s_isnan.c,v 1.8 2004/08/05 01:46:11 das Exp $
+ * $FreeBSD$
  */
 
 #include <math.h>
 
 #include "fpmath.h"
 
-/* Provided by libc */
-#if 1
+/* Provided by libc.so */
+#ifndef PIC
+#undef isnan
 int
-(isnan)(double d)
+isnan(double d)
 {
 	union IEEEd2bits u;
 
 	u.d = d;
 	return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
 }
-#endif
+#endif /* !PIC */
 
 int
-isnanf(float f)
+__isnanf(float f)
 {
 	union IEEEf2bits u;
 
@@ -60,3 +61,5 @@
 	mask_nbit_l(u);
 	return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
 }
+
+__weak_reference(__isnanf, isnanf);
diff --git a/libm/src/s_isnormal.c b/libm/upstream-freebsd/lib/msun/src/s_isnormal.c
similarity index 95%
rename from libm/src/s_isnormal.c
rename to libm/upstream-freebsd/lib/msun/src/s_isnormal.c
index 1345dba..49f2a74 100644
--- a/libm/src/s_isnormal.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_isnormal.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_isnormal.c,v 1.1 2004/07/09 03:32:39 das Exp $
+ * $FreeBSD$
  */
 
 #include <math.h>
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llrint.c b/libm/upstream-freebsd/lib/msun/src/s_llrint.c
new file mode 100644
index 0000000..7c959ec
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llrint.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		double
+#define	roundit		rint
+#define dtype		long long
+#define	fn		llrint
+
+#include "s_lrint.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llrintf.c b/libm/upstream-freebsd/lib/msun/src/s_llrintf.c
new file mode 100644
index 0000000..7ec6015
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llrintf.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		float
+#define	roundit		rintf
+#define dtype		long long
+#define	fn		llrintf
+
+#include "s_lrint.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llrintl.c b/libm/upstream-freebsd/lib/msun/src/s_llrintl.c
new file mode 100644
index 0000000..6ef8375
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llrintl.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		long double
+#define	roundit		rintl
+#define dtype		long long
+#define	fn		llrintl
+
+#include "s_lrint.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llround.c b/libm/upstream-freebsd/lib/msun/src/s_llround.c
new file mode 100644
index 0000000..827dfc1
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llround.c
@@ -0,0 +1,11 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		double
+#define	roundit		round
+#define dtype		long long
+#define	DTYPE_MIN	LLONG_MIN
+#define	DTYPE_MAX	LLONG_MAX
+#define	fn		llround
+
+#include "s_lround.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llroundf.c b/libm/upstream-freebsd/lib/msun/src/s_llroundf.c
new file mode 100644
index 0000000..c037a18
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llroundf.c
@@ -0,0 +1,11 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		float
+#define	roundit		roundf
+#define dtype		long long
+#define	DTYPE_MIN	LLONG_MIN
+#define	DTYPE_MAX	LLONG_MAX
+#define	fn		llroundf
+
+#include "s_lround.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_llroundl.c b/libm/upstream-freebsd/lib/msun/src/s_llroundl.c
new file mode 100644
index 0000000..02c44eb
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_llroundl.c
@@ -0,0 +1,11 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		long double
+#define	roundit		roundl
+#define dtype		long long
+#define	DTYPE_MIN	LLONG_MIN
+#define	DTYPE_MAX	LLONG_MAX
+#define	fn		llroundl
+
+#include "s_lround.c"
diff --git a/libm/src/s_log1p.c b/libm/upstream-freebsd/lib/msun/src/s_log1p.c
similarity index 95%
rename from libm/src/s_log1p.c
rename to libm/upstream-freebsd/lib/msun/src/s_log1p.c
index 56e1516..b062a8a 100644
--- a/libm/src/s_log1p.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_log1p.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_log1p.c,v 1.8 2005/12/04 12:28:33 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* double log1p(double x)
  *
@@ -79,6 +78,8 @@
  *	 See HP-15C Advanced Functions Handbook, p.193.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -124,7 +125,7 @@
 	if (hx >= 0x7ff00000) return x+x;
 	if(k!=0) {
 	    if(hx<0x43400000) {
-		u  = 1.0+x;
+		STRICT_ASSIGN(double,u,1.0+x);
 		GET_HIGH_WORD(hu,u);
 	        k  = (hu>>20)-1023;
 	        c  = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */
@@ -154,8 +155,14 @@
 	}
 	hfsq=0.5*f*f;
 	if(hu==0) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;
-			else {c += k*ln2_lo; return k*ln2_hi+c;}
+	    if(f==zero) {
+		if(k==0) {
+		    return zero;
+		} else {
+		    c += k*ln2_lo;
+		    return k*ln2_hi+c;
+		}
+	    }
 	    R = hfsq*(1.0-0.66666666666666666*f);
 	    if(k==0) return f-R; else
 	    	     return k*ln2_hi-((R-(k*ln2_lo+c))-f);
diff --git a/libm/src/s_log1pf.c b/libm/upstream-freebsd/lib/msun/src/s_log1pf.c
similarity index 89%
rename from libm/src/s_log1pf.c
rename to libm/upstream-freebsd/lib/msun/src/s_log1pf.c
index 8364da0..01d3457 100644
--- a/libm/src/s_log1pf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_log1pf.c
@@ -13,9 +13,10 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_log1pf.c,v 1.9 2005/12/04 12:30:44 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -49,9 +50,9 @@
 		if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */
 		else return (x-x)/(x-x);	/* log1p(x<-1)=NaN */
 	    }
-	    if(ax<0x31000000) {			/* |x| < 2**-29 */
+	    if(ax<0x38000000) {			/* |x| < 2**-15 */
 		if(two25+x>zero			/* raise inexact */
-	            &&ax<0x24800000) 		/* |x| < 2**-54 */
+	            &&ax<0x33800000) 		/* |x| < 2**-24 */
 		    return x;
 		else
 		    return x - x*x*(float)0.5;
@@ -62,7 +63,7 @@
 	if (hx >= 0x7f800000) return x+x;
 	if(k!=0) {
 	    if(hx<0x5a000000) {
-		*(volatile float *)&u = (float)1.0+x;
+		STRICT_ASSIGN(float,u,(float)1.0+x);
 		GET_FLOAT_WORD(hu,u);
 	        k  = (hu>>23)-127;
 		/* correction term */
@@ -93,8 +94,14 @@
 	}
 	hfsq=(float)0.5*f*f;
 	if(hu==0) {	/* |f| < 2**-20 */
-	    if(f==zero) if(k==0) return zero;
-			else {c += k*ln2_lo; return k*ln2_hi+c;}
+	    if(f==zero) {
+		if(k==0) {
+		    return zero;
+		} else {
+		    c += k*ln2_lo;
+		    return k*ln2_hi+c;
+		}
+	    }
 	    R = hfsq*((float)1.0-(float)0.66666666666666666*f);
 	    if(k==0) return f-R; else
 	    	     return k*ln2_hi-((R-(k*ln2_lo+c))-f);
diff --git a/libm/src/s_logb.c b/libm/upstream-freebsd/lib/msun/src/s_logb.c
similarity index 88%
rename from libm/src/s_logb.c
rename to libm/upstream-freebsd/lib/msun/src/s_logb.c
index 57f91c4..a47e354 100644
--- a/libm/src/s_logb.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_logb.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logb.c,v 1.10 2005/12/03 11:57:19 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * double logb(x)
@@ -20,6 +19,8 @@
  * Use ilogb instead.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -42,3 +43,7 @@
 	} else
 		return (double) ((ix>>20)-1023);
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(logb, logbl);
+#endif
diff --git a/libm/src/s_logbf.c b/libm/upstream-freebsd/lib/msun/src/s_logbf.c
similarity index 88%
rename from libm/src/s_logbf.c
rename to libm/upstream-freebsd/lib/msun/src/s_logbf.c
index c54928c..3ab190d 100644
--- a/libm/src/s_logbf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_logbf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_logbf.c,v 1.8 2005/12/03 11:57:19 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_ilogbl.c b/libm/upstream-freebsd/lib/msun/src/s_logbl.c
similarity index 68%
copy from libm/src/s_ilogbl.c
copy to libm/upstream-freebsd/lib/msun/src/s_logbl.c
index 406ad56..7e88e36 100644
--- a/libm/src/s_ilogbl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_logbl.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_ilogbl.c,v 1.1 2004/10/11 18:13:52 stefanf Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 #include <float.h>
@@ -20,8 +20,8 @@
 
 #include "fpmath.h"
 
-int
-ilogbl(long double x)
+long double
+logbl(long double x)
 {
 	union IEEEl2bits u;
 	unsigned long m;
@@ -29,8 +29,10 @@
 
 	u.e = x;
 	if (u.bits.exp == 0) {
-		if ((u.bits.manl | u.bits.manh) == 0)
-			return (FP_ILOGB0);
+		if ((u.bits.manl | u.bits.manh) == 0) {	/* x == 0 */
+			u.bits.sign = 1;
+			return (1.0L / u.e);
+		}
 		/* denormalized */
 		if (u.bits.manh == 0) {
 			m = 1lu << (LDBL_MANL_SIZE - 1);
@@ -44,11 +46,10 @@
 #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);
+		return ((long double)(LDBL_MIN_EXP - b - 1));
+	}
+	if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1)	/* normal */
+		return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1));
+	else						/* +/- inf or nan */
+		return (x * x);
 }
diff --git a/libm/src/s_lrint.c b/libm/upstream-freebsd/lib/msun/src/s_lrint.c
similarity index 95%
rename from libm/src/s_lrint.c
rename to libm/upstream-freebsd/lib/msun/src/s_lrint.c
index 74a09d3a..27ff5ff 100644
--- a/libm/src/s_lrint.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_lrint.c
@@ -29,7 +29,7 @@
 #include <math.h>
 
 #ifndef type
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lrint.c,v 1.1 2005/01/11 23:12:55 das Exp $"); */
+__FBSDID("$FreeBSD$");
 #define type		double
 #define	roundit		rint
 #define dtype		long
diff --git a/libm/upstream-freebsd/lib/msun/src/s_lrintf.c b/libm/upstream-freebsd/lib/msun/src/s_lrintf.c
new file mode 100644
index 0000000..a757ded
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_lrintf.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		float
+#define	roundit		rintf
+#define dtype		long
+#define	fn		lrintf
+
+#include "s_lrint.c"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_lrintl.c b/libm/upstream-freebsd/lib/msun/src/s_lrintl.c
new file mode 100644
index 0000000..497b442
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_lrintl.c
@@ -0,0 +1,9 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define type		long double
+#define	roundit		rintl
+#define dtype		long
+#define	fn		lrintl
+
+#include "s_lrint.c"
diff --git a/libm/src/s_lround.c b/libm/upstream-freebsd/lib/msun/src/s_lround.c
similarity index 95%
rename from libm/src/s_lround.c
rename to libm/upstream-freebsd/lib/msun/src/s_lround.c
index e99f46f..3cff489 100644
--- a/libm/src/s_lround.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_lround.c
@@ -25,12 +25,12 @@
  */
 
 #include <sys/cdefs.h>
-#include <limits.h>
+#include <sys/limits.h>
 #include <fenv.h>
 #include <math.h>
 
 #ifndef type
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lround.c,v 1.2 2005/04/08 00:52:16 das Exp $"); */
+__FBSDID("$FreeBSD$");
 #define type		double
 #define	roundit		round
 #define dtype		long
diff --git a/libm/src/s_lroundf.c b/libm/upstream-freebsd/lib/msun/src/s_lroundf.c
similarity index 66%
rename from libm/src/s_lroundf.c
rename to libm/upstream-freebsd/lib/msun/src/s_lroundf.c
index e069c9c..e24fe7f 100644
--- a/libm/src/s_lroundf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_lroundf.c
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lroundf.c,v 1.2 2005/04/08 00:52:27 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #define type		float
 #define	roundit		roundf
diff --git a/libm/src/s_lroundl.c b/libm/upstream-freebsd/lib/msun/src/s_lroundl.c
similarity index 66%
rename from libm/src/s_lroundl.c
rename to libm/upstream-freebsd/lib/msun/src/s_lroundl.c
index 7c3f854..e410827 100644
--- a/libm/src/s_lroundl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_lroundl.c
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_lroundl.c,v 1.1 2005/04/08 01:24:08 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #define type		long double
 #define	roundit		roundl
diff --git a/libm/src/s_modf.c b/libm/upstream-freebsd/lib/msun/src/s_modf.c
similarity index 93%
rename from libm/src/s_modf.c
rename to libm/upstream-freebsd/lib/msun/src/s_modf.c
index 683fbda..ab13191 100644
--- a/libm/src/s_modf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_modf.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_modf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 /*
@@ -55,6 +55,10 @@
 	    }
 	} else if (j0>51) {		/* no fraction part */
 	    u_int32_t high;
+	    if (j0 == 0x400) {		/* inf/NaN */
+		*iptr = x;
+		return 0.0 / x;
+	    }
 	    *iptr = x*one;
 	    GET_HIGH_WORD(high,x);
 	    INSERT_WORDS(x,high&0x80000000,0);	/* return +-0 */
diff --git a/libm/src/s_modff.c b/libm/upstream-freebsd/lib/msun/src/s_modff.c
similarity index 91%
rename from libm/src/s_modff.c
rename to libm/upstream-freebsd/lib/msun/src/s_modff.c
index 6c75ffd..062259c 100644
--- a/libm/src/s_modff.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_modff.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_modff.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -49,6 +48,8 @@
 	} else {			/* no fraction part */
 	    u_int32_t ix;
 	    *iptr = x*one;
+	    if (x != x)			/* NaN */
+		return x;
 	    GET_FLOAT_WORD(ix,x);
 	    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
 	    return x;
diff --git a/libm/upstream-freebsd/lib/msun/src/s_modfl.c b/libm/upstream-freebsd/lib/msun/src/s_modfl.c
new file mode 100644
index 0000000..3dcdf86
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_modfl.c
@@ -0,0 +1,101 @@
+/*-
+ * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Derived from s_modf.c, which has the following Copyright:
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * $FreeBSD$
+ */
+
+#include <float.h>
+#include <math.h>
+#include <sys/types.h>
+
+#include "fpmath.h"
+
+#if LDBL_MANL_SIZE > 32
+#define	MASK	((uint64_t)-1)
+#else
+#define	MASK	((uint32_t)-1)
+#endif
+/* Return the last n bits of a word, representing the fractional part. */
+#define	GETFRAC(bits, n)	((bits) & ~(MASK << (n)))
+/* The number of fraction bits in manh, not counting the integer bit */
+#define	HIBITS	(LDBL_MANT_DIG - LDBL_MANL_SIZE)
+
+static const long double zero[] = { 0.0L, -0.0L };
+
+long double
+modfl(long double x, long double *iptr)
+{
+	union IEEEl2bits ux;
+	int e;
+
+	ux.e = x;
+	e = ux.bits.exp - LDBL_MAX_EXP + 1;
+	if (e < HIBITS) {			/* Integer part is in manh. */
+		if (e < 0) {			/* |x|<1 */
+			*iptr = zero[ux.bits.sign];
+			return (x);
+		} else {
+			if ((GETFRAC(ux.bits.manh, HIBITS - 1 - e) |
+			     ux.bits.manl) == 0) {	/* X is an integer. */
+				*iptr = x;
+				return (zero[ux.bits.sign]);
+			} else {
+				/* Clear all but the top e+1 bits. */
+				ux.bits.manh >>= HIBITS - 1 - e;
+				ux.bits.manh <<= HIBITS - 1 - e;
+				ux.bits.manl = 0;
+				*iptr = ux.e;
+				return (x - ux.e);
+			}
+		}
+	} else if (e >= LDBL_MANT_DIG - 1) {	/* x has no fraction part. */
+		*iptr = x;
+		if (x != x)			/* Handle NaNs. */
+			return (x);
+		return (zero[ux.bits.sign]);
+	} else {				/* Fraction part is in manl. */
+		if (GETFRAC(ux.bits.manl, LDBL_MANT_DIG - 1 - e) == 0) {
+			/* x is integral. */
+			*iptr = x;
+			return (zero[ux.bits.sign]);
+		} else {
+			/* Clear all but the top e+1 bits. */
+			ux.bits.manl >>= LDBL_MANT_DIG - 1 - e;
+			ux.bits.manl <<= LDBL_MANT_DIG - 1 - e;
+			*iptr = ux.e;
+			return (x - ux.e);
+		}
+	}
+}
diff --git a/libm/src/s_nan.c b/libm/upstream-freebsd/lib/msun/src/s_nan.c
similarity index 89%
rename from libm/src/s_nan.c
rename to libm/upstream-freebsd/lib/msun/src/s_nan.c
index e366e6b..890f471 100644
--- a/libm/src/s_nan.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nan.c
@@ -35,27 +35,6 @@
 
 #include "math_private.h"
 
-/* digittoint is in the FreeBSD C library, but not Bionic at this point */
-static int
-digittoint(char ch)
-{
-    int d;
-
-    d = ch - '0';
-    if ((unsigned)d < 10) {
-        return d;
-    }
-    d = ch - 'a';
-    if ((unsigned)d < 6) {
-        return d + 10;
-    }
-    d = ch - 'A';
-    if ((unsigned)d < 6) {
-        return d + 10;
-    }
-    return -1;
-}
-
 /*
  * Scan a string of hexadecimal digits (the format nan(3) expects) and
  * make a bit array (using the local endianness). We stop when we
@@ -127,5 +106,5 @@
 }
 
 #if (LDBL_MANT_DIG == 53)
-__weak_alias(nanl, nan);
+__weak_reference(nan, nanl);
 #endif
diff --git a/libm/src/s_nearbyint.c b/libm/upstream-freebsd/lib/msun/src/s_nearbyint.c
similarity index 95%
rename from libm/src/s_nearbyint.c
rename to libm/upstream-freebsd/lib/msun/src/s_nearbyint.c
index 246d325..12493d2 100644
--- a/libm/src/s_nearbyint.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nearbyint.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_nearbyint.c,v 1.1 2004/07/06 04:46:08 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <fenv.h>
 #include <math.h>
@@ -52,3 +52,4 @@
 
 DECL(double, nearbyint, rint)
 DECL(float, nearbyintf, rintf)
+DECL(long double, nearbyintl, rintl)
diff --git a/libm/src/s_nextafter.c b/libm/upstream-freebsd/lib/msun/src/s_nextafter.c
similarity index 93%
rename from libm/src/s_nextafter.c
rename to libm/upstream-freebsd/lib/msun/src/s_nextafter.c
index 3ed0361..52dd21c 100644
--- a/libm/src/s_nextafter.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nextafter.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafter.c,v 1.11 2005/03/07 21:27:37 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* IEEE functions
  *	nextafter(x,y)
@@ -21,7 +20,6 @@
  *   Special cases:
  */
 
-#include <sys/cdefs.h>
 #include <float.h>
 
 #include "math.h"
diff --git a/libm/src/s_nextafterf.c b/libm/upstream-freebsd/lib/msun/src/s_nextafterf.c
similarity index 92%
rename from libm/src/s_nextafterf.c
rename to libm/upstream-freebsd/lib/msun/src/s_nextafterf.c
index ebeac4a..96e21ef 100644
--- a/libm/src/s_nextafterf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nextafterf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterf.c,v 1.10 2005/03/07 04:55:58 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_nextafterl.c b/libm/upstream-freebsd/lib/msun/src/s_nextafterl.c
similarity index 93%
rename from libm/src/s_nextafterl.c
rename to libm/upstream-freebsd/lib/msun/src/s_nextafterl.c
index eacfd33..9c61a43 100644
--- a/libm/src/s_nextafterl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nextafterl.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nextafterl.c,v 1.1 2005/03/07 04:56:46 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* IEEE functions
  *	nextafter(x,y)
@@ -21,7 +20,6 @@
  *   Special cases:
  */
 
-#include <sys/cdefs.h>
 #include <float.h>
 
 #include "fpmath.h"
diff --git a/libm/src/s_nexttoward.c b/libm/upstream-freebsd/lib/msun/src/s_nexttoward.c
similarity index 90%
rename from libm/src/s_nexttoward.c
rename to libm/upstream-freebsd/lib/msun/src/s_nexttoward.c
index 55da4ad..b2a50d3 100644
--- a/libm/src/s_nexttoward.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nexttoward.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nexttoward.c,v 1.1 2005/03/07 04:56:46 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * We assume that a long double has a 15-bit exponent.  On systems
@@ -64,8 +63,8 @@
 	if(ix<0x00100000) {		/* underflow */
 	    t = x*x;
 	    if(t!=x) {		/* raise underflow flag */
-	        INSERT_WORDS(y,hx,lx);
-		return y;
+	        INSERT_WORDS(x,hx,lx);
+		return x;
 	    }
 	}
 	INSERT_WORDS(x,hx,lx);
diff --git a/libm/src/s_nexttowardf.c b/libm/upstream-freebsd/lib/msun/src/s_nexttowardf.c
similarity index 88%
rename from libm/src/s_nexttowardf.c
rename to libm/upstream-freebsd/lib/msun/src/s_nexttowardf.c
index 54156e6..9ddfff9 100644
--- a/libm/src/s_nexttowardf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_nexttowardf.c
@@ -9,9 +9,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_nexttowardf.c,v 1.1 2005/03/07 04:57:38 das Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include <float.h>
 
@@ -51,8 +50,8 @@
 	if(ix<0x00800000) {		/* underflow */
 	    t = x*x;
 	    if(t!=x) {		/* raise underflow flag */
-	        SET_FLOAT_WORD(y,hx);
-		return y;
+	        SET_FLOAT_WORD(x,hx);
+		return x;
 	    }
 	}
 	SET_FLOAT_WORD(x,hx);
diff --git a/libm/src/s_remquo.c b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
similarity index 92%
rename from libm/src/s_remquo.c
rename to libm/upstream-freebsd/lib/msun/src/s_remquo.c
index 9ad1e4c..d811c69 100644
--- a/libm/src/s_remquo.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquo.c
@@ -11,7 +11,9 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_remquo.c,v 1.1 2005/03/25 04:40:44 das Exp $"); */
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #include "math_private.h"
@@ -49,7 +51,7 @@
 		goto fixup;	/* |x|<|y| return x or x-y */
 	    }
 	    if(lx==ly) {
-                *quo = (sxy ? -1 : 1);
+		*quo = (sxy ? -1 : 1);
 		return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
 	    }
 	}
@@ -112,8 +114,8 @@
 
     /* convert back to floating value and restore the sign */
 	if((hx|lx)==0) {			/* return sign(x)*0 */
-            q &= 0x7fffffff;
-            *quo = (sxy ? -q : q);
+	    q &= 0x7fffffff;
+	    *quo = (sxy ? -q : q);
 	    return Zero[(u_int32_t)sx>>31];
 	}
 	while(hx<0x00100000) {		/* normalize x */
@@ -128,9 +130,9 @@
 		lx = (lx>>n)|((u_int32_t)hx<<(32-n));
 		hx >>= n;
 	    } else if (n<=31) {
-                lx = (hx<<(32-n))|(lx>>n); hx = 0;
+		lx = (hx<<(32-n))|(lx>>n); hx = 0;
 	    } else {
-                lx = hx>>(n-32); hx = 0;
+		lx = hx>>(n-32); hx = 0;
 	    }
 	}
 fixup:
@@ -151,3 +153,7 @@
 	*quo = (sxy ? -q : q);
 	return x;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(remquo, remquol);
+#endif
diff --git a/libm/src/s_remquof.c b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
similarity index 93%
rename from libm/src/s_remquof.c
rename to libm/upstream-freebsd/lib/msun/src/s_remquof.c
index 43e05cb..f7b4c00 100644
--- a/libm/src/s_remquof.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquof.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_remquof.c,v 1.1 2005/03/25 04:40:44 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
@@ -46,7 +46,7 @@
 	    q = 0;
 	    goto fixup;	/* |x|<|y| return x or x-y */
 	} else if(hx==hy) {
-            *quo = (sxy ? -1 : 1);
+	    *quo = (sxy ? -1 : 1);
 	    return Zero[(u_int32_t)sx>>31];	/* |x|=|y| return x*0*/
 	}
 
@@ -88,8 +88,8 @@
 
     /* convert back to floating value and restore the sign */
 	if(hx==0) {				/* return sign(x)*0 */
-            q &= 0x7fffffff;
-            *quo = (sxy ? -q : q);
+	    q &= 0x7fffffff;
+	    *quo = (sxy ? -q : q);
 	    return Zero[(u_int32_t)sx>>31];
 	}
 	while(hx<0x00800000) {		/* normalize x */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_remquol.c b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
new file mode 100644
index 0000000..712651c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_remquol.c
@@ -0,0 +1,178 @@
+/* @(#)e_fmod.c 1.3 95/01/18 */
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <stdint.h>
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
+
+#define	BIAS (LDBL_MAX_EXP - 1)
+
+#if LDBL_MANL_SIZE > 32
+typedef	uint64_t manl_t;
+#else
+typedef	uint32_t manl_t;
+#endif
+
+#if LDBL_MANH_SIZE > 32
+typedef	uint64_t manh_t;
+#else
+typedef	uint32_t manh_t;
+#endif
+
+/*
+ * These macros add and remove an explicit integer bit in front of the
+ * fractional mantissa, if the architecture doesn't have such a bit by
+ * default already.
+ */
+#ifdef LDBL_IMPLICIT_NBIT
+#define	SET_NBIT(hx)	((hx) | (1ULL << LDBL_MANH_SIZE))
+#define	HFRAC_BITS	LDBL_MANH_SIZE
+#else
+#define	SET_NBIT(hx)	(hx)
+#define	HFRAC_BITS	(LDBL_MANH_SIZE - 1)
+#endif
+
+#define	MANL_SHIFT	(LDBL_MANL_SIZE - 1)
+
+static const long double Zero[] = {0.0L, -0.0L};
+
+/*
+ * Return the IEEE remainder and set *quo to the last n bits of the
+ * quotient, rounded to the nearest integer.  We choose n=31 because
+ * we wind up computing all the integer bits of the quotient anyway as
+ * a side-effect of computing the remainder by the shift and subtract
+ * method.  In practice, this is far more bits than are needed to use
+ * remquo in reduction algorithms.
+ *
+ * Assumptions:
+ * - The low part of the mantissa fits in a manl_t exactly.
+ * - The high part of the mantissa fits in an int64_t with enough room
+ *   for an explicit integer bit in front of the fractional bits.
+ */
+long double
+remquol(long double x, long double y, int *quo)
+{
+	union IEEEl2bits ux, uy;
+	int64_t hx,hz;	/* We need a carry bit even if LDBL_MANH_SIZE is 32. */
+	manh_t hy;
+	manl_t lx,ly,lz;
+	int ix,iy,n,q,sx,sxy;
+
+	ux.e = x;
+	uy.e = y;
+	sx = ux.bits.sign;
+	sxy = sx ^ uy.bits.sign;
+	ux.bits.sign = 0;	/* |x| */
+	uy.bits.sign = 0;	/* |y| */
+	x = ux.e;
+
+    /* purge off exception values */
+	if((uy.bits.exp|uy.bits.manh|uy.bits.manl)==0 || /* y=0 */
+	   (ux.bits.exp == BIAS + LDBL_MAX_EXP) ||	 /* or x not finite */
+	   (uy.bits.exp == BIAS + LDBL_MAX_EXP &&
+	    ((uy.bits.manh&~LDBL_NBIT)|uy.bits.manl)!=0)) /* or y is NaN */
+	    return (x*y)/(x*y);
+	if(ux.bits.exp<=uy.bits.exp) {
+	    if((ux.bits.exp<uy.bits.exp) ||
+	       (ux.bits.manh<=uy.bits.manh &&
+		(ux.bits.manh<uy.bits.manh ||
+		 ux.bits.manl<uy.bits.manl))) {
+		q = 0;
+		goto fixup;	/* |x|<|y| return x or x-y */
+	    }
+	    if(ux.bits.manh==uy.bits.manh && ux.bits.manl==uy.bits.manl) {
+		*quo = (sxy ? -1 : 1);
+		return Zero[sx];	/* |x|=|y| return x*0*/
+	    }
+	}
+
+    /* determine ix = ilogb(x) */
+	if(ux.bits.exp == 0) {	/* subnormal x */
+	    ux.e *= 0x1.0p512;
+	    ix = ux.bits.exp - (BIAS + 512);
+	} else {
+	    ix = ux.bits.exp - BIAS;
+	}
+
+    /* determine iy = ilogb(y) */
+	if(uy.bits.exp == 0) {	/* subnormal y */
+	    uy.e *= 0x1.0p512;
+	    iy = uy.bits.exp - (BIAS + 512);
+	} else {
+	    iy = uy.bits.exp - BIAS;
+	}
+
+    /* set up {hx,lx}, {hy,ly} and align y to x */
+	hx = SET_NBIT(ux.bits.manh);
+	hy = SET_NBIT(uy.bits.manh);
+	lx = ux.bits.manl;
+	ly = uy.bits.manl;
+
+    /* fix point fmod */
+	n = ix - iy;
+	q = 0;
+
+	while(n--) {
+	    hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	    if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;}
+	    else {hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz; q++;}
+	    q <<= 1;
+	}
+	hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+	if(hz>=0) {hx=hz;lx=lz;q++;}
+
+    /* convert back to floating value and restore the sign */
+	if((hx|lx)==0) {			/* return sign(x)*0 */
+	    q &= 0x7fffffff;
+	    *quo = (sxy ? -q : q);
+	    return Zero[sx];
+	}
+	while(hx<(1ULL<<HFRAC_BITS)) {	/* normalize x */
+	    hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;
+	    iy -= 1;
+	}
+	ux.bits.manh = hx; /* The integer bit is truncated here if needed. */
+	ux.bits.manl = lx;
+	if (iy < LDBL_MIN_EXP) {
+	    ux.bits.exp = iy + (BIAS + 512);
+	    ux.e *= 0x1p-512;
+	} else {
+	    ux.bits.exp = iy + BIAS;
+	}
+	ux.bits.sign = 0;
+	x = ux.e;
+fixup:
+	y = fabsl(y);
+	if (y < LDBL_MIN * 2) {
+	    if (x+x>y || (x+x==y && (q & 1))) {
+		q++;
+		x-=y;
+	    }
+	} else if (x>0.5*y || (x==0.5*y && (q & 1))) {
+	    q++;
+	    x-=y;
+	}
+
+	ux.e = x;
+	ux.bits.sign ^= sx;
+	x = ux.e;
+
+	q &= 0x7fffffff;
+	*quo = (sxy ? -q : q);
+	return x;
+}
diff --git a/libm/src/s_rint.c b/libm/upstream-freebsd/lib/msun/src/s_rint.c
similarity index 90%
rename from libm/src/s_rint.c
rename to libm/upstream-freebsd/lib/msun/src/s_rint.c
index a88d7b7..c56f8fb 100644
--- a/libm/src/s_rint.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_rint.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rint.c,v 1.13 2005/12/03 07:38:35 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * rint(x)
@@ -24,6 +23,8 @@
  *	Inexact flag raised if x not equal to rint(x).
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -49,7 +50,7 @@
 		i0 &= 0xfffe0000;
 		i0 |= ((i1|-i1)>>12)&0x80000;
 		SET_HIGH_WORD(x,i0);
-	        w = TWO52[sx]+x;
+	        STRICT_ASSIGN(double,w,TWO52[sx]+x);
 	        t =  w-TWO52[sx];
 		GET_HIGH_WORD(i0,t);
 		SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
@@ -82,6 +83,10 @@
 	    if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
 	}
 	INSERT_WORDS(x,i0,i1);
-	*(volatile double *)&w = TWO52[sx]+x;	/* clip any extra precision */
+	STRICT_ASSIGN(double,w,TWO52[sx]+x);
 	return w-TWO52[sx];
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(rint, rintl);
+#endif
diff --git a/libm/src/s_rintf.c b/libm/upstream-freebsd/lib/msun/src/s_rintf.c
similarity index 80%
rename from libm/src/s_rintf.c
rename to libm/upstream-freebsd/lib/msun/src/s_rintf.c
index 677421a..f8743a4 100644
--- a/libm/src/s_rintf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_rintf.c
@@ -13,11 +13,12 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_rintf.c,v 1.10 2005/12/03 09:00:29 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
-#include <sys/types.h>
+#include <float.h>
+#include <stdint.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -31,20 +32,20 @@
 rintf(float x)
 {
 	int32_t i0,j0,sx;
-	volatile float w,t;	/* volatile works around gcc bug */
+	float w,t;
 	GET_FLOAT_WORD(i0,x);
 	sx = (i0>>31)&1;
 	j0 = ((i0>>23)&0xff)-0x7f;
 	if(j0<23) {
 	    if(j0<0) {
 		if((i0&0x7fffffff)==0) return x;
-	        w = TWO23[sx]+x;
+		STRICT_ASSIGN(float,w,TWO23[sx]+x);
 	        t =  w-TWO23[sx];
 		GET_FLOAT_WORD(i0,t);
 		SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
 	        return t;
 	    }
-	    w = TWO23[sx]+x;
+	    STRICT_ASSIGN(float,w,TWO23[sx]+x);
 	    return w-TWO23[sx];
 	}
 	if(j0==0x80) return x+x;	/* inf or NaN */
diff --git a/libm/upstream-freebsd/lib/msun/src/s_rintl.c b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
new file mode 100644
index 0000000..b43df89
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+#if LDBL_MAX_EXP != 0x4000
+/* We also require the usual bias, min exp and expsign packing. */
+#error "Unsupported long double format"
+#endif
+
+#define	BIAS	(LDBL_MAX_EXP - 1)
+
+static const float
+shift[2] = {
+#if LDBL_MANT_DIG == 64
+	0x1.0p63, -0x1.0p63
+#elif LDBL_MANT_DIG == 113
+	0x1.0p112, -0x1.0p112
+#else
+#error "Unsupported long double format"
+#endif
+};
+static const float zero[2] = { 0.0, -0.0 };
+
+long double
+rintl(long double x)
+{
+	union IEEEl2bits u;
+	uint32_t expsign;
+	int ex, sign;
+
+	u.e = x;
+	expsign = u.xbits.expsign;
+	ex = expsign & 0x7fff;
+
+	if (ex >= BIAS + LDBL_MANT_DIG - 1) {
+		if (ex == BIAS + LDBL_MAX_EXP)
+			return (x + x);	/* Inf, NaN, or unsupported format */
+		return (x);		/* finite and already an integer */
+	}
+	sign = expsign >> 15;
+
+	/*
+	 * The following code assumes that intermediate results are
+	 * evaluated in long double precision. If they are evaluated in
+	 * greater precision, double rounding may occur, and if they are
+	 * evaluated in less precision (as on i386), results will be
+	 * wildly incorrect.
+	 */
+	x += shift[sign];
+	x -= shift[sign];
+
+	/*
+	 * If the result is +-0, then it must have the same sign as x, but
+	 * the above calculation doesn't always give this.  Fix up the sign.
+	 */
+	if (ex < BIAS && x == 0.0L)
+		return (zero[sign]);
+
+	return (x);
+}
diff --git a/libm/src/s_round.c b/libm/upstream-freebsd/lib/msun/src/s_round.c
similarity index 94%
rename from libm/src/s_round.c
rename to libm/upstream-freebsd/lib/msun/src/s_round.c
index 274c119..65de31b 100644
--- a/libm/src/s_round.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_round.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_roundf.c b/libm/upstream-freebsd/lib/msun/src/s_roundf.c
similarity index 94%
rename from libm/src/s_roundf.c
rename to libm/upstream-freebsd/lib/msun/src/s_roundf.c
index 823be9b..952e8e7 100644
--- a/libm/src/s_roundf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_roundf.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_roundf.c,v 1.4 2005/12/02 13:45:06 bde Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_roundl.c b/libm/upstream-freebsd/lib/msun/src/s_roundl.c
similarity index 94%
rename from libm/src/s_roundl.c
rename to libm/upstream-freebsd/lib/msun/src/s_roundl.c
index a65f330..a70b617 100644
--- a/libm/src/s_roundl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_roundl.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_roundl.c,v 1.2 2005/12/02 13:45:06 bde Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <math.h>
 
diff --git a/libm/src/s_scalbln.c b/libm/upstream-freebsd/lib/msun/src/s_scalbln.c
similarity index 94%
rename from libm/src/s_scalbln.c
rename to libm/upstream-freebsd/lib/msun/src/s_scalbln.c
index 41908d2..d609d4e 100644
--- a/libm/src/s_scalbln.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_scalbln.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_scalbln.c,v 1.2 2005/03/07 04:57:50 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 #include <limits.h>
 #include <math.h>
diff --git a/libm/src/s_scalbn.c b/libm/upstream-freebsd/lib/msun/src/s_scalbn.c
similarity index 81%
rename from libm/src/s_scalbn.c
rename to libm/upstream-freebsd/lib/msun/src/s_scalbn.c
index 6218c11..e7efaab 100644
--- a/libm/src/s_scalbn.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_scalbn.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbn.c,v 1.11 2005/03/07 21:27:37 das Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 /*
@@ -60,20 +60,7 @@
         return x*twom54;
 }
 
-// this is normally in FreeBSD's libc.
-double
-ldexp (double x, int n)
-{
-    return scalbn(x,n);
-}
-
-#if (LDBL_MANT_DIG == 53)    //XXX: brian FIXME __weak_reference doesn work
-long double ldexpl (long double x, int n) {
-    return scalbn((double)x,n);
-}
-long double scalbnl (long double x, int n) {
-    return scalbn((double)x,n);
-}
+#if (LDBL_MANT_DIG == 53)
 __weak_reference(scalbn, ldexpl);
 __weak_reference(scalbn, scalbnl);
 #endif
diff --git a/libm/src/s_scalbnf.c b/libm/upstream-freebsd/lib/msun/src/s_scalbnf.c
similarity index 94%
rename from libm/src/s_scalbnf.c
rename to libm/upstream-freebsd/lib/msun/src/s_scalbnf.c
index 46c7baf..7666c74 100644
--- a/libm/src/s_scalbnf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_scalbnf.c
@@ -14,7 +14,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnf.c,v 1.8 2005/03/07 04:52:43 das Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 #include <sys/cdefs.h>
diff --git a/libm/src/s_scalbnl.c b/libm/upstream-freebsd/lib/msun/src/s_scalbnl.c
similarity index 94%
rename from libm/src/s_scalbnl.c
rename to libm/upstream-freebsd/lib/msun/src/s_scalbnl.c
index c645d00..fc89f8d 100644
--- a/libm/src/s_scalbnl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_scalbnl.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_scalbnl.c,v 1.1 2005/03/07 04:52:58 das Exp $";
+static char rcsid[] = "$FreeBSD$";
 #endif
 
 /*
diff --git a/libm/src/s_signbit.c b/libm/upstream-freebsd/lib/msun/src/s_signbit.c
similarity index 95%
rename from libm/src/s_signbit.c
rename to libm/upstream-freebsd/lib/msun/src/s_signbit.c
index ffc08f3..01eb3ab 100644
--- a/libm/src/s_signbit.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_signbit.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_signbit.c,v 1.1 2004/07/19 08:16:10 das Exp $
+ * $FreeBSD$
  */
 
 #include <math.h>
diff --git a/libm/src/s_signgam.c b/libm/upstream-freebsd/lib/msun/src/s_signgam.c
similarity index 100%
rename from libm/src/s_signgam.c
rename to libm/upstream-freebsd/lib/msun/src/s_signgam.c
diff --git a/libm/src/s_significand.c b/libm/upstream-freebsd/lib/msun/src/s_significand.c
similarity index 84%
rename from libm/src/s_significand.c
rename to libm/upstream-freebsd/lib/msun/src/s_significand.c
index 08bb303..356e300 100644
--- a/libm/src/s_significand.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_significand.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_significand.c,v 1.9 2003/07/23 04:53:47 peter Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * significand(x) computes just
diff --git a/libm/src/s_significandf.c b/libm/upstream-freebsd/lib/msun/src/s_significandf.c
similarity index 83%
rename from libm/src/s_significandf.c
rename to libm/upstream-freebsd/lib/msun/src/s_significandf.c
index b3e341d..ad030e2 100644
--- a/libm/src/s_significandf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_significandf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_significandf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/src/s_sin.c b/libm/upstream-freebsd/lib/msun/src/s_sin.c
similarity index 90%
rename from libm/src/s_sin.c
rename to libm/upstream-freebsd/lib/msun/src/s_sin.c
index e893e23..17ea846 100644
--- a/libm/src/s_sin.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_sin.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_sin.c,v 1.10 2005/10/24 14:08:36 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* sin(x)
  * Return sine function of x.
@@ -45,8 +44,12 @@
  *	TRIG(x) returns trig(x) nearly rounded
  */
 
+#include <float.h>
+
 #include "math.h"
+#define INLINE_REM_PIO2
 #include "math_private.h"
+#include "e_rem_pio2.c"
 
 double
 sin(double x)
@@ -60,7 +63,7 @@
     /* |x| ~< pi/4 */
 	ix &= 0x7fffffff;
 	if(ix <= 0x3fe921fb) {
-	    if(ix<0x3e400000)			/* |x| < 2**-27 */
+	    if(ix<0x3e500000)			/* |x| < 2**-26 */
 	       {if((int)x==0) return x;}	/* generate inexact */
 	    return __kernel_sin(x,z,0);
 	}
@@ -80,3 +83,7 @@
 	    }
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(sin, sinl);
+#endif
diff --git a/libm/src/s_sinf.c b/libm/upstream-freebsd/lib/msun/src/s_sinf.c
similarity index 83%
rename from libm/src/s_sinf.c
rename to libm/upstream-freebsd/lib/msun/src/s_sinf.c
index 9dc3cae..41b5dc1 100644
--- a/libm/src/s_sinf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_sinf.c
@@ -14,14 +14,17 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_sinf.c,v 1.14 2005/11/28 06:15:10 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #define	INLINE_KERNEL_COSDF
 #define	INLINE_KERNEL_SINDF
+#define INLINE_REM_PIO2F
 #include "math_private.h"
+#include "e_rem_pio2f.c"
 #include "k_cosf.c"
 #include "k_sinf.c"
 
@@ -35,7 +38,7 @@
 float
 sinf(float x)
 {
-	float y[2];
+	double y;
 	int32_t n, hx, ix;
 
 	GET_FLOAT_WORD(hx,x);
@@ -70,13 +73,13 @@
 
     /* general argument reduction needed */
 	else {
-	    n = __ieee754_rem_pio2f(x,y);
+	    n = __ieee754_rem_pio2f(x,&y);
 	    switch(n&3) {
-		case 0: return  __kernel_sindf((double)y[0]+y[1]);
-		case 1: return  __kernel_cosdf((double)y[0]+y[1]);
-		case 2: return  __kernel_sindf(-(double)y[0]-y[1]);
+		case 0: return  __kernel_sindf(y);
+		case 1: return  __kernel_cosdf(y);
+		case 2: return  __kernel_sindf(-y);
 		default:
-			return -__kernel_cosdf((double)y[0]+y[1]);
+			return -__kernel_cosdf(y);
 	    }
 	}
 }
diff --git a/libm/upstream-freebsd/lib/msun/src/s_sinl.c b/libm/upstream-freebsd/lib/msun/src/s_sinl.c
new file mode 100644
index 0000000..f454f8f
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_sinl.c
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 2007 Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "math.h"
+#include "math_private.h"
+#if LDBL_MANT_DIG == 64
+#include "../ld80/e_rem_pio2l.h"
+#elif LDBL_MANT_DIG == 113
+#include "../ld128/e_rem_pio2l.h"
+#else
+#error "Unsupported long double format"
+#endif
+
+long double
+sinl(long double x)
+{
+	union IEEEl2bits z;
+	int e0, s;
+	long double y[2];
+	long double hi, lo;
+
+	z.e = x;
+	s = z.bits.sign;
+	z.bits.sign = 0;
+
+	/* If x = +-0 or x is a subnormal number, then sin(x) = x */
+	if (z.bits.exp == 0)
+		return (x);
+
+	/* If x = NaN or Inf, then sin(x) = NaN. */
+	if (z.bits.exp == 32767)
+		return ((x - x) / (x - x));
+
+	ENTERI();
+
+	/* Optimize the case where x is already within range. */
+	if (z.e < M_PI_4) {
+		hi = __kernel_sinl(z.e, 0, 0);
+		RETURNI(s ? -hi : hi);
+	}
+
+	e0 = __ieee754_rem_pio2l(x, y);
+	hi = y[0];
+	lo = y[1];
+
+	switch (e0 & 3) {
+	case 0:
+	    hi = __kernel_sinl(hi, lo, 1);
+	    break;
+	case 1:
+	    hi = __kernel_cosl(hi, lo);
+	    break;
+	case 2:
+	    hi = - __kernel_sinl(hi, lo, 1);
+	    break;
+	case 3:
+	    hi = - __kernel_cosl(hi, lo);
+	    break;
+	}
+	
+	RETURNI(hi);
+}
diff --git a/libm/src/s_tan.c b/libm/upstream-freebsd/lib/msun/src/s_tan.c
similarity index 89%
rename from libm/src/s_tan.c
rename to libm/upstream-freebsd/lib/msun/src/s_tan.c
index 7f0b4a0..196c27e 100644
--- a/libm/src/s_tan.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tan.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tan.c,v 1.10 2005/11/02 14:01:45 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* tan(x)
  * Return tangent function of x.
@@ -44,8 +43,12 @@
  *	TRIG(x) returns trig(x) nearly rounded
  */
 
+#include <float.h>
+
 #include "math.h"
+#define INLINE_REM_PIO2
 #include "math_private.h"
+#include "e_rem_pio2.c"
 
 double
 tan(double x)
@@ -59,7 +62,7 @@
     /* |x| ~< pi/4 */
 	ix &= 0x7fffffff;
 	if(ix <= 0x3fe921fb) {
-	    if(ix<0x3e300000)			/* x < 2**-28 */
+	    if(ix<0x3e400000)			/* x < 2**-27 */
 		if((int)x==0) return x;		/* generate inexact */
 	    return __kernel_tan(x,z,1);
 	}
@@ -74,3 +77,7 @@
 							-1 -- n odd */
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(tan, tanl);
+#endif
diff --git a/libm/src/s_tanf.c b/libm/upstream-freebsd/lib/msun/src/s_tanf.c
similarity index 88%
rename from libm/src/s_tanf.c
rename to libm/upstream-freebsd/lib/msun/src/s_tanf.c
index 7e80d69..4fe8c17 100644
--- a/libm/src/s_tanf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanf.c
@@ -14,13 +14,16 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanf.c,v 1.14 2005/11/28 05:35:32 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
 
 #include "math.h"
 #define	INLINE_KERNEL_TANDF
+#define INLINE_REM_PIO2F
 #include "math_private.h"
+#include "e_rem_pio2f.c"
 #include "k_tanf.c"
 
 /* Small multiples of pi/2 rounded to double precision. */
@@ -33,7 +36,7 @@
 float
 tanf(float x)
 {
-	float y[2];
+	double y;
 	int32_t n, hx, ix;
 
 	GET_FLOAT_WORD(hx,x);
@@ -62,8 +65,8 @@
 
     /* general argument reduction needed */
 	else {
-	    n = __ieee754_rem_pio2f(x,y);
+	    n = __ieee754_rem_pio2f(x,&y);
 	    /* integer parameter: 1 -- n even; -1 -- n odd */
-	    return __kernel_tandf((double)y[0]+y[1],1-((n&1)<<1));
+	    return __kernel_tandf(y,1-((n&1)<<1));
 	}
 }
diff --git a/libm/src/s_tanh.c b/libm/upstream-freebsd/lib/msun/src/s_tanh.c
similarity index 69%
rename from libm/src/s_tanh.c
rename to libm/upstream-freebsd/lib/msun/src/s_tanh.c
index 4729145..96e3565 100644
--- a/libm/src/s_tanh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanh.c
@@ -10,9 +10,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanh.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /* Tanh(x)
  * Return the Hyperbolic Tangent of x
@@ -24,14 +23,14 @@
  *				       x    -x
  *				      e  + e
  *	1. reduce x to non-negative by tanh(-x) = -tanh(x).
- *	2.  0      <= x <= 2**-55 : tanh(x) := x*(one+x)
+ *	2.  0      <= x <  2**-28 : tanh(x) := x with inexact if x != 0
  *					        -t
- *	    2**-55 <  x <=  1     : tanh(x) := -----; t = expm1(-2x)
+ *	    2**-28 <= x <  1      : tanh(x) := -----; t = expm1(-2x)
  *					       t + 2
  *						     2
- *	    1      <= x <=  22.0  : tanh(x) := 1-  ----- ; t=expm1(2x)
+ *	    1      <= x <  22     : tanh(x) := 1 - -----; t = expm1(2x)
  *						   t + 2
- *	    22.0   <  x <= INF    : tanh(x) := 1.
+ *	    22     <= x <= INF    : tanh(x) := 1.
  *
  * Special cases:
  *	tanh(NaN) is NaN;
@@ -41,7 +40,7 @@
 #include "math.h"
 #include "math_private.h"
 
-static const double one=1.0, two=2.0, tiny = 1.0e-300;
+static const double one = 1.0, two = 2.0, tiny = 1.0e-300, huge = 1.0e300;
 
 double
 tanh(double x)
@@ -49,7 +48,6 @@
 	double t,z;
 	int32_t jx,ix;
 
-    /* High word of |x|. */
 	GET_HIGH_WORD(jx,x);
 	ix = jx&0x7fffffff;
 
@@ -61,8 +59,9 @@
 
     /* |x| < 22 */
 	if (ix < 0x40360000) {		/* |x|<22 */
-	    if (ix<0x3c800000) 		/* |x|<2**-55 */
-		return x*(one+x);    	/* tanh(small) = small */
+	    if (ix<0x3e300000) {	/* |x|<2**-28 */
+		if(huge+x>one) return x; /* tanh(tiny) = tiny with inexact */
+	    }
 	    if (ix>=0x3ff00000) {	/* |x|>=1  */
 		t = expm1(two*fabs(x));
 		z = one - two/(t+two);
@@ -70,9 +69,9 @@
 	        t = expm1(-two*fabs(x));
 	        z= -t/(t+two);
 	    }
-    /* |x| > 22, return +-1 */
+    /* |x| >= 22, return +-1 */
 	} else {
-	    z = one - tiny;		/* raised inexact flag */
+	    z = one - tiny;		/* raise inexact flag */
 	}
 	return (jx>=0)? z: -z;
 }
diff --git a/libm/src/s_tanhf.c b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c
similarity index 91%
rename from libm/src/s_tanhf.c
rename to libm/upstream-freebsd/lib/msun/src/s_tanhf.c
index 0aca6cc..04f09c6 100644
--- a/libm/src/s_tanhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c
@@ -13,9 +13,8 @@
  * ====================================================
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_tanhf.c,v 1.8 2005/12/11 11:40:55 bde Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include "math.h"
 #include "math_private.h"
diff --git a/libm/upstream-freebsd/lib/msun/src/s_tanl.c b/libm/upstream-freebsd/lib/msun/src/s_tanl.c
new file mode 100644
index 0000000..eadc837
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanl.c
@@ -0,0 +1,95 @@
+/*-
+ * Copyright (c) 2007 Steven G. Kargl
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Limited testing on pseudorandom numbers drawn within [0:4e8] shows
+ * an accuracy of <= 1.5 ULP where 247024 values of x out of 40 million
+ * possibles resulted in tan(x) that exceeded 0.5 ULP (ie., 0.6%).
+ */
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "math.h"
+#include "math_private.h"
+#if LDBL_MANT_DIG == 64
+#include "../ld80/e_rem_pio2l.h"
+#elif LDBL_MANT_DIG == 113
+#include "../ld128/e_rem_pio2l.h"
+#else
+#error "Unsupported long double format"
+#endif
+
+long double
+tanl(long double x)
+{
+	union IEEEl2bits z;
+	int e0, s;
+	long double y[2];
+	long double hi, lo;
+
+	z.e = x;
+	s = z.bits.sign;
+	z.bits.sign = 0;
+
+	/* If x = +-0 or x is subnormal, then tan(x) = x. */
+	if (z.bits.exp == 0)
+		return (x);
+
+	/* If x = NaN or Inf, then tan(x) = NaN. */
+	if (z.bits.exp == 32767)
+		return ((x - x) / (x - x));
+
+	ENTERI();
+
+	/* Optimize the case where x is already within range. */
+	if (z.e < M_PI_4) {
+		hi = __kernel_tanl(z.e, 0, 0);
+		RETURNI(s ? -hi : hi);
+	}
+
+	e0 = __ieee754_rem_pio2l(x, y);
+	hi = y[0];
+	lo = y[1];
+
+	switch (e0 & 3) {
+	case 0:
+	case 2:
+	    hi = __kernel_tanl(hi, lo, 0);
+	    break;
+	case 1:
+	case 3:
+	    hi = __kernel_tanl(hi, lo, 1);
+	    break;
+	}
+
+	RETURNI(hi);
+}
diff --git a/libm/src/s_tgammaf.c b/libm/upstream-freebsd/lib/msun/src/s_tgammaf.c
similarity index 100%
rename from libm/src/s_tgammaf.c
rename to libm/upstream-freebsd/lib/msun/src/s_tgammaf.c
diff --git a/libm/src/s_trunc.c b/libm/upstream-freebsd/lib/msun/src/s_trunc.c
similarity index 91%
rename from libm/src/s_trunc.c
rename to libm/upstream-freebsd/lib/msun/src/s_trunc.c
index d5287eb..63a6753 100644
--- a/libm/src/s_trunc.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_trunc.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_trunc.c,v 1.1 2004/06/20 09:25:43 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 /*
  * trunc(x)
@@ -22,6 +22,8 @@
  *	Inexact flag raised if x not equal to trunc(x).
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -31,7 +33,7 @@
 trunc(double x)
 {
 	int32_t i0,i1,j0;
-	u_int32_t i,j;
+	u_int32_t i;
 	EXTRACT_WORDS(i0,i1,x);
 	j0 = ((i0>>20)&0x7ff)-0x3ff;
 	if(j0<20) {
@@ -59,3 +61,7 @@
 	INSERT_WORDS(x,i0,i1);
 	return x;
 }
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(trunc, truncl);
+#endif
diff --git a/libm/src/s_truncf.c b/libm/upstream-freebsd/lib/msun/src/s_truncf.c
similarity index 92%
rename from libm/src/s_truncf.c
rename to libm/upstream-freebsd/lib/msun/src/s_truncf.c
index 86b7247..384eaee 100644
--- a/libm/src/s_truncf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_truncf.c
@@ -11,7 +11,7 @@
  */
 
 #include <sys/cdefs.h>
-/* __FBSDID("$FreeBSD: src/lib/msun/src/s_truncf.c,v 1.1 2004/06/20 09:25:43 das Exp $"); */
+__FBSDID("$FreeBSD$");
 
 /*
  * truncf(x)
diff --git a/libm/src/s_truncl.c b/libm/upstream-freebsd/lib/msun/src/s_truncl.c
similarity index 91%
rename from libm/src/s_truncl.c
rename to libm/upstream-freebsd/lib/msun/src/s_truncl.c
index 39926a5..9e2b511 100644
--- a/libm/src/s_truncl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_truncl.c
@@ -11,9 +11,8 @@
  * From: @(#)s_floor.c 5.1 93/09/24
  */
 
-#ifndef lint
-static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_truncl.c,v 1.4 2005/04/28 19:45:55 stefanf Exp $";
-#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 /*
  * truncl(x)
@@ -37,6 +36,7 @@
 #endif
 
 static const long double huge = 1.0e300;
+static const float zero[] = { 0.0, -0.0 };
 
 long double
 truncl(long double x)
@@ -47,7 +47,7 @@
 	if (e < MANH_SIZE - 1) {
 		if (e < 0) {			/* raise inexact if x != 0 */
 			if (huge + x > 0.0)
-				u.e = 0.0;
+				u.e = zero[u.bits.sign];
 		} else {
 			uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
 			if (((u.bits.manh & m) | u.bits.manl) == 0)
diff --git a/libm/upstream-freebsd/lib/msun/src/w_cabs.c b/libm/upstream-freebsd/lib/msun/src/w_cabs.c
new file mode 100644
index 0000000..543b858
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/w_cabs.c
@@ -0,0 +1,23 @@
+/*
+ * cabs() wrapper for hypot().
+ *
+ * Written by J.T. Conklin, <jtc@wimsey.com>
+ * Placed into the Public Domain, 1994.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <float.h>
+#include <math.h>
+
+double
+cabs(double complex z)
+{
+	return hypot(creal(z), cimag(z));
+}
+
+#if LDBL_MANT_DIG == 53
+__weak_reference(cabs, cabsl);
+#endif
diff --git a/libm/src/w_cabsf.c b/libm/upstream-freebsd/lib/msun/src/w_cabsf.c
similarity index 81%
rename from libm/src/w_cabsf.c
rename to libm/upstream-freebsd/lib/msun/src/w_cabsf.c
index fac152f..e7bfe22 100644
--- a/libm/src/w_cabsf.c
+++ b/libm/upstream-freebsd/lib/msun/src/w_cabsf.c
@@ -7,7 +7,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-  "$FreeBSD: src/lib/msun/src/w_cabsf.c,v 1.3 2001/06/13 15:16:30 ru Exp $";
+  "$FreeBSD$";
 #endif /* not lint */
 
 #include <complex.h>
diff --git a/libm/upstream-freebsd/lib/msun/src/w_cabsl.c b/libm/upstream-freebsd/lib/msun/src/w_cabsl.c
new file mode 100644
index 0000000..b715e0c
--- /dev/null
+++ b/libm/upstream-freebsd/lib/msun/src/w_cabsl.c
@@ -0,0 +1,20 @@
+/*
+ * cabs() wrapper for hypot().
+ *
+ * Written by J.T. Conklin, <jtc@wimsey.com>
+ * Placed into the Public Domain, 1994.
+ *
+ * Modified by Steven G. Kargl for the long double type.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <complex.h>
+#include <math.h>
+
+long double
+cabsl(long double complex z)
+{
+	return hypotl(creall(z), cimagl(z));
+}
diff --git a/libm/src/w_drem.c b/libm/upstream-freebsd/lib/msun/src/w_drem.c
similarity index 100%
rename from libm/src/w_drem.c
rename to libm/upstream-freebsd/lib/msun/src/w_drem.c
diff --git a/libm/src/w_dremf.c b/libm/upstream-freebsd/lib/msun/src/w_dremf.c
similarity index 74%
rename from libm/src/w_dremf.c
rename to libm/upstream-freebsd/lib/msun/src/w_dremf.c
index e83ac0e..4bfcff2 100644
--- a/libm/src/w_dremf.c
+++ b/libm/upstream-freebsd/lib/msun/src/w_dremf.c
@@ -4,7 +4,7 @@
  * Written by J.T. Conklin, <jtc@wimsey.com>
  * Placed into the Public Domain, 1994.
  */
-/* $FreeBSD: src/lib/msun/src/w_dremf.c,v 1.3 2004/07/28 05:53:18 kan Exp $ */
+/* $FreeBSD$ */
 
 #include "math.h"
 #include "math_private.h"
diff --git a/tests/Android.mk b/tests/Android.mk
index 0685d4a..ed1df6e 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -51,6 +51,7 @@
     -g \
     -Wall -Wextra \
     -Werror \
+    -fno-builtin \
 
 test_src_files = \
     debug_format_test.cpp \
@@ -59,6 +60,7 @@
     getauxval_test.cpp \
     getcwd_test.cpp \
     libgen_test.cpp \
+    math_test.cpp \
     pthread_test.cpp \
     regex_test.cpp \
     signal_test.cpp \
diff --git a/tests/fenv_test.cpp b/tests/fenv_test.cpp
index 4adb066..db1bfc3 100644
--- a/tests/fenv_test.cpp
+++ b/tests/fenv_test.cpp
@@ -79,3 +79,7 @@
   feclearexcept(FE_DIVBYZERO);
   ASSERT_EQ(0, fetestexcept(FE_ALL_EXCEPT));
 }
+
+TEST(fenv, FE_DFL_ENV_macro) {
+  ASSERT_EQ(0, fesetenv(FE_DFL_ENV));
+}
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
new file mode 100644
index 0000000..8e0abdb
--- /dev/null
+++ b/tests/math_test.cpp
@@ -0,0 +1,1176 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _DECLARE_C99_LDBL_MATH 1
+
+#include <gtest/gtest.h>
+
+#include <fenv.h>
+#include <limits.h>
+#include <math.h>
+#include <stdint.h>
+
+float float_subnormal() {
+  union {
+    float f;
+    uint32_t i;
+  } u;
+  u.i = 0x007fffff;
+  return u.f;
+}
+
+double double_subnormal() {
+  union {
+    double d;
+    uint64_t i;
+  } u;
+  u.i = 0x000fffffffffffffL;
+  return u.d;
+}
+
+TEST(math, fpclassify) {
+  ASSERT_EQ(FP_INFINITE, fpclassify(INFINITY));
+  ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VALF));
+  ASSERT_EQ(FP_INFINITE, fpclassify(HUGE_VAL));
+
+  ASSERT_EQ(FP_NAN, fpclassify(nanf("")));
+  ASSERT_EQ(FP_NAN, fpclassify(nan("")));
+
+  ASSERT_EQ(FP_NORMAL, fpclassify(1.0f));
+  ASSERT_EQ(FP_NORMAL, fpclassify(1.0));
+
+  ASSERT_EQ(FP_SUBNORMAL, fpclassify(float_subnormal()));
+  ASSERT_EQ(FP_SUBNORMAL, fpclassify(double_subnormal()));
+
+  ASSERT_EQ(FP_ZERO, fpclassify(0.0f));
+  ASSERT_EQ(FP_ZERO, fpclassify(0.0));
+}
+
+/* TODO: stlport breaks the isfinite macro
+TEST(math, isfinite) {
+  ASSERT_TRUE(isfinite(123.0f));
+  ASSERT_TRUE(isfinite(123.0));
+  ASSERT_FALSE(isfinite(HUGE_VALF));
+  ASSERT_FALSE(isfinite(HUGE_VAL));
+}
+*/
+
+TEST(math, isinf) {
+  ASSERT_FALSE(isinf(123.0f));
+  ASSERT_FALSE(isinf(123.0));
+  ASSERT_TRUE(isinf(HUGE_VALF));
+  ASSERT_TRUE(isinf(HUGE_VAL));
+}
+
+TEST(math, isnan) {
+  ASSERT_FALSE(isnan(123.0f));
+  ASSERT_FALSE(isnan(123.0));
+  ASSERT_TRUE(isnan(nanf("")));
+  ASSERT_TRUE(isnan(nan("")));
+}
+
+TEST(math, isnormal) {
+  ASSERT_TRUE(isnormal(123.0f));
+  ASSERT_TRUE(isnormal(123.0));
+  ASSERT_FALSE(isnormal(float_subnormal()));
+  ASSERT_FALSE(isnormal(double_subnormal()));
+}
+
+// TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered
+
+/* TODO: stlport breaks the signbit macro
+TEST(math, signbit) {
+  ASSERT_EQ(0, signbit(0.0f));
+  ASSERT_EQ(0, signbit(0.0));
+
+  ASSERT_EQ(0, signbit(1.0f));
+  ASSERT_EQ(0, signbit(1.0));
+
+  ASSERT_NE(0, signbit(-1.0f));
+  ASSERT_NE(0, signbit(-1.0));
+}
+*/
+
+#if defined(__BIONIC__)
+TEST(math, __fpclassifyd) {
+  ASSERT_EQ(FP_INFINITE, __fpclassifyd(HUGE_VAL));
+  ASSERT_EQ(FP_NAN, __fpclassifyd(nan("")));
+  ASSERT_EQ(FP_NORMAL, __fpclassifyd(1.0));
+  ASSERT_EQ(FP_SUBNORMAL, __fpclassifyd(double_subnormal()));
+  ASSERT_EQ(FP_ZERO, __fpclassifyd(0.0));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __fpclassifyf) {
+  ASSERT_EQ(FP_INFINITE, __fpclassifyf(HUGE_VALF));
+  ASSERT_EQ(FP_NAN, __fpclassifyf(nanf("")));
+  ASSERT_EQ(FP_NORMAL, __fpclassifyf(1.0f));
+  ASSERT_EQ(FP_SUBNORMAL, __fpclassifyf(float_subnormal()));
+  ASSERT_EQ(FP_ZERO, __fpclassifyf(0.0f));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __fpclassifyl) {
+  EXPECT_EQ(FP_INFINITE, __fpclassifyl(HUGE_VALL));
+  EXPECT_EQ(FP_NAN, __fpclassifyl(nanl("")));
+  EXPECT_EQ(FP_NORMAL, __fpclassifyl(1.0));
+  EXPECT_EQ(FP_SUBNORMAL, __fpclassifyl(double_subnormal()));
+  EXPECT_EQ(FP_ZERO, __fpclassifyl(0.0));
+}
+#endif
+
+TEST(math, finitef) {
+  ASSERT_TRUE(finitef(123.0f));
+  ASSERT_FALSE(finitef(HUGE_VALF));
+}
+
+#if defined(__BIONIC__)
+TEST(math, __isfinite) {
+  ASSERT_TRUE(__isfinite(123.0));
+  ASSERT_FALSE(__isfinite(HUGE_VAL));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __isfinitef) {
+  ASSERT_TRUE(__isfinitef(123.0f));
+  ASSERT_FALSE(__isfinitef(HUGE_VALF));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __isfinitel) {
+  ASSERT_TRUE(__isfinitel(123.0f));
+  ASSERT_FALSE(__isfinitel(HUGE_VALL));
+}
+#endif
+
+TEST(math, finite) {
+  ASSERT_TRUE(finite(123.0));
+  ASSERT_FALSE(finite(HUGE_VAL));
+}
+
+TEST(math, __isinff) {
+  ASSERT_FALSE(__isinff(123.0f));
+  ASSERT_TRUE(__isinff(HUGE_VALF));
+}
+
+TEST(math, __isinfl) {
+  ASSERT_FALSE(__isinfl(123.0));
+  ASSERT_TRUE(__isinfl(HUGE_VALL));
+}
+
+TEST(math, __isnanf) {
+  ASSERT_FALSE(__isnanf(123.0f));
+  ASSERT_TRUE(__isnanf(nanf("")));
+}
+
+TEST(math, __isnanl) {
+  ASSERT_FALSE(__isnanl(123.0));
+  ASSERT_TRUE(__isnanl(nanl("")));
+}
+
+TEST(math, isnanf) {
+  ASSERT_FALSE(isnanf(123.0f));
+  ASSERT_TRUE(isnanf(nanf("")));
+}
+
+#if defined(__BIONIC__)
+TEST(math, __isnormal) {
+  ASSERT_TRUE(__isnormal(123.0));
+  ASSERT_FALSE(__isnormal(double_subnormal()));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __isnormalf) {
+  ASSERT_TRUE(__isnormalf(123.0f));
+  ASSERT_FALSE(__isnormalf(float_subnormal()));
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, __isnormall) {
+  ASSERT_TRUE(__isnormall(123.0));
+  ASSERT_FALSE(__isnormall(double_subnormal()));
+}
+#endif
+
+TEST(math, __signbit) {
+  ASSERT_EQ(0, __signbit(0.0));
+  ASSERT_EQ(0, __signbit(1.0));
+  ASSERT_NE(0, __signbit(-1.0));
+}
+
+TEST(math, __signbitf) {
+  ASSERT_EQ(0, __signbitf(0.0f));
+  ASSERT_EQ(0, __signbitf(1.0f));
+  ASSERT_NE(0, __signbitf(-1.0f));
+}
+
+TEST(math, __signbitl) {
+  ASSERT_EQ(0, __signbitl(0.0));
+  ASSERT_EQ(0, __signbitl(1.0));
+  ASSERT_NE(0, __signbitl(-1.0));
+}
+
+TEST(math, acos) {
+  ASSERT_FLOAT_EQ(M_PI/2.0, acos(0.0));
+}
+
+TEST(math, acosf) {
+  ASSERT_FLOAT_EQ(static_cast<float>(M_PI)/2.0f, acosf(0.0f));
+}
+
+TEST(math, acosl) {
+  ASSERT_FLOAT_EQ(M_PI/2.0, acosl(0.0));
+}
+
+TEST(math, asin) {
+  ASSERT_FLOAT_EQ(0.0, asin(0.0));
+}
+
+TEST(math, asinf) {
+  ASSERT_FLOAT_EQ(0.0f, asinf(0.0f));
+}
+
+TEST(math, asinl) {
+  ASSERT_FLOAT_EQ(0.0, asinl(0.0));
+}
+
+TEST(math, atan) {
+  ASSERT_FLOAT_EQ(0.0, atan(0.0));
+}
+
+TEST(math, atanf) {
+  ASSERT_FLOAT_EQ(0.0f, atanf(0.0f));
+}
+
+TEST(math, atanl) {
+  ASSERT_FLOAT_EQ(0.0, atanl(0.0));
+}
+
+TEST(math, atan2) {
+  ASSERT_FLOAT_EQ(0.0, atan2(0.0, 0.0));
+}
+
+TEST(math, atan2f) {
+  ASSERT_FLOAT_EQ(0.0f, atan2f(0.0f, 0.0f));
+}
+
+TEST(math, atan2l) {
+  ASSERT_FLOAT_EQ(0.0, atan2l(0.0, 0.0));
+}
+
+TEST(math, cos) {
+  ASSERT_FLOAT_EQ(1.0, cos(0.0));
+}
+
+TEST(math, cosf) {
+  ASSERT_FLOAT_EQ(1.0f, cosf(0.0f));
+}
+
+TEST(math, cosl) {
+  ASSERT_FLOAT_EQ(1.0, cosl(0.0));
+}
+
+TEST(math, sin) {
+  ASSERT_FLOAT_EQ(0.0, sin(0.0));
+}
+
+TEST(math, sinf) {
+  ASSERT_FLOAT_EQ(0.0f, sinf(0.0f));
+}
+
+TEST(math, sinl) {
+  ASSERT_FLOAT_EQ(0.0, sinl(0.0));
+}
+
+TEST(math, tan) {
+  ASSERT_FLOAT_EQ(0.0, tan(0.0));
+}
+
+TEST(math, tanf) {
+  ASSERT_FLOAT_EQ(0.0f, tanf(0.0f));
+}
+
+TEST(math, tanl) {
+  ASSERT_FLOAT_EQ(0.0, tanl(0.0));
+}
+
+TEST(math, acosh) {
+  ASSERT_FLOAT_EQ(0.0, acosh(1.0));
+}
+
+TEST(math, acoshf) {
+  ASSERT_FLOAT_EQ(0.0f, acoshf(1.0f));
+}
+
+TEST(math, acoshl) {
+  ASSERT_FLOAT_EQ(0.0, acoshl(1.0));
+}
+
+TEST(math, asinh) {
+  ASSERT_FLOAT_EQ(0.0, asinh(0.0));
+}
+
+TEST(math, asinhf) {
+  ASSERT_FLOAT_EQ(0.0f, asinhf(0.0f));
+}
+
+TEST(math, asinhl) {
+  ASSERT_FLOAT_EQ(0.0, asinhl(0.0));
+}
+
+TEST(math, atanh) {
+  ASSERT_FLOAT_EQ(0.0, atanh(0.0));
+}
+
+TEST(math, atanhf) {
+  ASSERT_FLOAT_EQ(0.0f, atanhf(0.0f));
+}
+
+TEST(math, atanhl) {
+  ASSERT_FLOAT_EQ(0.0, atanhl(0.0));
+}
+
+TEST(math, cosh) {
+  ASSERT_FLOAT_EQ(1.0, cosh(0.0));
+}
+
+TEST(math, coshf) {
+  ASSERT_FLOAT_EQ(1.0f, coshf(0.0f));
+}
+
+TEST(math, coshl) {
+  ASSERT_FLOAT_EQ(1.0, coshl(0.0));
+}
+
+TEST(math, sinh) {
+  ASSERT_FLOAT_EQ(0.0, sinh(0.0));
+}
+
+TEST(math, sinhf) {
+  ASSERT_FLOAT_EQ(0.0f, sinhf(0.0f));
+}
+
+TEST(math, sinhl) {
+  ASSERT_FLOAT_EQ(0.0, sinhl(0.0));
+}
+
+TEST(math, tanh) {
+  ASSERT_FLOAT_EQ(0.0, tanh(0.0));
+}
+
+TEST(math, tanhf) {
+  ASSERT_FLOAT_EQ(0.0f, tanhf(0.0f));
+}
+
+TEST(math, tanhl) {
+  ASSERT_FLOAT_EQ(0.0, tanhl(0.0));
+}
+
+TEST(math, log) {
+  ASSERT_FLOAT_EQ(1.0, log(M_E));
+}
+
+TEST(math, logf) {
+  ASSERT_FLOAT_EQ(1.0f, logf(static_cast<float>(M_E)));
+}
+
+TEST(math, logl) {
+  ASSERT_FLOAT_EQ(1.0, logl(M_E));
+}
+
+TEST(math, log2) {
+  ASSERT_FLOAT_EQ(12.0, log2(4096.0));
+}
+
+TEST(math, log2f) {
+  ASSERT_FLOAT_EQ(12.0f, log2f(4096.0f));
+}
+
+TEST(math, log2l) {
+  ASSERT_FLOAT_EQ(12.0, log2l(4096.0));
+}
+
+TEST(math, log10) {
+  ASSERT_FLOAT_EQ(3.0, log10(1000.0));
+}
+
+TEST(math, log10f) {
+  ASSERT_FLOAT_EQ(3.0f, log10f(1000.0f));
+}
+
+TEST(math, log10l) {
+  ASSERT_FLOAT_EQ(3.0, log10l(1000.0));
+}
+
+TEST(math, cbrt) {
+  ASSERT_FLOAT_EQ(3.0, cbrt(27.0));
+}
+
+TEST(math, cbrtf) {
+  ASSERT_FLOAT_EQ(3.0f, cbrtf(27.0f));
+}
+
+TEST(math, cbrtl) {
+  ASSERT_FLOAT_EQ(3.0, cbrtl(27.0));
+}
+
+TEST(math, sqrt) {
+  ASSERT_FLOAT_EQ(2.0, sqrt(4.0));
+}
+
+TEST(math, sqrtf) {
+  ASSERT_FLOAT_EQ(2.0f, sqrtf(4.0f));
+}
+
+TEST(math, sqrtl) {
+  ASSERT_FLOAT_EQ(2.0, sqrtl(4.0));
+}
+
+TEST(math, exp) {
+  ASSERT_FLOAT_EQ(1.0, exp(0.0));
+  ASSERT_FLOAT_EQ(M_E, exp(1.0));
+}
+
+TEST(math, expf) {
+  ASSERT_FLOAT_EQ(1.0f, expf(0.0f));
+  ASSERT_FLOAT_EQ(static_cast<float>(M_E), expf(1.0f));
+}
+
+TEST(math, expl) {
+  ASSERT_FLOAT_EQ(1.0, expl(0.0));
+  ASSERT_FLOAT_EQ(M_E, expl(1.0));
+}
+
+TEST(math, exp2) {
+  ASSERT_FLOAT_EQ(8.0, exp2(3.0));
+}
+
+TEST(math, exp2f) {
+  ASSERT_FLOAT_EQ(8.0f, exp2f(3.0f));
+}
+
+TEST(math, exp2l) {
+  ASSERT_FLOAT_EQ(8.0, exp2l(3.0));
+}
+
+TEST(math, expm1) {
+  ASSERT_FLOAT_EQ(M_E - 1.0, expm1(1.0));
+}
+
+TEST(math, expm1f) {
+  ASSERT_FLOAT_EQ(static_cast<float>(M_E) - 1.0f, expm1f(1.0f));
+}
+
+TEST(math, expm1l) {
+  ASSERT_FLOAT_EQ(M_E - 1.0, expm1l(1.0));
+}
+
+TEST(math, pow) {
+  ASSERT_FLOAT_EQ(8.0, pow(2.0, 3.0));
+}
+
+TEST(math, powf) {
+  ASSERT_FLOAT_EQ(8.0f, powf(2.0f, 3.0f));
+}
+
+TEST(math, powl) {
+  ASSERT_FLOAT_EQ(8.0, powl(2.0, 3.0));
+}
+
+TEST(math, ceil) {
+  ASSERT_FLOAT_EQ(1.0, ceil(0.9));
+}
+
+TEST(math, ceilf) {
+  ASSERT_FLOAT_EQ(1.0f, ceilf(0.9f));
+}
+
+TEST(math, ceill) {
+  ASSERT_FLOAT_EQ(1.0, ceill(0.9));
+}
+
+TEST(math, floor) {
+  ASSERT_FLOAT_EQ(1.0, floor(1.1));
+}
+
+TEST(math, floorf) {
+  ASSERT_FLOAT_EQ(1.0f, floorf(1.1f));
+}
+
+TEST(math, floorl) {
+  ASSERT_FLOAT_EQ(1.0, floorl(1.1));
+}
+
+TEST(math, fabs) {
+  ASSERT_FLOAT_EQ(1.0, fabs(-1.0));
+}
+
+TEST(math, fabsf) {
+  ASSERT_FLOAT_EQ(1.0f, fabsf(-1.0f));
+}
+
+TEST(math, fabsl) {
+  ASSERT_FLOAT_EQ(1.0, fabsl(-1.0));
+}
+
+TEST(math, ldexp) {
+  ASSERT_FLOAT_EQ(16.0, ldexp(2.0, 3.0));
+}
+
+TEST(math, ldexpf) {
+  ASSERT_FLOAT_EQ(16.0f, ldexpf(2.0f, 3.0f));
+}
+
+TEST(math, ldexpl) {
+  ASSERT_FLOAT_EQ(16.0, ldexpl(2.0, 3.0));
+}
+
+TEST(math, fmod) {
+  ASSERT_FLOAT_EQ(2.0, fmod(12.0, 10.0));
+}
+
+TEST(math, fmodf) {
+  ASSERT_FLOAT_EQ(2.0f, fmodf(12.0f, 10.0f));
+}
+
+TEST(math, fmodl) {
+  ASSERT_FLOAT_EQ(2.0, fmodl(12.0, 10.0));
+}
+
+TEST(math, remainder) {
+  ASSERT_FLOAT_EQ(2.0, remainder(12.0, 10.0));
+}
+
+TEST(math, remainderf) {
+  ASSERT_FLOAT_EQ(2.0f, remainderf(12.0f, 10.0f));
+}
+
+TEST(math, remainderl) {
+  ASSERT_FLOAT_EQ(2.0, remainderl(12.0, 10.0));
+}
+
+TEST(math, drem) {
+  ASSERT_FLOAT_EQ(2.0, drem(12.0, 10.0));
+}
+
+TEST(math, dremf) {
+  ASSERT_FLOAT_EQ(2.0f, dremf(12.0f, 10.0f));
+}
+
+TEST(math, fmax) {
+  ASSERT_FLOAT_EQ(12.0, fmax(12.0, 10.0));
+  ASSERT_FLOAT_EQ(12.0, fmax(12.0, nan("")));
+  ASSERT_FLOAT_EQ(12.0, fmax(nan(""), 12.0));
+}
+
+TEST(math, fmaxf) {
+  ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, 10.0f));
+  ASSERT_FLOAT_EQ(12.0f, fmaxf(12.0f, nanf("")));
+  ASSERT_FLOAT_EQ(12.0f, fmaxf(nanf(""), 12.0f));
+}
+
+TEST(math, fmaxl) {
+  ASSERT_FLOAT_EQ(12.0, fmaxl(12.0, 10.0));
+  ASSERT_FLOAT_EQ(12.0, fmaxl(12.0, nanl("")));
+  ASSERT_FLOAT_EQ(12.0, fmaxl(nanl(""), 12.0));
+}
+
+TEST(math, fmin) {
+  ASSERT_FLOAT_EQ(10.0, fmin(12.0, 10.0));
+  ASSERT_FLOAT_EQ(12.0, fmin(12.0, nan("")));
+  ASSERT_FLOAT_EQ(12.0, fmin(nan(""), 12.0));
+}
+
+TEST(math, fminf) {
+  ASSERT_FLOAT_EQ(10.0f, fminf(12.0f, 10.0f));
+  ASSERT_FLOAT_EQ(12.0f, fminf(12.0f, nanf("")));
+  ASSERT_FLOAT_EQ(12.0f, fminf(nanf(""), 12.0f));
+}
+
+TEST(math, fminl) {
+  ASSERT_FLOAT_EQ(10.0, fminl(12.0, 10.0));
+  ASSERT_FLOAT_EQ(12.0, fminl(12.0, nan("")));
+  ASSERT_FLOAT_EQ(12.0, fminl(nan(""), 12.0));
+}
+
+TEST(math, fma) {
+  ASSERT_FLOAT_EQ(10.0, fma(2.0, 3.0, 4.0));
+}
+
+TEST(math, fmaf) {
+  ASSERT_FLOAT_EQ(10.0f, fmaf(2.0f, 3.0f, 4.0f));
+}
+
+TEST(math, fmal) {
+  ASSERT_FLOAT_EQ(10.0, fmal(2.0, 3.0, 4.0));
+}
+
+TEST(math, hypot) {
+  ASSERT_FLOAT_EQ(5.0, hypot(3.0, 4.0));
+}
+
+TEST(math, hypotf) {
+  ASSERT_FLOAT_EQ(5.0f, hypotf(3.0f, 4.0f));
+}
+
+TEST(math, hypotl) {
+  ASSERT_FLOAT_EQ(5.0, hypotl(3.0, 4.0));
+}
+
+TEST(math, erf) {
+  ASSERT_FLOAT_EQ(0.84270078, erf(1.0));
+}
+
+TEST(math, erff) {
+  ASSERT_FLOAT_EQ(0.84270078f, erff(1.0f));
+}
+
+TEST(math, erfl) {
+  ASSERT_FLOAT_EQ(0.84270078, erfl(1.0));
+}
+
+TEST(math, erfc) {
+  ASSERT_FLOAT_EQ(0.15729921, erfc(1.0));
+}
+
+TEST(math, erfcf) {
+  ASSERT_FLOAT_EQ(0.15729921f, erfcf(1.0f));
+}
+
+TEST(math, erfcl) {
+  ASSERT_FLOAT_EQ(0.15729921, erfcl(1.0));
+}
+
+TEST(math, lrint) {
+  fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
+  ASSERT_EQ(1235, lrint(1234.01));
+  ASSERT_EQ(1235, lrintf(1234.01f));
+  ASSERT_EQ(1235, lrintl(1234.01));
+  fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
+  ASSERT_EQ(1234, lrint(1234.01));
+  ASSERT_EQ(1234, lrintf(1234.01f));
+  ASSERT_EQ(1234, lrintl(1234.01));
+
+  fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
+  ASSERT_EQ(1235L, llrint(1234.01));
+  ASSERT_EQ(1235L, llrintf(1234.01f));
+  ASSERT_EQ(1235L, llrintl(1234.01));
+  fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
+  ASSERT_EQ(1234L, llrint(1234.01));
+  ASSERT_EQ(1234L, llrintf(1234.01f));
+  ASSERT_EQ(1234L, llrintl(1234.01));
+}
+
+TEST(math, rint) {
+  fesetround(FE_UPWARD); // rint/rintf/rintl obey the rounding mode.
+  feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+  ASSERT_EQ(1234.0, rint(1234.0));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0, rint(1234.01));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
+
+  feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+  ASSERT_EQ(1234.0f, rintf(1234.0f));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0f, rintf(1234.01f));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
+
+  feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+  ASSERT_EQ(1234.0, rintl(1234.0));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0, rintl(1234.01));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) != 0);
+
+  fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
+  ASSERT_EQ(1234.0, rint(1234.01));
+  ASSERT_EQ(1234.0f, rintf(1234.01f));
+  ASSERT_EQ(1234.0, rintl(1234.01));
+}
+
+TEST(math, nearbyint) {
+  fesetround(FE_UPWARD); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
+  feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
+  ASSERT_EQ(1234.0, nearbyint(1234.0));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0, nearbyint(1234.01));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+
+  feclearexcept(FE_ALL_EXCEPT);
+  ASSERT_EQ(1234.0f, nearbyintf(1234.0f));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0f, nearbyintf(1234.01f));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+
+  feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
+  ASSERT_EQ(1234.0, nearbyintl(1234.0));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+  ASSERT_EQ(1235.0, nearbyintl(1234.01));
+  ASSERT_TRUE((fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT) == 0);
+
+  fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
+  ASSERT_EQ(1234.0, nearbyint(1234.01));
+  ASSERT_EQ(1234.0f, nearbyintf(1234.01f));
+  ASSERT_EQ(1234.0, nearbyintl(1234.01));
+}
+
+TEST(math, lround) {
+  fesetround(FE_UPWARD); // lround ignores the rounding mode.
+  ASSERT_EQ(1234, lround(1234.01));
+  ASSERT_EQ(1234, lroundf(1234.01f));
+  ASSERT_EQ(1234, lroundl(1234.01));
+}
+
+TEST(math, llround) {
+  fesetround(FE_UPWARD); // llround ignores the rounding mode.
+  ASSERT_EQ(1234L, llround(1234.01));
+  ASSERT_EQ(1234L, llroundf(1234.01f));
+  ASSERT_EQ(1234L, llroundl(1234.01));
+}
+
+TEST(math, ilogb) {
+  ASSERT_EQ(FP_ILOGB0, ilogb(0.0));
+  ASSERT_EQ(FP_ILOGBNAN, ilogb(nan("")));
+  ASSERT_EQ(INT_MAX, ilogb(HUGE_VAL));
+  ASSERT_EQ(0, ilogb(1.0));
+  ASSERT_EQ(3, ilogb(10.0));
+}
+
+TEST(math, ilogbf) {
+  ASSERT_EQ(FP_ILOGB0, ilogbf(0.0f));
+  ASSERT_EQ(FP_ILOGBNAN, ilogbf(nanf("")));
+  ASSERT_EQ(INT_MAX, ilogbf(HUGE_VALF));
+  ASSERT_EQ(0, ilogbf(1.0f));
+  ASSERT_EQ(3, ilogbf(10.0f));
+}
+
+TEST(math, ilogbl) {
+  ASSERT_EQ(FP_ILOGB0, ilogbl(0.0));
+  ASSERT_EQ(FP_ILOGBNAN, ilogbl(nanl("")));
+  ASSERT_EQ(INT_MAX, ilogbl(HUGE_VALL));
+  ASSERT_EQ(0, ilogbl(1.0));
+  ASSERT_EQ(3, ilogbl(10.0));
+}
+
+TEST(math, logb) {
+  ASSERT_EQ(-HUGE_VAL, logb(0.0));
+  ASSERT_TRUE(isnan(logb(nan(""))));
+  ASSERT_TRUE(isinf(logb(HUGE_VAL)));
+  ASSERT_EQ(0.0, logb(1.0));
+  ASSERT_EQ(3.0, logb(10.0));
+}
+
+TEST(math, logbf) {
+  ASSERT_EQ(-HUGE_VALF, logbf(0.0f));
+  ASSERT_TRUE(isnanf(logbf(nanf(""))));
+  ASSERT_TRUE(__isinff(logbf(HUGE_VALF)));
+  ASSERT_EQ(0.0f, logbf(1.0f));
+  ASSERT_EQ(3.0f, logbf(10.0f));
+}
+
+TEST(math, logbl) {
+  ASSERT_EQ(-HUGE_VAL, logbl(0.0));
+  ASSERT_TRUE(isnan(logbl(nanl(""))));
+  ASSERT_TRUE(isinf(logbl(HUGE_VALL)));
+  ASSERT_EQ(0.0, logbl(1.0));
+  ASSERT_EQ(3.0, logbl(10.0));
+}
+
+TEST(math, log1p) {
+  ASSERT_EQ(-HUGE_VAL, log1p(-1.0));
+  ASSERT_TRUE(isnan(log1p(nan(""))));
+  ASSERT_TRUE(isinf(log1p(HUGE_VAL)));
+  ASSERT_FLOAT_EQ(1.0, log1p(M_E - 1.0));
+}
+
+TEST(math, log1pf) {
+  ASSERT_EQ(-HUGE_VALF, log1pf(-1.0f));
+  ASSERT_TRUE(isnanf(log1pf(nanf(""))));
+  ASSERT_TRUE(__isinff(log1pf(HUGE_VALF)));
+  ASSERT_FLOAT_EQ(1.0f, log1pf(static_cast<float>(M_E) - 1.0f));
+}
+
+TEST(math, log1pl) {
+  ASSERT_EQ(-HUGE_VALL, log1pl(-1.0));
+  ASSERT_TRUE(isnan(log1pl(nanl(""))));
+  ASSERT_TRUE(isinf(log1pl(HUGE_VALL)));
+  ASSERT_FLOAT_EQ(1.0, log1pl(M_E - 1.0));
+}
+
+TEST(math, fdim) {
+  ASSERT_FLOAT_EQ(0.0, fdim(1.0, 1.0));
+  ASSERT_FLOAT_EQ(1.0, fdim(2.0, 1.0));
+  ASSERT_FLOAT_EQ(0.0, fdim(1.0, 2.0));
+}
+
+TEST(math, fdimf) {
+  ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 1.0f));
+  ASSERT_FLOAT_EQ(1.0f, fdimf(2.0f, 1.0f));
+  ASSERT_FLOAT_EQ(0.0f, fdimf(1.0f, 2.0f));
+}
+
+TEST(math, fdiml) {
+  ASSERT_FLOAT_EQ(0.0, fdiml(1.0, 1.0));
+  ASSERT_FLOAT_EQ(1.0, fdiml(2.0, 1.0));
+  ASSERT_FLOAT_EQ(0.0, fdiml(1.0, 2.0));
+}
+
+TEST(math, round) {
+  fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
+  ASSERT_FLOAT_EQ(1.0, round(0.5));
+  ASSERT_FLOAT_EQ(-1.0, round(-0.5));
+  ASSERT_FLOAT_EQ(0.0, round(0.0));
+  ASSERT_FLOAT_EQ(-0.0, round(-0.0));
+  ASSERT_TRUE(isnan(round(nan(""))));
+  ASSERT_FLOAT_EQ(HUGE_VAL, round(HUGE_VAL));
+}
+
+TEST(math, roundf) {
+  fesetround(FE_TOWARDZERO); // roundf ignores the rounding mode and always rounds away from zero.
+  ASSERT_FLOAT_EQ(1.0f, roundf(0.5f));
+  ASSERT_FLOAT_EQ(-1.0f, roundf(-0.5f));
+  ASSERT_FLOAT_EQ(0.0f, roundf(0.0f));
+  ASSERT_FLOAT_EQ(-0.0f, roundf(-0.0f));
+  ASSERT_TRUE(isnanf(roundf(nanf(""))));
+  ASSERT_FLOAT_EQ(HUGE_VALF, roundf(HUGE_VALF));
+}
+
+TEST(math, roundl) {
+  fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
+  ASSERT_FLOAT_EQ(1.0, roundl(0.5));
+  ASSERT_FLOAT_EQ(-1.0, roundl(-0.5));
+  ASSERT_FLOAT_EQ(0.0, roundl(0.0));
+  ASSERT_FLOAT_EQ(-0.0, roundl(-0.0));
+  ASSERT_TRUE(isnan(roundl(nanl(""))));
+  ASSERT_FLOAT_EQ(HUGE_VALL, roundl(HUGE_VALL));
+}
+
+TEST(math, trunc) {
+  fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
+  ASSERT_FLOAT_EQ(1.0, trunc(1.5));
+  ASSERT_FLOAT_EQ(-1.0, trunc(-1.5));
+  ASSERT_FLOAT_EQ(0.0, trunc(0.0));
+  ASSERT_FLOAT_EQ(-0.0, trunc(-0.0));
+  ASSERT_TRUE(isnan(trunc(nan(""))));
+  ASSERT_FLOAT_EQ(HUGE_VAL, trunc(HUGE_VAL));
+}
+
+TEST(math, truncf) {
+  fesetround(FE_UPWARD); // truncf ignores the rounding mode and always rounds toward zero.
+  ASSERT_FLOAT_EQ(1.0f, truncf(1.5f));
+  ASSERT_FLOAT_EQ(-1.0f, truncf(-1.5f));
+  ASSERT_FLOAT_EQ(0.0f, truncf(0.0f));
+  ASSERT_FLOAT_EQ(-0.0f, truncf(-0.0f));
+  ASSERT_TRUE(isnan(truncf(nanf(""))));
+  ASSERT_FLOAT_EQ(HUGE_VALF, truncf(HUGE_VALF));
+}
+
+TEST(math, truncl) {
+  fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
+  ASSERT_FLOAT_EQ(1.0, truncl(1.5));
+  ASSERT_FLOAT_EQ(-1.0, truncl(-1.5));
+  ASSERT_FLOAT_EQ(0.0, truncl(0.0));
+  ASSERT_FLOAT_EQ(-0.0, truncl(-0.0));
+  ASSERT_TRUE(isnan(truncl(nan(""))));
+  ASSERT_FLOAT_EQ(HUGE_VALL, truncl(HUGE_VALL));
+}
+
+TEST(math, nextafter) {
+  ASSERT_FLOAT_EQ(0.0, nextafter(0.0, 0.0));
+  ASSERT_FLOAT_EQ(1.4012985e-45, nextafter(0.0, 1.0));
+  ASSERT_FLOAT_EQ(0.0, nextafter(0.0, -1.0));
+}
+
+TEST(math, nextafterf) {
+  ASSERT_FLOAT_EQ(0.0f, nextafterf(0.0f, 0.0f));
+  ASSERT_FLOAT_EQ(1.4012985e-45f, nextafterf(0.0f, 1.0f));
+  ASSERT_FLOAT_EQ(0.0f, nextafterf(0.0f, -1.0f));
+}
+
+TEST(math, nextafterl) {
+  ASSERT_FLOAT_EQ(0.0, nextafterl(0.0, 0.0));
+  ASSERT_FLOAT_EQ(1.4012985e-45, nextafterl(0.0, 1.0));
+  ASSERT_FLOAT_EQ(0.0, nextafterl(0.0, -1.0));
+}
+
+// TODO: nexttoward
+// TODO: nexttowardf
+// TODO: nexttowardl
+
+TEST(math, copysign) {
+  ASSERT_FLOAT_EQ(0.0, copysign(0.0, 1.0));
+  ASSERT_FLOAT_EQ(-0.0, copysign(0.0, -1.0));
+  ASSERT_FLOAT_EQ(2.0, copysign(2.0, 1.0));
+  ASSERT_FLOAT_EQ(-2.0, copysign(2.0, -1.0));
+}
+
+TEST(math, copysignf) {
+  ASSERT_FLOAT_EQ(0.0f, copysignf(0.0f, 1.0f));
+  ASSERT_FLOAT_EQ(-0.0f, copysignf(0.0f, -1.0f));
+  ASSERT_FLOAT_EQ(2.0f, copysignf(2.0f, 1.0f));
+  ASSERT_FLOAT_EQ(-2.0f, copysignf(2.0f, -1.0f));
+}
+
+TEST(math, copysignl) {
+  ASSERT_FLOAT_EQ(0.0f, copysignl(0.0, 1.0));
+  ASSERT_FLOAT_EQ(-0.0f, copysignl(0.0, -1.0));
+  ASSERT_FLOAT_EQ(2.0f, copysignl(2.0, 1.0));
+  ASSERT_FLOAT_EQ(-2.0f, copysignl(2.0, -1.0));
+}
+
+TEST(math, significand) {
+  ASSERT_FLOAT_EQ(0.0, significand(0.0));
+  ASSERT_FLOAT_EQ(1.2, significand(1.2));
+  ASSERT_FLOAT_EQ(1.5375, significand(12.3));
+}
+
+TEST(math, significandf) {
+  ASSERT_FLOAT_EQ(0.0f, significandf(0.0f));
+  ASSERT_FLOAT_EQ(1.2f, significandf(1.2f));
+  ASSERT_FLOAT_EQ(1.5375f, significandf(12.3f));
+}
+
+extern "C" long double significandl(long double); // BSD's <math.h> doesn't declare this.
+
+TEST(math, significandl) {
+  ASSERT_FLOAT_EQ(0.0, significandl(0.0));
+  ASSERT_FLOAT_EQ(1.2, significandl(1.2));
+  ASSERT_FLOAT_EQ(1.5375, significandl(12.3));
+}
+
+TEST(math, scalb) {
+  ASSERT_FLOAT_EQ(12.0, scalb(3.0, 2.0));
+}
+
+TEST(math, scalbf) {
+  ASSERT_FLOAT_EQ(12.0f, scalbf(3.0f, 2.0f));
+}
+
+TEST(math, scalbln) {
+  ASSERT_FLOAT_EQ(12.0, scalbln(3.0, 2L));
+}
+
+TEST(math, scalblnf) {
+  ASSERT_FLOAT_EQ(12.0f, scalblnf(3.0f, 2L));
+}
+
+TEST(math, scalblnl) {
+  ASSERT_FLOAT_EQ(12.0, scalblnl(3.0, 2L));
+}
+
+TEST(math, scalbn) {
+  ASSERT_FLOAT_EQ(12.0, scalbn(3.0, 2));
+}
+
+TEST(math, scalbnf) {
+  ASSERT_FLOAT_EQ(12.0f, scalbnf(3.0f, 2));
+}
+
+TEST(math, scalbnl) {
+  ASSERT_FLOAT_EQ(12.0, scalbnl(3.0, 2));
+}
+
+TEST(math, gamma) {
+  ASSERT_FLOAT_EQ(log(24.0), gamma(5.0));
+}
+
+TEST(math, gammaf) {
+  ASSERT_FLOAT_EQ(logf(24.0f), gammaf(5.0f));
+}
+
+#if defined(__BIONIC__)
+TEST(math, gamma_r) {
+  int sign;
+  ASSERT_FLOAT_EQ(log(24.0), gamma_r(5.0, &sign));
+  ASSERT_EQ(1, sign);
+}
+#endif
+
+#if defined(__BIONIC__)
+TEST(math, gammaf_r) {
+  int sign;
+  ASSERT_FLOAT_EQ(logf(24.0f), gammaf_r(5.0f, &sign));
+  ASSERT_EQ(1, sign);
+}
+#endif
+
+TEST(math, lgamma) {
+  ASSERT_FLOAT_EQ(log(24.0), lgamma(5.0));
+}
+
+TEST(math, lgammaf) {
+  ASSERT_FLOAT_EQ(logf(24.0f), lgammaf(5.0f));
+}
+
+TEST(math, lgammal) {
+  ASSERT_FLOAT_EQ(logl(24.0), lgammal(5.0));
+}
+
+TEST(math, lgamma_r) {
+  int sign;
+  ASSERT_FLOAT_EQ(log(24.0), lgamma_r(5.0, &sign));
+  ASSERT_EQ(1, sign);
+}
+
+TEST(math, lgammaf_r) {
+  int sign;
+  ASSERT_FLOAT_EQ(logf(24.0f), lgammaf_r(5.0f, &sign));
+  ASSERT_EQ(1, sign);
+}
+
+TEST(math, tgamma) {
+  ASSERT_FLOAT_EQ(24.0, tgamma(5.0));
+}
+
+TEST(math, tgammaf) {
+  ASSERT_FLOAT_EQ(24.0f, tgammaf(5.0f));
+}
+
+TEST(math, tgammal) {
+  ASSERT_FLOAT_EQ(24.0, tgammal(5.0));
+}
+
+TEST(math, j0) {
+  ASSERT_FLOAT_EQ(1.0, j0(0.0));
+  ASSERT_FLOAT_EQ(0.76519769, j0(1.0));
+}
+
+TEST(math, j0f) {
+  ASSERT_FLOAT_EQ(1.0f, j0f(0.0f));
+  ASSERT_FLOAT_EQ(0.76519769f, j0f(1.0f));
+}
+
+TEST(math, j1) {
+  ASSERT_FLOAT_EQ(0.0, j1(0.0));
+  ASSERT_FLOAT_EQ(0.44005057, j1(1.0));
+}
+
+TEST(math, j1f) {
+  ASSERT_FLOAT_EQ(0.0f, j1f(0.0f));
+  ASSERT_FLOAT_EQ(0.44005057f, j1f(1.0f));
+}
+
+TEST(math, jn) {
+  ASSERT_FLOAT_EQ(0.0, jn(4, 0.0));
+  ASSERT_FLOAT_EQ(0.0024766389, jn(4, 1.0));
+}
+
+TEST(math, jnf) {
+  ASSERT_FLOAT_EQ(0.0f, jnf(4, 0.0f));
+  ASSERT_FLOAT_EQ(0.0024766389f, jnf(4, 1.0f));
+}
+
+TEST(math, y0) {
+  ASSERT_FLOAT_EQ(-HUGE_VAL, y0(0.0));
+  ASSERT_FLOAT_EQ(0.088256963, y0(1.0));
+}
+
+TEST(math, y0f) {
+  ASSERT_FLOAT_EQ(-HUGE_VALF, y0f(0.0f));
+  ASSERT_FLOAT_EQ(0.088256963f, y0f(1.0f));
+}
+
+TEST(math, y1) {
+  ASSERT_FLOAT_EQ(-HUGE_VAL, y1(0.0));
+  ASSERT_FLOAT_EQ(-0.78121281, y1(1.0));
+}
+
+TEST(math, y1f) {
+  ASSERT_FLOAT_EQ(-HUGE_VALF, y1f(0.0f));
+  ASSERT_FLOAT_EQ(-0.78121281f, y1f(1.0f));
+}
+
+TEST(math, yn) {
+  ASSERT_FLOAT_EQ(-HUGE_VAL, yn(4, 0.0));
+  ASSERT_FLOAT_EQ(-33.278423, yn(4, 1.0));
+}
+
+TEST(math, ynf) {
+  ASSERT_FLOAT_EQ(-HUGE_VALF, ynf(4, 0.0f));
+  ASSERT_FLOAT_EQ(-33.278423f, ynf(4, 1.0f));
+}
+
+TEST(math, frexp) {
+  int exp;
+  double dr = frexp(1024.0, &exp);
+  ASSERT_FLOAT_EQ(1024.0, scalbn(dr, exp));
+}
+
+TEST(math, frexpf) {
+  int exp;
+  float fr = frexpf(1024.0f, &exp);
+  ASSERT_FLOAT_EQ(1024.0f, scalbnf(fr, exp));
+}
+
+TEST(math, frexpl) {
+  int exp;
+  long double ldr = frexpl(1024.0, &exp);
+  ASSERT_FLOAT_EQ(1024.0, scalbnl(ldr, exp));
+}
+
+TEST(math, modf) {
+  double di;
+  double df = modf(123.456, &di);
+  ASSERT_FLOAT_EQ(123.0, di);
+  ASSERT_FLOAT_EQ(0.456, df);
+}
+
+TEST(math, modff) {
+  float fi;
+  float ff = modff(123.456f, &fi);
+  ASSERT_FLOAT_EQ(123.0f, fi);
+  ASSERT_FLOAT_EQ(0.45600128f, ff);
+}
+
+TEST(math, modfl) {
+  long double ldi;
+  long double ldf = modfl(123.456, &ldi);
+  ASSERT_FLOAT_EQ(123.0, ldi);
+  ASSERT_FLOAT_EQ(0.456, ldf);
+}
+
+TEST(math, remquo) {
+  int q;
+  double d = remquo(13.0, 4.0, &q);
+  ASSERT_EQ(3, q);
+  ASSERT_FLOAT_EQ(1.0, d);
+}
+
+TEST(math, remquof) {
+  int q;
+  float f = remquof(13.0f, 4.0f, &q);
+  ASSERT_EQ(3, q);
+  ASSERT_FLOAT_EQ(1.0, f);
+}
+
+TEST(math, remquol) {
+  int q;
+  long double ld = remquol(13.0, 4.0, &q);
+  ASSERT_EQ(3, q);
+  ASSERT_FLOAT_EQ(1.0, ld);
+}
+
+// https://code.google.com/p/android/issues/detail?id=6697
+TEST(math, frexpf_public_bug_6697) {
+  int exp;
+  float fr = frexpf(14.1f, &exp);
+  ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
+}