Mismatch between documentation and behaviour of encodeFloat
|Reported by:||daniel.is.fischer||Owned by:|
|Type of failure:||Documentation bug||Test Case:|
|Related Tickets:||Differential Revisions:|
In the process of elaborating the docs to treat #3898, I wrote
-- | 'encodeFloat' performs the inverse of 'decodeFloat' in the -- sense that for finite @x@ with the exception of @-0.0@, -- @'uncurry' 'encodeFloat' ('decodeFloat' x) = x@. -- @'encodeFloat' m n@ is the closest representable floating-point -- number to @m*b^^n@ (or @±Infinity@ if overflow occurs).
Unfortunately, the last sentence is not quite true. If the end result is a subnormal number, encodeFloat performs two roundings, which may lead to a wrong result (can be 1 ulp off). Changing encodeFloat so that it always finds the closest representable number would cost a lot in performance, it would bring it close to fromRational. So the thing to do is change the docs, I just don't know how yet.