|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: 15.8.2.17.js |
|
9 ECMA Section: 15.8.2.17 Math.sqrt(x) |
|
10 Description: return an approximation to the squareroot of the argument. |
|
11 special cases: |
|
12 - if x is NaN return NaN |
|
13 - if x < 0 return NaN |
|
14 - if x == 0 return 0 |
|
15 - if x == -0 return -0 |
|
16 - if x == Infinity return Infinity |
|
17 Author: christine@netscape.com |
|
18 Date: 7 july 1997 |
|
19 */ |
|
20 |
|
21 var SECTION = "15.8.2.17"; |
|
22 var VERSION = "ECMA_1"; |
|
23 startTest(); |
|
24 var TITLE = "Math.sqrt(x)"; |
|
25 |
|
26 writeHeaderToLog( SECTION + " "+ TITLE); |
|
27 |
|
28 new TestCase( SECTION, |
|
29 "Math.sqrt.length", |
|
30 1, |
|
31 Math.sqrt.length ); |
|
32 |
|
33 new TestCase( SECTION, |
|
34 "Math.sqrt()", |
|
35 Number.NaN, |
|
36 Math.sqrt() ); |
|
37 |
|
38 new TestCase( SECTION, |
|
39 "Math.sqrt(void 0)", |
|
40 Number.NaN, |
|
41 Math.sqrt(void 0) ); |
|
42 |
|
43 new TestCase( SECTION, |
|
44 "Math.sqrt(null)", |
|
45 0, |
|
46 Math.sqrt(null) ); |
|
47 |
|
48 new TestCase( SECTION, |
|
49 "Math.sqrt(true)", |
|
50 1, |
|
51 Math.sqrt(1) ); |
|
52 |
|
53 new TestCase( SECTION, |
|
54 "Math.sqrt(false)", |
|
55 0, |
|
56 Math.sqrt(false) ); |
|
57 |
|
58 new TestCase( SECTION, |
|
59 "Math.sqrt('225')", |
|
60 15, |
|
61 Math.sqrt('225') ); |
|
62 |
|
63 new TestCase( SECTION, |
|
64 "Math.sqrt(NaN)", |
|
65 Number.NaN, |
|
66 Math.sqrt(Number.NaN) ); |
|
67 |
|
68 new TestCase( SECTION, |
|
69 "Math.sqrt(-Infinity)", |
|
70 Number.NaN, |
|
71 Math.sqrt(Number.NEGATIVE_INFINITY)); |
|
72 |
|
73 new TestCase( SECTION, |
|
74 "Math.sqrt(-1)", |
|
75 Number.NaN, |
|
76 Math.sqrt(-1)); |
|
77 |
|
78 new TestCase( SECTION, |
|
79 "Math.sqrt(-0.5)", |
|
80 Number.NaN, |
|
81 Math.sqrt(-0.5)); |
|
82 |
|
83 new TestCase( SECTION, |
|
84 "Math.sqrt(0)", |
|
85 0, |
|
86 Math.sqrt(0)); |
|
87 |
|
88 new TestCase( SECTION, |
|
89 "Math.sqrt(-0)", |
|
90 -0, |
|
91 Math.sqrt(-0)); |
|
92 |
|
93 new TestCase( SECTION, |
|
94 "Infinity/Math.sqrt(-0)", |
|
95 -Infinity, |
|
96 Infinity/Math.sqrt(-0) ); |
|
97 |
|
98 new TestCase( SECTION, |
|
99 "Math.sqrt(Infinity)", |
|
100 Number.POSITIVE_INFINITY, |
|
101 Math.sqrt(Number.POSITIVE_INFINITY)); |
|
102 |
|
103 new TestCase( SECTION, |
|
104 "Math.sqrt(1)", |
|
105 1, |
|
106 Math.sqrt(1)); |
|
107 |
|
108 new TestCase( SECTION, |
|
109 "Math.sqrt(2)", |
|
110 Math.SQRT2, |
|
111 Math.sqrt(2)); |
|
112 |
|
113 new TestCase( SECTION, |
|
114 "Math.sqrt(0.5)", |
|
115 Math.SQRT1_2, |
|
116 Math.sqrt(0.5)); |
|
117 |
|
118 new TestCase( SECTION, |
|
119 "Math.sqrt(4)", |
|
120 2, |
|
121 Math.sqrt(4)); |
|
122 |
|
123 new TestCase( SECTION, |
|
124 "Math.sqrt(9)", |
|
125 3, |
|
126 Math.sqrt(9)); |
|
127 |
|
128 new TestCase( SECTION, |
|
129 "Math.sqrt(16)", |
|
130 4, |
|
131 Math.sqrt(16)); |
|
132 |
|
133 new TestCase( SECTION, |
|
134 "Math.sqrt(25)", |
|
135 5, |
|
136 Math.sqrt(25)); |
|
137 |
|
138 new TestCase( SECTION, |
|
139 "Math.sqrt(36)", |
|
140 6, |
|
141 Math.sqrt(36)); |
|
142 |
|
143 new TestCase( SECTION, |
|
144 "Math.sqrt(49)", |
|
145 7, |
|
146 Math.sqrt(49)); |
|
147 |
|
148 new TestCase( SECTION, |
|
149 "Math.sqrt(64)", |
|
150 8, |
|
151 Math.sqrt(64)); |
|
152 |
|
153 new TestCase( SECTION, |
|
154 "Math.sqrt(256)", |
|
155 16, |
|
156 Math.sqrt(256)); |
|
157 |
|
158 new TestCase( SECTION, |
|
159 "Math.sqrt(10000)", |
|
160 100, |
|
161 Math.sqrt(10000)); |
|
162 |
|
163 new TestCase( SECTION, |
|
164 "Math.sqrt(65536)", |
|
165 256, |
|
166 Math.sqrt(65536)); |
|
167 |
|
168 new TestCase( SECTION, |
|
169 "Math.sqrt(0.09)", |
|
170 0.3, |
|
171 Math.sqrt(0.09)); |
|
172 |
|
173 new TestCase( SECTION, |
|
174 "Math.sqrt(0.01)", |
|
175 0.1, |
|
176 Math.sqrt(0.01)); |
|
177 |
|
178 new TestCase( SECTION, |
|
179 "Math.sqrt(0.00000001)", |
|
180 0.0001, |
|
181 Math.sqrt(0.00000001)); |
|
182 |
|
183 test(); |