Mercurial > hg > xemacs-beta
comparison src/floatfns.c @ 430:a5df635868b2 r21-2-23
Import from CVS: tag r21-2-23
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:29:08 +0200 |
parents | 3ecd8885ac67 |
children | 9d177e8d4150 |
comparison
equal
deleted
inserted
replaced
429:8305706cbb93 | 430:a5df635868b2 |
---|---|
53 | 53 |
54 /* Need to define a differentiating symbol -- see sysfloat.h */ | 54 /* Need to define a differentiating symbol -- see sysfloat.h */ |
55 #define THIS_FILENAME floatfns | 55 #define THIS_FILENAME floatfns |
56 #include "sysfloat.h" | 56 #include "sysfloat.h" |
57 | 57 |
58 #ifndef HAVE_RINT | 58 /* The code uses emacs_rint, so that it works to undefine HAVE_RINT |
59 if `rint' exists but does not work right. */ | |
60 #ifdef HAVE_RINT | |
61 #define emacs_rint rint | |
62 #else | |
59 static double | 63 static double |
60 rint (double x) | 64 emacs_rint (double x) |
61 { | 65 { |
62 double r = floor (x + 0.5); | 66 double r = floor (x + 0.5); |
63 double diff = fabs (r - x); | 67 double diff = fabs (r - x); |
64 /* Round to even and correct for any roundoff errors. */ | 68 /* Round to even and correct for any roundoff errors. */ |
65 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0))) | 69 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0))) |
829 #ifdef LISP_FLOAT_TYPE | 833 #ifdef LISP_FLOAT_TYPE |
830 if (FLOATP (arg)) | 834 if (FLOATP (arg)) |
831 { | 835 { |
832 double d; | 836 double d; |
833 /* Screw the prevailing rounding mode. */ | 837 /* Screw the prevailing rounding mode. */ |
834 IN_FLOAT ((d = rint (XFLOAT_DATA (arg))), "round", arg); | 838 IN_FLOAT ((d = emacs_rint (XFLOAT_DATA (arg))), "round", arg); |
835 return (float_to_int (d, "round", arg, Qunbound)); | 839 return (float_to_int (d, "round", arg, Qunbound)); |
836 } | 840 } |
837 #endif /* LISP_FLOAT_TYPE */ | 841 #endif /* LISP_FLOAT_TYPE */ |
838 | 842 |
839 if (INTP (arg)) | 843 if (INTP (arg)) |
889 Return the nearest integer to ARG, as a float. | 893 Return the nearest integer to ARG, as a float. |
890 */ | 894 */ |
891 (arg)) | 895 (arg)) |
892 { | 896 { |
893 double d = extract_float (arg); | 897 double d = extract_float (arg); |
894 IN_FLOAT (d = rint (d), "fround", arg); | 898 IN_FLOAT (d = emacs_rint (d), "fround", arg); |
895 return make_float (d); | 899 return make_float (d); |
896 } | 900 } |
897 | 901 |
898 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /* | 902 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /* |
899 Truncate a floating point number to an integral float value. | 903 Truncate a floating point number to an integral float value. |