Skip to content

Editorial: correct references to negative zero#626

Merged
leobalter merged 3 commits intotc39:masterfrom
bocoup:number-type
Mar 28, 2022
Merged

Editorial: correct references to negative zero#626
leobalter merged 3 commits intotc39:masterfrom
bocoup:number-type

Conversation

@jugglinmike
Copy link
Contributor

"Negative zero" cannot be expressed with an ECMA262 mathematical value,
but it may be expressed with an ECMA262 Number value. Update new
references to "negative zero" to use an appropriate type. Update
corresponding references to "zero" to avoid comparing mathematical
values with Number values.

/cc @bakkot

"Negative zero" cannot be expressed with an ECMA262 mathematical value,
but it may be expressed with an ECMA262 Number value. Update new
references to "negative zero" to use an appropriate type. Update
corresponding references to "zero" to avoid comparing mathematical
values with Number values.

<emu-alg>
1. If _x_ &lt; 0 or _x_ is *-0*<sub>𝔽</sub>, let _isNegative_ be *true*; else let _isNegative_ be *false*.
1. If _x_ &lt; 0<sub>𝔽</sub> or _x_ is *-0*<sub>𝔽</sub>, let _isNegative_ be *true*; else let _isNegative_ be *false*.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is kind of tricky - this operation is generic over both Number and BigInt values, so it's not obviously reasonable to compare against the floating-point 0.

I'd suggest instead:

Suggested change
1. If _x_ &lt; 0<sub>𝔽</sub> or _x_ is *-0*<sub>𝔽</sub>, let _isNegative_ be *true*; else let _isNegative_ be *false*.
1. If ℝ(_x_) &lt; 0 or _x_ is *-0*<sub>𝔽</sub>, let _isNegative_ be *true*; else let _isNegative_ be *false*.

1. Else,
1. Assert: _signDisplay_ is *"exceptZero"*.
1. If _x_ is 0 or _x_ is -0 or _x_ is *NaN*, then
1. If _x_ is 0<sub>𝔽</sub> or _x_ is -0<sub>𝔽</sub> or _x_ is *NaN*, then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This operation is also generic over both Number and BigInt, so

Suggested change
1. If _x_ is 0<sub>𝔽</sub> or _x_ is -0<sub>𝔽</sub> or _x_ is *NaN*, then
1. If _x_ is *NaN* or ℝ(_x_) is 0, then

(ℝ requires its argument to be finite, so we have to rule out the infinities and NaN before calling it. I'm pretty sure the infinities are screened out at the callsite, so I didn't guard against them here, but if I'm wrong this should be or _x_ is finite and ℝ(_x_) is 0.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling attention to the infinities in particular. I don't think those are screened at the call site: PartitionNumberPattern has a branch for them, but it still ends up passing them to this abstract operation.

Is there any ambiguity in the prose, "If A or B and C", though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it's somewhat ambiguous, though I think in this context there's no other coherent reading.

But it's probably best to be more explicit. You can distinguish the cases as in If A, or if B and C, maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

1. If _x_ is 0<sub>𝔽</sub> or _x_ is -0<sub>𝔽</sub> or _x_ is *NaN*, then
1. Let _pattern_ be _patterns_.[[zeroPattern]].
1. Else if _x_ &gt; 0, then
1. Else if _x_ &gt; 0<sub>𝔽</sub>, then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Else if _x_ &gt; 0<sub>𝔽</sub>, then
1. Else if ℝ(_x_) &gt; 0, then

@jugglinmike
Copy link
Contributor Author

Thanks for the review, @bakkot!

@sffc
Copy link
Contributor

sffc commented Nov 20, 2021

I don't get it; in the current spec, _x_ is a Number, not a mathematical value. NFv3 changes it to be an Intl mathematical value.

@bakkot
Copy link
Member

bakkot commented Nov 20, 2021

_x_ is a Number (or BigInt), but 0 is a mathematical value, and -0 isn't anything. So saying _x_ is 0, as the spec text does without this PR, doesn't really mean anything - it's comparing an ES language value with a mathematical value. This PR changes it so that the comparisons (at least those it touches) are all between like types.

@leobalter leobalter merged commit d4be24e into tc39:master Mar 28, 2022
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.

4 participants