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

Complex.zero returns unexpeceted #sign #11700

Closed
jkthorne opened this issue Jan 5, 2022 · 5 comments · Fixed by #12242
Closed

Complex.zero returns unexpeceted #sign #11700

jkthorne opened this issue Jan 5, 2022 · 5 comments · Fixed by #12242
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric

Comments

@jkthorne
Copy link
Contributor

jkthorne commented Jan 5, 2022

Bug Report

Some Complex numbers that have zeros return 0 and 0i but on the default zero case it returns NaN and NaNi. This was unexpected to me. After bringing it up on Discord it seems like it might be a bug.

Here is an example of an expected 0 sign. https://play.crystal-lang.org/#/r/cjvt

require "complex"

p Complex.new(1, 0).sign

output:

(1.0 + 0.0i)

Here is the case I am not sure if it is correct. https://play.crystal-lang.org/#/r/cjvv

require "complex"

p Complex.zero.sign

output

(-NaN - -NaNi)
@jkthorne jkthorne added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jan 5, 2022
@martinhart
Copy link

Forgive me if I'm not fully understanding the problem, but what would we expect the correct output to be here? #sign is currently implemented using division, and division by 0 is resulting in NaN in this case.

@asterite
Copy link
Member

I think (0, 0) is expected to be returned.

That said, sign for Complex is a bit strange, I think we should remove that method.

@beta-ziliani
Copy link
Member

According to the wikipedia

For reasons of symmetry, and to keep this a proper generalization of the signum function on the reals, also in the complex domain one usually defines, for z = 0:
sgn ⁡ ( 0 + 0 i ) = 0

So I would classify this as an outright bug. @wontruefree out of curiosity, what brought you to this function?

@jkthorne
Copy link
Contributor Author

@beta-ziliani I have been looking for undocumented and under documented features and trying to understand them and add docs for them

@beta-ziliani
Copy link
Member

My physicist wife tells me this function is useful to have, so it's better to fix it and document it.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants