Running the following code should throw range errors: var num = 1234; var msg = "Before: " + " fixed: " + num.toFixed(50) + "\n" + " exp: " + num.toExponential(50) + "\n" + " prec: " + num.toPrecision(50) alert( msg ); toFixed and toExponential should throw a range error if the argument is less than 0 or greater than 20 and toPrecision should throw a range error if the argument is less than 1 or greater than 21 as per ECMA262v3. I do not know if you are just expanding upon the standard, but it is clear in the standard that an error should be thrown. See: 22.214.171.124 to 7 of the ECMAScript v3 documentation. Jeff http://www.pbwizard.com
Jeff is absolutely correct. Added testcases to JS test suite: mozilla/js/tests/ecma_3/Number/126.96.36.199-1.js mozilla/js/tests/ecma_3/Number/188.8.131.52-1.js mozilla/js/tests/ecma_3/Number/184.108.40.206-1.js Each test currently fails in SpiderMonkey -
OS: Windows 2000 → All
Hardware: PC → All
Reassigning to Kenton -
Assignee: rogerl → khanson
"An implementation is permitted to extend the behaviour of toFixed for values of fractionDigits less than 0 or greater than 20. In this case toFixed would not necessarily throw TangeError for such values" See: 220.127.116.11 of the ECMAScript v3 documentation. "An implementation is permitted to extend the behaviour of toExponential for values of fractionDigits less than 0 or greater than 20. In this case toExponential would not necessarily throw TangeError for such values" See: 18.104.22.168 of the ECMAScript v3 documentation.
Status: NEW → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → WONTFIX
Similarly for toPrecision: 22.214.171.124 Number.prototype.toPrecision (precision) An implementation is permitted to extend the behaviour of toPrecision for values of precision less than 1 or greater than 21. In this case toPrecision would not necessarily throw RangeError for such values.
Marking Verified Wontfix. Will remove or modify the above tests accordingly - Jeff, thank you for this report -
*** Bug 186562 has been marked as a duplicate of this bug. ***
But what is the range for these methods then? Jeff's tests use range up to 50 and still no RangeError! Don't tell me they're supposed to work for up to 100 !? How about range for negative values?
Although the spec permits this variability, other browsers do not take advantage of it. V8, JSC and ChakraCore all use the bounds [0, 21] as in the spec; it seems to be only SpiderMonkey that uses different bounds [-20, 100]. Would it make sense to harmonize with the other browsers here? This would also allow the ECMAScript spec to remove a point of variability among conforming implementations.
10 months ago
See Also: → bug 1068612
You need to log in before you can comment on or make changes to this bug.