annotate src/floatfns.c @ 2114:2e4be8dd02fc

[xemacs-hg @ 2004-06-06 12:35:44 by malcolmp] extw-Xt.c (_XT_WAIT_FOR_SOMETHING): Fix: complete macro renaming: #define.
author malcolmp
date Sun, 06 Jun 2004 12:35:45 +0000
parents f557693c61de
children 04bc9d2f42c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Primitive operations on floating point for XEmacs Lisp interpreter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* ANSI C requires only these float functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 Define HAVE_INVERSE_HYPERBOLIC if you have acosh, asinh, and atanh.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 Define HAVE_CBRT if you have cbrt().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 Define HAVE_RINT if you have rint().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 If you don't define these, then the appropriate routines will be simulated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 Define HAVE_MATHERR if on a system supporting the SysV matherr() callback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 (This should happen automatically.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Define FLOAT_CHECK_ERRNO if the float library routines set errno.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 This has no effect if HAVE_MATHERR is defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Define FLOAT_CATCH_SIGILL if the float library routines signal SIGILL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 (What systems actually do this? Let me know. -jwz)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 Define FLOAT_CHECK_DOMAIN if the float library doesn't handle errors by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 either setting errno, or signalling SIGFPE/SIGILL. Otherwise, domain and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 range checking will happen before calling the float routines. This has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 no effect if HAVE_MATHERR is defined (since matherr will be called when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 a domain error occurs).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "sysfloat.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
53 /* The code uses emacs_rint, so that it works to undefine HAVE_RINT
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
54 if `rint' exists but does not work right. */
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
55 #ifdef HAVE_RINT
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
56 #define emacs_rint rint
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
57 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 static double
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
59 emacs_rint (double x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 double r = floor (x + 0.5);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 double diff = fabs (r - x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 /* Round to even and correct for any roundoff errors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 if (diff >= 0.5 && (diff > 0.5 || r != 2.0 * floor (r / 2.0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 r += r < x ? 1.0 : -1.0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 return r;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 /* Nonzero while executing in floating point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 This tells float_error what to do. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 static int in_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 /* If an argument is out of range for a mathematical function,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 here is the actual argument value to use in the error message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 static Lisp_Object float_error_arg, float_error_arg2;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
77 static const char *float_error_fn_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 /* Evaluate the floating point expression D, recording NUM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 as the original argument for error messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 D is normally an assignment expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 Handle errors which may result in signals or may set errno.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 Note that float_error may be declared to return void, so you can't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 just cast the zero after the colon to (SIGTYPE) to make the types
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 check properly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #ifdef FLOAT_CHECK_ERRNO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #define IN_FLOAT(d, name, num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 float_error_arg = num; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 float_error_fn_name = name; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 in_float = 1; errno = 0; (d); in_float = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 if (errno != 0) in_float_error (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #define IN_FLOAT2(d, name, num, num2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 float_error_arg = num; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 float_error_arg2 = num2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 float_error_fn_name = name; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 in_float = 2; errno = 0; (d); in_float = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 if (errno != 0) in_float_error (); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #define IN_FLOAT(d, name, num) (in_float = 1, (d), in_float = 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 #define IN_FLOAT2(d, name, num, num2) (in_float = 2, (d), in_float = 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #define arith_error(op,arg) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
110 Fsignal (Qarith_error, list2 (build_msg_string (op), arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #define range_error(op,arg) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
112 Fsignal (Qrange_error, list2 (build_msg_string (op), arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #define range_error2(op,a1,a2) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
114 Fsignal (Qrange_error, list3 (build_msg_string (op), a1, a2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #define domain_error(op,arg) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
116 Fsignal (Qdomain_error, list2 (build_msg_string (op), arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #define domain_error2(op,a1,a2) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
118 Fsignal (Qdomain_error, list3 (build_msg_string (op), a1, a2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 /* Convert float to Lisp Integer if it fits, else signal a range
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
122 error using the given arguments. If bignums are available, range errors
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
123 are never signaled. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
125 float_to_int (double x, const char *name, Lisp_Object num, Lisp_Object num2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
127 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
128 bignum_set_double (scratch_bignum, x);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
129 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
130 #else
2039
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
131 REGISTER EMACS_INT result = (EMACS_INT) x;
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
132
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
133 if (result > EMACS_INT_MAX || result < EMACS_INT_MIN)
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
134 {
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
135 if (!UNBOUNDP (num2))
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
136 range_error2 (name, num, num2);
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
137 else
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
138 range_error (name, num);
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
139 }
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
140 return make_int (result);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
141 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 in_float_error (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 switch (errno)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 case EDOM:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 if (in_float == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 domain_error2 (float_error_fn_name, float_error_arg, float_error_arg2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 domain_error (float_error_fn_name, float_error_arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 case ERANGE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 range_error (float_error_fn_name, float_error_arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 arith_error (float_error_fn_name, float_error_arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 mark_float (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 float_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 return (extract_float (obj1) == extract_float (obj2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
180 static Hashcode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 float_hash (Lisp_Object obj, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 /* mod the value down to 32-bit range */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 /* #### change for 64-bit machines */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 return (unsigned long) fmod (extract_float (obj), 4e9);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
188 static const struct memory_description float_description[] = {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 771
diff changeset
192 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("float", float,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 771
diff changeset
193 1, /*dumpable-flag*/
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 771
diff changeset
194 mark_float, print_float, 0, float_equal,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 771
diff changeset
195 float_hash, float_description,
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 771
diff changeset
196 Lisp_Float);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 /* Extract a Lisp number as a `double', or signal an error. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 extract_float (Lisp_Object num)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 if (FLOATP (num))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 return XFLOAT_DATA (num);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 if (INTP (num))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 return (double) XINT (num);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
209 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
210 if (BIGNUMP (num))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
211 return bignum_to_double (XBIGNUM_DATA (num));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
212 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
213
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
214 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
215 if (RATIOP (num))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
216 return ratio_to_double (XRATIO_DATA (num));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
217 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
218
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
219 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
220 if (BIGFLOATP (num))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
221 return bigfloat_to_double (XBIGFLOAT_DATA (num));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
222 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
223
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 return extract_float (wrong_type_argument (Qnumberp, num));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* Trig functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 DEFUN ("acos", Facos, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
230 Return the inverse cosine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
232 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
234 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (d > 1.0 || d < -1.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
237 domain_error ("acos", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
239 IN_FLOAT (d = acos (d), "acos", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 DEFUN ("asin", Fasin, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
244 Return the inverse sine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
246 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
248 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 if (d > 1.0 || d < -1.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
251 domain_error ("asin", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
253 IN_FLOAT (d = asin (d), "asin", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 DEFUN ("atan", Fatan, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
258 Return the inverse tangent of NUMBER.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
259 If optional second argument NUMBER2 is provided,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
260 return atan2 (NUMBER, NUMBER2).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
262 (number, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
264 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
266 if (NILP (number2))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
267 IN_FLOAT (d = atan (d), "atan", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
270 double d2 = extract_float (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 if (d == 0.0 && d2 == 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
273 domain_error2 ("atan", number, number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
275 IN_FLOAT2 (d = atan2 (d, d2), "atan", number, number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 DEFUN ("cos", Fcos, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
281 Return the cosine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
283 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
285 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
286 IN_FLOAT (d = cos (d), "cos", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 DEFUN ("sin", Fsin, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
291 Return the sine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
293 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
295 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
296 IN_FLOAT (d = sin (d), "sin", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 DEFUN ("tan", Ftan, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
301 Return the tangent of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
303 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
305 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 double c = cos (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 if (c == 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
309 domain_error ("tan", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
311 IN_FLOAT (d = (sin (d) / c), "tan", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 /* Bessel functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 #if 0 /* Leave these out unless we find there's a reason for them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 DEFUN ("bessel-j0", Fbessel_j0, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
319 Return the bessel function j0 of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
321 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
323 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
324 IN_FLOAT (d = j0 (d), "bessel-j0", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 DEFUN ("bessel-j1", Fbessel_j1, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
329 Return the bessel function j1 of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
331 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
333 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
334 IN_FLOAT (d = j1 (d), "bessel-j1", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 DEFUN ("bessel-jn", Fbessel_jn, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
339 Return the order N bessel function output jn of NUMBER.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
340 The first number (the order) is truncated to an integer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
342 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
344 int i1 = extract_float (number1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
345 double f2 = extract_float (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
347 IN_FLOAT (f2 = jn (i1, f2), "bessel-jn", number1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 return make_float (f2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 DEFUN ("bessel-y0", Fbessel_y0, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
352 Return the bessel function y0 of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
354 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
356 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
357 IN_FLOAT (d = y0 (d), "bessel-y0", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 DEFUN ("bessel-y1", Fbessel_y1, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
362 Return the bessel function y1 of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
364 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
366 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
367 IN_FLOAT (d = y1 (d), "bessel-y0", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 DEFUN ("bessel-yn", Fbessel_yn, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
372 Return the order N bessel function output yn of NUMBER.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
373 The first number (the order) is truncated to an integer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
375 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
377 int i1 = extract_float (number1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
378 double f2 = extract_float (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
380 IN_FLOAT (f2 = yn (i1, f2), "bessel-yn", number1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 return make_float (f2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 #endif /* 0 (bessel functions) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 /* Error functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 #if 0 /* Leave these out unless we see they are worth having. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 DEFUN ("erf", Ferf, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
390 Return the mathematical error function of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
392 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
394 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
395 IN_FLOAT (d = erf (d), "erf", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 DEFUN ("erfc", Ferfc, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
400 Return the complementary error function of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
402 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
404 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
405 IN_FLOAT (d = erfc (d), "erfc", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 DEFUN ("log-gamma", Flog_gamma, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
410 Return the log gamma of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
412 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
414 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
415 IN_FLOAT (d = lgamma (d), "log-gamma", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 #endif /* 0 (error functions) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 /* Root and Log functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 DEFUN ("exp", Fexp, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
425 Return the exponential base e of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
427 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
429 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 if (d > 709.7827) /* Assume IEEE doubles here */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
432 range_error ("exp", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 else if (d < -709.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 return make_float (0.0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
437 IN_FLOAT (d = exp (d), "exp", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 DEFUN ("expt", Fexpt, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442 Return the exponential NUMBER1 ** NUMBER2.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
444 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
446 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
447 if (INTEGERP (number1) && INTP (number2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
448 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
449 if (INTP (number1))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
450 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
451 bignum_set_long (scratch_bignum2, XREALINT (number1));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
452 bignum_pow (scratch_bignum, scratch_bignum2, XREALINT (number2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
453 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
454 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
455 bignum_pow (scratch_bignum, XBIGNUM_DATA (number1),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
456 XREALINT (number2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
457 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
458 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
459 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
460
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
461 if (INTP (number1) && /* common lisp spec */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
462 INTP (number2)) /* don't promote, if both are ints */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 EMACS_INT retval;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
465 EMACS_INT x = XINT (number1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
466 EMACS_INT y = XINT (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 if (y < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 if (x == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 retval = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 else if (x == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 retval = (y & 1) ? -1 : 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 retval = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 retval = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 while (y > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 if (y & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 retval *= x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 x *= x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 y = (EMACS_UINT) y >> 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 return make_int (retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
491 #if defined(HAVE_BIGFLOAT) && defined(bigfloat_pow)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
492 if (BIGFLOATP (number1) && INTEGERP (number2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
493 {
2057
471242c84954 [xemacs-hg @ 2004-05-03 15:19:10 by james]
james
parents: 2039
diff changeset
494 unsigned long exponent;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
495
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
496 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
497 if (BIGNUMP (number2))
2057
471242c84954 [xemacs-hg @ 2004-05-03 15:19:10 by james]
james
parents: 2039
diff changeset
498 exponent = bignum_to_ulong (XBIGNUM_DATA (number2));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
499 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
500 #endif
2057
471242c84954 [xemacs-hg @ 2004-05-03 15:19:10 by james]
james
parents: 2039
diff changeset
501 exponent = XUINT (number2);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
502 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number1));
2057
471242c84954 [xemacs-hg @ 2004-05-03 15:19:10 by james]
james
parents: 2039
diff changeset
503 bigfloat_pow (scratch_bigfloat, XBIGFLOAT_DATA (number1), exponent);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
504 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
505 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
506 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
507
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
509 double f1 = extract_float (number1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
510 double f2 = extract_float (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 /* Really should check for overflow, too */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 if (f1 == 0.0 && f2 == 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 f1 = 1.0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 # ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 else if ((f1 == 0.0 && f2 < 0.0) || (f1 < 0 && f2 != floor(f2)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
516 domain_error2 ("expt", number1, number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 # endif /* FLOAT_CHECK_DOMAIN */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
518 IN_FLOAT2 (f1 = pow (f1, f2), "expt", number1, number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 return make_float (f1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 DEFUN ("log", Flog, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
524 Return the natural logarithm of NUMBER.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
525 If second optional argument BASE is given, return the logarithm of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
526 NUMBER using that base.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
528 (number, base))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
530 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 if (d <= 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
533 domain_error2 ("log", number, base);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 if (NILP (base))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
536 IN_FLOAT (d = log (d), "log", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 double b = extract_float (base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 if (b <= 0.0 || b == 1.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
542 domain_error2 ("log", number, base);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 if (b == 10.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
545 IN_FLOAT2 (d = log10 (d), "log", number, base);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
547 IN_FLOAT2 (d = (log (d) / log (b)), "log", number, base);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 DEFUN ("log10", Flog10, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
554 Return the logarithm base 10 of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
556 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
558 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 if (d <= 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
561 domain_error ("log10", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
563 IN_FLOAT (d = log10 (d), "log10", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 DEFUN ("sqrt", Fsqrt, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
569 Return the square root of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
571 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
573 double d;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
574
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
575 #if defined(HAVE_BIGFLOAT) && defined(bigfloat_sqrt)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
576 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
577 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
578 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
579 bigfloat_sqrt (scratch_bigfloat, XBIGFLOAT_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
580 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
581 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
582 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
583 d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 if (d < 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
586 domain_error ("sqrt", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
588 IN_FLOAT (d = sqrt (d), "sqrt", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 DEFUN ("cube-root", Fcube_root, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
594 Return the cube root of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
596 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
598 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 #ifdef HAVE_CBRT
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
600 IN_FLOAT (d = cbrt (d), "cube-root", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 if (d >= 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
603 IN_FLOAT (d = pow (d, 1.0/3.0), "cube-root", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
605 IN_FLOAT (d = -pow (-d, 1.0/3.0), "cube-root", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 /* Inverse trig functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 DEFUN ("acosh", Facosh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
613 Return the inverse hyperbolic cosine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
615 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
617 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 if (d < 1.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
620 domain_error ("acosh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 #ifdef HAVE_INVERSE_HYPERBOLIC
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
623 IN_FLOAT (d = acosh (d), "acosh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
625 IN_FLOAT (d = log (d + sqrt (d*d - 1.0)), "acosh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 DEFUN ("asinh", Fasinh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
631 Return the inverse hyperbolic sine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
633 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
635 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 #ifdef HAVE_INVERSE_HYPERBOLIC
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
637 IN_FLOAT (d = asinh (d), "asinh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
639 IN_FLOAT (d = log (d + sqrt (d*d + 1.0)), "asinh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 DEFUN ("atanh", Fatanh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
645 Return the inverse hyperbolic tangent of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
647 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
649 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 if (d >= 1.0 || d <= -1.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
652 domain_error ("atanh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 #ifdef HAVE_INVERSE_HYPERBOLIC
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
655 IN_FLOAT (d = atanh (d), "atanh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
657 IN_FLOAT (d = 0.5 * log ((1.0 + d) / (1.0 - d)), "atanh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 DEFUN ("cosh", Fcosh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
663 Return the hyperbolic cosine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
665 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
667 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 if (d > 710.0 || d < -710.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
670 range_error ("cosh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
672 IN_FLOAT (d = cosh (d), "cosh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 DEFUN ("sinh", Fsinh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
677 Return the hyperbolic sine of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
679 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
681 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 #ifdef FLOAT_CHECK_DOMAIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 if (d > 710.0 || d < -710.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
684 range_error ("sinh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
686 IN_FLOAT (d = sinh (d), "sinh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 DEFUN ("tanh", Ftanh, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
691 Return the hyperbolic tangent of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
693 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
695 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
696 IN_FLOAT (d = tanh (d), "tanh", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 /* Rounding functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 DEFUN ("abs", Fabs, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
703 Return the absolute value of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
705 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
707 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
709 IN_FLOAT (number = make_float (fabs (XFLOAT_DATA (number))),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
710 "abs", number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
711 return number;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
714 if (INTP (number))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
715 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
716 /* The most negative Lisp fixnum will overflow */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
717 return (XINT (number) >= 0) ? number : make_integer (- XINT (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
718 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
719 return (XINT (number) >= 0) ? number : make_int (- XINT (number));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
720 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
721
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
722 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
723 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
724 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
725 if (bignum_sign (XBIGNUM_DATA (number)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
726 return number;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
727 bignum_abs (scratch_bignum, XBIGNUM_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
728 return make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
729 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
730 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
731
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
732 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
733 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
734 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
735 if (ratio_sign (XRATIO_DATA (number)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
736 return number;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
737 ratio_abs (scratch_ratio, XRATIO_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
738 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
739 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
740 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
741
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
742 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
743 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
744 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
745 if (bigfloat_sign (XBIGFLOAT_DATA (number)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
746 return number;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
747 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
748 bigfloat_abs (scratch_bigfloat, XBIGFLOAT_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
749 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
750 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
751 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
753 return Fabs (wrong_type_argument (Qnumberp, number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 DEFUN ("float", Ffloat, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
757 Return the floating point number numerically equal to NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
759 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
761 if (INTP (number))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
762 return make_float ((double) XINT (number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
764 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
765 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
766 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
767 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
768 if (ZEROP (Vdefault_float_precision))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
769 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
770 return make_float (bignum_to_double (XBIGNUM_DATA (number)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
771 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
772 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
773 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
774 bigfloat_set_prec (scratch_bigfloat, bigfloat_get_default_prec ());
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
775 bigfloat_set_bignum (scratch_bigfloat, XBIGNUM_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
776 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
777 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
778 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
779 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
780 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
781
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
782 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
783 if (RATIOP (number))
2092
f557693c61de [xemacs-hg @ 2004-05-21 20:56:26 by james]
james
parents: 2057
diff changeset
784 return make_float (ratio_to_double (XRATIO_DATA (number)));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
785 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
786
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
787 if (FLOATP (number)) /* give 'em the same float back */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
788 return number;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
790 return Ffloat (wrong_type_argument (Qnumberp, number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 DEFUN ("logb", Flogb, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
794 Return largest integer <= the base 2 log of the magnitude of NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 This is the same as the exponent of a float.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
797 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
799 double f = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 if (f == 0.0)
2039
fd0cbe945410 [xemacs-hg @ 2004-04-22 03:24:00 by james]
james
parents: 1995
diff changeset
802 return make_int (EMACS_INT_MIN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 #ifdef HAVE_LOGB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 Lisp_Object val;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
806 IN_FLOAT (val = make_int ((EMACS_INT) logb (f)), "logb", number);
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 430
diff changeset
807 return val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 #ifdef HAVE_FREXP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 int exqp;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
813 IN_FLOAT (frexp (f, &exqp), "logb", number);
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 430
diff changeset
814 return make_int (exqp - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 double d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 EMACS_INT val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 if (f < 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 f = -f;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 val = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 while (f < 0.5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 for (i = 1, d = 0.5; d * d >= f; i += i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 d *= d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 f /= d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 val -= i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 while (f >= 1.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 for (i = 1, d = 2.0; d * d <= f; i += i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 d *= d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 f /= d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 val += i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 }
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 430
diff changeset
838 return make_int (val);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 #endif /* ! HAVE_FREXP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 #endif /* ! HAVE_LOGB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 DEFUN ("ceiling", Fceiling, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
845 Return the smallest integer no less than NUMBER. (Round toward +inf.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
847 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
849 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 double d;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
852 IN_FLOAT ((d = ceil (XFLOAT_DATA (number))), "ceiling", number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
853 return (float_to_int (d, "ceiling", number, Qunbound));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
856 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
857 if (INTEGERP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
858 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
859 if (INTP (number))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
860 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
861 return number;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
863 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
864 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
865 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
866 bignum_ceil (scratch_bignum, XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
867 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
868 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
869 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
870 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
871
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
872 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
873 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
874 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
875 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
876 bigfloat_ceil (scratch_bigfloat, XBIGFLOAT_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
877 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
878 bignum_set_bigfloat (scratch_bignum, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
879 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
880 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
881 return make_int ((EMACS_INT) bigfloat_to_long (scratch_bigfloat));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
882 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
883 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
884 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
885
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
886 return Fceiling (wrong_type_argument (Qnumberp, number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 DEFUN ("floor", Ffloor, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
891 Return the largest integer no greater than NUMBER. (Round towards -inf.)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
892 With optional second argument DIVISOR, return the largest integer no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
893 greater than NUMBER/DIVISOR.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
895 (number, divisor))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
897 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
898 CHECK_REAL (number);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
899 if (NILP (divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
900 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
901 if (FLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
902 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
903 double d;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
904 IN_FLOAT ((d = floor (XFLOAT_DATA (number))), "floor", number);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
905 return (float_to_int (d, "floor", number, Qunbound));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
906 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
907 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
908 else if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
909 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
910 bignum_floor (scratch_bignum, XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
911 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
912 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
913 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
914 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
915 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
916 else if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
917 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
918 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
919 bigfloat_floor (scratch_bigfloat, XBIGFLOAT_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
920 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
921 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
922 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
923 return number;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
924 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
925 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
926 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
927 CHECK_REAL (divisor);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
928 switch (promote_args (&number, &divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
929 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
930 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
931 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
932 EMACS_INT i1 = XREALINT (number);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
933 EMACS_INT i2 = XREALINT (divisor);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
934
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
935 if (i2 == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
936 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
937
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
938 /* With C's /, the result is implementation-defined if either
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
939 operand is negative, so use only nonnegative operands. */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
940 i1 = (i2 < 0
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
941 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
942 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
943
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
944 return make_int (i1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
945 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
946 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
947 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
948 if (bignum_sign (XBIGNUM_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
949 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
950 bignum_floor (scratch_bignum, XBIGNUM_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
951 XBIGNUM_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
952 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
953 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
954 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
955 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
956 if (ratio_sign (XRATIO_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
957 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
958 ratio_div (scratch_ratio, XRATIO_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
959 XRATIO_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
960 bignum_floor (scratch_bignum, ratio_numerator (scratch_ratio),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
961 ratio_denominator (scratch_ratio));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
962 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
963 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
964 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
965 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
966 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
967 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
968 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
969 max (XBIGFLOAT_GET_PREC (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
970 XBIGFLOAT_GET_PREC (divisor)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
971 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
972 XBIGFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
973 bigfloat_floor (scratch_bigfloat, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
974 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
975 #endif
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
976 default: /* FLOAT_T */
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
977 {
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
978 double f1 = extract_float (number);
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
979 double f2 = extract_float (divisor);
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
980
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
981 if (f2 == 0.0)
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
982 Fsignal (Qarith_error, Qnil);
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
983
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
984 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", number, divisor);
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
985 return float_to_int (f1, "floor", number, divisor);
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1983
diff changeset
986 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
987 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
988 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
989 #else /* !WITH_NUMBER_TYPES */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
990 CHECK_INT_OR_FLOAT (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 if (! NILP (divisor))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 EMACS_INT i1, i2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 CHECK_INT_OR_FLOAT (divisor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
998 if (FLOATP (number) || FLOATP (divisor))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1000 double f1 = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 double f2 = extract_float (divisor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 if (f2 == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 Fsignal (Qarith_error, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1006 IN_FLOAT2 (f1 = floor (f1 / f2), "floor", number, divisor);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1007 return float_to_int (f1, "floor", number, divisor);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1010 i1 = XINT (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 i2 = XINT (divisor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 if (i2 == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 Fsignal (Qarith_error, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 /* With C's /, the result is implementation-defined if either operand
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 is negative, so use only nonnegative operands. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 i1 = (i2 < 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 ? (i1 <= 0 ? -i1 / -i2 : -1 - ((i1 - 1) / -i2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 : (i1 < 0 ? -1 - ((-1 - i1) / i2) : i1 / i2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 return (make_int (i1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1025 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 double d;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1028 IN_FLOAT ((d = floor (XFLOAT_DATA (number))), "floor", number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1029 return (float_to_int (d, "floor", number, Qunbound));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1032 return number;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1033 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 DEFUN ("round", Fround, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1037 Return the nearest integer to NUMBER.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1039 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1041 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 double d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 /* Screw the prevailing rounding mode. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1045 IN_FLOAT ((d = emacs_rint (XFLOAT_DATA (number))), "round", number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1046 return (float_to_int (d, "round", number, Qunbound));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1049 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1050 if (INTEGERP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1051 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1052 if (INTP (number))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1053 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1054 return number;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1056 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1057 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1058 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1059 if (bignum_divisible_p (XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1060 XRATIO_DENOMINATOR (number)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1061 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1062 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1063 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1064 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1065 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1066 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1067 bignum_add (scratch_bignum2, XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1068 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1069 bignum_div (scratch_bignum, scratch_bignum2,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1070 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1071 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1072 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1073 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1074 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1075
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1076 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1077 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1078 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1079 unsigned long prec = XBIGFLOAT_GET_PREC (number);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1080 bigfloat_set_prec (scratch_bigfloat, prec);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1081 bigfloat_set_prec (scratch_bigfloat2, prec);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1082 bigfloat_set_double (scratch_bigfloat2,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1083 bigfloat_sign (XBIGFLOAT_DATA (number)) * 0.5);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1084 bigfloat_floor (scratch_bigfloat, scratch_bigfloat2);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1085 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1086 bignum_set_bigfloat (scratch_bignum, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1087 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1088 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1089 return make_int ((EMACS_INT) bigfloat_to_long (scratch_bigfloat));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1090 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1091 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1092 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1093
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1094 return Fround (wrong_type_argument (Qnumberp, number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 DEFUN ("truncate", Ftruncate, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 Truncate a floating point number to an integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 Rounds the value toward zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1101 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1103 if (FLOATP (number))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1104 return float_to_int (XFLOAT_DATA (number), "truncate", number, Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1106 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1107 if (INTEGERP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1108 #else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1109 if (INTP (number))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1110 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1111 return number;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1113 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1114 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1115 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1116 bignum_div (scratch_bignum, XRATIO_NUMERATOR (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1117 XRATIO_DENOMINATOR (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1118 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1119 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1120 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1121
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1122 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1123 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1124 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1125 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1126 bigfloat_trunc (scratch_bigfloat, XBIGFLOAT_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1127 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1128 bignum_set_bigfloat (scratch_bignum, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1129 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1130 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1131 return make_int ((EMACS_INT) bigfloat_to_long (scratch_bigfloat));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1132 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1133 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1134 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1204
diff changeset
1135
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1136 return Ftruncate (wrong_type_argument (Qnumberp, number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 /* Float-rounding functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 DEFUN ("fceiling", Ffceiling, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1142 Return the smallest integer no less than NUMBER, as a float.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 \(Round toward +inf.\)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1145 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1147 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1148 IN_FLOAT (d = ceil (d), "fceiling", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 DEFUN ("ffloor", Fffloor, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1153 Return the largest integer no greater than NUMBER, as a float.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 \(Round towards -inf.\)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1156 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1158 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1159 IN_FLOAT (d = floor (d), "ffloor", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 DEFUN ("fround", Ffround, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1164 Return the nearest integer to NUMBER, as a float.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1166 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1168 double d = extract_float (number);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1169 IN_FLOAT (d = emacs_rint (d), "fround", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 DEFUN ("ftruncate", Fftruncate, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 Truncate a floating point number to an integral float value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 Rounds the value toward zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1177 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1179 double d = extract_float (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 if (d >= 0.0)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1181 IN_FLOAT (d = floor (d), "ftruncate", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1183 IN_FLOAT (d = ceil (d), "ftruncate", number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 return make_float (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 #ifdef FLOAT_CATCH_SIGILL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 float_error (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 if (! in_float)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 fatal_error_signal (signo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 EMACS_UNBLOCK_SIGNAL (signo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 in_float = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 /* Was Fsignal(), but it just doesn't make sense for an error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 occurring inside a signal handler to be restartable, considering
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 that anything could happen when the error is signaled and trapped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 and considering the asynchronous nature of signal handlers. */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 444
diff changeset
1203 signal_error (Qarith_error, 0, float_error_arg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 /* Another idea was to replace the library function `infnan'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 where SIGILL is signaled. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 #endif /* FLOAT_CATCH_SIGILL */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 /* In C++, it is impossible to determine what type matherr expects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 without some more configure magic.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 We shouldn't be using matherr anyways - it's a non-standard SYSVism. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 #if defined (HAVE_MATHERR) && !defined(__cplusplus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 matherr (struct exception *x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 Lisp_Object args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 if (! in_float)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 /* Not called from emacs-lisp float routines; do the default thing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 /* if (!strcmp (x->name, "pow")) x->name = "expt"; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 args = Fcons (build_string (x->name),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 Fcons (make_float (x->arg1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 ((in_float == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 ? Fcons (make_float (x->arg2), Qnil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 : Qnil)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 switch (x->type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 case DOMAIN: Fsignal (Qdomain_error, args); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 case SING: Fsignal (Qsingularity_error, args); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 case OVERFLOW: Fsignal (Qoverflow_error, args); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 case UNDERFLOW: Fsignal (Qunderflow_error, args); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 default: Fsignal (Qarith_error, args); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 return 1; /* don't set errno or print a message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 #endif /* HAVE_MATHERR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 init_floatfns_very_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 # ifdef FLOAT_CATCH_SIGILL
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 563
diff changeset
1246 EMACS_SIGNAL (SIGILL, float_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 in_float = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 syms_of_floatfns (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1254 INIT_LRECORD_IMPLEMENTATION (float);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 /* Trig functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 DEFSUBR (Facos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 DEFSUBR (Fasin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 DEFSUBR (Fatan);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 DEFSUBR (Fcos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 DEFSUBR (Fsin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 DEFSUBR (Ftan);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 /* Bessel functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 DEFSUBR (Fbessel_y0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 DEFSUBR (Fbessel_y1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 DEFSUBR (Fbessel_yn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 DEFSUBR (Fbessel_j0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 DEFSUBR (Fbessel_j1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 DEFSUBR (Fbessel_jn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 /* Error functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 DEFSUBR (Ferf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 DEFSUBR (Ferfc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 DEFSUBR (Flog_gamma);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 /* Root and Log functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 DEFSUBR (Fexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 DEFSUBR (Fexpt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 DEFSUBR (Flog);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 DEFSUBR (Flog10);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 DEFSUBR (Fsqrt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 DEFSUBR (Fcube_root);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 /* Inverse trig functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 DEFSUBR (Facosh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 DEFSUBR (Fasinh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 DEFSUBR (Fatanh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 DEFSUBR (Fcosh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 DEFSUBR (Fsinh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 DEFSUBR (Ftanh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 /* Rounding functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 DEFSUBR (Fabs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 DEFSUBR (Ffloat);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 DEFSUBR (Flogb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 DEFSUBR (Fceiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 DEFSUBR (Ffloor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 DEFSUBR (Fround);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 DEFSUBR (Ftruncate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 /* Float-rounding functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 DEFSUBR (Ffceiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 DEFSUBR (Fffloor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 DEFSUBR (Ffround);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 DEFSUBR (Fftruncate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 vars_of_floatfns (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 Fprovide (intern ("lisp-float-type"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 }