1 // Copyright (C) 2016 The V8 Project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
5 esid: sec-number.prototype.toexponential
7 Handle undefined fractionDigits, not only casting it to 0
9 Number.prototype.toExponential ( fractionDigits )
11 1. Let x be ? thisNumberValue(this value).
12 2. Let f be ? ToInteger(fractionDigits).
15 a. If fractionDigits is not undefined, then
16 i. Let e and n be integers such that 10f ≤ n < 10f+1 and for which the
17 exact mathematical value of n × 10e-f - x is as close to zero as
18 possible. If there are two such sets of e and n, pick the e and n for
19 which n × 10e-f is larger.
20 b. Else fractionDigits is undefined,
21 i. Let e, n, and f be integers such that f ≥ 0, 10f ≤ n < 10f+1, the
22 Number value for n × 10e-f is x, and f is as small as possible. Note
23 that the decimal representation of n has f+1 digits, n is not divisible
24 by 10, and the least significant digit of n is not necessarily uniquely
25 determined by these criteria.
28 assert.sameValue((123.456).toExponential(undefined), "1.23456e+2", "undefined");
29 assert.sameValue((123.456).toExponential(), "1.23456e+2", "no arg");
30 assert.sameValue((123.456).toExponential(0), "1e+2", "0");
32 assert.sameValue((1.1e-32).toExponential(undefined), "1.1e-32", "undefined");
33 assert.sameValue((1.1e-32).toExponential(), "1.1e-32", "no arg");
34 assert.sameValue((1.1e-32).toExponential(0), "1e-32", "0");
36 assert.sameValue((100).toExponential(undefined), "1e+2", "undefined");
37 assert.sameValue((100).toExponential(), "1e+2", "no arg");
38 assert.sameValue((100).toExponential(0), "1e+2", "0");