|
<!DOCTYPE html> |
|
<head> |
|
<title>Foo</title> |
|
</head> |
|
<body> |
|
<table id="tests"> |
|
<thead> |
|
<tr> |
|
<th>Actual</th> |
|
<th>Expected</th> |
|
<th>Native ArrayBuffer</th> |
|
<th>Comments</th> |
|
</tr> |
|
</thead> |
|
</table> |
|
|
|
<script> |
|
var getFloat64LE = function(a,z,b,c){for(b=a[c=6]%16;c;b=a[--c]+b*256);c=a[7]<<25>>>21|a[6]>>4;return(a[7]>>7?-1:1)*z(2,c-1074)*(c?c^2047?b/2+z(2,51):!b/0:b)} |
|
|
|
var nativeGetFloat64LE = function(a){ |
|
if (!window.ArrayBuffer || !window.DataView) return 'Not available for this browser'; |
|
var b = new ArrayBuffer(8); |
|
for (var i=0; i<8; i++){ |
|
b[i] = a[i]; |
|
}; |
|
return new DataView(b).getFloat64(0, true /* LE flag */); |
|
} |
|
|
|
var testCases = [ |
|
{test: [0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xD5, 0x3F], expect: '0.3333333333333333', name: '+1/3'}, |
|
{test: [0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xD5, 0xBF], expect: '-0.3333333333333333', name: '-1/3'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], expect: '0', name: 'zero'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80], expect: '0', name: 'minus zero'}, |
|
{test: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00], expect: '2.225073858507201e-308', name: 'Highest subnormal number'}, |
|
{test: [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80], expect: '-5e-324', name: 'Lowest subnormal number (Number.MIN_VALUE)'}, |
|
{test: [0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80], expect: '-1e-323', name: 'Second lowest subnormal number'}, |
|
{test: [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F], expect: '1.7976931348623157e+308', name: 'Highest finite number (Number.MAX_VALUE)'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F], expect: 'Infinity', name: 'Infinity'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF], expect: '-Infinity', name: 'Minus infinity'}, |
|
{test: [0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0xF0, 0xFF], expect: 'NaN', name: 'NaN'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF1, 0x7F], expect: 'NaN', name: 'Another NaN'}, |
|
{test: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x40], expect: '42', name: 'The answer to Life, the Universe and Everything'} |
|
]; |
|
|
|
var tbody = document.getElementById('tests').appendChild(document.createElement("tbody")); |
|
for (var i=0; i<testCases.length; i++){ |
|
with (testCases[i]){ |
|
var data = [ |
|
getFloat64LE(test, Math.pow), |
|
expect, |
|
nativeGetFloat64LE(test), |
|
name |
|
] |
|
}; |
|
var tr = tbody.appendChild(document.createElement('tr')); |
|
for (var j=0; j<data.length; j++){ |
|
tr.appendChild(document.createElement('td')).appendChild(document.createTextNode(data[j])); |
|
}; |
|
} |
|
</script> |
|
</body> |
|
</html> |
This is awesome, @subzey!
Btw, what is the difference between index-no-external-static.js and index.js?