1 // Copyright 2010 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 // Tests the special cases specified by ES 15.8.2.13 29 30 // Simple sanity check 31 assertEquals(4, Math.pow(2, 2)); 32 assertEquals(2147483648, Math.pow(2, 31)); 33 assertEquals(0.25, Math.pow(2, -2)); 34 assertEquals(0.0625, Math.pow(2, -4)); 35 assertEquals(1, Math.pow(1, 100)); 36 assertEquals(0, Math.pow(0, 1000)); 37 38 // Spec tests 39 assertEquals(NaN, Math.pow(2, NaN)); 40 assertEquals(NaN, Math.pow(+0, NaN)); 41 assertEquals(NaN, Math.pow(-0, NaN)); 42 assertEquals(NaN, Math.pow(Infinity, NaN)); 43 assertEquals(NaN, Math.pow(-Infinity, NaN)); 44 45 assertEquals(1, Math.pow(NaN, +0)); 46 assertEquals(1, Math.pow(NaN, -0)); 47 48 assertEquals(NaN, Math.pow(NaN, NaN)); 49 assertEquals(NaN, Math.pow(NaN, 2.2)); 50 assertEquals(NaN, Math.pow(NaN, 1)); 51 assertEquals(NaN, Math.pow(NaN, -1)); 52 assertEquals(NaN, Math.pow(NaN, -2.2)); 53 assertEquals(NaN, Math.pow(NaN, Infinity)); 54 assertEquals(NaN, Math.pow(NaN, -Infinity)); 55 56 assertEquals(Infinity, Math.pow(1.1, Infinity)); 57 assertEquals(Infinity, Math.pow(-1.1, Infinity)); 58 assertEquals(Infinity, Math.pow(2, Infinity)); 59 assertEquals(Infinity, Math.pow(-2, Infinity)); 60 61 // Because +0 == -0, we need to compare 1/{+,-}0 to {+,-}Infinity 62 assertEquals(+Infinity, 1/Math.pow(1.1, -Infinity)); 63 assertEquals(+Infinity, 1/Math.pow(-1.1, -Infinity)); 64 assertEquals(+Infinity, 1/Math.pow(2, -Infinity)); 65 assertEquals(+Infinity, 1/Math.pow(-2, -Infinity)); 66 67 assertEquals(NaN, Math.pow(1, Infinity)); 68 assertEquals(NaN, Math.pow(1, -Infinity)); 69 assertEquals(NaN, Math.pow(-1, Infinity)); 70 assertEquals(NaN, Math.pow(-1, -Infinity)); 71 72 assertEquals(+0, Math.pow(0.1, Infinity)); 73 assertEquals(+0, Math.pow(-0.1, Infinity)); 74 assertEquals(+0, Math.pow(0.999, Infinity)); 75 assertEquals(+0, Math.pow(-0.999, Infinity)); 76 77 assertEquals(Infinity, Math.pow(0.1, -Infinity)); 78 assertEquals(Infinity, Math.pow(-0.1, -Infinity)); 79 assertEquals(Infinity, Math.pow(0.999, -Infinity)); 80 assertEquals(Infinity, Math.pow(-0.999, -Infinity)); 81 82 assertEquals(Infinity, Math.pow(Infinity, 0.1)); 83 assertEquals(Infinity, Math.pow(Infinity, 2)); 84 85 assertEquals(+Infinity, 1/Math.pow(Infinity, -0.1)); 86 assertEquals(+Infinity, 1/Math.pow(Infinity, -2)); 87 88 assertEquals(-Infinity, Math.pow(-Infinity, 3)); 89 assertEquals(-Infinity, Math.pow(-Infinity, 13)); 90 91 assertEquals(Infinity, Math.pow(-Infinity, 3.1)); 92 assertEquals(Infinity, Math.pow(-Infinity, 2)); 93 94 assertEquals(-Infinity, 1/Math.pow(-Infinity, -3)); 95 assertEquals(-Infinity, 1/Math.pow(-Infinity, -13)); 96 97 assertEquals(+Infinity, 1/Math.pow(-Infinity, -3.1)); 98 assertEquals(+Infinity, 1/Math.pow(-Infinity, -2)); 99 100 assertEquals(+Infinity, 1/Math.pow(+0, 1.1)); 101 assertEquals(+Infinity, 1/Math.pow(+0, 2)); 102 103 assertEquals(Infinity, Math.pow(+0, -1.1)); 104 assertEquals(Infinity, Math.pow(+0, -2)); 105 106 assertEquals(-Infinity, 1/Math.pow(-0, 3)); 107 assertEquals(-Infinity, 1/Math.pow(-0, 13)); 108 109 assertEquals(+Infinity, 1/Math.pow(-0, 3.1)); 110 assertEquals(+Infinity, 1/Math.pow(-0, 2)); 111 112 assertEquals(-Infinity, Math.pow(-0, -3)); 113 assertEquals(-Infinity, Math.pow(-0, -13)); 114 115 assertEquals(Infinity, Math.pow(-0, -3.1)); 116 assertEquals(Infinity, Math.pow(-0, -2)); 117 118 assertEquals(NaN, Math.pow(-0.00001, 1.1)); 119 assertEquals(NaN, Math.pow(-0.00001, -1.1)); 120 assertEquals(NaN, Math.pow(-1.1, 1.1)); 121 assertEquals(NaN, Math.pow(-1.1, -1.1)); 122 assertEquals(NaN, Math.pow(-2, 1.1)); 123 assertEquals(NaN, Math.pow(-2, -1.1)); 124 assertEquals(NaN, Math.pow(-1000, 1.1)); 125 assertEquals(NaN, Math.pow(-1000, -1.1)); 126 127 assertEquals(+Infinity, 1/Math.pow(-0, 0.5)); 128 assertEquals(+Infinity, 1/Math.pow(-0, 0.6)); 129 assertEquals(-Infinity, 1/Math.pow(-0, 1)); 130 assertEquals(-Infinity, 1/Math.pow(-0, 10000000001)); 131 132 assertEquals(+Infinity, Math.pow(-0, -0.5)); 133 assertEquals(+Infinity, Math.pow(-0, -0.6)); 134 assertEquals(-Infinity, Math.pow(-0, -1)); 135 assertEquals(-Infinity, Math.pow(-0, -10000000001)); 136 137 138 139 // Tests from Sputnik S8.5_A13_T1. 140 assertTrue((1*((Math.pow(2,53))-1)*(Math.pow(2,-1074))) === 4.4501477170144023e-308); 141 assertTrue((1*(Math.pow(2,52))*(Math.pow(2,-1074))) === 2.2250738585072014e-308); 142 assertTrue((-1*(Math.pow(2,52))*(Math.pow(2,-1074))) === -2.2250738585072014e-308); 143