conversion algorithm, floating pt formats

conversion algorithm, floating pt formats

Post by pada » Fri, 02 Mar 1990 19:55:00



I'm posting the following for a friend who does not have access to the net:

Does anyone know of an algorithm for converting IEEE format floating point
numbers to bcd floating point? Is there a commercially available  program in 'C' or 68881 assembler to do this? Please respond to the net or to my mail id

 Thanks, Padma Krishnaswamy

 
 
 

conversion algorithm, floating pt formats

Post by Geoffrey Coop » Fri, 02 Mar 1990 06:50:00



> Does anyone know of an algorithm for converting IEEE format floating point
> numbers to bcd floating point?

You're in luck.  BCD and IEEE are two formats supported by the 68881
hardware.  The machine co-instructions of the 68881-68020 combination
include commands to fetch a number from either format into a register
and write it back in either format.  So you can accomplish what you want
in two 68881 FMOVE.x instructions.  See the manual for details.

- Geof
--
{decwrl,sun,saber}!imagen!geof

 
 
 

conversion algorithm, floating pt formats

Post by Steven E. Rice, P. » Fri, 02 Mar 1990 09:18:00




> I'm posting the following for a friend who does not have access to the net:

> Does anyone know of an algorithm for converting IEEE format floating point
> numbers to bcd floating point? Is there a commercially available program
> in 'C' or 68881 assembler to do this? Please respond to the net or to my
> mail id.

The 68881 fmove instruction will do this.  Storing a value as a BCD
result will convert it to a packed decimal string (2 digits per byte)
with an exponent, as appropriate.  The 68020 has an unpack instruction
which allows unpacking the result as one digit per byte, with an
appropriate value (hex '3' is useful) in the upper 4 bits of each byte.

                                        Steve Rice

-----------------------------------------------------------------------------
* Every knee shall bow, and every tongue confess that Jesus Christ is Lord! *

old: {decvax | hplabs | ihnp4 | uw-beaver}!tektronix!videovax!stever

 
 
 

1. Floating Pt to Fixed Pt Algorithm?

|>
|> Hello, I just happened to run into this group which could hopefully answer a
|> question on real number conversion.
|>
|> I'd like to find a _very_ fast algorithm which converts floating point numbers
|> to fixed point using C/C++ at a binary level ( rather than strings ).  The reason
|> for being very fast is that I will have _mega_bytes of data to convert.
|>
|> If anyone knows of any general pseudocode algorithms or even ideas, please
|> e-mail me ( or post here ) if you can...
|>

Just use an union of your floating-point data type and and unsigned. Initialize
the floating-point part of the union with your data to convert and do the
comversion as:

        1/ get the exponent exp
        2/ substract the bias from the exponent (x7f for float, x3ff for double)
        3/ get the mantissa
        3'/ if implicit bit, add it to the mantissa
        4/ shift right the mantissa by (N - exp), where N is 23 for float, 52
           for double
        5/ add the sign

Following is a quick and dirty routine to convert from float to int, take it
just as an illustration of the above:

union thirty_two

  {
    float f;
    unsigned long l;
  };

long f2i (float x)

  {
    long mant;
    int exp, sign;
    union thirty_two fp32;
    fp32.f = x;
    /* get the sign */
    sign = fp32.l & 0x80000000;
    /* get the exponent */
    exp = (fp32.l >> 23) & 0xff;
    /* remove the bias */
    exp -= 0x7f;
    /* get the mantissa and make the implicit bit explicit */
    mant = fp32.l & 0x7fffff | 0x800000;
    /* convert the fixed point mantissa to an integer */
    mant >>= 23 - exp;
    /* fix the sign and return */
    return (sign) ? -mant : mant;
  }

There are many issues not addressed in this simple example:

        - overflow/underflow
        - rounding (the above routine truncates)

        Patrice.
--

        Patrice L. Roussel

2. emacs19 & ispell problem

3. conversion between floating point formats

4. Pop-up in the LAN

5. Data-General floating-point format conversion

6. syko stlrx mkd rk szmzn aii mit gqmg

7. Conversion of 1750A floating point to IEEE format

8. Currency Converter Software

9. S/370 float -> DEC float conversion?

10. seeking floating pt experiences with UT6R000

11. floating pt multiply..

12. Accurate results from FP computation ( was IEEE Floating Pt )