octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VAX<-->IEEE 32bit float conversion


From: Wolfgang Westphal
Subject: Re: VAX<-->IEEE 32bit float conversion
Date: Mon, 26 Jul 2004 13:45:13 +0200
User-agent: KMail/1.6.2

Am Thursday 22 July 2004 22:27 schrieb John W. Eaton:
> In any case, I don't think the conversion can be as simple as your
> code suggests.  The format described here
>  
> http://h18009.www1.hp.com/fortran/docs/unix-um/dfumcompat.htm#index_x
>_3983
>
> looks like this:
>
>    31        16   15    14       7 6        0
>
>   |   fraction | sign  | exponent | fraction |
>
>   * Bit 15 is the sign bit (0 for positive numbers, 1 for negative
> numbers).
>
>   * Bits 14:7 are a binary exponent in excess 128 notation (binary
>     exponents from --127 to 127 are represented by binary 1 to 255).
>
>   * Bits 6:0 and 31:16 are a normalized 24-bit fraction with the
>     redundant most significant fraction bit not represented.
>
> It looks like your code does not account for the fact that there are
> only 7 bits in the first part of the fraction.  Or am I missing
> something?

The code does not take care of that, because it doesn't need to. 
Starting from VAX, the byte swapping operations lead to the following 
bit order

     31    30      23 22                          0
   | sign | exponent |           fraction          |
   
Which is the correct order for IEEE. To make the conversion perfect you 
then need to adjust the exponent taking in account

  * the excess of the notation (VAX: 128, IEEE: 127)
  * the inpretation of the fraction part f. That is (notation in base-2)
      .1f in VAX
      1.f in IEEE
    which gives an factor of 2.

So we need to reduce the exponent by 2. This can most effectivly done by 
decreasing the highest ordered byte by one (the least significant bit 
of the exponent is in the next byte).

So to conclude, I do think the conversion is as simple as presented in 
the patch.

Regards,
Wolfgang
-- 
   / Wolfgang Westphal         / EMail: address@hidden /
  / TUM Physik-Department E15 /                           /
 / James Franck Stra├če       / Tel:   +49 89 289 125 25  /
/ D-85748 Garching          / Fax:   +49 89 289 126 80  /



reply via email to

[Prev in Thread] Current Thread [Next in Thread]