aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert1997-01-28 04:51:45 +0000
committerPaul Eggert1997-01-28 04:51:45 +0000
commitbc1c9d7e6b3c01a54a66617d550a6af6b6d4167d (patch)
treec759662d81ae96bfa2036a9bd19027fe43303a5e /src/data.c
parente1d409fed5ba45d595d35ea1915a06aa1bdc6fef (diff)
downloademacs-bc1c9d7e6b3c01a54a66617d550a6af6b6d4167d.tar.gz
emacs-bc1c9d7e6b3c01a54a66617d550a6af6b6d4167d.zip
(isnan): Define even if LISP_FLOAT_TYPE is not defined, since fmod
might need it. (fmod): Ensure that the magnitude of the result does not exceed that of the divisor, and that the sign of the result does not disagree with that of the dividend. This does not yield a particularly accurate result, but at least it will be in the range promised by fmod.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/data.c b/src/data.c
index 6fac1131eba..96d0a1032e7 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2007,11 +2007,11 @@ arith_driver (code, nargs, args)
2007 return val; 2007 return val;
2008} 2008}
2009 2009
2010#ifdef LISP_FLOAT_TYPE
2011
2012#undef isnan 2010#undef isnan
2013#define isnan(x) ((x) != (x)) 2011#define isnan(x) ((x) != (x))
2014 2012
2013#ifdef LISP_FLOAT_TYPE
2014
2015Lisp_Object 2015Lisp_Object
2016float_arith_driver (accum, argnum, code, nargs, args) 2016float_arith_driver (accum, argnum, code, nargs, args)
2017 double accum; 2017 double accum;
@@ -2141,9 +2141,21 @@ double
2141fmod (f1, f2) 2141fmod (f1, f2)
2142 double f1, f2; 2142 double f1, f2;
2143{ 2143{
2144 double r = f1;
2145
2144 if (f2 < 0.0) 2146 if (f2 < 0.0)
2145 f2 = -f2; 2147 f2 = -f2;
2146 return (f1 - f2 * floor (f1/f2)); 2148
2149 /* If the magnitude of the result exceeds that of the divisor, or
2150 the sign of the result does not agree with that of the dividend,
2151 iterate with the reduced value. This does not yield a
2152 particularly accurate result, but at least it will be in the
2153 range promised by fmod. */
2154 do
2155 r -= f2 * floor (r / f2);
2156 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2157
2158 return r;
2147} 2159}
2148#endif /* ! HAVE_FMOD */ 2160#endif /* ! HAVE_FMOD */
2149 2161