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
62 double r = floor (x + 0.5);
63 double diff = fabs (r - x);
64 /* Round to even and correct for any roundoff errors. */
65 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0)))
66 r += r < x ? 1.0 : -1.0;
71 /* Nonzero while executing in floating point.
72 This tells float_error what to do. */
75 /* If an argument is out of range for a mathematical function,
76 here is the actual argument value to use in the error message. */
77 static Lisp_Object float_error_arg, float_error_arg2;
78 static CONST char *float_error_fn_name;
80 /* Evaluate the floating point expression D, recording NUM
81 as the original argument for error messages.
82 D is normally an assignment expression.
83 Handle errors which may result in signals or may set errno.
85 Note that float_error may be declared to return void, so you can't
86 just cast the zero after the colon to (SIGTYPE) to make the types
88 #ifdef FLOAT_CHECK_ERRNO
89 #define IN_FLOAT(d, name, num) \
91 float_error_arg = num; \
92 float_error_fn_name = name; \
93 in_float = 1; errno = 0; (d); in_float = 0; \
94 if (errno != 0) in_float_error (); \
96 #define IN_FLOAT2(d, name, num, num2) \
98 float_error_arg = num; \
99 float_error_arg2 = num2; \
100 float_error_fn_name = name; \
101 in_float = 2; errno = 0; (d); in_float = 0; \
102 if (errno != 0) in_float_error (); \
105 #define IN_FLOAT(d, name, num) (in_float = 1, (d), in_float = 0)
106 #define IN_FLOAT2(d, name, num, num2) (in_float = 2, (d), in_float = 0)
110 #define arith_error(op,arg) \
111 Fsignal (Qarith_error, list2 (build_string ((op)), (arg)))
112 #define range_error(op,arg) \
113 Fsignal (Qrange_error, list2 (build_string ((op)), (arg)))
114 #define range_error2(op,a1,a2) \
115 Fsignal (Qrange_error, list3 (build_string ((op)), (a1), (a2)))
116 #define domain_error(op,arg) \
117 Fsignal (Qdomain_error, list2 (build_string ((op)), (arg)))
118 #define domain_error2(op,a1,a2) \
119 Fsignal (Qdomain_error, list3 (build_string ((op)), (a1), (a2)))
122 /* Convert float to Lisp Integer if it fits, else signal a range
123 error using the given arguments. */
125 float_to_int (double x, CONST char *name, Lisp_Object num, Lisp_Object num2)
127 if (x >= ((EMACS_INT) 1 << (VALBITS-1))
128 || x <= - ((EMACS_INT) 1 << (VALBITS-1)) - (EMACS_INT) 1)
130 if (!UNBOUNDP (num2))
131 range_error2 (name, num, num2);
133 range_error (name, num);
135 return (make_int ((EMACS_INT) x));
140 in_float_error (void)
148 domain_error2 (float_error_fn_name, float_error_arg, float_error_arg2);
150 domain_error (float_error_fn_name, float_error_arg);
153 range_error (float_error_fn_name, float_error_arg);
156 arith_error (float_error_fn_name, float_error_arg);
163 mark_float (Lisp_Object obj, void (*markobj) (Lisp_Object))
169 float_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
171 return (extract_float (obj1) == extract_float (obj2));
175 float_hash (Lisp_Object obj, int depth)
177 /* mod the value down to 32-bit range */
178 /* #### change for 64-bit machines */
179 return (unsigned long) fmod (extract_float (obj), 4e9);
182 static const struct lrecord_description float_description[] = {
186 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("float", float,
187 mark_float, print_float, 0, float_equal,
188 float_hash, float_description,
191 /* Extract a Lisp number as a `double', or signal an error. */
194 extract_float (Lisp_Object num)
197 return XFLOAT_DATA (num);
200 return (double) XINT (num);
202 return extract_float (wrong_type_argument (Qnumberp, num));
204 #endif /* LISP_FLOAT_TYPE */
207 /* Trig functions. */
208 #ifdef LISP_FLOAT_TYPE
210 DEFUN ("acos", Facos, 1, 1, 0, /*
211 Return the inverse cosine of ARG.
215 double d = extract_float (arg);
216 #ifdef FLOAT_CHECK_DOMAIN
217 if (d > 1.0 || d < -1.0)
218 domain_error ("acos", arg);
220 IN_FLOAT (d = acos (d), "acos", arg);
221 return make_float (d);
224 DEFUN ("asin", Fasin, 1, 1, 0, /*
225 Return the inverse sine of ARG.
229 double d = extract_float (arg);
230 #ifdef FLOAT_CHECK_DOMAIN
231 if (d > 1.0 || d < -1.0)
232 domain_error ("asin", arg);
234 IN_FLOAT (d = asin (d), "asin", arg);
235 return make_float (d);
238 DEFUN ("atan", Fatan, 1, 2, 0, /*
239 Return the inverse tangent of ARG.
243 double d = extract_float (arg1);
246 IN_FLOAT (d = atan (d), "atan", arg1);
249 double d2 = extract_float (arg2);
250 #ifdef FLOAT_CHECK_DOMAIN
251 if (d == 0.0 && d2 == 0.0)
252 domain_error2 ("atan", arg1, arg2);
254 IN_FLOAT2 (d = atan2 (d, d2), "atan", arg1, arg2);
256 return make_float (d);
259 DEFUN ("cos", Fcos, 1, 1, 0, /*
260 Return the cosine of ARG.
264 double d = extract_float (arg);
265 IN_FLOAT (d = cos (d), "cos", arg);
266 return make_float (d);
269 DEFUN ("sin", Fsin, 1, 1, 0, /*
270 Return the sine of ARG.
274 double d = extract_float (arg);
275 IN_FLOAT (d = sin (d), "sin", arg);
276 return make_float (d);
279 DEFUN ("tan", Ftan, 1, 1, 0, /*
280 Return the tangent of ARG.
284 double d = extract_float (arg);
286 #ifdef FLOAT_CHECK_DOMAIN
288 domain_error ("tan", arg);
290 IN_FLOAT (d = (sin (d) / c), "tan", arg);
291 return make_float (d);
293 #endif /* LISP_FLOAT_TYPE (trig functions) */
296 /* Bessel functions */
297 #if 0 /* Leave these out unless we find there's a reason for them. */
298 /* #ifdef LISP_FLOAT_TYPE */
300 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /*
301 Return the bessel function j0 of ARG.
305 double d = extract_float (arg);
306 IN_FLOAT (d = j0 (d), "bessel-j0", arg);
307 return make_float (d);
310 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /*
311 Return the bessel function j1 of ARG.
315 double d = extract_float (arg);
316 IN_FLOAT (d = j1 (d), "bessel-j1", arg);
317 return make_float (d);
320 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /*
321 Return the order N bessel function output jn of ARG.
322 The first arg (the order) is truncated to an integer.
326 int i1 = extract_float (arg1);
327 double f2 = extract_float (arg2);
329 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", arg1);
330 return make_float (f2);
333 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /*
334 Return the bessel function y0 of ARG.
338 double d = extract_float (arg);
339 IN_FLOAT (d = y0 (d), "bessel-y0", arg);
340 return make_float (d);
343 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /*
344 Return the bessel function y1 of ARG.
348 double d = extract_float (arg);
349 IN_FLOAT (d = y1 (d), "bessel-y0", arg);
350 return make_float (d);
353 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /*
354 Return the order N bessel function output yn of ARG.
355 The first arg (the order) is truncated to an integer.
359 int i1 = extract_float (arg1);
360 double f2 = extract_float (arg2);
362 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", arg1);
363 return make_float (f2);
366 #endif /* 0 (bessel functions) */
368 /* Error functions. */
369 #if 0 /* Leave these out unless we see they are worth having. */
370 /* #ifdef LISP_FLOAT_TYPE */
372 DEFUN ("erf", Ferf, 1, 1, 0, /*
373 Return the mathematical error function of ARG.
377 double d = extract_float (arg);
378 IN_FLOAT (d = erf (d), "erf", arg);
379 return make_float (d);
382 DEFUN ("erfc", Ferfc, 1, 1, 0, /*
383 Return the complementary error function of ARG.
387 double d = extract_float (arg);
388 IN_FLOAT (d = erfc (d), "erfc", arg);
389 return make_float (d);
392 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /*
393 Return the log gamma of ARG.
397 double d = extract_float (arg);
398 IN_FLOAT (d = lgamma (d), "log-gamma", arg);
399 return make_float (d);
402 #endif /* 0 (error functions) */
405 /* Root and Log functions. */
407 #ifdef LISP_FLOAT_TYPE
408 DEFUN ("exp", Fexp, 1, 1, 0, /*
409 Return the exponential base e of ARG.
413 double d = extract_float (arg);
414 #ifdef FLOAT_CHECK_DOMAIN
415 if (d > 709.7827) /* Assume IEEE doubles here */
416 range_error ("exp", arg);
418 return make_float (0.0);
421 IN_FLOAT (d = exp (d), "exp", arg);
422 return make_float (d);
424 #endif /* LISP_FLOAT_TYPE */
427 DEFUN ("expt", Fexpt, 2, 2, 0, /*
428 Return the exponential ARG1 ** ARG2.
432 if (INTP (arg1) && /* common lisp spec */
433 INTP (arg2)) /* don't promote, if both are ints */
436 EMACS_INT x = XINT (arg1);
437 EMACS_INT y = XINT (arg2);
444 retval = (y & 1) ? -1 : 1;
456 y = (EMACS_UINT) y >> 1;
459 return make_int (retval);
462 #ifdef LISP_FLOAT_TYPE
464 double f1 = extract_float (arg1);
465 double f2 = extract_float (arg2);
466 /* Really should check for overflow, too */
467 if (f1 == 0.0 && f2 == 0.0)
469 # ifdef FLOAT_CHECK_DOMAIN
470 else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
471 domain_error2 ("expt", arg1, arg2);
472 # endif /* FLOAT_CHECK_DOMAIN */
473 IN_FLOAT2 (f1 = pow (f1, f2), "expt", arg1, arg2);
474 return make_float (f1);
477 CHECK_INT_OR_FLOAT (arg1);
478 CHECK_INT_OR_FLOAT (arg2);
479 return Fexpt (arg1, arg2);
480 #endif /* LISP_FLOAT_TYPE */
483 #ifdef LISP_FLOAT_TYPE
484 DEFUN ("log", Flog, 1, 2, 0, /*
485 Return the natural logarithm of ARG.
486 If second optional argument BASE is given, return log ARG using that base.
490 double d = extract_float (arg);
491 #ifdef FLOAT_CHECK_DOMAIN
493 domain_error2 ("log", arg, base);
496 IN_FLOAT (d = log (d), "log", arg);
499 double b = extract_float (base);
500 #ifdef FLOAT_CHECK_DOMAIN
501 if (b <= 0.0 || b == 1.0)
502 domain_error2 ("log", arg, base);
505 IN_FLOAT2 (d = log10 (d), "log", arg, base);
507 IN_FLOAT2 (d = (log (d) / log (b)), "log", arg, base);
509 return make_float (d);
513 DEFUN ("log10", Flog10, 1, 1, 0, /*
514 Return the logarithm base 10 of ARG.
518 double d = extract_float (arg);
519 #ifdef FLOAT_CHECK_DOMAIN
521 domain_error ("log10", arg);
523 IN_FLOAT (d = log10 (d), "log10", arg);
524 return make_float (d);
528 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /*
529 Return the square root of ARG.
533 double d = extract_float (arg);
534 #ifdef FLOAT_CHECK_DOMAIN
536 domain_error ("sqrt", arg);
538 IN_FLOAT (d = sqrt (d), "sqrt", arg);
539 return make_float (d);
543 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /*
544 Return the cube root of ARG.
548 double d = extract_float (arg);
550 IN_FLOAT (d = cbrt (d), "cube-root", arg);
553 IN_FLOAT (d = pow (d, 1.0/3.0), "cube-root", arg);
555 IN_FLOAT (d = -pow (-d, 1.0/3.0), "cube-root", arg);
557 return make_float (d);
559 #endif /* LISP_FLOAT_TYPE */
562 /* Inverse trig functions. */
563 #ifdef LISP_FLOAT_TYPE
564 /* #if 0 Not clearly worth adding... */
566 DEFUN ("acosh", Facosh, 1, 1, 0, /*
567 Return the inverse hyperbolic cosine of ARG.
571 double d = extract_float (arg);
572 #ifdef FLOAT_CHECK_DOMAIN
574 domain_error ("acosh", arg);
576 #ifdef HAVE_INVERSE_HYPERBOLIC
577 IN_FLOAT (d = acosh (d), "acosh", arg);
579 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", arg);
581 return make_float (d);
584 DEFUN ("asinh", Fasinh, 1, 1, 0, /*
585 Return the inverse hyperbolic sine of ARG.
589 double d = extract_float (arg);
590 #ifdef HAVE_INVERSE_HYPERBOLIC
591 IN_FLOAT (d = asinh (d), "asinh", arg);
593 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", arg);
595 return make_float (d);
598 DEFUN ("atanh", Fatanh, 1, 1, 0, /*
599 Return the inverse hyperbolic tangent of ARG.
603 double d = extract_float (arg);
604 #ifdef FLOAT_CHECK_DOMAIN
605 if (d >= 1.0 || d <= -1.0)
606 domain_error ("atanh", arg);
608 #ifdef HAVE_INVERSE_HYPERBOLIC
609 IN_FLOAT (d = atanh (d), "atanh", arg);
611 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", arg);
613 return make_float (d);
616 DEFUN ("cosh", Fcosh, 1, 1, 0, /*
617 Return the hyperbolic cosine of ARG.
621 double d = extract_float (arg);
622 #ifdef FLOAT_CHECK_DOMAIN
623 if (d > 710.0 || d < -710.0)
624 range_error ("cosh", arg);
626 IN_FLOAT (d = cosh (d), "cosh", arg);
627 return make_float (d);
630 DEFUN ("sinh", Fsinh, 1, 1, 0, /*
631 Return the hyperbolic sine of ARG.
635 double d = extract_float (arg);
636 #ifdef FLOAT_CHECK_DOMAIN
637 if (d > 710.0 || d < -710.0)
638 range_error ("sinh", arg);
640 IN_FLOAT (d = sinh (d), "sinh", arg);
641 return make_float (d);
644 DEFUN ("tanh", Ftanh, 1, 1, 0, /*
645 Return the hyperbolic tangent of ARG.
649 double d = extract_float (arg);
650 IN_FLOAT (d = tanh (d), "tanh", arg);
651 return make_float (d);
653 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */
655 /* Rounding functions */
657 DEFUN ("abs", Fabs, 1, 1, 0, /*
658 Return the absolute value of ARG.
662 #ifdef LISP_FLOAT_TYPE
665 IN_FLOAT (arg = make_float (fabs (XFLOAT_DATA (arg))),
669 #endif /* LISP_FLOAT_TYPE */
672 return (XINT (arg) >= 0) ? arg : make_int (- XINT (arg));
674 return Fabs (wrong_type_argument (Qnumberp, arg));
677 #ifdef LISP_FLOAT_TYPE
678 DEFUN ("float", Ffloat, 1, 1, 0, /*
679 Return the floating point number numerically equal to ARG.
684 return make_float ((double) XINT (arg));
686 if (FLOATP (arg)) /* give 'em the same float back */
689 return Ffloat (wrong_type_argument (Qnumberp, arg));
691 #endif /* LISP_FLOAT_TYPE */
694 #ifdef LISP_FLOAT_TYPE
695 DEFUN ("logb", Flogb, 1, 1, 0, /*
696 Return largest integer <= the base 2 log of the magnitude of ARG.
697 This is the same as the exponent of a float.
701 double f = extract_float (arg);
704 return make_int (- (int)((((EMACS_UINT) 1) << (VALBITS - 1)))); /* most-negative-fixnum */
708 IN_FLOAT (val = make_int ((int) logb (f)), "logb", arg);
715 IN_FLOAT (frexp (f, &exqp), "logb", arg);
716 return (make_int (exqp - 1));
728 for (i = 1, d = 0.5; d * d >= f; i += i)
735 for (i = 1, d = 2.0; d * d <= f; i += i)
740 return (make_int (val));
742 #endif /* ! HAVE_FREXP */
743 #endif /* ! HAVE_LOGB */
745 #endif /* LISP_FLOAT_TYPE */
748 DEFUN ("ceiling", Fceiling, 1, 1, 0, /*
749 Return the smallest integer no less than ARG. (Round toward +inf.)
753 #ifdef LISP_FLOAT_TYPE
757 IN_FLOAT ((d = ceil (XFLOAT_DATA (arg))), "ceiling", arg);
758 return (float_to_int (d, "ceiling", arg, Qunbound));
760 #endif /* LISP_FLOAT_TYPE */
765 return Fceiling (wrong_type_argument (Qnumberp, arg));
769 DEFUN ("floor", Ffloor, 1, 2, 0, /*
770 Return the largest integer no greater than ARG. (Round towards -inf.)
771 With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR.
775 CHECK_INT_OR_FLOAT (arg);
777 if (! NILP (divisor))
781 CHECK_INT_OR_FLOAT (divisor);
783 #ifdef LISP_FLOAT_TYPE
784 if (FLOATP (arg) || FLOATP (divisor))
786 double f1 = extract_float (arg);
787 double f2 = extract_float (divisor);
790 Fsignal (Qarith_error, Qnil);
792 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", arg, divisor);
793 return float_to_int (f1, "floor", arg, divisor);
795 #endif /* LISP_FLOAT_TYPE */
801 Fsignal (Qarith_error, Qnil);
803 /* With C's /, the result is implementation-defined if either operand
804 is negative, so use only nonnegative operands. */
806 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
807 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
809 return (make_int (i1));
812 #ifdef LISP_FLOAT_TYPE
816 IN_FLOAT ((d = floor (XFLOAT_DATA (arg))), "floor", arg);
817 return (float_to_int (d, "floor", arg, Qunbound));
819 #endif /* LISP_FLOAT_TYPE */
824 DEFUN ("round", Fround, 1, 1, 0, /*
825 Return the nearest integer to ARG.
829 #ifdef LISP_FLOAT_TYPE
833 /* Screw the prevailing rounding mode. */
834 IN_FLOAT ((d = rint (XFLOAT_DATA (arg))), "round", arg);
835 return (float_to_int (d, "round", arg, Qunbound));
837 #endif /* LISP_FLOAT_TYPE */
842 return Fround (wrong_type_argument (Qnumberp, arg));
845 DEFUN ("truncate", Ftruncate, 1, 1, 0, /*
846 Truncate a floating point number to an integer.
847 Rounds the value toward zero.
851 #ifdef LISP_FLOAT_TYPE
853 return float_to_int (XFLOAT_DATA (arg), "truncate", arg, Qunbound);
854 #endif /* LISP_FLOAT_TYPE */
859 return Ftruncate (wrong_type_argument (Qnumberp, arg));
862 /* Float-rounding functions. */
863 #ifdef LISP_FLOAT_TYPE
864 /* #if 1 It's not clear these are worth adding... */
866 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /*
867 Return the smallest integer no less than ARG, as a float.
868 \(Round toward +inf.\)
872 double d = extract_float (arg);
873 IN_FLOAT (d = ceil (d), "fceiling", arg);
874 return make_float (d);
877 DEFUN ("ffloor", Fffloor, 1, 1, 0, /*
878 Return the largest integer no greater than ARG, as a float.
879 \(Round towards -inf.\)
883 double d = extract_float (arg);
884 IN_FLOAT (d = floor (d), "ffloor", arg);
885 return make_float (d);
888 DEFUN ("fround", Ffround, 1, 1, 0, /*
889 Return the nearest integer to ARG, as a float.
893 double d = extract_float (arg);
894 IN_FLOAT (d = rint (d), "fround", arg);
895 return make_float (d);
898 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /*
899 Truncate a floating point number to an integral float value.
900 Rounds the value toward zero.
904 double d = extract_float (arg);
906 IN_FLOAT (d = floor (d), "ftruncate", arg);
908 IN_FLOAT (d = ceil (d), "ftruncate", arg);
909 return make_float (d);
912 #endif /* LISP_FLOAT_TYPE (float-rounding functions) */
915 #ifdef LISP_FLOAT_TYPE
916 #ifdef FLOAT_CATCH_SIGILL
918 float_error (int signo)
921 fatal_error_signal (signo);
923 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
924 EMACS_UNBLOCK_SIGNAL (signo);
928 /* Was Fsignal(), but it just doesn't make sense for an error
929 occurring inside a signal handler to be restartable, considering
930 that anything could happen when the error is signaled and trapped
931 and considering the asynchronous nature of signal handlers. */
932 signal_error (Qarith_error, list1 (float_error_arg));
935 /* Another idea was to replace the library function `infnan'
936 where SIGILL is signaled. */
938 #endif /* FLOAT_CATCH_SIGILL */
940 /* In C++, it is impossible to determine what type matherr expects
941 without some more configure magic.
942 We shouldn't be using matherr anyways - it's a non-standard SYSVism. */
943 #if defined (HAVE_MATHERR) && !defined(__cplusplus)
945 matherr (struct exception *x)
949 /* Not called from emacs-lisp float routines; do the default thing. */
952 /* if (!strcmp (x->name, "pow")) x->name = "expt"; */
954 args = Fcons (build_string (x->name),
955 Fcons (make_float (x->arg1),
957 ? Fcons (make_float (x->arg2), Qnil)
961 case DOMAIN: Fsignal (Qdomain_error, args); break;
962 case SING: Fsignal (Qsingularity_error, args); break;
963 case OVERFLOW: Fsignal (Qoverflow_error, args); break;
964 case UNDERFLOW: Fsignal (Qunderflow_error, args); break;
965 default: Fsignal (Qarith_error, args); break;
967 return 1; /* don't set errno or print a message */
969 #endif /* HAVE_MATHERR */
970 #endif /* LISP_FLOAT_TYPE */
974 init_floatfns_very_early (void)
976 #ifdef LISP_FLOAT_TYPE
977 # ifdef FLOAT_CATCH_SIGILL
978 signal (SIGILL, float_error);
981 #endif /* LISP_FLOAT_TYPE */
985 syms_of_floatfns (void)
988 /* Trig functions. */
990 #ifdef LISP_FLOAT_TYPE
997 #endif /* LISP_FLOAT_TYPE */
999 /* Bessel functions */
1002 DEFSUBR (Fbessel_y0);
1003 DEFSUBR (Fbessel_y1);
1004 DEFSUBR (Fbessel_yn);
1005 DEFSUBR (Fbessel_j0);
1006 DEFSUBR (Fbessel_j1);
1007 DEFSUBR (Fbessel_jn);
1010 /* Error functions. */
1015 DEFSUBR (Flog_gamma);
1018 /* Root and Log functions. */
1020 #ifdef LISP_FLOAT_TYPE
1022 #endif /* LISP_FLOAT_TYPE */
1024 #ifdef LISP_FLOAT_TYPE
1028 DEFSUBR (Fcube_root);
1029 #endif /* LISP_FLOAT_TYPE */
1031 /* Inverse trig functions. */
1033 #ifdef LISP_FLOAT_TYPE
1040 #endif /* LISP_FLOAT_TYPE */
1042 /* Rounding functions */
1045 #ifdef LISP_FLOAT_TYPE
1048 #endif /* LISP_FLOAT_TYPE */
1052 DEFSUBR (Ftruncate);
1054 /* Float-rounding functions. */
1056 #ifdef LISP_FLOAT_TYPE
1057 DEFSUBR (Ffceiling);
1060 DEFSUBR (Fftruncate);
1061 #endif /* LISP_FLOAT_TYPE */
1065 vars_of_floatfns (void)
1067 #ifdef LISP_FLOAT_TYPE
1068 Fprovide (intern ("lisp-float-type"));