[Haskell-cafe] [ANN] FloatingHex: Hexadecimal floats (quasiquoter and pretty-printer)

Levent Erkok erkokl at gmail.com
Sat Jan 14 23:06:16 UTC 2017


Quick update: version 0.2 of FloatingHex is now on hackage (
http://hackage.haskell.org/package/FloatingHex) which fixes a few glitches
and makes the pretty-printer compatible with C's %a modifier. This brings
the support on par with that in C/C++. The quasi-quoter is called qf, and
the pretty-printer is called showHFloat, following the naming of other
float-printers already available.

On Sat, Jan 14, 2017 at 1:10 AM, Levent Erkok <erkokl at gmail.com> wrote:

> 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 http://www.open-std.org/
> jtc1/sc22/wg14/www/docs/n1256.pdf
>
> 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!
>
> Cheers,
>
> -Levent.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170114/0c91b96d/attachment.html>


More information about the Haskell-Cafe mailing list