mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Issue #510 - Exact conversion of large doubles
Allow `exact` to convert large double values to bignums.
This commit is contained in:
parent
f8fbb9ad7d
commit
e8ba3f1c1b
2 changed files with 21 additions and 6 deletions
|
@ -517,6 +517,7 @@ int Cyc_have_mstreams();
|
|||
} else if (type_of(z) == bignum_tag) { \
|
||||
return_closcall1(data, cont, z); \
|
||||
} else if (type_of(z) == complex_num_tag) { \
|
||||
return_closcall1(data, cont, z); \
|
||||
} else { \
|
||||
double d = ((double_type *)z)->value; \
|
||||
if (isnan(d)) { \
|
||||
|
@ -525,15 +526,15 @@ int Cyc_have_mstreams();
|
|||
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); \
|
||||
} \
|
||||
i = (int)OP(((double_type *)z)->value); \
|
||||
} \
|
||||
return_closcall1(data, cont, obj_int2obj(i))
|
||||
|
||||
// TODO: truncate complex number components
|
||||
// TODO: what if double is outside fixnum range??
|
||||
// need to convert to a bignum
|
||||
|
||||
/**
|
||||
* Directly compute exact
|
||||
*/
|
||||
|
@ -546,13 +547,25 @@ int Cyc_have_mstreams();
|
|||
i = (int)OP(((integer_type *)z)->value); \
|
||||
} else if (type_of(z) == bignum_tag) { \
|
||||
return z; \
|
||||
} else if (type_of(z) == complex_num_tag) { \
|
||||
return z; \
|
||||
} 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; \
|
||||
} \
|
||||
i = (int)OP(((double_type *)z)->value); \
|
||||
} \
|
||||
return obj_int2obj(i);
|
||||
|
||||
// TODO: sync changes from above CPS macro
|
||||
|
||||
/**
|
||||
* Take Scheme object that is a number and return the number as a C type
|
||||
*/
|
||||
|
|
|
@ -65,6 +65,8 @@
|
|||
(test -1 (exact -1.0))
|
||||
(test -1 (exact -1.1))
|
||||
(test -1 (exact -1.1))
|
||||
(test #t (bignum? (exact 111111111111111111111111111.0)))
|
||||
(test #t (bignum? (exact -111111111111111111111111111.0)))
|
||||
;(test +inf.0 (exact +inf.0))
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue