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 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("float", float,
183 mark_float, print_float, 0, float_equal,
184 float_hash, struct Lisp_Float);
186 /* Extract a Lisp number as a `double', or signal an error. */
189 extract_float (Lisp_Object num)
192 return XFLOAT_DATA (num);
195 return (double) XINT (num);
197 return extract_float (wrong_type_argument (num, Qnumberp));
199 #endif /* LISP_FLOAT_TYPE */
202 /* Trig functions. */
203 #ifdef LISP_FLOAT_TYPE
205 DEFUN ("acos", Facos, 1, 1, 0, /*
206 Return the inverse cosine of ARG.
210 double d = extract_float (arg);
211 #ifdef FLOAT_CHECK_DOMAIN
212 if (d > 1.0 || d < -1.0)
213 domain_error ("acos", arg);
215 IN_FLOAT (d = acos (d), "acos", arg);
216 return make_float (d);
219 DEFUN ("asin", Fasin, 1, 1, 0, /*
220 Return the inverse sine of ARG.
224 double d = extract_float (arg);
225 #ifdef FLOAT_CHECK_DOMAIN
226 if (d > 1.0 || d < -1.0)
227 domain_error ("asin", arg);
229 IN_FLOAT (d = asin (d), "asin", arg);
230 return make_float (d);
233 DEFUN ("atan", Fatan, 1, 2, 0, /*
234 Return the inverse tangent of ARG.
238 double d = extract_float (arg1);
241 IN_FLOAT (d = atan (d), "atan", arg1);
244 double d2 = extract_float (arg2);
245 #ifdef FLOAT_CHECK_DOMAIN
246 if (d == 0.0 && d2 == 0.0)
247 domain_error2 ("atan", arg1, arg2);
249 IN_FLOAT2 (d = atan2 (d, d2), "atan", arg1, arg2);
251 return make_float (d);
254 DEFUN ("cos", Fcos, 1, 1, 0, /*
255 Return the cosine of ARG.
259 double d = extract_float (arg);
260 IN_FLOAT (d = cos (d), "cos", arg);
261 return make_float (d);
264 DEFUN ("sin", Fsin, 1, 1, 0, /*
265 Return the sine of ARG.
269 double d = extract_float (arg);
270 IN_FLOAT (d = sin (d), "sin", arg);
271 return make_float (d);
274 DEFUN ("tan", Ftan, 1, 1, 0, /*
275 Return the tangent of ARG.
279 double d = extract_float (arg);
281 #ifdef FLOAT_CHECK_DOMAIN
283 domain_error ("tan", arg);
285 IN_FLOAT (d = (sin (d) / c), "tan", arg);
286 return make_float (d);
288 #endif /* LISP_FLOAT_TYPE (trig functions) */
291 /* Bessel functions */
292 #if 0 /* Leave these out unless we find there's a reason for them. */
293 /* #ifdef LISP_FLOAT_TYPE */
295 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /*
296 Return the bessel function j0 of ARG.
300 double d = extract_float (arg);
301 IN_FLOAT (d = j0 (d), "bessel-j0", arg);
302 return make_float (d);
305 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /*
306 Return the bessel function j1 of ARG.
310 double d = extract_float (arg);
311 IN_FLOAT (d = j1 (d), "bessel-j1", arg);
312 return make_float (d);
315 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /*
316 Return the order N bessel function output jn of ARG.
317 The first arg (the order) is truncated to an integer.
321 int i1 = extract_float (arg1);
322 double f2 = extract_float (arg2);
324 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", arg1);
325 return make_float (f2);
328 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /*
329 Return the bessel function y0 of ARG.
333 double d = extract_float (arg);
334 IN_FLOAT (d = y0 (d), "bessel-y0", arg);
335 return make_float (d);
338 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /*
339 Return the bessel function y1 of ARG.
343 double d = extract_float (arg);
344 IN_FLOAT (d = y1 (d), "bessel-y0", arg);
345 return make_float (d);
348 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /*
349 Return the order N bessel function output yn of ARG.
350 The first arg (the order) is truncated to an integer.
354 int i1 = extract_float (arg1);
355 double f2 = extract_float (arg2);
357 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", arg1);
358 return make_float (f2);
361 #endif /* 0 (bessel functions) */
363 /* Error functions. */
364 #if 0 /* Leave these out unless we see they are worth having. */
365 /* #ifdef LISP_FLOAT_TYPE */
367 DEFUN ("erf", Ferf, 1, 1, 0, /*
368 Return the mathematical error function of ARG.
372 double d = extract_float (arg);
373 IN_FLOAT (d = erf (d), "erf", arg);
374 return make_float (d);
377 DEFUN ("erfc", Ferfc, 1, 1, 0, /*
378 Return the complementary error function of ARG.
382 double d = extract_float (arg);
383 IN_FLOAT (d = erfc (d), "erfc", arg);
384 return make_float (d);
387 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /*
388 Return the log gamma of ARG.
392 double d = extract_float (arg);
393 IN_FLOAT (d = lgamma (d), "log-gamma", arg);
394 return make_float (d);
397 #endif /* 0 (error functions) */
400 /* Root and Log functions. */
402 #ifdef LISP_FLOAT_TYPE
403 DEFUN ("exp", Fexp, 1, 1, 0, /*
404 Return the exponential base e of ARG.
408 double d = extract_float (arg);
409 #ifdef FLOAT_CHECK_DOMAIN
410 if (d > 709.7827) /* Assume IEEE doubles here */
411 range_error ("exp", arg);
413 return make_float (0.0);
416 IN_FLOAT (d = exp (d), "exp", arg);
417 return make_float (d);
419 #endif /* LISP_FLOAT_TYPE */
422 DEFUN ("expt", Fexpt, 2, 2, 0, /*
423 Return the exponential ARG1 ** ARG2.
427 if (INTP (arg1) && /* common lisp spec */
428 INTP (arg2)) /* don't promote, if both are ints */
431 EMACS_INT x = XINT (arg1);
432 EMACS_INT y = XINT (arg2);
439 retval = (y & 1) ? -1 : 1;
451 y = (EMACS_UINT) y >> 1;
454 return make_int (retval);
457 #ifdef LISP_FLOAT_TYPE
459 double f1 = extract_float (arg1);
460 double f2 = extract_float (arg2);
461 /* Really should check for overflow, too */
462 if (f1 == 0.0 && f2 == 0.0)
464 # ifdef FLOAT_CHECK_DOMAIN
465 else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
466 domain_error2 ("expt", arg1, arg2);
467 # endif /* FLOAT_CHECK_DOMAIN */
468 IN_FLOAT2 (f1 = pow (f1, f2), "expt", arg1, arg2);
469 return make_float (f1);
472 CHECK_INT_OR_FLOAT (arg1);
473 CHECK_INT_OR_FLOAT (arg2);
474 return Fexpt (arg1, arg2);
475 #endif /* LISP_FLOAT_TYPE */
478 #ifdef LISP_FLOAT_TYPE
479 DEFUN ("log", Flog, 1, 2, 0, /*
480 Return the natural logarithm of ARG.
481 If second optional argument BASE is given, return log ARG using that base.
485 double d = extract_float (arg);
486 #ifdef FLOAT_CHECK_DOMAIN
488 domain_error2 ("log", arg, base);
491 IN_FLOAT (d = log (d), "log", arg);
494 double b = extract_float (base);
495 #ifdef FLOAT_CHECK_DOMAIN
496 if (b <= 0.0 || b == 1.0)
497 domain_error2 ("log", arg, base);
500 IN_FLOAT2 (d = log10 (d), "log", arg, base);
502 IN_FLOAT2 (d = (log (d) / log (b)), "log", arg, base);
504 return make_float (d);
508 DEFUN ("log10", Flog10, 1, 1, 0, /*
509 Return the logarithm base 10 of ARG.
513 double d = extract_float (arg);
514 #ifdef FLOAT_CHECK_DOMAIN
516 domain_error ("log10", arg);
518 IN_FLOAT (d = log10 (d), "log10", arg);
519 return make_float (d);
523 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /*
524 Return the square root of ARG.
528 double d = extract_float (arg);
529 #ifdef FLOAT_CHECK_DOMAIN
531 domain_error ("sqrt", arg);
533 IN_FLOAT (d = sqrt (d), "sqrt", arg);
534 return make_float (d);
538 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /*
539 Return the cube root of ARG.
543 double d = extract_float (arg);
545 IN_FLOAT (d = cbrt (d), "cube-root", arg);
548 IN_FLOAT (d = pow (d, 1.0/3.0), "cube-root", arg);
550 IN_FLOAT (d = -pow (-d, 1.0/3.0), "cube-root", arg);
552 return make_float (d);
554 #endif /* LISP_FLOAT_TYPE */
557 /* Inverse trig functions. */
558 #ifdef LISP_FLOAT_TYPE
559 /* #if 0 Not clearly worth adding... */
561 DEFUN ("acosh", Facosh, 1, 1, 0, /*
562 Return the inverse hyperbolic cosine of ARG.
566 double d = extract_float (arg);
567 #ifdef FLOAT_CHECK_DOMAIN
569 domain_error ("acosh", arg);
571 #ifdef HAVE_INVERSE_HYPERBOLIC
572 IN_FLOAT (d = acosh (d), "acosh", arg);
574 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", arg);
576 return make_float (d);
579 DEFUN ("asinh", Fasinh, 1, 1, 0, /*
580 Return the inverse hyperbolic sine of ARG.
584 double d = extract_float (arg);
585 #ifdef HAVE_INVERSE_HYPERBOLIC
586 IN_FLOAT (d = asinh (d), "asinh", arg);
588 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", arg);
590 return make_float (d);
593 DEFUN ("atanh", Fatanh, 1, 1, 0, /*
594 Return the inverse hyperbolic tangent of ARG.
598 double d = extract_float (arg);
599 #ifdef FLOAT_CHECK_DOMAIN
600 if (d >= 1.0 || d <= -1.0)
601 domain_error ("atanh", arg);
603 #ifdef HAVE_INVERSE_HYPERBOLIC
604 IN_FLOAT (d = atanh (d), "atanh", arg);
606 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", arg);
608 return make_float (d);
611 DEFUN ("cosh", Fcosh, 1, 1, 0, /*
612 Return the hyperbolic cosine of ARG.
616 double d = extract_float (arg);
617 #ifdef FLOAT_CHECK_DOMAIN
618 if (d > 710.0 || d < -710.0)
619 range_error ("cosh", arg);
621 IN_FLOAT (d = cosh (d), "cosh", arg);
622 return make_float (d);
625 DEFUN ("sinh", Fsinh, 1, 1, 0, /*
626 Return the hyperbolic sine of ARG.
630 double d = extract_float (arg);
631 #ifdef FLOAT_CHECK_DOMAIN
632 if (d > 710.0 || d < -710.0)
633 range_error ("sinh", arg);
635 IN_FLOAT (d = sinh (d), "sinh", arg);
636 return make_float (d);
639 DEFUN ("tanh", Ftanh, 1, 1, 0, /*
640 Return the hyperbolic tangent of ARG.
644 double d = extract_float (arg);
645 IN_FLOAT (d = tanh (d), "tanh", arg);
646 return make_float (d);
648 #endif /* LISP_FLOAT_TYPE (inverse trig functions) */
650 /* Rounding functions */
652 DEFUN ("abs", Fabs, 1, 1, 0, /*
653 Return the absolute value of ARG.
657 #ifdef LISP_FLOAT_TYPE
660 IN_FLOAT (arg = make_float (fabs (XFLOAT_DATA (arg))),
664 #endif /* LISP_FLOAT_TYPE */
667 return (XINT (arg) >= 0) ? arg : make_int (- XINT (arg));
669 return Fabs (wrong_type_argument (arg, Qnumberp));
672 #ifdef LISP_FLOAT_TYPE
673 DEFUN ("float", Ffloat, 1, 1, 0, /*
674 Return the floating point number equal to ARG.
679 return make_float ((double) XINT (arg));
681 if (FLOATP (arg)) /* give 'em the same float back */
684 return Ffloat (wrong_type_argument (arg, Qnumberp));
686 #endif /* LISP_FLOAT_TYPE */
689 #ifdef LISP_FLOAT_TYPE
690 DEFUN ("logb", Flogb, 1, 1, 0, /*
691 Return largest integer <= the base 2 log of the magnitude of ARG.
692 This is the same as the exponent of a float.
696 double f = extract_float (arg);
699 return make_int (- (int)((((EMACS_UINT) 1) << (VALBITS - 1)))); /* most-negative-fixnum */
703 IN_FLOAT (val = make_int ((int) logb (f)), "logb", arg);
710 IN_FLOAT (frexp (f, &exqp), "logb", arg);
711 return (make_int (exqp - 1));
723 for (i = 1, d = 0.5; d * d >= f; i += i)
730 for (i = 1, d = 2.0; d * d <= f; i += i)
735 return (make_int (val));
737 #endif /* ! HAVE_FREXP */
738 #endif /* ! HAVE_LOGB */
740 #endif /* LISP_FLOAT_TYPE */
743 DEFUN ("ceiling", Fceiling, 1, 1, 0, /*
744 Return the smallest integer no less than ARG. (Round toward +inf.)
748 #ifdef LISP_FLOAT_TYPE
752 IN_FLOAT ((d = ceil (XFLOAT_DATA (arg))), "ceiling", arg);
753 return (float_to_int (d, "ceiling", arg, Qunbound));
755 #endif /* LISP_FLOAT_TYPE */
760 return Fceiling (wrong_type_argument (arg, Qnumberp));
764 DEFUN ("floor", Ffloor, 1, 2, 0, /*
765 Return the largest integer no greater than ARG. (Round towards -inf.)
766 With optional DIVISOR, return the largest integer no greater than ARG/DIVISOR.
770 CHECK_INT_OR_FLOAT (arg);
772 if (! NILP (divisor))
776 CHECK_INT_OR_FLOAT (divisor);
778 #ifdef LISP_FLOAT_TYPE
779 if (FLOATP (arg) || FLOATP (divisor))
781 double f1 = extract_float (arg);
782 double f2 = extract_float (divisor);
785 Fsignal (Qarith_error, Qnil);
787 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", arg, divisor);
788 return float_to_int (f1, "floor", arg, divisor);
790 #endif /* LISP_FLOAT_TYPE */
796 Fsignal (Qarith_error, Qnil);
798 /* With C's /, the result is implementation-defined if either operand
799 is negative, so use only nonnegative operands. */
801 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
802 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
804 return (make_int (i1));
807 #ifdef LISP_FLOAT_TYPE
811 IN_FLOAT ((d = floor (XFLOAT_DATA (arg))), "floor", arg);
812 return (float_to_int (d, "floor", arg, Qunbound));
814 #endif /* LISP_FLOAT_TYPE */
819 DEFUN ("round", Fround, 1, 1, 0, /*
820 Return the nearest integer to ARG.
824 #ifdef LISP_FLOAT_TYPE
828 /* Screw the prevailing rounding mode. */
829 IN_FLOAT ((d = rint (XFLOAT_DATA (arg))), "round", arg);
830 return (float_to_int (d, "round", arg, Qunbound));
832 #endif /* LISP_FLOAT_TYPE */
837 return Fround (wrong_type_argument (arg, Qnumberp));
840 DEFUN ("truncate", Ftruncate, 1, 1, 0, /*
841 Truncate a floating point number to an integer.
842 Rounds the value toward zero.
846 #ifdef LISP_FLOAT_TYPE
848 return float_to_int (XFLOAT_DATA (arg), "truncate", arg, Qunbound);
849 #endif /* LISP_FLOAT_TYPE */
854 return Ftruncate (wrong_type_argument (arg, Qnumberp));
857 /* Float-rounding functions. */
858 #ifdef LISP_FLOAT_TYPE
859 /* #if 1 It's not clear these are worth adding... */
861 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /*
862 Return the smallest integer no less than ARG, as a float.
863 \(Round toward +inf.\)
867 double d = extract_float (arg);
868 IN_FLOAT (d = ceil (d), "fceiling", arg);
869 return make_float (d);
872 DEFUN ("ffloor", Fffloor, 1, 1, 0, /*
873 Return the largest integer no greater than ARG, as a float.
874 \(Round towards -inf.\)
878 double d = extract_float (arg);
879 IN_FLOAT (d = floor (d), "ffloor", arg);
880 return make_float (d);
883 DEFUN ("fround", Ffround, 1, 1, 0, /*
884 Return the nearest integer to ARG, as a float.
888 double d = extract_float (arg);
889 IN_FLOAT (d = rint (d), "fround", arg);
890 return make_float (d);
893 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /*
894 Truncate a floating point number to an integral float value.
895 Rounds the value toward zero.
899 double d = extract_float (arg);
901 IN_FLOAT (d = floor (d), "ftruncate", arg);
903 IN_FLOAT (d = ceil (d), "ftruncate", arg);
904 return make_float (d);
907 #endif /* LISP_FLOAT_TYPE (float-rounding functions) */
910 #ifdef LISP_FLOAT_TYPE
911 #ifdef FLOAT_CATCH_SIGILL
913 float_error (int signo)
916 fatal_error_signal (signo);
918 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
919 EMACS_UNBLOCK_SIGNAL (signo);
923 /* Was Fsignal(), but it just doesn't make sense for an error
924 occurring inside a signal handler to be restartable, considering
925 that anything could happen when the error is signaled and trapped
926 and considering the asynchronous nature of signal handlers. */
927 signal_error (Qarith_error, list1 (float_error_arg));
930 /* Another idea was to replace the library function `infnan'
931 where SIGILL is signaled. */
933 #endif /* FLOAT_CATCH_SIGILL */
935 /* In C++, it is impossible to determine what type matherr expects
936 without some more configure magic.
937 We shouldn't be using matherr anyways - it's a non-standard SYSVism. */
938 #if defined (HAVE_MATHERR) && !defined(__cplusplus)
940 matherr (struct exception *x)
944 /* Not called from emacs-lisp float routines; do the default thing. */
947 /* if (!strcmp (x->name, "pow")) x->name = "expt"; */
949 args = Fcons (build_string (x->name),
950 Fcons (make_float (x->arg1),
952 ? Fcons (make_float (x->arg2), Qnil)
956 case DOMAIN: Fsignal (Qdomain_error, args); break;
957 case SING: Fsignal (Qsingularity_error, args); break;
958 case OVERFLOW: Fsignal (Qoverflow_error, args); break;
959 case UNDERFLOW: Fsignal (Qunderflow_error, args); break;
960 default: Fsignal (Qarith_error, args); break;
962 return 1; /* don't set errno or print a message */
964 #endif /* HAVE_MATHERR */
965 #endif /* LISP_FLOAT_TYPE */
969 init_floatfns_very_early (void)
971 #ifdef LISP_FLOAT_TYPE
972 # ifdef FLOAT_CATCH_SIGILL
973 signal (SIGILL, float_error);
976 #endif /* LISP_FLOAT_TYPE */
980 syms_of_floatfns (void)
983 /* Trig functions. */
985 #ifdef LISP_FLOAT_TYPE
992 #endif /* LISP_FLOAT_TYPE */
994 /* Bessel functions */
997 DEFSUBR (Fbessel_y0);
998 DEFSUBR (Fbessel_y1);
999 DEFSUBR (Fbessel_yn);
1000 DEFSUBR (Fbessel_j0);
1001 DEFSUBR (Fbessel_j1);
1002 DEFSUBR (Fbessel_jn);
1005 /* Error functions. */
1010 DEFSUBR (Flog_gamma);
1013 /* Root and Log functions. */
1015 #ifdef LISP_FLOAT_TYPE
1017 #endif /* LISP_FLOAT_TYPE */
1019 #ifdef LISP_FLOAT_TYPE
1023 DEFSUBR (Fcube_root);
1024 #endif /* LISP_FLOAT_TYPE */
1026 /* Inverse trig functions. */
1028 #ifdef LISP_FLOAT_TYPE
1035 #endif /* LISP_FLOAT_TYPE */
1037 /* Rounding functions */
1040 #ifdef LISP_FLOAT_TYPE
1043 #endif /* LISP_FLOAT_TYPE */
1047 DEFSUBR (Ftruncate);
1049 /* Float-rounding functions. */
1051 #ifdef LISP_FLOAT_TYPE
1052 DEFSUBR (Ffceiling);
1055 DEFSUBR (Fftruncate);
1056 #endif /* LISP_FLOAT_TYPE */
1060 vars_of_floatfns (void)
1062 #ifdef LISP_FLOAT_TYPE
1063 Fprovide (intern ("lisp-float-type"));