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

Range with NaN, Infinity #12

Closed
sffc opened this issue Apr 29, 2020 · 5 comments
Closed

Range with NaN, Infinity #12

sffc opened this issue Apr 29, 2020 · 5 comments
Labels
has-consensus Has consensus and ready to implement

Comments

@sffc
Copy link
Collaborator

sffc commented Apr 29, 2020

I think we should probably forbid NaN and Infinity from taking part in a number range format. What would be your expected behavior in these cases?

new Intl.NumberFormat().formatRange(10, NaN);
new Intl.NumberFormat().formatRange(10, Infinity);

The first case makes no sense. The second case could be an interesting application of the "greater than" pattern, but that's not yet supported in ICU.

For now, better to throw a RangeError. We can remove that restriction later if we ever needed to.

@ryzokuken
Copy link
Member

I agree that throwing a RangeError seems rather reasonable in both cases, unless infinite ranges are explicitly supported (I don't really think we need to, though, since I don't know of any applications outside of abstract mathematics, but some use cases for infinite ranges would make me change my mind).

@FrankYFTang
Copy link
Contributor

I agree with the NaN should throw RangeError, but I disagree with Infinity.

d8> a = new Intl.NumberFormat()
[object Intl.NumberFormat]
d8> a.formatRange(0, Infinity)
"0–∞"
d8> a.formatRange(-Infinity, Infinity)
"-∞ – ∞"
d8> a.formatRange(-Infinity, 3)
"-∞ – 3"
d8> a.formatRange(-5 , Infinity)
"-5 – ∞"

looks reasonable to me. Why should we prohibit that?

@sffc
Copy link
Collaborator Author

sffc commented Aug 5, 2020

My reasoning was that we might eventually want something like "5+" or "≥5" for formatRange(5,Infinity), but ICU doesn't support that yet. But, if we adopted the current behavior, we could add these other styles via an option.

@sffc sffc added the discuss Needs discussion to make progress label Oct 8, 2020
@sffc
Copy link
Collaborator Author

sffc commented Oct 8, 2020

2020-10-08: Throw on NaN; allow Infinity and -Infinity.

@sffc sffc added has-consensus Has consensus and ready to implement and removed discuss Needs discussion to make progress labels Oct 8, 2020
@sffc
Copy link
Collaborator Author

sffc commented Oct 8, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-consensus Has consensus and ready to implement
Projects
None yet
Development

No branches or pull requests

3 participants