RE: Converting Extended (80-bit) fp numbers

new topic     » topic index » view thread      » older message » newer message

> -----Original Message-----
> From: Matthew Lewis [mailto:matthewwalkerlewis at YAHOO.COM]
> 
> I needed to convert some 80-bit floating point numbers to 
> 64-bit floating
> point numbers (doubles).  I thought I'd share what I came up with:

I sped this up by about a factor of 9 (you can get it up to 14 by using a
pointer allocated outside of the function):

include machine.e

function float80_to_atom( sequence e )
    atom mydouble, ptr, small
    integer mysign, adj_exp

    if e[10] > 127 then 
        mysign = 1
    else
        mysign = 0
    end if

    adj_exp = e[9] + and_bits(e[10],127) * 256 - 16414

    mydouble = 0

    ptr = allocate(10)
    poke(ptr, e)
    
    mydouble = peek4u(ptr+4) * power(2,adj_exp)
    adj_exp -= 32
    small = peek4u(ptr) * power(2,adj_exp)
    mydouble += small

    if mysign then
        mydouble = -mydouble
    end if
    free(ptr)
    return mydouble
end function

Matt Lewis

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu