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((NaN).toString() === "NaN"); 18assert((-Infinity).toString() === "-Infinity"); 19assert((Infinity).toString() === "Infinity"); 20assert((NaN).toString(6) === "NaN"); 21assert((-Infinity).toString(7) === "-Infinity"); 22assert((Infinity).toString(8) === "Infinity"); 23assert((16).toString(16) === "10"); 24assert((15).toString(16) === "f"); 25assert((12.5).toString(4) === "30.2"); 26assert((0.005).toString(4) === "0.000110132232011013223201101323"); 27assert((2000).toString(4) === "133100"); 28assert((2000).toString(3) === "2202002"); 29assert((2000).toString(16) === "7d0"); 30assert((0.03125).toString(2) === "0.00001"); 31assert((0.03125).toString(16) === "0.08"); 32assert((0.0001).toString(4) === "0.000000122031232023223013010030231") 33assert((0).toString(16) === "0"); 34assert((-16).toString(16) === "-10"); 35assert((-15).toString(16) === "-f"); 36assert((-12.5).toString(4) === "-30.2"); 37assert((-0.005).toString(4) === "-0.000110132232011013223201101323"); 38assert((-2000).toString(4) === "-133100"); 39assert((-2000).toString(3) === "-2202002"); 40assert((-2000).toString(16) === "-7d0"); 41assert((-0.03125).toString(2) === "-0.00001"); 42assert((-0.03125).toString(16) === "-0.08"); 43assert((-0.0001).toString(4) === "-0.000000122031232023223013010030231") 44assert((-0).toString(16) === "0"); 45assert((1e+73).toString(35) === "2nx1mg1l0w4ujlpt449c5qfrkkmtpgpsfsc2prlaqtnjbli2") 46assert((-1e+73).toString(35) === "-2nx1mg1l0w4ujlpt449c5qfrkkmtpgpsfsc2prlaqtnjbli2") 47assert((1).toString(undefined) === "1") 48 49assert((123400).toString(2) === "11110001000001000"); 50assert((123400).toString(3) === "20021021101"); 51assert((123400).toString(4) === "132020020"); 52assert((123400).toString(5) === "12422100"); 53assert((123400).toString(6) === "2351144"); 54assert((123400).toString(7) === "1022524"); 55assert((123400).toString(8) === "361010"); 56assert((123400).toString(9) === "207241"); 57assert((123400).toString(10) === "123400"); 58assert((123400).toString(11) === "84792"); 59assert((123400).toString(12) === "5b4b4"); 60assert((123400).toString(13) === "44224"); 61assert((123400).toString(14) === "32d84"); 62assert((123400).toString(15) === "2686a"); 63assert((123400).toString(16) === "1e208"); 64assert((123400).toString(17) === "181ge"); 65assert((123400).toString(18) === "132fa"); 66assert((123400).toString(19) === "hife"); 67assert((123400).toString(20) === "f8a0"); 68assert((123400).toString(21) === "d6h4"); 69assert((123400).toString(22) === "bcl2"); 70assert((123400).toString(23) === "a365"); 71assert((123400).toString(24) === "8m5g"); 72assert((123400).toString(25) === "7mb0"); 73assert((123400).toString(26) === "70e4"); 74assert((123400).toString(27) === "677a"); 75assert((123400).toString(28) === "5hb4"); 76assert((123400).toString(29) === "51l5"); 77assert((123400).toString(30) === "4h3a"); 78assert((123400).toString(31) === "44ck"); 79assert((123400).toString(32) === "3og8"); 80assert((123400).toString(33) === "3ead"); 81assert((123400).toString(34) === "34pe"); 82assert((123400).toString(35) === "2upp"); 83assert((123400).toString(36) === "2n7s"); 84 85assert ((1152921504606846600).toString([1,2,3,4].slice(1,2)) === "111111111111111111111111111111111111111111111111111010000000"); 86assert ((-1152921504606846600).toString(2) === "-111111111111111111111111111111111111111111111111111010000000"); 87 88assert ((0x100000000000061).toString(2) === "100000000000000000000000000000000000000000000000001100000") 89assert ((-0x100000000000061).toString(16) === "-100000000000060"); 90 91assert((123400).toString(new Number(16)) === "1e208"); 92 93assert(65535.9.toString(3) === "10022220020.2200220022002200220022102110122000001102212"); 94 95var digit_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 96 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 97 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 98 'u', 'v', 'w', 'x', 'y', 'z']; 99 100for (radix = 2; radix <= 36; radix++) { 101 for (num = 1; num < 100; num++) { 102 var value = num; 103 var str = ""; 104 while (value > 0) { 105 str = digit_chars[value % radix] + str; 106 value = Math.floor(value / radix); 107 } 108 109 assert(str === (num).toString(radix)); 110 } 111} 112 113try { 114 assert((123).toString(1)); 115 assert(false) 116} catch (e) { 117 assert(e instanceof RangeError); 118} 119 120try { 121 assert((123).toString(37)); 122 assert(false) 123} catch (e) { 124 assert(e instanceof RangeError); 125} 126 127try { 128 assert((123).toString(Infinity)); 129 assert(false) 130} catch (e) { 131 assert(e instanceof RangeError); 132} 133