-
Notifications
You must be signed in to change notification settings - Fork 18
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
Specify the with-fractional-digits protocol #177
Specify the with-fractional-digits protocol #177
Conversation
fe2f84e
to
3481c4d
Compare
1. If _digits_ is not a Number, throw a *TypeError* exception. | ||
1. If _digits_ is *NaN*<sub>𝔽</sub>, *+∞<sub>𝔽</sub>*, or *+∞<sub>𝔽</sub>*, throw a *RangeError* exception. | ||
1. If ℝ(_digits_) is not an integer, throw a *TypeError* exception. | ||
1. IF ℝ(_digits_) < 0, throw a *RangeError* exception. |
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.
The name .withFractionalDigits
might not be ideal, but it'd be great to allow negative numbers here.
1234..withFractionalDigits(1)
is 1234.0
, and 1234..withFractionalDigits
is 123e1
.
Let's see if this is desired though. If nobody cares it's fine to throw for simmetry with .toFixed()
.
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 will need also changes in the Intl integration.
<h1>get %WithFractionalDigitsPrototype%.precision</h1> | ||
<p>The <q>precision</q> that the number is understood to have.</p> |
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.
The reason I called this .fractionalDigis
is because it's a different concept of "precision" from the .toPrecision()
method (once starts counting from the units, the other one from the most-significant digit).
Also, I really dislike .number
exactly because it might not be a .number
value. I would make it explicit that the naming is very much open for bikeshed between Stage 2 and 2.7/
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.
Agree. I'm not happy with the names, either. I chose "precision" because that's what we use instead of "quantum". I'm happy to just roll with these names and bikeshed later.
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
1. Perform ? RequireInternalSlot(_O_, [[Prototype]]). | ||
1. If _O_.[[Prototype]] is not %WithFractionalDigitsPrototype%, throw an *TypeError* exception. |
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.
Also change the brand check here
1. If _options_ is not an Object, throw a *TypeError* exception. | ||
1. Let _N_ be ! Get(_O_, *"number"*). | ||
1. Let _P_ be ! Get(_O_, *"precision"*). | ||
1. Let _toLocaleString_ be ! Get(_N_, *"toLocaleString"*). |
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 can throw
1. Set _options_.[[minimumFractionalDigits]] to _P_. | ||
1. Set _options_.[[maximumFractionalDigits]] to _P_. |
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.
These should be properties, not internal slots.
Also, I am thinking that probably it would be better to not install extra properties on a user-provided config object. Instead, we should leave the implementation of this .toLocaleString
to be ECMA-402 defined, and then in ECMA-402 we do we use this.[[Precision]]
as a fallback for when there is no minimum/maximumFractionalDigits
specified in the options.
This fallback should happen in NumberFormat.prototype.format
(which will receive the WithFractionalDigits object as an argument), and it should check if the constructor had the option explicitly set.
Co-authored-by: Michael Ficarra <[email protected]>
Essentially copied from tc39/proposal-decimal#177 .
closing in favor of nicolo-ribaudo/proposal-numeric-with-precision#1 . |
No description provided.