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

Specify the with-fractional-digits protocol #177

Closed

Conversation

jessealama
Copy link
Collaborator

No description provided.

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.
Copy link
Member

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().

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a 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.

spec.emu Outdated Show resolved Hide resolved
Comment on lines +1370 to +1371
<h1>get %WithFractionalDigitsPrototype%.precision</h1>
<p>The <q>precision</q> that the number is understood to have.</p>
Copy link
Member

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/

Copy link
Collaborator Author

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.

spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
spec.emu Outdated Show resolved Hide resolved
Comment on lines +1401 to +1402
1. Perform ? RequireInternalSlot(_O_, [[Prototype]]).
1. If _O_.[[Prototype]] is not %WithFractionalDigitsPrototype%, throw an *TypeError* exception.
Copy link
Member

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"*).
Copy link
Member

Choose a reason for hiding this comment

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

This can throw

Comment on lines +1408 to +1409
1. Set _options_.[[minimumFractionalDigits]] to _P_.
1. Set _options_.[[maximumFractionalDigits]] to _P_.
Copy link
Member

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.

spec.emu Outdated Show resolved Hide resolved
jessealama added a commit to nicolo-ribaudo/proposal-numeric-with-precision that referenced this pull request Sep 20, 2024
@jessealama
Copy link
Collaborator Author

closing in favor of nicolo-ribaudo/proposal-numeric-with-precision#1 .

@jessealama jessealama closed this Sep 22, 2024
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.

3 participants