annotate src/floatfns.c @ 1933:63ba4f555b90

* minibuf.c (Fdisplay_completion_list): Pass the proper number of arguments to Flength. * xmenu.c (list_of_items): Same.
author Jim Blandy <jimb@redhat.com>
date Mon, 22 Feb 1993 15:09:33 +0000
parents 699ae3079c09
children c77607f8e32d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
1 /* Primitive operations on floating point for GNU Emacs Lisp interpreter.
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
2 Copyright (C) 1988, 1992 Free Software Foundation, Inc.
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
3
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
4 This file is part of GNU Emacs.
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
5
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
9 any later version.
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
10
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
14 GNU General Public License for more details.
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
15
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
19
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
20
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
21 #include <signal.h>
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
22
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
23 #include "config.h"
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
24 #include "lisp.h"
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
25 #include "syssignal.h"
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
26
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
27 Lisp_Object Qarith_error;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
28
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
29 #ifdef LISP_FLOAT_TYPE
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
30
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
31 #include <math.h>
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
32 #include <errno.h>
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
33
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
34 extern int errno;
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
35
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
36 /* Avoid traps on VMS from sinh and cosh.
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
37 All the other functions set errno instead. */
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
38
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
39 #ifdef VMS
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
40 #undef cosh
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
41 #undef sinh
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
42 #define cosh(x) ((exp(x)+exp(-x))*0.5)
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
43 #define sinh(x) ((exp(x)-exp(-x))*0.5)
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
44 #endif /* VMS */
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
45
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
46 static SIGTYPE float_error ();
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
47
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
48 /* Nonzero while executing in floating point.
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
49 This tells float_error what to do. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
50
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
51 static int in_float;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
52
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
53 /* If an argument is out of range for a mathematical function,
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
54 here is the actual argument value to use in the error message. */
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
55
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
56 static Lisp_Object float_error_arg;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
57
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
58 /* Evaluate the floating point expression D, recording NUM
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
59 as the original argument for error messages.
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
60 D is normally an assignment expression.
1918
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
61 Handle errors which may result in signals or may set errno.
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
62
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
63 Note that float_error may be declared to return void, so you can't
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
64 just cast the zero after the colon to (SIGTYPE) to make the types
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
65 check properly. */
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
66
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
67 #define IN_FLOAT(D, NUM) \
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
68 (in_float = 1, errno = 0, float_error_arg = NUM, (D), \
1918
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
69 (errno == ERANGE || errno == EDOM ? (float_error (),0) : 0), \
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
70 in_float = 0)
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
71
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
72 /* Extract a Lisp number as a `double', or signal an error. */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
73
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
74 double
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
75 extract_float (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
76 Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
77 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
78 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
79
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
80 if (XTYPE (num) == Lisp_Float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
81 return XFLOAT (num)->data;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
82 return (double) XINT (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
83 }
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
84
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
85 /* Trig functions. */
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
86
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
87 DEFUN ("acos", Facos, Sacos, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
88 "Return the inverse cosine of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
89 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
90 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
91 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
92 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
93 IN_FLOAT (d = acos (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
94 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
95 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
96
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
97 DEFUN ("asin", Fasin, Sasin, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
98 "Return the inverse sine of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
99 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
100 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
101 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
102 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
103 IN_FLOAT (d = asin (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
104 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
105 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
106
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
107 DEFUN ("atan", Fatan, Satan, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
108 "Return the inverse tangent of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
109 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
110 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
111 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
112 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
113 IN_FLOAT (d = atan (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
114 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
115 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
116
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
117 DEFUN ("cos", Fcos, Scos, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
118 "Return the cosine of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
119 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
120 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
121 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
122 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
123 IN_FLOAT (d = cos (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
124 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
125 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
126
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
127 DEFUN ("sin", Fsin, Ssin, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
128 "Return the sine of ARG.")
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
129 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
130 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
131 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
132 double d = extract_float (num);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
133 IN_FLOAT (d = sin (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
134 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
135 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
136
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
137 DEFUN ("tan", Ftan, Stan, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
138 "Return the tangent of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
139 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
140 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
141 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
142 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
143 IN_FLOAT (d = tan (d), num);
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
144 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
145 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
146
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
147 #if 0 /* Leave these out unless we find there's a reason for them. */
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
148
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
149 DEFUN ("bessel-j0", Fbessel_j0, Sbessel_j0, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
150 "Return the bessel function j0 of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
151 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
152 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
153 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
154 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
155 IN_FLOAT (d = j0 (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
156 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
157 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
158
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
159 DEFUN ("bessel-j1", Fbessel_j1, Sbessel_j1, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
160 "Return the bessel function j1 of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
161 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
162 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
163 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
164 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
165 IN_FLOAT (d = j1 (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
166 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
167 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
168
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
169 DEFUN ("bessel-jn", Fbessel_jn, Sbessel_jn, 2, 2, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
170 "Return the order N bessel function output jn of ARG.\n\
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
171 The first arg (the order) is truncated to an integer.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
172 (num1, num2)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
173 register Lisp_Object num1, num2;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
174 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
175 int i1 = extract_float (num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
176 double f2 = extract_float (num2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
177
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
178 IN_FLOAT (f2 = jn (i1, f2), num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
179 return make_float (f2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
180 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
181
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
182 DEFUN ("bessel-y0", Fbessel_y0, Sbessel_y0, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
183 "Return the bessel function y0 of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
184 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
185 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
186 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
187 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
188 IN_FLOAT (d = y0 (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
189 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
190 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
191
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
192 DEFUN ("bessel-y1", Fbessel_y1, Sbessel_y1, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
193 "Return the bessel function y1 of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
194 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
195 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
196 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
197 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
198 IN_FLOAT (d = y1 (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
199 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
200 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
201
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
202 DEFUN ("bessel-yn", Fbessel_yn, Sbessel_yn, 2, 2, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
203 "Return the order N bessel function output yn of ARG.\n\
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
204 The first arg (the order) is truncated to an integer.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
205 (num1, num2)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
206 register Lisp_Object num1, num2;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
207 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
208 int i1 = extract_float (num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
209 double f2 = extract_float (num2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
210
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
211 IN_FLOAT (f2 = yn (i1, f2), num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
212 return make_float (f2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
213 }
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
214
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
215 #endif
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
216
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
217 #if 0 /* Leave these out unless we see they are worth having. */
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
218
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
219 DEFUN ("erf", Ferf, Serf, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
220 "Return the mathematical error function of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
221 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
222 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
223 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
224 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
225 IN_FLOAT (d = erf (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
226 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
227 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
228
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
229 DEFUN ("erfc", Ferfc, Serfc, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
230 "Return the complementary error function of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
231 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
232 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
233 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
234 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
235 IN_FLOAT (d = erfc (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
236 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
237 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
238
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
239 DEFUN ("log-gamma", Flog_gamma, Slog_gamma, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
240 "Return the log gamma of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
241 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
242 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
243 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
244 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
245 IN_FLOAT (d = lgamma (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
246 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
247 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
248
694
714b8017cc6b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 683
diff changeset
249 DEFUN ("cbrt", Fcbrt, Scbrt, 1, 1, 0,
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
250 "Return the cube root of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
251 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
252 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
253 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
254 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
255 IN_FLOAT (d = cbrt (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
256 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
257 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
258
694
714b8017cc6b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 683
diff changeset
259 #endif
714b8017cc6b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 683
diff changeset
260
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
261 DEFUN ("exp", Fexp, Sexp, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
262 "Return the exponential base e of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
263 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
264 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
265 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
266 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
267 IN_FLOAT (d = exp (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
268 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
269 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
270
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
271 DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0,
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
272 "Return the exponential X ** Y.")
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
273 (num1, num2)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
274 register Lisp_Object num1, num2;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
275 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
276 double f1, f2;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
277
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
278 CHECK_NUMBER_OR_FLOAT (num1, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
279 CHECK_NUMBER_OR_FLOAT (num2, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
280 if ((XTYPE (num1) == Lisp_Int) && /* common lisp spec */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
281 (XTYPE (num2) == Lisp_Int)) /* don't promote, if both are ints */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
282 { /* this can be improved by pre-calculating */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
283 int acc, x, y; /* some binary powers of x then acumulating */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
284 /* these, therby saving some time. -wsr */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
285 x = XINT (num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
286 y = XINT (num2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
287 acc = 1;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
288
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
289 if (y < 0)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
290 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
291 for (; y < 0; y++)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
292 acc /= x;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
293 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
294 else
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
295 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
296 for (; y > 0; y--)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
297 acc *= x;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
298 }
1512
bef6b6903528 * floatfns.c (Flog): Don't forget to declare the BASE argument a
Jim Blandy <jimb@redhat.com>
parents: 1005
diff changeset
299 XFASTINT (x) = acc;
bef6b6903528 * floatfns.c (Flog): Don't forget to declare the BASE argument a
Jim Blandy <jimb@redhat.com>
parents: 1005
diff changeset
300 return x;
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
301 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
302 f1 = (XTYPE (num1) == Lisp_Float) ? XFLOAT (num1)->data : XINT (num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
303 f2 = (XTYPE (num2) == Lisp_Float) ? XFLOAT (num2)->data : XINT (num2);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
304 IN_FLOAT (f1 = pow (f1, f2), num1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
305 return make_float (f1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
306 }
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
307
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
308 DEFUN ("log", Flog, Slog, 1, 2, 0,
1715
cd23f7ef1bd0 * floatfns.c (Flog): Fix unescaped newline in string.
Jim Blandy <jimb@redhat.com>
parents: 1512
diff changeset
309 "Return the natural logarithm of NUM.\n\
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
310 If second optional argument BASE is given, return log NUM using that base.")
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
311 (num, base)
1512
bef6b6903528 * floatfns.c (Flog): Don't forget to declare the BASE argument a
Jim Blandy <jimb@redhat.com>
parents: 1005
diff changeset
312 register Lisp_Object num, base;
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
313 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
314 double d = extract_float (num);
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
315
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
316 if (NILP (base))
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
317 IN_FLOAT (d = log (d), num);
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
318 else
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
319 {
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
320 double b = extract_float (base);
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
321
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
322 IN_FLOAT (d = log (num) / log (b), num);
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
323 }
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
324 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
325 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
326
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
327 DEFUN ("log10", Flog10, Slog10, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
328 "Return the logarithm base 10 of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
329 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
330 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
331 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
332 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
333 IN_FLOAT (d = log10 (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
334 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
335 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
336
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
337 DEFUN ("sqrt", Fsqrt, Ssqrt, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
338 "Return the square root of ARG.")
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
339 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
340 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
341 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
342 double d = extract_float (num);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
343 IN_FLOAT (d = sqrt (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
344 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
345 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
346
694
714b8017cc6b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 683
diff changeset
347 #if 0 /* Not clearly worth adding. */
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
348
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
349 DEFUN ("acosh", Facosh, Sacosh, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
350 "Return the inverse hyperbolic cosine of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
351 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
352 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
353 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
354 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
355 IN_FLOAT (d = acosh (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
356 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
357 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
358
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
359 DEFUN ("asinh", Fasinh, Sasinh, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
360 "Return the inverse hyperbolic sine of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
361 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
362 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
363 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
364 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
365 IN_FLOAT (d = asinh (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
366 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
367 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
368
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
369 DEFUN ("atanh", Fatanh, Satanh, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
370 "Return the inverse hyperbolic tangent of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
371 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
372 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
373 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
374 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
375 IN_FLOAT (d = atanh (d), num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
376 return make_float (d);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
377 }
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
378
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
379 DEFUN ("cosh", Fcosh, Scosh, 1, 1, 0,
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
380 "Return the hyperbolic cosine of ARG.")
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
381 (num)
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
382 register Lisp_Object num;
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
383 {
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
384 double d = extract_float (num);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
385 IN_FLOAT (d = cosh (d), num);
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
386 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
387 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
388
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
389 DEFUN ("sinh", Fsinh, Ssinh, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
390 "Return the hyperbolic sine of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
391 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
392 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
393 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
394 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
395 IN_FLOAT (d = sinh (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
396 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
397 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
398
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
399 DEFUN ("tanh", Ftanh, Stanh, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
400 "Return the hyperbolic tangent of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
401 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
402 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
403 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
404 double d = extract_float (num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
405 IN_FLOAT (d = tanh (d), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
406 return make_float (d);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
407 }
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
408 #endif
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
409
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
410 DEFUN ("abs", Fabs, Sabs, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
411 "Return the absolute value of ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
412 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
413 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
414 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
415 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
416
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
417 if (XTYPE (num) == Lisp_Float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
418 IN_FLOAT (num = make_float (fabs (XFLOAT (num)->data)), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
419 else if (XINT (num) < 0)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
420 XSETINT (num, - XFASTINT (num));
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
421
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
422 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
423 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
424
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
425 DEFUN ("float", Ffloat, Sfloat, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
426 "Return the floating point number equal to ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
427 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
428 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
429 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
430 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
431
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
432 if (XTYPE (num) == Lisp_Int)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
433 return make_float ((double) XINT (num));
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
434 else /* give 'em the same float back */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
435 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
436 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
437
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
438 DEFUN ("logb", Flogb, Slogb, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
439 "Returns the integer that is the base 2 log of ARG.\n\
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
440 This is the same as the exponent of a float.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
441 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
442 Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
443 {
1918
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
444 /* System V apparently doesn't have a `logb' function. It might be
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
445 better to use it on systems that have it, but Ultrix (at least)
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
446 doesn't declare it properly in <math.h>; does anyone really care? */
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
447 return Flog (num, make_number (2));
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
448 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
449
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
450 /* the rounding functions */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
451
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
452 DEFUN ("ceiling", Fceiling, Sceiling, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
453 "Return the smallest integer no less than ARG. (Round toward +inf.)")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
454 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
455 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
456 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
457 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
458
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
459 if (XTYPE (num) == Lisp_Float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
460 IN_FLOAT (XSET (num, Lisp_Int, ceil (XFLOAT (num)->data)), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
461
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
462 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
463 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
464
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
465 DEFUN ("floor", Ffloor, Sfloor, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
466 "Return the largest integer no greater than ARG. (Round towards -inf.)")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
467 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
468 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
469 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
470 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
471
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
472 if (XTYPE (num) == Lisp_Float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
473 IN_FLOAT (XSET (num, Lisp_Int, floor (XFLOAT (num)->data)), num);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
474
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
475 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
476 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
477
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
478 DEFUN ("round", Fround, Sround, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
479 "Return the nearest integer to ARG.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
480 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
481 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
482 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
483 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
484
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
485 if (XTYPE (num) == Lisp_Float)
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
486 {
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
487 /* Screw the prevailing rounding mode. */
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
488 IN_FLOAT (XSET (num, Lisp_Int, floor (XFLOAT (num)->data + 0.5)), num);
1918
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
489
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
490 /* It used to be that on non-USG systems we'd use the `rint'
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
491 function. But that seems not to be declared properly in
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
492 <math.h> on Ultrix, I don't want to declare it myself because
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
493 that might conflict with <math.h> on other systems, and I
699ae3079c09 * floatfns.c (Flogb): Always implement this by calling Flog, even
Jim Blandy <jimb@redhat.com>
parents: 1715
diff changeset
494 don't see what's wrong with the code above anyway. */
1005
70ed307d9047 * floatfns.c (Fexpm1, Flog1p): Function removed; it's not widely
Jim Blandy <jimb@redhat.com>
parents: 694
diff changeset
495 }
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
496
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
497 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
498 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
499
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
500 DEFUN ("truncate", Ftruncate, Struncate, 1, 1, 0,
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
501 "Truncate a floating point number to an int.\n\
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
502 Rounds the value toward zero.")
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
503 (num)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
504 register Lisp_Object num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
505 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
506 CHECK_NUMBER_OR_FLOAT (num, 0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
507
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
508 if (XTYPE (num) == Lisp_Float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
509 XSET (num, Lisp_Int, (int) XFLOAT (num)->data);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
510
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
511 return num;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
512 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
513
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
514 static SIGTYPE
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
515 float_error (signo)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
516 int signo;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
517 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
518 if (! in_float)
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
519 fatal_error_signal (signo);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
520
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
521 #ifdef BSD
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
522 #ifdef BSD4_1
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
523 sigrelse (SIGILL);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
524 #else /* not BSD4_1 */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
525 sigsetmask (SIGEMPTYMASK);
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
526 #endif /* not BSD4_1 */
485
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
527 #else
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
528 /* Must reestablish handler each time it is called. */
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
529 signal (SIGILL, float_error);
8c615e453683 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 102
diff changeset
530 #endif /* BSD */
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
531
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
532 in_float = 0;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
533
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
534 Fsignal (Qarith_error, Fcons (float_error_arg, Qnil));
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
535 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
536
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
537 init_floatfns ()
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
538 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
539 signal (SIGILL, float_error);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
540 in_float = 0;
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
541 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
542
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
543 syms_of_floatfns ()
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
544 {
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
545 defsubr (&Sacos);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
546 defsubr (&Sasin);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
547 defsubr (&Satan);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
548 defsubr (&Scos);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
549 defsubr (&Ssin);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
550 defsubr (&Stan);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
551 #if 0
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
552 defsubr (&Sacosh);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
553 defsubr (&Sasinh);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
554 defsubr (&Satanh);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
555 defsubr (&Scosh);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
556 defsubr (&Ssinh);
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
557 defsubr (&Stanh);
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
558 defsubr (&Sbessel_y0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
559 defsubr (&Sbessel_y1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
560 defsubr (&Sbessel_yn);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
561 defsubr (&Sbessel_j0);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
562 defsubr (&Sbessel_j1);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
563 defsubr (&Sbessel_jn);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
564 defsubr (&Serf);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
565 defsubr (&Serfc);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
566 defsubr (&Slog_gamma);
694
714b8017cc6b entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 683
diff changeset
567 defsubr (&Scbrt);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
568 #endif
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
569 defsubr (&Sexp);
683
7f4d77d29804 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 638
diff changeset
570 defsubr (&Sexpt);
102
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
571 defsubr (&Slog);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
572 defsubr (&Slog10);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
573 defsubr (&Ssqrt);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
574
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
575 defsubr (&Sabs);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
576 defsubr (&Sfloat);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
577 defsubr (&Slogb);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
578 defsubr (&Sceiling);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
579 defsubr (&Sfloor);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
580 defsubr (&Sround);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
581 defsubr (&Struncate);
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
582 }
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
583
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
584 #else /* not LISP_FLOAT_TYPE */
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
585
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
586 init_floatfns ()
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
587 {}
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
588
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
589 syms_of_floatfns ()
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
590 {}
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
591
0d3a6b3b64a4 Initial revision
Mike Rowan <mtr@gnu.org>
parents:
diff changeset
592 #endif /* not LISP_FLOAT_TYPE */