https://github.com/leventerkok/floatinghex
Hexadecimal Floats for Haskell
https://github.com/leventerkok/floatinghex
floating-point haskell hexadecimal-floats ieee754
Last synced: 10 months ago
JSON representation
Hexadecimal Floats for Haskell
- Host: GitHub
- URL: https://github.com/leventerkok/floatinghex
- Owner: LeventErkok
- License: other
- Created: 2017-01-14T07:18:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-09-05T22:23:48.000Z (over 5 years ago)
- Last Synced: 2025-03-23T20:51:14.166Z (10 months ago)
- Topics: floating-point, haskell, hexadecimal-floats, ieee754
- Language: Haskell
- Size: 15.6 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
## FloatingHex: Read/Write Hexadecimal floats
[](http://hackage.haskell.org/package/FloatingHex)
[](http://travis-ci.org/LeventErkok/FloatingHex)
### Hexadecimal Floats
For syntax reference, see: , 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
```haskell
{-# 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 use floating-point literals in pattern matching.)
### Thanks
The following people reported bugs, provided comments/feedback, or contributed to the development of
FloatingHex in various ways: Herbert Valerio Riedel.