Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upEditorial: use "is 0" instead of "is zero" for consistency #1086
Conversation
This comment has been minimized.
This comment has been minimized.
I suggest 0, but please record the resolution in tc39/proposal-bigint#10. |
This comment has been minimized.
This comment has been minimized.
LGTM. I like this change for a better consistency and the well observed change on the literalSegments check for String.raw. |
This comment has been minimized.
This comment has been minimized.
Note that if Of course, if |
This comment has been minimized.
This comment has been minimized.
@jmdyck I think
If the specs requires strict comparisons to positive or negative zero, this is and should be always explicit. The |
This comment has been minimized.
This comment has been minimized.
@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". |
This comment has been minimized.
This comment has been minimized.
I’m content with anything that’s unambiguous and consistent. Would “is zero” remove the potential interpretation that it’s only comparing to +0? |
This comment has been minimized.
This comment has been minimized.
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? |
This comment has been minimized.
This comment has been minimized.
That sounds fine too - I could also replace all these cases with |
This comment has been minimized.
This comment has been minimized.
"is ±0", "is not ±0"? |
This comment has been minimized.
This comment has been minimized.
I like PLUS-MINUS SIGN, yeah, good call. |
This comment has been minimized.
This comment has been minimized.
Great, I'll update all of these to match that. |
This comment has been minimized.
This comment has been minimized.
hmm, that doesn't really work for the conceptual places like when they're talking about string length. Would using |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bterlson cool, i'll use |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
From ECMA/TC39/97/24, Notes from the 2/14/1997 ECMAScript 1st Edition Drafting Working Group Meeting:
|
This comment has been minimized.
This comment has been minimized.
That suggests that a |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
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) |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
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.
Now that BigInt has merged, I've rebased this. Rereview would be appreciated. |
There's one more occurrence of "is zero", under |
This comment has been minimized.
This comment has been minimized.
(Should have included this in my review:) All occurrences of (The |
This comment was marked as resolved.
This comment was marked as resolved.
@ljharb Can you rebase and resolve conflicts? |
This comment was marked as resolved.
This comment was marked as resolved.
@ljharb It seems you've missed two uses of "zero" in 21.2.2.5.1 Runtime Semantics: RepeatMatcher that would be appropriate to change. |
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*. |
This comment has been minimized.
This comment has been minimized.
bakkot
Nov 13, 2019
Contributor
Hm, I'm not sure about this change. BigIntBitwiseOp, the caller of these operations, deals with unsuffixed numbers.
This comment has been minimized.
This comment has been minimized.
jmdyck
Nov 14, 2019
Collaborator
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".)
ljharb commentedJan 29, 2018
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.