1 /* Primitive operations on floating point for XEmacs Lisp interpreter.
2 Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: FSF 19.30. */
23 /* ANSI C requires only these float functions:
24 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod,
25 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh.
27 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh.
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.
32 Define HAVE_MATHERR if on a system supporting the SysV matherr() callback.
33 (This should happen automatically.)
35 Define FLOAT_CHECK_ERRNO if the float library routines set errno.
36 This has no effect if HAVE_MATHERR is defined.
38 Define FLOAT_CATCH_SIGILL if the float library routines signal SIGILL.
39 (What systems actually do this? Let me know. -jwz)
41 Define FLOAT_CHECK_DOMAIN if the float library doesn't handle errors by
42 either setting errno, or signalling SIGFPE/SIGILL. Otherwise, domain and
43 range checking will happen before calling the float routines. This has
44 no effect if HAVE_MATHERR is defined (since matherr will be called when
45 a domain error occurs).
50 #include "syssignal.h"
52 #ifdef LISP_FLOAT_TYPE
54 /* Need to define a differentiating symbol -- see sysfloat.h */
55 #define THIS_FILENAME floatfns
58 /* The code uses emacs_rint, so that it works to undefine HAVE_RINT
59 if `rint' exists but does not work right. */
61 #define emacs_rint rint
66 double r = floor (x + 0.5);
67 double diff = fabs (r - x);
68 /* Round to even and correct for any roundoff errors. */
69 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0)))
70 r += r < x ? 1.0 : -1.0;
75 /* Nonzero while executing in floating point.
76 This tells float_error what to do. */
79 /* If an argument is out of range for a mathematical function,
80 here is the actual argument value to use in the error message. */
81 static Lisp_Object float_error_arg, float_error_arg2;
82 static const char *float_error_fn_name;
84 /* Evaluate the floating point expression D, recording NUM
85 as the original argument for error messages.
86 D is normally an assignment expression.
87 Handle errors which may result in signals or may set errno.
89 Note that float_error may be declared to return void, so you can't
90 just cast the zero after the colon to (SIGTYPE) to make the types
92 #ifdef FLOAT_CHECK_ERRNO
93 #define IN_FLOAT(d, name, num) \
95 float_error_arg = num; \
96 float_error_fn_name = name; \
97 in_float = 1; errno = 0; (d); in_float = 0; \
98 if (errno != 0) in_float_error (); \
100 #define IN_FLOAT2(d, name, num, num2) \
102 float_error_arg = num; \
103 float_error_arg2 = num2; \
104 float_error_fn_name = name; \
105 in_float = 2; errno = 0; (d); in_float = 0; \
106 if (errno != 0) in_float_error (); \
109 #define IN_FLOAT(d, name, num) (in_float = 1, (d), in_float = 0)
110 #define IN_FLOAT2(d, name, num, num2) (in_float = 2, (d), in_float = 0)
114 #define arith_error(op,arg) \
115 Fsignal (Qarith_error, list2 (build_string (op), arg))
116 #define range_error(op,arg) \
117 Fsignal (Qrange_error, list2 (build_string (op), arg))
118 #define range_error2(op,a1,a2) \
119 Fsignal (Qrange_error, list3 (build_string (op), a1, a2))
120 #define domain_error(op,arg) \
121 Fsignal (Qdomain_error, list2 (build_string (op), arg))
122 #define domain_error2(op,a1,a2) \
123 Fsignal (Qdomain_error, list3 (build_string (op), a1, a2))
126 /* Convert float to Lisp Integer if it fits, else signal a range
127 error using the given arguments. */
129 float_to_int (double x, const char *name, Lisp_Object num, Lisp_Object num2)
131 REGISTER EMACS_INT result = (EMACS_INT) x;
133 if (result > EMACS_INT_MAX || result < EMACS_INT_MIN)
135 if (!UNBOUNDP (num2))
136 range_error2 (name, num, num2);
138 range_error (name, num);
140 return make_int (result);
145 in_float_error (void)
153 domain_error2 (float_error_fn_name, float_error_arg, float_error_arg2);
155 domain_error (float_error_fn_name, float_error_arg);
158 range_error (float_error_fn_name, float_error_arg);
161 arith_error (float_error_fn_name, float_error_arg);
168 mark_float (Lisp_Object obj)
174 float_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
176 return (extract_float (obj1) == extract_float (obj2));
180 float_hash (Lisp_Object obj, int depth)
182 /* mod the value down to 32-bit range */
183 /* #### change for 64-bit machines */
184 return (unsigned long) fmod (extract_float (obj), 4e9);
187 static const struct lrecord_description float_description[] = {
191 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("float", float,
192 mark_float, print_float, 0, float_equal,
193 float_hash, float_description,
196 /* Extract a Lisp number as a `double', or signal an error. */
199 extract_float (Lisp_Object num)
202 return XFLOAT_DATA (num);
205 return (double) XINT (num);
207 return extract_float (wrong_type_argument (Qnumberp, num));
209 #endif /* LISP_FLOAT_TYPE */
212 /* Trig functions. */
213 #ifdef LISP_FLOAT_TYPE
215 DEFUN ("acos", Facos, 1, 1, 0, /*
216 Return the inverse cosine of NUMBER.
220 double d = extract_float (number);
221 #ifdef FLOAT_CHECK_DOMAIN
222 if (d > 1.0 || d < -1.0)
223 domain_error ("acos", number);
225 IN_FLOAT (d = acos (d), "acos", number);
226 return make_float (d);
229 DEFUN ("asin", Fasin, 1, 1, 0, /*
230 Return the inverse sine of NUMBER.
234 double d = extract_float (number);
235 #ifdef FLOAT_CHECK_DOMAIN
236 if (d > 1.0 || d < -1.0)
237 domain_error ("asin", number);
239 IN_FLOAT (d = asin (d), "asin", number);
240 return make_float (d);
243 DEFUN ("atan", Fatan, 1, 2, 0, /*
244 Return the inverse tangent of NUMBER.
245 If optional second argument NUMBER2 is provided,
246 return atan2 (NUMBER, NUMBER2).
250 double d = extract_float (number);
253 IN_FLOAT (d = atan (d), "atan", number);
256 double d2 = extract_float (number2);
257 #ifdef FLOAT_CHECK_DOMAIN
258 if (d == 0.0 && d2 == 0.0)
259 domain_error2 ("atan", number, number2);
261 IN_FLOAT2 (d = atan2 (d, d2), "atan", number, number2);
263 return make_float (d);
266 DEFUN ("cos", Fcos, 1, 1, 0, /*
267 Return the cosine of NUMBER.
271 double d = extract_float (number);
272 IN_FLOAT (d = cos (d), "cos", number);
273 return make_float (d);
276 DEFUN ("sin", Fsin, 1, 1, 0, /*
277 Return the sine of NUMBER.
281 double d = extract_float (number);
282 IN_FLOAT (d = sin (d), "sin", number);
283 return make_float (d);
286 DEFUN ("tan", Ftan, 1, 1, 0, /*
287 Return the tangent of NUMBER.
291 double d = extract_float (number);
293 #ifdef FLOAT_CHECK_DOMAIN
295 domain_error ("tan", number);
297 IN_FLOAT (d = (sin (d) / c), "tan", number);
298 return make_float (d);
300 #endif /* LISP_FLOAT_TYPE (trig functions) */
303 /* Bessel functions */
304 #if 0 /* Leave these out unless we find there's a reason for them. */
305 /* #ifdef LISP_FLOAT_TYPE */
307 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /*
308 Return the bessel function j0 of NUMBER.
312 double d = extract_float (number);
313 IN_FLOAT (d = j0 (d), "bessel-j0", number);
314 return make_float (d);
317 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /*
318 Return the bessel function j1 of NUMBER.
322 double d = extract_float (number);
323 IN_FLOAT (d = j1 (d), "bessel-j1", number);
324 return make_float (d);
327 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /*
328 Return the order N bessel function output jn of NUMBER.
329 The first number (the order) is truncated to an integer.
333 int i1 = extract_float (number1);
334 double f2 = extract_float (number2);
336 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", number1);
337 return make_float (f2);
340 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /*
341 Return the bessel function y0 of NUMBER.
345 double d = extract_float (number);
346 IN_FLOAT (d = y0 (d), "bessel-y0", number);
347 return make_float (d);
350 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /*
351 Return the bessel function y1 of NUMBER.
355 double d = extract_float (number);
356 IN_FLOAT (d = y1 (d), "bessel-y0", number);
357 return make_float (d);
360 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /*
361 Return the order N bessel function output yn of NUMBER.
362 The first number (the order) is truncated to an integer.
366 int i1 = extract_float (number1);
367 double f2 = extract_float (number2);
369 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", number1);
370 return make_float (f2);
373 #endif /* 0 (bessel functions) */
375 /* Error functions. */
376 #if 0 /* Leave these out unless we see they are worth having. */
377 /* #ifdef LISP_FLOAT_TYPE */
379 DEFUN ("erf", Ferf, 1, 1, 0, /*
380 Return the mathematical error function of NUMBER.
384 double d = extract_float (number);
385 IN_FLOAT (d = erf (d), "erf", number);
386 return make_float (d);
389 DEFUN ("erfc", Ferfc, 1, 1, 0, /*
390 Return the complementary error function of NUMBER.
394 double d = extract_float (number);
395 IN_FLOAT (d = erfc (d), "erfc", number);
396 return make_float (d);
399 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /*
400 Return the log gamma of NUMBER.
404 double d = extract_float (number);
405 IN_FLOAT (d = lgamma (d), "log-gamma", number);
406 return make_float (d);
409 #endif /* 0 (error functions) */
412 /* Root and Log functions. */
414 #ifdef LISP_FLOAT_TYPE
415 DEFUN ("exp", Fexp, 1, 1, 0, /*
416 Return the exponential base e of NUMBER.
420 double d = extract_float (number);
421 #ifdef FLOAT_CHECK_DOMAIN
422 if (d > 709.7827) /* Assume IEEE doubles here */
423 range_error ("exp", number);
425 return make_float (0.0);
428 IN_FLOAT (d = exp (d), "exp", number);
429 return make_float (d);
431 #endif /* LISP_FLOAT_TYPE */
434 DEFUN ("expt", Fexpt, 2, 2, 0, /*
435 Return the exponential NUMBER1 ** NUMBER2.
439 if (INTP (number1) && /* common lisp spec */
440 INTP (number2)) /* don't promote, if both are ints */
443 EMACS_INT x = XINT (number1);
444 EMACS_INT y = XINT (number2);
451 retval = (y & 1) ? -1 : 1;
463 y = (EMACS_UINT) y >> 1;
466 return make_int (retval);
469 #ifdef LISP_FLOAT_TYPE
471 double f1 = extract_float (number1);
472 double f2 = extract_float (number2);
473 /* Really should check for overflow, too */
474 if (f1 == 0.0 && f2 == 0.0)
476 # ifdef FLOAT_CHECK_DOMAIN
477 else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
478 domain_error2 ("expt", number1, number2);
479 # endif /* FLOAT_CHECK_DOMAIN */
480 IN_FLOAT2 (f1 = pow (f1, f2), "expt", number1, number2);
481 return make_float (f1);
484 CHECK_INT_OR_FLOAT (number1);
485 CHECK_INT_OR_FLOAT (number2);
486 return Fexpt (number1, number2);
487 #endif /* LISP_FLOAT_TYPE */
490 #ifdef LISP_FLOAT_TYPE
491 DEFUN ("log", Flog, 1, 2, 0, /*
492 Return the natural logarithm of NUMBER.
493 If second optional argument BASE is given, return the logarithm of
494 NUMBER using that base.
498 double d = extract_float (number);
499 #ifdef FLOAT_CHECK_DOMAIN
501 domain_error2 ("log", number, base);
504 IN_FLOAT (d = log (d), "log", number);
507 double b = extract_float (base);
508 #ifdef FLOAT_CHECK_DOMAIN
509 if (b <= 0.0 || b == 1.0)
510 domain_error2 ("log", number, base);
513 IN_FLOAT2 (d = log10 (d), "log", number, base);
515 IN_FLOAT2 (d = (log (d) / log (b)), "log", number, base);
517 return make_float (d);
521 DEFUN ("log10", Flog10, 1, 1, 0, /*
522 Return the logarithm base 10 of NUMBER.
526 double d = extract_float (number);
527 #ifdef FLOAT_CHECK_DOMAIN
529 domain_error ("log10", number);
531 IN_FLOAT (d = log10 (d), "log10", number);
532 return make_float (d);
536 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /*
537 Return the square root of NUMBER.
541 double d = extract_float (number);
542 #ifdef FLOAT_CHECK_DOMAIN
544 domain_error ("sqrt", number);
546 IN_FLOAT (d = sqrt (d), "sqrt", number);
547 return make_float (d);
551 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /*
552 Return the cube root of NUMBER.
556 double d = extract_float (number);
558 IN_FLOAT (d = cbrt (d), "cube-root", number);
561 IN_FLOAT (d = pow (d, 1.0/3.0), "cube-root", number);
563 IN_FLOAT (d = -pow (-d, 1.0/3.0), "cube-root", number);
565 return make_float (d);
567 #endif /* LISP_FLOAT_TYPE */
570 /* Inverse trig functions. */
571 #ifdef LISP_FLOAT_TYPE
572 /* #if 0 Not clearly worth adding... */
574 DEFUN ("acosh", Facosh, 1, 1, 0, /*
575 Return the inverse hyperbolic cosine of NUMBER.
579 double d = extract_float (number);
580 #ifdef FLOAT_CHECK_DOMAIN
582 domain_error ("acosh", number);
584 #ifdef HAVE_INVERSE_HYPERBOLIC
585 IN_FLOAT (d = acosh (d), "acosh", number);
587 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", number);
589 return make_float (d);
592 DEFUN ("asinh", Fasinh, 1, 1, 0, /*
593 Return the inverse hyperbolic sine of NUMBER.
597 double d = extract_float (number);
598 #ifdef HAVE_INVERSE_HYPERBOLIC
599 IN_FLOAT (d = asinh (d), "asinh", number);
601 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", number);
603 return make_float (d);
606 DEFUN ("atanh", Fatanh, 1, 1, 0, /*
607 Return the inverse hyperbolic tangent of NUMBER.
611 double d = extract_float (number);
612 #ifdef FLOAT_CHECK_DOMAIN
613 if (d >= 1.0 || d <= -1.0)
614 domain_error ("atanh", number);
616 #ifdef HAVE_INVERSE_HYPERBOLIC
617 IN_FLOAT (d = atanh (d), "atanh", number);
619 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", number);
621 return make_float (d);
624 DEFUN ("cosh", Fcosh, 1, 1, 0, /*
625 Return the hyperbolic cosine of NUMBER.
629 double d = extract_float (number);
630 #ifdef FLOAT_CHECK_DOMAIN
631 if (d > 710.0 || d < -710.0)
632 range_error ("cosh", number);
634 IN_FLOAT (d = cosh (d), "cosh", number);
635 return make_float (d);
638 DEFUN ("sinh", Fsinh, 1, 1, 0, /*
639 Return the hyperbolic sine of NUMBER.
643 double d = extract_float (number);
644 #ifdef FLOAT_CHECK_DOMAIN
645 if (d > 710.0 || d < -710.0)
646 range_error ("sinh", number);
648 IN_FLOAT (d = sinh (d), "sinh", number);
649 return make_float (d);
652 DEFUN ("tanh", Ftanh, 1, 1, 0, /*
653 Return the hyperbolic tangent of NUMBER.
657 double d = extract_float (number);
658 IN_FLOAT (d = tanh (d), "tanh", number);
659 return make_float (d);
661 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */
663 /* Rounding functions */
665 DEFUN ("abs", Fabs, 1, 1, 0, /*
666 Return the absolute value of NUMBER.
670 #ifdef LISP_FLOAT_TYPE
673 IN_FLOAT (number = make_float (fabs (XFLOAT_DATA (number))),
677 #endif /* LISP_FLOAT_TYPE */
680 return (XINT (number) >= 0) ? number : make_int (- XINT (number));
682 return Fabs (wrong_type_argument (Qnumberp, number));
685 #ifdef LISP_FLOAT_TYPE
686 DEFUN ("float", Ffloat, 1, 1, 0, /*
687 Return the floating point number numerically equal to NUMBER.
692 return make_float ((double) XINT (number));
694 if (FLOATP (number)) /* give 'em the same float back */
697 return Ffloat (wrong_type_argument (Qnumberp, number));
699 #endif /* LISP_FLOAT_TYPE */
702 #ifdef LISP_FLOAT_TYPE
703 DEFUN ("logb", Flogb, 1, 1, 0, /*
704 Return largest integer <= the base 2 log of the magnitude of NUMBER.
705 This is the same as the exponent of a float.
709 double f = extract_float (number);
712 return make_int (EMACS_INT_MIN);
716 IN_FLOAT (val = make_int ((EMACS_INT) logb (f)), "logb", number);
723 IN_FLOAT (frexp (f, &exqp), "logb", number);
724 return make_int (exqp - 1);
736 for (i = 1, d = 0.5; d * d >= f; i += i)
743 for (i = 1, d = 2.0; d * d <= f; i += i)
748 return make_int (val);
750 #endif /* ! HAVE_FREXP */
751 #endif /* ! HAVE_LOGB */
753 #endif /* LISP_FLOAT_TYPE */
756 DEFUN ("ceiling", Fceiling, 1, 1, 0, /*
757 Return the smallest integer no less than NUMBER. (Round toward +inf.)
761 #ifdef LISP_FLOAT_TYPE
765 IN_FLOAT ((d = ceil (XFLOAT_DATA (number))), "ceiling", number);
766 return (float_to_int (d, "ceiling", number, Qunbound));
768 #endif /* LISP_FLOAT_TYPE */
773 return Fceiling (wrong_type_argument (Qnumberp, number));
777 DEFUN ("floor", Ffloor, 1, 2, 0, /*
778 Return the largest integer no greater than NUMBER. (Round towards -inf.)
779 With optional second argument DIVISOR, return the largest integer no
780 greater than NUMBER/DIVISOR.
784 CHECK_INT_OR_FLOAT (number);
786 if (! NILP (divisor))
790 CHECK_INT_OR_FLOAT (divisor);
792 #ifdef LISP_FLOAT_TYPE
793 if (FLOATP (number) || FLOATP (divisor))
795 double f1 = extract_float (number);
796 double f2 = extract_float (divisor);
799 Fsignal (Qarith_error, Qnil);
801 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", number, divisor);
802 return float_to_int (f1, "floor", number, divisor);
804 #endif /* LISP_FLOAT_TYPE */
810 Fsignal (Qarith_error, Qnil);
812 /* With C's /, the result is implementation-defined if either operand
813 is negative, so use only nonnegative operands. */
815 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
816 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
818 return (make_int (i1));
821 #ifdef LISP_FLOAT_TYPE
825 IN_FLOAT ((d = floor (XFLOAT_DATA (number))), "floor", number);
826 return (float_to_int (d, "floor", number, Qunbound));
828 #endif /* LISP_FLOAT_TYPE */
833 DEFUN ("round", Fround, 1, 1, 0, /*
834 Return the nearest integer to NUMBER.
838 #ifdef LISP_FLOAT_TYPE
842 /* Screw the prevailing rounding mode. */
843 IN_FLOAT ((d = emacs_rint (XFLOAT_DATA (number))), "round", number);
844 return (float_to_int (d, "round", number, Qunbound));
846 #endif /* LISP_FLOAT_TYPE */
851 return Fround (wrong_type_argument (Qnumberp, number));
854 DEFUN ("truncate", Ftruncate, 1, 1, 0, /*
855 Truncate a floating point number to an integer.
856 Rounds the value toward zero.
860 #ifdef LISP_FLOAT_TYPE
862 return float_to_int (XFLOAT_DATA (number), "truncate", number, Qunbound);
863 #endif /* LISP_FLOAT_TYPE */
868 return Ftruncate (wrong_type_argument (Qnumberp, number));
871 /* Float-rounding functions. */
872 #ifdef LISP_FLOAT_TYPE
873 /* #if 1 It's not clear these are worth adding... */
875 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /*
876 Return the smallest integer no less than NUMBER, as a float.
877 \(Round toward +inf.\)
881 double d = extract_float (number);
882 IN_FLOAT (d = ceil (d), "fceiling", number);
883 return make_float (d);
886 DEFUN ("ffloor", Fffloor, 1, 1, 0, /*
887 Return the largest integer no greater than NUMBER, as a float.
888 \(Round towards -inf.\)
892 double d = extract_float (number);
893 IN_FLOAT (d = floor (d), "ffloor", number);
894 return make_float (d);
897 DEFUN ("fround", Ffround, 1, 1, 0, /*
898 Return the nearest integer to NUMBER, as a float.
902 double d = extract_float (number);
903 IN_FLOAT (d = emacs_rint (d), "fround", number);
904 return make_float (d);
907 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /*
908 Truncate a floating point number to an integral float value.
909 Rounds the value toward zero.
913 double d = extract_float (number);
915 IN_FLOAT (d = floor (d), "ftruncate", number);
917 IN_FLOAT (d = ceil (d), "ftruncate", number);
918 return make_float (d);
921 #endif /* LISP_FLOAT_TYPE (float-rounding functions) */
924 #ifdef LISP_FLOAT_TYPE
925 #ifdef FLOAT_CATCH_SIGILL
927 float_error (int signo)
930 fatal_error_signal (signo);
932 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
933 EMACS_UNBLOCK_SIGNAL (signo);
937 /* Was Fsignal(), but it just doesn't make sense for an error
938 occurring inside a signal handler to be restartable, considering
939 that anything could happen when the error is signaled and trapped
940 and considering the asynchronous nature of signal handlers. */
941 signal_error (Qarith_error, list1 (float_error_arg));
944 /* Another idea was to replace the library function `infnan'
945 where SIGILL is signaled. */
947 #endif /* FLOAT_CATCH_SIGILL */
949 /* In C++, it is impossible to determine what type matherr expects
950 without some more configure magic.
951 We shouldn't be using matherr anyways - it's a non-standard SYSVism. */
952 #if defined (HAVE_MATHERR) && !defined(__cplusplus)
954 matherr (struct exception *x)
958 /* Not called from emacs-lisp float routines; do the default thing. */
961 /* if (!strcmp (x->name, "pow")) x->name = "expt"; */
963 args = Fcons (build_string (x->name),
964 Fcons (make_float (x->arg1),
966 ? Fcons (make_float (x->arg2), Qnil)
970 case DOMAIN: Fsignal (Qdomain_error, args); break;
971 case SING: Fsignal (Qsingularity_error, args); break;
972 case OVERFLOW: Fsignal (Qoverflow_error, args); break;
973 case UNDERFLOW: Fsignal (Qunderflow_error, args); break;
974 default: Fsignal (Qarith_error, args); break;
976 return 1; /* don't set errno or print a message */
978 #endif /* HAVE_MATHERR */
979 #endif /* LISP_FLOAT_TYPE */
983 init_floatfns_very_early (void)
985 #ifdef LISP_FLOAT_TYPE
986 # ifdef FLOAT_CATCH_SIGILL
987 signal (SIGILL, float_error);
990 #endif /* LISP_FLOAT_TYPE */
994 syms_of_floatfns (void)
996 INIT_LRECORD_IMPLEMENTATION (float);
998 /* Trig functions. */
1000 #ifdef LISP_FLOAT_TYPE
1007 #endif /* LISP_FLOAT_TYPE */
1009 /* Bessel functions */
1012 DEFSUBR (Fbessel_y0);
1013 DEFSUBR (Fbessel_y1);
1014 DEFSUBR (Fbessel_yn);
1015 DEFSUBR (Fbessel_j0);
1016 DEFSUBR (Fbessel_j1);
1017 DEFSUBR (Fbessel_jn);
1020 /* Error functions. */
1025 DEFSUBR (Flog_gamma);
1028 /* Root and Log functions. */
1030 #ifdef LISP_FLOAT_TYPE
1032 #endif /* LISP_FLOAT_TYPE */
1034 #ifdef LISP_FLOAT_TYPE
1038 DEFSUBR (Fcube_root);
1039 #endif /* LISP_FLOAT_TYPE */
1041 /* Inverse trig functions. */
1043 #ifdef LISP_FLOAT_TYPE
1050 #endif /* LISP_FLOAT_TYPE */
1052 /* Rounding functions */
1055 #ifdef LISP_FLOAT_TYPE
1058 #endif /* LISP_FLOAT_TYPE */
1062 DEFSUBR (Ftruncate);
1064 /* Float-rounding functions. */
1066 #ifdef LISP_FLOAT_TYPE
1067 DEFSUBR (Ffceiling);
1070 DEFSUBR (Fftruncate);
1071 #endif /* LISP_FLOAT_TYPE */
1075 vars_of_floatfns (void)
1077 #ifdef LISP_FLOAT_TYPE
1078 Fprovide (intern ("lisp-float-type"));