-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: use "is 0" instead of "is zero" for consistency #1086
Conversation
I suggest 0, but please record the resolution in tc39/proposal-bigint#10. |
LGTM. I like this change for a better consistency and the well observed change on the literalSegments check for String.raw. |
Note that if Of course, if |
@jmdyck I think
If the specs requires strict comparisons to positive or negative zero, this is and should be always explicit. The |
@leobalter: Relying on the Mathematical Operations clause to resolve this question requires you to say that "is" is a mathematical operation, which is a stretch just on its own, but also inconsistent with the spec's many non-mathematical uses of "is". |
I’m content with anything that’s unambiguous and consistent. Would “is zero” remove the potential interpretation that it’s only comparing to +0? |
Am I alone in thinking we should avoid depending on "mathematical values" if at all possible (in part because the long-standing question about whether/how they exist) and just go with explicit +/- 0? Or, define a term like "the value zero" which is just +0 and -0? |
That sounds fine too - I could also replace all these cases with |
"is ±0", "is not ±0"? 👍 |
I like PLUS-MINUS SIGN, yeah, good call. |
Great, I'll update all of these to match that. |
hmm, that doesn't really work for the conceptual places like when they're talking about string length. Would using |
@bterlson you are not alone, but the general problem is pretty endemic in the spec right now (see tc39/proposal-bigint#10 as mentioned by @jmdyck upthread). But yeah, if you think it's reasonable to make a piecemeal fix for these cases instead of waiting on the big-ol'-refactor that I'm sure @littledan will be contributing any day now, that seems like a good move. |
@bterlson cool, i'll use |
Isn't this all a matter of context? If you compare an ECMAScript value to "zero" you must be dealing with ECMAScript number values not mathematical values. If you are comparing a value that was computed using a mathematical formula then you are comparing to a mathematical 0. The context is usually pretty clear. If you are testing a mathematical value to see if it is mathematically equal to 0 you should use the mathematical = operator and the numeral 0. If you are testing an ECMAScript Number value x to see if it is a number value you should say: "if x is 0" meaning x is either the number value +0 or the number value -0; "if x is +0" meaning x is the number value +0 but not the number value -0; or, "if x is -0" meaning x is the number value -0 but not the number value +0. I think these meanings should be pretty obvious but if you want to explicitly explain them somewhere the 5th paragraph of Number Type seem like a fine place. Never use "is zero" in an algorithm or formula. It may be appropriate in some prose paragraphs that aren't explicitly talking about either number values or mathematical values. I checked the current draft. There appears to be 7 occurrences of "is zero" in an algorithm (or algorithm-like table). They all appear to be very old text that was never updated. They should all be fixed. I think that using ±0 in place of 0 would just be adding noise to the specification. |
From ECMA/TC39/97/24, Notes from the 2/14/1997 ECMAScript 1st Edition Drafting Working Group Meeting:
|
That suggests that a |
@ljharb Actually, don't think a comment about a 1997 draft suggests anything about the current specification. The specification and its conventions have changed drastically in the last 21 years... However, I did think it highly assuming, in the context of this thread, that I ran into it this afternoon. Had to share the fun. |
There are a lot of contexts where it isn't clear, i.e. where a numeric quantity is neither the result of a mathematical formula nor obviously an ES language value. E.g., consider
With any of these, it's unclear whether Moreover, even when a quantity is defined with a mathematical formula, and so should be a mathematical value, it's not so clear. Consider the example given by @littledan in tc39/proposal-bigint#10: Array.prototype.indexOf has the step |
@jmdyck
doesn't explicitly say be "Let x be -0" so clearly this is either an implicit +0 number value or a mathematical unsigned 0 value. If it isn't clear from context needs to be clarified. I haven't look at all such uses but in my sampling I haven't seen any needing to clarification.
https://tc39.github.io/ecma262/#sec-abstract-relational-comparison Even without additional context, it is clear that in the following fragments the values could never be -0
Turning all occurrences of "0" into either "±0", "+0", or "-0" going to force consideration of the possibility of signed 0 into many places within the specification where the concept of signed 0 is not at all relevant. Seems to me that it would only make things less clear then they already are. |
It's interesting that you find all of those clear from context, Allen. I don't find it clear at all. Edit: I guess you are talking about +0 vs. -0, but I was talking about mathematical number value vs. ES number value, which is @jmdyck's point. |
Which ones are unclear to you? Don't see how counting integer values or bit values could possibly involve a IEEE 768 -0 value (or an Infinity or a NaN) |
I've always treated mathematical values and Number values as interchangeable, as long as the specific value is well-defined for both types. And this seems to be the case for the Well, if we want to be super correct, more problematic is |
I count 80 occurrences of
Knowing that a numeric value can't be -0 doesn't tell you whether it's a Number value or a mathematical value. |
This comment has been minimized.
This comment has been minimized.
spec.html
Outdated
1. Assert: _y_ is 0 or 1. | ||
1. If _x_ is 1 and _y_ is 1, return 1. | ||
1. Else, return 0. | ||
1. Assert: _x_ is *0n* or *1n*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'm not sure about this change. BigIntBitwiseOp, the caller of these operations, deals with unsuffixed numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, those should probably be changed as well (in this PR or not, I don't mind). (Presumably this PR didn't touch BigIntBitwiseOp because it doesn't have any occurrences of "is zero" or "is 0".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has been completely overtaken by the merge of PR #2007, and should probably just be closed.
There's still one occurrence left of "is zero" that should be an explicit number; I've rebased this PR with that one change intact. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WFM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objection.
Discovered here.
The spec seems to use
is 0
most often for comparing to zero, specifically with the results of aToLength
call, which can not return anything<= 0
besides positive zero.An equally valid and consistent alternative would be replacing all the
is 0
instances withis zero
, if we'd find that clearer.