1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/test262/ch08/8.5/8.5.1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/// Copyright (c) 2012 Ecma International. All rights reserved. 1.5 +/// Ecma International makes this code available under the terms and conditions set 1.6 +/// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the 1.7 +/// "Use Terms"). Any redistribution of this code must retain the above 1.8 +/// copyright and this notice and otherwise comply with the Use Terms. 1.9 +/** 1.10 + * @path ch08/8.5/8.5.1.js 1.11 + * @description Valid Number ranges 1.12 + */ 1.13 + 1.14 +// Check range support for Number values (IEEE 754 64-bit floats having the form s*m*2**e) 1.15 +// 1.16 +// For normalized floats, sign (s) is +1 or -1, m (mantisa) is a positive integer less 1.17 +// than 2**53 but not less than 2**52 and e (exponent) is an integer ranging from -1074 to 971 1.18 +// 1.19 +// For denormalized floats, s is +1 or -1, m is a positive integer less than 2**52, and 1.20 +// e is -1074 1.21 +// 1.22 +// Below 64-bit float values shown for informational purposes. Values may be positive or negative. 1.23 +// Infinity >= ~1.797693134862315907729305190789e+308 >= 2**1024 1.24 +// MAX_NORM = ~1.797693134862315708145274237317e+308 = (2**53 - 1) * (2**-52) * (2**1023) = (2**53-1) * (2**971) = (2**1024) - (2**971) 1.25 +// MIN_NORM = ~2.2250738585072013830902327173324e-308 = 2**-1022 1.26 +// MAX_DENORM = ~2.2250738585072008890245868760859e-308 = MIN_NORM - MIN_DENORM = (2**-1022) - (2**-1074) 1.27 +// MIN_DENORM = ~4.9406564584124654417656879286822e-324 = 2**-1074 1.28 + 1.29 +// Fill an array with 2 to the power of (0 ... -1075) 1.30 +var value = 1; 1.31 +var floatValues = new Array(1076); 1.32 +for(var power = 0; power <= 1075; power++){ 1.33 + floatValues[power] = value; 1.34 + // Use basic math operations for testing, which are required to support 'gradual underflow' rather 1.35 + // than Math.pow etc..., which are defined as 'implementation dependent'. 1.36 + value = value * 0.5; 1.37 +} 1.38 + 1.39 +// The last value is below min denorm and should round to 0, everything else should contain a value 1.40 +if(floatValues[1075] !== 0) { 1.41 + $ERROR("Value after min denorm should round to 0"); 1.42 +} 1.43 + 1.44 +// Validate the last actual value is min denorm 1.45 +if(floatValues[1074] !== 4.9406564584124654417656879286822e-324) { 1.46 + $ERROR("Min denorm value is incorrect: " + floatValues[1074]); 1.47 +} 1.48 + 1.49 +// Validate that every value is half the value before it up to 1 1.50 +for(var index = 1074; index > 0; index--){ 1.51 + if(floatValues[index] === 0){ 1.52 + $ERROR("2**-" + index + " should not be 0"); 1.53 + } 1.54 + if(floatValues[index - 1] !== (floatValues[index] * 2)){ 1.55 + $ERROR("Value should be double adjacent value at index " + index); 1.56 + } 1.57 +} 1.58 + 1.59 +// Max norm should be supported and compare less than inifity 1.60 +if(!(1.797693134862315708145274237317e+308 < Infinity)){ 1.61 + $ERROR("Max Number value 1.797693134862315708145274237317e+308 should not overflow to infinity"); 1.62 +} 1.63 + 1.64 +// Numbers closer to 2**1024 then max norm should overflow to infinity 1.65 +if(!(1.797693134862315808e+308 === +Infinity)){ 1.66 + $ERROR("1.797693134862315808e+308 did not resolve to Infinity"); 1.67 +}