Mercurial > emacs
comparison src/floatfns.c @ 19737:cad2a27d4451
(emacs_rint): Define this,
either as a function or as a macro for rint.
(Fround, Ffround): Use emacs_rint, not rint directly.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 03 Sep 1997 23:01:57 +0000 |
parents | c372b7e6669b |
children | 923e1f635ace |
comparison
equal
deleted
inserted
replaced
19736:ca5e30c4e578 | 19737:cad2a27d4451 |
---|---|
23 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, | 23 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, |
24 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh. | 24 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh. |
25 | 25 |
26 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh. | 26 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh. |
27 Define HAVE_CBRT if you have cbrt. | 27 Define HAVE_CBRT if you have cbrt. |
28 Define HAVE_RINT if you have rint. | 28 Define HAVE_RINT if you have a working rint. |
29 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. |
30 | 30 |
31 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. |
32 (This should happen automatically.) | 32 (This should happen automatically.) |
33 | 33 |
824 EMACS_INT abs_r = r < 0 ? -r : r; | 824 EMACS_INT abs_r = r < 0 ? -r : r; |
825 EMACS_INT abs_r1 = (i2 < 0 ? -i2 : i2) - abs_r; | 825 EMACS_INT abs_r1 = (i2 < 0 ? -i2 : i2) - abs_r; |
826 return q + (abs_r + (q & 1) <= abs_r1 ? 0 : (i2 ^ r) < 0 ? -1 : 1); | 826 return q + (abs_r + (q & 1) <= abs_r1 ? 0 : (i2 ^ r) < 0 ? -1 : 1); |
827 } | 827 } |
828 | 828 |
829 #ifndef HAVE_RINT | 829 /* The code uses emacs_rint, so that it works to undefine HAVE_RINT |
830 if `rint' exists but does not work right. */ | |
831 #ifdef HAVE_RINT | |
832 #define emacs_rint rint | |
833 #else | |
830 static double | 834 static double |
831 rint (d) | 835 emacs_rint (d) |
832 double d; | 836 double d; |
833 { | 837 { |
834 return floor (d + 0.5); | 838 return floor (d + 0.5); |
835 } | 839 } |
836 #endif | 840 #endif |
864 "Return the nearest integer to ARG.\n\ | 868 "Return the nearest integer to ARG.\n\ |
865 With optional DIVISOR, return the nearest integer to ARG/DIVISOR.") | 869 With optional DIVISOR, return the nearest integer to ARG/DIVISOR.") |
866 (arg, divisor) | 870 (arg, divisor) |
867 Lisp_Object arg, divisor; | 871 Lisp_Object arg, divisor; |
868 { | 872 { |
869 return rounding_driver (arg, divisor, rint, round2, "round"); | 873 return rounding_driver (arg, divisor, emacs_rint, round2, "round"); |
870 } | 874 } |
871 | 875 |
872 DEFUN ("truncate", Ftruncate, Struncate, 1, 2, 0, | 876 DEFUN ("truncate", Ftruncate, Struncate, 1, 2, 0, |
873 "Truncate a floating point number to an int.\n\ | 877 "Truncate a floating point number to an int.\n\ |
874 Rounds ARG toward zero.\n\ | 878 Rounds ARG toward zero.\n\ |
929 "Return the nearest integer to ARG, as a float.") | 933 "Return the nearest integer to ARG, as a float.") |
930 (arg) | 934 (arg) |
931 register Lisp_Object arg; | 935 register Lisp_Object arg; |
932 { | 936 { |
933 double d = extract_float (arg); | 937 double d = extract_float (arg); |
934 IN_FLOAT (d = rint (d), "fround", arg); | 938 IN_FLOAT (d = emacs_rint (d), "fround", arg); |
935 return make_float (d); | 939 return make_float (d); |
936 } | 940 } |
937 | 941 |
938 DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0, | 942 DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0, |
939 "Truncate a floating point number to an integral float value.\n\ | 943 "Truncate a floating point number to an integral float value.\n\ |
940 Rounds the value toward zero.") | 944 Rounds the value toward zero.") |
941 (arg) | 945 (arg) |
942 register Lisp_Object arg; | 946 register Lisp_Object arg; |
943 { | 947 { |
944 double d = extract_float (arg); | 948 double d = extract_float (arg); |