archives

« Bugzilla Issues Index

#301 — 15.7.4.6: Bugs in Number.prototype.toExponential algorithm


When this Number value is 0 and fractionDigits > 0, according to the algorithm in 15.7.4.6, result is wrong. For example, here are the steps taken for (0).toExponential(1):

1. x = 0
2. f = 1
3. skip
4. s = ""
5. skip
6. skip
7. skip
8. then
a. f = 0
b. m = "0"
c. e = 0
9. skip
10. skip
11. then
a. c = "+"
b. d = "0"
12. skip
13. m = "0e+0"
14. return "0e+0"


The step 8.a "a. Let f = 0." should be "a. if fractionDigits is undefined, then let f = 0.".


see https://mail.mozilla.org/pipermail/es-discuss/2012-March/021095.html


(reclassified as a technical content issue)

This is apparently a bug introduced when the ES3 algorithm was restructured for ES5.

Line 8.a should read:
a. If fractionDigit is undefined, then Let f = 0.


it's also valid to simply delete step 8.a because f is already 0 when fractionDigit is undefined.


Fixed in ES2015.