abs computes magnitude for complex nums

Instead of raising an error use C99 function to compute the magnitude instead. This is more useful and seems more correct as well.
This commit is contained in:
Justin Ethier 2023-09-11 19:13:08 -07:00
parent 0cad4cef8c
commit 3e3f0114e5
2 changed files with 3 additions and 2 deletions

View file

@ -7,7 +7,7 @@ Bug Fixes
- Fix `exact` to properly handle complex numbers, including raising an error when passed `nan` or `inf` double values.
- Ensure the runtime properly differentiates between `+inf.0` and `-inf.0`. Thanks to jpellegrini for the bug report.
- jpellegrini reported that Cyclone returns `#f` when comparing complex numbers using operators other than `=`. Instead it is better to raise an error in these situations.
- lassik and jpellegrini reported that `abs` was incorrectly returning the real part of a complex number argument. Modified `abs` to return an error for complex numbers.
- lassik and jpellegrini reported that `abs` was incorrectly returning the real part of a complex number argument. Modified `abs` to properly handle complex numbers.
- jpellegrini fixed `(srfi 143)` so that the following are constants instead of procedures: `fx-width`, `fx-greatest`, and `fx-least`.
- Raise an error if `odd?` or `even?` is passed a decimal number. Thanks to jpellegrini for the bug report.
- Fix `read-line` to read entire lines that consist of more than 1022 bytes. Previously the function would only return partial data up to this limit. Thanks to Robby Zambito for the bug report.

View file

@ -1400,7 +1400,8 @@
BIGNUM_CALL(mp_abs(&bignum_value(num), &bignum_value(bn)));
return_closcall1(data, k, bn);
} else if (is_object_type(num) && type_of(num) == complex_num_tag){
Cyc_rt_raise2(data, \"Unable to compute absolute value of complex number\", num);
make_double(d, cabs(((complex_num_type *)num)->value));
return_closcall1(data, k, &d);
} else {
make_double(d, fabs(((double_type *)num)->value));
return_closcall1(data, k, &d);