+++ /dev/null
-/* Math functions for i387.
- Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by John C. Bowman <bowman@ipp-garching.mpg.de>, 1995.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <math.h>
-
-double fmod (double __x, double __y);
-
-double fmod (double __x, double __y)
-{
- register double __val;
-#ifdef __GNUC__
- __asm __volatile__
- ("1: fprem\n\t"
- "fstsw %%ax\n\t"
- "sahf\n\t"
- "jp 1b"
- : "=t" (__val) : "0" (__x), "u" (__y) : "ax", "cc");
-#else
- __val = linkme_fmod(__x, __y);
-#endif /*__GNUC__*/
- return __val;
-}
--- /dev/null
+\r
+\r
+/* @(#)s_modf.c 5.1 93/09/24 */\r
+/*\r
+ * ====================================================\r
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
+ *\r
+ * Developed at SunPro, a Sun Microsystems, Inc. business.\r
+ * Permission to use, copy, modify, and distribute this\r
+ * software is freely granted, provided that this notice \r
+ * is preserved.\r
+ * ====================================================\r
+ */\r
+\r
+/*\r
+FUNCTION\r
+ <<modf>>, <<modff>>---split fractional and integer parts\r
+\r
+INDEX\r
+ modf\r
+INDEX\r
+ modff\r
+\r
+ANSI_SYNOPSIS\r
+ #include <math.h>\r
+ double modf(double <[val]>, double *<[ipart]>);\r
+ float modff(float <[val]>, float *<[ipart]>);\r
+\r
+TRAD_SYNOPSIS\r
+ #include <math.h>\r
+ double modf(<[val]>, <[ipart]>)\r
+ double <[val]>;\r
+ double *<[ipart]>;\r
+\r
+ float modff(<[val]>, <[ipart]>)\r
+ float <[val]>;\r
+ float *<[ipart]>;\r
+\r
+DESCRIPTION\r
+ <<modf>> splits the double <[val]> apart into an integer part\r
+ and a fractional part, returning the fractional part and\r
+ storing the integer part in <<*<[ipart]>>>. No rounding\r
+ whatsoever is done; the sum of the integer and fractional\r
+ parts is guaranteed to be exactly equal to <[val]>. That\r
+ is, if . <[realpart]> = modf(<[val]>, &<[intpart]>); then\r
+ `<<<[realpart]>+<[intpart]>>>' is the same as <[val]>.\r
+ <<modff>> is identical, save that it takes and returns\r
+ <<float>> rather than <<double>> values. \r
+\r
+RETURNS\r
+ The fractional part is returned. Each result has the same\r
+ sign as the supplied argument <[val]>.\r
+\r
+PORTABILITY\r
+ <<modf>> is ANSI C. <<modff>> is an extension.\r
+\r
+QUICKREF\r
+ modf ansi pure \r
+ modff - pure\r
+\r
+*/\r
+\r
+/*\r
+ * modf(double x, double *iptr) \r
+ * return fraction part of x, and return x's integral part in *iptr.\r
+ * Method:\r
+ * Bit twiddling.\r
+ *\r
+ * Exception:\r
+ * No exception.\r
+ */\r
+\r
+\r
+static const double one = 1.0;\r
+\r
+#define __int32_t long\r
+#define __uint32_t unsigned long\r
+#define __IEEE_LITTLE_ENDIAN\r
+\r
+#ifdef __IEEE_BIG_ENDIAN\r
+\r
+typedef union \r
+{\r
+ struct \r
+ {\r
+ __uint32_t msw;\r
+ __uint32_t lsw;\r
+ } parts;\r
+ double value;\r
+} ieee_double_shape_type;\r
+\r
+#endif\r
+\r
+#ifdef __IEEE_LITTLE_ENDIAN\r
+\r
+typedef union \r
+{\r
+ struct \r
+ {\r
+ __uint32_t lsw;\r
+ __uint32_t msw;\r
+ } parts;\r
+ double value;\r
+} ieee_double_shape_type;\r
+\r
+#endif\r
+\r
+\r
+/* Get two 32 bit ints from a double. */\r
+\r
+#define EXTRACT_WORDS(ix0,ix1,d) \\r
+do { \\r
+ ieee_double_shape_type ew_u; \\r
+ ew_u.value = (d); \\r
+ (ix0) = ew_u.parts.msw; \\r
+ (ix1) = ew_u.parts.lsw; \\r
+} while (0)\r
+\r
+/* Get the more significant 32 bit int from a double. */\r
+\r
+#define GET_HIGH_WORD(i,d) \\r
+do { \\r
+ ieee_double_shape_type gh_u; \\r
+ gh_u.value = (d); \\r
+ (i) = gh_u.parts.msw; \\r
+} while (0)\r
+\r
+/* Get the less significant 32 bit int from a double. */\r
+\r
+#define GET_LOW_WORD(i,d) \\r
+do { \\r
+ ieee_double_shape_type gl_u; \\r
+ gl_u.value = (d); \\r
+ (i) = gl_u.parts.lsw; \\r
+} while (0)\r
+\r
+/* Set a double from two 32 bit ints. */\r
+\r
+#define INSERT_WORDS(d,ix0,ix1) \\r
+do { \\r
+ ieee_double_shape_type iw_u; \\r
+ iw_u.parts.msw = (ix0); \\r
+ iw_u.parts.lsw = (ix1); \\r
+ (d) = iw_u.value; \\r
+} while (0)\r
+\r
+\r
+\r
+\r
+double modf(double x, double *iptr)\r
+{\r
+ __int32_t i0,i1,j_0;\r
+ __uint32_t i;\r
+ EXTRACT_WORDS(i0,i1,x);\r
+ j_0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */\r
+ if(j_0<20) { /* integer part in high x */\r
+ if(j_0<0) { /* |x|<1 */\r
+ INSERT_WORDS(*iptr,i0&0x80000000U,0); /* *iptr = +-0 */\r
+ return x;\r
+ } else {\r
+ i = (0x000fffff)>>j_0;\r
+ if(((i0&i)|i1)==0) { /* x is integral */\r
+ __uint32_t high;\r
+ *iptr = x;\r
+ GET_HIGH_WORD(high,x);\r
+ INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */\r
+ return x;\r
+ } else {\r
+ INSERT_WORDS(*iptr,i0&(~i),0);\r
+ return x - *iptr;\r
+ }\r
+ }\r
+ } else if (j_0>51) { /* no fraction part */\r
+ __uint32_t high;\r
+ *iptr = x*one;\r
+ GET_HIGH_WORD(high,x);\r
+ INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */\r
+ return x;\r
+ } else { /* fraction part in low x */\r
+ i = ((__uint32_t)(0xffffffffU))>>(j_0-20);\r
+ if((i1&i)==0) { /* x is integral */\r
+ __uint32_t high;\r
+ *iptr = x;\r
+ GET_HIGH_WORD(high,x);\r
+ INSERT_WORDS(x,high&0x80000000U,0); /* return +-0 */\r
+ return x;\r
+ } else {\r
+ INSERT_WORDS(*iptr,i0,i1&(~i));\r
+ return x - *iptr;\r
+ }\r
+ }\r
+}\r
+\r
+//#endif /* _DOUBLE_IS_32BITS */\r