2004-08-05 16:49:55 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
void primitive_floatp(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_boolean(typep(FLOAT_TYPE,dpeek())));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FLOAT* to_float(CELL tagged)
|
|
|
|
{
|
|
|
|
switch(type_of(tagged))
|
|
|
|
{
|
|
|
|
case FIXNUM_TYPE:
|
|
|
|
return fixnum_to_float(tagged);
|
|
|
|
case BIGNUM_TYPE:
|
|
|
|
return bignum_to_float(tagged);
|
|
|
|
case RATIO_TYPE:
|
|
|
|
return ratio_to_float(tagged);
|
|
|
|
case FLOAT_TYPE:
|
|
|
|
return (FLOAT*)UNTAG(tagged);
|
|
|
|
default:
|
|
|
|
type_error(FLOAT_TYPE,tagged);
|
|
|
|
return NULL; /* can't happen */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_to_float(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(to_float(dpeek())));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-05 17:33:02 -04:00
|
|
|
void primitive_str_to_float(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
STRING* str = untag_string(dpeek());
|
2004-08-06 18:40:44 -04:00
|
|
|
char* c_str = to_c_string(str);
|
|
|
|
char* end = c_str;
|
|
|
|
double f = strtod(c_str,&end);
|
|
|
|
if(end != c_str + str->capacity)
|
|
|
|
general_error(ERROR_FLOAT_FORMAT,tag_object(str));
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(f)));
|
2004-08-05 17:33:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_float_to_str(void)
|
|
|
|
{
|
|
|
|
char tmp[33];
|
2004-08-12 17:36:36 -04:00
|
|
|
snprintf(&tmp,32,"%.16g",to_float(dpeek())->n);
|
2004-08-05 17:33:02 -04:00
|
|
|
tmp[32] = '\0';
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(from_c_string(tmp)));
|
2004-08-05 17:33:02 -04:00
|
|
|
}
|
|
|
|
|
2004-08-06 02:51:32 -04:00
|
|
|
void primitive_float_to_bits(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
double f = untag_float(dpeek());
|
2004-08-25 20:51:19 -04:00
|
|
|
long long f_raw = *(long long*)&f;
|
2004-08-25 02:00:52 -04:00
|
|
|
drepl(tag_object(s48_long_to_bignum(f_raw)));
|
2004-08-06 02:51:32 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL number_eq_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_boolean(x->n == y->n);
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL add_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_object(make_float(x->n + y->n));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL subtract_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_object(make_float(x->n - y->n));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL multiply_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_object(make_float(x->n * y->n));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL divide_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_object(make_float(x->n / y->n));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL divfloat_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_object(make_float(x->n / y->n));
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL less_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_boolean(x->n < y->n);
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL lesseq_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_boolean(x->n <= y->n);
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL greater_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_boolean(x->n > y->n);
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
|
|
|
|
2004-08-25 00:26:49 -04:00
|
|
|
CELL greatereq_float(FLOAT* x, FLOAT* y)
|
2004-08-05 16:49:55 -04:00
|
|
|
{
|
2004-08-25 00:26:49 -04:00
|
|
|
return tag_boolean(x->n >= y->n);
|
2004-08-05 16:49:55 -04:00
|
|
|
}
|
2004-08-06 18:40:44 -04:00
|
|
|
|
|
|
|
void primitive_facos(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(acos(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fasin(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(asin(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fatan(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(atan(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fatan2(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
double x = to_float(dpop())->n;
|
2004-08-06 18:40:44 -04:00
|
|
|
double y = to_float(dpop())->n;
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(tag_object(make_float(atan2(y,x))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fcos(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(cos(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fexp(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(exp(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fcosh(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(cosh(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_flog(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(log(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fpow(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
double x = to_float(dpop())->n;
|
2004-08-06 18:40:44 -04:00
|
|
|
double y = to_float(dpop())->n;
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(tag_object(make_float(pow(y,x))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fsin(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(sin(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fsinh(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(sinh(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_fsqrt(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_object(make_float(sqrt(to_float(dpeek())->n))));
|
2004-08-06 18:40:44 -04:00
|
|
|
}
|