blob: e732955c983e50c423d40ac641880f8162c5292c [file] [log] [blame]
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001// 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
31assertEquals(4, Math.pow(2, 2));
32assertEquals(2147483648, Math.pow(2, 31));
33assertEquals(0.25, Math.pow(2, -2));
34assertEquals(0.0625, Math.pow(2, -4));
35assertEquals(1, Math.pow(1, 100));
36assertEquals(0, Math.pow(0, 1000));
37
38// Spec tests
39assertEquals(NaN, Math.pow(2, NaN));
40assertEquals(NaN, Math.pow(+0, NaN));
41assertEquals(NaN, Math.pow(-0, NaN));
42assertEquals(NaN, Math.pow(Infinity, NaN));
43assertEquals(NaN, Math.pow(-Infinity, NaN));
44
45assertEquals(1, Math.pow(NaN, +0));
46assertEquals(1, Math.pow(NaN, -0));
47
48assertEquals(NaN, Math.pow(NaN, NaN));
49assertEquals(NaN, Math.pow(NaN, 2.2));
50assertEquals(NaN, Math.pow(NaN, 1));
51assertEquals(NaN, Math.pow(NaN, -1));
52assertEquals(NaN, Math.pow(NaN, -2.2));
53assertEquals(NaN, Math.pow(NaN, Infinity));
54assertEquals(NaN, Math.pow(NaN, -Infinity));
55
56assertEquals(Infinity, Math.pow(1.1, Infinity));
57assertEquals(Infinity, Math.pow(-1.1, Infinity));
58assertEquals(Infinity, Math.pow(2, Infinity));
59assertEquals(Infinity, Math.pow(-2, Infinity));
60
61assertEquals(+0, Math.pow(1.1, -Infinity));
62assertEquals(+0, Math.pow(-1.1, -Infinity));
63assertEquals(+0, Math.pow(2, -Infinity));
64assertEquals(+0, Math.pow(-2, -Infinity));
65
66assertEquals(NaN, Math.pow(1, Infinity));
67assertEquals(NaN, Math.pow(1, -Infinity));
68assertEquals(NaN, Math.pow(-1, Infinity));
69assertEquals(NaN, Math.pow(-1, -Infinity));
70
71assertEquals(+0, Math.pow(0.1, Infinity));
72assertEquals(+0, Math.pow(-0.1, Infinity));
73assertEquals(+0, Math.pow(0.999, Infinity));
74assertEquals(+0, Math.pow(-0.999, Infinity));
75
76assertEquals(Infinity, Math.pow(0.1, -Infinity));
77assertEquals(Infinity, Math.pow(-0.1, -Infinity));
78assertEquals(Infinity, Math.pow(0.999, -Infinity));
79assertEquals(Infinity, Math.pow(-0.999, -Infinity));
80
81assertEquals(Infinity, Math.pow(Infinity, 0.1));
82assertEquals(Infinity, Math.pow(Infinity, 2));
83
84assertEquals(+0, Math.pow(Infinity, -0.1));
85assertEquals(+0, Math.pow(Infinity, -2));
86
87assertEquals(-Infinity, Math.pow(-Infinity, 3));
88assertEquals(-Infinity, Math.pow(-Infinity, 13));
89
90assertEquals(Infinity, Math.pow(-Infinity, 3.1));
91assertEquals(Infinity, Math.pow(-Infinity, 2));
92
93assertEquals(-0, Math.pow(-Infinity, -3));
94assertEquals(-0, Math.pow(-Infinity, -13));
95
96assertEquals(+0, Math.pow(-Infinity, -3.1));
97assertEquals(+0, Math.pow(-Infinity, -2));
98
99assertEquals(+0, Math.pow(+0, 1.1));
100assertEquals(+0, Math.pow(+0, 2));
101
102assertEquals(Infinity, Math.pow(+0, -1.1));
103assertEquals(Infinity, Math.pow(+0, -2));
104
105assertEquals(-0, Math.pow(-0, 3));
106assertEquals(-0, Math.pow(-0, 13));
107
108assertEquals(+0, Math.pow(-0, 3.1));
109assertEquals(+0, Math.pow(-0, 2));
110
111assertEquals(-Infinity, Math.pow(-0, -3));
112assertEquals(-Infinity, Math.pow(-0, -13));
113
114assertEquals(Infinity, Math.pow(-0, -3.1));
115assertEquals(Infinity, Math.pow(-0, -2));
116
117assertEquals(NaN, Math.pow(-0.00001, 1.1));
118assertEquals(NaN, Math.pow(-0.00001, -1.1));
119assertEquals(NaN, Math.pow(-1.1, 1.1));
120assertEquals(NaN, Math.pow(-1.1, -1.1));
121assertEquals(NaN, Math.pow(-2, 1.1));
122assertEquals(NaN, Math.pow(-2, -1.1));
123assertEquals(NaN, Math.pow(-1000, 1.1));
124assertEquals(NaN, Math.pow(-1000, -1.1));
125
126// Tests from Sputnik S8.5_A13_T1.
127assertTrue((1*((Math.pow(2,53))-1)*(Math.pow(2,-1074))) === 4.4501477170144023e-308);
128assertTrue((1*(Math.pow(2,52))*(Math.pow(2,-1074))) === 2.2250738585072014e-308);
129assertTrue((-1*(Math.pow(2,52))*(Math.pow(2,-1074))) === -2.2250738585072014e-308);