248 |
static object |
static object |
249 |
number_sqrt(object x) |
number_sqrt(object x) |
250 |
{ |
{ |
251 |
object z; |
object z,q; |
252 |
double sqrt(double); |
int s; |
253 |
|
enum type t; |
254 |
|
double sqrt(double),d; |
255 |
vs_mark; |
vs_mark; |
256 |
|
|
257 |
if (type_of(x) == t_complex) |
if (type_of(x) == t_complex) |
258 |
goto COMPLEX; |
goto COMPLEX; |
259 |
if (number_minusp(x)) |
if ((s=number_minusp(x))) |
260 |
goto COMPLEX; |
x=number_negate(x); |
261 |
switch (type_of(x)) { |
|
262 |
|
switch ((t=type_of(x))) { |
263 |
case t_fixnum: |
case t_fixnum: |
264 |
case t_bignum: |
case t_bignum: |
265 |
case t_ratio: |
case t_ratio: |
266 |
return(make_longfloat( |
d=sqrt(number_to_double(x)); |
267 |
(longfloat)sqrt(number_to_double(x)))); |
if (d!=(number_to_double((q=double_to_integer(d))))) |
268 |
|
t=t_longfloat; |
269 |
|
break; |
270 |
case t_shortfloat: |
case t_shortfloat: |
271 |
return(make_shortfloat((shortfloat)sqrt((double)(sf(x))))); |
d=sqrt((double)(sf(x))); |
272 |
|
q=make_shortfloat((shortfloat)d); |
273 |
|
break; |
274 |
case t_longfloat: |
case t_longfloat: |
275 |
return(make_longfloat(sqrt(lf(x)))); |
d=sqrt(lf(x)); |
276 |
|
break; |
277 |
default: |
default: |
278 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
279 |
} |
} |
280 |
|
|
281 |
|
q=t==t_longfloat ? make_longfloat(d) : q; |
282 |
|
|
283 |
|
return s ? make_complex(small_fixnum(0),q) : q; |
284 |
|
|
285 |
|
|
286 |
COMPLEX: |
COMPLEX: |
287 |
z = make_ratio(small_fixnum(1), small_fixnum(2)); |
{extern object plus_half; |
288 |
vs_push(z); |
z = number_expt(x, plus_half);} |
|
z = number_expt(x, z); |
|
289 |
vs_reset; |
vs_reset; |
290 |
return(z); |
return(z); |
291 |
} |
} |
319 |
dz = PI; |
dz = PI; |
320 |
else |
else |
321 |
dz = -PI + atan(-dy / -dx); |
dz = -PI + atan(-dy / -dx); |
322 |
if (type_of(x) == t_shortfloat) |
if ((type_of(x) == t_shortfloat && type_of(y)!=t_longfloat) || |
323 |
|
(type_of(y) == t_shortfloat && type_of(x)!=t_longfloat)) |
324 |
z = make_shortfloat((shortfloat)dz); |
z = make_shortfloat((shortfloat)dz); |
325 |
else |
else |
326 |
z = make_longfloat(dz); |
z = make_longfloat(dz); |
615 |
gcl_init_num_sfun(void) |
gcl_init_num_sfun(void) |
616 |
{ |
{ |
617 |
imag_unit |
imag_unit |
618 |
= make_complex(make_longfloat((longfloat)0.0), |
= make_complex(small_fixnum(0), |
619 |
make_longfloat((longfloat)1.0)); |
small_fixnum(1)); |
620 |
enter_mark_origin(&imag_unit); |
enter_mark_origin(&imag_unit); |
621 |
minus_imag_unit |
minus_imag_unit |
622 |
= make_complex(make_longfloat((longfloat)0.0), |
= make_complex(small_fixnum(0), |
623 |
make_longfloat((longfloat)-1.0)); |
small_fixnum(-1)); |
624 |
enter_mark_origin(&minus_imag_unit); |
enter_mark_origin(&minus_imag_unit); |
625 |
imag_two |
imag_two |
626 |
= make_complex(make_longfloat((longfloat)0.0), |
= make_complex(small_fixnum(0), |
627 |
make_longfloat((longfloat)2.0)); |
small_fixnum(2)); |
628 |
enter_mark_origin(&imag_two); |
enter_mark_origin(&imag_two); |
629 |
|
/* imag_unit */ |
630 |
|
/* = make_complex(make_longfloat((longfloat)0.0), */ |
631 |
|
/* make_longfloat((longfloat)1.0)); */ |
632 |
|
/* enter_mark_origin(&imag_unit); */ |
633 |
|
/* minus_imag_unit */ |
634 |
|
/* = make_complex(make_longfloat((longfloat)0.0), */ |
635 |
|
/* make_longfloat((longfloat)-1.0)); */ |
636 |
|
/* enter_mark_origin(&minus_imag_unit); */ |
637 |
|
/* imag_two */ |
638 |
|
/* = make_complex(make_longfloat((longfloat)0.0), */ |
639 |
|
/* make_longfloat((longfloat)2.0)); */ |
640 |
|
/* enter_mark_origin(&imag_two); */ |
641 |
|
|
642 |
make_constant("PI", make_longfloat(PI)); |
make_constant("PI", make_longfloat(PI)); |
643 |
|
|