|
1 /// Copyright (c) 2012 Ecma International. All rights reserved. |
|
2 /// Ecma International makes this code available under the terms and conditions set |
|
3 /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the |
|
4 /// "Use Terms"). Any redistribution of this code must retain the above |
|
5 /// copyright and this notice and otherwise comply with the Use Terms. |
|
6 /** |
|
7 * @path ch08/8.5/8.5.1.js |
|
8 * @description Valid Number ranges |
|
9 */ |
|
10 |
|
11 // Check range support for Number values (IEEE 754 64-bit floats having the form s*m*2**e) |
|
12 // |
|
13 // For normalized floats, sign (s) is +1 or -1, m (mantisa) is a positive integer less |
|
14 // than 2**53 but not less than 2**52 and e (exponent) is an integer ranging from -1074 to 971 |
|
15 // |
|
16 // For denormalized floats, s is +1 or -1, m is a positive integer less than 2**52, and |
|
17 // e is -1074 |
|
18 // |
|
19 // Below 64-bit float values shown for informational purposes. Values may be positive or negative. |
|
20 // Infinity >= ~1.797693134862315907729305190789e+308 >= 2**1024 |
|
21 // MAX_NORM = ~1.797693134862315708145274237317e+308 = (2**53 - 1) * (2**-52) * (2**1023) = (2**53-1) * (2**971) = (2**1024) - (2**971) |
|
22 // MIN_NORM = ~2.2250738585072013830902327173324e-308 = 2**-1022 |
|
23 // MAX_DENORM = ~2.2250738585072008890245868760859e-308 = MIN_NORM - MIN_DENORM = (2**-1022) - (2**-1074) |
|
24 // MIN_DENORM = ~4.9406564584124654417656879286822e-324 = 2**-1074 |
|
25 |
|
26 // Fill an array with 2 to the power of (0 ... -1075) |
|
27 var value = 1; |
|
28 var floatValues = new Array(1076); |
|
29 for(var power = 0; power <= 1075; power++){ |
|
30 floatValues[power] = value; |
|
31 // Use basic math operations for testing, which are required to support 'gradual underflow' rather |
|
32 // than Math.pow etc..., which are defined as 'implementation dependent'. |
|
33 value = value * 0.5; |
|
34 } |
|
35 |
|
36 // The last value is below min denorm and should round to 0, everything else should contain a value |
|
37 if(floatValues[1075] !== 0) { |
|
38 $ERROR("Value after min denorm should round to 0"); |
|
39 } |
|
40 |
|
41 // Validate the last actual value is min denorm |
|
42 if(floatValues[1074] !== 4.9406564584124654417656879286822e-324) { |
|
43 $ERROR("Min denorm value is incorrect: " + floatValues[1074]); |
|
44 } |
|
45 |
|
46 // Validate that every value is half the value before it up to 1 |
|
47 for(var index = 1074; index > 0; index--){ |
|
48 if(floatValues[index] === 0){ |
|
49 $ERROR("2**-" + index + " should not be 0"); |
|
50 } |
|
51 if(floatValues[index - 1] !== (floatValues[index] * 2)){ |
|
52 $ERROR("Value should be double adjacent value at index " + index); |
|
53 } |
|
54 } |
|
55 |
|
56 // Max norm should be supported and compare less than inifity |
|
57 if(!(1.797693134862315708145274237317e+308 < Infinity)){ |
|
58 $ERROR("Max Number value 1.797693134862315708145274237317e+308 should not overflow to infinity"); |
|
59 } |
|
60 |
|
61 // Numbers closer to 2**1024 then max norm should overflow to infinity |
|
62 if(!(1.797693134862315808e+308 === +Infinity)){ |
|
63 $ERROR("1.797693134862315808e+308 did not resolve to Infinity"); |
|
64 } |