X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fz80%2Fsupport.c;h=05352a5643e4016f3a37028ddc7343a4dfbea853;hb=b0528af48546cdfe3f2be3c126732eaff8933fe2;hp=01bbe8454170cd9d6cd284c9f7f0b4ab27e85d4b;hpb=e8af787a7af30e7d132b40a278b1d131032f3b88;p=fw%2Fsdcc diff --git a/src/z80/support.c b/src/z80/support.c index 01bbe845..05352a56 100644 --- a/src/z80/support.c +++ b/src/z80/support.c @@ -3,32 +3,35 @@ #include "z80.h" #include -int convertFloat(Z80_FLOAT *f, double native) +int +convertFloat (Z80_FLOAT * f, double native) { - unsigned long mantissa, exponent; - double f2; - wassert(f); - if (native!=0) { - f2 = floor(log(fabs(native))/log(2))+1; - mantissa = 0x1000000*fabs(native)/exp(f2*log(2)); - mantissa &= 0xffffff; - exponent = f2 + 0x40; - if (native<0) - exponent |= 0x80; + unsigned long mantissa, exponent; + double f2; + wassert (f); + if (native != 0) + { + f2 = floor (log (fabs (native)) / log (2)) + 1; + mantissa = (unsigned long) (0x1000000 * fabs (native) / exp (f2 * log (2))) ; + mantissa &= 0xffffff; + exponent = (unsigned long) (f2 + 0x40) ; + if (native < 0) + exponent |= 0x80; } - else { - mantissa = 0; - exponent = 0; + else + { + mantissa = 0; + exponent = 0; } - f->w[0] = (WORD)mantissa; - f->w[1] = (BYTE)(mantissa>>16); - f->w[1] |= exponent << 8; - - f->b[0] = (BYTE)f->w[0]; - f->b[1] = (BYTE)(f->w[0]>>8); - f->b[2] = (BYTE)f->w[1]; - f->b[3] = (BYTE)(f->w[1]>>8); + f->w[0] = (WORD) mantissa; + f->w[1] = (BYTE) (mantissa >> 16); + f->w[1] |= exponent << 8; - return 0; + f->b[0] = (BYTE) f->w[0]; + f->b[1] = (BYTE) (f->w[0] >> 8); + f->b[2] = (BYTE) f->w[1]; + f->b[3] = (BYTE) (f->w[1] >> 8); + + return 0; }