2
Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
4
This file is part of GNU Common Lisp, herein referred to as GCL
6
GCL is free software; you can redistribute it and/or modify it under
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
GCL is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with GCL; see the file COPYING. If not, write to the Free Software
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
#include "num_include.h"
25
object imag_unit, minus_imag_unit, imag_two;
55
return(make_longfloat((longfloat)exp(number_to_double(x))));
58
return(make_shortfloat((shortfloat)exp((double)(sf(x)))));
61
return(make_longfloat(exp(lf(x))));
66
object number_sin(), number_cos();
77
y = make_complex(y1, y);
79
x = number_times(x, y);
85
FEwrong_type_argument(sLnumber, x);
94
object z, number_nlog();
99
if (ty == t_fixnum && fix(y) == 0)
101
case t_fixnum: case t_bignum: case t_ratio:
102
return(small_fixnum(1));
105
return(make_shortfloat((shortfloat)1.0));
108
return(make_longfloat(1.0));
111
z = number_expt(x->cmp.cmp_real, y);
113
z = make_complex(z, small_fixnum(0));
118
FEwrong_type_argument(sLnumber, x);
120
if (number_zerop(x)) {
121
if (!number_plusp(ty==t_complex?y->cmp.cmp_real:y))
122
FEerror("Cannot raise zero to the power ~S.", 1, y);
123
return(number_times(x, y));
125
if (ty == t_fixnum || ty == t_bignum) {
126
if (number_minusp(y)) {
127
z = number_negate(y);
129
z = number_expt(x, z);
131
z = number_divide(small_fixnum(1), z);
139
while (number_plusp(y))
140
if (number_evenp(y)) {
141
x = number_times(x, x);
143
y = integer_divide1(y, small_fixnum(2));
146
z = number_times(z, x);
148
y = number_minus(y, small_fixnum(1));
156
z = number_times(z, y);
168
object r, i, a, p, number_sqrt(), number_atan2();
171
if (type_of(x) == t_complex) {
177
FEerror("Zero is the logarithmic singularity.", 0);
178
if (number_minusp(x)) {
183
switch (type_of(x)) {
187
return(make_longfloat(log(number_to_double(x))));
190
return(make_shortfloat((shortfloat)log((double)(sf(x)))));
193
return(make_longfloat(log(lf(x))));
196
FEwrong_type_argument(sLnumber, x);
200
a = number_times(r, r);
202
p = number_times(i, i);
204
a = number_plus(a, p);
208
a = number_divide(a, small_fixnum(2));
210
p = number_atan2(i, r);
212
x = make_complex(a, p);
225
FEerror("Zero is the logarithmic singularity.", 0);
227
return(number_times(x, y));
232
z = number_divide(y, x);
245
if (type_of(x) == t_complex)
247
if (number_minusp(x))
249
switch (type_of(x)) {
253
return(make_longfloat(
254
(longfloat)sqrt(number_to_double(x))));
257
return(make_shortfloat((shortfloat)sqrt((double)(sf(x)))));
260
return(make_longfloat(sqrt(lf(x))));
263
FEwrong_type_argument(sLnumber, x);
267
z = make_ratio(small_fixnum(1), small_fixnum(2));
269
z = number_expt(x, z);
279
double atan(), dy, dx, dz;
281
dy = number_to_double(y);
282
dx = number_to_double(x);
289
dz = -atan(-dy / dx);
294
FEerror("Logarithmic singularity.", 0);
299
dz = PI - atan(dy / -dx);
303
dz = -PI + atan(-dy / -dx);
304
if (type_of(x) == t_shortfloat)
305
z = make_shortfloat((shortfloat)dz);
307
z = make_longfloat(dz);
318
if (type_of(y) == t_complex) {
319
z = number_times(imag_unit, y);
323
z1 = number_times(y, y);
327
z1 = number_sqrt(z1);
329
z = number_divide(z, z1);
333
z = number_times(minus_imag_unit, z);
337
return(number_atan2(y, small_fixnum(1)));
346
switch (type_of(x)) {
351
return(make_longfloat((longfloat)sin(number_to_double(x))));
354
return(make_shortfloat((shortfloat)sin((double)(sf(x)))));
357
return(make_longfloat(sin(lf(x))));
365
x0 = number_times(imag_unit, x);
369
x1 = number_times(minus_imag_unit, x);
373
x2 = number_minus(x0, x1);
375
r = number_divide(x2, imag_two);
382
FEwrong_type_argument(sLnumber, x);
393
switch (type_of(x)) {
398
return(make_longfloat((longfloat)cos(number_to_double(x))));
401
return(make_shortfloat((shortfloat)cos((double)(sf(x)))));
404
return(make_longfloat(cos(lf(x))));
412
x0 = number_times(imag_unit, x);
416
x1 = number_times(minus_imag_unit, x);
420
x2 = number_plus(x0, x1);
422
r = number_divide(x2, small_fixnum(2));
429
FEwrong_type_argument(sLnumber, x);
445
if (number_zerop(c) == TRUE)
446
FEerror("Cannot compute the tangent of ~S.", 1, x);
447
r = number_divide(s, c);
455
check_type_number(&vs_base[0]);
456
vs_base[0] = number_exp(vs_base[0]);
462
check_type_number(&vs_base[0]);
463
check_type_number(&vs_base[1]);
464
vs_base[0] = number_expt(vs_base[0], vs_base[1]);
472
narg = vs_top - vs_base;
475
else if (narg == 1) {
476
check_type_number(&vs_base[0]);
477
vs_base[0] = number_nlog(vs_base[0]);
478
} else if (narg == 2) {
479
check_type_number(&vs_base[0]);
480
check_type_number(&vs_base[1]);
481
vs_base[0] = number_log(vs_base[1], vs_base[0]);
484
too_many_arguments();
490
check_type_number(&vs_base[0]);
491
vs_base[0] = number_sqrt(vs_base[0]);
497
check_type_number(&vs_base[0]);
498
vs_base[0] = number_sin(vs_base[0]);
504
check_type_number(&vs_base[0]);
505
vs_base[0] = number_cos(vs_base[0]);
511
check_type_number(&vs_base[0]);
512
vs_base[0] = number_tan(vs_base[0]);
519
narg = vs_top - vs_base;
523
check_type_number(&vs_base[0]);
524
vs_base[0] = number_atan(vs_base[0]);
525
} else if (narg == 2) {
526
check_type_or_rational_float(&vs_base[0]);
527
check_type_or_rational_float(&vs_base[1]);
528
vs_base[0] = number_atan2(vs_base[0], vs_base[1]);
531
too_many_arguments();
537
= make_complex(make_longfloat((longfloat)0.0),
538
make_longfloat((longfloat)1.0));
539
enter_mark_origin(&imag_unit);
541
= make_complex(make_longfloat((longfloat)0.0),
542
make_longfloat((longfloat)-1.0));
543
enter_mark_origin(&minus_imag_unit);
545
= make_complex(make_longfloat((longfloat)0.0),
546
make_longfloat((longfloat)2.0));
547
enter_mark_origin(&imag_two);
549
make_constant("PI", make_longfloat(PI));
551
make_function("EXP", Lexp);
552
make_function("EXPT", Lexpt);
553
make_function("LOG", Llog);
554
make_function("SQRT", Lsqrt);
555
make_function("SIN", Lsin);
556
make_function("COS", Lcos);
557
make_function("TAN", Ltan);
558
make_function("ATAN", Latan);