1. Converting reals

Can anyone write a Euphoria function to convert a
48 bit Pascal real to Euphoria atom?

Format is: msb..................................lsb
      bit 1 = sign
          bits 2..39 = f
              bits 40..48 = e

The formula given is :
  if 0 < e <= 255 then v = (-1)s * 2(e-129) * (1.f)
                               ^       ^
  the s and e-129 are superscripts.

Thanks,
Irv

new topic     » topic index » view message » categorize

2. Re: Converting reals

On Tue, 9 Feb 1999, Irv Mullins wrote:

] Can anyone write a Euphoria function to convert a
] 48 bit Pascal real to Euphoria atom?
]
] Format is: msb..................................lsb
]       bit 1 = sign
]           bits 2..39 = f
]               bits 40..48 = e
]
] The formula given is :
]   if 0 < e <= 255 then v = (-1)s * 2(e-129) * (1.f)
]                                ^       ^
]   the s and e-129 are superscripts.

It might help if you told us how you've currently got it stored in
memory... It's too big for an integer...

On the fly coding...

00000000 00000000 00000000 00000000 00000000 00000000
sfffffff ffffffff ffffffff ffffffff ffffffff eeeeeeee

function two_to_the(integer n)
    return power(2, n)
end function

function pascal48IEEE_to_atom(six_byte_integer ieee)
    six_byte_integer index, index2
    integer sign, number, mantissa
    atom out

    index = two_to_the(47)

    sign = 1 - 2 * (and_bits(ieee, index)/index)

    index2 = two_to_the(8)
    index = (two_to_the(46)/index2 - 1) * index2

    number = and_bits(ieee, index) / index2

    index2 = index2 - 1

    mantissa = and_bits(ieee, index2) - two_to_the(7) - 1

    out = sign * number * two_to_the(mantissa)
end function

I may have misplaced a power of two by coding on the fly and not
testing but HTH,
Carl

--
Carl R White -- Final Year Computer Science at the University of Bradford
E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :)
URL...........: http://www.bigfoot.com/~cyrek/
Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58"

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu