« Bugzilla Issues Index
#301 — 15.7.4.6: Bugs in Number.prototype.toExponential algorithm
- bug_id:
301
- creation_ts:
2012-03-10 00:01:00 -0800
- short_desc:
15.7.4.6: Bugs in Number.prototype.toExponential algorithm
- delta_ts:
2015-10-03 14:34:10 -0700
- product:
ECMA-262, Editions 5 and 5.1
- component:
technical content
- version:
Edition 5.1
- rep_platform:
All
- op_sys:
All
- bug_status:
RESOLVED
- resolution:
FIXED
- priority:
Normal
- bug_severity:
normal
- blocked:
305
- everconfirmed:
true
- reporter:
Jin DX
- assigned_to:
Allen Wirfs-Brock
- cc:
brterlso
- commentid:
743
- comment_count:
0
- who:
Jin DX
- bug_when:
2012-03-10 00:01:58 -0800
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.".
- commentid:
746
- comment_count:
1
- who:
Jin DX
- bug_when:
2012-03-10 07:39:41 -0800
see https://mail.mozilla.org/pipermail/es-discuss/2012-March/021095.html
- commentid:
750
- comment_count:
2
- who:
Allen Wirfs-Brock
- bug_when:
2012-03-12 17:51:38 -0700
(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.
- commentid:
4369
- comment_count:
3
- who:
Allen Wirfs-Brock
- bug_when:
2013-07-11 17:12:29 -0700
it's also valid to simply delete step 8.a because f is already 0 when fractionDigit is undefined.
- commentid:
14758
- comment_count:
4
- who:
Brian Terlson
- bug_when:
2015-10-03 14:34:10 -0700
Fixed in ES2015.