Issue #510 - Exact support for complex nums

Allow `exact` to properly handle complex numbers
This commit is contained in:
Justin Ethier 2023-09-11 19:02:28 -07:00
parent e8ba3f1c1b
commit 7dc1f9e179
2 changed files with 10 additions and 2 deletions

View file

@ -517,7 +517,10 @@ int Cyc_have_mstreams();
} else if (type_of(z) == bignum_tag) { \ } else if (type_of(z) == bignum_tag) { \
return_closcall1(data, cont, z); \ return_closcall1(data, cont, z); \
} else if (type_of(z) == complex_num_tag) { \ } else if (type_of(z) == complex_num_tag) { \
return_closcall1(data, cont, z); \ double dreal = OP(creal(((complex_num_type *) z)->value)); \
double dimag = OP(cimag(((complex_num_type *) z)->value)); \
make_complex_num(num, dreal, dimag); \
return_closcall1(data, cont, &num); \
} else { \ } else { \
double d = ((double_type *)z)->value; \ double d = ((double_type *)z)->value; \
if (isnan(d)) { \ if (isnan(d)) { \
@ -548,7 +551,11 @@ int Cyc_have_mstreams();
} else if (type_of(z) == bignum_tag) { \ } else if (type_of(z) == bignum_tag) { \
return z; \ return z; \
} else if (type_of(z) == complex_num_tag) { \ } else if (type_of(z) == complex_num_tag) { \
return z; \ double dreal = OP(creal(((complex_num_type *) z)->value)); \
double dimag = OP(cimag(((complex_num_type *) z)->value)); \
double complex unboxed = dreal + (dimag * I); \
assign_complex_num(ptr, unboxed); \
return ptr; \
} else { \ } else { \
double d = ((double_type *)z)->value; \ double d = ((double_type *)z)->value; \
if (isnan(d)) { \ if (isnan(d)) { \

View file

@ -65,6 +65,7 @@
(test -1 (exact -1.0)) (test -1 (exact -1.0))
(test -1 (exact -1.1)) (test -1 (exact -1.1))
(test -1 (exact -1.1)) (test -1 (exact -1.1))
(test 1.0+1.0i (exact 1.1+1.2i))
(test #t (bignum? (exact 111111111111111111111111111.0))) (test #t (bignum? (exact 111111111111111111111111111.0)))
(test #t (bignum? (exact -111111111111111111111111111.0))) (test #t (bignum? (exact -111111111111111111111111111.0)))
;(test +inf.0 (exact +inf.0)) ;(test +inf.0 (exact +inf.0))