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 if (x >= ((EMACS_INT) 1 << (VALBITS-1))
132 || x <= - ((EMACS_INT) 1 << (VALBITS-1)) - (EMACS_INT) 1)
134 if (!UNBOUNDP (num2))
135 range_error2 (name, num, num2);
137 range_error (name, num);
139 return (make_int ((EMACS_INT) x));
144 in_float_error (void)
152 domain_error2 (float_error_fn_name, float_error_arg, float_error_arg2);
154 domain_error (float_error_fn_name, float_error_arg);
157 range_error (float_error_fn_name, float_error_arg);
160 arith_error (float_error_fn_name, float_error_arg);
167 mark_float (Lisp_Object obj)
173 float_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
175 return (extract_float (obj1) == extract_float (obj2));
179 float_hash (Lisp_Object obj, int depth)
181 /* mod the value down to 32-bit range */
182 /* #### change for 64-bit machines */
183 return (unsigned long) fmod (extract_float (obj), 4e9);
186 static const struct lrecord_description float_description[] = {
190 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("float", float,
191 mark_float, print_float, 0, float_equal,
192 float_hash, float_description,
195 /* Extract a Lisp number as a `double', or signal an error. */
198 extract_float (Lisp_Object num)
201 return XFLOAT_DATA (num);
204 return (double) XINT (num);
206 return extract_float (wrong_type_argument (Qnumberp, num));
208 #endif /* LISP_FLOAT_TYPE */
211 /* Trig functions. */
212 #ifdef LISP_FLOAT_TYPE
214 DEFUN ("acos", Facos, 1, 1, 0, /*
215 Return the inverse cosine of NUMBER.
219 double d = extract_float (number);
220 #ifdef FLOAT_CHECK_DOMAIN
221 if (d > 1.0 || d < -1.0)
222 domain_error ("acos", number);
224 IN_FLOAT (d = acos (d), "acos", number);
225 return make_float (d);
228 DEFUN ("asin", Fasin, 1, 1, 0, /*
229 Return the inverse sine of NUMBER.
233 double d = extract_float (number);
234 #ifdef FLOAT_CHECK_DOMAIN
235 if (d > 1.0 || d < -1.0)
236 domain_error ("asin", number);
238 IN_FLOAT (d = asin (d), "asin", number);
239 return make_float (d);
242 DEFUN ("atan", Fatan, 1, 2, 0, /*
243 Return the inverse tangent of NUMBER.
244 If optional second argument NUMBER2 is provided,
245 return atan2 (NUMBER, NUMBER2).
249 double d = extract_float (number);
252 IN_FLOAT (d = atan (d), "atan", number);
255 double d2 = extract_float (number2);
256 #ifdef FLOAT_CHECK_DOMAIN
257 if (d == 0.0 && d2 == 0.0)
258 domain_error2 ("atan", number, number2);
260 IN_FLOAT2 (d = atan2 (d, d2), "atan", number, number2);
262 return make_float (d);
265 DEFUN ("cos", Fcos, 1, 1, 0, /*
266 Return the cosine of NUMBER.
270 double d = extract_float (number);
271 IN_FLOAT (d = cos (d), "cos", number);
272 return make_float (d);
275 DEFUN ("sin", Fsin, 1, 1, 0, /*
276 Return the sine of NUMBER.
280 double d = extract_float (number);
281 IN_FLOAT (d = sin (d), "sin", number);
282 return make_float (d);
285 DEFUN ("tan", Ftan, 1, 1, 0, /*
286 Return the tangent of NUMBER.
290 double d = extract_float (number);
292 #ifdef FLOAT_CHECK_DOMAIN
294 domain_error ("tan", number);
296 IN_FLOAT (d = (sin (d) / c), "tan", number);
297 return make_float (d);
299 #endif /* LISP_FLOAT_TYPE (trig functions) */
302 /* Bessel functions */
303 #if 0 /* Leave these out unless we find there's a reason for them. */
304 /* #ifdef LISP_FLOAT_TYPE */
306 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /*
307 Return the bessel function j0 of NUMBER.
311 double d = extract_float (number);
312 IN_FLOAT (d = j0 (d), "bessel-j0", number);
313 return make_float (d);
316 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /*
317 Return the bessel function j1 of NUMBER.
321 double d = extract_float (number);
322 IN_FLOAT (d = j1 (d), "bessel-j1", number);
323 return make_float (d);
326 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /*
327 Return the order N bessel function output jn of NUMBER.
328 The first number (the order) is truncated to an integer.
332 int i1 = extract_float (number1);
333 double f2 = extract_float (number2);
335 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", number1);
336 return make_float (f2);
339 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /*
340 Return the bessel function y0 of NUMBER.
344 double d = extract_float (number);
345 IN_FLOAT (d = y0 (d), "bessel-y0", number);
346 return make_float (d);
349 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /*
350 Return the bessel function y1 of NUMBER.
354 double d = extract_float (number);
355 IN_FLOAT (d = y1 (d), "bessel-y0", number);
356 return make_float (d);
359 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /*
360 Return the order N bessel function output yn of NUMBER.
361 The first number (the order) is truncated to an integer.
365 int i1 = extract_float (number1);
366 double f2 = extract_float (number2);
368 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", number1);
369 return make_float (f2);
372 #endif /* 0 (bessel functions) */
374 /* Error functions. */
375 #if 0 /* Leave these out unless we see they are worth having. */
376 /* #ifdef LISP_FLOAT_TYPE */
378 DEFUN ("erf", Ferf, 1, 1, 0, /*
379 Return the mathematical error function of NUMBER.
383 double d = extract_float (number);
384 IN_FLOAT (d = erf (d), "erf", number);
385 return make_float (d);
388 DEFUN ("erfc", Ferfc, 1, 1, 0, /*
389 Return the complementary error function of NUMBER.
393 double d = extract_float (number);
394 IN_FLOAT (d = erfc (d), "erfc", number);
395 return make_float (d);
398 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /*
399 Return the log gamma of NUMBER.
403 double d = extract_float (number);
404 IN_FLOAT (d = lgamma (d), "log-gamma", number);
405 return make_float (d);
408 #endif /* 0 (error functions) */
411 /* Root and Log functions. */
413 #ifdef LISP_FLOAT_TYPE
414 DEFUN ("exp", Fexp, 1, 1, 0, /*
415 Return the exponential base e of NUMBER.
419 double d = extract_float (number);
420 #ifdef FLOAT_CHECK_DOMAIN
421 if (d > 709.7827) /* Assume IEEE doubles here */
422 range_error ("exp", number);
424 return make_float (0.0);
427 IN_FLOAT (d = exp (d), "exp", number);
428 return make_float (d);
430 #endif /* LISP_FLOAT_TYPE */
433 DEFUN ("expt", Fexpt, 2, 2, 0, /*
434 Return the exponential NUMBER1 ** NUMBER2.
438 if (INTP (number1) && /* common lisp spec */
439 INTP (number2)) /* don't promote, if both are ints */
442 EMACS_INT x = XINT (number1);
443 EMACS_INT y = XINT (number2);
450 retval = (y & 1) ? -1 : 1;
462 y = (EMACS_UINT) y >> 1;
465 return make_int (retval);
468 #ifdef LISP_FLOAT_TYPE
470 double f1 = extract_float (number1);
471 double f2 = extract_float (number2);
472 /* Really should check for overflow, too */
473 if (f1 == 0.0 && f2 == 0.0)
475 # ifdef FLOAT_CHECK_DOMAIN
476 else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
477 domain_error2 ("expt", number1, number2);
478 # endif /* FLOAT_CHECK_DOMAIN */
479 IN_FLOAT2 (f1 = pow (f1, f2), "expt", number1, number2);
480 return make_float (f1);
483 CHECK_INT_OR_FLOAT (number1);
484 CHECK_INT_OR_FLOAT (number2);
485 return Fexpt (number1, number2);
486 #endif /* LISP_FLOAT_TYPE */
489 #ifdef LISP_FLOAT_TYPE
490 DEFUN ("log", Flog, 1, 2, 0, /*
491 Return the natural logarithm of NUMBER.
492 If second optional argument BASE is given, return the logarithm of
493 NUMBER using that base.
497 double d = extract_float (number);
498 #ifdef FLOAT_CHECK_DOMAIN
500 domain_error2 ("log", number, base);
503 IN_FLOAT (d = log (d), "log", number);
506 double b = extract_float (base);
507 #ifdef FLOAT_CHECK_DOMAIN
508 if (b <= 0.0 || b == 1.0)
509 domain_error2 ("log", number, base);
512 IN_FLOAT2 (d = log10 (d), "log", number, base);
514 IN_FLOAT2 (d = (log (d) / log (b)), "log", number, base);
516 return make_float (d);
520 DEFUN ("log10", Flog10, 1, 1, 0, /*
521 Return the logarithm base 10 of NUMBER.
525 double d = extract_float (number);
526 #ifdef FLOAT_CHECK_DOMAIN
528 domain_error ("log10", number);
530 IN_FLOAT (d = log10 (d), "log10", number);
531 return make_float (d);
535 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /*
536 Return the square root of NUMBER.
540 double d = extract_float (number);
541 #ifdef FLOAT_CHECK_DOMAIN
543 domain_error ("sqrt", number);
545 IN_FLOAT (d = sqrt (d), "sqrt", number);
546 return make_float (d);
550 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /*
551 Return the cube root of NUMBER.
555 double d = extract_float (number);
557 IN_FLOAT (d = cbrt (d), "cube-root", number);
560 IN_FLOAT (d = pow (d, 1.0/3.0), "cube-root", number);
562 IN_FLOAT (d = -pow (-d, 1.0/3.0), "cube-root", number);
564 return make_float (d);
566 #endif /* LISP_FLOAT_TYPE */
569 /* Inverse trig functions. */
570 #ifdef LISP_FLOAT_TYPE
571 /* #if 0 Not clearly worth adding... */
573 DEFUN ("acosh", Facosh, 1, 1, 0, /*
574 Return the inverse hyperbolic cosine of NUMBER.
578 double d = extract_float (number);
579 #ifdef FLOAT_CHECK_DOMAIN
581 domain_error ("acosh", number);
583 #ifdef HAVE_INVERSE_HYPERBOLIC
584 IN_FLOAT (d = acosh (d), "acosh", number);
586 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", number);
588 return make_float (d);
591 DEFUN ("asinh", Fasinh, 1, 1, 0, /*
592 Return the inverse hyperbolic sine of NUMBER.
596 double d = extract_float (number);
597 #ifdef HAVE_INVERSE_HYPERBOLIC
598 IN_FLOAT (d = asinh (d), "asinh", number);
600 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", number);
602 return make_float (d);
605 DEFUN ("atanh", Fatanh, 1, 1, 0, /*
606 Return the inverse hyperbolic tangent of NUMBER.
610 double d = extract_float (number);
611 #ifdef FLOAT_CHECK_DOMAIN
612 if (d >= 1.0 || d <= -1.0)
613 domain_error ("atanh", number);
615 #ifdef HAVE_INVERSE_HYPERBOLIC
616 IN_FLOAT (d = atanh (d), "atanh", number);
618 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", number);
620 return make_float (d);
623 DEFUN ("cosh", Fcosh, 1, 1, 0, /*
624 Return the hyperbolic cosine of NUMBER.
628 double d = extract_float (number);
629 #ifdef FLOAT_CHECK_DOMAIN
630 if (d > 710.0 || d < -710.0)
631 range_error ("cosh", number);
633 IN_FLOAT (d = cosh (d), "cosh", number);
634 return make_float (d);
637 DEFUN ("sinh", Fsinh, 1, 1, 0, /*
638 Return the hyperbolic sine of NUMBER.
642 double d = extract_float (number);
643 #ifdef FLOAT_CHECK_DOMAIN
644 if (d > 710.0 || d < -710.0)
645 range_error ("sinh", number);
647 IN_FLOAT (d = sinh (d), "sinh", number);
648 return make_float (d);
651 DEFUN ("tanh", Ftanh, 1, 1, 0, /*
652 Return the hyperbolic tangent of NUMBER.
656 double d = extract_float (number);
657 IN_FLOAT (d = tanh (d), "tanh", number);
658 return make_float (d);
660 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */
662 /* Rounding functions */
664 DEFUN ("abs", Fabs, 1, 1, 0, /*
665 Return the absolute value of NUMBER.
669 #ifdef LISP_FLOAT_TYPE
672 IN_FLOAT (number = make_float (fabs (XFLOAT_DATA (number))),
676 #endif /* LISP_FLOAT_TYPE */
679 return (XINT (number) >= 0) ? number : make_int (- XINT (number));
681 return Fabs (wrong_type_argument (Qnumberp, number));
684 #ifdef LISP_FLOAT_TYPE
685 DEFUN ("float", Ffloat, 1, 1, 0, /*
686 Return the floating point number numerically equal to NUMBER.
691 return make_float ((double) XINT (number));
693 if (FLOATP (number)) /* give 'em the same float back */
696 return Ffloat (wrong_type_argument (Qnumberp, number));
698 #endif /* LISP_FLOAT_TYPE */
701 #ifdef LISP_FLOAT_TYPE
702 DEFUN ("logb", Flogb, 1, 1, 0, /*
703 Return largest integer <= the base 2 log of the magnitude of NUMBER.
704 This is the same as the exponent of a float.
708 double f = extract_float (number);
711 return make_int (- (EMACS_INT)(((EMACS_UINT) 1) << (VALBITS - 1))); /* most-negative-fixnum */
715 IN_FLOAT (val = make_int ((EMACS_INT) logb (f)), "logb", number);
722 IN_FLOAT (frexp (f, &exqp), "logb", number);
723 return make_int (exqp - 1);
735 for (i = 1, d = 0.5; d * d >= f; i += i)
742 for (i = 1, d = 2.0; d * d <= f; i += i)
747 return make_int (val);
749 #endif /* ! HAVE_FREXP */
750 #endif /* ! HAVE_LOGB */
752 #endif /* LISP_FLOAT_TYPE */
755 DEFUN ("ceiling", Fceiling, 1, 1, 0, /*
756 Return the smallest integer no less than NUMBER. (Round toward +inf.)
760 #ifdef LISP_FLOAT_TYPE
764 IN_FLOAT ((d = ceil (XFLOAT_DATA (number))), "ceiling", number);
765 return (float_to_int (d, "ceiling", number, Qunbound));
767 #endif /* LISP_FLOAT_TYPE */
772 return Fceiling (wrong_type_argument (Qnumberp, number));
776 DEFUN ("floor", Ffloor, 1, 2, 0, /*
777 Return the largest integer no greater than NUMBER. (Round towards -inf.)
778 With optional second argument DIVISOR, return the largest integer no
779 greater than NUMBER/DIVISOR.
783 CHECK_INT_OR_FLOAT (number);
785 if (! NILP (divisor))
789 CHECK_INT_OR_FLOAT (divisor);
791 #ifdef LISP_FLOAT_TYPE
792 if (FLOATP (number) || FLOATP (divisor))
794 double f1 = extract_float (number);
795 double f2 = extract_float (divisor);
798 Fsignal (Qarith_error, Qnil);
800 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", number, divisor);
801 return float_to_int (f1, "floor", number, divisor);
803 #endif /* LISP_FLOAT_TYPE */
809 Fsignal (Qarith_error, Qnil);
811 /* With C's /, the result is implementation-defined if either operand
812 is negative, so use only nonnegative operands. */
814 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
815 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
817 return (make_int (i1));
820 #ifdef LISP_FLOAT_TYPE
824 IN_FLOAT ((d = floor (XFLOAT_DATA (number))), "floor", number);
825 return (float_to_int (d, "floor", number, Qunbound));
827 #endif /* LISP_FLOAT_TYPE */
832 DEFUN ("round", Fround, 1, 1, 0, /*
833 Return the nearest integer to NUMBER.
837 #ifdef LISP_FLOAT_TYPE
841 /* Screw the prevailing rounding mode. */
842 IN_FLOAT ((d = emacs_rint (XFLOAT_DATA (number))), "round", number);
843 return (float_to_int (d, "round", number, Qunbound));
845 #endif /* LISP_FLOAT_TYPE */
850 return Fround (wrong_type_argument (Qnumberp, number));
853 DEFUN ("truncate", Ftruncate, 1, 1, 0, /*
854 Truncate a floating point number to an integer.
855 Rounds the value toward zero.
859 #ifdef LISP_FLOAT_TYPE
861 return float_to_int (XFLOAT_DATA (number), "truncate", number, Qunbound);
862 #endif /* LISP_FLOAT_TYPE */
867 return Ftruncate (wrong_type_argument (Qnumberp, number));
870 /* Float-rounding functions. */
871 #ifdef LISP_FLOAT_TYPE
872 /* #if 1 It's not clear these are worth adding... */
874 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /*
875 Return the smallest integer no less than NUMBER, as a float.
876 \(Round toward +inf.\)
880 double d = extract_float (number);
881 IN_FLOAT (d = ceil (d), "fceiling", number);
882 return make_float (d);
885 DEFUN ("ffloor", Fffloor, 1, 1, 0, /*
886 Return the largest integer no greater than NUMBER, as a float.
887 \(Round towards -inf.\)
891 double d = extract_float (number);
892 IN_FLOAT (d = floor (d), "ffloor", number);
893 return make_float (d);
896 DEFUN ("fround", Ffround, 1, 1, 0, /*
897 Return the nearest integer to NUMBER, as a float.
901 double d = extract_float (number);
902 IN_FLOAT (d = emacs_rint (d), "fround", number);
903 return make_float (d);
906 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /*
907 Truncate a floating point number to an integral float value.
908 Rounds the value toward zero.
912 double d = extract_float (number);
914 IN_FLOAT (d = floor (d), "ftruncate", number);
916 IN_FLOAT (d = ceil (d), "ftruncate", number);
917 return make_float (d);
920 #endif /* LISP_FLOAT_TYPE (float-rounding functions) */
923 #ifdef LISP_FLOAT_TYPE
924 #ifdef FLOAT_CATCH_SIGILL
926 float_error (int signo)
929 fatal_error_signal (signo);
931 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
932 EMACS_UNBLOCK_SIGNAL (signo);
936 /* Was Fsignal(), but it just doesn't make sense for an error
937 occurring inside a signal handler to be restartable, considering
938 that anything could happen when the error is signaled and trapped
939 and considering the asynchronous nature of signal handlers. */
940 signal_error (Qarith_error, list1 (float_error_arg));
943 /* Another idea was to replace the library function `infnan'
944 where SIGILL is signaled. */
946 #endif /* FLOAT_CATCH_SIGILL */
948 /* In C++, it is impossible to determine what type matherr expects
949 without some more configure magic.
950 We shouldn't be using matherr anyways - it's a non-standard SYSVism. */
951 #if defined (HAVE_MATHERR) && !defined(__cplusplus)
953 matherr (struct exception *x)
957 /* Not called from emacs-lisp float routines; do the default thing. */
960 /* if (!strcmp (x->name, "pow")) x->name = "expt"; */
962 args = Fcons (build_string (x->name),
963 Fcons (make_float (x->arg1),
965 ? Fcons (make_float (x->arg2), Qnil)
969 case DOMAIN: Fsignal (Qdomain_error, args); break;
970 case SING: Fsignal (Qsingularity_error, args); break;
971 case OVERFLOW: Fsignal (Qoverflow_error, args); break;
972 case UNDERFLOW: Fsignal (Qunderflow_error, args); break;
973 default: Fsignal (Qarith_error, args); break;
975 return 1; /* don't set errno or print a message */
977 #endif /* HAVE_MATHERR */
978 #endif /* LISP_FLOAT_TYPE */
982 init_floatfns_very_early (void)
984 #ifdef LISP_FLOAT_TYPE
985 # ifdef FLOAT_CATCH_SIGILL
986 signal (SIGILL, float_error);
989 #endif /* LISP_FLOAT_TYPE */
993 syms_of_floatfns (void)
995 INIT_LRECORD_IMPLEMENTATION (float);
997 /* Trig functions. */
999 #ifdef LISP_FLOAT_TYPE
1006 #endif /* LISP_FLOAT_TYPE */
1008 /* Bessel functions */
1011 DEFSUBR (Fbessel_y0);
1012 DEFSUBR (Fbessel_y1);
1013 DEFSUBR (Fbessel_yn);
1014 DEFSUBR (Fbessel_j0);
1015 DEFSUBR (Fbessel_j1);
1016 DEFSUBR (Fbessel_jn);
1019 /* Error functions. */
1024 DEFSUBR (Flog_gamma);
1027 /* Root and Log functions. */
1029 #ifdef LISP_FLOAT_TYPE
1031 #endif /* LISP_FLOAT_TYPE */
1033 #ifdef LISP_FLOAT_TYPE
1037 DEFSUBR (Fcube_root);
1038 #endif /* LISP_FLOAT_TYPE */
1040 /* Inverse trig functions. */
1042 #ifdef LISP_FLOAT_TYPE
1049 #endif /* LISP_FLOAT_TYPE */
1051 /* Rounding functions */
1054 #ifdef LISP_FLOAT_TYPE
1057 #endif /* LISP_FLOAT_TYPE */
1061 DEFSUBR (Ftruncate);
1063 /* Float-rounding functions. */
1065 #ifdef LISP_FLOAT_TYPE
1066 DEFSUBR (Ffceiling);
1069 DEFSUBR (Fftruncate);
1070 #endif /* LISP_FLOAT_TYPE */
1074 vars_of_floatfns (void)
1076 #ifdef LISP_FLOAT_TYPE
1077 Fprovide (intern ("lisp-float-type"));