toFixed, toExponential and toPrecision not throwing range errors

VERIFIED WONTFIX

Status

()

Core
JavaScript Engine
VERIFIED WONTFIX
17 years ago
10 months ago

People

(Reporter: Jeff Yates, Assigned: Kenton Hanson (gone))

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

17 years ago
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: 15.7.4.5 to 7 of the ECMAScript v3 documentation.


Jeff
http://www.pbwizard.com

Comment 1

17 years ago
Jeff is absolutely correct. Added testcases to JS test suite: 

           mozilla/js/tests/ecma_3/Number/15.7.4.5-1.js
           mozilla/js/tests/ecma_3/Number/15.7.4.6-1.js
           mozilla/js/tests/ecma_3/Number/15.7.4.7-1.js


Each test currently fails in SpiderMonkey -
OS: Windows 2000 → All
Hardware: PC → All

Comment 2

17 years ago
Reassigning to Kenton - 
Assignee: rogerl → khanson
(Assignee)

Comment 3

17 years ago
"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: 15.7.4.5 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: 15.7.4.6 of the ECMAScript v3 documentation.
Status: NEW → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → WONTFIX

Comment 4

17 years ago
Similarly for toPrecision:


15.7.4.7 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. 

Updated

17 years ago
Status: RESOLVED → VERIFIED

Comment 5

17 years ago
Marking Verified Wontfix. Will remove or modify the above tests accordingly -
Jeff, thank you for this report - 

Comment 6

15 years ago
*** 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?

Comment 8

10 months ago
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.
You need to log in before you can comment on or make changes to this bug.