diff options
| author | Paul Eggert | 1996-12-30 08:07:51 +0000 |
|---|---|---|
| committer | Paul Eggert | 1996-12-30 08:07:51 +0000 |
| commit | d137ae2faa5be6a2af07e60c103f39264ce3829b (patch) | |
| tree | 85249e63ee2f445d2f9cbc9f5db767f590759cd3 /src | |
| parent | 22a8b81674876a700db26e237270c0fc6c66ae01 (diff) | |
| download | emacs-d137ae2faa5be6a2af07e60c103f39264ce3829b.tar.gz emacs-d137ae2faa5be6a2af07e60c103f39264ce3829b.zip | |
<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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/floatfns.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/floatfns.c b/src/floatfns.c index 87eb1f129aa..452bdc2ea54 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -52,6 +52,20 @@ Boston, MA 02111-1307, USA. */ | |||
| 52 | 52 | ||
| 53 | #ifdef LISP_FLOAT_TYPE | 53 | #ifdef LISP_FLOAT_TYPE |
| 54 | 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 | ||
| 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 |
| @@ -752,7 +766,7 @@ With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR.") | |||
| 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); |
| @@ -791,6 +805,25 @@ With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR.") | |||
| 791 | 805 | ||
| 792 | #ifdef LISP_FLOAT_TYPE | 806 | #ifdef LISP_FLOAT_TYPE |
| 793 | 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 | } | ||
| 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) |