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