From 792e51b721491b19904e046124fb8c4c0e83f621 Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Mon, 28 Mar 2016 19:35:20 +0200
Subject: [PATCH] Add missing long double functions to Cygwin

This patch adds the long double functions missing in newlib to Cygwin.
Apart from some self-written additions (exp10l, finite{f,l}, isinf{f,l},
isnan{f,l}, pow10l) the files are taken from the Mingw-w64 math lib.
Minor changes were required, e.g. substitue _WIN64 with __x86_64__ and
fixing __FLT_RPT_DOMAIN/__FLT_RPT_ERANGE for Cygwin.

Cygwin:
	* math: New subdir with math functions.
	* Makefile.in (VPATH): Add math subdir.
	(MATH_OFILES): List of object files collected from building files in
	math subdir.
	(DLL_OFILES): Add $(MATH_OFILES).
	${CURDIR}/libm.a: Add $(MATH_OFILES) to build.
	* common.din: Add new functions from math subdir.
	* i686.din: Align to new math subdir.  Remove functions now commonly
	available.
	* x86_64.din: Ditto.
	* math.h: math.h wrapper to define mingw structs used in some files in
	math subdir.
	* include/cygwin/version.h: Bump API minor version.

newlib:
	* libc/include/complex.h: Add prototypes for complex long double
	functions.  Only define for Cygwin.
	* libc/include/math.h: Additionally enable prototypes of long double
	functions for Cygwin.  Add Cygwin-only prototypes for dreml, sincosl,
	exp10l and pow10l.  Explain why we don't add them to newlib.
	* libc/include/tgmath.h: Enable long double handling on Cygwin.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 newlib/libc/include/complex.h          |   27 +-
 newlib/libc/include/math.h             |   26 +-
 newlib/libc/include/tgmath.h           |    7 +-
 winsup/cygwin/Makefile.in              |  100 +-
 winsup/cygwin/common.din               |  102 +-
 winsup/cygwin/i686.din                 |   27 +-
 winsup/cygwin/include/cygwin/version.h |   13 +-
 winsup/cygwin/math.h                   |   43 +
 winsup/cygwin/math/DISCLAIMER.PD       |    9 +
 winsup/cygwin/math/acosh.def.h         |   70 ++
 winsup/cygwin/math/acoshl.c            |   46 +
 winsup/cygwin/math/acosl.c             |   22 +
 winsup/cygwin/math/asinhl.c            |   33 +
 winsup/cygwin/math/asinl.c             |   27 +
 winsup/cygwin/math/atan2l.c            |   14 +
 winsup/cygwin/math/atanhl.c            |   34 +
 winsup/cygwin/math/atanl.c             |   17 +
 winsup/cygwin/math/cabs.def.h          |   49 +
 winsup/cygwin/math/cabsl.c             |   48 +
 winsup/cygwin/math/cacos.def.h         |   57 ++
 winsup/cygwin/math/cacosh.def.h        |  100 ++
 winsup/cygwin/math/cacosl.c            |   50 +
 winsup/cygwin/math/carg.def.h          |   49 +
 winsup/cygwin/math/cargl.c             |   48 +
 winsup/cygwin/math/casin.def.h         |   61 ++
 winsup/cygwin/math/casinh.def.h        |   99 ++
 winsup/cygwin/math/casinl.c            |   50 +
 winsup/cygwin/math/catan.def.h         |   61 ++
 winsup/cygwin/math/catanh.def.h        |   93 ++
 winsup/cygwin/math/catanl.c            |   50 +
 winsup/cygwin/math/cbrtl.c             |   80 ++
 winsup/cygwin/math/ccos.def.h          |   54 +
 winsup/cygwin/math/ccosh.def.h         |   95 ++
 winsup/cygwin/math/ccosl.c             |   50 +
 winsup/cygwin/math/ceil.S              |  124 +++
 winsup/cygwin/math/ceilf.S             |  120 +++
 winsup/cygwin/math/ceill.S             |   64 ++
 winsup/cygwin/math/cephes_emath.c      | 1283 ++++++++++++++++++++++++
 winsup/cygwin/math/cephes_emath.h      |  719 +++++++++++++
 winsup/cygwin/math/cephes_mconf.h      |  417 ++++++++
 winsup/cygwin/math/cexp.def.h          |  111 ++
 winsup/cygwin/math/cexpl.c             |   48 +
 winsup/cygwin/math/cimag.def.h         |   49 +
 winsup/cygwin/math/cimagl.c            |   48 +
 winsup/cygwin/math/clog.def.h          |   71 ++
 winsup/cygwin/math/clog10.def.h        |   71 ++
 winsup/cygwin/math/clog10l.c           |   48 +
 winsup/cygwin/math/clogl.c             |   48 +
 winsup/cygwin/math/complex_internal.h  |  153 +++
 winsup/cygwin/math/conj.def.h          |   49 +
 winsup/cygwin/math/conjl.c             |   48 +
 winsup/cygwin/math/copysignl.S         |   56 ++
 winsup/cygwin/math/cos.def.h           |   65 ++
 winsup/cygwin/math/coshl.c             |   45 +
 winsup/cygwin/math/cosl.c              |   46 +
 winsup/cygwin/math/cosl_internal.S     |   55 +
 winsup/cygwin/math/cossin.c            |   75 ++
 winsup/cygwin/math/cpow.def.h          |   49 +
 winsup/cygwin/math/cpowl.c             |   48 +
 winsup/cygwin/math/cproj.def.h         |   58 ++
 winsup/cygwin/math/cprojl.c            |   48 +
 winsup/cygwin/math/creal.def.h         |   49 +
 winsup/cygwin/math/creall.c            |   48 +
 winsup/cygwin/math/csin.def.h          |   61 ++
 winsup/cygwin/math/csinh.def.h         |  107 ++
 winsup/cygwin/math/csinl.c             |   50 +
 winsup/cygwin/math/csqrt.def.h         |  122 +++
 winsup/cygwin/math/csqrtl.c            |   48 +
 winsup/cygwin/math/ctan.def.h          |   61 ++
 winsup/cygwin/math/ctanh.def.h         |   94 ++
 winsup/cygwin/math/ctanl.c             |   50 +
 winsup/cygwin/math/erfl.c              |  303 ++++++
 winsup/cygwin/math/exp.def.h           |  136 +++
 winsup/cygwin/math/exp10l.c            |    8 +
 winsup/cygwin/math/exp2.S              |   94 ++
 winsup/cygwin/math/exp2l.S             |   92 ++
 winsup/cygwin/math/expl.c              |   46 +
 winsup/cygwin/math/expm1.def.h         |   72 ++
 winsup/cygwin/math/expm1l.c            |   46 +
 winsup/cygwin/math/fabsl.c             |   18 +
 winsup/cygwin/math/fastmath.h          |  120 +++
 winsup/cygwin/math/fdiml.c             |   24 +
 winsup/cygwin/math/finite.c            |   19 +
 winsup/cygwin/math/floorl.S            |   72 ++
 winsup/cygwin/math/fmal.c              |   12 +
 winsup/cygwin/math/fmaxl.c             |   13 +
 winsup/cygwin/math/fminl.c             |   12 +
 winsup/cygwin/math/fmodl.c             |   20 +
 winsup/cygwin/math/frexpl.S            |  130 +++
 winsup/cygwin/math/ilogbl.S            |   65 ++
 winsup/cygwin/math/internal_logl.S     |   66 ++
 winsup/cygwin/math/isinf.c             |   18 +
 winsup/cygwin/math/isnan.c             |   18 +
 winsup/cygwin/math/ldexpl.c            |   23 +
 winsup/cygwin/math/lgammal.c           |  342 +++++++
 winsup/cygwin/math/llrint.c            |   18 +
 winsup/cygwin/math/llrintf.c           |   17 +
 winsup/cygwin/math/llrintl.c           |   18 +
 winsup/cygwin/math/llroundl.c          |   38 +
 winsup/cygwin/math/log.def.h           |   69 ++
 winsup/cygwin/math/log10l.S            |   93 ++
 winsup/cygwin/math/log1pl.S            |  102 ++
 winsup/cygwin/math/log2l.S             |   87 ++
 winsup/cygwin/math/logbl.c             |   22 +
 winsup/cygwin/math/logl.c              |   46 +
 winsup/cygwin/math/lrint.c             |   30 +
 winsup/cygwin/math/lrintf.c            |   30 +
 winsup/cygwin/math/lrintl.c            |   18 +
 winsup/cygwin/math/lroundl.c           |   37 +
 winsup/cygwin/math/modfl.c             |   41 +
 winsup/cygwin/math/nearbyint.S         |   57 ++
 winsup/cygwin/math/nearbyintf.S        |   57 ++
 winsup/cygwin/math/nearbyintl.S        |   58 ++
 winsup/cygwin/math/nextafterl.c        |   71 ++
 winsup/cygwin/math/nexttoward.c        |   47 +
 winsup/cygwin/math/nexttowardf.c       |   43 +
 winsup/cygwin/math/pow.def.h           |  215 ++++
 winsup/cygwin/math/pow10l.c            |    8 +
 winsup/cygwin/math/powi.def.h          |  153 +++
 winsup/cygwin/math/powil.c             |   46 +
 winsup/cygwin/math/powl.c              |   46 +
 winsup/cygwin/math/remainder.S         |   40 +
 winsup/cygwin/math/remainderf.S        |   40 +
 winsup/cygwin/math/remainderl.S        |   39 +
 winsup/cygwin/math/remquol.S           |   75 ++
 winsup/cygwin/math/rint.c              |   29 +
 winsup/cygwin/math/rintf.c             |   29 +
 winsup/cygwin/math/rintl.c             |   16 +
 winsup/cygwin/math/roundl.c            |   26 +
 winsup/cygwin/math/scalbl.S            |   35 +
 winsup/cygwin/math/scalbnl.S           |   41 +
 winsup/cygwin/math/sin.def.h           |   65 ++
 winsup/cygwin/math/sinhl.c             |  100 ++
 winsup/cygwin/math/sinl.c              |   46 +
 winsup/cygwin/math/sinl_internal.S     |   58 ++
 winsup/cygwin/math/sqrt.def.h          |   94 ++
 winsup/cygwin/math/sqrtl.c             |   46 +
 winsup/cygwin/math/tanhl.c             |   92 ++
 winsup/cygwin/math/tanl.S              |   62 ++
 winsup/cygwin/math/tgammal.c           |  393 ++++++++
 winsup/cygwin/math/truncl.c            |   26 +
 winsup/cygwin/x86_64.din               |    6 -
 142 files changed, 10969 insertions(+), 42 deletions(-)
 create mode 100644 winsup/cygwin/math.h
 create mode 100644 winsup/cygwin/math/DISCLAIMER.PD
 create mode 100644 winsup/cygwin/math/acosh.def.h
 create mode 100644 winsup/cygwin/math/acoshl.c
 create mode 100644 winsup/cygwin/math/acosl.c
 create mode 100644 winsup/cygwin/math/asinhl.c
 create mode 100644 winsup/cygwin/math/asinl.c
 create mode 100644 winsup/cygwin/math/atan2l.c
 create mode 100644 winsup/cygwin/math/atanhl.c
 create mode 100644 winsup/cygwin/math/atanl.c
 create mode 100644 winsup/cygwin/math/cabs.def.h
 create mode 100644 winsup/cygwin/math/cabsl.c
 create mode 100644 winsup/cygwin/math/cacos.def.h
 create mode 100644 winsup/cygwin/math/cacosh.def.h
 create mode 100644 winsup/cygwin/math/cacosl.c
 create mode 100644 winsup/cygwin/math/carg.def.h
 create mode 100644 winsup/cygwin/math/cargl.c
 create mode 100644 winsup/cygwin/math/casin.def.h
 create mode 100644 winsup/cygwin/math/casinh.def.h
 create mode 100644 winsup/cygwin/math/casinl.c
 create mode 100644 winsup/cygwin/math/catan.def.h
 create mode 100644 winsup/cygwin/math/catanh.def.h
 create mode 100644 winsup/cygwin/math/catanl.c
 create mode 100644 winsup/cygwin/math/cbrtl.c
 create mode 100644 winsup/cygwin/math/ccos.def.h
 create mode 100644 winsup/cygwin/math/ccosh.def.h
 create mode 100644 winsup/cygwin/math/ccosl.c
 create mode 100644 winsup/cygwin/math/ceil.S
 create mode 100644 winsup/cygwin/math/ceilf.S
 create mode 100644 winsup/cygwin/math/ceill.S
 create mode 100644 winsup/cygwin/math/cephes_emath.c
 create mode 100644 winsup/cygwin/math/cephes_emath.h
 create mode 100644 winsup/cygwin/math/cephes_mconf.h
 create mode 100644 winsup/cygwin/math/cexp.def.h
 create mode 100644 winsup/cygwin/math/cexpl.c
 create mode 100644 winsup/cygwin/math/cimag.def.h
 create mode 100644 winsup/cygwin/math/cimagl.c
 create mode 100644 winsup/cygwin/math/clog.def.h
 create mode 100644 winsup/cygwin/math/clog10.def.h
 create mode 100644 winsup/cygwin/math/clog10l.c
 create mode 100644 winsup/cygwin/math/clogl.c
 create mode 100644 winsup/cygwin/math/complex_internal.h
 create mode 100644 winsup/cygwin/math/conj.def.h
 create mode 100644 winsup/cygwin/math/conjl.c
 create mode 100644 winsup/cygwin/math/copysignl.S
 create mode 100644 winsup/cygwin/math/cos.def.h
 create mode 100644 winsup/cygwin/math/coshl.c
 create mode 100644 winsup/cygwin/math/cosl.c
 create mode 100644 winsup/cygwin/math/cosl_internal.S
 create mode 100644 winsup/cygwin/math/cossin.c
 create mode 100644 winsup/cygwin/math/cpow.def.h
 create mode 100644 winsup/cygwin/math/cpowl.c
 create mode 100644 winsup/cygwin/math/cproj.def.h
 create mode 100644 winsup/cygwin/math/cprojl.c
 create mode 100644 winsup/cygwin/math/creal.def.h
 create mode 100644 winsup/cygwin/math/creall.c
 create mode 100644 winsup/cygwin/math/csin.def.h
 create mode 100644 winsup/cygwin/math/csinh.def.h
 create mode 100644 winsup/cygwin/math/csinl.c
 create mode 100644 winsup/cygwin/math/csqrt.def.h
 create mode 100644 winsup/cygwin/math/csqrtl.c
 create mode 100644 winsup/cygwin/math/ctan.def.h
 create mode 100644 winsup/cygwin/math/ctanh.def.h
 create mode 100644 winsup/cygwin/math/ctanl.c
 create mode 100644 winsup/cygwin/math/erfl.c
 create mode 100644 winsup/cygwin/math/exp.def.h
 create mode 100644 winsup/cygwin/math/exp10l.c
 create mode 100644 winsup/cygwin/math/exp2.S
 create mode 100644 winsup/cygwin/math/exp2l.S
 create mode 100644 winsup/cygwin/math/expl.c
 create mode 100644 winsup/cygwin/math/expm1.def.h
 create mode 100644 winsup/cygwin/math/expm1l.c
 create mode 100644 winsup/cygwin/math/fabsl.c
 create mode 100644 winsup/cygwin/math/fastmath.h
 create mode 100644 winsup/cygwin/math/fdiml.c
 create mode 100644 winsup/cygwin/math/finite.c
 create mode 100644 winsup/cygwin/math/floorl.S
 create mode 100644 winsup/cygwin/math/fmal.c
 create mode 100644 winsup/cygwin/math/fmaxl.c
 create mode 100644 winsup/cygwin/math/fminl.c
 create mode 100644 winsup/cygwin/math/fmodl.c
 create mode 100644 winsup/cygwin/math/frexpl.S
 create mode 100644 winsup/cygwin/math/ilogbl.S
 create mode 100644 winsup/cygwin/math/internal_logl.S
 create mode 100644 winsup/cygwin/math/isinf.c
 create mode 100644 winsup/cygwin/math/isnan.c
 create mode 100644 winsup/cygwin/math/ldexpl.c
 create mode 100644 winsup/cygwin/math/lgammal.c
 create mode 100644 winsup/cygwin/math/llrint.c
 create mode 100644 winsup/cygwin/math/llrintf.c
 create mode 100644 winsup/cygwin/math/llrintl.c
 create mode 100644 winsup/cygwin/math/llroundl.c
 create mode 100644 winsup/cygwin/math/log.def.h
 create mode 100644 winsup/cygwin/math/log10l.S
 create mode 100644 winsup/cygwin/math/log1pl.S
 create mode 100644 winsup/cygwin/math/log2l.S
 create mode 100644 winsup/cygwin/math/logbl.c
 create mode 100644 winsup/cygwin/math/logl.c
 create mode 100644 winsup/cygwin/math/lrint.c
 create mode 100644 winsup/cygwin/math/lrintf.c
 create mode 100644 winsup/cygwin/math/lrintl.c
 create mode 100644 winsup/cygwin/math/lroundl.c
 create mode 100644 winsup/cygwin/math/modfl.c
 create mode 100644 winsup/cygwin/math/nearbyint.S
 create mode 100644 winsup/cygwin/math/nearbyintf.S
 create mode 100644 winsup/cygwin/math/nearbyintl.S
 create mode 100644 winsup/cygwin/math/nextafterl.c
 create mode 100644 winsup/cygwin/math/nexttoward.c
 create mode 100644 winsup/cygwin/math/nexttowardf.c
 create mode 100644 winsup/cygwin/math/pow.def.h
 create mode 100644 winsup/cygwin/math/pow10l.c
 create mode 100644 winsup/cygwin/math/powi.def.h
 create mode 100644 winsup/cygwin/math/powil.c
 create mode 100644 winsup/cygwin/math/powl.c
 create mode 100644 winsup/cygwin/math/remainder.S
 create mode 100644 winsup/cygwin/math/remainderf.S
 create mode 100644 winsup/cygwin/math/remainderl.S
 create mode 100644 winsup/cygwin/math/remquol.S
 create mode 100644 winsup/cygwin/math/rint.c
 create mode 100644 winsup/cygwin/math/rintf.c
 create mode 100644 winsup/cygwin/math/rintl.c
 create mode 100644 winsup/cygwin/math/roundl.c
 create mode 100644 winsup/cygwin/math/scalbl.S
 create mode 100644 winsup/cygwin/math/scalbnl.S
 create mode 100644 winsup/cygwin/math/sin.def.h
 create mode 100644 winsup/cygwin/math/sinhl.c
 create mode 100644 winsup/cygwin/math/sinl.c
 create mode 100644 winsup/cygwin/math/sinl_internal.S
 create mode 100644 winsup/cygwin/math/sqrt.def.h
 create mode 100644 winsup/cygwin/math/sqrtl.c
 create mode 100644 winsup/cygwin/math/tanhl.c
 create mode 100644 winsup/cygwin/math/tanl.S
 create mode 100644 winsup/cygwin/math/tgammal.c
 create mode 100644 winsup/cygwin/math/truncl.c

diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
index 3150f3423..89d6162dc 100644
--- a/newlib/libc/include/complex.h
+++ b/newlib/libc/include/complex.h
@@ -108,12 +108,10 @@ long double cimagl(long double complex);
 /* 7.3.9.3 The conj functions */
 double complex conj(double complex);
 float complex conjf(float complex);
-/*long double complex conjl(long double complex); */
 
 /* 7.3.9.4 The cproj functions */
 double complex cproj(double complex);
 float complex cprojf(float complex);
-/*long double complex cprojl(long double complex); */
 
 /* 7.3.9.5 The creal functions */
 double creal(double complex);
@@ -125,6 +123,31 @@ double complex clog10(double complex);
 float complex clog10f(float complex);
 #endif
 
+#if defined(__CYGWIN__)
+long double complex cacosl(long double complex);
+long double complex casinl(long double complex);
+long double complex catanl(long double complex);
+long double complex ccosl(long double complex);
+long double complex csinl(long double complex);
+long double complex ctanl(long double complex);
+long double complex cacoshl(long double complex);
+long double complex casinhl(long double complex);
+long double complex catanhl(long double complex);
+long double complex ccoshl(long double complex);
+long double complex csinhl(long double complex);
+long double complex ctanhl(long double complex);
+long double complex cexpl(long double complex);
+long double complex clogl(long double complex);
+long double complex cpowl(long double complex, long double complex);
+long double complex csqrtl(long double complex);
+long double cargl(long double complex);
+long double complex conjl(long double complex);
+long double complex cprojl(long double complex);
+#if __GNU_VISIBLE
+long double complex clog10l(long double complex);
+#endif
+#endif /* __CYGWIN__ */
+
 __END_DECLS
 
 #endif	/* ! _COMPLEX_H */
diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index eeedeba92..e5d612367 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -421,8 +421,12 @@ extern float log2f _PARAMS((float));
 extern float hypotf _PARAMS((float, float));
 #endif /* ! defined (_REENT_ONLY) */
 
-/* On platforms where long double equals double.  */
-#ifdef _LDBL_EQ_DBL
+/* Newlib doesn't fully support long double math functions so far.
+   On platforms where long double equals double the long double functions
+   simply call the double functions.  On Cygwin the long double functions
+   are implemented independently from newlib to be able to use optimized
+   assembler functions despite using the Microsoft x86_64 ABI. */
+#if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__)
 /* Reentrant ANSI C functions.  */
 #ifndef __math_68881
 extern long double atanl _PARAMS((long double));
@@ -492,7 +496,7 @@ extern long double lgammal _PARAMS((long double));
 extern long double erfl _PARAMS((long double));
 extern long double erfcl _PARAMS((long double));
 #endif /* ! defined (_REENT_ONLY) */
-#else /* !_LDBL_EQ_DBL */
+#else /* !_LDBL_EQ_DBL && !__CYGWIN__ */
 extern long double hypotl _PARAMS((long double, long double));
 extern long double sqrtl _PARAMS((long double));
 #ifdef __i386__
@@ -501,13 +505,16 @@ extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE));
 extern long int lrintl _PARAMS((_LONG_DOUBLE));
 extern long long int llrintl _PARAMS((_LONG_DOUBLE));
 #endif /* __i386__ */
-#endif /* !_LDBL_EQ_DBL */
+#endif /* !_LDBL_EQ_DBL && !__CYGWIN__ */
 
 #endif /* __ISO_C_VISIBLE >= 1999 */
 
 #if __MISC_VISIBLE
 extern double drem _PARAMS((double, double));
 extern float dremf _PARAMS((float, float));
+#ifdef __CYGWIN__
+extern float dreml _PARAMS((long double, long double));
+#endif /* __CYGWIN__ */
 extern double gamma_r _PARAMS((double, int *));
 extern double lgamma_r _PARAMS((double, int *));
 extern float gammaf_r _PARAMS((float, int *));
@@ -536,6 +543,9 @@ extern float jnf _PARAMS((int, float));
 #if __GNU_VISIBLE
 extern void sincos _PARAMS((double, double *, double *));
 extern void sincosf _PARAMS((float, float *, float *));
+#ifdef __CYGWIN__
+extern void sincosl _PARAMS((long double, long double *, long double *));
+#endif /* __CYGWIN__ */
 # ifndef exp10
 extern double exp10 _PARAMS((double));
 # endif
@@ -548,6 +558,14 @@ extern float exp10f _PARAMS((float));
 # ifndef pow10f
 extern float pow10f _PARAMS((float));
 # endif
+#ifdef __CYGWIN__
+# ifndef exp10l
+extern float exp10l _PARAMS((float));
+# endif
+# ifndef pow10l
+extern float pow10l _PARAMS((float));
+# endif
+#endif /* __CYGWIN__ */
 #endif /* __GNU_VISIBLE */
 
 #if __MISC_VISIBLE || __XSI_VISIBLE
diff --git a/newlib/libc/include/tgmath.h b/newlib/libc/include/tgmath.h
index f9c8311cc..97dc50eaa 100644
--- a/newlib/libc/include/tgmath.h
+++ b/newlib/libc/include/tgmath.h
@@ -79,7 +79,7 @@
 	 __tg_type3(__e1, __e2, __e3, long double _Complex) ||		\
 	 __tg_type3(__e1, __e2, __e3, __typeof__(_Complex_I)))
 
-#ifdef _LDBL_EQ_DBL
+#if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__)
 #define	__tg_impl_simple(x, y, z, fn, fnf, fnl, ...)			\
 	__builtin_choose_expr(__tg_type_corr(x, y, z, long double),	\
 	    fnl(__VA_ARGS__), __builtin_choose_expr(			\
@@ -161,9 +161,10 @@
 #define	lround(__x)		__tg_simple(__x, lround)
 #define	nearbyint(__x)		__tg_simple(__x, nearbyint)
 #define	nextafter(__x, __y)	__tg_simple2(__x, __y, nextafter)
-/* not yet implemented even for _LDBL_EQ_DBL platforms
+/* not yet implemented even for _LDBL_EQ_DBL platforms */
+#ifdef __CYGWIN__
 #define	nexttoward(__x, __y)	__tg_simplev(__x, nexttoward, __x, __y)
-*/
+#endif
 #define	remainder(__x, __y)	__tg_simple2(__x, __y, remainder)
 #define	remquo(__x, __y, __z)	__tg_impl_simple(__x, __x, __y, remquo, remquof,	\
 						 remquol, __x, __y, __z)
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 669548857..bcfaa2f55 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -29,7 +29,7 @@ export CCWRAP_HEADERS:=. ${srcdir}
 export CCWRAP_SYSTEM_HEADERS:=@cygwin_headers@ @newlib_headers@
 export CCWRAP_DIRAFTER_HEADERS:=@windows_headers@
 
-VPATH+=$(srcdir)/regex $(srcdir)/lib $(srcdir)/libc
+VPATH+=$(srcdir)/regex $(srcdir)/lib $(srcdir)/libc $(srcdir)/math
 
 target_cpu:=@target_cpu@
 target_alias:=@target_alias@
@@ -153,6 +153,101 @@ DLL_IMPORTS:=${shell $(CC) -print-file-name=w32api/libkernel32.a} ${shell $(CC)
 
 MT_SAFE_OBJECTS:=
 #
+MATH_OFILES:= \
+	acoshl.o \
+	acosl.o \
+	asinhl.o \
+	asinl.o \
+	atan2l.o \
+	atanhl.o \
+	atanl.o \
+	cabsl.o \
+	cacosl.o \
+	cargl.o \
+	casinl.o \
+	catanl.o \
+	cbrtl.o \
+	ccosl.o \
+	ceill.o \
+	cephes_emath.o \
+	cexpl.o \
+	cimagl.o \
+	clog10l.o \
+	clogl.o \
+	conjl.o \
+	copysignl.o \
+	coshl.o \
+	cosl.o \
+	cosl_internal.o \
+	cossin.o \
+	cpowl.o \
+	cprojl.o \
+	creall.o \
+	csinl.o \
+	csqrtl.o \
+	ctanl.o \
+	erfl.o \
+	exp10l.o \
+	exp2l.o \
+	expl.o \
+	expm1l.o \
+	fabsl.o \
+	fdiml.o \
+	finite.o \
+	floorl.o \
+	fmal.o \
+	fmaxl.o \
+	fminl.o \
+	fmodl.o \
+	frexpl.o \
+	ilogbl.o \
+	internal_logl.o \
+	isinf.o \
+	isnan.o \
+	ldexpl.o \
+	lgammal.o \
+	llrint.o \
+	llrintf.o \
+	llrintl.o \
+	llroundl.o \
+	log10l.o \
+	log1pl.o \
+	log2l.o \
+	logbl.o \
+	logl.o \
+	lrint.o \
+	lrintf.o \
+	lrintl.o \
+	lroundl.o \
+	modfl.o \
+	nearbyint.o \
+	nearbyintf.o \
+	nearbyintl.o \
+	nextafterl.o \
+	nexttoward.o \
+	nexttowardf.o \
+	pow10l.o \
+	powil.o \
+	powl.o \
+	remainder.o \
+	remainderf.o \
+	remainderl.o \
+	remquol.o \
+	rint.o \
+	rintf.o \
+	rintl.o \
+	roundl.o \
+	scalbl.o \
+	scalbnl.o \
+	sinhl.o \
+	sinl.o \
+	sinl_internal.o \
+	sqrtl.o \
+	tanhl.o \
+	tanl.o \
+	tgammal.o \
+	truncl.o
+
 DLL_OFILES:= \
 	advapi32.o \
 	arc4random_stir.o \
@@ -305,6 +400,7 @@ DLL_OFILES:= \
 	xsique.o \
 	$(EXTRA_OFILES) \
 	$(MALLOC_OFILES) \
+	$(MATH_OFILES) \
 	$(MT_SAFE_OBJECTS)
 
 EXCLUDE_STATIC_OFILES:=$(addprefix --exclude=,\
@@ -626,7 +722,7 @@ $(srcdir)/devices.cc: gendevices devices.in devices.h
 ${CURDIR}/libc.a: ${LIB_NAME} ${CURDIR}/libm.a libpthread.a libutil.a
 	${speclib} -v ${@F}
 
-${CURDIR}/libm.a: ${LIB_NAME} $(LIBM)
+${CURDIR}/libm.a: ${LIB_NAME} $(LIBM) $(MATH_OFILES)
 	${speclib} ${@F}
 
 libpthread.a: ${LIB_NAME} pthread.o thread.o
diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 7e72abe50..c2f5f0fd4 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -64,10 +64,10 @@ __getpagesize = getpagesize SIGFE
 __getreent NOSIGFE
 __gnu_basename NOSIGFE
 __infinity NOSIGFE
-__isinfd NOSIGFE
-__isinff NOSIGFE
-__isnand NOSIGFE
-__isnanf NOSIGFE
+__isinfd = isinf NOSIGFE
+__isinff = isinff NOSIGFE
+__isnand = isnan NOSIGFE
+__isnanf = isnanf NOSIGFE
 __locale_mb_cur_max NOSIGFE
 __main NOSIGFE
 __mempcpy = mempcpy NOSIGFE
@@ -169,6 +169,8 @@ acos NOSIGFE
 acosf NOSIGFE
 acosh NOSIGFE
 acoshf NOSIGFE
+acoshl NOSIGFE
+acosl NOSIGFE
 alarm SIGFE
 aligned_alloc SIGFE
 alphasort NOSIGFE
@@ -195,14 +197,19 @@ asin NOSIGFE
 asinf NOSIGFE
 asinh NOSIGFE
 asinhf NOSIGFE
+asinhl NOSIGFE
+asinl NOSIGFE
 asnprintf SIGFE
 asprintf SIGFE
 atan NOSIGFE
 atan2 NOSIGFE
 atan2f NOSIGFE
+atan2l NOSIGFE
 atanf NOSIGFE
 atanh NOSIGFE
 atanhf NOSIGFE
+atanhl NOSIGFE
+atanl NOSIGFE
 atexit = cygwin_atexit SIGFE
 atof SIGFE
 atoff SIGFE
@@ -226,28 +233,40 @@ cacos NOSIGFE
 cacosf NOSIGFE
 cacosh NOSIGFE
 cacoshf NOSIGFE
+cacoshl NOSIGFE
+cacosl NOSIGFE
 calloc SIGFE
 canonicalize_file_name SIGFE
 carg NOSIGFE
 cargf NOSIGFE
+cargl NOSIGFE
 casin NOSIGFE
 casinf NOSIGFE
 casinh NOSIGFE
 casinhf NOSIGFE
+casinhl NOSIGFE
+casinl NOSIGFE
 catan NOSIGFE
 catanf NOSIGFE
 catanh NOSIGFE
 catanhf NOSIGFE
+catanhl NOSIGFE
+catanl NOSIGFE
 cbrt NOSIGFE
 cbrtf NOSIGFE
+cbrtl NOSIGFE
 ccos NOSIGFE
 ccosf NOSIGFE
 ccosh NOSIGFE
 ccoshf NOSIGFE
+ccoshl NOSIGFE
+ccosl NOSIGFE
 ceil NOSIGFE
 ceilf NOSIGFE
+ceill NOSIGFE
 cexp NOSIGFE
 cexpf NOSIGFE
+cexpl NOSIGFE
 cfgetispeed NOSIGFE
 cfgetospeed NOSIGFE
 cfmakeraw NOSIGFE
@@ -274,24 +293,32 @@ clock_settime SIGFE
 clog NOSIGFE
 clog10 NOSIGFE
 clog10f NOSIGFE
+clog10l NOSIGFE
 clogf NOSIGFE
+clogl NOSIGFE
 close SIGFE
 closedir SIGFE
 closelog SIGFE
 confstr NOSIGFE
 conj NOSIGFE
 conjf NOSIGFE
+conjl NOSIGFE
 connect = cygwin_connect SIGFE
 copysign NOSIGFE
 copysignf NOSIGFE
+copysignl NOSIGFE
 cos NOSIGFE
 cosf NOSIGFE
 cosh NOSIGFE
 coshf NOSIGFE
+coshl NOSIGFE
+cosl NOSIGFE
 cpow NOSIGFE
 cpowf NOSIGFE
+cpowl NOSIGFE
 cproj NOSIGFE
 cprojf NOSIGFE
+cprojl NOSIGFE
 creal NOSIGFE
 crealf NOSIGFE
 creall NOSIGFE
@@ -300,12 +327,17 @@ csin NOSIGFE
 csinf NOSIGFE
 csinh NOSIGFE
 csinhf NOSIGFE
+csinhl NOSIGFE
+csinl NOSIGFE
 csqrt NOSIGFE
 csqrtf NOSIGFE
+csqrtl NOSIGFE
 ctan NOSIGFE
 ctanf NOSIGFE
 ctanh NOSIGFE
 ctanhf NOSIGFE
+ctanhl NOSIGFE
+ctanl NOSIGFE
 ctermid SIGFE
 ctime SIGFE
 ctime_r SIGFE
@@ -342,8 +374,9 @@ dn_expand = __dn_expand SIGFE
 dn_skipname = __dn_skipname SIGFE
 dprintf SIGFE
 drand48 NOSIGFE
-drem NOSIGFE
-dremf NOSIGFE
+drem = remainder NOSIGFE
+dremf= remainderf NOSIGFE
+dreml= remainderl NOSIGFE
 dup SIGFE
 dup2 SIGFE
 dup3 SIGFE
@@ -370,7 +403,9 @@ erand48 NOSIGFE
 erf NOSIGFE
 erfc NOSIGFE
 erfcf NOSIGFE
+erfcl NOSIGFE
 erff NOSIGFE
+erfl NOSIGFE
 err SIGFE
 error SIGFE
 error_at_line SIGFE
@@ -387,13 +422,18 @@ exit = cygwin_exit SIGFE
 exp NOSIGFE
 exp10 NOSIGFE
 exp10f NOSIGFE
+exp10l NOSIGFE
 exp2 NOSIGFE
 exp2f NOSIGFE
+exp2l NOSIGFE
 expf NOSIGFE
+expl NOSIGFE
 expm1 NOSIGFE
 expm1f NOSIGFE
+expm1l NOSIGFE
 fabs NOSIGFE
 fabsf NOSIGFE
+fabsl NOSIGFE
 faccessat SIGFE
 facl SIGFE
 fchdir SIGFE
@@ -410,6 +450,7 @@ fcvtf SIGFE
 fdatasync SIGFE
 fdim NOSIGFE
 fdimf NOSIGFE
+fdiml NOSIGFE
 fdopen SIGFE
 fdopendir SIGFE
 feclearexcept NOSIGFE
@@ -459,15 +500,20 @@ flock SIGFE
 flockfile SIGFE
 floor NOSIGFE
 floorf NOSIGFE
+floorl NOSIGFE
 fma NOSIGFE
 fmaf NOSIGFE
+fmal NOSIGFE
 fmax NOSIGFE
 fmaxf NOSIGFE
+fmaxl NOSIGFE
 fmemopen SIGFE
 fmin NOSIGFE
 fminf NOSIGFE
+fminl NOSIGFE
 fmod NOSIGFE
 fmodf NOSIGFE
+fmodl NOSIGFE
 fnmatch NOSIGFE
 fopen SIGFE
 fopencookie SIGFE
@@ -493,6 +539,7 @@ fremovexattr SIGFE
 freopen SIGFE
 frexp NOSIGFE
 frexpf NOSIGFE
+frexpl NOSIGFE
 fscanf SIGFE
 fseek SIGFE
 fseeko SIGFE
@@ -650,6 +697,7 @@ if_nameindex SIGFE
 if_nametoindex SIGFE
 ilogb NOSIGFE
 ilogbf NOSIGFE
+ilogbl NOSIGFE
 imaxabs = llabs NOSIGFE
 imaxdiv = lldiv NOSIGFE
 index NOSIGFE
@@ -680,9 +728,11 @@ isdigit NOSIGFE
 isgraph NOSIGFE
 isinf NOSIGFE
 isinff NOSIGFE
+isinfl NOSIGFE
 islower NOSIGFE
 isnan NOSIGFE
 isnanf NOSIGFE
+isnanl NOSIGFE
 isprint NOSIGFE
 ispunct NOSIGFE
 issetugid NOSIGFE
@@ -717,12 +767,15 @@ lchown SIGFE
 lcong48 NOSIGFE
 ldexp NOSIGFE
 ldexpf NOSIGFE
+ldexpl NOSIGFE
 ldiv NOSIGFE
 lfind NOSIGFE
 lgamma NOSIGFE
 lgamma_r NOSIGFE
 lgammaf NOSIGFE
 lgammaf_r NOSIGFE
+lgammal NOSIGFE
+lgammal_r NOSIGFE
 lgetxattr SIGFE
 link SIGFE
 linkat SIGFE
@@ -731,8 +784,12 @@ listxattr SIGFE
 llabs NOSIGFE
 lldiv NOSIGFE
 llistxattr SIGFE
+llrint NOSIGFE
+llrintf NOSIGFE
+llrintl NOSIGFE
 llround NOSIGFE
 llroundf NOSIGFE
+llroundl NOSIGFE
 localeconv NOSIGFE
 localtime SIGFE
 localtime_r SIGFE
@@ -740,13 +797,18 @@ lockf SIGFE
 log NOSIGFE
 log10 NOSIGFE
 log10f NOSIGFE
+log10l NOSIGFE
 log1p NOSIGFE
 log1pf NOSIGFE
+log1pl NOSIGFE
 log2 NOSIGFE
 log2f NOSIGFE
+log2l NOSIGFE
 logb NOSIGFE
 logbf NOSIGFE
+logbl NOSIGFE
 logf NOSIGFE
+logl NOSIGFE
 login SIGFE
 login_tty SIGFE
 logout SIGFE
@@ -754,8 +816,12 @@ logwtmp SIGFE
 longjmp NOSIGFE
 lrand48 NOSIGFE
 lremovexattr SIGFE
+lrint NOSIGFE
+lrintf NOSIGFE
+lrintl NOSIGFE
 lround NOSIGFE
 lroundf NOSIGFE
+lroundl NOSIGFE
 lsearch NOSIGFE
 lseek SIGFE
 lsetxattr SIGFE
@@ -805,6 +871,7 @@ mlock SIGFE
 mmap SIGFE
 modf NOSIGFE
 modff NOSIGFE
+modfl NOSIGFE
 mount SIGFE
 mprotect SIGFE
 mq_close SIGFE
@@ -830,8 +897,13 @@ nanf NOSIGFE
 nanosleep SIGFE
 nearbyint NOSIGFE
 nearbyintf NOSIGFE
+nearbyintl NOSIGFE
 nextafter NOSIGFE
 nextafterf NOSIGFE
+nextafterl NOSIGFE
+nexttoward NOSIGFE
+nexttowardf NOSIGFE
+nexttowardl NOSIGFE
 nftw SIGFE
 nice SIGFE
 nl_langinfo SIGFE
@@ -883,7 +955,9 @@ posix_spawn_file_actions_addopen SIGFE
 pow NOSIGFE
 pow10 NOSIGFE
 pow10f NOSIGFE
+pow10l NOSIGFE
 powf NOSIGFE
+powl NOSIGFE
 ppoll SIGFE
 pread SIGFE
 printf SIGFE
@@ -1037,11 +1111,13 @@ regexec SIGFE
 regfree SIGFE
 remainder NOSIGFE
 remainderf NOSIGFE
+remainderl NOSIGFE
 remove SIGFE
 removexattr SIGFE
 remque NOSIGFE
 remquo NOSIGFE
 remquof NOSIGFE
+remquol NOSIGFE
 rename SIGFE
 renameat SIGFE
 res_close = __res_close SIGFE
@@ -1063,9 +1139,13 @@ rewind SIGFE
 rewinddir SIGFE
 rexec = cygwin_rexec SIGFE
 rindex NOSIGFE
+rint NOSIGFE
+rintf NOSIGFE
+rintl NOSIGFE
 rmdir SIGFE
 round NOSIGFE
 roundf NOSIGFE
+roundl NOSIGFE
 rpmatch SIGFE
 rresvport = cygwin_rresvport SIGFE
 rresvport_af = cygwin_rresvport_af SIGFE
@@ -1073,10 +1153,13 @@ ruserok SIGFE
 sbrk SIGFE
 scalb NOSIGFE
 scalbf NOSIGFE
+scalbl NOSIGFE
 scalbln NOSIGFE
 scalblnf NOSIGFE
+scalblnl NOSIGFE
 scalbn NOSIGFE
 scalbnf NOSIGFE
+scalbnl NOSIGFE
 scandir SIGFE
 scandirat SIGFE
 scanf SIGFE
@@ -1180,9 +1263,12 @@ sigwaitinfo SIGFE
 sin NOSIGFE
 sincos NOSIGFE
 sincosf NOSIGFE
+sincosl NOSIGFE
 sinf NOSIGFE
 sinh NOSIGFE
 sinhf NOSIGFE
+sinhl NOSIGFE
+sinl NOSIGFE
 siprintf SIGFE
 sleep SIGFE
 snprintf SIGFE
@@ -1271,6 +1357,8 @@ tan NOSIGFE
 tanf NOSIGFE
 tanh NOSIGFE
 tanhf NOSIGFE
+tanhl NOSIGFE
+tanl NOSIGFE
 tcdrain SIGFE
 tcflow SIGFE
 tcflush SIGFE
@@ -1287,6 +1375,7 @@ tempnam SIGFE
 tfind NOSIGFE
 tgamma NOSIGFE
 tgammaf NOSIGFE
+tgammal NOSIGFE
 time SIGFE
 timegm NOSIGFE
 timelocal SIGFE
@@ -1307,6 +1396,7 @@ towupper NOSIGFE
 trunc NOSIGFE
 truncate SIGFE
 truncf NOSIGFE
+truncl NOSIGFE
 tsearch SIGFE
 ttyname SIGFE
 ttyname_r SIGFE
diff --git a/winsup/cygwin/i686.din b/winsup/cygwin/i686.din
index a9b31172b..f3cd2fd37 100644
--- a/winsup/cygwin/i686.din
+++ b/winsup/cygwin/i686.din
@@ -164,21 +164,21 @@ _f_frexp NOSIGFE
 _f_frexpf NOSIGFE
 _f_ldexp NOSIGFE
 _f_ldexpf NOSIGFE
-_f_llrint NOSIGFE
-_f_llrintf NOSIGFE
-_f_llrintl NOSIGFE
+_f_llrint = llrint NOSIGFE
+_f_llrintf = llrintf NOSIGFE
+_f_llrintl = llrintl NOSIGFE
 _f_log NOSIGFE
 _f_log10 NOSIGFE
 _f_log10f NOSIGFE
 _f_logf NOSIGFE
-_f_lrint NOSIGFE
-_f_lrintf NOSIGFE
-_f_lrintl NOSIGFE
+_f_lrint = lrint NOSIGFE
+_f_lrintf = lrintf NOSIGFE
+_f_lrintl = lrintl NOSIGFE
 _f_pow NOSIGFE
 _f_powf NOSIGFE
-_f_rint NOSIGFE
-_f_rintf NOSIGFE
-_f_rintl NOSIGFE
+_f_rint = rint NOSIGFE
+_f_rintf = rintf NOSIGFE
+_f_rintl = rintl NOSIGFE
 _f_tan NOSIGFE
 _f_tanf NOSIGFE
 _fabs = fabs NOSIGFE
@@ -622,19 +622,10 @@ fscanf_r = _fscanf_r SIGFE
 get_osfhandle = _get_osfhandle SIGFE
 getpwduid NOSIGFE
 lacl SIGFE
-llrint = _f_llrint NOSIGFE
-llrintf = _f_llrintf NOSIGFE
-llrintl = _f_llrintl NOSIGFE
-lrint = _f_lrint NOSIGFE
-lrintf = _f_lrintf NOSIGFE
-lrintl = _f_lrintl NOSIGFE
 posix_regcomp = regcomp SIGFE
 posix_regerror = regerror SIGFE
 posix_regexec = regexec SIGFE
 posix_regfree = regfree SIGFE
-rint = _f_rint NOSIGFE
-rintf = _f_rintf NOSIGFE
-rintl = _f_rintl NOSIGFE
 scanf_r = _scanf_r SIGFE
 setmode = cygwin_setmode SIGFE
 setregid32 SIGFE
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index ee7c4ff6f..8b1a8fc99 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -478,13 +478,24 @@ details. */
       294: Export clog10, clog10f.
       295: Export POSIX ACL functions.
       296: Export __getpagesize.
+      297: Export missing math functions, acoshl, acosl, asinhl, asinl, atan2l,
+	   atanhl, atanl, cacoshl, cacosl, cargl, casinhl, casinl, catanhl,
+	   catanl, ccoshl, ccosl, ceill, cexpl, clog10l, clogl, conjl,
+	   copysignl, coshl, cosl, cpowl, cprojl, csinhl, csinl, csqrtl, ctanhl,
+	   ctanl, dreml, erfcl, erfl, exp10l, exp2l, expl, expm1l, fabsl, fdiml,
+	   floorl, fmal, fmaxl, fminl, fmodl, frexpl, ilogbl, isinfl, isnanl,
+	   ldexpl, lgammal, lgammal_r, llroundl, log10l, log1pl, log2l, logbl,
+	   logl, lroundl, modfl, nearbyintl, nextafterl, nexttoward,
+	   nexttowardf, nexttowardl, pow10l, powl, remainderl, remquol, roundl,
+	   scalbl, scalblnl, scalbnl, sincosl, sinhl, sinl, tanhl, tanl,
+	   tgammal, truncl.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull,
 	sigaltstack, sethostname. */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 296
+#define CYGWIN_VERSION_API_MINOR 297
 
      /* There is also a compatibity version number associated with the
 	shared memory regions.  It is incremented when incompatible
diff --git a/winsup/cygwin/math.h b/winsup/cygwin/math.h
new file mode 100644
index 000000000..d30ecf9e2
--- /dev/null
+++ b/winsup/cygwin/math.h
@@ -0,0 +1,43 @@
+#ifndef _LOCAL_MATH_H_
+#define _LOCAL_MATH_H_
+
+/* This header is required to define the types used by some of the
+   mingw-w64 based files in the math subdir. */
+
+typedef union __mingw_dbl_type_t {
+  double x;
+  unsigned long long val;
+  struct {
+    unsigned int low, high;
+  } lh;
+} __mingw_dbl_type_t;
+
+typedef union __mingw_flt_type_t {
+  float x;
+  unsigned int val;
+} __mingw_flt_type_t;
+
+typedef union __mingw_ldbl_type_t
+{
+  long double x;
+  struct {
+    unsigned int low, high;
+    int sign_exponent : 16;
+    int res1 : 16;
+    int res0 : 32;
+  } lh;
+} __mingw_ldbl_type_t;
+
+typedef union __mingw_fp_types_t
+{
+  long double *ld;
+  double *d;
+  float *f;
+  __mingw_ldbl_type_t *ldt;
+  __mingw_dbl_type_t *dt;
+  __mingw_flt_type_t *ft;
+} __mingw_fp_types_t;
+
+#include_next <math.h>
+
+#endif /* _LOCAL_MATH_H_ */
diff --git a/winsup/cygwin/math/DISCLAIMER.PD b/winsup/cygwin/math/DISCLAIMER.PD
new file mode 100644
index 000000000..6c2a7c3bb
--- /dev/null
+++ b/winsup/cygwin/math/DISCLAIMER.PD
@@ -0,0 +1,9 @@
+/**
+ * DISCLAIMER
+ * This file has no copyright assigned and is placed in the Public Domain.
+ *
+ * Its code is distributed in the hope that it will be useful but WITHOUT
+ * ANY WARRANTY.  ALL WARRANTIES, EXPRESSED OR IMPLIED ARE HEREBY DISCLAIMED.
+ * This includes but is not limited to warranties of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ */
diff --git a/winsup/cygwin/math/acosh.def.h b/winsup/cygwin/math/acosh.def.h
new file mode 100644
index 000000000..c039bd8eb
--- /dev/null
+++ b/winsup/cygwin/math/acosh.def.h
@@ -0,0 +1,70 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+#include "fastmath.h"
+
+__FLT_TYPE
+__FLT_ABI(acosh) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN || x < __FLT_CST(1.0))
+    {
+      __FLT_RPT_DOMAIN ("acosh", x, 0.0, __FLT_NAN);
+      return __FLT_NAN;
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      __FLT_RPT_DOMAIN ("acosh", x, 0.0, __FLT_NAN);
+      return __FLT_NAN;
+    }
+
+  if (x > __FLT_CST(0x1p32))
+    return __FLT_ABI (__fast_log) (x) + 6.9314718055994530941723E-1L;
+
+  return __FLT_ABI (__fast_log) (x +
+   __FLT_ABI (__fast_sqrt) ((x + __FLT_CST(1.0)) * (x - __FLT_CST(1.0))));
+}
+
diff --git a/winsup/cygwin/math/acoshl.c b/winsup/cygwin/math/acoshl.c
new file mode 100644
index 000000000..88f9f130e
--- /dev/null
+++ b/winsup/cygwin/math/acoshl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "acosh.def.h"
diff --git a/winsup/cygwin/math/acosl.c b/winsup/cygwin/math/acosl.c
new file mode 100644
index 000000000..511b5def2
--- /dev/null
+++ b/winsup/cygwin/math/acosl.c
@@ -0,0 +1,22 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double acosl (long double x);
+
+long double acosl (long double x)
+{
+  long double res = 0.0L;
+
+  /* acosl = atanl (sqrtl(1 - x^2) / x) */
+  asm (	"fld	%%st\n\t"
+	"fmul	%%st(0)\n\t"		/* x^2 */
+	"fld1\n\t"
+	"fsubp\n\t"			/* 1 - x^2 */
+	"fsqrt\n\t"			/* sqrtl (1 - x^2) */
+	"fxch	%%st(1)\n\t"
+	"fpatan"
+	: "=t" (res) : "0" (x) : "st(1)");
+  return res;
+}
diff --git a/winsup/cygwin/math/asinhl.c b/winsup/cygwin/math/asinhl.c
new file mode 100644
index 000000000..bb2ca97b2
--- /dev/null
+++ b/winsup/cygwin/math/asinhl.c
@@ -0,0 +1,33 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+#include <errno.h>
+#include "fastmath.h"
+
+ /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
+long double asinhl(long double x)
+{
+  long double z;
+  if (!isfinite (x))
+    return x;
+
+  z = fabsl (x);
+
+  /* Avoid setting FPU underflow exception flag in x * x. */
+#if 0
+  if ( z < 0x1p-32)
+    return x;
+#endif
+
+  /* Use log1p to avoid cancellation with small x. Put
+     x * x in denom, so overflow is harmless. 
+     asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0)
+              = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0))  */
+
+  z = __fast_log1pl (z + z * z / (__fast_sqrtl (z * z + 1.0L) + 1.0L));
+
+  return ( x > 0.0 ? z : -z);
+}
diff --git a/winsup/cygwin/math/asinl.c b/winsup/cygwin/math/asinl.c
new file mode 100644
index 000000000..a4d8746be
--- /dev/null
+++ b/winsup/cygwin/math/asinl.c
@@ -0,0 +1,27 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for long double type by Danny Smith <dannysmith@users.sourceforge.net>.
+ */
+
+/* asin = atan (x / sqrt(1 - x^2)) */
+long double asinl (long double x);
+
+long double asinl (long double x)
+{
+  long double res = 0.0L;
+
+  asm (	"fld	%%st\n\t"
+	"fmul	%%st(0)\n\t"			/* x^2 */
+	"fld1\n\t"
+	"fsubp\n\t"				/* 1 - x^2 */
+	"fsqrt\n\t"				/* sqrt (1 - x^2) */
+	"fpatan"
+	: "=t" (res) : "0" (x) : "st(1)");
+  return res;
+}
diff --git a/winsup/cygwin/math/atan2l.c b/winsup/cygwin/math/atan2l.c
new file mode 100644
index 000000000..a32b097fb
--- /dev/null
+++ b/winsup/cygwin/math/atan2l.c
@@ -0,0 +1,14 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double atan2l (long double y, long double x);
+
+long double
+atan2l (long double y, long double x)
+{
+  long double res = 0.0L;
+  asm ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
+  return res;
+}
diff --git a/winsup/cygwin/math/atanhl.c b/winsup/cygwin/math/atanhl.c
new file mode 100644
index 000000000..59eb1bd91
--- /dev/null
+++ b/winsup/cygwin/math/atanhl.c
@@ -0,0 +1,34 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+#include <errno.h>
+#include "fastmath.h"
+
+/* atanh (x) = 0.5 * log ((1.0 + x)/(1.0 - x)) */
+long double atanhl (long double x)
+{
+  long double z;
+  if (isnan (x))
+    return x;
+  z = fabsl (x);
+  if (z == 1.0L)
+    {
+      errno  = ERANGE;
+      return (x > 0 ? INFINITY : -INFINITY);
+    }
+  if ( z > 1.0L)
+    {
+      errno = EDOM;
+      return nanl("");
+    }
+  /* Rearrange formula to avoid precision loss for small x.
+  atanh(x) = 0.5 * log ((1.0 + x)/(1.0 - x))
+ 	   = 0.5 * log1p ((1.0 + x)/(1.0 - x) - 1.0)
+           = 0.5 * log1p ((1.0 + x - 1.0 + x) /(1.0 - x)) 
+           = 0.5 * log1p ((2.0 * x ) / (1.0 - x))  */
+  z = 0.5L * __fast_log1pl ((z + z) / (1.0L - z));
+  return x >= 0 ? z : -z;
+}
diff --git a/winsup/cygwin/math/atanl.c b/winsup/cygwin/math/atanl.c
new file mode 100644
index 000000000..b85d05350
--- /dev/null
+++ b/winsup/cygwin/math/atanl.c
@@ -0,0 +1,17 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double atanl (long double x);
+
+long double
+atanl (long double x)
+{
+  long double res = 0.0L;
+
+  asm ("fld1\n\t"
+       "fpatan"
+       : "=t" (res) : "0" (x));
+  return res;
+}
diff --git a/winsup/cygwin/math/cabs.def.h b/winsup/cygwin/math/cabs.def.h
new file mode 100644
index 000000000..b3ea09764
--- /dev/null
+++ b/winsup/cygwin/math/cabs.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __cdecl
+__FLT_ABI(cabs) (__FLT_TYPE __complex__ z)
+{
+  return __FLT_ABI(hypot) (__real__ z, __imag__ z);
+}
diff --git a/winsup/cygwin/math/cabsl.c b/winsup/cygwin/math/cabsl.c
new file mode 100644
index 000000000..c750e877d
--- /dev/null
+++ b/winsup/cygwin/math/cabsl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "cabs.def.h"
diff --git a/winsup/cygwin/math/cacos.def.h b/winsup/cygwin/math/cacos.def.h
new file mode 100644
index 000000000..300faffac
--- /dev/null
+++ b/winsup/cygwin/math/cacos.def.h
@@ -0,0 +1,57 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(cacos) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE x;
+  __complex__ __FLT_TYPE ret;
+
+  x = __FLT_ABI(casin) (z);
+
+  __real__ ret = (__FLT_TYPE) __FLT_PI_2 - __real__ x;
+  __imag__ ret = -__imag__ x;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/cacosh.def.h b/winsup/cygwin/math/cacosh.def.h
new file mode 100644
index 000000000..f4ea2da07
--- /dev/null
+++ b/winsup/cygwin/math/cacosh.def.h
@@ -0,0 +1,100 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(cacosh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (i_class == FP_INFINITE)
+  {
+    __real__ ret = __FLT_HUGE_VAL;
+    __imag__ ret = (r_class == FP_NAN ? __FLT_NAN : __FLT_ABI(copysign) (
+      (r_class == FP_INFINITE ? (__real__ z < __FLT_CST(0.0) ? __FLT_PI_3_4 : __FLT_PI_4) : __FLT_PI_2), __imag__ z));
+    return ret;
+  }
+
+  if (r_class == FP_INFINITE)
+  {
+    __real__ ret = __FLT_HUGE_VAL;
+    __imag__ ret = ((i_class != FP_NAN && i_class != FP_INFINITE)
+      ? __FLT_ABI(copysign) (signbit (__real__ z) ? __FLT_PI : __FLT_CST(0.0), __imag__ z) : __FLT_NAN);
+    return ret;
+  }
+
+  if (r_class == FP_NAN || i_class == FP_NAN)
+  {
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  if (r_class == FP_ZERO && i_class == FP_ZERO)
+  {
+    __real__ ret = __FLT_CST(0.0);
+    __imag__ ret = __FLT_ABI(copysign) (__FLT_PI_2, __imag__ z);
+    return ret;
+  }
+
+  __real__ x = (__real__ z - __imag__ z) * (__real__ z + __imag__ z) - __FLT_CST(1.0);
+  __imag__ x = __FLT_CST(2.0) * __real__ z * __imag__ z;
+
+  x = __FLT_ABI(csqrt) (x);
+
+  if (__real__ z < __FLT_CST(0.0))
+    x = -x;
+
+  __real__ x += __real__ z;
+  __imag__ x += __imag__ z;
+
+  ret = __FLT_ABI(clog) (x);
+
+  if (__real__ ret < __FLT_CST(0.0))
+    ret = -ret;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/cacosl.c b/winsup/cygwin/math/cacosl.c
new file mode 100644
index 000000000..7a8df652d
--- /dev/null
+++ b/winsup/cygwin/math/cacosl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "cacosh.def.h"
+#include "cacos.def.h"
diff --git a/winsup/cygwin/math/carg.def.h b/winsup/cygwin/math/carg.def.h
new file mode 100644
index 000000000..2ccf84189
--- /dev/null
+++ b/winsup/cygwin/math/carg.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __cdecl
+__FLT_ABI(carg) (__FLT_TYPE __complex__ z)
+{
+  return __FLT_ABI(atan2) (__imag__ z, __real__ z);
+}
diff --git a/winsup/cygwin/math/cargl.c b/winsup/cygwin/math/cargl.c
new file mode 100644
index 000000000..e70f580ea
--- /dev/null
+++ b/winsup/cygwin/math/cargl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "carg.def.h"
diff --git a/winsup/cygwin/math/casin.def.h b/winsup/cygwin/math/casin.def.h
new file mode 100644
index 000000000..808c1bef0
--- /dev/null
+++ b/winsup/cygwin/math/casin.def.h
@@ -0,0 +1,61 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(casin) (__FLT_TYPE __complex__ z)
+{
+  /* Annex G.6: casin(z) = -i casinh (iz) */
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+
+  __real__ x = -__imag__ z;
+  __imag__ x = __real__ z;
+
+  x = __FLT_ABI(casinh) (x);
+
+  __real__ ret = __imag__ x;
+  __imag__ ret = -__real__ x;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/casinh.def.h b/winsup/cygwin/math/casinh.def.h
new file mode 100644
index 000000000..050d885a0
--- /dev/null
+++ b/winsup/cygwin/math/casinh.def.h
@@ -0,0 +1,99 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(casinh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (i_class == FP_INFINITE)
+  {
+    __real__ ret = __FLT_ABI(copysign) (__FLT_HUGE_VAL, __real__ z);
+    __imag__ ret = (r_class == FP_NAN
+      ? __FLT_NAN
+      : (__FLT_ABI(copysign) ((r_class != FP_NAN && r_class != FP_INFINITE) ? __FLT_PI_2 : __FLT_PI_4, __imag__ z)));
+    return ret;
+  }
+
+  if (r_class == FP_INFINITE)
+  {
+    __real__ ret = __real__ z;
+    __imag__ ret = (i_class != FP_NAN
+      ? __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z)
+      : __FLT_NAN);
+    return ret;
+  }
+
+  if (r_class == FP_NAN)
+  {
+    __real__ ret = __real__ z;
+    __imag__ ret = (i_class == FP_ZERO
+      ? __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z)
+      : __FLT_NAN);
+    return ret;
+  }
+
+  if (i_class == FP_NAN)
+  {
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  if (r_class == FP_ZERO && i_class == FP_ZERO)
+    return z;
+
+  __real__ x = (__real__ z - __imag__ z) * (__real__ z + __imag__ z) + __FLT_CST(1.0);
+  __imag__ x = __FLT_CST(2.0) * __real__ z * __imag__ z;
+
+  x = __FLT_ABI(csqrt) (x);
+
+  __real__ x += __real__ z;
+  __imag__ x += __imag__ z;
+
+  return __FLT_ABI(clog) (x);
+}
diff --git a/winsup/cygwin/math/casinl.c b/winsup/cygwin/math/casinl.c
new file mode 100644
index 000000000..1d7e24785
--- /dev/null
+++ b/winsup/cygwin/math/casinl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "casinh.def.h"
+#include "casin.def.h"
diff --git a/winsup/cygwin/math/catan.def.h b/winsup/cygwin/math/catan.def.h
new file mode 100644
index 000000000..19db6b78b
--- /dev/null
+++ b/winsup/cygwin/math/catan.def.h
@@ -0,0 +1,61 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(catan) (__FLT_TYPE __complex__ z)
+{
+  /* Annex G.6: catan(z) = -i catanh (iz) */
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+
+  __real__ x = -__imag__ z;
+  __imag__ x = __real__ z;
+
+  x = __FLT_ABI(catanh) (x);
+
+  __real__ ret = __imag__ x;
+  __imag__ ret = -__real__ x;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/catanh.def.h b/winsup/cygwin/math/catanh.def.h
new file mode 100644
index 000000000..68949d139
--- /dev/null
+++ b/winsup/cygwin/math/catanh.def.h
@@ -0,0 +1,93 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(catanh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE i2, n, d;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_INFINITE || r_class == FP_NAN || i_class == FP_INFINITE || i_class == FP_NAN)
+  {
+    if (i_class == FP_INFINITE)
+    {
+      __real__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __real__ z);
+      __imag__ ret = __FLT_ABI(copysign) (__FLT_PI_2, __imag__ z);
+      return ret;
+    }
+
+    if (r_class == FP_INFINITE || r_class == FP_ZERO)
+    {
+      __real__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __real__ z);
+      __imag__ ret = ((i_class != FP_NAN && i_class != FP_INFINITE)
+        ? __FLT_ABI(copysign) (__FLT_PI_2, __imag__ z) : __FLT_NAN);
+      return ret;
+    }
+
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  if (r_class == FP_ZERO && i_class == FP_ZERO)
+    return z;
+
+  i2 = __imag__ z * __imag__ z;
+
+  n = __FLT_CST(1.0) + __real__ z;
+  n = i2 + n * n;
+
+  d = __FLT_CST(1.0) - __real__ z;
+  d = i2 + d * d;
+
+  __real__ ret = __FLT_CST(0.25) * (__FLT_ABI(log) (n) - __FLT_ABI(log) (d));
+
+  d = 1 - __real__ z * __real__ z - i2;
+
+  __imag__ ret = __FLT_CST(0.5) * __FLT_ABI(atan2) (__FLT_CST(2.0) * __imag__ z, d);
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/catanl.c b/winsup/cygwin/math/catanl.c
new file mode 100644
index 000000000..9c1ccdfcb
--- /dev/null
+++ b/winsup/cygwin/math/catanl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "catanh.def.h"
+#include "catan.def.h"
diff --git a/winsup/cygwin/math/cbrtl.c b/winsup/cygwin/math/cbrtl.c
new file mode 100644
index 000000000..95074e964
--- /dev/null
+++ b/winsup/cygwin/math/cbrtl.c
@@ -0,0 +1,80 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+static const long double CBRT2  = 1.2599210498948731647672L;
+static const long double CBRT4  = 1.5874010519681994747517L;
+static const long double CBRT2I = 0.79370052598409973737585L;
+static const long double CBRT4I = 0.62996052494743658238361L;
+
+long double cbrtl(long double x)
+{
+	int e, rem, sign;
+	long double z;
+
+	if (!isfinite (x) || x == 0.0L)
+		return (x);
+
+	if (x > 0)
+		sign = 1;
+	else
+	{
+		sign = -1;
+		x = -x;
+	}
+
+	z = x;
+	/* extract power of 2, leaving
+	 * mantissa between 0.5 and 1
+	 */
+	x = frexpl(x, &e);
+
+	/* Approximate cube root of number between .5 and 1,
+	 * peak relative error = 1.2e-6
+	 */
+	x = (((( 1.3584464340920900529734e-1L * x
+	       - 6.3986917220457538402318e-1L) * x
+	       + 1.2875551670318751538055e0L) * x
+	       - 1.4897083391357284957891e0L) * x
+	       + 1.3304961236013647092521e0L) * x
+	       + 3.7568280825958912391243e-1L;
+
+	/* exponent divided by 3 */
+	if (e >= 0)
+	{
+		rem = e;
+		e /= 3;
+		rem -= 3*e;
+		if (rem == 1)
+			x *= CBRT2;
+		else if (rem == 2)
+			x *= CBRT4;
+	}
+	else
+	{ /* argument less than 1 */
+		e = -e;
+		rem = e;
+		e /= 3;
+		rem -= 3*e;
+		if (rem == 1)
+			x *= CBRT2I;
+		else if (rem == 2)
+			x *= CBRT4I;
+		e = -e;
+	}
+
+	/* multiply by power of 2 */
+	x = ldexpl(x, e);
+
+	/* Newton iteration */
+
+	x -= ( x - (z/(x*x)) )*0.3333333333333333333333L;
+	x -= ( x - (z/(x*x)) )*0.3333333333333333333333L;
+
+	if (sign < 0)
+		x = -x;
+	return (x);
+}
diff --git a/winsup/cygwin/math/ccos.def.h b/winsup/cygwin/math/ccos.def.h
new file mode 100644
index 000000000..2e7472cd9
--- /dev/null
+++ b/winsup/cygwin/math/ccos.def.h
@@ -0,0 +1,54 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(ccos) (__FLT_TYPE __complex__ z)
+{
+  /* Annex G.6, ccos(z) = ccosh(iz) */
+  __complex__ __FLT_TYPE x;
+  __real__ x = -__imag__ z;
+  __imag__ x = __real__ z;
+
+  return __FLT_ABI(ccosh) (x);
+}
diff --git a/winsup/cygwin/math/ccosh.def.h b/winsup/cygwin/math/ccosh.def.h
new file mode 100644
index 000000000..c18d657bf
--- /dev/null
+++ b/winsup/cygwin/math/ccosh.def.h
@@ -0,0 +1,95 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(ccosh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE s_x, c_x;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_NAN)
+  {
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __imag__ z == __FLT_CST(0.0) ? __imag__ z : __FLT_NAN;
+    return ret;
+  }
+
+  if (r_class == FP_INFINITE)
+  {
+    if (i_class == FP_ZERO)
+    {
+      __real__ ret = __FLT_HUGE_VAL;
+      __imag__ ret = __imag__ z * __FLT_ABI(copysign) (__FLT_CST(1.0), __real__ z);
+      return ret;
+    }
+
+    if (i_class == FP_NAN || i_class == FP_INFINITE)
+    {
+      __real__ ret = __FLT_HUGE_VAL;
+      __imag__ ret = __FLT_NAN + __FLT_NAN;
+      return ret;
+    }
+
+    __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+    __real__ ret = __FLT_ABI(copysign) (__FLT_HUGE_VAL, c_x);
+    __imag__ ret = (__FLT_ABI(copysign) (__FLT_HUGE_VAL, s_x) * __FLT_ABI(copysign) (__FLT_CST(1.0), __real__ z));
+    return ret;
+  }
+
+  if (i_class == FP_NAN || i_class == FP_INFINITE)
+  {
+    __imag__ ret = __real__ z == __FLT_CST(0.0) ? __FLT_CST(0.0) : __FLT_NAN;
+    __real__ ret = __FLT_NAN + __FLT_NAN;
+    return ret;
+  }
+
+  __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+  __real__ ret = __FLT_ABI(cosh) (__real__ z) * c_x;
+  __imag__ ret = __FLT_ABI(sinh) (__real__ z) * s_x;
+  return ret;
+}
diff --git a/winsup/cygwin/math/ccosl.c b/winsup/cygwin/math/ccosl.c
new file mode 100644
index 000000000..594a4d1de
--- /dev/null
+++ b/winsup/cygwin/math/ccosl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "ccosh.def.h"
+#include "ccos.def.h"
diff --git a/winsup/cygwin/math/ceil.S b/winsup/cygwin/math/ceil.S
new file mode 100644
index 000000000..636df1e30
--- /dev/null
+++ b/winsup/cygwin/math/ceil.S
@@ -0,0 +1,124 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"ceil.S"
+	.text
+	.align 4
+	.globl __MINGW_USYMBOL(ceil)
+	.def	__MINGW_USYMBOL(ceil);	.scl	2;	.type	32;	.endef
+#ifdef __x86_64__
+	.seh_proc	__MINGW_USYMBOL(ceil)
+#endif
+
+__MINGW_USYMBOL(ceil):
+#if defined(_AMD64_) || defined(__x86_64__)
+	.seh_endprologue
+	movd %xmm0, %rax
+	movq	%rax, %rcx
+	sarq	$52, %rcx
+	andl	$2047, %ecx
+	subl	$1023, %ecx
+	cmpl	$51, %ecx
+	jg	.is_intnaninf
+	/* Is x zero? */
+	testq	%rax, %rax
+	je	.ret_org
+	/* Is x signed? */
+	testl	%ecx, %ecx
+	js	.signed_val
+	/* Is x integral? */
+	movabsq	$4503599627370495, %rdx
+	sarq	%cl, %rdx
+	testq	%rax, %rdx
+	je	.ret_org
+	addsd	.huge(%rip), %xmm0
+	ucomisd	.zero(%rip), %xmm0
+	jbe	.doret
+	testq	%rax, %rax
+	jle	.l1
+	/* inexact ... */
+	movabsq	$4503599627370496, %r8
+	shrq	%cl, %r8
+	addq	%r8, %rax
+.l1:
+	notq	%rdx
+	andq	%rdx, %rax
+.doret:
+	movd %rax, %xmm0
+	ret
+	.p2align 4,,10
+.signed_val:
+	addsd	.huge(%rip), %xmm0
+	ucomisd	.zero(%rip), %xmm0
+	jbe	.doret2
+	testq	%rax, %rax
+	movabsq	$4607182418800017408, %rdx
+	movabsq	$-9223372036854775808, %rax
+	cmovns	%rdx, %rax
+	.p2align 4,,10
+.doret2:
+	movd %rax, %xmm0
+	ret
+
+	.p2align 4,,10
+.is_intnaninf:
+	/* Is Nan or Inf? */
+	cmpl	$1024, %ecx
+	je	.ret_naninf
+	.p2align 4,,10
+.ret_org:
+	/* return x.  */
+	rep
+	ret
+	.p2align 4,,10
+.ret_naninf:
+	/* return x + x; */
+	addsd	%xmm0, %xmm0
+	ret
+	.seh_endproc
+
+/* local data.  */
+	.section .rdata,"dr"
+	.align 8
+.huge:
+	.long	-2013235812
+	.long	2117592124
+	.align 8
+.zero:
+	.long	0
+	.long	0
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	bic		r0, r1, #0x00c00000
+	orr		r0, r0, #0x00400000 /* Round towards Plus Infinity */
+	vmsr	fpscr, r0
+	vcvtr.s32.f64	s0, d0
+	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	fldl	4(%esp)
+	subl	$8,%esp
+
+	fstcw	4(%esp)			/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x0800,%edx		/* round towards +oo */
+	orl	4(%esp),%edx
+	andl	$0xfbff,%edx
+	movl	%edx,(%esp)
+	fldcw	(%esp)			/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	4(%esp)			/* restore original control word */
+
+	addl	$8,%esp
+	ret
+#endif
diff --git a/winsup/cygwin/math/ceilf.S b/winsup/cygwin/math/ceilf.S
new file mode 100644
index 000000000..605c7bffa
--- /dev/null
+++ b/winsup/cygwin/math/ceilf.S
@@ -0,0 +1,120 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"ceilf.S"
+	.text
+	.align 4
+	.globl __MINGW_USYMBOL(ceilf)
+	.def	__MINGW_USYMBOL(ceilf);	.scl	2;	.type	32;	.endef
+#ifdef __x86_64__
+	.seh_proc	__MINGW_USYMBOL(ceilf)
+#endif
+
+__MINGW_USYMBOL(ceilf):
+#if defined(_AMD64_) || defined(__x86_64__)
+        subq    $24, %rsp
+        .seh_stackalloc 24
+        .seh_endprologue
+        movd    %xmm0, 12(%rsp)
+        movl    12(%rsp), %eax
+        movl    %eax, %ecx
+        movl    %eax, %edx
+        sarl    $23, %ecx
+        andl    $255, %ecx
+        subl    $127, %ecx
+        cmpl    $22, %ecx
+        jg      .l4
+        testl   %ecx, %ecx
+        js      .l5
+        movl    $8388607, %r8d
+        sarl    %cl, %r8d
+        testl   %eax, %r8d
+        je      .l3
+        addss   .hugeval(%rip), %xmm0
+        ucomiss .zeroval(%rip), %xmm0
+        jbe     .l2
+        testl   %eax, %eax
+        jle     .l1
+        movl    $8388608, %eax
+        sarl    %cl, %eax
+        addl    %eax, %edx
+.l1:
+        movl    %r8d, %eax
+        notl    %eax
+        andl    %edx, %eax
+.l2:
+        movl    %eax, 8(%rsp)
+        movss   8(%rsp), %xmm0
+.l3:
+        addq    $24, %rsp
+        ret
+        .p2align 4,,10
+.l4:
+        addl    $-128, %ecx
+        jne     .l3
+        addss   %xmm0, %xmm0
+        addq    $24, %rsp
+        ret
+        .p2align 4,,10
+.l5:
+        addss   .hugeval(%rip), %xmm0
+        ucomiss .zeroval(%rip), %xmm0
+        jbe     .islesseqzero
+        testl   %eax, %eax
+        js      .l6
+        movl    $1065353216, %edx
+        cmovne  %edx, %eax
+.islesseqzero:
+        movl    %eax, 8(%rsp)
+        movss   8(%rsp), %xmm0
+        addq    $24, %rsp
+        ret
+        .p2align 4,,10
+.l6:
+        movl    $-2147483648, 8(%rsp)
+        movss   8(%rsp), %xmm0
+        addq    $24, %rsp
+        ret
+        .seh_endproc
+        .section .rdata,"dr"
+        .align 4
+.hugeval:
+        .long   1900671690
+        .align 4
+.zeroval:
+        .long   0
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	bic		r0, r1, #0x00c00000
+	orr		r0, r0, #0x00400000 /* Round towards Plus Infinity */
+	vmsr	fpscr, r0
+	vcvt.s32.f32	s0, s0
+	vcvt.f32.s32	s0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	flds	4(%esp)
+	subl	$8,%esp
+
+	fstcw	4(%esp)			/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x0800,%edx		/* round towards +oo */
+	orl	4(%esp),%edx
+	andl	$0xfbff,%edx
+	movl	%edx,(%esp)
+	fldcw	(%esp)			/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	4(%esp)			/* restore original control word */
+
+	addl	$8,%esp
+	ret
+#endif
diff --git a/winsup/cygwin/math/ceill.S b/winsup/cygwin/math/ceill.S
new file mode 100644
index 000000000..61d619929
--- /dev/null
+++ b/winsup/cygwin/math/ceill.S
@@ -0,0 +1,64 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"ceill.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	.globl __MINGW_USYMBOL(ceill)
+	.def	__MINGW_USYMBOL(ceill);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(ceill):
+#if defined(_AMD64_) || defined(__x86_64__)
+	fldt	(%rdx)
+	subq	$24,%rsp
+
+	fstcw	8(%rsp)			/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x0800,%edx		/* round towards +oo */
+	orl	8(%rsp),%edx
+	andl	$0xfbff,%edx
+	movl	%edx,(%rsp)
+	fldcw	(%rsp)			/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	8(%rsp)			/* restore original control word */
+
+	addq	$24,%rsp
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	bic		r0, r1, #0x00c00000
+	orr		r0, r0, #0x00400000 /* Round towards Plus Infinity */
+	vmsr	fpscr, r0
+	vcvtr.s32.f64	s0, d0
+	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	fldt	4(%esp)
+	subl	$8,%esp
+	fstcw	4(%esp)
+	movl	$0x0800,%edx
+	orl	4(%esp),%edx
+	andl	$0xfbff,%edx
+	movl	%edx,(%esp)
+	fldcw	(%esp)
+	frndint
+	fldcw	4(%esp)
+	addl $8,%esp
+	ret
+#endif
diff --git a/winsup/cygwin/math/cephes_emath.c b/winsup/cygwin/math/cephes_emath.c
new file mode 100644
index 000000000..8fb44346c
--- /dev/null
+++ b/winsup/cygwin/math/cephes_emath.c
@@ -0,0 +1,1283 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_emath.h"
+
+/*
+ * The constants are for 64 bit precision.
+ */
+
+
+/* Move in external format number,
+ * converting it to internal format.
+ */
+void __emovi(const short unsigned int * __restrict__ a,
+	     short unsigned int * __restrict__ b)
+{
+	register const unsigned short *p;
+	register unsigned short *q;
+	int i;
+
+	q = b;
+	p = a + (NE-1);	/* point to last word of external number */
+	/* get the sign bit */
+	if (*p & 0x8000)
+		*q++ = 0xffff;
+	else
+		*q++ = 0;
+	/* get the exponent */
+	*q = *p--;
+	*q++ &= 0x7fff;	/* delete the sign bit */
+#ifdef INFINITY
+	if ((*(q - 1) & 0x7fff) == 0x7fff)
+	{
+#ifdef NANS
+		if (__eisnan(a))
+		{
+			*q++ = 0;
+			for (i = 3; i < NI; i++ )
+				*q++ = *p--;
+			return;
+		}
+#endif
+		for (i = 2; i < NI; i++)
+			*q++ = 0;
+		return;
+	}
+#endif
+	/* clear high guard word */
+	*q++ = 0;
+	/* move in the significand */
+	for (i = 0; i < NE - 1; i++ )
+		*q++ = *p--;
+	/* clear low guard word */
+	*q = 0;
+}
+
+
+/*
+;	Add significands
+;	x + y replaces y
+*/
+
+void __eaddm(const short unsigned int * __restrict__ x,
+		  short unsigned int * __restrict__ y)
+{
+	register unsigned long a;
+	int i;
+	unsigned int carry;
+
+	x += NI - 1;
+	y += NI - 1;
+	carry = 0;
+	for (i = M; i < NI; i++)
+	{
+		a = (unsigned long)(*x) + (unsigned long)(*y) + carry;
+		if (a & 0x10000)
+			carry = 1;
+		else
+			carry = 0;
+		*y = (unsigned short)a;
+		--x;
+		--y;
+	}
+}
+
+/*
+;	Subtract significands
+;	y - x replaces y
+*/
+
+void __esubm(const short unsigned int * __restrict__ x,
+		  short unsigned int * __restrict__ y)
+{
+	unsigned long a;
+	int i;
+	unsigned int carry;
+
+	x += NI - 1;
+	y += NI - 1;
+	carry = 0;
+	for (i = M; i < NI; i++)
+	{
+		a = (unsigned long)(*y) - (unsigned long)(*x) - carry;
+		if (a & 0x10000)
+			carry = 1;
+		else
+			carry = 0;
+		*y = (unsigned short)a;
+		--x;
+		--y;
+	}
+}
+
+
+/* Multiply significand of e-type number b
+by 16-bit quantity a, e-type result to c. */
+
+static void __m16m(short unsigned int a,
+		   short unsigned int *  __restrict__ b,
+		   short unsigned int *  __restrict__ c)
+{
+	register unsigned short *pp;
+	register unsigned long carry;
+	unsigned short *ps;
+	unsigned short p[NI];
+	unsigned long aa, m;
+	int i;
+
+	aa = a;
+	pp = &p[NI - 2];
+	*pp++ = 0;
+	*pp = 0;
+	ps = &b[NI - 1];
+
+	for(i = M + 1; i < NI; i++)
+	{
+		if (*ps == 0)
+		{
+			--ps;
+			--pp;
+			*(pp - 1) = 0;
+		}
+		else
+		{
+			m = (unsigned long) aa * *ps--;
+			carry = (m & 0xffff) + *pp;
+			*pp-- = (unsigned short)carry;
+			carry = (carry >> 16) + (m >> 16) + *pp;
+			*pp = (unsigned short)carry;
+			*(pp - 1) = carry >> 16;
+		}
+	}
+	for (i = M; i < NI; i++)
+	c[i] = p[i];
+}
+
+
+/* Divide significands. Neither the numerator nor the denominator
+is permitted to have its high guard word nonzero.  */
+
+int __edivm(short unsigned int * __restrict__ den,
+		 short unsigned int * __restrict__ num)
+{
+	int i;
+	register unsigned short *p;
+	unsigned long tnum;
+	unsigned short j, tdenm, tquot;
+	unsigned short tprod[NI + 1];
+	unsigned short equot[NI];
+
+	p = &equot[0];
+	*p++ = num[0];
+	*p++ = num[1];
+
+	for (i = M; i < NI; i++)
+	{
+		*p++ = 0;
+	}
+	__eshdn1(num);
+	tdenm = den[M + 1];
+	for (i = M; i < NI; i++)
+	{
+		/* Find trial quotient digit (the radix is 65536). */
+		tnum = (((unsigned long) num[M]) << 16) + num[M + 1];
+
+		/* Do not execute the divide instruction if it will overflow. */
+		if ((tdenm * 0xffffUL) < tnum)
+			tquot = 0xffff;
+		else
+			tquot = tnum / tdenm;
+
+		/* Prove that the divide worked. */
+		/*
+		tcheck = (unsigned long)tquot * tdenm;
+		if (tnum - tcheck > tdenm)
+			tquot = 0xffff;
+		*/
+		/* Multiply denominator by trial quotient digit. */
+		__m16m(tquot, den, tprod);
+		/* The quotient digit may have been overestimated. */
+		if (__ecmpm(tprod, num) > 0)
+		{
+			tquot -= 1;
+			__esubm(den, tprod);
+			if(__ecmpm(tprod, num) > 0)
+			{
+				tquot -= 1;
+				__esubm(den, tprod);
+			}
+		}
+		__esubm(tprod, num);
+		equot[i] = tquot;
+		__eshup6(num);
+	}
+	/* test for nonzero remainder after roundoff bit */
+	p = &num[M];
+	j = 0;
+	for (i = M; i < NI; i++)
+	{
+		j |= *p++;
+	}
+	if (j)
+		j = 1;
+
+	for (i = 0; i < NI; i++)
+		num[i] = equot[i];
+
+	return ( (int)j );
+}
+
+
+/* Multiply significands */
+int __emulm(const short unsigned int * __restrict__ a,
+		 short unsigned int * __restrict__ b)
+{
+	const unsigned short *p;
+	unsigned short *q;
+	unsigned short pprod[NI];
+	unsigned short equot[NI];
+	unsigned short j;
+	int i;
+
+	equot[0] = b[0];
+	equot[1] = b[1];
+	for (i = M; i < NI; i++)
+		equot[i] = 0;
+
+	j = 0;
+	p = &a[NI - 1];
+	q = &equot[NI - 1];
+	for (i = M + 1; i < NI; i++)
+	{
+		if (*p == 0)
+		{
+			--p;
+		}
+		else
+		{
+			__m16m(*p--, b, pprod);
+			__eaddm(pprod, equot);
+		}
+		j |= *q;
+		__eshdn6(equot);
+	}
+
+	for (i = 0; i < NI; i++)
+		b[i] = equot[i];
+
+	/* return flag for lost nonzero bits */
+	return ( (int)j );
+}
+
+
+/*
+ * Normalize and round off.
+ *
+ * The internal format number to be rounded is "s".
+ * Input "lost" indicates whether the number is exact.
+ * This is the so-called sticky bit.
+ *
+ * Input "subflg" indicates whether the number was obtained
+ * by a subtraction operation.  In that case if lost is nonzero
+ * then the number is slightly smaller than indicated.
+ *
+ * Input "expo" is the biased exponent, which may be negative.
+ * the exponent field of "s" is ignored but is replaced by
+ * "expo" as adjusted by normalization and rounding.
+ *
+ * Input "rcntrl" is the rounding control.
+ *
+ * Input "rnprc" is precison control (64 or NBITS).
+ */
+
+void __emdnorm(short unsigned int *s, int lost, int subflg, int expo, int rcntrl, int rndprc)
+{
+	int i, j;
+	unsigned short r;
+	int rw = NI-1; /* low guard word */
+	int re = NI-2;
+	const unsigned short rmsk = 0xffff;
+	const unsigned short rmbit = 0x8000;
+#if NE == 6
+	unsigned short rbit[NI] = {0,0,0,0,0,0,0,1,0};
+#else
+	unsigned short rbit[NI] = {0,0,0,0,0,0,0,0,0,0,0,1,0};
+#endif
+
+	/* Normalize */
+	j = __enormlz(s);
+
+	/* a blank significand could mean either zero or infinity. */
+#ifndef INFINITY
+	if (j > NBITS)
+	{
+		__ecleazs(s);
+		return;
+	}
+#endif
+	expo -= j;
+#ifndef INFINITY
+	if (expo >= 32767)
+		goto overf;
+#else
+	if ((j > NBITS) && (expo < 32767))
+	{
+		__ecleazs(s);
+		return;
+	}
+#endif
+	if (expo < 0)
+	{
+		if (expo > (-NBITS - 1))
+		{
+			j = expo;
+			i = __eshift(s, j);
+			if (i)
+				lost = 1;
+		}
+		else
+		{
+			__ecleazs(s);
+			return;
+		}
+	}
+	/* Round off, unless told not to by rcntrl. */
+	if (rcntrl == 0)
+		goto mdfin;
+	if (rndprc == 64)
+	{
+		rw = 7;
+		re = 6;
+		rbit[NI - 2] = 0;
+		rbit[6] = 1;
+	}
+
+	/* Shift down 1 temporarily if the data structure has an implied
+	 * most significant bit and the number is denormal.
+	 * For rndprc = 64 or NBITS, there is no implied bit.
+	 * But Intel long double denormals lose one bit of significance even so.
+	 */
+#if IBMPC
+	if ((expo <= 0) && (rndprc != NBITS))
+#else
+	if ((expo <= 0) && (rndprc != 64) && (rndprc != NBITS))
+#endif
+	{
+		lost |= s[NI - 1] & 1;
+		__eshdn1(s);
+	}
+	/* Clear out all bits below the rounding bit,
+	 * remembering in r if any were nonzero.
+	 */
+	r = s[rw] & rmsk;
+	if (rndprc < NBITS)
+	{
+		i = rw + 1;
+		while (i < NI)
+		{
+			if( s[i] )
+				r |= 1;
+			s[i] = 0;
+			++i;
+		}
+	}
+	s[rw] &= (rmsk ^ 0xffff);
+	if ((r & rmbit) != 0)
+	{
+		if (r == rmbit)
+		{
+			if (lost == 0)
+			{ /* round to even */
+				if ((s[re] & 1) == 0)
+					goto mddone;
+			}
+			else
+			{
+				if (subflg != 0)
+					goto mddone;
+			}
+		}
+		__eaddm(rbit, s);
+	}
+mddone:
+#if IBMPC
+	if ((expo <= 0) && (rndprc != NBITS))
+#else
+	if ((expo <= 0) && (rndprc != 64) && (rndprc != NBITS))
+#endif
+	{
+		__eshup1(s);
+	}
+	if (s[2] != 0)
+	{ /* overflow on roundoff */
+		__eshdn1(s);
+		expo += 1;
+	}
+mdfin:
+	s[NI - 1] = 0;
+	if (expo >= 32767)
+	{
+#ifndef INFINITY
+overf:
+#endif
+#ifdef INFINITY
+		s[1] = 32767;
+		for (i = 2; i < NI - 1; i++ )
+			s[i] = 0;
+#else
+		s[1] = 32766;
+		s[2] = 0;
+		for (i = M + 1; i < NI - 1; i++)
+			s[i] = 0xffff;
+		s[NI - 1] = 0;
+		if ((rndprc < 64) || (rndprc == 113))
+			s[rw] &= (rmsk ^ 0xffff);
+#endif
+		return;
+	}
+	if (expo < 0)
+		s[1] = 0;
+	else
+		s[1] = (unsigned short)expo;
+}
+
+
+/*
+;	Multiply.
+;
+;	unsigned short a[NE], b[NE], c[NE];
+;	emul( a, b, c );	c = b * a
+*/
+void __emul(const short unsigned int *a,
+		 const short unsigned int *b,
+		 short unsigned int *c)
+{
+	unsigned short ai[NI], bi[NI];
+	int i, j;
+	long lt, lta, ltb;
+
+#ifdef NANS
+	/* NaN times anything is the same NaN. */
+	if (__eisnan(a))
+	{
+		__emov(a, c);
+		return;
+	}
+	if (__eisnan(b))
+	{
+		__emov(b, c);
+		return;
+	}
+	/* Zero times infinity is a NaN. */
+	if ((__eisinf(a) && __eiiszero(b))
+	 || (__eisinf(b) && __eiiszero(a)))
+	{
+		mtherr( "emul", DOMAIN);
+		__enan_NBITS(c);
+		return;
+	}
+#endif
+/* Infinity times anything else is infinity. */
+#ifdef INFINITY
+	if (__eisinf(a) || __eisinf(b))
+	{
+		if (__eisneg(a) ^ __eisneg(b))
+			*(c + (NE-1)) = 0x8000;
+		else
+			*(c + (NE-1)) = 0;
+		__einfin(c);
+		return;
+	}
+#endif
+	__emovi(a, ai);
+	__emovi(b, bi);
+	lta = ai[E];
+	ltb = bi[E];
+	if (ai[E] == 0)
+	{
+		for (i = 1; i < NI - 1; i++)
+		{
+			if (ai[i] != 0)
+			{
+				lta -= __enormlz( ai );
+				goto mnzer1;
+			}
+		}
+		__eclear(c);
+		return;
+	}
+mnzer1:
+
+	if (bi[E] == 0)
+	{
+		for (i = 1; i < NI - 1; i++)
+		{
+			if (bi[i] != 0)
+			{
+				ltb -= __enormlz(bi);
+				goto mnzer2;
+			}
+		}
+		__eclear(c);
+		return;
+	}
+mnzer2:
+
+	/* Multiply significands */
+	j = __emulm(ai, bi);
+	/* calculate exponent */
+	lt = lta + ltb - (EXONE - 1);
+	__emdnorm(bi, j, 0, lt, 64, NBITS);
+	/* calculate sign of product */
+	if (ai[0] == bi[0])
+		bi[0] = 0;
+	else
+		bi[0] = 0xffff;
+	__emovo(bi, c);
+}
+
+
+/* move out internal format to ieee long double */
+void __toe64(short unsigned int *a, short unsigned int *b)
+{
+	register unsigned short *p, *q;
+	unsigned short i;
+
+#ifdef NANS
+	if (__eiisnan(a))
+	{
+		__enan_64(b);
+		return;
+	}
+#endif
+#ifdef IBMPC
+	/* Shift Intel denormal significand down 1.  */
+	if (a[E] == 0)
+		__eshdn1(a);
+#endif
+	p = a;
+#ifdef MIEEE
+	q = b;
+#else
+	q = b + 4; /* point to output exponent */
+#if 1
+	/* NOTE: if data type is 96 bits wide, clear the last word here. */
+	*(q + 1)= 0;
+#endif
+#endif
+
+	/* combine sign and exponent */
+	i = *p++;
+#ifdef MIEEE
+	if (i)
+		*q++ = *p++ | 0x8000;
+	else
+		*q++ = *p++;
+	*q++ = 0;
+#else
+	if (i)
+		*q-- = *p++ | 0x8000;
+	else
+		*q-- = *p++;
+#endif
+	/* skip over guard word */
+	++p;
+	/* move the significand */
+#ifdef MIEEE
+	for (i = 0; i < 4; i++)
+		*q++ = *p++;
+#else
+#ifdef INFINITY
+	if (__eiisinf(a))
+        {
+	/* Intel long double infinity.  */
+		*q-- = 0x8000;
+		*q-- = 0;
+		*q-- = 0;
+		*q = 0;
+		return;
+	}
+#endif
+	for (i = 0; i < 4; i++)
+		*q-- = *p++;
+#endif
+}
+
+
+/* Compare two e type numbers.
+ *
+ * unsigned short a[NE], b[NE];
+ * ecmp( a, b );
+ *
+ *  returns +1 if a > b
+ *           0 if a == b
+ *          -1 if a < b
+ *          -2 if either a or b is a NaN.
+ */
+int __ecmp(const short unsigned int * __restrict__ a,
+		const short unsigned int *  __restrict__ b)
+{
+	unsigned short ai[NI], bi[NI];
+	register unsigned short *p, *q;
+	register int i;
+	int msign;
+
+#ifdef NANS
+	if (__eisnan (a) || __eisnan (b))
+		return (-2);
+#endif
+	__emovi(a, ai);
+	p = ai;
+	__emovi(b, bi);
+	q = bi;
+
+	if (*p != *q)
+	{ /* the signs are different */
+		/* -0 equals + 0 */
+		for (i = 1; i < NI - 1; i++)
+		{
+			if (ai[i] != 0)
+				goto nzro;
+			if (bi[i] != 0)
+				goto nzro;
+		}
+		return (0);
+nzro:
+		if (*p == 0)
+			return (1);
+		else
+			return (-1);
+	}
+	/* both are the same sign */
+	if (*p == 0)
+		msign = 1;
+	else
+		msign = -1;
+	i = NI - 1;
+	do
+	{
+		if (*p++ != *q++)
+		{
+			goto diff;
+		}
+	}
+	while (--i > 0);
+
+	return (0);	/* equality */
+
+diff:
+	if ( *(--p) > *(--q) )
+		return (msign);		/* p is bigger */
+	else
+		return (-msign);	/* p is littler */
+}
+
+/*
+;	Shift significand
+;
+;	Shifts significand area up or down by the number of bits
+;	given by the variable sc.
+*/
+int __eshift(short unsigned int *x, int sc)
+{
+	unsigned short lost;
+	unsigned short *p;
+
+	if (sc == 0)
+		return (0);
+
+	lost = 0;
+	p = x + NI - 1;
+
+	if (sc < 0)
+	{
+		sc = -sc;
+		while (sc >= 16)
+		{
+			lost |= *p;	/* remember lost bits */
+			__eshdn6(x);
+			sc -= 16;
+		}
+
+		while (sc >= 8)
+		{
+			lost |= *p & 0xff;
+			__eshdn8(x);
+			sc -= 8;
+		}
+
+		while (sc > 0)
+		{
+			lost |= *p & 1;
+			__eshdn1(x);
+			sc -= 1;
+		}
+	}
+	else
+	{
+		while (sc >= 16)
+		{
+			__eshup6(x);
+			sc -= 16;
+		}
+
+		while (sc >= 8)
+		{
+			__eshup8(x);
+			sc -= 8;
+		}
+
+		while (sc > 0)
+		{
+			__eshup1(x);
+			sc -= 1;
+		}
+	}
+	if (lost)
+		lost = 1;
+	return ( (int)lost );
+}
+
+
+/*
+;	normalize
+;
+; Shift normalizes the significand area pointed to by argument
+; shift count (up = positive) is returned.
+*/
+int __enormlz(short unsigned int *x)
+{
+	register unsigned short *p;
+	int sc;
+
+	sc = 0;
+	p = &x[M];
+	if (*p != 0)
+		goto normdn;
+	++p;
+	if (*p & 0x8000)
+		return (0);	/* already normalized */
+	while (*p == 0)
+	{
+		__eshup6(x);
+		sc += 16;
+		/* With guard word, there are NBITS+16 bits available.
+		 * return true if all are zero.
+		 */
+		if (sc > NBITS)
+			return (sc);
+	}
+	/* see if high byte is zero */
+	while ((*p & 0xff00) == 0)
+	{
+		__eshup8(x);
+		sc += 8;
+	}
+	/* now shift 1 bit at a time */
+	while ((*p  & 0x8000) == 0)
+	{
+		__eshup1(x);
+		sc += 1;
+		if (sc > (NBITS + 16))
+		{
+			mtherr( "enormlz", UNDERFLOW);
+			return (sc);
+		}
+	}
+	return (sc);
+
+	/* Normalize by shifting down out of the high guard word
+	   of the significand */
+normdn:
+	if (*p & 0xff00)
+	{
+		__eshdn8(x);
+		sc -= 8;
+	}
+	while (*p != 0)
+	{
+		__eshdn1(x);
+		sc -= 1;
+
+		if (sc < -NBITS)
+		{
+			mtherr("enormlz", OVERFLOW);
+			return (sc);
+		}
+	}
+	return (sc);
+}
+
+
+/* Move internal format number out,
+ * converting it to external format.
+ */
+void __emovo(const short unsigned int * __restrict__ a,
+		  short unsigned int * __restrict__ b)
+{
+	register const unsigned short *p;
+	register unsigned short *q;
+	unsigned short i;
+
+	p = a;
+	q = b + (NE - 1); /* point to output exponent */
+	/* combine sign and exponent */
+	i = *p++;
+	if (i)
+		*q-- = *p++ | 0x8000;
+	else
+		*q-- = *p++;
+#ifdef INFINITY
+	if (*(p - 1) == 0x7fff)
+	{
+#ifdef NANS
+		if (__eiisnan(a))
+		{
+			__enan_NBITS(b);
+			return;
+		}
+#endif
+		__einfin(b);
+		return;
+	}
+#endif
+	/* skip over guard word */
+	++p;
+	/* move the significand */
+	for (i = 0; i < NE - 1; i++)
+		*q-- = *p++;
+}
+
+
+#if USE_LDTOA
+
+void __eiremain(short unsigned int *den, short unsigned int *num,
+	 short unsigned int *equot )
+{
+	long ld, ln;
+	unsigned short j;
+
+	ld = den[E];
+	ld -= __enormlz(den);
+	ln = num[E];
+	ln -= __enormlz(num);
+	__ecleaz(equot);
+	while (ln >= ld)
+	{
+		if(__ecmpm(den,num) <= 0)
+		{
+			__esubm(den, num);
+			j = 1;
+		}
+		else
+		{
+			j = 0;
+		}
+		__eshup1(equot);
+		equot[NI - 1] |= j;
+		__eshup1(num);
+		ln -= 1;
+	}
+	__emdnorm( num, 0, 0, ln, 0, NBITS );
+}
+
+
+void __eadd1(const short unsigned int *  __restrict__ a,
+		  const short unsigned int *  __restrict__ b,
+		  short unsigned int *  __restrict__ c,
+		  int subflg)
+{
+	unsigned short ai[NI], bi[NI], ci[NI];
+	int i, lost, j, k;
+	long lt, lta, ltb;
+
+#ifdef INFINITY
+	if (__eisinf(a))
+	{
+		__emov(a, c);
+		if( subflg )
+			__eneg(c);
+		return;
+	}
+	if (__eisinf(b))
+	{
+		__emov(b, c);
+		return;
+	}
+#endif
+	__emovi(a, ai);
+	__emovi(b, bi);
+	if (sub)
+		ai[0] = ~ai[0];
+
+	/* compare exponents */
+	lta = ai[E];
+	ltb = bi[E];
+	lt = lta - ltb;
+	if (lt > 0L)
+	{	/* put the larger number in bi */
+		__emovz(bi, ci);
+		__emovz(ai, bi);
+		__emovz(ci, ai);
+		ltb = bi[E];
+		lt = -lt;
+	}
+	lost = 0;
+	if (lt != 0L)
+	{
+		if (lt < (long)(-NBITS - 1))
+			goto done;	/* answer same as larger addend */
+		k = (int)lt;
+		lost = __eshift(ai, k); /* shift the smaller number down */
+	}
+	else
+	{
+		/* exponents were the same, so must compare significands */
+		i = __ecmpm(ai, bi);
+		if (i == 0)
+		{ /* the numbers are identical in magnitude */
+			/* if different signs, result is zero */
+			if (ai[0] != bi[0])
+			{
+				__eclear(c);
+				return;
+			}
+			/* if same sign, result is double */
+			/* double denomalized tiny number */
+			if ((bi[E] == 0) && ((bi[3] & 0x8000) == 0))
+			{
+				__eshup1( bi );
+				goto done;
+			}
+			/* add 1 to exponent unless both are zero! */
+			for (j = 1; j < NI - 1; j++)
+			{
+				if (bi[j] != 0)
+				{
+				/* This could overflow, but let emovo take care of that. */
+					ltb += 1;
+					break;
+				}
+			}
+			bi[E] = (unsigned short )ltb;
+			goto done;
+		}
+		if (i > 0)
+		{	/* put the larger number in bi */
+			__emovz(bi, ci);
+			__emovz(ai, bi);
+			__emovz(ci, ai);
+		}
+	}
+	if (ai[0] == bi[0])
+	{
+		__eaddm(ai, bi);
+		subflg = 0;
+	}
+	else
+	{
+		__esubm(ai, bi);
+		subflg = 1;
+	}
+	__emdnorm(bi, lost, subflg, ltb, 64, NBITS);
+
+done:
+	__emovo(bi, c);
+}
+
+
+/* y = largest integer not greater than x
+ * (truncated toward minus infinity)
+ *
+ * unsigned short x[NE], y[NE]
+ *
+ * efloor( x, y );
+ */
+
+
+void __efloor(short unsigned int *x, short unsigned int *y)
+{
+	register unsigned short *p;
+	int e, expon, i;
+	unsigned short f[NE];
+	const unsigned short bmask[] = {
+				0xffff,
+				0xfffe,
+				0xfffc,
+				0xfff8,
+				0xfff0,
+				0xffe0,
+				0xffc0,
+				0xff80,
+				0xff00,
+				0xfe00,
+				0xfc00,
+				0xf800,
+				0xf000,
+				0xe000,
+				0xc000,
+				0x8000,
+				0x0000,
+	};
+
+	__emov(x, f); /* leave in external format */
+	expon = (int) f[NE - 1];
+	e = (expon & 0x7fff) - (EXONE - 1);
+	if (e <= 0)
+	{
+		__eclear(y);
+		goto isitneg;
+	}
+	/* number of bits to clear out */
+	e = NBITS - e;
+	__emov(f, y);
+	if (e <= 0)
+		return;
+
+	p = &y[0];
+	while (e >= 16)
+	{
+		*p++ = 0;
+		e -= 16;
+	}
+	/* clear the remaining bits */
+	*p &= bmask[e];
+	/* truncate negatives toward minus infinity */
+isitneg:
+
+	if ((unsigned short)expon & (unsigned short)0x8000)
+	{
+		for (i = 0; i < NE - 1; i++)
+		{
+			if (f[i] != y[i])
+			{
+				__esub( __eone, y, y );
+				break;
+			}
+		}
+	}
+}
+
+/*
+;	Subtract external format numbers.
+;
+;	unsigned short a[NE], b[NE], c[NE];
+;	esub( a, b, c );	 c = b - a
+*/
+
+void __esub(const short unsigned int *  a,
+		 const short unsigned int *  b,
+		 short unsigned int *  c)
+{
+#ifdef NANS
+	if (__eisnan(a))
+	{
+		__emov (a, c);
+		return;
+	}
+	if ( __eisnan(b))
+	{
+		__emov(b, c);
+		return;
+	}
+	/* Infinity minus infinity is a NaN.
+	 * Test for subtracting infinities of the same sign.
+	 */
+	if (__eisinf(a) && __eisinf(b) && ((__eisneg (a) ^ __eisneg (b)) == 0))
+	{
+		mtherr("esub", DOMAIN);
+		__enan_NBITS( c );
+		return;
+	}
+#endif
+	__eadd1(a, b, c, 1);
+}
+
+
+/*
+;	Divide.
+;
+;	unsigned short a[NI], b[NI], c[NI];
+;	ediv( a, b, c );	c = b / a
+*/
+
+void __ediv(const short unsigned int *a,
+		 const short unsigned int *b,
+		 short unsigned int *c)
+{
+	unsigned short ai[NI], bi[NI];
+	int i;
+	long lt, lta, ltb;
+
+#ifdef NANS
+	/* Return any NaN input. */
+	if (__eisnan(a))
+	{
+		__emov(a, c);
+		return;
+	}
+	if (__eisnan(b))
+	{
+		__emov(b, c);
+		return;
+	}
+	/* Zero over zero, or infinity over infinity, is a NaN. */
+	if ((__eiszero(a) && __eiszero(b))
+	 || (__eisinf (a) && __eisinf (b)))
+	{
+		mtherr("ediv", DOMAIN);
+		__enan_NBITS( c );
+		return;
+	}
+#endif
+/* Infinity over anything else is infinity. */
+#ifdef INFINITY
+	if (__eisinf(b))
+	{
+		if (__eisneg(a) ^ __eisneg(b))
+			*(c + (NE - 1)) = 0x8000;
+		else
+			*(c + (NE - 1)) = 0;
+		__einfin(c);
+		return;
+	}
+	if (__eisinf(a))
+	{
+		__eclear(c);
+		return;
+	}
+#endif
+	__emovi(a, ai);
+	__emovi(b, bi);
+	lta = ai[E];
+	ltb = bi[E];
+	if (bi[E] == 0)
+	{ /* See if numerator is zero. */
+		for (i = 1; i < NI - 1; i++)
+		{
+			if (bi[i] != 0)
+			{
+				ltb -= __enormlz(bi);
+				goto dnzro1;
+			}
+		}
+		__eclear(c);
+		return;
+	}
+dnzro1:
+
+	if (ai[E] == 0)
+	{	/* possible divide by zero */
+		for (i = 1; i < NI - 1; i++)
+		{
+			if (ai[i] != 0)
+			{
+				lta -= __enormlz(ai);
+				goto dnzro2;
+			}
+		}
+		if (ai[0] == bi[0])
+			*(c + (NE - 1)) = 0;
+		else
+			*(c + (NE - 1)) = 0x8000;
+		__einfin(c);
+		mtherr("ediv", SING);
+		return;
+	}
+dnzro2:
+
+	i = __edivm(ai, bi);
+	/* calculate exponent */
+	lt = ltb - lta + EXONE;
+	__emdnorm(bi, i, 0, lt, 64, NBITS);
+	/* set the sign */
+	if (ai[0] == bi[0])
+		bi[0] = 0;
+	else
+		bi[0] = 0Xffff;
+	__emovo(bi, c);
+}
+
+void __e64toe(short unsigned int *pe, short unsigned int *y)
+{
+	unsigned short yy[NI];
+	unsigned short *p, *q, *e;
+	int i;
+
+	e = pe;
+	p = yy;
+	for (i = 0; i < NE - 5; i++)
+		*p++ = 0;
+#ifdef IBMPC
+	for (i = 0; i < 5; i++)
+		*p++ = *e++;
+#endif
+#ifdef DEC
+	for (i = 0; i < 5; i++)
+		*p++ = *e++;
+#endif
+#ifdef MIEEE
+	p = &yy[0] + (NE - 1);
+	*p-- = *e++;
+	++e;
+	for (i = 0; i < 4; i++)
+		*p-- = *e++;
+#endif
+
+#ifdef IBMPC
+	/* For Intel long double, shift denormal significand up 1
+	   -- but only if the top significand bit is zero.  */
+	if ((yy[NE - 1] & 0x7fff) == 0 && (yy[NE - 2] & 0x8000) == 0)
+	{
+		unsigned short temp[NI + 1];
+		__emovi(yy, temp);
+		__eshup1(temp);
+		__emovo(temp,y);
+		return;
+	}
+#endif
+#ifdef INFINITY
+	/* Point to the exponent field.  */
+	p = &yy[NE - 1];
+	if (*p == 0x7fff)
+	{
+#ifdef NANS
+#ifdef IBMPC
+		for (i = 0; i < 4; i++)
+		{
+			if ((i != 3 && pe[i] != 0)
+			  /* Check for Intel long double infinity pattern.  */
+			  || (i == 3 && pe[i] != 0x8000))
+			{
+				__enan_NBITS(y);
+				return;
+			}
+		}
+#else
+		for (i = 1; i <= 4; i++)
+		{
+			if (pe[i] != 0)
+			{
+				__enan_NBITS(y);
+				return;
+			}
+		}
+#endif
+#endif /* NANS */
+		__eclear(y);
+		__einfin(y);
+		if (*p & 0x8000)
+			__eneg(y);
+		return;
+	}
+#endif
+	p = yy;
+	q = y;
+	for (i = 0; i < NE; i++)
+		*q++ = *p++;
+}
+
+#endif /* USE_LDTOA */ 
diff --git a/winsup/cygwin/math/cephes_emath.h b/winsup/cygwin/math/cephes_emath.h
new file mode 100644
index 000000000..b92d710f6
--- /dev/null
+++ b/winsup/cygwin/math/cephes_emath.h
@@ -0,0 +1,719 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#ifndef _CEPHES_EMATH_H
+#define _CEPHES_EMATH_H
+
+/**
+ * This is a workaround for a gcc bug
+ */
+#define __restrict__
+
+/* This file is extracted from S L Moshier's  ioldoubl.c,
+ * modified for use in MinGW 
+ *
+ * Extended precision arithmetic functions for long double I/O.
+ * This program has been placed in the public domain.
+ */
+
+
+/*
+ * Revision history:
+ *
+ *  5 Jan 84	PDP-11 assembly language version
+ *  6 Dec 86	C language version
+ * 30 Aug 88	100 digit version, improved rounding
+ * 15 May 92    80-bit long double support
+ *
+ * Author:  S. L. Moshier.
+ *
+ * 6 Oct 02	Modified for MinGW by inlining utility routines,
+ * 		removing global variables, and splitting out strtold
+ *		from _IO_ldtoa and _IO_ldtostr.
+ *  
+ *		Danny Smith <dannysmith@users.sourceforge.net>
+ * 
+ */
+
+
+/*							ieee.c
+ *
+ *    Extended precision IEEE binary floating point arithmetic routines
+ *
+ * Numbers are stored in C language as arrays of 16-bit unsigned
+ * short integers.  The arguments of the routines are pointers to
+ * the arrays.
+ *
+ *
+ * External e type data structure, simulates Intel 8087 chip
+ * temporary real format but possibly with a larger significand:
+ *
+ *	NE-1 significand words	(least significant word first,
+ *				 most significant bit is normally set)
+ *	exponent		(value = EXONE for 1.0,
+ *				top bit is the sign)
+ *
+ *
+ * Internal data structure of a number (a "word" is 16 bits):
+ *
+ * ei[0]	sign word	(0 for positive, 0xffff for negative)
+ * ei[1]	biased __exponent	(value = EXONE for the number 1.0)
+ * ei[2]	high guard word	(always zero after normalization)
+ * ei[3]
+ * to ei[NI-2]	significand	(NI-4 significand words,
+ *				 most significant word first,
+ *				 most significant bit is set)
+ * ei[NI-1]	low guard word	(0x8000 bit is rounding place)
+ *
+ *
+ *
+ *		Routines for external format numbers
+ *
+ *	__asctoe64( string, &d )	ASCII string to long double
+ *	__asctoeg( string, e, prec )	ASCII string to specified precision
+ *	__e64toe( &d, e )		IEEE long double precision to e type
+ *	__eadd( a, b, c )		c = b + a
+ *	__eclear(e)			e = 0
+ *	__ecmp (a, b)			Returns 1 if a > b, 0 if a == b,
+ *					-1 if a < b, -2 if either a or b is a NaN.
+ *	__ediv( a, b, c )		c = b / a
+ *	__efloor( a, b )		truncate to integer, toward -infinity
+ *	__efrexp( a, exp, s )		extract exponent and significand
+ *	__eifrac( e, &l, frac )   	e to long integer and e type fraction
+ *	__euifrac( e, &l, frac )  	e to unsigned long integer and e type fraction
+ *	__einfin( e )			set e to infinity, leaving its sign alone
+ *	__eldexp( a, n, b )		multiply by 2**n
+ *	__emov( a, b )			b = a
+ *	__emul( a, b, c )		c = b * a
+ *	__eneg(e)			e = -e
+ *	__eround( a, b )		b = nearest integer value to a
+ *	__esub( a, b, c )		c = b - a
+ *	__e24toasc( &f, str, n )	single to ASCII string, n digits after decimal
+ *	__e53toasc( &d, str, n )	double to ASCII string, n digits after decimal
+ *	__e64toasc( &d, str, n )	long double to ASCII string
+ *	__etoasc( e, str, n )		e to ASCII string, n digits after decimal
+ *	__etoe24( e, &f )		convert e type to IEEE single precision
+ *	__etoe53( e, &d )		convert e type to IEEE double precision
+ *	__etoe64( e, &d )		convert e type to IEEE long double precision
+ *	__eisneg( e )             	1 if sign bit of e != 0, else 0
+ *	__eisinf( e )             	1 if e has maximum exponent (non-IEEE)
+ *					or is infinite (IEEE)
+ *	__eisnan( e )             	1 if e is a NaN
+ *	__esqrt( a, b )			b = square root of a
+ *
+ *
+ *		Routines for internal format numbers
+ *
+ *	__eaddm( ai, bi )		add significands, bi = bi + ai
+ *	__ecleaz(ei)		ei = 0
+ *	__ecleazs(ei)		set ei = 0 but leave its sign alone
+ *	__ecmpm( ai, bi )		compare significands, return 1, 0, or -1
+ *	__edivm( ai, bi )		divide  significands, bi = bi / ai
+ *	__emdnorm(ai,l,s,exp)	normalize and round off
+ *	__emovi( a, ai )		convert external a to internal ai
+ *	__emovo( ai, a )		convert internal ai to external a
+ *	__emovz( ai, bi )		bi = ai, low guard word of bi = 0
+ *	__emulm( ai, bi )		multiply significands, bi = bi * ai
+ *	__enormlz(ei)		left-justify the significand
+ *	__eshdn1( ai )		shift significand and guards down 1 bit
+ *	__eshdn8( ai )		shift down 8 bits
+ *	__eshdn6( ai )		shift down 16 bits
+ *	__eshift( ai, n )		shift ai n bits up (or down if n < 0)
+ *	__eshup1( ai )		shift significand and guards up 1 bit
+ *	__eshup8( ai )		shift up 8 bits
+ *	__eshup6( ai )		shift up 16 bits
+ *	__esubm( ai, bi )		subtract significands, bi = bi - ai
+ *
+ *
+ * The result is always normalized and rounded to NI-4 word precision
+ * after each arithmetic operation.
+ *
+ * Exception flags are NOT fully supported.
+ *
+ * Define INFINITY in mconf.h for support of infinity; otherwise a
+ * saturation arithmetic is implemented.
+ *
+ * Define NANS for support of Not-a-Number items; otherwise the
+ * arithmetic will never produce a NaN output, and might be confused
+ * by a NaN input.
+ * If NaN's are supported, the output of ecmp(a,b) is -2 if
+ * either a or b is a NaN. This means asking if(ecmp(a,b) < 0)
+ * may not be legitimate. Use if(ecmp(a,b) == -1) for less-than
+ * if in doubt.
+ * Signaling NaN's are NOT supported; they are treated the same
+ * as quiet NaN's.
+ *
+ * Denormals are always supported here where appropriate (e.g., not
+ * for conversion to DEC numbers).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <math.h>
+#include <locale.h>
+#include <ctype.h>
+
+#undef alloca
+#define alloca __builtin_alloca
+
+/* Don't build non-ANSI _IO_ldtoa.  It is not thread safe. */ 
+#ifndef USE_LDTOA
+#define USE_LDTOA 0
+#endif
+
+
+ /* Number of 16 bit words in external x type format */
+#define NE 6
+
+ /* Number of 16 bit words in internal format */
+#define NI (NE+3)
+
+ /* Array offset to exponent */
+#define E 1
+
+ /* Array offset to high guard word */
+#define M 2
+
+ /* Number of bits of precision */
+#define NBITS ((NI-4)*16)
+
+ /* Maximum number of decimal digits in ASCII conversion
+  * = NBITS*log10(2)
+  */
+#define NDEC (NBITS*8/27)
+
+ /* The exponent of 1.0 */
+#define EXONE (0x3fff)
+
+
+#define  mtherr(x,y)
+
+
+extern long double strtold (const char * __restrict__ s, char ** __restrict__ se);
+extern int __asctoe64(const char * __restrict__ ss,
+		      short unsigned int * __restrict__ y);
+extern void __emul(const short unsigned int *  a,
+		   const short unsigned int *  b,
+		   short unsigned int * c);
+extern int __ecmp(const short unsigned int * __restrict__ a,
+		  const short unsigned int *  __restrict__ b);
+extern int __enormlz(short unsigned int *x);
+extern int __eshift(short unsigned int *x, int sc);
+extern void __eaddm(const short unsigned int  *  __restrict__  x,
+		    short unsigned int *  __restrict__  y);
+extern void __esubm(const short unsigned int * __restrict__  x,
+		    short unsigned int *  __restrict__ y);
+extern void __emdnorm(short unsigned int *s, int lost, int subflg,
+		      int exp, int rcntrl, const int rndprc);
+extern void __toe64(short unsigned int *  __restrict__  a,
+		    short unsigned int *  __restrict__  b);
+extern int __edivm(short unsigned int *  __restrict__  den,
+		   short unsigned int * __restrict__  num);
+extern int __emulm(const short unsigned int *  __restrict__ a,
+		   short unsigned int *  __restrict__ b);
+extern void __emovi(const short unsigned int * __restrict__ a,
+		    short unsigned int * __restrict__ b);
+extern void __emovo(const short unsigned int * __restrict__ a,
+		    short unsigned int * __restrict__ b);
+
+#if USE_LDTOA
+
+extern char * _IO_ldtoa(long double, int, int, int *, int *, char **);
+extern void _IO_ldtostr(long double *x, char *string, int ndigs,
+			int flags, char fmt);
+
+extern void __eiremain(short unsigned int * __restrict__ den,
+		       short unsigned int *__restrict__ num,
+		       short unsigned int *__restrict__ equot);
+extern void __efloor(short unsigned int *x, short unsigned int *y);
+extern void __eadd1(const short unsigned int * __restrict__ a,
+		    const short unsigned int * __restrict__ b,
+		    short unsigned int * __restrict__ c,
+		    int subflg);
+extern void __esub(const short unsigned int *a, const short unsigned int *b,
+		   short unsigned int *c);
+extern void __ediv(const short unsigned int *a, const short unsigned int *b,
+		   short unsigned int *c);
+extern void __e64toe(short unsigned int *pe, short unsigned int *y);
+
+
+#endif
+
+static  __inline__ int __eisneg(const short unsigned int *x);
+static  __inline__ int __eisinf(const short unsigned int *x);
+static __inline__ int __eisnan(const short unsigned int *x);
+static __inline__ int __eiszero(const short unsigned int *a);
+static __inline__ void __emovz(register const short unsigned int * __restrict__ a,
+			       register short unsigned int * __restrict__ b);
+static __inline__ void __eclear(register short unsigned int *x);
+static __inline__ void __ecleaz(register short unsigned int *xi);
+static __inline__ void __ecleazs(register short unsigned int *xi);
+static  __inline__ int __eiisinf(const short unsigned int *x);
+static __inline__ int __eiisnan(const short unsigned int *x);
+static __inline__ int __eiiszero(const short unsigned int *x);
+static __inline__ void __enan_64(short unsigned int *nanptr);
+static __inline__ void __enan_NBITS (short unsigned int *nanptr);
+static __inline__ void __enan_NI16 (short unsigned int *nanptr);
+static __inline__ void __einfin(register short unsigned int *x);
+static __inline__ void __eneg(short unsigned int *x);
+static __inline__ void __eshup1(register short unsigned int *x);
+static __inline__ void __eshup8(register short unsigned int *x);
+static __inline__ void __eshup6(register short unsigned int *x);
+static __inline__ void __eshdn1(register short unsigned int *x);
+static __inline__ void __eshdn8(register short unsigned int *x);
+static __inline__ void __eshdn6(register short unsigned int *x);
+
+
+
+/* Intel IEEE, low order words come first:
+ */
+#define IBMPC 1
+
+/* Define 1 for ANSI C atan2() function
+ * See atan.c and clog.c.
+ */
+#define ANSIC 1
+
+/*define VOLATILE volatile*/
+#define VOLATILE
+
+/* For 12-byte long doubles on an i386, pad a 16-bit short 0
+ * to the end of real constants initialized by integer arrays.
+ *
+ * #define XPD 0,
+ *
+ * Otherwise, the type is 10 bytes long and XPD should be
+ * defined blank.
+ *
+ * #define XPD
+ */
+#define XPD 0,
+/* #define XPD */
+#define NANS
+
+/* NaN's require infinity support. */
+#ifdef NANS
+#ifndef INFINITY
+#define INFINITY
+#endif
+#endif
+
+/* This handles 64-bit long ints. */
+#define LONGBITS (8 * sizeof(long))
+
+
+#define NTEN 12
+#define MAXP 4096
+
+/*
+; Clear out entire external format number.
+;
+; unsigned short x[];
+; eclear( x );
+*/
+
+static __inline__ void __eclear(register short unsigned int *x)
+{
+	memset(x, 0, NE * sizeof(unsigned short));
+}
+
+
+/* Move external format number from a to b.
+ *
+ * emov( a, b );
+ */
+
+static __inline__ void __emov(register const short unsigned int * __restrict__ a,
+			      register short unsigned int * __restrict__ b)
+{
+	memcpy(b, a, NE * sizeof(unsigned short));
+}
+
+
+/*
+;	Negate external format number
+;
+;	unsigned short x[NE];
+;	eneg( x );
+*/
+
+static __inline__ void __eneg(short unsigned int *x)
+{
+#ifdef NANS
+	if (__eisnan(x))
+		return;
+#endif
+	x[NE-1] ^= 0x8000; /* Toggle the sign bit */
+}
+
+
+/* Return 1 if external format number is negative,
+ * else return zero.
+ */
+static __inline__ int __eisneg(const short unsigned int *x)
+{
+#ifdef NANS
+	if (__eisnan(x))
+		return (0);
+#endif
+	if (x[NE-1] & 0x8000)
+		return (1);
+	else
+		return (0);
+}
+
+
+/* Return 1 if external format number has maximum possible exponent,
+ * else return zero.
+ */
+static __inline__ int __eisinf(const short unsigned int *x)
+{
+	if ((x[NE - 1] & 0x7fff) == 0x7fff)
+	{
+#ifdef NANS
+		if (__eisnan(x))
+			return (0);
+#endif
+		return (1);
+	}
+	else
+		return (0);
+}
+
+/* Check if e-type number is not a number.
+ */
+static __inline__ int __eisnan(const short unsigned int *x)
+{
+#ifdef NANS
+	int i;
+	/* NaN has maximum __exponent */
+	if ((x[NE - 1] & 0x7fff) == 0x7fff)
+		/* ... and non-zero significand field. */
+		for (i = 0; i < NE - 1; i++)
+		{
+			if (*x++ != 0)
+				return (1);
+		}
+#endif
+	return (0);
+}
+
+/*
+; Fill __entire number, including __exponent and significand, with
+; largest possible number.  These programs implement a saturation
+; value that is an ordinary, legal number.  A special value
+; "infinity" may also be implemented; this would require tests
+; for that value and implementation of special rules for arithmetic
+; operations involving inifinity.
+*/
+
+static __inline__ void __einfin(register short unsigned int *x)
+{
+	register int i;
+#ifdef INFINITY
+	for (i = 0; i < NE - 1; i++)
+		*x++ = 0;
+	*x |= 32767;
+#else
+	for (i = 0; i < NE - 1; i++)
+		*x++ = 0xffff;
+	*x |= 32766;
+	*(x - 5) = 0;
+#endif
+}
+
+/* Clear out internal format number.
+ */
+
+static __inline__ void __ecleaz(register short unsigned int *xi)
+{
+	memset(xi, 0, NI * sizeof(unsigned short));
+}
+
+/* same, but don't touch the sign. */
+
+static __inline__ void __ecleazs(register short unsigned int *xi)
+{
+	++xi;
+	memset(xi, 0, (NI-1) * sizeof(unsigned short));
+}
+
+/* Move internal format number from a to b.
+ */
+static __inline__ void __emovz(register const short unsigned int * __restrict__ a,
+			       register short unsigned int * __restrict__ b)
+{
+	memcpy(b, a, (NI-1) * sizeof(unsigned short));
+	b[NI - 1] = 0;
+}
+
+/* Return nonzero if internal format number is a NaN.
+ */
+
+static __inline__ int __eiisnan (const short unsigned int *x)
+{
+	int i;
+
+	if ((x[E] & 0x7fff) == 0x7fff)
+	{
+		for (i = M + 1; i < NI; i++ )
+		{
+			if (x[i] != 0)
+				return (1);
+		}
+	}
+	return (0);
+}
+
+/* Return nonzero if external format number is zero. */
+
+static __inline__ int
+__eiszero(const short unsigned int * a)
+{
+  union {
+    long double ld;
+    unsigned short sh[8];
+  } av;
+  av.ld = 0.0;
+  memcpy (av.sh, a, 12);
+  if (av.ld == 0.0)
+    return (1);
+  return (0);
+}
+
+/* Return nonzero if internal format number is zero. */
+
+static __inline__ int
+__eiiszero(const short unsigned int * ai)
+{
+	int i;
+	/* skip the sign word */
+	for (i = 1; i < NI - 1; i++ )
+	{
+		if (ai[i] != 0)
+			return (0);
+	}
+	return (1);
+}
+
+
+/* Return nonzero if internal format number is infinite. */
+
+static __inline__ int 
+__eiisinf (const unsigned short *x)
+{
+#ifdef NANS
+	if (__eiisnan (x))
+		return (0);
+#endif
+	if ((x[E] & 0x7fff) == 0x7fff)
+		return (1);
+	return (0);
+}
+
+/*
+;	Compare significands of numbers in internal format.
+;	Guard words are included in the comparison.
+;
+;	unsigned short a[NI], b[NI];
+;	cmpm( a, b );
+;
+;	for the significands:
+;	returns	+1 if a > b
+;		 0 if a == b
+;		-1 if a < b
+*/
+static __inline__ int __ecmpm(register const short unsigned int * __restrict__ a,
+			      register const short unsigned int * __restrict__ b)
+{
+	int i;
+
+	a += M; /* skip up to significand area */
+	b += M;
+	for (i = M; i < NI; i++)
+	{
+		if( *a++ != *b++ )
+		goto difrnt;
+	}
+	return(0);
+
+  difrnt:
+	if ( *(--a) > *(--b) )
+		return (1);
+	else
+		return (-1);
+}
+
+
+/*
+;	Shift significand down by 1 bit
+*/
+
+static __inline__ void __eshdn1(register short unsigned int *x)
+{
+	register unsigned short bits;
+	int i;
+
+	x += M;	/* point to significand area */
+
+	bits = 0;
+	for (i = M; i < NI; i++ )
+	{
+		if (*x & 1)
+			bits |= 1;
+		*x >>= 1;
+		if (bits & 2)
+			*x |= 0x8000;
+		bits <<= 1;
+		++x;
+	}
+}
+
+/*
+;	Shift significand up by 1 bit
+*/
+
+static __inline__ void __eshup1(register short unsigned int *x)
+{
+	register unsigned short bits;
+	int i;
+
+	x += NI-1;
+	bits = 0;
+
+	for (i = M; i < NI; i++)
+	{
+		if (*x & 0x8000)
+			bits |= 1;
+		*x <<= 1;
+		if (bits & 2)
+			*x |= 1;
+		bits <<= 1;
+		--x;
+	}
+}
+
+
+/*
+;	Shift significand down by 8 bits
+*/
+
+static __inline__ void __eshdn8(register short unsigned int *x)
+{
+	register unsigned short newbyt, oldbyt;
+	int i;
+
+	x += M;
+	oldbyt = 0;
+	for (i = M; i < NI; i++)
+	{
+		newbyt = *x << 8;
+		*x >>= 8;
+		*x |= oldbyt;
+		oldbyt = newbyt;
+		++x;
+	}
+}
+
+/*
+;	Shift significand up by 8 bits
+*/
+
+static __inline__ void __eshup8(register short unsigned int *x)
+{
+	int i;
+	register unsigned short newbyt, oldbyt;
+
+	x += NI - 1;
+	oldbyt = 0;
+
+	for (i = M; i < NI; i++)
+	{
+		newbyt = *x >> 8;
+		*x <<= 8;
+		*x |= oldbyt;
+		oldbyt = newbyt;
+		--x;
+	}
+}
+
+/*
+;	Shift significand up by 16 bits
+*/
+
+static __inline__ void __eshup6(register short unsigned int *x)
+{
+	int i;
+	register unsigned short *p;
+
+	p = x + M;
+	x += M + 1;
+
+	for (i = M; i < NI - 1; i++)
+		*p++ = *x++;
+
+	*p = 0;
+}
+
+/*
+;	Shift significand down by 16 bits
+*/
+
+static __inline__ void __eshdn6(register short unsigned int *x)
+{
+	int i;
+	register unsigned short *p;
+
+	x += NI - 1;
+	p = x + 1;
+
+	for (i = M; i < NI - 1; i++)
+		*(--p) = *(--x);
+
+	*(--p) = 0;
+}
+
+/*
+;	Add significands
+;	x + y replaces y
+*/
+
+static __inline__ void __enan_64(unsigned short* nanptr)
+{
+	int i;
+	for (i = 0; i < 3; i++)
+		*nanptr++ = 0;
+	*nanptr++ = 0xc000;
+	*nanptr++ = 0x7fff;
+	*nanptr = 0;
+	return;
+}
+
+static __inline__ void __enan_NBITS(unsigned short* nanptr)
+{
+	int i;
+	for (i = 0; i < NE - 2; i++)
+		*nanptr++ = 0;
+	*nanptr++ = 0xc000;
+	*nanptr = 0x7fff;
+	return;
+}
+
+static __inline__ void __enan_NI16(unsigned short* nanptr)
+{
+	int i;
+	*nanptr++ = 0;
+	*nanptr++ = 0x7fff;
+	*nanptr++ = 0;
+	*nanptr++ = 0xc000;
+	for (i = 4; i < NI; i++)
+		*nanptr++ = 0;
+	return;
+}
+
+#endif /* _CEPHES_EMATH_H */
+
diff --git a/winsup/cygwin/math/cephes_mconf.h b/winsup/cygwin/math/cephes_mconf.h
new file mode 100644
index 000000000..832fae0df
--- /dev/null
+++ b/winsup/cygwin/math/cephes_mconf.h
@@ -0,0 +1,417 @@
+#include <math.h>
+#include <errno.h>
+
+
+#define IBMPC 1
+#define ANSIPROT 1
+#define MINUSZERO 1
+#define INFINITIES 1
+#define NANS 1
+#define DENORMAL 1
+#define VOLATILE
+#define mtherr(fname, code)
+#define XPD 0,
+#ifdef __x86_64__
+#define XPD_SHORT 0, 0,
+#define XPD_LONG 0,
+#else
+#define XPD_SHORT
+#define XPD_LONG
+#endif
+
+#if UNK
+typedef union uLD { long double ld; unsigned short sh[8]; long lo[4]; } uLD;
+typedef union uD { double d; unsigned short sh[4]; } uD;
+#elif IBMPC
+typedef union uLD { unsigned short sh[8]; long double ld; long lo[4]; } uLD;
+typedef union uD { unsigned short sh[4]; double d; } uD;
+#elif MIEEE
+typedef union uLD { long lo[4]; long double ld; unsigned short sh[8]; } uLD;
+typedef union uD { unsigned short sh[4]; double d; } uD;
+#else
+#error Unknown uLD/uD type definition
+#endif
+
+#define _CEPHES_USE_ERRNO
+
+#ifdef _CEPHES_USE_ERRNO
+#define _SET_ERRNO(x) errno = (x)
+#else
+#define _SET_ERRNO(x)
+#endif
+
+/* constants used by cephes functions */
+
+/* double */
+#define MAXNUM	1.7976931348623158E308
+#define MAXLOG	7.09782712893383996843E2
+#define MINLOG	-7.08396418532264106224E2
+#define LOGE2	6.93147180559945309417E-1
+#define LOG2E	1.44269504088896340736
+#define PI	3.14159265358979323846
+#define PIO2	1.57079632679489661923
+#define PIO4	7.85398163397448309616E-1
+
+#define NEGZERO (-0.0)
+#undef NAN
+#undef INFINITY
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
+#define INFINITY __builtin_huge_val()
+#define NAN __builtin_nan("")
+#else
+extern double __INF;
+#define INFINITY (__INF)
+extern double __QNAN;
+#define NAN (__QNAN)
+#endif
+
+/*long double*/
+#if defined(__arm__) || defined(_ARM_)
+#define MAXNUML	1.7976931348623158E308
+#define MAXLOGL	7.09782712893383996843E2
+#define MINLOGL	-7.08396418532264106224E2
+#define LOGE2L	6.93147180559945309417E-1
+#define LOG2EL	1.44269504088896340736
+#define PIL	3.14159265358979323846
+#define PIO2L	1.57079632679489661923
+#define PIO4L	7.85398163397448309616E-1
+#else
+#define MAXNUML 1.189731495357231765021263853E4932L
+#define MAXLOGL	1.1356523406294143949492E4L
+#define MINLOGL	-1.13994985314888605586758E4L
+#define LOGE2L	6.9314718055994530941723E-1L
+#define LOG2EL	1.4426950408889634073599E0L
+#define PIL	3.1415926535897932384626L
+#define PIO2L	1.5707963267948966192313L
+#define PIO4L	7.8539816339744830961566E-1L
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+#define isfinitel isfinite
+#define isinfl isinf
+#define isnanl isnan
+#define signbitl signbit
+
+#define NEGZEROL (-0.0L)
+
+#undef NANL
+#undef INFINITYL
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
+#define INFINITYL __builtin_huge_vall()
+#define NANL __builtin_nanl("")
+#else
+extern long double __INFL;
+#define INFINITYL (__INFL)
+extern long double __QNANL;
+#define NANL (__QNANL)
+#endif
+
+/* float */
+
+#define MAXNUMF	3.4028234663852885981170418348451692544e38F
+#define MAXLOGF	88.72283905206835F
+#define MINLOGF	-103.278929903431851103F /* log(2^-149) */
+#define LOG2EF	1.44269504088896341F
+#define LOGE2F	0.693147180559945309F
+#define PIF	3.141592653589793238F
+#define PIO2F	1.5707963267948966192F
+#define PIO4F	0.7853981633974483096F
+
+#define isfinitef isfinite
+#define isinff isinf
+#define isnanf isnan
+#define signbitf signbit
+
+#define NEGZEROF (-0.0F)
+
+#undef NANF
+#undef INFINITYF
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2))
+#define INFINITYF __builtin_huge_valf()
+#define NANF __builtin_nanf("")
+#else
+extern float __INFF;
+#define INFINITYF (__INFF)
+extern float __QNANF;
+#define NANF (__QNANF)
+#endif
+
+
+/* double */
+
+/*
+Cephes Math Library Release 2.2:  July, 1992
+Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
+Direct inquiries to 30 Frost Street, Cambridge, MA 02140
+*/
+
+
+/*							polevl.c
+ *							p1evl.c
+ *
+ *	Evaluate polynomial
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int N;
+ * double x, y, coef[N+1], polevl[];
+ *
+ * y = polevl( x, coef, N );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Evaluates polynomial of degree N:
+ *
+ *                     2          N
+ * y  =  C  + C x + C x  +...+ C x
+ *        0    1     2          N
+ *
+ * Coefficients are stored in reverse order:
+ *
+ * coef[0] = C  , ..., coef[N] = C  .
+ *            N                   0
+ *
+ *  The function p1evl() assumes that coef[N] = 1.0 and is
+ * omitted from the array.  Its calling arguments are
+ * otherwise the same as polevl().
+ *
+ *
+ * SPEED:
+ *
+ * In the interest of speed, there are no checks for out
+ * of bounds arithmetic.  This routine is used by most of
+ * the functions in the library.  Depending on available
+ * equipment features, the user may wish to rewrite the
+ * program in microcode or assembly language.
+ *
+ */
+
+/* Polynomial evaluator:
+ *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
+ */
+static __inline__ double polevl(double x, const uD *p, int n)
+{
+	register double y;
+
+	y = p->d;
+	p++;
+	do
+	{
+		y = y * x + p->d;
+		p++;
+	}
+	while (--n);
+	return (y);
+}
+
+
+/* Polynomial evaluator:
+ *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
+ */
+static __inline__  double p1evl(double x, const uD *p, int n)
+{
+	register double y;
+
+	n -= 1;
+	y = x + p->d; p++;
+	do
+	{
+		y = y * x + p->d; p++;
+	}
+	while (--n);
+	return (y);
+}
+
+
+/* long double */
+/*
+Cephes Math Library Release 2.2:  July, 1992
+Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
+Direct inquiries to 30 Frost Street, Cambridge, MA 02140
+*/
+
+
+/*							polevll.c
+ *							p1evll.c
+ *
+ *	Evaluate polynomial
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int N;
+ * long double x, y, coef[N+1], polevl[];
+ *
+ * y = polevll( x, coef, N );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Evaluates polynomial of degree N:
+ *
+ *                     2          N
+ * y  =  C  + C x + C x  +...+ C x
+ *        0    1     2          N
+ *
+ * Coefficients are stored in reverse order:
+ *
+ * coef[0] = C  , ..., coef[N] = C  .
+ *            N                   0
+ *
+ *  The function p1evll() assumes that coef[N] = 1.0 and is
+ * omitted from the array.  Its calling arguments are
+ * otherwise the same as polevll().
+ *
+ *
+ * SPEED:
+ *
+ * In the interest of speed, there are no checks for out
+ * of bounds arithmetic.  This routine is used by most of
+ * the functions in the library.  Depending on available
+ * equipment features, the user may wish to rewrite the
+ * program in microcode or assembly language.
+ *
+ */
+
+/* Polynomial evaluator:
+ *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
+ */
+static __inline__ long double polevll(long double x, const uLD *p, int n)
+{
+	register long double y;
+
+	y = p->ld;
+	p++;
+	do
+	{
+		y = y * x + p->ld;
+		p++;
+	}
+	while (--n);
+	return y;
+}
+
+
+
+/* Polynomial evaluator:
+ *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
+ */
+static __inline__ long double p1evll(long double x, const uLD *p, int n)
+{
+	register long double y;
+
+	n -= 1;
+	y = x + p->ld;
+	p++;
+
+	do
+	{
+		y = y * x + p->ld;
+		p++;
+	}
+	while (--n);
+	return (y);
+}
+
+/* Float version */
+
+/*							polevlf.c
+ *							p1evlf.c
+ *
+ *	Evaluate polynomial
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int N;
+ * float x, y, coef[N+1], polevlf[];
+ *
+ * y = polevlf( x, coef, N );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Evaluates polynomial of degree N:
+ *
+ *                     2          N
+ * y  =  C  + C x + C x  +...+ C x
+ *        0    1     2          N
+ *
+ * Coefficients are stored in reverse order:
+ *
+ * coef[0] = C  , ..., coef[N] = C  .
+ *            N                   0
+ *
+ *  The function p1evl() assumes that coef[N] = 1.0 and is
+ * omitted from the array.  Its calling arguments are
+ * otherwise the same as polevl().
+ *
+ *
+ * SPEED:
+ *
+ * In the interest of speed, there are no checks for out
+ * of bounds arithmetic.  This routine is used by most of
+ * the functions in the library.  Depending on available
+ * equipment features, the user may wish to rewrite the
+ * program in microcode or assembly language.
+ *
+ */
+
+/*
+Cephes Math Library Release 2.1:  December, 1988
+Copyright 1984, 1987, 1988 by Stephen L. Moshier
+Direct inquiries to 30 Frost Street, Cambridge, MA 02140
+*/
+
+static __inline__ float polevlf(float x, const float* coef, int N)
+{
+	float ans;
+	float *p;
+	int i;
+
+	p = (float*)coef;
+	ans = *p++;
+
+	/*
+	for (i = 0; i < N; i++)
+		ans = ans * x  +  *p++;
+	*/
+
+	i = N;
+	do
+		ans = ans * x  +  *p++;
+	while (--i);
+
+	return (ans);
+}
+
+/*							p1evl()	*/
+/*                                          N
+ * Evaluate polynomial when coefficient of x  is 1.0.
+ * Otherwise same as polevl.
+ */
+
+static __inline__ float p1evlf(float x, const float *coef, int N)
+{
+	float ans;
+	float *p;
+	int i;
+
+	p = (float*)coef;
+	ans = x + *p++;
+	i = N - 1;
+
+	do
+		ans = ans * x  + *p++;
+	while (--i);
+
+	return (ans);
+}
+
diff --git a/winsup/cygwin/math/cexp.def.h b/winsup/cygwin/math/cexp.def.h
new file mode 100644
index 000000000..c0c97b70f
--- /dev/null
+++ b/winsup/cygwin/math/cexp.def.h
@@ -0,0 +1,111 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(cexp) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE s_x, c_x, exp_val, v;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_INFINITE)
+  {
+    if (i_class != FP_NAN && i_class != FP_INFINITE)
+    {
+      v = signbit (__real__ z) ? __FLT_CST(0.0) : __FLT_HUGE_VAL;
+
+      if (i_class == FP_ZERO)
+      {
+	__real__ ret = v;
+	__imag__ ret = __imag__ z;
+	return ret;
+      }
+
+      __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+      __real__ ret = __FLT_ABI(copysign) (v, c_x);
+      __imag__ ret = __FLT_ABI(copysign) (v, s_x);
+      return ret;
+    }
+
+    if (signbit (__real__ z) == 0)
+    {
+      __real__ ret = __FLT_HUGE_VAL;
+      __imag__ ret = __FLT_NAN;
+    }
+    else
+    {
+      __real__ ret = __FLT_CST(0.0);
+      __imag__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z);
+    }
+    return ret;
+  }
+
+  if (r_class == FP_NAN || i_class == FP_NAN || i_class == FP_INFINITE)
+  {
+    __real__ ret = __FLT_NAN;
+    if (i_class == FP_ZERO)
+      __imag__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z);
+    else
+      __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  exp_val = __FLT_ABI(exp) (__real__ z);
+
+  __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+  if (isfinite (exp_val))
+  {
+    __real__ ret = exp_val * c_x;
+    __imag__ ret = exp_val * s_x;
+  }
+  else
+  {
+    __real__ ret = __FLT_ABI(copysign) (exp_val, c_x);
+    __imag__ ret = __FLT_ABI(copysign) (exp_val, s_x);
+  }
+  return ret;
+}
diff --git a/winsup/cygwin/math/cexpl.c b/winsup/cygwin/math/cexpl.c
new file mode 100644
index 000000000..9c33bc05c
--- /dev/null
+++ b/winsup/cygwin/math/cexpl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "cexp.def.h"
diff --git a/winsup/cygwin/math/cimag.def.h b/winsup/cygwin/math/cimag.def.h
new file mode 100644
index 000000000..0212d9390
--- /dev/null
+++ b/winsup/cygwin/math/cimag.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __cdecl
+__FLT_ABI(cimag) (__FLT_TYPE __complex z)
+{
+  return __imag__ z;
+}
diff --git a/winsup/cygwin/math/cimagl.c b/winsup/cygwin/math/cimagl.c
new file mode 100644
index 000000000..94835d745
--- /dev/null
+++ b/winsup/cygwin/math/cimagl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "cimag.def.h"
diff --git a/winsup/cygwin/math/clog.def.h b/winsup/cygwin/math/clog.def.h
new file mode 100644
index 000000000..604c3f321
--- /dev/null
+++ b/winsup/cygwin/math/clog.def.h
@@ -0,0 +1,71 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(clog) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_ZERO && i_class == FP_ZERO)
+  {
+    __imag__ ret = signbit (__real__ z) ? __FLT_PI : __FLT_CST(0.0);
+    __imag__ ret = __FLT_ABI(copysign) (__imag__ ret, __imag__ z);
+    __real__ ret = -__FLT_CST(1.0) / __FLT_ABI(fabs) (__real__ z);
+    return ret;
+  }
+
+  if (r_class == FP_NAN || i_class == FP_NAN)
+  {
+    __imag__ ret = __FLT_NAN;
+    __real__ ret = ((r_class == FP_INFINITE || i_class == FP_INFINITE) ? __FLT_HUGE_VAL : __FLT_NAN);
+
+    return ret;
+  }
+
+  __real__ ret = __FLT_ABI(log) (__FLT_ABI(hypot) (__real__ z, __imag__ z));
+  __imag__ ret = __FLT_ABI(atan2) (__imag__ z, __real__ z);
+  return ret;
+}
diff --git a/winsup/cygwin/math/clog10.def.h b/winsup/cygwin/math/clog10.def.h
new file mode 100644
index 000000000..cdd4eb6b5
--- /dev/null
+++ b/winsup/cygwin/math/clog10.def.h
@@ -0,0 +1,71 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(clog10) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_ZERO && i_class == FP_ZERO)
+  {
+    __imag__ ret = signbit (__real__ z) ? __FLT_PI : __FLT_CST(0.0);
+    __imag__ ret = __FLT_ABI(copysign) (__imag__ ret, __imag__ z);
+    __real__ ret = -__FLT_CST(1.0) / __FLT_ABI(fabs) (__real__ z);
+    return ret;
+  }
+
+  if (r_class == FP_NAN || i_class == FP_NAN)
+  {
+    __imag__ ret = __FLT_NAN;
+    __real__ ret = ((r_class == FP_INFINITE || i_class == FP_INFINITE) ? __FLT_HUGE_VAL : __FLT_NAN);
+
+    return ret;
+  }
+
+  __real__ ret = __FLT_ABI(log10) (__FLT_ABI(hypot) (__real__ z, __imag__ z));
+  __imag__ ret = __FLT_LOG10E * __FLT_ABI(atan2) (__imag__ z, __real__ z);
+  return ret;
+}
diff --git a/winsup/cygwin/math/clog10l.c b/winsup/cygwin/math/clog10l.c
new file mode 100644
index 000000000..8baa2aafd
--- /dev/null
+++ b/winsup/cygwin/math/clog10l.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "clog10.def.h"
diff --git a/winsup/cygwin/math/clogl.c b/winsup/cygwin/math/clogl.c
new file mode 100644
index 000000000..383fcfa0f
--- /dev/null
+++ b/winsup/cygwin/math/clogl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "clog.def.h"
diff --git a/winsup/cygwin/math/complex_internal.h b/winsup/cygwin/math/complex_internal.h
new file mode 100644
index 000000000..b230b15b8
--- /dev/null
+++ b/winsup/cygwin/math/complex_internal.h
@@ -0,0 +1,153 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef __CYGWIN__
+/* Disable __IMPORT when defining __fdlib_version. */
+#define _COMPILING_NEWLIB
+#define _GNU_SOURCE
+#endif
+#include <math.h>
+#include <complex.h>
+
+/* Define some PI constants for long double, as they are not defined in math.h  */
+#ifndef M_PI_4l
+#define M_PI_4l 0.7853981633974483096156608458198757L
+#define M_PI_2l 1.5707963267948966192313216916397514L
+#define M_PIl   3.1415926535897932384626433832795029L
+#endif
+
+/* NAN builtins for gcc, as they are not part of math.h  */
+#ifndef NANF
+#define NANF __builtin_nanf ("")
+#endif
+#ifndef NANL
+#define NANL __builtin_nanl ("")
+#endif
+
+/* Some more helpers.  */
+#define M_PI_3_4  (M_PI - M_PI_4)
+#define M_PI_3_4l (M_PIl - M_PI_4l)
+
+#if defined(_NEW_COMPLEX_FLOAT)
+# define __FLT_TYPE	float
+# define __FLT_ABI(N)	N##f
+# define __FLT_CST(N)	N##F
+# define __FLT_EPSILON  __FLT_EPSILON__
+# define __FLT_NAN	NANF
+# define __FLT_HUGE_VAL	HUGE_VALF
+# define __FLT_PI	M_PI
+# define __FLT_PI_2	M_PI_2
+# define __FLT_PI_4	M_PI_4
+# define __FLT_PI_3_4	M_PI_3_4
+# define __FLT_MAXLOG	88.72283905206835F
+# define __FLT_MINLOG	-103.278929903431851103F
+# define __FLT_LOGE2	0.693147180559945309F
+# define __FLT_LOG10E   0.434294481903251828F
+# define __FLT_REPORT(NAME) NAME "f"
+#elif defined(_NEW_COMPLEX_DOUBLE)
+# define __FLT_TYPE	double
+# define __FLT_ABI(N)	N
+# define __FLT_EPSILON  __DBL_EPSILON__
+# define __FLT_CST(N)	N
+# define __FLT_NAN	NAN
+# define __FLT_HUGE_VAL	HUGE_VAL
+# define __FLT_PI	M_PI
+# define __FLT_PI_2	M_PI_2
+# define __FLT_PI_4	M_PI_4
+# define __FLT_PI_3_4	M_PI_3_4
+# define __FLT_MAXLOG	7.09782712893383996843E2
+# define __FLT_MINLOG	-7.45133219101941108420E2
+# define __FLT_LOGE2	6.93147180559945309417E-1
+# define __FLT_LOG10E   4.34294481903251827651E-1
+# define __FLT_REPORT(NAME)	NAME
+#elif defined(_NEW_COMPLEX_LDOUBLE)
+# define __FLT_TYPE	long double
+# define __FLT_ABI(N)	N##l
+# define __FLT_CST(N)	N##L
+# define __FLT_EPSILON  __LDBL_EPSILON__
+# define __FLT_NAN	NANL
+# define __FLT_HUGE_VAL	HUGE_VALL
+# define __FLT_PI	M_PIl
+# define __FLT_PI_2	M_PI_2l
+# define __FLT_PI_4	M_PI_4l
+# define __FLT_PI_3_4	M_PI_3_4l
+# define __FLT_MAXLOG	1.1356523406294143949492E4L
+# define __FLT_MINLOG	-1.1355137111933024058873E4L
+# define __FLT_LOGE2	6.9314718055994530941723E-1L
+# define __FLT_LOG10E   4.3429448190325182765113E-1L
+# define __FLT_REPORT(NAME) NAME "l"
+#else
+# error "Unknown complex number type"
+#endif
+
+#define __FLT_RPT_DOMAIN(NAME, ARG1, ARG2, RSLT) \
+	errno = EDOM, \
+	__mingw_raise_matherr (_DOMAIN, __FLT_REPORT(NAME), (double) (ARG1), \
+			       (double) (ARG2), (double) (RSLT))
+#define __FLT_RPT_ERANGE(NAME, ARG1, ARG2, RSLT, OVL) \
+	errno = ERANGE, \
+        __mingw_raise_matherr (((OVL) ? _OVERFLOW : _UNDERFLOW), \
+			       __FLT_REPORT(NAME), (double) (ARG1), \
+                               (double) (ARG2), (double) (RSLT))
+
+#ifdef __CYGWIN__
+inline void __attribute__ ((always_inline))
+__mingw_raise_matherr (int typ, const char *name, double a1, double a2,
+		       double rslt)
+{
+  if (_LIB_VERSION != _POSIX_)
+    {
+      struct exception ex;
+      ex.type = typ;
+      ex.name = (char*)name;
+      ex.arg1 = a1;
+      ex.arg2 = a2;
+      ex.retval = rslt;
+      matherr(&ex);
+    }
+}
+#define _DOMAIN		DOMAIN
+#define _OVERFLOW	OVERFLOW
+#define _UNDERFLOW	UNDERFLOW
+#endif
diff --git a/winsup/cygwin/math/conj.def.h b/winsup/cygwin/math/conj.def.h
new file mode 100644
index 000000000..35fa8989d
--- /dev/null
+++ b/winsup/cygwin/math/conj.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(conj) (__FLT_TYPE __complex__ z)
+{
+  return ~z;
+}
diff --git a/winsup/cygwin/math/conjl.c b/winsup/cygwin/math/conjl.c
new file mode 100644
index 000000000..52e32e65a
--- /dev/null
+++ b/winsup/cygwin/math/conjl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "conj.def.h"
diff --git a/winsup/cygwin/math/copysignl.S b/winsup/cygwin/math/copysignl.S
new file mode 100644
index 000000000..ffe6240d5
--- /dev/null
+++ b/winsup/cygwin/math/copysignl.S
@@ -0,0 +1,56 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Changes for long double by Ulrich Drepper <drepper@cygnus.com>
+ * Public domain.
+ */
+#include <_mingw_mac.h>
+
+	.file	"copysignl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+
+	.globl __MINGW_USYMBOL(copysignl)
+	.def	__MINGW_USYMBOL(copysignl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(copysignl):
+#if defined(_AMD64_) || defined(__x86_64__)
+	movq	(%rdx), %rax
+	movq	%rax, (%rcx)
+	movq	8(%rdx), %rax
+	movq	8(%r8), %rdx
+	andq	$0x777f, %rax
+	andq	$0x8000, %rdx
+	orq	%rdx, %rax
+	movq	%rax, 8(%rcx)
+	movq	%rcx, %rax
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	fcmpzd	d1
+	fmstat
+	bmi	1f /* jump if d1 is negative */
+	fcmpzd	d0
+	fmstat
+	vnegmi.f64	d0, d0 /* negate d0 if it is negative */
+	bx	lr
+	1: fcmpzd	d0
+	fmstat
+	vnegpl.f64	d0, d0 /* negate d0 if it is positive */
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	movl	24(%esp),%edx
+	movl	12(%esp),%eax
+	andl	$0x8000,%edx
+	andl	$0x7fff,%eax
+	orl	%edx,%eax
+	movl	%eax,12(%esp)
+	fldt	4(%esp)
+	ret
+#endif
diff --git a/winsup/cygwin/math/cos.def.h b/winsup/cygwin/math/cos.def.h
new file mode 100644
index 000000000..1058d031f
--- /dev/null
+++ b/winsup/cygwin/math/cos.def.h
@@ -0,0 +1,65 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+extern long double __cosl_internal (long double);
+
+__FLT_TYPE
+__FLT_ABI(cos) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN)
+    {
+      __FLT_RPT_DOMAIN ("cos", x, 0.0, x);
+      return x;
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      __FLT_RPT_DOMAIN ("cos", x, 0.0, __FLT_NAN);
+      return __FLT_NAN;
+    }
+  return (__FLT_TYPE) __cosl_internal ((long double) x);
+}
diff --git a/winsup/cygwin/math/coshl.c b/winsup/cygwin/math/coshl.c
new file mode 100644
index 000000000..d7eb4b7cb
--- /dev/null
+++ b/winsup/cygwin/math/coshl.c
@@ -0,0 +1,45 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_mconf.h"
+
+#ifndef _SET_ERRNO
+#define _SET_ERRNO(x)
+#endif
+
+long double coshl(long double x)
+{
+  long double y;
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN)
+    {
+      errno = EDOM;
+      return x;
+    }
+  else if (x_class == FP_INFINITE)
+    {
+       errno = ERANGE;
+       return x;
+    }
+  x = fabsl (x);
+  if (x > (MAXLOGL + LOGE2L))
+    {
+      errno = ERANGE;
+#ifdef INFINITIES
+      return (INFINITYL);
+#else
+      return (MAXNUML);
+#endif
+    }
+  if (x >= (MAXLOGL - LOGE2L))
+    {
+      y = expl(0.5L * x);
+      y = (0.5L * y) * y;
+      return y;
+    }
+  y = expl(x);
+  y = 0.5L * (y + 1.0L / y);
+  return y;
+}
diff --git a/winsup/cygwin/math/cosl.c b/winsup/cygwin/math/cosl.c
new file mode 100644
index 000000000..f798862d3
--- /dev/null
+++ b/winsup/cygwin/math/cosl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "cos.def.h"
diff --git a/winsup/cygwin/math/cosl_internal.S b/winsup/cygwin/math/cosl_internal.S
new file mode 100644
index 000000000..3c8f60d14
--- /dev/null
+++ b/winsup/cygwin/math/cosl_internal.S
@@ -0,0 +1,55 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"cosl_internal.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(__cosl_internal)
+	.def	__MINGW_USYMBOL(__cosl_internal);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(__cosl_internal):
+#ifdef __x86_64__
+	fldt	(%rdx)
+	fcos
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jz	1f
+	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fcos
+1:	movq %rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt (%rcx)
+	ret
+#else
+	fldt	4(%esp)
+	fcos
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	1f
+	ret
+1:	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fcos
+	ret
+#endif
+
diff --git a/winsup/cygwin/math/cossin.c b/winsup/cygwin/math/cossin.c
new file mode 100644
index 000000000..0095daa66
--- /dev/null
+++ b/winsup/cygwin/math/cossin.c
@@ -0,0 +1,75 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+void sincos (double __x, double *p_sin, double *p_cos);
+void sincosl (long double __x, long double *p_sin, long double *p_cos);
+void sincosf (float __x, float *p_sin, float *p_cos);
+
+void sincos (double __x, double *p_sin, double *p_cos)
+{
+  long double c, s;
+
+  __asm__ __volatile__ ("fsincos\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jz        1f\n\t"
+    "fldpi\n\t"
+    "fadd      %%st(0)\n\t"
+    "fxch      %%st(1)\n\t"
+    "2: fprem1\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jnz       2b\n\t"
+    "fstp      %%st(1)\n\t"
+    "fsincos\n\t"
+    "1:" : "=t" (c), "=u" (s) : "0" (__x));
+  *p_sin = (double) s;
+  *p_cos = (double) c;
+}
+
+void sincosf (float __x, float *p_sin, float *p_cos)
+{
+  long double c, s;
+
+  __asm__ __volatile__ ("fsincos\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jz        1f\n\t"
+    "fldpi\n\t"
+    "fadd      %%st(0)\n\t"
+    "fxch      %%st(1)\n\t"
+    "2: fprem1\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jnz       2b\n\t"
+    "fstp      %%st(1)\n\t"
+    "fsincos\n\t"
+    "1:" : "=t" (c), "=u" (s) : "0" (__x));
+  *p_sin = (float) s;
+  *p_cos = (float) c;
+}
+
+void sincosl (long double __x, long double *p_sin, long double *p_cos)
+{
+  long double c, s;
+
+  __asm__ __volatile__ ("fsincos\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jz        1f\n\t"
+    "fldpi\n\t"
+    "fadd      %%st(0)\n\t"
+    "fxch      %%st(1)\n\t"
+    "2: fprem1\n\t"
+    "fnstsw    %%ax\n\t"
+    "testl     $0x400, %%eax\n\t"
+    "jnz       2b\n\t"
+    "fstp      %%st(1)\n\t"
+    "fsincos\n\t"
+    "1:" : "=t" (c), "=u" (s) : "0" (__x));
+  *p_sin = s;
+  *p_cos = c;
+}
diff --git a/winsup/cygwin/math/cpow.def.h b/winsup/cygwin/math/cpow.def.h
new file mode 100644
index 000000000..984224b96
--- /dev/null
+++ b/winsup/cygwin/math/cpow.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(cpow) (__FLT_TYPE __complex__ z, __FLT_TYPE __complex__ x)
+{
+  return __FLT_ABI(cexp) (x * __FLT_ABI(clog) (z));
+}
diff --git a/winsup/cygwin/math/cpowl.c b/winsup/cygwin/math/cpowl.c
new file mode 100644
index 000000000..42edb7996
--- /dev/null
+++ b/winsup/cygwin/math/cpowl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "cpow.def.h"
diff --git a/winsup/cygwin/math/cproj.def.h b/winsup/cygwin/math/cproj.def.h
new file mode 100644
index 000000000..e15d779f7
--- /dev/null
+++ b/winsup/cygwin/math/cproj.def.h
@@ -0,0 +1,58 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(cproj) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+
+  if (isinf (__real__ z) || isinf (__imag__ z))
+  {
+    __real__ ret = INFINITY;
+    __imag__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z);
+    return ret;
+  }
+
+  return z;
+}
diff --git a/winsup/cygwin/math/cprojl.c b/winsup/cygwin/math/cprojl.c
new file mode 100644
index 000000000..d48d10877
--- /dev/null
+++ b/winsup/cygwin/math/cprojl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "cproj.def.h"
diff --git a/winsup/cygwin/math/creal.def.h b/winsup/cygwin/math/creal.def.h
new file mode 100644
index 000000000..554c99d8c
--- /dev/null
+++ b/winsup/cygwin/math/creal.def.h
@@ -0,0 +1,49 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE
+__FLT_ABI(creal) (__FLT_TYPE __complex__ z)
+{
+  return __real__ z;
+}
diff --git a/winsup/cygwin/math/creall.c b/winsup/cygwin/math/creall.c
new file mode 100644
index 000000000..e46c8ea37
--- /dev/null
+++ b/winsup/cygwin/math/creall.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "creal.def.h"
diff --git a/winsup/cygwin/math/csin.def.h b/winsup/cygwin/math/csin.def.h
new file mode 100644
index 000000000..cf9cfe108
--- /dev/null
+++ b/winsup/cygwin/math/csin.def.h
@@ -0,0 +1,61 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(csin) (__FLT_TYPE __complex__ z)
+{
+  /* Annex G.6: csin(z) = -i csinh (iz) */
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+
+  __real__ x = -__imag__ z;
+  __imag__ x = __real__ z;
+
+  x = __FLT_ABI(csinh) (x);
+
+  __real__ ret = __imag__ x;
+  __imag__ ret = -__real__ x;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/csinh.def.h b/winsup/cygwin/math/csinh.def.h
new file mode 100644
index 000000000..3e07d2bab
--- /dev/null
+++ b/winsup/cygwin/math/csinh.def.h
@@ -0,0 +1,107 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(csinh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE s_x, c_x;
+  int negate = signbit (__real__ z);
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  __real__ z = __FLT_ABI(fabs) (__real__ z);
+
+  if (r_class == FP_NAN)
+  {
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __imag__ z == __FLT_CST(0.0) ? __imag__ z : __FLT_NAN;
+
+    return ret;
+  }
+
+  if (r_class == FP_INFINITE)
+  {
+    if (i_class == FP_ZERO)
+    {
+      __real__ ret = negate ? -__FLT_HUGE_VAL : __FLT_HUGE_VAL;
+      __imag__ ret = __imag__ z;
+      return ret;
+    }
+
+    if (i_class == FP_NAN || i_class == FP_INFINITE)
+    {
+      __real__ ret = __FLT_HUGE_VAL;
+      __imag__ ret = __FLT_NAN + __FLT_NAN;
+
+      return ret;
+    }
+    __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+    __real__ ret = __FLT_ABI(copysign) (__FLT_HUGE_VAL, c_x);
+    __imag__ ret = __FLT_ABI(copysign) (__FLT_HUGE_VAL, s_x);
+
+    if (negate)
+    __real__ ret = -__real__ ret;
+    return ret;
+  }
+
+  if (i_class == FP_NAN || i_class == FP_INFINITE)
+  {
+    __real__ ret = (r_class == FP_ZERO
+      ? (__FLT_ABI(copysign) (__FLT_CST(0.0), negate ? -__FLT_CST(1.0) : __FLT_CST(1.0))) : __FLT_NAN);
+    __imag__ ret = (r_class == FP_ZERO ? (__FLT_NAN + __FLT_NAN) : __FLT_NAN);
+
+    return ret;
+  }
+
+  __FLT_ABI(sincos) (__imag__ z, &s_x, &c_x);
+
+  __real__ ret = __FLT_ABI(sinh) (__real__ z) * c_x;
+  __imag__ ret = __FLT_ABI(cosh) (__real__ z) * s_x;
+
+  if (negate)
+    __real__ ret = -__real__ ret;
+  return ret;
+}
diff --git a/winsup/cygwin/math/csinl.c b/winsup/cygwin/math/csinl.c
new file mode 100644
index 000000000..de04104c8
--- /dev/null
+++ b/winsup/cygwin/math/csinl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "csinh.def.h"
+#include "csin.def.h"
diff --git a/winsup/cygwin/math/csqrt.def.h b/winsup/cygwin/math/csqrt.def.h
new file mode 100644
index 000000000..714f303c1
--- /dev/null
+++ b/winsup/cygwin/math/csqrt.def.h
@@ -0,0 +1,122 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(csqrt) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE d, r, s;
+  int r_class = fpclassify (__real__ z);
+  int i_class = fpclassify (__imag__ z);
+
+  if (r_class == FP_INFINITE || r_class == FP_NAN || i_class == FP_INFINITE || i_class == FP_NAN)
+  {
+    if (i_class == FP_INFINITE)
+    {
+      __real__ ret = __FLT_HUGE_VAL;
+      __imag__ ret = __imag__ z;
+      return ret;
+    }
+
+    if (r_class == FP_INFINITE)
+    {
+      if (__real__ z < __FLT_CST(0.0))
+      {
+	__real__ ret = i_class == FP_NAN ? __FLT_NAN : __FLT_CST(0.0);
+	__imag__ ret = __FLT_ABI(copysign) (__FLT_HUGE_VAL, __imag__ z);
+	return ret;
+      }
+
+      __real__ ret = __real__ z;
+      __imag__ ret = (i_class == FP_NAN
+	? __FLT_NAN : __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z));
+      return ret;
+    }
+
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  if (i_class == FP_ZERO)
+  {
+    if (__real__ z < __FLT_CST(0.0))
+    {
+      __real__ ret = __FLT_CST(0.0);
+      __imag__ ret = __FLT_ABI(copysign) (__FLT_ABI(sqrt) (-__real__ z), __imag__ z);
+    }
+    else
+    {
+      __real__ ret = __FLT_ABI(fabs) (__FLT_ABI(sqrt) (__real__ z));
+      __imag__ ret = __FLT_ABI(copysign) (__FLT_CST(0.0), __imag__ z);
+    }
+    return ret;
+  }
+
+  if (r_class == FP_ZERO)
+  {
+    r = __FLT_ABI(sqrt) (__FLT_CST(0.5) * __FLT_ABI(fabs) (__imag__ z));
+
+    __real__ ret = r;
+    __imag__ ret = __FLT_ABI(copysign) (r, __imag__ z);
+    return ret;
+  }
+
+  d = __FLT_ABI(hypot) (__real__ z, __imag__ z);
+  if (__real__ z > __FLT_CST(0.0))
+  {
+    r = __FLT_ABI(sqrt) (__FLT_CST(0.5) * d + __FLT_CST(0.5) * __real__ z);
+    s = (__FLT_CST(0.5) * __imag__ z) / r;
+  }
+  else
+  {
+    s = __FLT_ABI(sqrt) (__FLT_CST(0.5) * d - __FLT_CST(0.5) * __real__ z);
+    r = __FLT_ABI(fabs) ((__FLT_CST(0.5) * __imag__ z) / s);
+  }
+
+  __real__ ret = r;
+  __imag__ ret = __FLT_ABI(copysign) (s, __imag__ z);
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/csqrtl.c b/winsup/cygwin/math/csqrtl.c
new file mode 100644
index 000000000..1993289b5
--- /dev/null
+++ b/winsup/cygwin/math/csqrtl.c
@@ -0,0 +1,48 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+#include "csqrt.def.h"
diff --git a/winsup/cygwin/math/ctan.def.h b/winsup/cygwin/math/ctan.def.h
new file mode 100644
index 000000000..28df5f330
--- /dev/null
+++ b/winsup/cygwin/math/ctan.def.h
@@ -0,0 +1,61 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(ctan) (__FLT_TYPE __complex__ z)
+{
+  /* Annex G.6: ctan(z) = -i ctanh (iz) */
+  __complex__ __FLT_TYPE ret;
+  __complex__ __FLT_TYPE x;
+
+  __real__ x = -__imag__ z;
+  __imag__ x = __real__ z;
+
+  x = __FLT_ABI(ctanh) (x);
+
+  __real__ ret = __imag__ x;
+  __imag__ ret = -__real__ x;
+
+  return ret;
+}
diff --git a/winsup/cygwin/math/ctanh.def.h b/winsup/cygwin/math/ctanh.def.h
new file mode 100644
index 000000000..11a183648
--- /dev/null
+++ b/winsup/cygwin/math/ctanh.def.h
@@ -0,0 +1,94 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+__FLT_TYPE __complex__ __cdecl
+__FLT_ABI(ctanh) (__FLT_TYPE __complex__ z)
+{
+  __complex__ __FLT_TYPE ret;
+  __FLT_TYPE s, c, d;
+
+  if (!isfinite (__real__ z) || !isfinite (__imag__ z))
+  {
+    if (isinf (__real__ z))
+    {
+      __real__ ret = __FLT_ABI(copysign) (__FLT_CST(1.0), __real__ z);
+
+      /* fmod will return NaN if __imag__ z is infinity. This is actually
+	 OK, because imaginary infinity returns a + or - zero (unspecified).
+	 For +x, sin (x) is negative if fmod (x, 2pi) > pi.
+	 For -x, sin (x) is positive if fmod (x, 2pi) < pi.
+	 We use epsilon to ensure that the zeros are detected properly with
+	 float and long double comparisons.  */
+      s = __FLT_ABI(fmod) (__imag__ z, __FLT_PI);
+      if (signbit (__imag__ z))
+	__imag__ ret = s + __FLT_PI_2 < -__FLT_EPSILON ? 0.0 : -0.0;
+      else
+	__imag__ ret = s - __FLT_PI_2 > __FLT_EPSILON ? -0.0 : 0.0;
+      return ret;
+    }
+
+    if (__imag__ z == __FLT_CST(0.0))
+      return z;
+
+    __real__ ret = __FLT_NAN;
+    __imag__ ret = __FLT_NAN;
+    return ret;
+  }
+
+  __FLT_ABI(sincos) (__FLT_CST(2.0) * __imag__ z, &s, &c);
+
+  d = (__FLT_ABI(cosh) (__FLT_CST(2.0) * __real__ z) + c);
+
+  if (d == __FLT_CST(0.0))
+  {
+    __complex__ __FLT_TYPE ez = __FLT_ABI(cexp) (z);
+    __complex__ __FLT_TYPE emz = __FLT_ABI(cexp) (-z);
+
+    return (ez - emz) / (ez + emz);
+  }
+
+  __real__ ret = __FLT_ABI(sinh) (__FLT_CST(2.0) * __real__ z) / d;
+  __imag__ ret = s / d;
+  return ret;
+}
diff --git a/winsup/cygwin/math/ctanl.c b/winsup/cygwin/math/ctanl.c
new file mode 100644
index 000000000..eb7e37807
--- /dev/null
+++ b/winsup/cygwin/math/ctanl.c
@@ -0,0 +1,50 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* long double version of the functions.  */
+#define  _NEW_COMPLEX_LDOUBLE 1
+#include "complex_internal.h"
+
+#include "ctanh.def.h"
+#include "ctan.def.h"
diff --git a/winsup/cygwin/math/erfl.c b/winsup/cygwin/math/erfl.c
new file mode 100644
index 000000000..3832fe9e0
--- /dev/null
+++ b/winsup/cygwin/math/erfl.c
@@ -0,0 +1,303 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*							erfl.c
+ *
+ *	Error function
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * long double x, y, erfl();
+ *
+ * y = erfl( x );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * The integral is
+ *
+ *                           x 
+ *                            -
+ *                 2         | |          2
+ *   erf(x)  =  --------     |    exp( - t  ) dt.
+ *              sqrt(pi)   | |
+ *                          -
+ *                           0
+ *
+ * The magnitude of x is limited to about 106.56 for IEEE
+ * arithmetic; 1 or -1 is returned outside this range.
+ *
+ * For 0 <= |x| < 1, erf(x) = x * P6(x^2)/Q6(x^2);
+ * Otherwise: erf(x) = 1 - erfc(x).
+ *
+ *
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic   domain     # trials      peak         rms
+ *    IEEE      0,1         50000       2.0e-19     5.7e-20
+ *
+ */
+
+/*							erfcl.c
+ *
+ *	Complementary error function
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * long double x, y, erfcl();
+ *
+ * y = erfcl( x );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ *
+ *  1 - erf(x) =
+ *
+ *                           inf. 
+ *                             -
+ *                  2         | |          2
+ *   erfc(x)  =  --------     |    exp( - t  ) dt
+ *               sqrt(pi)   | |
+ *                           -
+ *                            x
+ *
+ *
+ * For small x, erfc(x) = 1 - erf(x); otherwise rational
+ * approximations are computed.
+ *
+ * A special function expx2l.c is used to suppress error amplification
+ * in computing exp(-x^2).
+ *
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic   domain     # trials      peak         rms
+ *    IEEE      0,13        50000      8.4e-19      9.7e-20
+ *    IEEE      6,106.56    20000      2.9e-19      7.1e-20
+ *
+ *
+ * ERROR MESSAGES:
+ *
+ *   message          condition              value returned
+ * erfcl underflow    x^2 > MAXLOGL              0.0
+ *
+ *
+ */
+
+
+/*
+Modified from file ndtrl.c
+Cephes Math Library Release 2.3:  January, 1995
+Copyright 1984, 1995 by Stephen L. Moshier
+*/
+
+#include <math.h>
+#include "cephes_mconf.h"
+
+long double erfl(long double x);
+
+/* erfc(x) = exp(-x^2) P(1/x)/Q(1/x)
+   1/8 <= 1/x <= 1
+   Peak relative error 5.8e-21  */
+
+static const uLD P[10] = {
+  { { 0x4bf0,0x9ad8,0x7a03,0x86c7,0x401d, 0, 0, 0 } },
+  { { 0xdf23,0xd843,0x4032,0x8881,0x401e, 0, 0, 0 } },
+  { { 0xd025,0xcfd5,0x8494,0x88d3,0x401e, 0, 0, 0 } },
+  { { 0xb6d0,0xc92b,0x5417,0xacb1,0x401d, 0, 0, 0 } },
+  { { 0xada8,0x356a,0x4982,0x94a6,0x401c, 0, 0, 0 } },
+  { { 0x4e13,0xcaee,0x9e31,0xb258,0x401a, 0, 0, 0 } },
+  { { 0x5840,0x554d,0x37a3,0x9239,0x4018, 0, 0, 0 } },
+  { { 0x3b58,0x3da2,0xaf02,0x9780,0x4015, 0, 0, 0 } },
+  { { 0x0144,0x489e,0xbe68,0x9c31,0x4011, 0, 0, 0 } },
+  { { 0x333b,0xd9e6,0xd404,0x986f,0xbfee, 0, 0, 0 } }
+};
+static const uLD Q[] = {
+  { { 0x0e43,0x302d,0x79ed,0x86c7,0x401d, 0, 0, 0 } },
+  { { 0xf817,0x9128,0xc0f8,0xd48b,0x401e, 0, 0, 0 } },
+  { { 0x8eae,0x8dad,0x6eb4,0x9aa2,0x401f, 0, 0, 0 } },
+  { { 0x00e7,0x7595,0xcd06,0x88bb,0x401f, 0, 0, 0 } },
+  { { 0x4991,0xcfda,0x52f1,0xa2a9,0x401e, 0, 0, 0 } },
+  { { 0xc39d,0xe415,0xc43d,0x87c0,0x401d, 0, 0, 0 } },
+  { { 0xa75d,0x436f,0x30dd,0xa027,0x401b, 0, 0, 0 } },
+  { { 0xc4cb,0x305a,0xbf78,0x8220,0x4019, 0, 0, 0 } },
+  { { 0x3708,0x33b1,0x07fa,0x8644,0x4016, 0, 0, 0 } },
+  { { 0x24fa,0x96f6,0x7153,0x8a6c,0x4012, 0, 0, 0 } }
+};
+
+/* erfc(x) = exp(-x^2) 1/x R(1/x^2) / S(1/x^2)
+   1/128 <= 1/x < 1/8
+   Peak relative error 1.9e-21  */
+
+static const uLD R[] = {
+  { { 0x260a,0xab95,0x2fc7,0xe7c4,0x4000, 0, 0, 0 } },
+  { { 0x4761,0x613e,0xdf6d,0xe58e,0x4001, 0, 0, 0 } },
+  { { 0x0615,0x4b00,0x575f,0xdc7b,0x4000, 0, 0, 0 } },
+  { { 0x521d,0x8527,0x3435,0x8dc2,0x3ffe, 0, 0, 0 } },
+  { { 0x22cf,0xc711,0x6c5b,0xdcfb,0x3ff9, 0, 0, 0 } }
+};
+static const uLD S[] = {
+  { { 0x5de6,0x17d7,0x54d6,0xaba9,0x4002, 0, 0, 0 } },
+  { { 0x55d5,0xd300,0xe71e,0xf564,0x4002, 0, 0, 0 } },
+  { { 0xb611,0x8f76,0xf020,0xd255,0x4001, 0, 0, 0 } },
+  { { 0x3684,0x3798,0xb793,0x80b0,0x3fff, 0, 0, 0 } },
+  { { 0xf5af,0x2fb2,0x1e57,0xc3d7,0x3ffa, 0, 0, 0 } }
+};
+
+/* erf(x)  = x T(x^2)/U(x^2)
+   0 <= x <= 1
+   Peak relative error 7.6e-23  */
+
+static const uLD T[] = {
+  { { 0xfd7a,0x3a1a,0x705b,0xe0c4,0x3ffb, 0, 0, 0 } },
+  { { 0x3128,0xc337,0x3716,0xace5,0x4001, 0, 0, 0 } },
+  { { 0x9517,0x4e93,0x540e,0x8f97,0x4007, 0, 0, 0 } },
+  { { 0x6118,0x6059,0x9093,0xa757,0x400a, 0, 0, 0 } },
+  { { 0xb954,0xa987,0xc60c,0xbc83,0x400e, 0, 0, 0 } },
+  { { 0x7a56,0xe45a,0xa4bd,0x975b,0x4010, 0, 0, 0 } },
+  { { 0xc446,0x6bab,0x0b2a,0x86d0,0x4013, 0, 0, 0 } }
+};
+
+static const uLD U[] = {
+  { { 0x3453,0x1f8e,0xf688,0xb507,0x4004, 0, 0, 0 } },
+  { { 0x71ac,0xb12f,0x21ca,0xf2e2,0x4008, 0, 0, 0 } },
+  { { 0xffe8,0x9cac,0x3b84,0xc2ac,0x400c, 0, 0, 0 } },
+  { { 0x481d,0x445b,0xc807,0xc232,0x400f, 0, 0, 0 } },
+  { { 0x9ad5,0x1aef,0x45b1,0xe25e,0x4011, 0, 0, 0 } },
+  { { 0x71a7,0x1cad,0x012e,0xeef3,0x4012, 0, 0, 0 } }
+};
+
+/*							expx2l.c
+ *
+ *	Exponential of squared argument
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * long double x, y, expmx2l();
+ * int sign;
+ *
+ * y = expx2l( x );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Computes y = exp(x*x) while suppressing error amplification
+ * that would ordinarily arise from the inexactness of the
+ * exponential argument x*x.
+ *
+ *
+ *
+ * ACCURACY:
+ *
+ *                      Relative error:
+ * arithmetic      domain        # trials      peak         rms
+ *   IEEE     -106.566, 106.566    10^5       1.6e-19     4.4e-20
+ *
+ */
+
+#define M 32768.0L
+#define MINV 3.0517578125e-5L
+
+static long double expx2l (long double x)
+{
+	long double u, u1, m, f;
+
+	x = fabsl (x);
+	/* Represent x as an exact multiple of M plus a residual.
+	   M is a power of 2 chosen so that exp(m * m) does not overflow
+	   or underflow and so that |x - m| is small.  */
+	m = MINV * floorl(M * x + 0.5L);
+	f = x - m;
+
+	/* x^2 = m^2 + 2mf + f^2 */
+	u = m * m;
+	u1 = 2 * m * f  +  f * f;
+
+	if ((u + u1) > MAXLOGL)
+		return (INFINITYL);
+
+	/* u is exact, u1 is small.  */
+	u = expl(u) * expl(u1);
+	return (u);
+}
+
+long double erfcl(long double a)
+{
+	long double p, q, x, y, z;
+
+	if (isinf (a))
+		return (signbit(a) ? 2.0 : 0.0);
+
+	x = fabsl (a);
+
+	if (x < 1.0L)
+		return (1.0L - erfl(a));
+
+	z = a * a;
+
+	if (z  > MAXLOGL)
+	{
+under:
+		mtherr("erfcl", UNDERFLOW);
+		errno = ERANGE;
+		return (signbit(a) ? 2.0 : 0.0);
+	}
+
+	/* Compute z = expl(a * a).  */
+	z = expx2l(a);
+	y = 1.0L/x;
+
+	if (x < 8.0L)
+	{
+		p = polevll(y, P, 9);
+		q = p1evll(y, Q, 10);
+	}
+	else
+	{
+		q = y * y;
+		p = y * polevll(q, R, 4);
+		q = p1evll(q, S, 5);
+	}
+	y = p/(q * z);
+
+	if (a < 0.0L)
+		y = 2.0L - y;
+
+	if (y == 0.0L)
+		goto under;
+
+	return (y);
+}
+
+long double erfl(long double x)
+{
+	long double y, z;
+
+	if (x == 0.0L)
+		return (x);
+
+	if (isinf (x))
+		return (signbit(x) ?  -1.0L : 1.0L);
+
+	if (fabsl(x) > 1.0L)
+		return (1.0L - erfcl(x));
+
+	z = x * x;
+	y = x * polevll(z, T, 6) / p1evll(z, U, 6);
+	return (y);
+}
diff --git a/winsup/cygwin/math/exp.def.h b/winsup/cygwin/math/exp.def.h
new file mode 100644
index 000000000..2419ef6d1
--- /dev/null
+++ b/winsup/cygwin/math/exp.def.h
@@ -0,0 +1,136 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+static long double c0 = 1.44268798828125L; // INV_LN2
+static long double c1 = 7.05260771340735992468e-6L;
+
+static long double
+__expl_internal (long double x)
+{
+  long double res = 0.0L;
+  asm ("fldl2e\n\t"             /* 1  log2(e)         */
+       "fmul %%st(1),%%st\n\t"  /* 1  x log2(e)       */
+
+#ifdef __x86_64__
+    "subq $8, %%rsp\n"
+    "fnstcw 4(%%rsp)\n"
+    "movzwl 4(%%rsp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%rsp)\n"
+    "fldcw (%%rsp)\n"
+    "frndint\n\t"            /* 1  i               */
+    "fld %%st(1)\n\t"        /* 2  x               */
+    "frndint\n\t"            /* 2  xi              */
+    "fldcw 4(%%rsp)\n"
+    "addq $8, %%rsp\n"
+#else
+    "push %%eax\n\tsubl $8, %%esp\n"
+    "fnstcw 4(%%esp)\n"
+    "movzwl 4(%%esp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%esp)\n"
+    "fldcw (%%esp)\n"
+    "frndint\n\t"            /* 1  i               */
+    "fld %%st(1)\n\t"        /* 2  x               */
+    "frndint\n\t"            /* 2  xi              */
+    "fldcw 4(%%esp)\n"
+    "addl $8, %%esp\n\tpop %%eax\n"
+#endif
+       "fld %%st(1)\n\t"        /* 3  i               */
+       "fldt %2\n\t"            /* 4  c0              */
+       "fld %%st(2)\n\t"        /* 5  xi              */
+       "fmul %%st(1),%%st\n\t"  /* 5  c0 xi           */
+       "fsubp %%st,%%st(2)\n\t" /* 4  f = c0 xi  - i  */
+       "fld %%st(4)\n\t"        /* 5  x               */
+       "fsub %%st(3),%%st\n\t"  /* 5  xf = x - xi     */
+       "fmulp %%st,%%st(1)\n\t" /* 4  c0 xf           */
+       "faddp %%st,%%st(1)\n\t" /* 3  f = f + c0 xf   */
+       "fldt %3\n\t"            /* 4                  */
+       "fmul %%st(4),%%st\n\t"  /* 4  c1 * x          */
+       "faddp %%st,%%st(1)\n\t" /* 3  f = f + c1 * x  */
+       "f2xm1\n\t"		/* 3 2^(fract(x * log2(e))) - 1 */
+       "fld1\n\t"               /* 4 1.0              */
+       "faddp\n\t"		/* 3 2^(fract(x * log2(e))) */
+       "fstp	%%st(1)\n\t"    /* 2  */
+       "fscale\n\t"	        /* 2 scale factor is st(1); e^x */
+       "fstp	%%st(1)\n\t"    /* 1  */
+       "fstp	%%st(1)\n\t"    /* 0  */
+       : "=t" (res) : "0" (x), "m" (c0), "m" (c1) : "ax", "dx");
+  return res;
+}
+
+__FLT_TYPE
+__FLT_ABI(exp) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN)
+    {
+      __FLT_RPT_DOMAIN ("exp", x, 0.0, x);
+      return x;
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      __FLT_TYPE r = (signbit (x) ? __FLT_CST (0.0) : __FLT_HUGE_VAL);
+      __FLT_RPT_ERANGE ("exp", x, 0.0, r, signbit (x));
+      return r;
+    }
+  else if (x_class == FP_ZERO)
+    {
+      return __FLT_CST (1.0);
+    }
+  else if (x > __FLT_MAXLOG)
+    {
+      __FLT_RPT_ERANGE ("exp", x, 0.0, __FLT_HUGE_VAL, 1);
+      return __FLT_HUGE_VAL;
+    }
+  else if (x < __FLT_MINLOG)
+    {
+      return __FLT_CST(0.0);
+    }
+  else
+    return (__FLT_TYPE) __expl_internal ((long double) x);
+}
diff --git a/winsup/cygwin/math/exp10l.c b/winsup/cygwin/math/exp10l.c
new file mode 100644
index 000000000..821b8f5c3
--- /dev/null
+++ b/winsup/cygwin/math/exp10l.c
@@ -0,0 +1,8 @@
+#undef exp10l
+#include <math.h>
+
+long double
+exp10l (long double x)
+{
+  return powl (10.0L, x);
+}
diff --git a/winsup/cygwin/math/exp2.S b/winsup/cygwin/math/exp2.S
new file mode 100644
index 000000000..37d4a2b89
--- /dev/null
+++ b/winsup/cygwin/math/exp2.S
@@ -0,0 +1,94 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"exp2.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(exp2)
+	.def	__MINGW_USYMBOL(exp2);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(exp2):
+#ifdef __x86_64__
+	subq	$24, %rsp
+	movsd	%xmm0,(%rsp)
+	fldl	(%rsp)
+	fxam				/* Is NaN or +-Inf?  */
+	fstsw	%ax
+	movb	$0x45, %dh
+	andb	%ah, %dh
+	cmpb	$0x05, %dh
+	je	1f			/* Is +-Inf, jump.  */
+	fld	%st
+  	subq $8, %rsp /* int(x) */
+    	fnstcw 4(%rsp)
+    	movzwl 4(%rsp), %eax
+    	orb $12, %ah
+    	movw %ax, (%rsp)
+    	fldcw (%rsp)
+    	frndint
+    	fldcw 4(%rsp)
+    	addq $8, %rsp
+	fsubr	%st,%st(1)		/* fract(x) */
+	fxch
+	f2xm1				/* 2^(fract(x)) - 1 */
+	fld1
+	faddp				/* 2^(fract(x)) */
+	fscale				/* e^x */
+	fstp	%st(1)
+	fstpl	(%rsp)
+	movsd	(%rsp),%xmm0
+	addq	$24, %rsp
+	ret
+
+1:	testl	$0x200, %eax		/* Test sign.  */
+	jz	2f			/* If positive, jump.  */
+	fstp	%st
+	fldz				/* Set result to 0.  */
+2:	fstpl	(%rsp)
+	movsd	(%rsp),%xmm0
+	addq	$24,%rsp
+	ret
+#else
+	fldl	4(%esp)
+/* I added the following ugly construct because exp(+-Inf) resulted
+   in NaN.  The ugliness results from the bright minds at Intel.
+   For the i686 the code can be written better.
+   -- drepper@cygnus.com.  */
+	fxam				/* Is NaN or +-Inf?  */
+	fstsw	%ax
+	movb	$0x45, %dh
+	andb	%ah, %dh
+	cmpb	$0x05, %dh
+	je	1f			/* Is +-Inf, jump.  */
+	fld	%st
+	subl $8, %esp /* int(x) */
+	fnstcw 4(%esp)
+	movzwl 4(%esp), %eax
+	orb $12, %ah
+	movw %ax, (%esp)
+	fldcw (%esp)
+	frndint
+	fldcw 4(%esp)
+	addl $8, %esp
+	fsubr	%st,%st(1)		/* fract(x) */
+	fxch
+	f2xm1				/* 2^(fract(x)) - 1 */
+	fld1
+	faddp				/* 2^(fract(x)) */
+	fscale				/* e^x */
+	fstp	%st(1)
+	ret
+
+1:	testl	$0x200, %eax		/* Test sign.  */
+	jz	2f			/* If positive, jump.  */
+	fstp	%st
+	fldz				/* Set result to 0.  */
+2:	ret
+#endif
diff --git a/winsup/cygwin/math/exp2l.S b/winsup/cygwin/math/exp2l.S
new file mode 100644
index 000000000..2e58c37b8
--- /dev/null
+++ b/winsup/cygwin/math/exp2l.S
@@ -0,0 +1,92 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"exp2l.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(exp2l)
+	.def	__MINGW_USYMBOL(exp2l);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(exp2l):
+#ifdef __x86_64__
+	fldt	(%rdx)
+	fxam				/* Is NaN or +-Inf?  */
+	fstsw	%ax
+	movb	$0x45, %dh
+	andb	%ah, %dh
+	cmpb	$0x05, %dh
+	je	1f			/* Is +-Inf, jump.  */
+	fld	%st
+  	subq $8, %rsp /* int(x) */
+    	fnstcw 4(%rsp)
+    	movzwl 4(%rsp), %eax
+    	orb $12, %ah
+    	movw %ax, (%rsp)
+    	fldcw (%rsp)
+    	frndint
+    	fldcw 4(%rsp)
+    	addq $8, %rsp
+	fsubr	%st,%st(1)		/* fract(x) */
+	fxch
+	f2xm1				/* 2^(fract(x)) - 1 */
+	fld1
+	faddp				/* 2^(fract(x)) */
+	fscale				/* e^x */
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+1:	testl	$0x200, %eax		/* Test sign.  */
+	jz	2f			/* If positive, jump.  */
+	fstp	%st
+	fldz				/* Set result to 0.  */
+2:	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldt	4(%esp)
+/* I added the following ugly construct because exp(+-Inf) resulted
+   in NaN.  The ugliness results from the bright minds at Intel.
+   For the i686 the code can be written better.
+   -- drepper@cygnus.com.  */
+	fxam				/* Is NaN or +-Inf?  */
+	fstsw	%ax
+	movb	$0x45, %dh
+	andb	%ah, %dh
+	cmpb	$0x05, %dh
+	je	1f			/* Is +-Inf, jump.  */
+	fld	%st
+	subl $8, %esp /* int(x) */
+	fnstcw 4(%esp)
+	movzwl 4(%esp), %eax
+	orb $12, %ah
+	movw %ax, (%esp)
+	fldcw (%esp)
+	frndint
+	fldcw 4(%esp)
+	addl $8, %esp
+	fsubr	%st,%st(1)		/* fract(x) */
+	fxch
+	f2xm1				/* 2^(fract(x)) - 1 */
+	fld1
+	faddp				/* 2^(fract(x)) */
+	fscale				/* e^x */
+	fstp	%st(1)
+	ret
+
+1:	testl	$0x200, %eax		/* Test sign.  */
+	jz	2f			/* If positive, jump.  */
+	fstp	%st
+	fldz				/* Set result to 0.  */
+2:	ret
+#endif
diff --git a/winsup/cygwin/math/expl.c b/winsup/cygwin/math/expl.c
new file mode 100644
index 000000000..7f4be6239
--- /dev/null
+++ b/winsup/cygwin/math/expl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "exp.def.h"
diff --git a/winsup/cygwin/math/expm1.def.h b/winsup/cygwin/math/expm1.def.h
new file mode 100644
index 000000000..5a2b6f498
--- /dev/null
+++ b/winsup/cygwin/math/expm1.def.h
@@ -0,0 +1,72 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+__FLT_TYPE
+__FLT_ABI(expm1) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN)
+  {
+    __FLT_RPT_DOMAIN ("expm1", x, 0.0, x);
+    return x;
+  }
+  else if (x_class == FP_INFINITE)
+  {
+    return (signbit (x) ? -__FLT_CST(1.0) : __FLT_HUGE_VAL);
+  }
+  else if (x_class == FP_ZERO)
+  {
+    return x;
+  }
+  if (__FLT_ABI (fabs) (x) < __FLT_LOGE2)
+    {
+      x /= __FLT_LOGE2;
+      __asm__ __volatile__ ("f2xm1" : "=t" (x) : "0" (x));
+      return x;
+    }
+  return __FLT_ABI (exp) (x) - __FLT_CST (1.0);
+}
diff --git a/winsup/cygwin/math/expm1l.c b/winsup/cygwin/math/expm1l.c
new file mode 100644
index 000000000..625fbb1d7
--- /dev/null
+++ b/winsup/cygwin/math/expm1l.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "expm1.def.h"
diff --git a/winsup/cygwin/math/fabsl.c b/winsup/cygwin/math/fabsl.c
new file mode 100644
index 000000000..2dfdfaa45
--- /dev/null
+++ b/winsup/cygwin/math/fabsl.c
@@ -0,0 +1,18 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double fabsl (long double x);
+
+long double
+fabsl (long double x)
+{
+#if defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_)
+  long double res = 0.0L;
+  asm ("fabs;" : "=t" (res) : "0" (x));
+  return res;
+#elif defined(__arm__) || defined(_ARM_)
+  return __builtin_fabsl (x);
+#endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_) */
+}
diff --git a/winsup/cygwin/math/fastmath.h b/winsup/cygwin/math/fastmath.h
new file mode 100644
index 000000000..a6bb467c2
--- /dev/null
+++ b/winsup/cygwin/math/fastmath.h
@@ -0,0 +1,120 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#ifndef _MINGWEX_FASTMATH_H_
+#define _MINGWEX_FASTMATH_H_
+
+/* Fast math inlines
+   No range or domain checks. No setting of errno.  No tweaks to
+   protect precision near range limits. */
+
+/* For now this is an internal header with just the functions that
+   are currently used in building libmingwex.a math components */
+
+/* FIXME: We really should get rid of the code duplication using euther
+   C++ templates or tgmath-type macros.  */  
+
+static __inline__ double __fast_sqrt (double x)
+{
+  double res;
+  asm __volatile__ ("fsqrt" : "=t" (res) : "0" (x));
+  return res;
+}
+
+static __inline__ long double __fast_sqrtl (long double x)
+{
+  long double res;
+  asm __volatile__ ("fsqrt" : "=t" (res) : "0" (x));
+  return res;
+}
+
+static __inline__ float __fast_sqrtf (float x)
+{
+  float res;
+  asm __volatile__ ("fsqrt" : "=t" (res) : "0" (x));
+  return res;
+}
+
+
+static __inline__ double __fast_log (double x)
+{
+   double res;
+   asm __volatile__
+     ("fldln2\n\t"
+      "fxch\n\t"
+      "fyl2x"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+static __inline__ long double __fast_logl (long double x)
+{
+  long double res;
+   asm __volatile__
+     ("fldln2\n\t"
+      "fxch\n\t"
+      "fyl2x"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+
+static __inline__ float __fast_logf (float x)
+{
+   float res;
+   asm __volatile__
+     ("fldln2\n\t"
+      "fxch\n\t"
+      "fyl2x"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+static __inline__ double __fast_log1p (double x)
+{
+  double res;
+  /* fyl2xp1 accurate only for |x| <= 1.0 - 0.5 * sqrt (2.0) */
+  if (fabs (x) >= 1.0 - 0.5 * 1.41421356237309504880)
+    res = __fast_log (1.0 + x);
+  else
+    asm __volatile__
+      ("fldln2\n\t"
+       "fxch\n\t"
+       "fyl2xp1"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+static __inline__ long double __fast_log1pl (long double x)
+{
+  long double res;
+  /* fyl2xp1 accurate only for |x| <= 1.0 - 0.5 * sqrt (2.0) */
+  if (fabsl (x) >= 1.0L - 0.5L * 1.41421356237309504880L)
+    res = __fast_logl (1.0L + x);
+  else
+    asm __volatile__
+      ("fldln2\n\t"
+       "fxch\n\t"
+       "fyl2xp1"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+static __inline__ float __fast_log1pf (float x)
+{
+  float res;
+  /* fyl2xp1 accurate only for |x| <= 1.0 - 0.5 * sqrt (2.0) */
+  if (fabsf (x) >= 1.0 - 0.5 * 1.41421356237309504880)
+    res = __fast_logf (1.0 + x);
+  else
+    asm __volatile__
+      ("fldln2\n\t"
+       "fxch\n\t"
+       "fyl2xp1"
+       : "=t" (res) : "0" (x) : "st(1)");
+   return res;
+}
+
+#endif
diff --git a/winsup/cygwin/math/fdiml.c b/winsup/cygwin/math/fdiml.c
new file mode 100644
index 000000000..3be0679ac
--- /dev/null
+++ b/winsup/cygwin/math/fdiml.c
@@ -0,0 +1,24 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <errno.h>
+#include <math.h>
+
+long double
+fdiml (long double x, long double y)
+{
+  int cx = fpclassify (x), cy = fpclassify (y);
+  long double r;
+
+  if (cx == FP_NAN || cy == FP_NAN
+      || (y < 0 && cx == FP_INFINITE && cy == FP_INFINITE))
+    return x - y;  /* Take care invalid flag is raised.  */
+  if (x <= y)
+    return 0.0;
+  r = x - y;
+  if (fpclassify (r) == FP_INFINITE)
+    errno = ERANGE;
+  return r;
+}
diff --git a/winsup/cygwin/math/finite.c b/winsup/cygwin/math/finite.c
new file mode 100644
index 000000000..bcef72a92
--- /dev/null
+++ b/winsup/cygwin/math/finite.c
@@ -0,0 +1,19 @@
+#include <math.h>
+
+int
+finite (double x)
+{
+  return __builtin_isfinite (x);
+}
+
+int
+finitef (float x)
+{
+  return __builtin_isfinite (x);
+}
+
+int
+finitel (long double x)
+{
+  return __builtin_isfinite (x);
+}
diff --git a/winsup/cygwin/math/floorl.S b/winsup/cygwin/math/floorl.S
new file mode 100644
index 000000000..19ab3f099
--- /dev/null
+++ b/winsup/cygwin/math/floorl.S
@@ -0,0 +1,72 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"floorl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	.globl __MINGW_USYMBOL(floorl)
+	.def	__MINGW_USYMBOL(floorl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(floorl):
+#if defined(_AMD64_) || defined(__x86_64__)
+	fldt	(%rdx)
+	subq	$24,%rsp
+
+	fstcw	8(%rsp)			/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x400,%edx		/* round towards -oo */
+	orl	8(%rsp),%edx
+	andl	$0xf7ff,%edx
+	movl	%edx,(%rsp)
+	fldcw	(%rsp)			/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	8(%rsp)			/* restore original control word */
+
+	addq	$24,%rsp
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	bic		r0, r1, #0x00c00000
+	orr		r0, r0, #0x00800000 /* Round towards Minus Infinity */
+	vmsr	fpscr, r0
+	vcvtr.s32.f64	s0, d0
+	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	fldt	4(%esp)
+	subl	$8,%esp
+
+	fstcw	4(%esp)			/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x400,%edx		/* round towards -oo */
+	orl	4(%esp),%edx
+	andl	$0xf7ff,%edx
+	movl	%edx,(%esp)
+	fldcw	(%esp)			/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	4(%esp)			/* restore original control word */
+
+	addl	$8,%esp
+	ret
+#endif
diff --git a/winsup/cygwin/math/fmal.c b/winsup/cygwin/math/fmal.c
new file mode 100644
index 000000000..3d0eb020b
--- /dev/null
+++ b/winsup/cygwin/math/fmal.c
@@ -0,0 +1,12 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double fmal ( long double _x,  long double _y,  long double _z);
+
+long double
+fmal ( long double _x,  long double _y,  long double _z)
+{
+  return ((_x * _y) + _z);
+}
diff --git a/winsup/cygwin/math/fmaxl.c b/winsup/cygwin/math/fmaxl.c
new file mode 100644
index 000000000..4ac6e2194
--- /dev/null
+++ b/winsup/cygwin/math/fmaxl.c
@@ -0,0 +1,13 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long double
+fmaxl (long double _x, long double  _y)
+{
+  return (__builtin_isgreaterequal (_x, _y) || __builtin_isnan (_y))
+	 ?  _x : _y;
+}
diff --git a/winsup/cygwin/math/fminl.c b/winsup/cygwin/math/fminl.c
new file mode 100644
index 000000000..0396a8eba
--- /dev/null
+++ b/winsup/cygwin/math/fminl.c
@@ -0,0 +1,12 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long double
+fminl (long double _x, long double _y)
+{
+  return ((__builtin_islessequal(_x, _y) || __builtin_isnan (_y)) ? _x : _y );
+}
diff --git a/winsup/cygwin/math/fmodl.c b/winsup/cygwin/math/fmodl.c
new file mode 100644
index 000000000..6224db13b
--- /dev/null
+++ b/winsup/cygwin/math/fmodl.c
@@ -0,0 +1,20 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+long double fmodl (long double x, long double y);
+
+long double
+fmodl (long double x, long double y)
+{
+  long double res = 0.0L;
+
+  asm ("1:\tfprem\n\t"
+       "fstsw   %%ax\n\t"
+       "sahf\n\t"
+       "jp      1b\n\t"
+       "fstp    %%st(1)"
+       : "=t" (res) : "0" (x), "u" (y) : "ax", "st(1)");
+  return res;
+}
diff --git a/winsup/cygwin/math/frexpl.S b/winsup/cygwin/math/frexpl.S
new file mode 100644
index 000000000..f9fcc6be1
--- /dev/null
+++ b/winsup/cygwin/math/frexpl.S
@@ -0,0 +1,130 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+/*
+ * frexpl(long double x, int* expnt) extracts the exponent from x.
+ * It returns an integer power of two to expnt and the significand
+ * between 0.5 and 1 to y.  Thus  x = y * 2**expn.
+ */ 
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 2
+#endif
+.globl __MINGW_USYMBOL(frexpl)
+__MINGW_USYMBOL(frexpl):
+#ifdef __x86_64__
+	pushq %rbp
+	movq %rsp,%rbp
+	subq $48,%rsp
+	pushq %rsi
+	fldt (%rdx)
+	movq %rcx,%r9
+	fld %st(0)
+	fstpt -12(%rbp)
+	leaq -4(%rbp),%rcx
+	movw -4(%rbp),%dx
+	andl $32767,%edx
+	jne L25
+	fldz
+	fucompp
+	fnstsw %ax
+	andb $68,%ah
+	xorb $64,%ah
+	jne L21
+	movl $0,(%r8)
+	fldz
+	jmp L24
+	.align 4,0x90
+	.align 4,0x90
+L21:
+	fldt -12(%rbp)
+	fadd %st(0),%st
+	fstpt -12(%rbp)
+	decl %edx
+	movw (%rcx),%si
+	andl $32767,%esi
+	jne L22
+	cmpl $-66,%edx
+	jg L21
+L22:
+	add %esi,%edx
+	jmp L19
+	.align 2,0x90
+L25:
+	fstp %st(0)
+L19:
+	addl $-16382,%edx
+	movl %edx,(%r8)
+	movw (%rcx),%ax
+	andl $-32768,%eax
+	orl $16382,%eax
+	movw %ax,(%rcx)
+	fldt -12(%rbp)
+L24:
+	popq %rsi
+	movq	%r9,%rax
+	movq	$0,8(%r9)
+	fstpt	(%r9)
+	leave
+	ret
+#else
+	pushl %ebp
+	movl %esp,%ebp
+	subl $24,%esp
+	pushl %esi
+	pushl %ebx
+	fldt 8(%ebp)
+	movl 20(%ebp),%ebx
+	fld %st(0)
+	fstpt -12(%ebp)
+	leal -4(%ebp),%ecx
+	movw -4(%ebp),%dx
+	andl $32767,%edx
+	jne L25
+	fldz
+	fucompp
+	fnstsw %ax
+	andb $68,%ah
+	xorb $64,%ah
+	jne L21
+	movl $0,(%ebx)
+	fldz
+	jmp L24
+	.align 2,0x90
+	.align 2,0x90
+L21:
+	fldt -12(%ebp)
+	fadd %st(0),%st
+	fstpt -12(%ebp)
+	decl %edx
+	movw (%ecx),%si
+	andl $32767,%esi
+	jne L22
+	cmpl $-66,%edx
+	jg L21
+L22:
+	addl %esi,%edx
+	jmp L19
+	.align 2,0x90
+L25:
+	fstp %st(0)
+L19:
+	addl $-16382,%edx
+	movl %edx,(%ebx)
+	movw (%ecx),%ax
+	andl $-32768,%eax
+	orl $16382,%eax
+	movw %ax,(%ecx)
+	fldt -12(%ebp)
+L24:
+	leal -32(%ebp),%esp
+	popl %ebx
+	popl %esi
+	leave
+	ret
+#endif
diff --git a/winsup/cygwin/math/ilogbl.S b/winsup/cygwin/math/ilogbl.S
new file mode 100644
index 000000000..f68082ce6
--- /dev/null
+++ b/winsup/cygwin/math/ilogbl.S
@@ -0,0 +1,65 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"ilogbl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(ilogbl)
+	.def	__MINGW_USYMBOL(ilogbl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(ilogbl):
+#ifdef __x86_64__
+	fldt	(%rcx)
+	fxam			/* Is NaN or +-Inf?  */
+	fstsw   %ax
+	movb    $0x45, %dh
+	andb    %ah, %dh
+	cmpb    $0x05, %dh
+	je      1f		/* Is +-Inf, jump.  */
+
+	fxtract
+	pushq	%rax
+	fstp	%st
+
+	fistpl	(%rsp)
+	fwait
+	popq	%rax
+
+	ret
+
+1:	fstp	%st
+	movl	$0x7fffffff, %eax
+	ret
+#else
+	fldt	4(%esp)
+/* I added the following ugly construct because ilogb(+-Inf) is
+   required to return INT_MAX in ISO C99.
+   -- jakub@redhat.com.  */
+	fxam			/* Is NaN or +-Inf?  */
+	fstsw   %ax
+	movb    $0x45, %dh
+	andb    %ah, %dh
+	cmpb    $0x05, %dh
+	je      1f		/* Is +-Inf, jump.  */
+
+	fxtract
+	pushl	%eax
+	fstp	%st
+
+	fistpl	(%esp)
+	fwait
+	popl	%eax
+
+	ret
+
+1:	fstp	%st
+	movl	$0x7fffffff, %eax
+	ret
+#endif
diff --git a/winsup/cygwin/math/internal_logl.S b/winsup/cygwin/math/internal_logl.S
new file mode 100644
index 000000000..f8a075774
--- /dev/null
+++ b/winsup/cygwin/math/internal_logl.S
@@ -0,0 +1,66 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"internal_logl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+one:	.double 1.0
+	/* It is not important that this constant is precise.  It is only
+	   a value which is known to be on the safe side for using the
+	   fyl2xp1 instruction.  */
+limit:	.double 0.29
+
+.globl __MINGW_USYMBOL(__logl_internal)
+	.def	__MINGW_USYMBOL(__logl_internal);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(__logl_internal):
+#ifdef __x86_64__
+	fldln2			// log(2)
+	fldt	(%rdx)		// x : log(2)
+	fld	%st		// x : x : log(2)
+	fsubl	one(%rip)	// x-1 : x : log(2)
+	fld	%st		// x-1 : x-1 : x : log(2)
+	fabs			// |x-1| : x-1 : x : log(2)
+	fcompl	limit(%rip)	// x-1 : x : log(2)
+	fnstsw			// x-1 : x : log(2)
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : log(2)
+	fyl2xp1			// log(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+2:	fstp	%st(0)		// x : log(2)
+	fyl2x			// log(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldln2			// log(2)
+	fldt	4(%esp)		// x : log(2)
+	fld	%st		// x : x : log(2)
+	fsubl	one		// x-1 : x : log(2)
+	fld	%st		// x-1 : x-1 : x : log(2)
+	fabs			// |x-1| : x-1 : x : log(2)
+	fcompl	limit		// x-1 : x : log(2)
+	fnstsw			// x-1 : x : log(2)
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : log(2)
+	fyl2xp1			// log(x)
+	ret
+
+2:	fstp	%st(0)		// x : log(2)
+	fyl2x			// log(x)
+	ret
+#endif
diff --git a/winsup/cygwin/math/isinf.c b/winsup/cygwin/math/isinf.c
new file mode 100644
index 000000000..e7d3e2626
--- /dev/null
+++ b/winsup/cygwin/math/isinf.c
@@ -0,0 +1,18 @@
+int
+isinf (double x)
+{
+  return __builtin_isinf (x);
+}
+
+int
+isinff (float x)
+{
+  return __builtin_isinf (x);
+}
+
+int
+isinfl (long double x)
+{
+  return __builtin_isinf (x);
+}
+
diff --git a/winsup/cygwin/math/isnan.c b/winsup/cygwin/math/isnan.c
new file mode 100644
index 000000000..ac68bef6d
--- /dev/null
+++ b/winsup/cygwin/math/isnan.c
@@ -0,0 +1,18 @@
+int
+isnan (double x)
+{
+  return __builtin_isnan (x);
+}
+
+int
+isnanf (float x)
+{
+  return __builtin_isnan (x);
+}
+
+int
+isnanl (long double x)
+{
+  return __builtin_isnan (x);
+}
+
diff --git a/winsup/cygwin/math/ldexpl.c b/winsup/cygwin/math/ldexpl.c
new file mode 100644
index 000000000..fde31a23c
--- /dev/null
+++ b/winsup/cygwin/math/ldexpl.c
@@ -0,0 +1,23 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+#include <errno.h>
+
+long double ldexpl(long double x, int expn)
+{
+  long double res = 0.0L;
+  if (!isfinite (x) || x == 0.0L)
+    return x;
+
+  __asm__ __volatile__ ("fscale"
+  	    : "=t" (res)
+	    : "0" (x), "u" ((long double) expn));
+
+  if (!isfinite (res) || res == 0.0L)
+    errno = ERANGE;
+
+  return res;
+}
diff --git a/winsup/cygwin/math/lgammal.c b/winsup/cygwin/math/lgammal.c
new file mode 100644
index 000000000..03c030e00
--- /dev/null
+++ b/winsup/cygwin/math/lgammal.c
@@ -0,0 +1,342 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_mconf.h"
+
+#if UNK
+static uLD S[9] = {
+  { { -1.193945051381510095614E-3L } },
+  { {  7.220599478036909672331E-3L } },
+  { { -9.622023360406271645744E-3L } },
+  { { -4.219773360705915470089E-2L } },
+  { {  1.665386113720805206758E-1L } },
+  { { -4.200263503403344054473E-2L } },
+  { { -6.558780715202540684668E-1L } },
+  { {  5.772156649015328608253E-1L } },
+  { {  1.000000000000000000000E0L } }
+};
+#endif
+#if IBMPC
+static const uLD S[] = {
+  { { 0xbaeb,0xd6d3,0x25e5,0x9c7e,0xbff5, 0, 0, 0 } },
+  { { 0xfe9a,0xceb4,0xc74e,0xec9a,0x3ff7, 0, 0, 0 } },
+  { { 0x9225,0xdfef,0xb0e9,0x9da5,0xbff8, 0, 0, 0 } },
+  { { 0x10b0,0xec17,0x87dc,0xacd7,0xbffa, 0, 0, 0 } },
+  { { 0x6b8d,0x7515,0x1905,0xaa89,0x3ffc, 0, 0, 0 } },
+  { { 0xf183,0x126b,0xf47d,0xac0a,0xbffa, 0, 0, 0 } },
+  { { 0x7bf6,0x57d1,0xa013,0xa7e7,0xbffe, 0, 0, 0 } },
+  { { 0xc7a9,0x7db0,0x67e3,0x93c4,0x3ffe, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0x3fff, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static uLD S[27] = {
+  { { 0xbff50000,0x9c7e25e5,0xd6d3baeb, 0 } },
+  { { 0x3ff70000,0xec9ac74e,0xceb4fe9a, 0 } },
+  { { 0xbff80000,0x9da5b0e9,0xdfef9225, 0 } },
+  { { 0xbffa0000,0xacd787dc,0xec1710b0, 0 } },
+  { { 0x3ffc0000,0xaa891905,0x75156b8d, 0 } },
+  { { 0xbffa0000,0xac0af47d,0x126bf183, 0 } },
+  { { 0xbffe0000,0xa7e7a013,0x57d17bf6, 0 } },
+  { { 0x3ffe0000,0x93c467e3,0x7db0c7a9, 0 } },
+  { { 0x3fff0000,0x80000000,0x00000000, 0 } }
+};
+#endif
+
+#if UNK
+static uLD SN[9] = {
+  { {  1.133374167243894382010E-3L } },
+  { {  7.220837261893170325704E-3L } },
+  { {  9.621911155035976733706E-3L } },
+  { { -4.219773343731191721664E-2L } },
+  { { -1.665386113944413519335E-1L } },
+  { { -4.200263503402112910504E-2L } },
+  { {  6.558780715202536547116E-1L } },
+  { {  5.772156649015328608727E-1L } },
+  { { -1.000000000000000000000E0L } }
+};
+#endif
+#if IBMPC
+static const uLD SN[] = {
+  { { 0x5dd1,0x02de,0xb9f7,0x948d,0x3ff5, 0, 0, 0 } },
+  { { 0x989b,0xdd68,0xc5f1,0xec9c,0x3ff7, 0, 0, 0 } },
+  { { 0x2ca1,0x18f0,0x386f,0x9da5,0x3ff8, 0, 0, 0 } },
+  { { 0x783f,0x41dd,0x87d1,0xacd7,0xbffa, 0, 0, 0 } },
+  { { 0x7a5b,0xd76d,0x1905,0xaa89,0xbffc, 0, 0, 0 } },
+  { { 0x7f64,0x1234,0xf47d,0xac0a,0xbffa, 0, 0, 0 } },
+  { { 0x5e26,0x57d1,0xa013,0xa7e7,0x3ffe, 0, 0, 0 } },
+  { { 0xc7aa,0x7db0,0x67e3,0x93c4,0x3ffe, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0xbfff, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static uLD SN[] = {
+  { { 0x3ff50000,0x948db9f7,0x02de5dd1, 0 } },
+  { { 0x3ff70000,0xec9cc5f1,0xdd68989b, 0 } },
+  { { 0x3ff80000,0x9da5386f,0x18f02ca1, 0 } },
+  { { 0xbffa0000,0xacd787d1,0x41dd783f, 0 } },
+  { { 0xbffc0000,0xaa891905,0xd76d7a5b, 0 } },
+  { { 0xbffa0000,0xac0af47d,0x12347f64, 0 } },
+  { { 0x3ffe0000,0xa7e7a013,0x57d15e26, 0 } },
+  { { 0x3ffe0000,0x93c467e3,0x7db0c7aa, 0 } },
+  { { 0xbfff0000,0x80000000,0x00000000, 0 } }
+};
+#endif
+
+
+/* A[]: Stirling's formula expansion of log gamma
+ * B[], C[]: log gamma function between 2 and 3
+ */
+
+
+/* log gamma(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x A(1/x^2)
+ * x >= 8
+ * Peak relative error 1.51e-21
+ * Relative spread of error peaks 5.67e-21
+ */
+#if UNK
+static uLD A[7] = {
+  { {  4.885026142432270781165E-3L } },
+  { { -1.880801938119376907179E-3L } },
+  { {  8.412723297322498080632E-4L } },
+  { { -5.952345851765688514613E-4L } },
+  { {  7.936507795855070755671E-4L } },
+  { { -2.777777777750349603440E-3L } },
+  { {  8.333333333333331447505E-2L } }
+};
+#endif
+#if IBMPC
+static const uLD A[] = {
+  { { 0xd984,0xcc08,0x91c2,0xa012,0x3ff7, 0, 0, 0 } },
+  { { 0x3d91,0x0304,0x3da1,0xf685,0xbff5, 0, 0, 0 } },
+  { { 0x3bdc,0xaad1,0xd492,0xdc88,0x3ff4, 0, 0, 0 } },
+  { { 0x8b20,0x9fce,0x844e,0x9c09,0xbff4, 0, 0, 0 } },
+  { { 0xf8f2,0x30e5,0x0092,0xd00d,0x3ff4, 0, 0, 0 } },
+  { { 0x4d88,0x03a8,0x60b6,0xb60b,0xbff6, 0, 0, 0 } },
+  { { 0x9fcc,0xaaaa,0xaaaa,0xaaaa,0x3ffb, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static uLD A[] = {
+  { { 0x3ff70000,0xa01291c2,0xcc08d984, 0 } },
+  { { 0xbff50000,0xf6853da1,0x03043d91, 0 } },
+  { { 0x3ff40000,0xdc88d492,0xaad13bdc, 0 } },
+  { { 0xbff40000,0x9c09844e,0x9fce8b20, 0 } },
+  { { 0x3ff40000,0xd00d0092,0x30e5f8f2, 0 } },
+  { { 0xbff60000,0xb60b60b6,0x03a84d88, 0 } },
+  { { 0x3ffb0000,0xaaaaaaaa,0xaaaa9fcc, 0 } }
+};
+#endif
+
+/* log gamma(x+2) = x B(x)/C(x)
+ * 0 <= x <= 1
+ * Peak relative error 7.16e-22
+ * Relative spread of error peaks 4.78e-20
+ */
+#if UNK
+static uLD B[7] = {
+  { { -2.163690827643812857640E3L } },
+  { { -8.723871522843511459790E4L } },
+  { { -1.104326814691464261197E6L } },
+  { { -6.111225012005214299996E6L } },
+  { { -1.625568062543700591014E7L } },
+  { { -2.003937418103815175475E7L } },
+  { { -8.875666783650703802159E6L } }
+};
+static uLD C[7] = {
+  { { -5.139481484435370143617E2L } },
+  { { -3.403570840534304670537E4L } },
+  { { -6.227441164066219501697E5L } },
+  { { -4.814940379411882186630E6L } },
+  { { -1.785433287045078156959E7L } },
+  { { -3.138646407656182662088E7L } },
+  { { -2.099336717757895876142E7L } }
+};
+#endif
+#if IBMPC
+static const uLD B[] = {
+  { { 0x9557,0x4995,0x0da1,0x873b,0xc00a, 0, 0, 0 } },
+  { { 0xfe44,0x9af8,0x5b8c,0xaa63,0xc00f, 0, 0, 0 } },
+  { { 0x5aa8,0x7cf5,0x3684,0x86ce,0xc013, 0, 0, 0 } },
+  { { 0x259a,0x258c,0xf206,0xba7f,0xc015, 0, 0, 0 } },
+  { { 0xbe18,0x1ca3,0xc0a0,0xf80a,0xc016, 0, 0, 0 } },
+  { { 0x168f,0x2c42,0x6717,0x98e3,0xc017, 0, 0, 0 } },
+  { { 0x2051,0x9d55,0x92c8,0x876e,0xc016, 0, 0, 0 } }
+};
+static const uLD C[] = {
+  { { 0xaa77,0xcf2f,0xae76,0x807c,0xc008, 0, 0, 0 } },
+  { { 0xb280,0x0d74,0xb55a,0x84f3,0xc00e, 0, 0, 0 } },
+  { { 0xa505,0xcd30,0x81dc,0x9809,0xc012, 0, 0, 0 } },
+  { { 0x3369,0x4246,0xb8c2,0x92f0,0xc015, 0, 0, 0 } },
+  { { 0x63cf,0x6aee,0xbe6f,0x8837,0xc017, 0, 0, 0 } },
+  { { 0x26bb,0xccc7,0xb009,0xef75,0xc017, 0, 0, 0 } },
+  { { 0x462b,0xbae8,0xab96,0xa02a,0xc017, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static uLD B[] = {
+  { { 0xc00a0000,0x873b0da1,0x49959557, 0 } },
+  { { 0xc00f0000,0xaa635b8c,0x9af8fe44, 0 } },
+  { { 0xc0130000,0x86ce3684,0x7cf55aa8, 0 } },
+  { { 0xc0150000,0xba7ff206,0x258c259a, 0 } },
+  { { 0xc0160000,0xf80ac0a0,0x1ca3be18, 0 } },
+  { { 0xc0170000,0x98e36717,0x2c42168f, 0 } },
+  { { 0xc0160000,0x876e92c8,0x9d552051, 0 } }
+};
+static uLD C[] = {
+  { { 0xc0080000,0x807cae76,0xcf2faa77, 0 } },
+  { { 0xc00e0000,0x84f3b55a,0x0d74b280, 0 } },
+  { { 0xc0120000,0x980981dc,0xcd30a505, 0 } },
+  { { 0xc0150000,0x92f0b8c2,0x42463369, 0 } },
+  { { 0xc0170000,0x8837be6f,0x6aee63cf, 0 } },
+  { { 0xc0170000,0xef75b009,0xccc726bb, 0 } },
+  { { 0xc0170000,0xa02aab96,0xbae8462b, 0 } }
+};
+#endif
+
+/* log( sqrt( 2*pi ) ) */
+static const long double LS2PI  =  0.91893853320467274178L;
+#if defined(__arm__) || defined(_ARM_)
+#define MAXLGM 2.035093e36
+#else
+#define MAXLGM 1.04848146839019521116e+4928L
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+/* Logarithm of gamma function */
+/* Reentrant version */ 
+long double __lgammal_r(long double x, int* sgngaml);
+
+long double __lgammal_r(long double x, int* sgngaml)
+{
+	long double p, q, w, z, f, nx;
+	int i;
+
+	*sgngaml = 1;
+#ifdef NANS
+	if (isnanl(x))
+		return(NANL);
+#endif
+#ifdef INFINITIES
+	if (!isfinitel(x))
+		return (INFINITYL);
+#endif
+	if (x < -34.0L)
+	{
+		q = -x;
+		w = __lgammal_r(q, sgngaml); /* note this modifies sgngam! */
+		p = floorl(q);
+		if (p == q)
+		{
+lgsing:
+			_SET_ERRNO(EDOM);
+			mtherr( "lgammal", SING );
+#ifdef INFINITIES
+			return (INFINITYL);
+#else
+			return (MAXNUML);
+#endif
+		}
+		i = p;
+		if ((i & 1) == 0)
+			*sgngaml = -1;
+		else
+			*sgngaml = 1;
+		z = q - p;
+		if (z > 0.5L)
+		{
+			p += 1.0L;
+			z = p - q;
+		}
+		z = q * sinl(PIL * z);
+		if (z == 0.0L)
+			goto lgsing;
+	/*	z = LOGPI - logl( z ) - w; */
+		z = logl(PIL/z) - w;
+		return (z);
+	}
+
+	if (x < 13.0L)
+	{
+		z = 1.0L;
+		nx = floorl(x +  0.5L);
+		f = x - nx;
+		while (x >= 3.0L)
+		{
+			nx -= 1.0L;
+			x = nx + f;
+			z *= x;
+		}
+		while (x < 2.0L)
+		{
+			if (fabsl(x) <= 0.03125)
+				goto lsmall;
+			z /= nx +  f;
+			nx += 1.0L;
+			x = nx + f;
+		}
+		if (z < 0.0L)
+		{
+			*sgngaml = -1;
+			z = -z;
+		}
+		else
+			*sgngaml = 1;
+		if (x == 2.0L)
+			return ( logl(z) );
+		x = (nx - 2.0L) + f;
+		p = x * polevll(x, B, 6) / p1evll(x, C, 7);
+		return ( logl(z) + p );
+	}
+
+	if (x > MAXLGM)
+	{
+		_SET_ERRNO(ERANGE);
+		mtherr("lgammal", OVERFLOW);
+#ifdef INFINITIES
+		return (*sgngaml * INFINITYL);
+#else
+		return (*sgngaml * MAXNUML);
+#endif
+	}
+
+	q = (x - 0.5L) * logl(x) - x + LS2PI;
+	if (x > 1.0e10L)
+		return(q);
+	p = 1.0L/(x*x);
+	q += polevll(p, A, 6) / x;
+	return (q);
+
+lsmall:
+	if (x == 0.0L)
+		goto lgsing;
+	if (x < 0.0L)
+	{
+		x = -x;
+		q = z / (x * polevll(x, SN, 8));
+	}
+	else
+		q = z / (x * polevll(x, S, 8));
+	if (q < 0.0L)
+	{
+		*sgngaml = -1;
+		q = -q;
+	}
+	else
+		*sgngaml = 1;
+	q = logl(q);
+	return (q);
+}
+
+/* This is the C99 version */
+long double lgammal(long double x)
+{
+	return (__lgammal_r (x, &signgam));
+}
+
+long double lgammal_r(long double x, int *signp)
+{
+	return (__lgammal_r (x, signp));
+}
+
diff --git a/winsup/cygwin/math/llrint.c b/winsup/cygwin/math/llrint.c
new file mode 100644
index 000000000..1fc11e886
--- /dev/null
+++ b/winsup/cygwin/math/llrint.c
@@ -0,0 +1,18 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long long llrint (double x) 
+{
+  long long retval = 0ll;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
+#else
+  retval = (long long)x;
+#endif
+  return retval;
+}
+
diff --git a/winsup/cygwin/math/llrintf.c b/winsup/cygwin/math/llrintf.c
new file mode 100644
index 000000000..aabd81f33
--- /dev/null
+++ b/winsup/cygwin/math/llrintf.c
@@ -0,0 +1,17 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long long llrintf (float x) 
+{
+  long long retval = 0ll;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
+#else
+  retval = (long long)x;
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/llrintl.c b/winsup/cygwin/math/llrintl.c
new file mode 100644
index 000000000..59ace2dfe
--- /dev/null
+++ b/winsup/cygwin/math/llrintl.c
@@ -0,0 +1,18 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long long llrintl (long double x) 
+{
+  long long retval = 0ll;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpll %0"  : "=m" (retval) : "t" (x) : "st");
+#else
+  retval = (long long)x;
+#endif
+  return retval;
+}
+
diff --git a/winsup/cygwin/math/llroundl.c b/winsup/cygwin/math/llroundl.c
new file mode 100644
index 000000000..fc600e77d
--- /dev/null
+++ b/winsup/cygwin/math/llroundl.c
@@ -0,0 +1,38 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+#include <limits.h>
+#include <errno.h>
+
+long long
+llroundl (long double x)
+{
+  long double res;
+
+  if (x >= 0.0L)
+    {
+      res = ceill (x);
+      if (res - x > 0.5L)
+        res -= 1.0L;
+    }
+  else
+    {
+      res = ceill (-x);
+      if (res + x > 0.5L)
+        res -= 1.0L;
+      res = -res;
+    }
+  if (!isfinite (res)
+      || res > (double) LLONG_MAX
+      || res < (double) LLONG_MIN)
+    {
+      errno = ERANGE;
+      /* Undefined behaviour, so we could return anything.  */
+      /* return res > 0.0 ? LLONG_MAX : LLONG_MIN;  */
+    }
+  return (long long) res;
+}
+
diff --git a/winsup/cygwin/math/log.def.h b/winsup/cygwin/math/log.def.h
new file mode 100644
index 000000000..94a77007f
--- /dev/null
+++ b/winsup/cygwin/math/log.def.h
@@ -0,0 +1,69 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+extern long double __cdecl __logl_internal (long double);
+
+__FLT_TYPE __cdecl
+__FLT_ABI(log) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_ZERO)
+    {
+      __FLT_RPT_ERANGE ("log", x, 0.0, -__FLT_HUGE_VAL, 1);
+      return -__FLT_HUGE_VAL;
+    }
+  else if (signbit (x))
+    {
+      __FLT_RPT_DOMAIN ("log", x, 0.0, __FLT_NAN);
+      return __FLT_NAN;
+    }
+  else if (x_class == FP_INFINITE)
+    return __FLT_HUGE_VAL;
+  else if (x_class == FP_NAN)
+    return __FLT_NAN;
+  return (__FLT_TYPE) __logl_internal ((long double) x);
+}
diff --git a/winsup/cygwin/math/log10l.S b/winsup/cygwin/math/log10l.S
new file mode 100644
index 000000000..33d45a3a8
--- /dev/null
+++ b/winsup/cygwin/math/log10l.S
@@ -0,0 +1,93 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"log10l.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+one:	.double 1.0
+	/* It is not important that this constant is precise.  It is only
+	   a value which is known to be on the safe side for using the
+	   fyl2xp1 instruction.  */
+limit:	.double 0.29
+
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(log10l)
+	.def	__MINGW_USYMBOL(log10l);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(log10l):
+#ifdef __x86_64__
+	fldlg2			// log10(2)
+	fldt	(%rdx)		// x : log10(2)
+	fxam
+	fnstsw
+	fld	%st		// x : x : log10(2)
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:	fsubl	one(%rip)	// x-1 : x : log10(2)
+	fld	%st		// x-1 : x-1 : x : log10(2)
+	fabs			// |x-1| : x-1 : x : log10(2)
+	fcompl	limit(%rip)	// x-1 : x : log10(2)
+	fnstsw			// x-1 : x : log10(2)
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : log10(2)
+	fyl2xp1			// log10(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+2:	fstp	%st(0)		// x : log10(2)
+	fyl2x			// log10(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldlg2			// log10(2)
+	fldt	4(%esp)		// x : log10(2)
+	fxam
+	fnstsw
+	fld	%st		// x : x : log10(2)
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:	fsubl	one		// x-1 : x : log10(2)
+	fld	%st		// x-1 : x-1 : x : log10(2)
+	fabs			// |x-1| : x-1 : x : log10(2)
+	fcompl	limit		// x-1 : x : log10(2)
+	fnstsw			// x-1 : x : log10(2)
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : log10(2)
+	fyl2xp1			// log10(x)
+	ret
+
+2:	fstp	%st(0)		// x : log10(2)
+	fyl2x			// log10(x)
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/log1pl.S b/winsup/cygwin/math/log1pl.S
new file mode 100644
index 000000000..a56bcf4ec
--- /dev/null
+++ b/winsup/cygwin/math/log1pl.S
@@ -0,0 +1,102 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"log1pl.S"
+	.text
+	/* The fyl2xp1 can only be used for values in
+	   -1 + sqrt(2) / 2 <= x <= 1 - sqrt(2) / 2
+	   0.29 is a safe value.
+	 */
+
+	/* Only gcc understands the .tfloat type
+	   The series of .long below represents
+	   limit:	.tfloat 0.29
+	 */
+	.align 16
+limit:
+	.long 2920577761
+	.long 2491081031
+	.long 16381
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	/* Please note:	 we use a double value here.  Since 1.0 has
+	   an exact representation this does not effect the accuracy
+	   but it helps to optimize the code.  */
+one:	.double 1.0
+
+/*
+ * Use the fyl2xp1 function when the argument is in the range -0.29 to 0.29,
+ * otherwise fyl2x with the needed extra computation.
+ */
+.globl __MINGW_USYMBOL(log1pl)
+	.def	__MINGW_USYMBOL(log1pl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(log1pl):
+#ifdef __x86_64__
+	fldln2
+	fldt	(%rdx)
+	fxam
+	fnstsw
+	fld	%st
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:
+	fabs
+	fldt	limit(%rip)
+	fcompp
+	fnstsw
+	sahf
+	jnc	2f
+	faddl	one(%rip)
+	fyl2x
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+2:	fyl2xp1
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldln2
+	fldt	4(%esp)
+	fxam
+	fnstsw
+	fld	%st
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:
+	fabs
+	fldt	limit
+	fcompp
+	fnstsw
+	sahf
+	jnc	2f
+	faddl	one
+	fyl2x
+	ret
+
+2:	fyl2xp1
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/log2l.S b/winsup/cygwin/math/log2l.S
new file mode 100644
index 000000000..771cd8ae4
--- /dev/null
+++ b/winsup/cygwin/math/log2l.S
@@ -0,0 +1,87 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"log2l.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+one:	.double 1.0
+	/* It is not important that this constant is precise.  It is only
+	   a value which is known to be on the safe side for using the
+	   fyl2xp1 instruction.  */
+limit:	.double 0.29
+
+.globl __MINGW_USYMBOL(log2l)
+	.def	__MINGW_USYMBOL(log2l);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(log2l):
+#ifdef __x86_64__
+	fldl	one(%rip)
+	fldt	(%rdx)		// x : 1
+	fxam
+	fnstsw
+	fld	%st		// x : x : 1
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:	fsub	%st(2), %st	// x-1 : x : 1
+	fld	%st		// x-1 : x-1 : x : 1
+	fabs			// |x-1| : x-1 : x : 1
+	fcompl	limit(%rip)	// x-1 : x : 1
+	fnstsw			// x-1 : x : 1
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : 1
+	fyl2xp1			// log(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+2:	fstp	%st(0)		// x : 1
+	fyl2x			// log(x)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldl	one
+	fldt	4(%esp)		// x : 1
+	fxam
+	fnstsw
+	fld	%st		// x : x : 1
+	sahf
+	jc	3f		// in case x is NaN or �Inf
+4:	fsub	%st(2), %st	// x-1 : x : 1
+	fld	%st		// x-1 : x-1 : x : 1
+	fabs			// |x-1| : x-1 : x : 1
+	fcompl	limit		// x-1 : x : 1
+	fnstsw			// x-1 : x : 1
+	andb	$0x45, %ah
+	jz	2f
+	fstp	%st(1)		// x-1 : 1
+	fyl2xp1			// log(x)
+	ret
+
+2:	fstp	%st(0)		// x : 1
+	fyl2x			// log(x)
+	ret
+
+3:	jp	4b		// in case x is �Inf
+	fstp	%st(1)
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/logbl.c b/winsup/cygwin/math/logbl.c
new file mode 100644
index 000000000..310c4457b
--- /dev/null
+++ b/winsup/cygwin/math/logbl.c
@@ -0,0 +1,22 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Changes for long double by Ulrich Drepper <drepper@cygnus.com>
+ * Public domain.
+ */
+
+#include <math.h>
+
+long double
+logbl (long double x)
+{
+  long double res = 0.0L;
+
+  asm ("fxtract\n\t"
+       "fstp	%%st" : "=t" (res) : "0" (x));
+  return res;
+}
diff --git a/winsup/cygwin/math/logl.c b/winsup/cygwin/math/logl.c
new file mode 100644
index 000000000..a0fa386dc
--- /dev/null
+++ b/winsup/cygwin/math/logl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "log.def.h"
diff --git a/winsup/cygwin/math/lrint.c b/winsup/cygwin/math/lrint.c
new file mode 100644
index 000000000..0409da660
--- /dev/null
+++ b/winsup/cygwin/math/lrint.c
@@ -0,0 +1,30 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+long __lrint_internal( double x );
+asm(".def __lrint_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __lrint_internal\n"
+    "__lrint_internal:\n"
+    "\tvcvtr.s32.f64    s0, d0\n"
+    "\tfmrs             r0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+long lrint (double x) 
+{
+  long retval = 0L;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __lrint_internal(x);
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/lrintf.c b/winsup/cygwin/math/lrintf.c
new file mode 100644
index 000000000..2b6d89318
--- /dev/null
+++ b/winsup/cygwin/math/lrintf.c
@@ -0,0 +1,30 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+long __lrintf_internal( float x );
+asm(".def __lrintf_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __lrintf_internal\n"
+    "__lrintf_internal:\n"
+    "\tvcvtr.s32.f32    s0, s0\n"
+    "\tfmrs             r0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+long lrintf (float x) 
+{
+  long retval = 0l;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __lrintf_internal(x);
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/lrintl.c b/winsup/cygwin/math/lrintl.c
new file mode 100644
index 000000000..94c4e4924
--- /dev/null
+++ b/winsup/cygwin/math/lrintl.c
@@ -0,0 +1,18 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long lrintl (long double x) 
+{
+  long retval = 0l;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
+#elif defined(__arm__) || defined(_ARM_)
+    retval = lrint(x);
+#endif
+  return retval;
+}
+
diff --git a/winsup/cygwin/math/lroundl.c b/winsup/cygwin/math/lroundl.c
new file mode 100644
index 000000000..b4584a896
--- /dev/null
+++ b/winsup/cygwin/math/lroundl.c
@@ -0,0 +1,37 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+#include <limits.h>
+#include <errno.h>
+
+long
+lroundl (long double x)
+{
+  long double res;
+
+  if (x >= 0.0L)
+    {
+      res = ceill (x);
+      if (res - x > 0.5L)
+	res -= 1.0;
+    }
+  else
+    {
+      res = ceill (-x);
+      if (res + x > 0.5L)
+	res -= 1.0L;
+      res = -res;
+    }
+  if (!isfinite (res)
+      || res > (long double)LONG_MAX
+      || res < (long double)LONG_MIN)
+    {
+      errno = ERANGE;
+      /* Undefined behaviour, so we could return anything.  */
+      /* return res > 0.0L ? LONG_MAX : LONG_MIN;  */
+    }
+  return (long) res;
+}
diff --git a/winsup/cygwin/math/modfl.c b/winsup/cygwin/math/modfl.c
new file mode 100644
index 000000000..af75a8b8c
--- /dev/null
+++ b/winsup/cygwin/math/modfl.c
@@ -0,0 +1,41 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <fenv.h>
+#include <math.h>
+#include <errno.h>
+
+long double
+modfl (long double value, long double* iptr)
+{
+  long double int_part = 0.0L;
+  /* truncate */
+#if defined(_AMD64_) || defined(__x86_64__)
+  asm ("subq $8, %%rsp\n"
+    "fnstcw 4(%%rsp)\n"
+    "movzwl 4(%%rsp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%rsp)\n"
+    "fldcw (%%rsp)\n"
+    "frndint\n"
+    "fldcw 4(%%rsp)\n"
+    "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value)); /* round */
+#elif defined(_X86_) || defined(__i386__)
+  asm ("push %%eax\n\tsubl $8, %%esp\n"
+    "fnstcw 4(%%esp)\n"
+    "movzwl 4(%%esp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%esp)\n"
+    "fldcw (%%esp)\n"
+    "frndint\n"
+    "fldcw 4(%%esp)\n"
+    "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value)); /* round */
+#else
+  int_part = truncl(value);
+#endif
+  if (iptr)
+    *iptr = int_part;
+  return (isinf (value) ?  0.0L : value - int_part);
+}
diff --git a/winsup/cygwin/math/nearbyint.S b/winsup/cygwin/math/nearbyint.S
new file mode 100644
index 000000000..8aec9bdb0
--- /dev/null
+++ b/winsup/cygwin/math/nearbyint.S
@@ -0,0 +1,57 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"nearbyint.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	.globl __MINGW_USYMBOL(nearbyint)
+	.def	__MINGW_USYMBOL(nearbyint);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(nearbyint):
+#if defined(_AMD64_) || defined(__x86_64__)
+	movsd	%xmm0,-16(%rsp)
+	fldl	-16(%rsp)
+	pushq	%rax
+	pushq	%rcx
+	fnstcw	(%rsp)
+	movq	(%rsp), %rax
+	orq	$0x20, %rax
+	movq	%rax, 8(%rsp)
+	fldcw	8(%rsp)
+	frndint
+	fclex
+	fldcw	(%rsp)
+	popq	%rcx
+	popq	%rax
+	fstpl	-16(%rsp)
+	movsd	-16(%rsp),%xmm0
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	vcvtr.s32.f64	s0, d0
+	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	fldl	4(%esp)
+	pushl	%eax
+	pushl	%ecx
+	fnstcw	(%esp)
+	movl	(%esp), %eax
+	orl	$0x20, %eax
+	movl	%eax, 4(%esp)
+	fldcw	4(%esp)
+	frndint
+	fclex
+	fldcw	(%esp)
+	popl	%ecx
+	popl	%eax
+	ret
+#endif
diff --git a/winsup/cygwin/math/nearbyintf.S b/winsup/cygwin/math/nearbyintf.S
new file mode 100644
index 000000000..460e1a5e5
--- /dev/null
+++ b/winsup/cygwin/math/nearbyintf.S
@@ -0,0 +1,57 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"nearbyintf.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	.globl __MINGW_USYMBOL(nearbyintf)
+	.def	__MINGW_USYMBOL(nearbyintf);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(nearbyintf):
+#if defined(_AMD64_) || defined(__x86_64__)
+	movss	%xmm0,-12(%rsp)
+	flds	-12(%rsp)
+	pushq	%rax
+	pushq	%rcx
+	fnstcw	(%rsp)
+	movq	(%rsp), %rax
+	orq	$0x20, %rax
+	movq	%rax, 8(%rsp)
+	fldcw	8(%rsp)
+	frndint
+	fclex
+	fldcw	(%rsp)
+	popq	%rcx
+	popq	%rax
+	fstps	-12(%rsp)
+	movss	-12(%rsp),%xmm0
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	vcvt.s32.f32	s0, s0
+	vcvt.f32.s32	s0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	flds	4(%esp)
+	pushl	%eax
+	pushl	%ecx
+	fnstcw	(%esp)
+	movl	(%esp), %eax
+	orl	$0x20, %eax
+	movl	%eax, 4(%esp)
+	fldcw	4(%esp)
+	frndint
+	fclex
+	fldcw	(%esp)
+	popl	%ecx
+	popl	%eax
+	ret
+#endif
diff --git a/winsup/cygwin/math/nearbyintl.S b/winsup/cygwin/math/nearbyintl.S
new file mode 100644
index 000000000..f4262a2e0
--- /dev/null
+++ b/winsup/cygwin/math/nearbyintl.S
@@ -0,0 +1,58 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"nearbyintl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+	.globl __MINGW_USYMBOL(nearbyintl)
+	.def	__MINGW_USYMBOL(nearbyintl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(nearbyintl):
+#if defined(_AMD64_) || defined(__x86_64__)
+	fldt	(%rdx)
+	movq	%rcx,%r8
+	pushq	%rax
+	pushq	%rcx
+	fnstcw	(%rsp)
+	movl	(%rsp), %eax
+	orl	$0x20, %eax
+	movl	%eax, 8(%rsp)
+	fldcw	8(%rsp)
+	frndint
+	fclex
+	fldcw	(%rsp)
+	popq	%rcx
+	popq	%rax
+	movq	%r8,%rax
+	movq	$0,8(%r8)
+	fstpt	(%r8)
+	ret
+#elif defined(_ARM_) || defined(__arm__)
+	vmrs	r1, fpscr
+	vcvtr.s32.f64	s0, d0
+	vcvt.f64.s32	d0, s0
+	vmsr	fpscr, r1
+	bx	lr
+#elif defined(_X86_) || defined(__i386__)
+	fldt	4(%esp)
+	pushl	%eax
+	pushl	%ecx
+	fnstcw	(%esp)
+	movl	(%esp), %eax
+	orl	$0x20, %eax
+	movl	%eax, 4(%esp)
+	fldcw	4(%esp)
+	frndint
+	fclex
+	fldcw	(%esp)
+	popl	%ecx
+	popl	%eax
+	ret
+#endif
diff --git a/winsup/cygwin/math/nextafterl.c b/winsup/cygwin/math/nextafterl.c
new file mode 100644
index 000000000..5db3af74a
--- /dev/null
+++ b/winsup/cygwin/math/nextafterl.c
@@ -0,0 +1,71 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+   nextafterl.c
+   Contributed by Danny Smith <dannysmith@users.sourceforge.net>
+   No copyright claimed, absolutely no warranties.
+
+   2005-05-09
+*/
+
+#include <math.h>
+
+long double
+nextafterl (long double x, long double y)
+{
+  union {
+      long double ld;
+      struct {
+        /* packed attribute is unnecessary on x86/x64 for these three variables */
+        unsigned long long mantissa;
+        unsigned short expn;
+        unsigned short pad;
+      } parts; 
+  } u;
+
+  /* The normal bit is explicit for long doubles, unlike
+     float and double.  */
+  static const unsigned long long normal_bit = 0x8000000000000000ull;
+  u.ld = 0.0L;
+  if (isnan (y) || isnan (x))
+    return x + y;
+
+  if (x == y )
+     /* nextafter (0.0, -O.0) should return -0.0.  */
+     return y;
+
+  u.ld = x;
+  if (x == 0.0L)
+    {
+      u.parts.mantissa = 1ull;
+      return y > 0.0L ? u.ld : -u.ld;
+    }
+
+  if (((x > 0.0L) ^ (y > x)) == 0)
+    {
+      u.parts.mantissa++;
+      if ((u.parts.mantissa & ~normal_bit) == 0ull)
+	u.parts.expn++;
+    }
+  else
+    {
+      if ((u.parts.mantissa & ~normal_bit) == 0ull)
+	u.parts.expn--;
+      u.parts.mantissa--;
+    }
+
+  /* If we have updated the expn of a normal number,
+     or moved from denormal to normal, [re]set the normal bit.  */ 
+  if (u.parts.expn & 0x7fff)
+    u.parts.mantissa |=  normal_bit;
+
+  return u.ld;
+}
+
+/* nexttowardl is the same function with a different name.  */
+long double
+nexttowardl (long double, long double) __attribute__ ((alias("nextafterl")));
+
diff --git a/winsup/cygwin/math/nexttoward.c b/winsup/cygwin/math/nexttoward.c
new file mode 100644
index 000000000..909f6ea2d
--- /dev/null
+++ b/winsup/cygwin/math/nexttoward.c
@@ -0,0 +1,47 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+   nexttoward.c
+   Contributed by Danny Smith <dannysmith@users.sourceforge.net>
+   No copyright claimed, absolutely no warranties.
+
+   2005-05-10
+*/
+
+#include <math.h>
+
+double
+nexttoward (double x, long double y)
+{
+  union
+  {
+    double d;
+    unsigned long long ll;
+  } u;
+
+  long double xx = x;
+
+  if (isnan (y) || isnan (x))
+    return x + y;
+
+  if (xx == y)
+     /* nextafter (0.0, -O.0) should return -0.0.  */
+     return y;
+  u.d = x; 
+  if (x == 0.0)
+    {
+      u.ll = 1;
+      return y > 0.0L ? u.d : -u.d;
+    }
+
+  /* Non-extended encodings are lexicographically ordered,
+     with implicit "normal" bit.  */ 
+  if (((x > 0.0) ^ (y > xx)) == 0)
+    u.ll++;
+  else
+    u.ll--;
+  return u.d;
+}
diff --git a/winsup/cygwin/math/nexttowardf.c b/winsup/cygwin/math/nexttowardf.c
new file mode 100644
index 000000000..0a2f3bfb7
--- /dev/null
+++ b/winsup/cygwin/math/nexttowardf.c
@@ -0,0 +1,43 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+   nexttowardf.c
+   Contributed by Danny Smith <dannysmith@users.sourceforge.net>
+   No copyright claimed, absolutely no warranties.
+
+   2005-05-10
+*/
+
+#include <math.h>
+
+float
+nexttowardf (float x, long double y)
+{
+  union
+  {
+    float f;
+    unsigned int i;
+  } u;
+
+  long double xx = x;
+
+  if (isnan (y) || isnan (x))
+    return x + y;
+  if (xx == y )
+     /* nextafter (0.0, -O.0) should return -0.0.  */
+     return y;
+  u.f = x; 
+  if (x == 0.0F)
+    {
+      u.i = 1;
+      return y > 0.0L ? u.f : -u.f;
+    }
+  if (((x > 0.0F) ^ (y > xx)) == 0)
+    u.i++;
+  else
+    u.i--;
+  return u.f;
+}
diff --git a/winsup/cygwin/math/pow.def.h b/winsup/cygwin/math/pow.def.h
new file mode 100644
index 000000000..a5513c1f9
--- /dev/null
+++ b/winsup/cygwin/math/pow.def.h
@@ -0,0 +1,215 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* IEEE 754 - Elementary Functions - Special Cases
+ * pow(+/-0, oo) is +0
+ * pow(+/-0, -oo) is +oo
+ * pow (x, +/-0) is 1 for any x (even a zero, quiet NaN, or infinity)
+ * pow (+1, y) is 1 for any y (even a quiet NaN)
+ * pow (+/-0, y) is +/-oo and signals the divideByZero exception for y an odd integer < 0
+ * pow (+/-0, y) is +oo and signals the divideByZero exception for finite y < 0 and not an odd integer
+ * pow (+/-0, y) is +/-0 for finite y > 0 an odd integer
+ * pow (+/-0, y) is +0 for finite y > 0 and not an odd integer
+ * pow (-1, +/-oo) is 1 with no exception
+ pow( -inf, y) = +0 for y<0 and not an odd integer
+ pow( -inf, y) = -inf for y an odd integer > 0
+ pow( -inf, y) = +inf for y>0 and not an odd integer
+ pow (+/-inf, y) is +/-0 with no exception for y an odd integer < 0
+ pow (+/-inf, -inf) is +0 with no exception
+ pow (+/-inf, +inf) is +inf with no exception
+ pow (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer
+ pow (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer
+ pow (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer
+ pow (x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.
+ 
+ For x /= 0: lim y->oo (1/x)^y results as: for |x| < 1 that sgn(x)*0 and for |x| > 0 that sgn(x)*Infinity
+
+*/
+#include "complex_internal.h"
+#include <errno.h>
+#include <limits.h>
+#include <fenv.h>
+#include <math.h>
+#include <errno.h>
+#define FE_ROUNDING_MASK \
+  (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+
+static __FLT_TYPE
+internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr)
+{
+  __FLT_TYPE int_part = (__FLT_TYPE) 0.0;
+  /* truncate */ 
+  /* truncate */
+#ifdef __x86_64__
+  asm ("pushq %%rax\n\tsubq $8, %%rsp\n"
+    "fnstcw 4(%%rsp)\n"
+    "movzwl 4(%%rsp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%rsp)\n"
+    "fldcw (%%rsp)\n"
+    "frndint\n"
+    "fldcw 4(%%rsp)\n"
+    "addq $8, %%rsp\npopq %%rax" : "=t" (int_part) : "0" (value)); /* round */
+#else
+  asm ("push %%eax\n\tsubl $8, %%esp\n"
+    "fnstcw 4(%%esp)\n"
+    "movzwl 4(%%esp), %%eax\n"
+    "orb $12, %%ah\n"
+    "movw %%ax, (%%esp)\n"
+    "fldcw (%%esp)\n"
+    "frndint\n"
+    "fldcw 4(%%esp)\n"
+    "addl $8, %%esp\n\tpop %%eax\n" : "=t" (int_part) : "0" (value)); /* round */
+#endif
+  if (iptr)
+    *iptr = int_part;
+  return (isinf (value) ?  (__FLT_TYPE) 0.0 : value - int_part);
+}
+
+__FLT_TYPE __cdecl __FLT_ABI(__powi) (__FLT_TYPE x, int n);
+
+__FLT_TYPE __cdecl
+__FLT_ABI(pow) (__FLT_TYPE x, __FLT_TYPE y)
+{
+  int x_class = fpclassify (x);
+  int y_class = fpclassify (y);
+  long odd_y = 0;
+  __FLT_TYPE d, rslt;
+
+  if (y_class == FP_ZERO || x == __FLT_CST(1.0))
+    return __FLT_CST(1.0);
+  else if (x_class == FP_NAN || y_class == FP_NAN)
+    {
+      rslt = (signbit(x) ? -__FLT_NAN : __FLT_NAN);
+      __FLT_RPT_DOMAIN ("pow", x, y, rslt);
+      return rslt;
+    }
+  else if (x_class == FP_ZERO)
+    {
+      if (y_class == FP_INFINITE)
+	return (signbit(y) ? __FLT_HUGE_VAL : __FLT_CST(0.0));
+
+      if (signbit(x) && internal_modf (y, &d) != 0.0)
+	{
+	  return signbit (y) ? (1.0 / -x) : __FLT_CST (0.0);
+	  /*__FLT_RPT_DOMAIN ("pow", x, y, -__FLT_NAN);
+	  return -__FLT_NAN; */
+	}
+      odd_y = (internal_modf (__FLT_ABI (ldexp) (y, -1), &d) != 0.0) ? 1 : 0;
+      if (!signbit(y))
+	{
+	  if (!odd_y || !signbit (x))
+	    return __FLT_CST (0.0);
+	  return -__FLT_CST(0.0);
+	}
+
+      if (!odd_y || !signbit (x))
+	return __FLT_HUGE_VAL;
+      return (signbit(x) ? -__FLT_HUGE_VAL : __FLT_HUGE_VAL);
+    }
+  else if (y_class == FP_INFINITE)
+    {
+      __FLT_TYPE a_x;
+
+      if (x_class == FP_INFINITE)
+	return (signbit (y) ? __FLT_CST (0.0) : __FLT_HUGE_VAL);
+      a_x = (signbit (x) ? -x : x);
+      if (a_x == 1.0)
+	return __FLT_CST (1.0);
+      if (a_x > 1.0)
+	return (signbit (y) == 0 ? __FLT_HUGE_VAL : __FLT_CST (0.0));
+      return (!signbit (y) ? __FLT_CST (0.0) : __FLT_HUGE_VAL);
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      /* pow (x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.  */
+      if (signbit(x) && internal_modf (y, &d) != 0.0)
+	{
+	  return signbit(y) ? 1.0 / -x : -x;
+	  /*__FLT_RPT_DOMAIN ("pow", x, y, -__FLT_NAN);
+	  return -__FLT_NAN;*/
+	}
+      odd_y = (internal_modf (__FLT_ABI (ldexp) (y, -1), &d) != 0.0) ? 1 : 0;
+      /* pow( -inf, y) = +0 for y<0 and not an odd integer,  */
+      if (signbit(x) && signbit(y) && !odd_y)
+	return __FLT_CST(0.0);
+      /* pow( -inf, y) = -inf for y an odd integer > 0.  */
+      if (signbit(x) && !signbit(y) && odd_y)
+	return -__FLT_HUGE_VAL;
+      /* pow( -inf, y) = +inf for y>0 and not an odd integer.  */
+      if (signbit(x) && !signbit(y) && !odd_y)
+	return __FLT_HUGE_VAL;
+      /* pow (+/-inf, y) is +/-0 with no exception for y an odd integer < 0. */
+      if (signbit(y))
+      {
+        /* pow (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer.  */
+	return (odd_y && signbit(x) ? -__FLT_CST(0.0) : __FLT_CST(0.0));
+      }
+      /* pow (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer.  */
+      /* pow (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer.  */
+      return (odd_y && signbit(x) ? -__FLT_HUGE_VAL : __FLT_HUGE_VAL);
+    }
+
+  if (internal_modf (y, &d) != 0.0)
+    {
+      if (signbit (x))
+	{
+	  __FLT_RPT_DOMAIN ("pow", x, y, -__FLT_NAN);
+	  return -__FLT_NAN;
+	}
+      if (y == __FLT_CST(0.5))
+	{
+	  asm ("fsqrt" : "=t" (rslt) : "0" (x));
+	  return rslt;
+	}
+    }
+  else if ((d <= (__FLT_TYPE) INT_MAX && d >= (__FLT_TYPE) INT_MIN))
+     return __FLT_ABI (__powi) (x, (int) y);
+  /* As exp already checks for minlog and maxlog no further checks are necessary.  */
+  rslt = (__FLT_TYPE) exp2l ((long double) y * log2l ((long double) __FLT_ABI(fabs) (x)));
+
+  if (signbit (x) && internal_modf (__FLT_ABI (ldexp) (y, -1), &d) != 0.0)
+    rslt = -rslt;
+  return rslt;
+}
diff --git a/winsup/cygwin/math/pow10l.c b/winsup/cygwin/math/pow10l.c
new file mode 100644
index 000000000..ad5348951
--- /dev/null
+++ b/winsup/cygwin/math/pow10l.c
@@ -0,0 +1,8 @@
+#undef pow10l
+#include <math.h>
+
+long double
+pow10l (long double x)
+{
+  return powl (10.0L, x);
+}
diff --git a/winsup/cygwin/math/powi.def.h b/winsup/cygwin/math/powi.def.h
new file mode 100644
index 000000000..f7fa860a6
--- /dev/null
+++ b/winsup/cygwin/math/powi.def.h
@@ -0,0 +1,153 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* IEEE 754 - Elementary Functions - Special Cases
+ * powi (x, +/-0) is 1 for any x (even a zero, quiet NaN, or infinity)
+ * powi (+1, y) is 1 for any y (even a quiet NaN)
+ * powi (+/-0, y) is +/-oo and signals the divideByZero exception for y an odd integer < 0
+ * powi (+/-0, y) is +oo and signals the divideByZero exception for finite y < 0 and not an odd integer
+ * powi (+/-0, y) is +/-0 for finite y > 0 an odd integer
+ * powi (+/-0, y) is +0 for finite y > 0 and not an odd integer
+ powi (-inf, y) = +0 for y<0 and not an odd integer
+ powi (-inf, y) = -inf for y an odd integer > 0
+ powi (-inf, y) = +inf for y>0 and not an odd integer
+ powi (+/-inf, y) is +/-0 with no exception for y an odd integer < 0
+ powi (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer
+ powi (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer
+ powi (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer
+ powi (x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.
+ 
+ For x /= 0: lim y->oo (1/x)^y results as: for |x| < 1 that sgn(x)*0 and for |x| > 0 that sgn(x)*Infinity
+
+*/
+#include "complex_internal.h"
+#include <errno.h>
+#include <limits.h>
+#include <fenv.h>
+#include <math.h>
+#include <errno.h>
+
+__FLT_TYPE __cdecl
+__FLT_ABI(__powi) (__FLT_TYPE x, int y);
+
+__FLT_TYPE __cdecl
+__FLT_ABI(__powi) (__FLT_TYPE x, int y)
+{
+  int x_class = fpclassify (x);
+  int odd_y = y & 1;
+  __FLT_TYPE d, rslt;
+
+  if (y == 0 || x == __FLT_CST(1.0))
+    return __FLT_CST(1.0);
+  else if (x_class == FP_NAN)
+    {
+      rslt = (signbit(x) ? -__FLT_NAN : __FLT_NAN);
+      __FLT_RPT_DOMAIN ("__powi", x, (__FLT_TYPE) y, rslt);
+      return rslt;
+    }
+  else if (x_class == FP_ZERO)
+    {
+      if (y >= 0)
+	{
+	  if (!odd_y || !signbit (x))
+	    return __FLT_CST (0.0);
+	  return -__FLT_CST(0.0);
+	}
+
+      if (!odd_y || !signbit (x))
+	return __FLT_HUGE_VAL;
+      return (signbit(x) ? -__FLT_HUGE_VAL : __FLT_HUGE_VAL);
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      /* pow( -inf, y) = +0 for y<0 and not an odd integer,  */
+      if (signbit(x) && y < 0 && !odd_y)
+	return __FLT_CST(0.0);
+      /* pow( -inf, y) = -inf for y an odd integer > 0.  */
+      if (signbit(x) && y >= 0 && odd_y)
+	return -__FLT_HUGE_VAL;
+      /* pow( -inf, y) = +inf for y>0 and not an odd integer.  */
+      if (signbit(x) && y >= 0 && !odd_y)
+	return __FLT_HUGE_VAL;
+      /* pow (+/-inf, y) is +/-0 with no exception for y an odd integer < 0. */
+      if (y < 0)
+      {
+        /* pow (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer.  */
+	return (odd_y && signbit(x) ? -__FLT_CST(0.0) : __FLT_CST(0.0));
+      }
+      /* pow (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer.  */
+      /* pow (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer.  */
+      return (odd_y && signbit(x) ? -__FLT_HUGE_VAL : __FLT_HUGE_VAL);
+    }
+
+  d = __FLT_ABI(fabs) (x);
+
+  if (y < 0)
+    {
+      d = __FLT_CST(1.0) / d;
+      y = -y;
+    }
+
+  if (!y)
+    rslt = __FLT_CST(1.0);
+  else if (y == 1)
+    rslt = d;
+  else
+    {
+      unsigned int u = (unsigned int) y;
+      rslt = ((u & 1) != 0) ? d : __FLT_CST(1.0);
+      u >>= 1;
+      do
+	{
+	  d *= d;
+	  if ((u & 1) != 0)
+	    rslt *= d;
+	  u >>= 1;
+	}
+      while (u > 0);
+    }
+  if (signbit (x) && odd_y)
+    rslt = -rslt;
+  return rslt;
+}
diff --git a/winsup/cygwin/math/powil.c b/winsup/cygwin/math/powil.c
new file mode 100644
index 000000000..d3e08e301
--- /dev/null
+++ b/winsup/cygwin/math/powil.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "powi.def.h"
diff --git a/winsup/cygwin/math/powl.c b/winsup/cygwin/math/powl.c
new file mode 100644
index 000000000..686437069
--- /dev/null
+++ b/winsup/cygwin/math/powl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "pow.def.h"
diff --git a/winsup/cygwin/math/remainder.S b/winsup/cygwin/math/remainder.S
new file mode 100644
index 000000000..5a713f904
--- /dev/null
+++ b/winsup/cygwin/math/remainder.S
@@ -0,0 +1,40 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"remainder.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(remainder)
+	.def	__MINGW_USYMBOL(remainder);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(remainder):
+#ifdef __x86_64__
+	movsd	%xmm0,-16(%rsp)
+	movsd	%xmm1,-32(%rsp)
+	fldl	-32(%rsp)
+	fldl	-16(%rsp)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	fstpl	-16(%rsp)
+	movsd	-16(%rsp),%xmm0
+	ret
+#else
+	fldl	12(%esp)
+	fldl	4(%esp)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/remainderf.S b/winsup/cygwin/math/remainderf.S
new file mode 100644
index 000000000..c3a3a3dc5
--- /dev/null
+++ b/winsup/cygwin/math/remainderf.S
@@ -0,0 +1,40 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"remainderf.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(remainder)
+	.def	__MINGW_USYMBOL(remainderf);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(remainderf):
+#ifdef __x86_64__
+	movss	%xmm1,-12(%rsp)
+	flds	-12(%rsp)
+	movss	%xmm0,-12(%rsp)
+	flds	-12(%rsp)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	fstps	-12(%rsp)
+	movss	-12(%rsp),%xmm0
+	ret
+#else
+	flds	8(%esp)
+	flds	4(%esp)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/remainderl.S b/winsup/cygwin/math/remainderl.S
new file mode 100644
index 000000000..a69e38296
--- /dev/null
+++ b/winsup/cygwin/math/remainderl.S
@@ -0,0 +1,39 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"remainderl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(remainderl)
+	.def	__MINGW_USYMBOL(remainderl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(remainderl):
+#ifdef __x86_64__
+	fldt	(%r8)
+	fldt	(%rdx)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldt	16(%esp)
+	fldt	4(%esp)
+1:	fprem1
+	fstsw	%ax
+	sahf
+	jp	1b
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/remquol.S b/winsup/cygwin/math/remquol.S
new file mode 100644
index 000000000..42cc2a78d
--- /dev/null
+++ b/winsup/cygwin/math/remquol.S
@@ -0,0 +1,75 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"remquol.S"
+        .text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(remquol)
+__MINGW_USYMBOL(remquol):
+#ifdef __x86_64__
+ 	pushq	%rcx
+        fldt (%r8)
+        fldt (%rdx)
+1:	fprem1
+        fstsw %ax
+        sahf
+        jp 1b
+        fstp %st(1)
+        movl %eax, %ecx
+        shrl $8, %eax
+        shrl $12, %ecx
+        andl $4, %ecx
+        andl $3, %eax
+        orl %eax, %ecx
+        movl $0xef2a60, %eax
+	leal (%ecx,%ecx,2),%ecx
+        shrl %cl, %eax
+        andl $7, %eax
+        movl 8(%rdx), %edx
+        xorl 8(%r8), %edx
+        testl $0x8000, %edx
+        jz 1f
+        negl %eax
+1:	movl %eax, (%r9)
+
+	popq %rcx
+	movq %rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+        ret
+#else
+        fldt 4 +12(%esp)
+        fldt 4(%esp)
+1:	fprem1
+        fstsw %ax
+        sahf
+        jp 1b
+        fstp %st(1)
+        movl %eax, %ecx
+        shrl $8, %eax
+        shrl $12, %ecx
+        andl $4, %ecx
+        andl $3, %eax
+        orl %eax, %ecx
+        movl $0xef2a60, %eax
+	leal (%ecx,%ecx,2),%ecx
+        shrl %cl, %eax
+        andl $7, %eax
+        movl 4 +12 +12(%esp), %ecx      
+        movl 4 +8(%esp), %edx
+        xorl 4 +12 +8(%esp), %edx
+        testl $0x8000, %edx
+        jz 1f
+        negl %eax
+1:	movl %eax, (%ecx)
+      
+        ret
+#endif
diff --git a/winsup/cygwin/math/rint.c b/winsup/cygwin/math/rint.c
new file mode 100644
index 000000000..01f9644b1
--- /dev/null
+++ b/winsup/cygwin/math/rint.c
@@ -0,0 +1,29 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+double __rint_internal( double x );
+asm(".def __rint_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __rint_internal\n"
+    "__rint_internal:\n"
+    "\tvcvtr.s32.f64    s0, d0\n"
+    "\tvcvt.f64.s32     d0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+double rint (double x) {
+  double retval = 0.0;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("frndint;" : "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __rint_internal(x);
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/rintf.c b/winsup/cygwin/math/rintf.c
new file mode 100644
index 000000000..09c641bcd
--- /dev/null
+++ b/winsup/cygwin/math/rintf.c
@@ -0,0 +1,29 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug */
+float __rintf_internal( float x );
+asm(".def __rintf_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __rintf_internal\n"
+    "__rintf_internal:\n"
+    "\tvcvtr.s32.f32    s0, s0\n"
+    "\tvcvt.f32.s32     s0, s0\n"
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+float rintf (float x) {
+  float retval = 0.0F;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = __rintf_internal(x);
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/rintl.c b/winsup/cygwin/math/rintl.c
new file mode 100644
index 000000000..9ec159d17
--- /dev/null
+++ b/winsup/cygwin/math/rintl.c
@@ -0,0 +1,16 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long double rintl (long double x) {
+  long double retval = 0.0L;
+#if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__)
+  __asm__ __volatile__ ("frndint;": "=t" (retval) : "0" (x));
+#elif defined(__arm__) || defined(_ARM_)
+    retval = rint(x);
+#endif
+  return retval;
+}
diff --git a/winsup/cygwin/math/roundl.c b/winsup/cygwin/math/roundl.c
new file mode 100644
index 000000000..9879a82cc
--- /dev/null
+++ b/winsup/cygwin/math/roundl.c
@@ -0,0 +1,26 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <math.h>
+
+long double
+roundl (long double x)
+{
+  long double res = 0.0L;
+  if (x >= 0.0L)
+    {
+      res = ceill (x);
+      if (res - x > 0.5L)
+	res -= 1.0L;
+    }
+  else
+    {
+      res = ceill (-x);
+      if (res + x > 0.5L)
+	res -= 1.0L;
+      res = -res;
+    }
+  return res;
+}
diff --git a/winsup/cygwin/math/scalbl.S b/winsup/cygwin/math/scalbl.S
new file mode 100644
index 000000000..f9675ac4b
--- /dev/null
+++ b/winsup/cygwin/math/scalbl.S
@@ -0,0 +1,35 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"scalbl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(scalbl)
+	.def	__MINGW_USYMBOL(scalbl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(scalbl):
+#ifdef __x86_64__
+	subq  $24, %rsp
+	fldt	(%r8)
+	fldt	(%rdx)
+	fscale
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	addq $24, %rsp
+	ret
+#else
+	fildl	16(%esp)
+	fldt	4(%esp)
+	fscale
+	fstp	%st(1)
+	ret
+#endif
diff --git a/winsup/cygwin/math/scalbnl.S b/winsup/cygwin/math/scalbnl.S
new file mode 100644
index 000000000..5ff0a68f3
--- /dev/null
+++ b/winsup/cygwin/math/scalbnl.S
@@ -0,0 +1,41 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"scalbnl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(scalbnl)
+	.def	__MINGW_USYMBOL(scalbnl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(scalbnl):
+#ifdef __x86_64__
+	subq  $24, %rsp
+	andl    $-1, %r8d
+	movq	%r8, (%rsp)
+	fildl	(%rsp)
+	fldt	(%rdx)
+	fscale
+	fstp	%st(1)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	addq $24, %rsp
+	ret
+#else
+	fildl	16(%esp)
+	fldt	4(%esp)
+	fscale
+	fstp	%st(1)
+	ret
+#endif
+
+.globl __MINGW_USYMBOL(scalblnl)
+	.set	__MINGW_USYMBOL(scalblnl),__MINGW_USYMBOL(scalbnl)
+
diff --git a/winsup/cygwin/math/sin.def.h b/winsup/cygwin/math/sin.def.h
new file mode 100644
index 000000000..c9b3b0499
--- /dev/null
+++ b/winsup/cygwin/math/sin.def.h
@@ -0,0 +1,65 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+extern long double __sinl_internal (long double);
+
+__FLT_TYPE
+__FLT_ABI(sin) (__FLT_TYPE x)
+{
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN)
+    {
+      __FLT_RPT_DOMAIN ("sin", x, 0.0, x);
+      return x;
+    }
+  else if (x_class == FP_INFINITE)
+    {
+      __FLT_RPT_DOMAIN ("sin", x, 0.0, __FLT_NAN);
+      return __FLT_NAN;
+    }
+  return (__FLT_TYPE) __sinl_internal ((long double) x);
+}
diff --git a/winsup/cygwin/math/sinhl.c b/winsup/cygwin/math/sinhl.c
new file mode 100644
index 000000000..f6ecef0f2
--- /dev/null
+++ b/winsup/cygwin/math/sinhl.c
@@ -0,0 +1,100 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_mconf.h"
+#include <errno.h>
+
+#ifdef UNK
+static uLD P[] = {
+  { { 1.7550769032975377032681E-6L } },
+  { { 4.1680702175874268714539E-4L } },
+  { { 3.0993532520425419002409E-2L } },
+  { { 9.9999999999999999998002E-1L } }
+};
+static long double Q[] = {
+  { { 1.7453965448620151484660E-8L } },
+  { { -5.9116673682651952419571E-6L } },
+  { { 1.0599252315677389339530E-3L } },
+  { { -1.1403880487744749056675E-1L } },
+  { { 6.0000000000000000000200E0L } }
+};
+#endif
+
+#ifdef IBMPC
+static const uLD P[] = {
+  { { 0xec6a,0xd942,0xfbb3,0xeb8f,0x3feb, 0, 0, 0 } },
+  { { 0x365e,0xb30a,0xe437,0xda86,0x3ff3, 0, 0, 0 } },
+  { { 0x8890,0x01f6,0x2612,0xfde6,0x3ff9, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0x3fff, 0, 0, 0 } }
+};
+static const uLD Q[] = {
+  { { 0x4edd,0x4c21,0xad09,0x95ed,0x3fe5, 0, 0, 0 } },
+  { { 0x4376,0x9b70,0xd605,0xc65c,0xbfed, 0, 0, 0 } },
+  { { 0xc8ad,0x5d21,0x3069,0x8aed,0x3ff5, 0, 0, 0 } },
+  { { 0x9c32,0x6374,0x2d4b,0xe98d,0xbffb, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0xc000,0x4001, 0, 0, 0 } }
+};
+#endif
+
+#ifdef MIEEE
+static uLD P[] = {
+  { { 0x3feb0000,0xeb8ffbb3,0xd942ec6a, 0 } },
+  { { 0x3ff30000,0xda86e437,0xb30a365e, 0 } },
+  { { 0x3ff90000,0xfde62612,0x01f68890, 0 } },
+  { { 0x3fff0000,0x80000000,0x00000000, 0 } }
+};
+static uLD Q[] = {
+  { { 0x3fe50000,0x95edad09,0x4c214edd, 0 } },
+  { { 0xbfed0000,0xc65cd605,0x9b704376, 0 } },
+  { { 0x3ff50000,0x8aed3069,0x5d21c8ad, 0 } },
+  { { 0xbffb0000,0xe98d2d4b,0x63749c32, 0 } },
+  { { 0x40010000,0xc0000000,0x00000000, 0 } }
+};
+#endif
+
+long double sinhl(long double x)
+{
+  long double a;
+  int x_class = fpclassify (x);
+
+  if (x_class == FP_NAN)
+    {
+      errno = EDOM;
+      return x;
+    }
+  if (x_class == FP_ZERO)
+    return x;
+  if (x_class == FP_INFINITE ||
+      (fabs (x) > (MAXLOGL + LOGE2L)))
+  {
+    errno = ERANGE;
+#ifdef INFINITIES
+    return (signbit (x) ? -INFINITYL : INFINITYL);
+#else
+    return (signbit (x) ? -MAXNUML : MAXNUML);
+#endif
+  }
+  a = fabsl (x);
+  if (a > 1.0L)
+  {
+    if (a >= (MAXLOGL - LOGE2L))
+    {
+      a = expl(0.5L*a);
+      a = (0.5L * a) * a;
+      if (x < 0.0L)
+	a = -a;
+      return (a);
+    }
+    a = expl(a);
+    a = 0.5L*a - (0.5L/a);
+    if (x < 0.0L)
+      a = -a;
+    return (a);
+  }
+
+  a *= a;
+  return (x + x * a * (polevll(a,P,3)/polevll(a,Q,4)));
+}
+
diff --git a/winsup/cygwin/math/sinl.c b/winsup/cygwin/math/sinl.c
new file mode 100644
index 000000000..0bbb71d37
--- /dev/null
+++ b/winsup/cygwin/math/sinl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "sin.def.h"
diff --git a/winsup/cygwin/math/sinl_internal.S b/winsup/cygwin/math/sinl_internal.S
new file mode 100644
index 000000000..6d766b098
--- /dev/null
+++ b/winsup/cygwin/math/sinl_internal.S
@@ -0,0 +1,58 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"sinl_internal.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(__sinl_internal)
+	.def	__MINGW_USYMBOL(__sinl_internal);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(__sinl_internal):
+#ifdef __x86_64__
+	fldt	(%rdx)
+	fsin
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	1f
+	movq	%rcx,%rax
+        movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+1:	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fsin
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldt	4(%esp)
+	fsin
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	1f
+	ret
+1:	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fsin
+	ret
+#endif
diff --git a/winsup/cygwin/math/sqrt.def.h b/winsup/cygwin/math/sqrt.def.h
new file mode 100644
index 000000000..1048130d0
--- /dev/null
+++ b/winsup/cygwin/math/sqrt.def.h
@@ -0,0 +1,94 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (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 "complex_internal.h"
+#include <errno.h>
+
+#if defined(__arm__) || defined(_ARM_)
+/* This works around a compiler bug, normally you would inline it with e.g.
+ * asm ("fsqrts %[dst], %[src];\n" : [dst] "=w" (res) : [src] "w" (x));
+ */
+__FLT_TYPE __fsqrt_internal( __FLT_TYPE x );
+asm(".def __fsqrt_internal; .scl 2; .type 32; .endef\n"
+    "\t.text\n"
+    "\t.align 4\n"
+    "\t.globl __fsqrt_internal\n"
+    "__fsqrt_internal:\n"
+#if _NEW_COMPLEX_FLOAT
+    "\t" "fsqrts s0, s0\n"
+#else
+    "\t" "fsqrtd d0, d0\n"
+#endif /* _NEW_COMPLEX_FLOAT */
+    "\tbx lr");
+#endif /* defined(__arm__) || defined(_ARM_) */
+
+__FLT_TYPE
+__FLT_ABI (sqrt) (__FLT_TYPE x)
+{
+  __FLT_TYPE res = __FLT_CST (0.0);
+  int x_class = fpclassify (x);
+  if (x_class == FP_NAN || signbit (x))
+    {
+      if (x_class == FP_ZERO)
+	return __FLT_CST (-0.0);
+
+      res = (signbit (x) ? -__FLT_NAN : __FLT_NAN);
+      __FLT_RPT_DOMAIN ("sqrt", x, 0.0, res);
+      return res;
+    }
+  else if (x_class == FP_ZERO)
+    return __FLT_CST (0.0);
+  else if (x_class == FP_INFINITE)
+    return __FLT_HUGE_VAL;
+  else if (x == __FLT_CST (1.0))
+   return __FLT_CST (1.0);
+#if defined(__arm__) || defined(_ARM_)
+  __fsqrt_internal(x);
+#elif defined(_X86_) || defined(__i386__) || defined(_AMD64_) || defined(__x86_64__)
+  asm ("fsqrt" : "=t" (res) : "0" (x));
+#else
+#error Not supported on your platform yet
+#endif
+  return res;
+}
diff --git a/winsup/cygwin/math/sqrtl.c b/winsup/cygwin/math/sqrtl.c
new file mode 100644
index 000000000..ffd818591
--- /dev/null
+++ b/winsup/cygwin/math/sqrtl.c
@@ -0,0 +1,46 @@
+/*
+ This Software is provided under the Zope Public License (ZPL) Version 2.1.
+
+ Copyright (c) 2009, 2010 by the mingw-w64 project
+
+ See the AUTHORS file for the list of contributors to the mingw-w64 project.
+
+ This license has been certified as open source. It has also been designated
+ as GPL compatible by the Free Software Foundation (FSF).
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions in source code must retain the accompanying copyright
+      notice, this list of conditions, and the following disclaimer.
+   2. Redistributions in binary form must reproduce the accompanying
+      copyright notice, this list of conditions, and the following disclaimer
+      in the documentation and/or other materials provided with the
+      distribution.
+   3. Names of the copyright holders must not be used to endorse or promote
+      products derived from this software without prior written permission
+      from the copyright holders.
+   4. The right to distribute this software or to use it for any purpose does
+      not give you the right to use Servicemarks (sm) or Trademarks (tm) of
+      the copyright holders.  Use of them is covered by separate agreement
+      with the copyright holders.
+   5. If any files are modified, you must cause the modified files to carry
+      prominent notices stating that you changed the files and the date of
+      any change.
+
+ Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define _NEW_COMPLEX_LDOUBLE 1
+#include "sqrt.def.h"
diff --git a/winsup/cygwin/math/tanhl.c b/winsup/cygwin/math/tanhl.c
new file mode 100644
index 000000000..2c48a6aab
--- /dev/null
+++ b/winsup/cygwin/math/tanhl.c
@@ -0,0 +1,92 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_mconf.h"
+#ifndef _SET_ERRNO
+#define _SET_ERRNO(x)
+#endif
+
+#ifdef UNK
+static uLD P[] = {
+  { { -6.8473739392677100872869E-5L } },
+  { { -9.5658283111794641589011E-1L } },
+  { { -8.4053568599672284488465E1L } },
+  { { -1.3080425704712825945553E3L } }
+};
+static uLD Q[] = {
+  { { 9.6259501838840336946872E1L } },
+  { { 1.8218117903645559060232E3L } },
+  { { 3.9241277114138477845780E3L } }
+};
+#endif
+
+#ifdef IBMPC
+static uLD P[] = {
+  { { 0xd2a4,0x1b0c,0x8f15,0x8f99,0xbff1, 0, 0, 0 } },
+  { { 0x5959,0x9111,0x9cc7,0xf4e2,0xbffe, 0, 0, 0 } },
+  { { 0xb576,0xef5e,0x6d57,0xa81b,0xc005, 0, 0, 0 } },
+  { { 0xe3be,0xbfbd,0x5cbc,0xa381,0xc009, 0, 0, 0 } }
+};
+static uLD Q[] = {
+  { { 0x687f,0xce24,0xdd6c,0xc084,0x4005, 0, 0, 0 } },
+  { { 0x3793,0xc95f,0xfa2f,0xe3b9,0x4009, 0, 0, 0 } },
+  { { 0xd5a2,0x1f9c,0x0b1b,0xf542,0x400a, 0, 0, 0 } }
+};
+#endif
+
+#ifdef MIEEE
+static uLD P[] = {
+  { { 0xbff10000,0x8f998f15,0x1b0cd2a4, 0 } },
+  { { 0xbffe0000,0xf4e29cc7,0x91115959, 0 } },
+  { { 0xc0050000,0xa81b6d57,0xef5eb576, 0 } },
+  { { 0xc0090000,0xa3815cbc,0xbfbde3be, 0 } }
+};
+static uLD Q[] = {
+  { { 0x40050000,0xc084dd6c,0xce24687f, 0 } },
+  { { 0x40090000,0xe3b9fa2f,0xc95f3793, 0 } },
+  { { 0x400a0000,0xf5420b1b,0x1f9cd5a2, 0 } }
+};
+#endif
+
+long double tanhl(long double x)
+{
+  long double s, z;
+
+#ifdef MINUSZERO
+  if (x == 0.0L)
+    return (x);
+#endif
+  if (isnanl(x))
+  {
+    _SET_ERRNO (EDOM);
+    return x;
+  }
+
+  z = fabsl(x);
+  if (z > 0.5L * MAXLOGL)
+  {
+    _SET_ERRNO (ERANGE);
+    if (x > 0)
+      return (1.0L);
+    else
+      return (-1.0L);
+  }
+  if (z >= 0.625L)
+  {
+    s = expl(2.0*z);
+    z =  1.0L  - 2.0/(s + 1.0L);
+    if (x < 0)
+      z = -z;
+  }
+  else
+  {
+    s = x * x;
+    z = polevll( s, P, 3 )/p1evll(s, Q, 3);
+    z = x * s * z;
+    z = x + z;
+  }
+  return (z);
+}
+
diff --git a/winsup/cygwin/math/tanl.S b/winsup/cygwin/math/tanl.S
new file mode 100644
index 000000000..f11b53920
--- /dev/null
+++ b/winsup/cygwin/math/tanl.S
@@ -0,0 +1,62 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+	.file	"tanl.S"
+	.text
+#ifdef __x86_64__
+	.align 8
+#else
+	.align 4
+#endif
+.globl __MINGW_USYMBOL(tanl)
+	.def	__MINGW_USYMBOL(tanl);	.scl	2;	.type	32;	.endef
+__MINGW_USYMBOL(tanl):
+#ifdef __x86_64__
+	fldt	(%rdx)
+	fptan
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	1f
+	fstp	%st(0)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+1:	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fptan
+	fstp	%st(0)
+	movq	%rcx,%rax
+	movq	$0,8(%rcx)
+	fstpt	(%rcx)
+	ret
+#else
+	fldt	4(%esp)
+	fptan
+	fnstsw	%ax
+	testl	$0x400,%eax
+	jnz	1f
+	fstp	%st(0)
+	ret
+1:	fldpi
+	fadd	%st(0)
+	fxch	%st(1)
+2:	fprem1
+	fstsw	%ax
+	testl	$0x400,%eax
+	jnz	2b
+	fstp	%st(1)
+	fptan
+	fstp	%st(0)
+	ret
+#endif
diff --git a/winsup/cygwin/math/tgammal.c b/winsup/cygwin/math/tgammal.c
new file mode 100644
index 000000000..99408eed7
--- /dev/null
+++ b/winsup/cygwin/math/tgammal.c
@@ -0,0 +1,393 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include "cephes_mconf.h"
+
+/*
+gamma(x+2)  = gamma(x+2) P(x)/Q(x)
+0 <= x <= 1
+Relative error
+n=7, d=8
+Peak error =  1.83e-20
+Relative error spread =  8.4e-23
+*/
+
+#if UNK
+static const uLD P[8] = {
+  { { 4.212760487471622013093E-5L } },
+  { { 4.542931960608009155600E-4L } },
+  { { 4.092666828394035500949E-3L } },
+  { { 2.385363243461108252554E-2L } },
+  { { 1.113062816019361559013E-1L } },
+  { { 3.629515436640239168939E-1L } },
+  { { 8.378004301573126728826E-1L } },
+  { { 1.000000000000000000009E0L } }
+};
+static const uLD Q[9] = {
+  { { -1.397148517476170440917E-5L } },
+  { { 2.346584059160635244282E-4L } },
+  { { -1.237799246653152231188E-3L } },
+  { { -7.955933682494738320586E-4L } },
+  { { 2.773706565840072979165E-2L } },
+  { { -4.633887671244534213831E-2L } },
+  { { -2.243510905670329164562E-1L } },
+  { { 4.150160950588455434583E-1L } },
+  { { 9.999999999999999999908E-1L } }
+};
+#endif
+#if IBMPC
+static const uLD P[8] = {
+  { { 0x434a,0x3f22,0x2bda,0xb0b2,0x3ff0, 0x0, 0x0, 0x0 } },
+  { { 0xf5aa,0xe82f,0x335b,0xee2e,0x3ff3, 0x0, 0x0, 0x0 } },
+  { { 0xbe6c,0x3757,0xc717,0x861b,0x3ff7, 0x0, 0x0, 0x0 } },
+  { { 0x7f43,0x5196,0xb166,0xc368,0x3ff9, 0x0, 0x0, 0x0 } },
+  { { 0x9549,0x8eb5,0x8c3a,0xe3f4,0x3ffb, 0x0, 0x0, 0x0 } },
+  { { 0x8d75,0x23af,0xc8e4,0xb9d4,0x3ffd, 0x0, 0x0, 0x0 } },
+  { { 0x29cf,0x19b3,0x16c8,0xd67a,0x3ffe, 0x0, 0x0, 0x0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0x3fff, 0x0, 0x0, 0x0 } }
+};
+static const uLD Q[9] = {
+  { { 0x5473,0x2de8,0x1268,0xea67,0xbfee, 0x0, 0x0, 0x0 } },
+  { { 0x334b,0xc2f0,0xa2dd,0xf60e,0x3ff2, 0x0, 0x0, 0x0 } },
+  { { 0xbeed,0x1853,0xa691,0xa23d,0xbff5, 0x0, 0x0, 0x0 } },
+  { { 0x296e,0x7cb1,0x5dfd,0xd08f,0xbff4, 0x0, 0x0, 0x0 } },
+  { { 0x0417,0x7989,0xd7bc,0xe338,0x3ff9, 0x0, 0x0, 0x0 } },
+  { { 0x3295,0x3698,0xd580,0xbdcd,0xbffa, 0x0, 0x0, 0x0 } },
+  { { 0x75ef,0x3ab7,0x4ad3,0xe5bc,0xbffc, 0x0, 0x0, 0x0 } },
+  { { 0xe458,0x2ec7,0xfd57,0xd47c,0x3ffd, 0x0, 0x0, 0x0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0x3fff, 0x0, 0x0, 0x0 } }
+};
+#endif
+#if MIEEE
+static const uLD P[8] = {
+  { { 0x3ff00000,0xb0b22bda,0x3f22434a, 0 } },
+  { { 0x3ff30000,0xee2e335b,0xe82ff5aa, 0 } },
+  { { 0x3ff70000,0x861bc717,0x3757be6c, 0 } },
+  { { 0x3ff90000,0xc368b166,0x51967f43, 0 } },
+  { { 0x3ffb0000,0xe3f48c3a,0x8eb59549, 0 } },
+  { { 0x3ffd0000,0xb9d4c8e4,0x23af8d75, 0 } },
+  { { 0x3ffe0000,0xd67a16c8,0x19b329cf, 0 } },
+  { { 0x3fff0000,0x80000000,0x00000000, 0 } }
+};
+static const uLD Q[9] = {
+  { { 0xbfee0000,0xea671268,0x2de85473, 0 } },
+  { { 0x3ff20000,0xf60ea2dd,0xc2f0334b, 0 } },
+  { { 0xbff50000,0xa23da691,0x1853beed, 0 } },
+  { { 0xbff40000,0xd08f5dfd,0x7cb1296e, 0 } },
+  { { 0x3ff90000,0xe338d7bc,0x79890417, 0 } },
+  { { 0xbffa0000,0xbdcdd580,0x36983295, 0 } },
+  { { 0xbffc0000,0xe5bc4ad3,0x3ab775ef, 0 } },
+  { { 0x3ffd0000,0xd47cfd57,0x2ec7e458, 0 } },
+  { { 0x3fff0000,0x80000000,0x00000000, 0 } }
+};
+#endif
+
+#define MAXGAML 1755.455L
+/*static const long double LOGPI = 1.14472988584940017414L;*/
+
+/* Stirling's formula for the gamma function
+gamma(x) = sqrt(2 pi) x^(x-.5) exp(-x) (1 + 1/x P(1/x))
+z(x) = x
+13 <= x <= 1024
+Relative error
+n=8, d=0
+Peak error =  9.44e-21
+Relative error spread =  8.8e-4
+*/
+#if UNK
+static const uLD STIR[9] = {
+  { { 7.147391378143610789273E-4L } },
+  { { -2.363848809501759061727E-5L } },
+  { { -5.950237554056330156018E-4L } },
+  { { 6.989332260623193171870E-5L } },
+  { { 7.840334842744753003862E-4L } },
+  { { -2.294719747873185405699E-4L } },
+  { { -2.681327161876304418288E-3L } },
+  { { 3.472222222230075327854E-3L } },
+  { { 8.333333333333331800504E-2L } }
+};
+#endif
+#if IBMPC
+static const uLD STIR[9] = {
+  { { 0x6ede,0x69f7,0x54e3,0xbb5d,0x3ff4, 0, 0, 0 } },
+  { { 0xc395,0x0295,0x4443,0xc64b,0xbfef, 0, 0, 0 } },
+  { { 0xba6f,0x7c59,0x5e47,0x9bfb,0xbff4, 0, 0, 0 } },
+  { { 0x5704,0x1a39,0xb11d,0x9293,0x3ff1, 0, 0, 0 } },
+  { { 0x30b7,0x1a21,0x98b2,0xcd87,0x3ff4, 0, 0, 0 } },
+  { { 0xbef3,0x7023,0x6a08,0xf09e,0xbff2, 0, 0, 0 } },
+  { { 0x3a1c,0x5ac8,0x3478,0xafb9,0xbff6, 0, 0, 0 } },
+  { { 0xc3c9,0x906e,0x38e3,0xe38e,0x3ff6, 0, 0, 0 } },
+  { { 0xa1d5,0xaaaa,0xaaaa,0xaaaa,0x3ffb, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static const uLD STIR[9] = {
+  { { 0x3ff40000,0xbb5d54e3,0x69f76ede, 0 } },
+  { { 0xbfef0000,0xc64b4443,0x0295c395, 0 } },
+  { { 0xbff40000,0x9bfb5e47,0x7c59ba6f, 0 } },
+  { { 0x3ff10000,0x9293b11d,0x1a395704, 0 } },
+  { { 0x3ff40000,0xcd8798b2,0x1a2130b7, 0 } },
+  { { 0xbff20000,0xf09e6a08,0x7023bef3, 0 } },
+  { { 0xbff60000,0xafb93478,0x5ac83a1c, 0 } },
+  { { 0x3ff60000,0xe38e38e3,0x906ec3c9, 0 } },
+  { { 0x3ffb0000,0xaaaaaaaa,0xaaaaa1d5, 0 } }
+};
+#endif
+#define MAXSTIR 1024.0L
+static const long double SQTPI = 2.50662827463100050242E0L;
+
+/* 1/gamma(x) = z P(z)
+ * z(x) = 1/x
+ * 0 < x < 0.03125
+ * Peak relative error 4.2e-23
+ */
+#if UNK
+static const uLD S[9] = {
+  { { -1.193945051381510095614E-3L } },
+  { { 7.220599478036909672331E-3L } },
+  { { -9.622023360406271645744E-3L } },
+  { { -4.219773360705915470089E-2L } },
+  { { 1.665386113720805206758E-1L } },
+  { { -4.200263503403344054473E-2L } },
+  { { -6.558780715202540684668E-1L } },
+  { { 5.772156649015328608253E-1L } },
+  { { 1.000000000000000000000E0L } }
+};
+#endif
+#if IBMPC
+static const uLD S[9] = {
+  { { 0xbaeb,0xd6d3,0x25e5,0x9c7e,0xbff5, 0, 0, 0 } },
+  { { 0xfe9a,0xceb4,0xc74e,0xec9a,0x3ff7, 0, 0, 0 } },
+  { { 0x9225,0xdfef,0xb0e9,0x9da5,0xbff8, 0, 0, 0 } },
+  { { 0x10b0,0xec17,0x87dc,0xacd7,0xbffa, 0, 0, 0 } },
+  { { 0x6b8d,0x7515,0x1905,0xaa89,0x3ffc, 0, 0, 0 } },
+  { { 0xf183,0x126b,0xf47d,0xac0a,0xbffa, 0, 0, 0 } },
+  { { 0x7bf6,0x57d1,0xa013,0xa7e7,0xbffe, 0, 0, 0 } },
+  { { 0xc7a9,0x7db0,0x67e3,0x93c4,0x3ffe, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0x3fff, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static const long S[9] = {
+  { { 0xbff50000,0x9c7e25e5,0xd6d3baeb, 0 } },
+  { { 0x3ff70000,0xec9ac74e,0xceb4fe9a, 0 } },
+  { { 0xbff80000,0x9da5b0e9,0xdfef9225, 0 } },
+  { { 0xbffa0000,0xacd787dc,0xec1710b0, 0 } },
+  { { 0x3ffc0000,0xaa891905,0x75156b8d, 0 } },
+  { { 0xbffa0000,0xac0af47d,0x126bf183, 0 } },
+  { { 0xbffe0000,0xa7e7a013,0x57d17bf6, 0 } },
+  { { 0x3ffe0000,0x93c467e3,0x7db0c7a9, 0 } },
+  { { 0x3fff0000,0x80000000,0x00000000, 0 } }
+};
+#endif
+/* 1/gamma(-x) = z P(z)
+ * z(x) = 1/x
+ * 0 < x < 0.03125
+ * Peak relative error 5.16e-23
+ * Relative error spread =  2.5e-24
+ */
+#if UNK
+static const uLD SN[9] = {
+  { { 1.133374167243894382010E-3L } },
+  { { 7.220837261893170325704E-3L } },
+  { { 9.621911155035976733706E-3L } },
+  { { -4.219773343731191721664E-2L } },
+  { { -1.665386113944413519335E-1L } },
+  { { -4.200263503402112910504E-2L } },
+  { { 6.558780715202536547116E-1L } },
+  { { 5.772156649015328608727E-1L } },
+  { { -1.000000000000000000000E0L } }
+};
+#endif
+#if IBMPC
+static const uLD SN[9] = {
+  { { 0x5dd1,0x02de,0xb9f7,0x948d,0x3ff5, 0, 0, 0 } },
+  { { 0x989b,0xdd68,0xc5f1,0xec9c,0x3ff7, 0, 0, 0 } },
+  { { 0x2ca1,0x18f0,0x386f,0x9da5,0x3ff8, 0, 0, 0 } },
+  { { 0x783f,0x41dd,0x87d1,0xacd7,0xbffa, 0, 0, 0 } },
+  { { 0x7a5b,0xd76d,0x1905,0xaa89,0xbffc, 0, 0, 0 } },
+  { { 0x7f64,0x1234,0xf47d,0xac0a,0xbffa, 0, 0, 0 } },
+  { { 0x5e26,0x57d1,0xa013,0xa7e7,0x3ffe, 0, 0, 0 } },
+  { { 0xc7aa,0x7db0,0x67e3,0x93c4,0x3ffe, 0, 0, 0 } },
+  { { 0x0000,0x0000,0x0000,0x8000,0xbfff, 0, 0, 0 } }
+};
+#endif
+#if MIEEE
+static const uLD SN[9] = {
+  { { 0x3ff50000,0x948db9f7,0x02de5dd1, 0 } },
+  { { 0x3ff70000,0xec9cc5f1,0xdd68989b, 0 } },
+  { { 0x3ff80000,0x9da5386f,0x18f02ca1, 0 } },
+  { { 0xbffa0000,0xacd787d1,0x41dd783f, 0 } },
+  { { 0xbffc0000,0xaa891905,0xd76d7a5b, 0 } },
+  { { 0xbffa0000,0xac0af47d,0x12347f64, 0 } },
+  { { 0x3ffe0000,0xa7e7a013,0x57d15e26, 0 } },
+  { { 0x3ffe0000,0x93c467e3,0x7db0c7aa, 0 } },
+  { { 0xbfff0000,0x80000000,0x00000000, 0 } }
+};
+#endif
+
+static long double stirf (long double);
+
+/* Gamma function computed by Stirling's formula.  */
+
+static long double stirf(long double x)
+{
+	long double y, w, v;
+
+	w = 1.0L/x;
+	/* For large x, use rational coefficients from the analytical expansion.  */
+	if (x > 1024.0L)
+		w = (((((6.97281375836585777429E-5L * w
+		      + 7.84039221720066627474E-4L) * w
+		      - 2.29472093621399176955E-4L) * w
+		      - 2.68132716049382716049E-3L) * w
+		      + 3.47222222222222222222E-3L) * w
+		      + 8.33333333333333333333E-2L) * w
+		      + 1.0L;
+	else
+		w = 1.0L + w * polevll( w, STIR, 8 );
+	y = expl(x);
+	if (x > MAXSTIR)
+	{ /* Avoid overflow in pow() */
+		v = powl(x, 0.5L * x - 0.25L);
+		y = v * (v / y);
+	}
+	else
+	{
+		y = powl(x, x - 0.5L) / y;
+	}
+	y = SQTPI * y * w;
+	return (y);
+}
+
+long double __tgammal_r(long double, int *);
+
+long double __tgammal_r(long double x, int* sgngaml)
+{
+	long double p, q, z;
+	int i;
+
+	*sgngaml = 1;
+#ifdef NANS
+	if (isnanl(x))
+		return (NANL);
+#endif
+#ifdef INFINITIES
+#ifdef NANS
+	if (x == INFINITYL)
+		return (x);
+	if (x == -INFINITYL)
+		return (NANL);
+#else
+	if (!isfinite(x))
+		return (x);
+#endif
+#endif
+	q = fabsl(x);
+
+	if (q > 13.0L)
+	{
+		if (q > MAXGAML)
+			goto goverf;
+		if (x < 0.0L)
+		{
+			p = floorl(q);
+			if (p == q)
+			{
+gsing:
+				_SET_ERRNO(EDOM);
+				mtherr("tgammal", SING);
+#ifdef INFINITIES
+				return (INFINITYL);
+#else
+				return (*sgngaml * MAXNUML);
+#endif
+			}
+			i = p;
+			if ((i & 1) == 0)
+				*sgngaml = -1;
+			z = q - p;
+			if (z > 0.5L)
+			{
+				p += 1.0L;
+				z = q - p;
+			}
+			z = q * sinl(PIL * z);
+			z = fabsl(z) * stirf(q);
+			if (z <= PIL/MAXNUML)
+			{
+goverf:
+				_SET_ERRNO(ERANGE);
+				mtherr("tgammal", OVERFLOW);
+#ifdef INFINITIES
+				return(*sgngaml * INFINITYL);
+#else
+				return(*sgngaml * MAXNUML);
+#endif
+			}
+			z = PIL/z;
+		}
+		else
+		{
+			z = stirf(x);
+		}
+		return (*sgngaml * z);
+	}
+
+	z = 1.0L;
+	while (x >= 3.0L)
+	{
+		x -= 1.0L;
+		z *= x;
+	}
+
+	while (x < -0.03125L)
+	{
+		z /= x;
+		x += 1.0L;
+	}
+
+	if (x <= 0.03125L)
+		goto Small;
+
+	while (x < 2.0L)
+	{
+		z /= x;
+		x += 1.0L;
+	}
+
+	if (x == 2.0L)
+		return (z);
+
+	x -= 2.0L;
+	p = polevll( x, P, 7 );
+	q = polevll( x, Q, 8 );
+	return (z * p / q);
+
+Small:
+	if (x == 0.0L)
+	{
+		goto gsing;
+	}
+	else
+	{
+		if (x < 0.0L)
+		{
+			x = -x;
+			q = z / (x * polevll(x, SN, 8));
+		}
+		else
+			q = z / (x * polevll(x, S, 8));
+	}
+	return q;
+}
+
+/* This is the C99 version. */
+long double tgammal(long double x)
+{
+	int local_sgngaml = 0;
+	return (__tgammal_r(x, &local_sgngaml));
+}
+
diff --git a/winsup/cygwin/math/truncl.c b/winsup/cygwin/math/truncl.c
new file mode 100644
index 000000000..ddc6af68f
--- /dev/null
+++ b/winsup/cygwin/math/truncl.c
@@ -0,0 +1,26 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <fenv.h>
+#include <math.h>
+
+long double
+truncl (long double _x)
+{
+#if defined(_ARM_) || defined(__arm__)
+  return trunc(_x);
+#else
+  long double retval = 0.0L;
+  unsigned short saved_cw;
+  unsigned short tmp_cw;
+  __asm__ __volatile__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
+  tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
+	    | FE_TOWARDZERO;
+  __asm__ __volatile__ ("fldcw %0;" : : "m" (tmp_cw));
+  __asm__ __volatile__ ("frndint;" : "=t" (retval)  : "0" (_x)); /* round towards zero */
+  __asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
+  return retval;
+#endif /* defined(_ARM_) || defined(__arm__) */
+}
diff --git a/winsup/cygwin/x86_64.din b/winsup/cygwin/x86_64.din
index 24f2584c6..e1896bf8a 100644
--- a/winsup/cygwin/x86_64.din
+++ b/winsup/cygwin/x86_64.din
@@ -12,9 +12,3 @@ __wrap__ZnwmRKSt9nothrow_t NOSIGFE  # void *operator new(std::size_t sz, const s
 _alloca = __alloca NOSIGFE
 _dll_crt0 NOSIGFE
 dll_entry NOSIGFE
-llrint NOSIGFE
-llrintf NOSIGFE
-lrint NOSIGFE
-lrintf NOSIGFE
-rint NOSIGFE
-rintf NOSIGFE