Add to libmingwex the local math functions for double type modf and fmod.


git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@3018 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index a30c72b..934b85d 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -147,6 +147,7 @@
   math/expm1.c        math/expm1f.c       math/expm1l.c       math/fabs.c          math/fabsf.c       math/fabsl.c       \
   math/fdim.c         math/fdimf.c        math/fdiml.c        math/floorf.c        math/fmal.c        math/fmax.c        \
   math/fmaxf.c        math/fmaxl.c        math/fmin.c         math/fminf.c         math/fminl.c       math/fmodf.c       \
+  math/fmod.c         math/modf.c \
   math/fmodl.c        math/fpclassify.c   math/fpclassifyf.c  math/fpclassifyl.c   math/fp_consts.c   math/fp_constsf.c  \
   math/fp_constsl.c   math/frexpf.c       math/fucom.c        math/hypotf.c        math/hypotl.c      math/isnan.c       \
   math/isnanf.c       math/isnanl.c       math/ldexpf.c       math/ldexpl.c        math/lgamma.c      math/lgammaf.c     \
diff --git a/mingw-w64-crt/math/fmod.c b/mingw-w64-crt/math/fmod.c
new file mode 100644
index 0000000..d2f97ed
--- /dev/null
+++ b/mingw-w64-crt/math/fmod.c
@@ -0,0 +1,20 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the w64 mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+double fmodl (double x, double y);
+
+double
+fmod (double x, double y)
+{
+  double res = 0.0;
+
+  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/mingw-w64-crt/math/modf.c b/mingw-w64-crt/math/modf.c
new file mode 100644
index 0000000..3bfd4e0
--- /dev/null
+++ b/mingw-w64-crt/math/modf.c
@@ -0,0 +1,27 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the w64 mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <fenv.h>
+#include <math.h>
+#include <errno.h>
+#define FE_ROUNDING_MASK \
+  (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+
+double
+modf (double value, double* iptr)
+{
+  double int_part = 0.0;
+  unsigned short saved_cw;
+  unsigned short tmp_cw;
+  /* truncate */ 
+  asm ("fnstcw %0;" : "=m" (saved_cw)); /* save control word */
+  tmp_cw = (saved_cw & ~FE_ROUNDING_MASK) | FE_TOWARDZERO;
+  asm ("fldcw %0;" : : "m" (tmp_cw));
+  asm ("frndint;" : "=t" (int_part) : "0" (value)); /* round */
+  asm ("fldcw %0;" : : "m" (saved_cw)); /* restore saved cw */
+  if (iptr)
+    *iptr = int_part;
+  return (isinf (value) ?  0.0 : value - int_part);
+}