diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /src/z80/support.c | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'src/z80/support.c')
| -rw-r--r-- | src/z80/support.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/z80/support.c b/src/z80/support.c new file mode 100644 index 0000000..05352a5 --- /dev/null +++ b/src/z80/support.c @@ -0,0 +1,37 @@ +/** @file z80/support.c + */ +#include "z80.h" +#include <math.h> + +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 = (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; + } + + 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); + + return 0; +} |
