Backed out changeset 3743627d5eff (bug 1917652) for causing leak failures VideoBridge...
[gecko.git] / js / src / tests / test262 / built-ins / Number / prototype / toExponential / undefined-fractiondigits.js
blob9194721ad6fd4668e55a77a22263f24b1bc9aaa3
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.
4 /*---
5 esid: sec-number.prototype.toexponential
6 description: >
7   Handle undefined fractionDigits, not only casting it to 0
8 info: |
9   Number.prototype.toExponential ( fractionDigits )
11   1. Let x be ? thisNumberValue(this value).
12   2. Let f be ? ToInteger(fractionDigits).
13   [...]
14   10. Else x ≠ 0,
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.
26 ---*/
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");
40 reportCompare(0, 0);