16{
if FLONUMP(
x)
return(truth);
else return(NIL);}
22 for (sum=0.0,l=args; l != NIL; l=cdr(l))
24 if (NFLONUMP(car(l))) err(
"wrong type of argument to plus",car(l));
34 for (
product=1.0,l=args; l != NIL; l=cdr(l))
36 if (NFLONUMP(car(l))) err(
"wrong type of argument to times",car(l));
43{
if NFLONUMP(
x) err(
"wrong type of argument(1st) to difference",
x);
44 if NFLONUMP(
y) err(
"wrong type of argument(2nd) to difference",
y);
45 return(flocons(FLONM(
x) - FLONM(
y)));}
48{
if NFLONUMP(
x) err(
"wrong type of argument(1st) to quotient",
x);
49 if NFLONUMP(
y) err(
"wrong type of argument(2nd) to quotient",
y);
50 return(flocons(FLONM(
x)/FLONM(
y)));}
53{
if NFLONUMP(
x) err(
"wrong type of argument(1st) to greaterp",
x);
54 if NFLONUMP(
y) err(
"wrong type of argument(2nd) to greaterp",
y);
55 if (FLONM(
x)>FLONM(
y))
return(truth);
59{
if NFLONUMP(
x) err(
"wrong type of argument(1st) to lessp",
x);
60 if NFLONUMP(
y) err(
"wrong type of argument(2nd) to lessp",
y);
61 if (FLONM(
x)<FLONM(
y))
return(truth);
66 if (TYPEP(
number,tc_flonum))
71 else if (TYPEP(
number,tc_symbol))
77 err(
"nint: argument not a number",
number);
84 if (n && (TYPEP(n,tc_flonum)))
85 return flocons(
log(FLONM(n)));
87 err(
"log: not a number",n);
101 if (
seed && (TYPEP(
seed,tc_flonum)))
104 err(
"srand: not a number",
seed);
110 if (n && (TYPEP(n,tc_flonum)))
111 return flocons(
exp(FLONM(n)));
113 err(
"exp: not a number",n);
119 if (n && (TYPEP(n,tc_flonum)))
120 return flocons(
sin(FLONM(n)));
122 err(
"sin: not a number",n);
128 if (n && (TYPEP(n,tc_flonum)))
129 return flocons(
cos(FLONM(n)));
131 err(
"cos: not a number",n);
137 if (n && (TYPEP(n,tc_flonum)))
138 return flocons(
tan(FLONM(n)));
140 err(
"tan: not a number",n);
146 if (n && (TYPEP(n,tc_flonum)))
147 return flocons(
asin(FLONM(n)));
149 err(
"asin: not a number",n);
155 if (n && (TYPEP(n,tc_flonum)))
156 return flocons(
acos(FLONM(n)));
158 err(
"acos: not a number",n);
164 if (n && (TYPEP(n,tc_flonum)))
165 return flocons(
atan(FLONM(n)));
167 err(
"atan: not a number",n);
173 if (n && (TYPEP(n,tc_flonum)))
174 return flocons(
sqrt(FLONM(n)));
176 err(
"sqrt: not a number",n);
182 if (
x && (TYPEP(
x,tc_flonum)) &&
183 y && (TYPEP(
y,tc_flonum)))
184 return flocons(
pow(FLONM(
x),FLONM(
y)));
186 err(
"pow: x or y not a number",cons(
x,cons(
y,NIL)));
192 if (
x && (TYPEP(
x,tc_flonum)) &&
193 y && (TYPEP(
y,tc_flonum)))
200 err(
"mod: y cannot be 0",cons(
x,cons(
y,NIL)));
202 return flocons((
float)(a%b));
205 err(
"mod: x or y not a number",cons(
x,cons(
y,NIL)));
209void init_subrs_math(
void)
211 init_subr_1(
"number?",numberp,
213 Returns t if DATA is a number, nil otherwise.");
214 init_lsubr(
"+",lplus,
215 "(+ NUM1 NUM2 ...)\n\
216 Returns the sum of NUM1 and NUM2 ... An error is given is any argument\n\
218 init_subr_2(
"-",difference,
220 Returns the difference between NUM1 and NUM2. An error is given is any\n\
221 argument is not a number.");
222 init_lsubr(
"*",ltimes,
223 "(* NUM1 NUM2 ...)\n\
224 Returns the product of NUM1 and NUM2 ... An error is given is any\n\
225 argument is not a number.");
226 init_subr_2(
"/",quotient,
228 Returns the quotient of NUM1 and NUM2. An error is given is any\n\
229 argument is not a number.");
230 init_subr_2(
">",greaterp,
232 Returns t if NUM1 is greater than NUM2, nil otherwise. An error is\n\
233 given is either argument is not a number.");
234 init_subr_2(
"<",lessp,
236 Returns t if NUM1 is less than NUM2, nil otherwise. An error is\n\
237 given is either argument is not a number.");
238 init_subr_1(
"nint",l_nint,
240 Returns nearest int to NUMBER.");
241 init_subr_1(
"log",l_log,
243 Return natural log of NUM.");
244 init_subr_0(
"rand",l_rand,
246 Returns a pseudo random number between 0 and 1 using the libc rand()\n\
248 init_subr_1(
"srand",l_srand,
250 Seeds the libc pseudo random number generator with the integer SEED.");
251 init_subr_1(
"exp",l_exp,
254 init_subr_1(
"sin",l_sin,
256 Return sine of NUM.");
257 init_subr_1(
"cos",l_cos,
259 Return cosine of NUM.");
260 init_subr_1(
"tan",l_tan,
262 Return tangent of NUM.");
263 init_subr_1(
"asin",l_asin,
265 Return arcsine of NUM.");
266 init_subr_1(
"acos",l_acos,
268 Return arccosine of NUM.");
269 init_subr_1(
"atan",l_atan,
271 Return arctangent of NUM.");
272 init_subr_1(
"sqrt",l_sqrt,
274 Return square root of NUM.");
275 init_subr_2(
"pow",l_pow,
278 init_subr_2(
"%",l_mod,