Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Complex#to_s imaginary component sign for certain values #12244

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Jul 10, 2022

Some special values of a Complex's imaginary component cause it to print an incorrect sign:

  • -0.0+ -0.0 (should be - 0.0)
  • +NaN- NaN (should be + NaN)
  • -NaN- -NaN (should be + NaN)

This PR fixes those edge cases by extracting the intrinsic sign with Math.copysign.

I don't think the rest of the standard library has the same issue, but this is something to keep in mind if we decide to implement %+f etc. for String::Formatter in pure Crystal.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric topic:stdlib:text labels Jul 10, 2022
@straight-shoota straight-shoota added this to the 1.6.0 milestone Aug 13, 2022
@HertzDevil HertzDevil marked this pull request as draft August 16, 2022 15:19
@HertzDevil HertzDevil marked this pull request as ready for review August 18, 2022 13:24
@straight-shoota straight-shoota added this to the 1.6.0 milestone Aug 18, 2022
@straight-shoota straight-shoota merged commit 3423767 into crystal-lang:master Aug 29, 2022
@HertzDevil HertzDevil deleted the bug/complex-to_s-neg-imag branch August 29, 2022 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric topic:stdlib:text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants