User:Chaser Zaks/IEEE-754

From Second Life Wiki
< User:Chaser Zaks
Revision as of 15:21, 8 November 2017 by Chaser Zaks (talk | contribs) (Created page with "Licensed under public domain ==Encoder== <syntaxhighlight lang="lsl2"> //Todo </syntaxhighlight> ==Decoder== <syntaxhighlight lang="lsl2"> float integerToFloat(integer input...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Licensed under public domain

Encoder

//Todo

Decoder

float integerToFloat(integer input){
    integer sign = 1;
    if(input & 0x80000000) sign = -1;
    
    integer pow = -1;
    float val = 0.0;
    integer i = 9;
    for(; i < 32; i++)
        val += (float)(((input >> 31 - i) & 1)) * (float)llPow(2.0, pow--);
    
    return sign * (float)llPow( 2.0, ((input & 0x7f800000) >> 23) - 127) * (val + 1.0);
}

Also see