Err, why do we need FREXP?

10 views
Skip to first unread message

The Beez

unread,
Jun 21, 2026, 9:27:01 AM (9 days ago) Jun 21
to 4tH-compiler
Hi 4tH-ers!

You've probably noticed I recently added a lot of (especially Zen) floating point stuff. Some of them very niche. So -- why did that happen?

Well, I've always wanted to add the "Quake inverse SQRT" routine. Because -- well, I think it's cool. And that CLF discussion around IEEE 754 just stirred that desire. Because that is what you need to make it.

It isn't very hard to do that for ANS float. Because the mantissa and exponent for that system use base 2. And I already wrote that routine for a FLN implementation. This "EXP" format consists of a double word mantissa and a single exponent.

In order to make it work for Zen I wrote an ZEN>EXP routine which kind of worked for 64 bit. I later wrote one with a much wider range. Using ZEN>EXP I could invoke EXP>IEEE-SF and the world was fine again.

However, now I had that, I could write an FREXP routine for Zen -- and that opened up a whole new range of capabilities. In the meanwhile I added some words to manipulate the exponents of floating point numbers, the SCALBN and SCALDN words. It speeds up some divisions and manipulations considerably.

Just to prove what you may FREXP use for, I wrote a four line FSQRT routine. It works almost as well as the native one -- can't tell you how fast they are, though. Feel free to try.

Note FREXP leaves a float between 0.5 and 1 -- and an exponent, all base 2. So now you know what's exactly behind the madness! ;-)

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages