Closed Bug 1068612 Opened 10 years ago Closed 9 years ago

toPrecision accepts arguments that are larger than 21

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: bzbarsky, Unassigned)

References

Details

Per spec, this should throw RangeError:

  (123.445).toPrecision(55)

though it _is_ kinda useful that it works... ;)
This is allowed per ES5.1, ch. 16 and ES6-draft, ch. 16 [1]:

> An implementation may define behaviour other than throwing RangeError for
> toFixed, toExponential, and toPrecision when the fractionDigits or
> precision argument is outside the specified range.


[1] https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error-handling-and-language-extensions
Gah.  Then why is that not specified in the toPrecision algorithm itself?  This sort of spec monkeypatching is ridiculous.  :(
The allowed extensions are also mentioned after the algorithms for toPrecision() and friends [1]. Maybe an additional in-line note in the actual algorithm should be added?

[1] https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.prototype.toprecision
Yeah.  That would be a lot better than this COMEFROM style of specification.
Resolving as Won't Fix - Higher precision is allowed per spec.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WONTFIX
I think it could still make sense to revisit this; posted a little more at https://bugzilla.mozilla.org/show_bug.cgi?id=90551#c8 (sorry, not sure how to mark it as a duplicate here). Does anyone have an idea what the motivation for the larger range beyond integer precision is? If the larger range is useful, it could be implemented in other engines and standardized that way.
See Also: → 90551
You need to log in before you can comment on or make changes to this bug.