Hi 4tH-ers!
And here it is:
include lib/fp3.4th
include lib/fieee754.4th
: finvsqrt ( f -- 1/sqrt f)
fdup f>ieee-sf 2/ negate 1597463007 + ieee-sf>f
fswap f2/ fover fdup f* f* fnegate 3 s>f f2/ f+ f*
;
16 s>f finvsqrt f. cr depth . fdepth .
And it does this:
$ pp4th -x zenisqrt.4th
0.249576787396195506538282980998661071
0 0
It's not much, is it? But WHAT is it actually? It's a bit of "DOOM" code - and it calculates the inverse square root, which is in this case: 1/sqrt(16) or one quarter. I've been trying this for some time, but without the IEEE-754 format, it was a lost cause.
Which I fixed in the last few days. And yes, it works also for ZEN float, just differently. You can now convert ZEN fp into IEEE-754 format and vice versa. Same for ANS float, BTW.
For ANS float it was easier, because that one already has a FLOAT>EXP routine, which returns a binary signed double mantissa and a signed exponent. For ZEN I had to design something that converted a ZEN fp number to a binary signed double mantissa and a signed exponent (aka radix two representation). It's not perfect, but it's good enough for government work ;-)
Soon in a SVN near you!
Hans Bezemer