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

Show -0.0 sign #236

Closed
wants to merge 1 commit into from
Closed

Conversation

kl0tl
Copy link
Member

@kl0tl kl0tl commented Dec 20, 2020

Close #152.

@hdgarrood
Copy link
Contributor

Ah, I’m more conflicted about this after looking at the diff and realising that JS’s .toString doesn’t include the minus sign for negative zero. I can definitely see this causing breakage at runtime without warning. I’ll see if I can find anything about this in IEEE 754.

@hdgarrood
Copy link
Contributor

It turns out IEEE 754 doesn't say anything about functions like .toString() for formatting floating point numbers as strings for display.

@kl0tl
Copy link
Member Author

kl0tl commented Dec 22, 2020

If we don’t infringe IEEE 754 by showing positive and negative zeroes differently is there any reason not to do it?

@hdgarrood
Copy link
Contributor

I think the reasons not to do it are that a) people may be relying on the current behaviour, and b) there might be a good reason why JS's .toString() doesn't distinguish positive and negative zero, and I'd like to look into that first. It's probably worth seeking out some examples of the stance other languages have taken on this question and what conclusions they came to. This is definitely not a decision we'll want to rush; much as I'd prefer this wasn't the case, in practice people will be using Show Number for a whole lot of different things beyond just debugging and the repl.

@hdgarrood
Copy link
Contributor

rust-lang/rust#20596 and rust-lang/rfcs#1074 are relevant

@JordanMartinez
Copy link
Contributor

This comment in runt-lang/rfcs#1074 shows how most popular languages handle this.

One could get around this problem by specifying a newtype that will always include the sign, but that seems like overkill.

@kl0tl
Copy link
Member Author

kl0tl commented Dec 23, 2020

I suspect that Number.prototype.toString hides the sign of negative zero to not leak its existence to end users? You’re right that people are probably using Show to display numbers in user interfaces (I certainly did it myself 😬). Perhaps we should rather make your Debug class the default in the REPL, show the sign of negative zero there and even deprecate Show if we’re feeling bold.

@hdgarrood
Copy link
Contributor

I would love to deprecate Show in favour of Debug eventually, yes.

@kl0tl
Copy link
Member Author

kl0tl commented Dec 23, 2020

Let’s close this for now and reconsider when replacing Show with Debug then?

@hdgarrood
Copy link
Contributor

Works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should show (-0.0) produce "-0.0"?
3 participants