Hi All,
I've made a few changes recently to my Haskell Posit library, some based on discussions from this board. I've also read some mention of a new Posit Standard. I'm quite interested in having my library based on the Posit Standard, so I thought I'd open up a discussion about my recent changes and share some thoughts. I have felt free to experiment with some changes since the Posit Standard did not discuss them.
1. Automatic rewriting of fused operations
So in my recent pull request located here:
Fused ops rewrite rules, I implemented functionality for the compiler to attempt to automatically rewrite the code to use various fused operations. The functionality is somewhat fragile and from what I read in "The End of Error", that's not great. I've also use the functionality to find places in the code where I could explicitly write the fused operations.
2. Removed various constants and functions
I read on this board about the Posit Standard perhaps describing more special functions. I've removed some of the special functions I've implemented previously (I was not really happy with the implementation), and renamed some of the specific values to not use the names of Greek letters to not pollute the namespace.
3. Implemented a printing of Posit Numbers to round trip
My previous implementation did not fully round trip the printing and reading of Posits. I've now changed to the following algorithm:
decimalPrec posit =
let regimeFormat = findRegimeFormat @es posit
regimeCount = countRegimeBits @es regimeFormat posit
fractionSize = max (fromIntegral (nBits @es) - fromIntegral (signBitSize @es) - regimeCount - fromIntegral (exponentSize @es)) 0 -- fractionSize is at least zero
in succ.ceiling $ (fromIntegral fractionSize + 1) * log10Of2 + halflog10Of2
The round-tripping was tested to P32 exhaustively, it also seems to work up-to at least P256 in my spot checks.
4. Implementation of an `approxEq` function
Approximately Equal, is something I've found I need in practice. After thinking of rather complex implementations I've thought of a rather simple implementation that uses existing Posit Standard functionality:
approxEq a b =
let a' = convert a :: Posit (Prev es)
b' = convert b :: Posit (Prev es)
in a' == b'
Thanks,
Nathan.