From efece6a4130ab732c4c23c28863d955237d6f1b7 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 22 Jul 2021 21:45:08 -0400 Subject: [PATCH] Handle complex numbers better for numerator/denominator Peel off real part if there is no imaginary part --- runtime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime.c b/runtime.c index 97a68480..9a2c3f46 100644 --- a/runtime.c +++ b/runtime.c @@ -8438,8 +8438,9 @@ void Cyc_get_ratio(void *data, object cont, object n, int numerator) } else if (type_of(n) == bignum_tag) { d = mp_get_double(&bignum_value(n)); } else if (type_of(n) == complex_num_tag) { - // TODO: if i is 0, set d = real part - if (numerator) { + if (cimag(complex_num_value(n)) == 0.0) { + d = creal(complex_num_value(n)); + } else if (numerator) { return_closcall1(data, cont, n); } else { d = 1.0;