| 1 |
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 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: [email protected] |
| 18 |
Date: 7 july 1997 |
| 19 |
*/ |
| 20 |
|
| 21 |
var SECTION = "15.8.2.17"; |
| 22 |
var TITLE = "Math.sqrt(x)"; |
| 23 |
|
| 24 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 25 |
|
| 26 |
new TestCase( |
| 27 |
"Math.sqrt.length", |
| 28 |
1, |
| 29 |
Math.sqrt.length ); |
| 30 |
|
| 31 |
new TestCase( |
| 32 |
"Math.sqrt()", |
| 33 |
Number.NaN, |
| 34 |
Math.sqrt() ); |
| 35 |
|
| 36 |
new TestCase( |
| 37 |
"Math.sqrt(void 0)", |
| 38 |
Number.NaN, |
| 39 |
Math.sqrt(void 0) ); |
| 40 |
|
| 41 |
new TestCase( |
| 42 |
"Math.sqrt(null)", |
| 43 |
0, |
| 44 |
Math.sqrt(null) ); |
| 45 |
|
| 46 |
new TestCase( |
| 47 |
"Math.sqrt(true)", |
| 48 |
1, |
| 49 |
Math.sqrt(1) ); |
| 50 |
|
| 51 |
new TestCase( |
| 52 |
"Math.sqrt(false)", |
| 53 |
0, |
| 54 |
Math.sqrt(false) ); |
| 55 |
|
| 56 |
new TestCase( |
| 57 |
"Math.sqrt('225')", |
| 58 |
15, |
| 59 |
Math.sqrt('225') ); |
| 60 |
|
| 61 |
new TestCase( |
| 62 |
"Math.sqrt(NaN)", |
| 63 |
Number.NaN, |
| 64 |
Math.sqrt(Number.NaN) ); |
| 65 |
|
| 66 |
new TestCase( |
| 67 |
"Math.sqrt(-Infinity)", |
| 68 |
Number.NaN, |
| 69 |
Math.sqrt(Number.NEGATIVE_INFINITY)); |
| 70 |
|
| 71 |
new TestCase( |
| 72 |
"Math.sqrt(-1)", |
| 73 |
Number.NaN, |
| 74 |
Math.sqrt(-1)); |
| 75 |
|
| 76 |
new TestCase( |
| 77 |
"Math.sqrt(-0.5)", |
| 78 |
Number.NaN, |
| 79 |
Math.sqrt(-0.5)); |
| 80 |
|
| 81 |
new TestCase( |
| 82 |
"Math.sqrt(0)", |
| 83 |
0, |
| 84 |
Math.sqrt(0)); |
| 85 |
|
| 86 |
new TestCase( |
| 87 |
"Math.sqrt(-0)", |
| 88 |
-0, |
| 89 |
Math.sqrt(-0)); |
| 90 |
|
| 91 |
new TestCase( |
| 92 |
"Infinity/Math.sqrt(-0)", |
| 93 |
-Infinity, |
| 94 |
Infinity/Math.sqrt(-0) ); |
| 95 |
|
| 96 |
new TestCase( |
| 97 |
"Math.sqrt(Infinity)", |
| 98 |
Number.POSITIVE_INFINITY, |
| 99 |
Math.sqrt(Number.POSITIVE_INFINITY)); |
| 100 |
|
| 101 |
new TestCase( |
| 102 |
"Math.sqrt(1)", |
| 103 |
1, |
| 104 |
Math.sqrt(1)); |
| 105 |
|
| 106 |
new TestCase( |
| 107 |
"Math.sqrt(2)", |
| 108 |
Math.SQRT2, |
| 109 |
Math.sqrt(2)); |
| 110 |
|
| 111 |
new TestCase( |
| 112 |
"Math.sqrt(0.5)", |
| 113 |
Math.SQRT1_2, |
| 114 |
Math.sqrt(0.5)); |
| 115 |
|
| 116 |
new TestCase( |
| 117 |
"Math.sqrt(4)", |
| 118 |
2, |
| 119 |
Math.sqrt(4)); |
| 120 |
|
| 121 |
new TestCase( |
| 122 |
"Math.sqrt(9)", |
| 123 |
3, |
| 124 |
Math.sqrt(9)); |
| 125 |
|
| 126 |
new TestCase( |
| 127 |
"Math.sqrt(16)", |
| 128 |
4, |
| 129 |
Math.sqrt(16)); |
| 130 |
|
| 131 |
new TestCase( |
| 132 |
"Math.sqrt(25)", |
| 133 |
5, |
| 134 |
Math.sqrt(25)); |
| 135 |
|
| 136 |
new TestCase( |
| 137 |
"Math.sqrt(36)", |
| 138 |
6, |
| 139 |
Math.sqrt(36)); |
| 140 |
|
| 141 |
new TestCase( |
| 142 |
"Math.sqrt(49)", |
| 143 |
7, |
| 144 |
Math.sqrt(49)); |
| 145 |
|
| 146 |
new TestCase( |
| 147 |
"Math.sqrt(64)", |
| 148 |
8, |
| 149 |
Math.sqrt(64)); |
| 150 |
|
| 151 |
new TestCase( |
| 152 |
"Math.sqrt(256)", |
| 153 |
16, |
| 154 |
Math.sqrt(256)); |
| 155 |
|
| 156 |
new TestCase( |
| 157 |
"Math.sqrt(10000)", |
| 158 |
100, |
| 159 |
Math.sqrt(10000)); |
| 160 |
|
| 161 |
new TestCase( |
| 162 |
"Math.sqrt(65536)", |
| 163 |
256, |
| 164 |
Math.sqrt(65536)); |
| 165 |
|
| 166 |
new TestCase( |
| 167 |
"Math.sqrt(0.09)", |
| 168 |
0.3, |
| 169 |
Math.sqrt(0.09)); |
| 170 |
|
| 171 |
new TestCase( |
| 172 |
"Math.sqrt(0.01)", |
| 173 |
0.1, |
| 174 |
Math.sqrt(0.01)); |
| 175 |
|
| 176 |
new TestCase( |
| 177 |
"Math.sqrt(0.00000001)", |
| 178 |
0.0001, |
| 179 |
Math.sqrt(0.00000001)); |
| 180 |
|
| 181 |
test(); |