1/* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          15.8.2.13.js
24    ECMA Section:       15.8.2.13 Math.pow(x, y)
25    Description:        return an approximation to the result of x
26                        to the power of y.  there are many special cases;
27                        refer to the spec.
28    Author:             christine@netscape.com
29    Date:               9 july 1997
30*/
31
32    var SECTION = "15.8.2.13";
33    var VERSION = "ECMA_1";
34    startTest();
35    var TITLE   = "Math.pow(x, y)";
36    var BUGNUMBER="77141";
37
38    writeHeaderToLog( SECTION + " "+ TITLE);
39
40    var testcases = getTestCases();
41    test();
42function getTestCases() {
43    var array = new Array();
44    var item = 0;
45
46    array[item++] = new TestCase( SECTION,  "Math.pow.length",                  2,                          Math.pow.length );
47
48    array[item++] = new TestCase( SECTION,  "Math.pow()",                       Number.NaN,                 Math.pow() );
49    array[item++] = new TestCase( SECTION,  "Math.pow(null, null)",             1,                          Math.pow(null,null) );
50    array[item++] = new TestCase( SECTION,  "Math.pow(void 0, void 0)",         Number.NaN,                 Math.pow(void 0, void 0));
51    array[item++] = new TestCase( SECTION,  "Math.pow(true, false)",            1,                          Math.pow(true, false) );
52    array[item++] = new TestCase( SECTION,  "Math.pow(false,true)",             0,                          Math.pow(false,true) );
53    array[item++] = new TestCase( SECTION,  "Math.pow('2','32')",               4294967296,                 Math.pow('2','32') );
54
55    array[item++] = new TestCase( SECTION,  "Math.pow(1,NaN)",                  Number.NaN,                 Math.pow(1,Number.NaN) );
56    array[item++] = new TestCase( SECTION,  "Math.pow(0,NaN)",	                Number.NaN,                 Math.pow(0,Number.NaN) );
57    array[item++] = new TestCase( SECTION,  "Math.pow(NaN,0)",                  1,                          Math.pow(Number.NaN,0) );
58    array[item++] = new TestCase( SECTION,  "Math.pow(NaN,-0)",                 1,                          Math.pow(Number.NaN,-0) );
59    array[item++] = new TestCase( SECTION,  "Math.pow(NaN,1)",                  Number.NaN,                 Math.pow(Number.NaN, 1) );
60    array[item++] = new TestCase( SECTION,  "Math.pow(NaN,.5)",                 Number.NaN,                 Math.pow(Number.NaN, .5) );
61    array[item++] = new TestCase( SECTION,  "Math.pow(1.00000001, Infinity)",   Number.POSITIVE_INFINITY,   Math.pow(1.00000001, Number.POSITIVE_INFINITY) );
62    array[item++] = new TestCase( SECTION,  "Math.pow(1.00000001, -Infinity)",  0,                          Math.pow(1.00000001, Number.NEGATIVE_INFINITY) );
63    array[item++] = new TestCase( SECTION,  "Math.pow(-1.00000001, Infinity)",  Number.POSITIVE_INFINITY,   Math.pow(-1.00000001,Number.POSITIVE_INFINITY) );
64    array[item++] = new TestCase( SECTION,  "Math.pow(-1.00000001, -Infinity)", 0,                          Math.pow(-1.00000001,Number.NEGATIVE_INFINITY) );
65    array[item++] = new TestCase( SECTION,  "Math.pow(1, Infinity)",            Number.NaN,                 Math.pow(1, Number.POSITIVE_INFINITY) );
66    array[item++] = new TestCase( SECTION,  "Math.pow(1, -Infinity)",           Number.NaN,                 Math.pow(1, Number.NEGATIVE_INFINITY) );
67    array[item++] = new TestCase( SECTION,  "Math.pow(-1, Infinity)",           Number.NaN,                 Math.pow(-1, Number.POSITIVE_INFINITY) );
68    array[item++] = new TestCase( SECTION,  "Math.pow(-1, -Infinity)",          Number.NaN,                 Math.pow(-1, Number.NEGATIVE_INFINITY) );
69    array[item++] = new TestCase( SECTION,  "Math.pow(.0000000009, Infinity)",  0,                          Math.pow(.0000000009, Number.POSITIVE_INFINITY) );
70    array[item++] = new TestCase( SECTION,  "Math.pow(-.0000000009, Infinity)", 0,                          Math.pow(-.0000000009, Number.POSITIVE_INFINITY) );
71    array[item++] = new TestCase( SECTION,  "Math.pow(.0000000009, -Infinity)", Number.POSITIVE_INFINITY,   Math.pow(-.0000000009, Number.NEGATIVE_INFINITY) );
72    array[item++] = new TestCase( SECTION,  "Math.pow(Infinity, .00000000001)", Number.POSITIVE_INFINITY,   Math.pow(Number.POSITIVE_INFINITY,.00000000001) );
73    array[item++] = new TestCase( SECTION,  "Math.pow(Infinity, 1)",            Number.POSITIVE_INFINITY,   Math.pow(Number.POSITIVE_INFINITY, 1) );
74    array[item++] = new TestCase( SECTION,  "Math.pow(Infinity, -.00000000001)",0,                          Math.pow(Number.POSITIVE_INFINITY, -.00000000001) );
75    array[item++] = new TestCase( SECTION,  "Math.pow(Infinity, -1)",           0,                          Math.pow(Number.POSITIVE_INFINITY, -1) );
76    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, 1)",           Number.NEGATIVE_INFINITY,   Math.pow(Number.NEGATIVE_INFINITY, 1) );
77    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, 333)",         Number.NEGATIVE_INFINITY,   Math.pow(Number.NEGATIVE_INFINITY, 333) );
78    array[item++] = new TestCase( SECTION,  "Math.pow(Infinity, 2)",            Number.POSITIVE_INFINITY,   Math.pow(Number.POSITIVE_INFINITY, 2) );
79    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, 666)",         Number.POSITIVE_INFINITY,   Math.pow(Number.NEGATIVE_INFINITY, 666) );
80    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, 0.5)",         Number.POSITIVE_INFINITY,   Math.pow(Number.NEGATIVE_INFINITY, 0.5) );
81    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, Infinity)",    Number.POSITIVE_INFINITY,   Math.pow(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY) );
82
83    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, -1)",          -0,                         Math.pow(Number.NEGATIVE_INFINITY, -1) );
84    array[item++] = new TestCase( SECTION,  "Infinity/Math.pow(-Infinity, -1)", -Infinity,                  Infinity/Math.pow(Number.NEGATIVE_INFINITY, -1) );
85
86    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, -3)",          -0,                         Math.pow(Number.NEGATIVE_INFINITY, -3) );
87    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, -2)",          0,                          Math.pow(Number.NEGATIVE_INFINITY, -2) );
88    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, -0.5)",        0,                          Math.pow(Number.NEGATIVE_INFINITY,-0.5) );
89    array[item++] = new TestCase( SECTION,  "Math.pow(-Infinity, -Infinity)",   0,                          Math.pow(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY) );
90    array[item++] = new TestCase( SECTION,  "Math.pow(0, 1)",                   0,                          Math.pow(0,1) );
91    array[item++] = new TestCase( SECTION,  "Math.pow(0, 0)",                   1,                          Math.pow(0,0) );
92    array[item++] = new TestCase( SECTION,  "Math.pow(1, 0)",                   1,                          Math.pow(1,0) );
93    array[item++] = new TestCase( SECTION,  "Math.pow(-1, 0)",                  1,                          Math.pow(-1,0) );
94    array[item++] = new TestCase( SECTION,  "Math.pow(0, 0.5)",                 0,                          Math.pow(0,0.5) );
95    array[item++] = new TestCase( SECTION,  "Math.pow(0, 1000)",                0,                          Math.pow(0,1000) );
96    array[item++] = new TestCase( SECTION,  "Math.pow(0, Infinity)",            0,                          Math.pow(0, Number.POSITIVE_INFINITY) );
97    array[item++] = new TestCase( SECTION,  "Math.pow(0, -1)",                  Number.POSITIVE_INFINITY,   Math.pow(0, -1) );
98    array[item++] = new TestCase( SECTION,  "Math.pow(0, -0.5)",                Number.POSITIVE_INFINITY,   Math.pow(0, -0.5) );
99    array[item++] = new TestCase( SECTION,  "Math.pow(0, -1000)",               Number.POSITIVE_INFINITY,   Math.pow(0, -1000) );
100    array[item++] = new TestCase( SECTION,  "Math.pow(0, -Infinity)",           Number.POSITIVE_INFINITY,   Math.pow(0, Number.NEGATIVE_INFINITY) );
101    array[item++] = new TestCase( SECTION,  "Math.pow(-0, 1)",                  -0,                         Math.pow(-0, 1) );
102    array[item++] = new TestCase( SECTION,  "Math.pow(-0, 3)",                  -0,                         Math.pow(-0,3) );
103
104    array[item++] = new TestCase( SECTION,  "Infinity/Math.pow(-0, 1)",         -Infinity,                  Infinity/Math.pow(-0, 1) );
105    array[item++] = new TestCase( SECTION,  "Infinity/Math.pow(-0, 3)",         -Infinity,                  Infinity/Math.pow(-0,3) );
106
107    array[item++] = new TestCase( SECTION,  "Math.pow(-0, 2)",                  0,                          Math.pow(-0,2) );
108    array[item++] = new TestCase( SECTION,  "Math.pow(-0, Infinity)",           0,                          Math.pow(-0, Number.POSITIVE_INFINITY) );
109    array[item++] = new TestCase( SECTION,  "Math.pow(-0, -1)",                 Number.NEGATIVE_INFINITY,   Math.pow(-0, -1) );
110    array[item++] = new TestCase( SECTION,  "Math.pow(-0, -10001)",             Number.NEGATIVE_INFINITY,   Math.pow(-0, -10001) );
111    array[item++] = new TestCase( SECTION,  "Math.pow(-0, -2)",                 Number.POSITIVE_INFINITY,   Math.pow(-0, -2) );
112    array[item++] = new TestCase( SECTION,  "Math.pow(-0, 0.5)",                0,                          Math.pow(-0, 0.5) );
113    array[item++] = new TestCase( SECTION,  "Math.pow(-0, Infinity)",           0,                          Math.pow(-0, Number.POSITIVE_INFINITY) );
114    array[item++] = new TestCase( SECTION,  "Math.pow(-1, 0.5)",                Number.NaN,                 Math.pow(-1, 0.5) );
115    array[item++] = new TestCase( SECTION,  "Math.pow(-1, NaN)",                Number.NaN,                 Math.pow(-1, Number.NaN) );
116    array[item++] = new TestCase( SECTION,  "Math.pow(-1, -0.5)",               Number.NaN,                 Math.pow(-1, -0.5) );
117
118    return ( array );
119}
120function test() {
121    for ( tc=0; tc < testcases.length; tc++ ) {
122        testcases[tc].passed = writeTestCaseResult(
123                            testcases[tc].expect,
124                            testcases[tc].actual,
125                            testcases[tc].description +" = "+
126                            testcases[tc].actual );
127
128        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
129    }
130    stopTest();
131    return ( testcases );
132}
133