poke-devel
[Top][All Lists]

## Re: Floating point

 From: Nicholas Patrick Subject: Re: Floating point Date: Wed, 12 May 2021 20:44:07 -0500

Thanks Jose.  That's about what I figured based on a few searches.  I actually started with writing a pickle for it...and decided I ought to look up the simplest floating point printer.  I stopped when I hit the dragonbox algorithm and realized it's a bigger project than I'm willing to commit to currently.

Taking a different approach...is there any plan to implement an interface for interoperability with external applications?  The idea being I could export the printf to some other application.

On Wed, May 12, 2021 at 8:08 AM Jose E. Marchesi <jemarch@gnu.org> wrote:

Hi Nicholas.

> I've got a bunch of binary data files that contain a mixture of 32 and 64
> bit IEEE 754 floating point values. How can I print the values as a
> formatted decimal?

Poke doesn't support IEEE 754 floating-point values as native values.

The idea is to instead have a iee754.pk pickle containing definitions
for the several supported precision FP numbers, and methods and utility
functions to work with them (like printing their value for example.)

Unfortunately no one has written such a pickle yet, but it sounds like a
fun project :)

This could be a start for ieee754.pk:

type IEEE754_S_FP =
struct uint<32>
{
uint<1> sign;
uint<8> exponent;
uint<23> mantissa;

method denormalised_p = int<32>:
{
return exponent == 0 && mantissa != 0;
}

method is_inf = int<32>:
{
return exponent == 0xff && mantissa == 0;
}

method is_nan = int<32>:
{
return (exponent == -1 as uint<8>
&& (sign == 0 || mantissa != 1 <<. 22);
}

/* More methods... */
};