FloatingHex: Read and write hexadecimal floating point numbers

[ bsd3, library, tools ] [ Propose Tags ]
This version is deprecated.

Read and write hexadecimal floating point numbers. Provides a quasiquoter for entering hex-float literals, and a function for printing them in hexadecimal.

See: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, pages 57-58. We slightly diverge from the standard and do not allow for the "floating-suffix," as the type inference of Haskell makes this unnecessary.

For details, please see: http://github.com/LeventErkok/FloatingHex/


[Skip to Readme]

Modules

[Index]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.3, 0.4, 0.5 (info)
Change log CHANGES.md
Dependencies base (>=4 && <5), template-haskell (>=2.10) [details]
License BSD-3-Clause
Copyright Levent Erkok
Author Levent Erkok
Maintainer erkokl@gmail.com
Revised Revision 1 made by HerbertValerioRiedel at 2017-01-15T10:10:04Z
Category Tools
Source repo head: git clone git://github.com/LeventErkok/FloatingHex.git
Uploaded by LeventErkok at 2017-01-14T19:59:42Z
Distributions Arch:0.5, Debian:0.4, LTSHaskell:0.5, NixOS:0.5, Stackage:0.5
Reverse Dependencies 1 direct, 24 indirect [details]
Downloads 8969 total (41 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-01-14 [all 1 reports]

Readme for FloatingHex-0.2

[back to package description]

FloatingHex: Read/Write Hexadecimal floats

Hackage version Build Status

Hexadecimal Floats

For syntax reference, see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf, pages 57-58. We slightly diverge from the standard and do not allow for the "floating-suffix," as the type inference of Haskell makes this unnecessary. Some examples are:

  [hf|0x1p+1|]
  [hf|0x1p+8|]
  [hf|0x1.b7p-1|]
  [hf|0x1.fffffffffffffp+1023|]
  [hf|0X1.921FB4D12D84AP-1|]

This format allows for concise and precise string representation for floating point numbers. Note that you need the QuasiQuotes extension of GHC to be able to write these literals.

Example

{-# LANGUAGE QuasiQuotes #-}
import Data.Numbers.FloatingHex

-- expressions
f :: Double
f = [hf|0x1.f44abd5aa7ca4p+25|]

-- patterns
g :: Float -> String
g [hf|0x1p1|]  = "two!"
g [hf|0x1p-1|] = "half!"
g d            = "something else: " ++ show d

-- showing hexadecimal floats
test = showHFloat [hf|0x1.f44abd5aa7ca4p+25|] ""

(Note that while the quasiquoter allows for floating-point patterns, it is usually not a good idea to have floating-point literals used in pattern matching.)