1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15//This test will not pass on FLOAT32 due to precision issues 16 17assert((123.56).toExponential() === "1.2356e+2"); 18assert((123.56).toExponential(0) === "1e+2"); 19assert((123.56).toExponential(1) === "1.2e+2"); 20assert((123.56).toExponential(5) === "1.23560e+2"); 21assert((-1.23).toExponential(1) === "-1.2e+0"); 22assert((0.00023).toExponential(0) === "2e-4"); 23assert((0.356).toExponential(1) === "3.6e-1"); 24assert((0.0000356).toExponential(2) === "3.56e-5"); 25assert((0.000030056).toExponential(2) === "3.01e-5"); 26assert(Infinity.toExponential(0) === "Infinity"); 27assert((-Infinity).toExponential(0) === "-Infinity"); 28assert(NaN.toExponential(0) === "NaN"); 29assert((0.0).toExponential(0) === "0e+0"); 30assert((0.0).toExponential(1) === "0.0e+0"); 31assert((-0.0).toExponential(0) === "0e+0"); 32assert((-0.0).toExponential(1) === "0.0e+0"); 33assert((123456789012345678901.0).toExponential(20) === "1.23456789012345680000e+20"); 34assert((123456789012345678901.0).toExponential("6") === "1.234568e+20"); 35assert((123.45).toExponential(3.2) === "1.235e+2"); 36assert((123.45).toExponential(-0.1) === "1e+2"); 37 38try { 39 (12).toExponential(Number.MAX_VALUE); 40 assert(false); 41} catch (e) { 42 assert(e instanceof RangeError) 43} 44 45try { 46 (12).toExponential(Infinity); 47 assert(false); 48} catch (e) { 49 assert(e instanceof RangeError) 50} 51 52try { 53 (12).toExponential(-1); 54 assert(false); 55} catch (e) { 56 assert(e instanceof RangeError) 57} 58 59try { 60 (12).toExponential(21); 61 assert(false); 62} catch (e) { 63 assert(e instanceof RangeError) 64} 65 66try { 67 Number.prototype.toExponential.call(new Object()); 68 assert(false); 69} catch (e) { 70 assert(e instanceof TypeError) 71} 72