From: Matt Borland (matt_at_[hidden])
Date: 2025-02-01 19:41:36


>

>

> John Maddock wrote:
>

> > In late breaking news, I also hear from Matt that GCC and IBM both "cheat" by using (mutually incompatible) non-IEEE binary encodings.
>

>

> Are these documented anywhere? It would be interesting to look at them for inspiration.
>

I wish. They docs just say BID format. Here is what IEEE 754 specifies:

https://github.com/cppalliance/decimal/blob/develop/include/boost/decimal/decimal32.hpp#L72-L102

Here is what I gathered from trying to wrap the builtin libstdc++ (IBM) types:

https://github.com/cppalliance/decimal/pull/823/files#diff-dacda7fd3b3e5817b4e2768685693e26a2cf70cb58c68e1798b21a243e384953R30-R38

I kept dumping the bits of powers of two etc to figure it out:

https://github.com/cppalliance/decimal/pull/823/files?file-filters%5B%5D=.cpp&file-filters%5B%5D=No+extension&show-viewed-files=true#diff-b439f27c2dfc48ec83a0f53ee47db4b27c21f2edf8ff6245931c09b06477a80dR59

Basically, it's laid out like a binary float most of the time. In Intel's case for implementation of mathematical functions they convert the Decimal32 to a float, perform an operation, and then convert back. Makes things pretty quick when your conversion operation is NOP, and then you can offload computations to presumably the MKL.

Matt