[Haskell-cafe] [ANN] FloatingHex: Hexadecimal floats (quasiquoter and pretty-printer)
erkokl at gmail.com
Sat Jan 14 09:10:20 UTC 2017
FloatingHex (http://hackage.haskell.org/package/FloatingHex) is a simple
package that implement hexadecimal notation for floating point numbers, as
described in p57-58 of
The package provides a quasi-quoter for hexadecimal floats: hf, and a
pretty-printer for floats to show them in this notation: showFFloat. (Note
that the latter is not 100% compatible with C's %a modifier for printf, but
it does render a faithful representation of its input.)
Hex-floats are useful as they allow writing floating-point constants
without any loss of precision, while remaining human readable. For
instance, the float 2 is written as 0x1p1. (With the quasiquoter, the
syntax is [hf|0x1p1|].) This representation is to be preferred over decimal
rendering where loss of precision can be a problem: Note that not all
floating point numbers have a terminating decimal representation as
currently required by the Haskell syntax.
It would be nice if Haskell itself allowed for such literals in the
language specs itself, following the recent changes to other language
standards. (Again, see p57-58 of
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf for the new C
standard.) In the mean time, I hope FloatingHex library will provide a
workaround for the numerophilias amongst us.
Bug reports and improvements always welcome!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe