Fast base 10 mantissa / exponent to base 2 mantissa / exponent conversion
From Hans Bezemer@the.beez.speaks@gmail.com to comp.lang.forth on Fri Jun 19 18:34:26 2026
From Newsgroup: comp.lang.forth
For those who simply ask - and don't start to whine like little children
- I'll provide any missing word definitions. ;-)
Lemme help you getting started:
0 constant u>d
: >zero dup xor ;
: ?exit if exit then ;
create (mant) 2 cells allot \ limit on mantissa
variable (exp) \ limit on exponent
: normalize10 ( d1 n1 d2 n2 -- d' n')
(exp) ! (mant) 2! over 0< >r >r dabs \ save sign and exponent
begin 2dup (mant) 2@ d< while (exp) @ r@ < while d10* r> 1- >r repeat
r> -rot r> if dnegate then 2dup d0= if rot >zero ;then rot
; \ zero is a special case