ekmett / ekmett/half

decodeFloat for subnormals

Closed
#43 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
18
Forks
9
Avg merge
1h 23m
Merged PRs (30d)
1

Description

According to [Haskell 2010](https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4), the first result of `decodeFloat` is expected to return a value whose absolute value lies between `b^(d-1)` and `b^d`. This is `2^10=1024` and `2^11=2048`, even if the value is subnormal.

For normal values, this library works good:

```
$ cabal repl --build-depends half==0.3.3
ghci> :m + Numeric.Half
ghci> decodeFloat (1.0 :: Half)
(1024,-10)
ghci> decodeFloat (1.5 :: Half)
(1536,-10)
ghci> decodeFloat (1.9 :: Half)
(1946,-10)
```

For smaller values, it fails to satisfy the invariant:

```
ghci> :set -XHexFloatLiterals
ghci> decodeFloat (0x1p-14 :: Half) -- smallest positive normal
(1024,-24)
ghci> decodeFloat (0x1p-15 :: Half) -- subnormal
(512,-24)
ghci> decodeFloat (0x1p-16 :: Half) -- subnormal
(256,-24)
```

I think [this line](https://github.com/ekmett/half/blob/7237d8a25f10c61b53daa134cce537c7158d57f6/src/Numeric/Half/Internal.hs#L236) is doing the opposite.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the normal and subnormal examples with `cabal repl --build-depends half==0.3.3`, then inspect `src/Numeric/Half/Internal.hs` around line 236. Confirm that `decodeFloat` returns a first result whose absolute value is between 2^10 and 2^11 for subnormal values, while preserving the normal-value behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.