home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
FREXP.CPP
< prev
next >
Wrap
Text File
|
1993-08-03
|
2KB
|
68 lines
| remove exponent from floating point number
| C Interface
| double frexp(double value, int *eptr)
|
| returns significand (|significand| < 1)
| in *eptr returns n such that value = significand * 2**n
|-----------------------------------------------------------------------------
| ported to 68000 by Kai-Uwe Bloem, 12/89
| #1 original author: Peter S. Housel 9/21/88,01/17/89,03/19/89,5/24/89
| #2 added support for denormalized numbers -kub-, 01/90
| # ported to gcc ++jrb 04/90
|-----------------------------------------------------------------------------
BIAS8 = 0x3ff - 1
.text; .even
.globl _frexp
_frexp:
movel sp@(12),a0 | initialize exponent for loop
#ifdef __MSHORT__
clrw a0@
#else
clrl a0@
#endif
lea sp@(4),a1
moveml d2-d7,sp@-
2:
movew a1@,d0 | extract value.exp
movew d0,d2 | extract value.sign ++jrb
lsrw #4,d0
andw #0x7ff,d0 | kill sign bit
cmpw #BIAS8,d0 | get out of loop if finally (a1) in [0.5,1.0)
beq 3f
andw #0x0f,a1@ | remove exponent from value.mantissa
tstw d0 | check for zero exponent - no leading 1
beq 0f
orw #0x10,a1@ | restore implied leading 1
bra 1f
0: addw #1,d0
1:
movel a1@,d1 | check for zero
orl a1@(4),d1
beq 3f | if zero, all done : exp = 0, num = 0.0
subw #BIAS8,d0 | remove bias
#ifdef __MSHORT__
addw d0,a0@ | add current exponent in
#else
extl d0
addl d0,a0@ | add current exponent in
#endif
movew #BIAS8,d0 | set bias for return value
clrw d1 | rounding = 0
pea L0 | call to norm_df (dirty, but dont ...
moveml d2-d7,sp@- | ... need to copy with -mshort)
moveml a1@,d4-d5
jmp norm_df | normalize result
L0:
moveml d0-d1,a1@
bra 2b | loop around to catch denormalized numbers
3:
moveml a1@,d0-d1
moveml sp@+,d2-d7
| d0-d1 has normalized mantissa
rts