Skip to content

Commit

Permalink
Issue #510 - Stage macos compat fix
Browse files Browse the repository at this point in the history
Apparently mp_set_double does not compile on OSX. Need to fix up this portion of the code.
  • Loading branch information
justinethier committed Sep 12, 2023
1 parent 3e3f011 commit 29a2709
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -8572,3 +8572,76 @@ void Cyc_get_ratio(void *data, object cont, object n, int numerator)
return_closcall1(data, cont, &val);
}
}

void Cyc_exact(void *data, object cont, object z)
{
int i = 0;
Cyc_check_num(data, z);
if (obj_is_int(z)) {
i = obj_obj2int(z);
} else if (type_of(z) == integer_tag) {
i = (int)round(((integer_type *)z)->value);
} else if (type_of(z) == bignum_tag) {
return_closcall1(data, cont, z);
} else if (type_of(z) == complex_num_tag) {
double dreal = round(creal(((complex_num_type *) z)->value));
double dimag = round(cimag(((complex_num_type *) z)->value));
make_complex_num(num, dreal, dimag);
return_closcall1(data, cont, &num);
} else {
double d = ((double_type *)z)->value;
if (isnan(d)) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d == INFINITY) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d == -INFINITY) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d > CYC_FIXNUM_MAX || d < CYC_FIXNUM_MIN){
alloc_bignum(data, bn);
BIGNUM_CALL(mp_set_double(&bignum_value(bn), d));
return_closcall1(data, cont, bn);
// TODO: mp_set_double not supported on macos !?!
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
#endif
}
i = (int)round(((double_type *)z)->value);
}
return_closcall1(data, cont, obj_int2obj(i));
}

object Cyc_exact_no_cps(void *data, object ptr, object z)
{
int i = 0;
Cyc_check_num(data, z);
if (obj_is_int(z)) {
i = obj_obj2int(z);
} else if (type_of(z) == integer_tag) {
i = (int)round(((integer_type *)z)->value);
} else if (type_of(z) == bignum_tag) {
return z;
} else if (type_of(z) == complex_num_tag) {
double dreal = round(creal(((complex_num_type *) z)->value));
double dimag = round(cimag(((complex_num_type *) z)->value));
double complex unboxed = dreal + (dimag * I);
assign_complex_num(ptr, unboxed);
return ptr;
} else {
double d = ((double_type *)z)->value;
if (isnan(d)) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d == INFINITY) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d == -INFINITY) {
Cyc_rt_raise2(data, "Expected number but received", z);
} else if (d > CYC_FIXNUM_MAX || d < CYC_FIXNUM_MIN){
alloc_bignum(data, bn);
BIGNUM_CALL(mp_set_double(&bignum_value(bn), d));
return bn;
// TODO: mp_set_double not supported on macos !?!
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
#endif
}
i = (int)round(((double_type *)z)->value);
}
return obj_int2obj(i);
}

0 comments on commit 29a2709

Please sign in to comment.