struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / src / z80 / support.c
blob05352a5643e4016f3a37028ddc7343a4dfbea853
1 /** @file z80/support.c
2 */
3 #include "z80.h"
4 #include <math.h>
6 int
7 convertFloat (Z80_FLOAT * f, double native)
9 unsigned long mantissa, exponent;
10 double f2;
11 wassert (f);
12 if (native != 0)
14 f2 = floor (log (fabs (native)) / log (2)) + 1;
15 mantissa = (unsigned long) (0x1000000 * fabs (native) / exp (f2 * log (2))) ;
16 mantissa &= 0xffffff;
17 exponent = (unsigned long) (f2 + 0x40) ;
18 if (native < 0)
19 exponent |= 0x80;
21 else
23 mantissa = 0;
24 exponent = 0;
27 f->w[0] = (WORD) mantissa;
28 f->w[1] = (BYTE) (mantissa >> 16);
29 f->w[1] |= exponent << 8;
31 f->b[0] = (BYTE) f->w[0];
32 f->b[1] = (BYTE) (f->w[0] >> 8);
33 f->b[2] = (BYTE) f->w[1];
34 f->b[3] = (BYTE) (f->w[1] >> 8);
36 return 0;