Mercurial > hg > xemacs-beta
comparison src/floatfns.c @ 4865:6c0bb4d2c23a
Always use our rint(), for rounding consistency with the bignum code.
ChangeLog addition:
2010-01-16 Aidan Kehoe <kehoea@parhasard.net>
* configure: Regenerate, now we no longer look for rint().
src/ChangeLog addition:
2010-01-16 Aidan Kehoe <kehoea@parhasard.net>
* config.h.in:
* floatfns.c (emacs_rint):
Don't look for rint in configure, always use our own
implementation that rounds to the even number in the case of
ambiguity, for consistency with the bignum code.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 16 Jan 2010 19:04:52 +0000 |
parents | f31c12360354 |
children | 6ef8256a020a 19a72041c5ed |
comparison
equal
deleted
inserted
replaced
4864:a03421eb562b | 4865:6c0bb4d2c23a |
---|---|
24 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, | 24 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, |
25 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh. | 25 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh. |
26 | 26 |
27 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh. | 27 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh. |
28 Define HAVE_CBRT if you have cbrt(). | 28 Define HAVE_CBRT if you have cbrt(). |
29 Define HAVE_RINT if you have rint(). | |
30 If you don't define these, then the appropriate routines will be simulated. | 29 If you don't define these, then the appropriate routines will be simulated. |
31 | 30 |
32 Define HAVE_MATHERR if on a system supporting the SysV matherr() callback. | 31 Define HAVE_MATHERR if on a system supporting the SysV matherr() callback. |
33 (This should happen automatically.) | 32 (This should happen automatically.) |
34 | 33 |
48 #include <config.h> | 47 #include <config.h> |
49 #include "lisp.h" | 48 #include "lisp.h" |
50 #include "syssignal.h" | 49 #include "syssignal.h" |
51 #include "sysfloat.h" | 50 #include "sysfloat.h" |
52 | 51 |
53 /* The code uses emacs_rint, so that it works to undefine HAVE_RINT | 52 /* An implementation of rint that always rounds towards the even number in |
54 if `rint' exists but does not work right. */ | 53 the case of ambiguity. */ |
55 #ifdef HAVE_RINT | |
56 #define emacs_rint rint | |
57 #else | |
58 static double | 54 static double |
59 emacs_rint (double x) | 55 emacs_rint (double x) |
60 { | 56 { |
61 double r = floor (x + 0.5); | 57 double r = floor (x + 0.5); |
62 double diff = fabs (r - x); | 58 double diff = fabs (r - x); |
63 /* Round to even and correct for any roundoff errors. */ | 59 /* Round to even and correct for any roundoff errors. */ |
64 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0))) | 60 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0))) |
65 r += r < x ? 1.0 : -1.0; | 61 r += r < x ? 1.0 : -1.0; |
66 return r; | 62 return r; |
67 } | 63 } |
68 #endif | |
69 | 64 |
70 /* Nonzero while executing in floating point. | 65 /* Nonzero while executing in floating point. |
71 This tells float_error what to do. */ | 66 This tells float_error what to do. */ |
72 static int in_float; | 67 static int in_float; |
73 | 68 |