- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
datatypes.Float = function(inString)
{
var fBytes = [];
for (var i=0;i<4;i++)
{
var curByte = (inString.charCodeAt(i)&255).toString(2);
var byteLen = curByte.length;
if (byteLen<8)
{
for (var bit=0;bit<(8-byteLen);bit++)
curByte = '0'+curByte;
}
fBytes[i] = curByte;
}
var fBits = fBytes[3]+fBytes[2]+fBytes[1]+fBytes[0];
var fSign = parseInt(fBits[0]) ? -1 : 1;
var fExp = parseInt(fBits.substring(1,9),2)-127;
var fMan;
if (fExp == -127)
fMan = 0;
else
{
fMan = 1;
for (i=0;i<23;i++)
{
if (parseInt(fBits[9+i])==1)
fMan = fMan + 1/Math.pow(2,i+1);
}
fMan = fMan.toFixed(7);
}
return(parseFloat((fSign*Math.pow(2,fExp)*fMan).toFixed(3)));
}