I also plan to implement the 80 bit "extended precision" format, which
is not IEEE 754 compatible. Perhaps the best and simplest is
Number::Pack and Number::Unpack?
Peter
tor. 3. jun. 2021 kl. 11:43 skrev Peter John Acklam <pjack...@gmail.com>:
>
> Hi
>
> I am working on two modules for encoding and decoding numbers as per IEEE754.
> The pack() function can encode and decode the formats binary32 (single
> precision) and binary64 (double precision). My module can also handle
> binary128 (quad precision), binary16 (half precision), bfloat16 (not an
> IEEE754 format, but it follows the IEEE754 pattern), and a few other formats.
>
> My question is about the namespace. Is Math::IEEE754::Encoder (and
> ...::Decoder) OK? Or is Number::IEEE754::Encoder better? Or any other?
>
> Here is an example showing how I use it:
>
> my $encoder = Math::IEEE754::Encoder -> new("binary16");
> my $bytes = $encoder -> (3.14159265358979); # = "\x42\x48"
>
> my $decoder = Math::IEEE754::Decoder -> new("binary16");
> my $number = $decoder -> ($bytes); # = 3.140625
>
> The reason for returning an anonymous function rather than implementing the
> function directly, is speed. There are some constants involved, and I don't
> want to compute them for each function call.
>
> Cheers,
> Peter John Acklam (PJACKLAM)