comparison src/floatfns.c @ 16786:8907c00c0cc6

<float.h>: Include if STDC_HEADERS. (IEEE_FLOATING_POINT): New symbol. (Ffloor): Test for division by 0 only if ! IEEE_FLOATING_POINT. (fmod_float): New function.
author Paul Eggert <eggert@twinsun.com>
date Mon, 30 Dec 1996 08:07:51 +0000
parents 02044b05d8e0
children bdafa1f28a64
comparison
equal deleted inserted replaced
16785:9ae722ef923e 16786:8907c00c0cc6
49 #include <config.h> 49 #include <config.h>
50 #include "lisp.h" 50 #include "lisp.h"
51 #include "syssignal.h" 51 #include "syssignal.h"
52 52
53 #ifdef LISP_FLOAT_TYPE 53 #ifdef LISP_FLOAT_TYPE
54
55 #if STDC_HEADERS
56 #include <float.h>
57 #endif
58
59 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
60 #ifndef IEEE_FLOATING_POINT
61 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
62 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
63 #define IEEE_FLOATING_POINT 1
64 #else
65 #define IEEE_FLOATING_POINT 0
66 #endif
67 #endif
54 68
55 /* Work around a problem that happens because math.h on hpux 7 69 /* Work around a problem that happens because math.h on hpux 7
56 defines two static variables--which, in Emacs, are not really static, 70 defines two static variables--which, in Emacs, are not really static,
57 because `static' is defined as nothing. The problem is that they are 71 because `static' is defined as nothing. The problem is that they are
58 defined both here and in lread.c. 72 defined both here and in lread.c.
750 { 764 {
751 double f1, f2; 765 double f1, f2;
752 766
753 f1 = FLOATP (arg) ? XFLOAT (arg)->data : XINT (arg); 767 f1 = FLOATP (arg) ? XFLOAT (arg)->data : XINT (arg);
754 f2 = (FLOATP (divisor) ? XFLOAT (divisor)->data : XINT (divisor)); 768 f2 = (FLOATP (divisor) ? XFLOAT (divisor)->data : XINT (divisor));
755 if (f2 == 0) 769 if (! IEEE_FLOATING_POINT && f2 == 0)
756 Fsignal (Qarith_error, Qnil); 770 Fsignal (Qarith_error, Qnil);
757 771
758 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", arg, divisor); 772 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", arg, divisor);
759 FLOAT_TO_INT2 (f1, arg, "floor", arg, divisor); 773 FLOAT_TO_INT2 (f1, arg, "floor", arg, divisor);
760 return arg; 774 return arg;
788 802
789 return arg; 803 return arg;
790 } 804 }
791 805
792 #ifdef LISP_FLOAT_TYPE 806 #ifdef LISP_FLOAT_TYPE
807
808 Lisp_Object
809 fmod_float (x, y)
810 register Lisp_Object x, y;
811 {
812 double f1, f2;
813
814 f1 = FLOATP (x) ? XFLOAT (x)->data : XINT (x);
815 f2 = FLOATP (y) ? XFLOAT (y)->data : XINT (y);
816
817 if (! IEEE_FLOATING_POINT && f2 == 0)
818 Fsignal (Qarith_error, Qnil);
819
820 /* If the "remainder" comes out with the wrong sign, fix it. */
821 IN_FLOAT2 ((f1 = fmod (f1, f2),
822 f1 = (f2 < 0 ? f1 > 0 : f1 < 0) ? f1 + f2 : f1),
823 "mod", x, y);
824 return make_float (f1);
825 }
793 826
794 DEFUN ("round", Fround, Sround, 1, 1, 0, 827 DEFUN ("round", Fround, Sround, 1, 1, 0,
795 "Return the nearest integer to ARG.") 828 "Return the nearest integer to ARG.")
796 (arg) 829 (arg)
797 register Lisp_Object arg; 830 register Lisp_Object arg;