Comments (10)
@romulocintra I'm assigning this issue to you to fix in corrdination with #72. I think once we update the proposal to use the |StringNumericLiteral|
grammar as @bakkot proposed, this issue will be fixed.
We should also add Test262 for this behavior, of course.
from proposal-intl-numberformat-v3.
Hmm, interesting question.
I don't necessarily see anything wrong with accepting "0x10"
. It's an interesting side-effect of the way I implemented ToIntlMathematicalValue
.
I'd like if an editor (@ryzokuken?) could take a closer look at ToIntlMathematicalValue
and provide feedback here.
https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-tointlmathematicalvalue
from proposal-intl-numberformat-v3.
CC @bakkot, @ljharb, and @waldemarhorwat to take a closer look at ToIntlMathematicalValue
.
from proposal-intl-numberformat-v3.
Hmm, "0x10"
was probably a bad example, because that's already supported now. Larger number strings like "0x20000000000001"
are more interesting, because there's only a difference when the number is larger than Number.MAX_SAFE_INTEGER
.
from proposal-intl-numberformat-v3.
Given https://github.com/tc39/proposal-intl-numberformat-v3#interpret-strings-as-decimals-ecma-402-334, I take it the intention is to allow arbitrary numeric strings to be interpreted precisely, not just those strings which are precisely representable as Numbers?
If so, the current spec text does not do that. In particular, ToIntlMathematicalValue step 6 is Let mv be the MV, a mathematical value, of ? ToNumber(str), as described in 7.1.4.1.1.
This passes through ToNumber, which means that it loses precision.
I'm happy to suggest a change to the spec text to make it handle precise values in binary, octal, decimal, and hex, (i.e. the current formats), if that's the intention. (I think there might be implementability concerns with that, but that's not my area.)
from proposal-intl-numberformat-v3.
If so, the current spec text does not do that. In particular, ToIntlMathematicalValue step 6 is
Let mv be the MV, a mathematical value, of ? ToNumber(str), as described in 7.1.4.1.1.
This passes through ToNumber, which means that it loses precision.
The intent of that section was to extract the private variable called MV out of ToNumber before it gets flattened into a Number. In other words, leverage the string grammar, but keep the full precision mathematical value.
About non-decimal strings (binary, octal, hex): Precise values in decimal is the primary use case, and is what ICU handles. The use case is not as strong for binary, octal, and hex. If they are easy to implement in the browser engine, I think we should go for it, but if it presents challenges, then it's fine to call it out of scope.
@FrankYFTang thoughts?
from proposal-intl-numberformat-v3.
If they are easy to implement in the browser engine, I think we should go for it, but if it presents challenges, then it's fine to call it out of scope.
It's (currently) not difficult to implement, because right now all non-decimal number strings are guaranteed to be integers, so implementations can simply parse them as BigInts. Should we ever support the hexadecimal floating point notation (e.g. 0x1.24p0
), more work will be necessary.
from proposal-intl-numberformat-v3.
Discussion 2021-11-04: https://github.com/tc39/ecma402/blob/master/meetings/notes-2021-11-04.md#should-tointlmathematicalvalue-accept-non-decimal-number-strings
Consensus: "I think we should accept all grammars currently accepted, and the only behavior difference is that we should resolve the numerical values to be mathematical values, instead of downcasting them to Number."
from proposal-intl-numberformat-v3.
@sffc the issue that's linked from that discussion has a typo in it, "proposal" => "proposals"; but it also points to 4 year old issue about method shorthand that was closed for "wrong venue". Can we get a corrected link? Thanks!!
from proposal-intl-numberformat-v3.
The link should point back to this issue. Fixed.
from proposal-intl-numberformat-v3.
Related Issues (20)
- Intl.PluralRules does not have the [[RoundingMode]] internal slot required by FormatNumericToString HOT 2
- `formatRangeToParts` produces an empty `source` when `FormatApproximately` is used HOT 2
- FormatNumericToString - isNegative first value clarification HOT 2
- Ordinal formating in NumberFormat HOT 2
- useGrouping's Note is inconsistent with the actual code HOT 1
- ResolvePluralRange does not account for approximately formatted ranges HOT 2
- Clarify that literals can be changed in CollapseNumberRange
- Should "approximatelySign" be renamed to "approximateSign"? HOT 1
- Can the order in which properties are read be more comprehensible? HOT 8
- Can ToRawPrecision and ToRawFixed be made more deterministic? HOT 1
- String(Intl)MV should be defined in ECMA-262 HOT 2
- `FormatNumericToString` will errantly convert -0 to +0 then back to -0 before calling `ToRaw[Precision|Fixed]` HOT 1
- Missing 𝔽 subscript for -0 in FormatNumericToString
- Meta: cross-references are gone
- Simplify PartitionNumberRangePattern
- Hard time to implement IntlMathematicalValue HOT 12
- Clarification on what "precision" means in roundingPriority: morePrecision/lessPrecision HOT 4
- Only passing `roundingIncrement` will throw an error. HOT 3
- Limit exponent of intl mathematical value HOT 7
- Lack of [[Source]] in FormatNumericRangeToParts if returned by FormatApproximately HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-intl-numberformat-v3.