js/src/tests/test262/ch08/8.5/8.5.1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial