kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame^] | 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 | assertEquals(+0, Math.pow(1.1, -Infinity)); |
| 62 | assertEquals(+0, Math.pow(-1.1, -Infinity)); |
| 63 | assertEquals(+0, Math.pow(2, -Infinity)); |
| 64 | assertEquals(+0, Math.pow(-2, -Infinity)); |
| 65 | |
| 66 | assertEquals(NaN, Math.pow(1, Infinity)); |
| 67 | assertEquals(NaN, Math.pow(1, -Infinity)); |
| 68 | assertEquals(NaN, Math.pow(-1, Infinity)); |
| 69 | assertEquals(NaN, Math.pow(-1, -Infinity)); |
| 70 | |
| 71 | assertEquals(+0, Math.pow(0.1, Infinity)); |
| 72 | assertEquals(+0, Math.pow(-0.1, Infinity)); |
| 73 | assertEquals(+0, Math.pow(0.999, Infinity)); |
| 74 | assertEquals(+0, Math.pow(-0.999, Infinity)); |
| 75 | |
| 76 | assertEquals(Infinity, Math.pow(0.1, -Infinity)); |
| 77 | assertEquals(Infinity, Math.pow(-0.1, -Infinity)); |
| 78 | assertEquals(Infinity, Math.pow(0.999, -Infinity)); |
| 79 | assertEquals(Infinity, Math.pow(-0.999, -Infinity)); |
| 80 | |
| 81 | assertEquals(Infinity, Math.pow(Infinity, 0.1)); |
| 82 | assertEquals(Infinity, Math.pow(Infinity, 2)); |
| 83 | |
| 84 | assertEquals(+0, Math.pow(Infinity, -0.1)); |
| 85 | assertEquals(+0, Math.pow(Infinity, -2)); |
| 86 | |
| 87 | assertEquals(-Infinity, Math.pow(-Infinity, 3)); |
| 88 | assertEquals(-Infinity, Math.pow(-Infinity, 13)); |
| 89 | |
| 90 | assertEquals(Infinity, Math.pow(-Infinity, 3.1)); |
| 91 | assertEquals(Infinity, Math.pow(-Infinity, 2)); |
| 92 | |
| 93 | assertEquals(-0, Math.pow(-Infinity, -3)); |
| 94 | assertEquals(-0, Math.pow(-Infinity, -13)); |
| 95 | |
| 96 | assertEquals(+0, Math.pow(-Infinity, -3.1)); |
| 97 | assertEquals(+0, Math.pow(-Infinity, -2)); |
| 98 | |
| 99 | assertEquals(+0, Math.pow(+0, 1.1)); |
| 100 | assertEquals(+0, Math.pow(+0, 2)); |
| 101 | |
| 102 | assertEquals(Infinity, Math.pow(+0, -1.1)); |
| 103 | assertEquals(Infinity, Math.pow(+0, -2)); |
| 104 | |
| 105 | assertEquals(-0, Math.pow(-0, 3)); |
| 106 | assertEquals(-0, Math.pow(-0, 13)); |
| 107 | |
| 108 | assertEquals(+0, Math.pow(-0, 3.1)); |
| 109 | assertEquals(+0, Math.pow(-0, 2)); |
| 110 | |
| 111 | assertEquals(-Infinity, Math.pow(-0, -3)); |
| 112 | assertEquals(-Infinity, Math.pow(-0, -13)); |
| 113 | |
| 114 | assertEquals(Infinity, Math.pow(-0, -3.1)); |
| 115 | assertEquals(Infinity, Math.pow(-0, -2)); |
| 116 | |
| 117 | assertEquals(NaN, Math.pow(-0.00001, 1.1)); |
| 118 | assertEquals(NaN, Math.pow(-0.00001, -1.1)); |
| 119 | assertEquals(NaN, Math.pow(-1.1, 1.1)); |
| 120 | assertEquals(NaN, Math.pow(-1.1, -1.1)); |
| 121 | assertEquals(NaN, Math.pow(-2, 1.1)); |
| 122 | assertEquals(NaN, Math.pow(-2, -1.1)); |
| 123 | assertEquals(NaN, Math.pow(-1000, 1.1)); |
| 124 | assertEquals(NaN, Math.pow(-1000, -1.1)); |
| 125 | |
| 126 | // Tests from Sputnik S8.5_A13_T1. |
| 127 | assertTrue((1*((Math.pow(2,53))-1)*(Math.pow(2,-1074))) === 4.4501477170144023e-308); |
| 128 | assertTrue((1*(Math.pow(2,52))*(Math.pow(2,-1074))) === 2.2250738585072014e-308); |
| 129 | assertTrue((-1*(Math.pow(2,52))*(Math.pow(2,-1074))) === -2.2250738585072014e-308); |