Proposal: Add "fma" to the RealFloat class

Scott Turner 2haskell at
Tue May 5 11:22:41 UTC 2015

On 2015-05-05 00:54, Levent Erkok wrote:
> I can see at least two designs:
>    * One where the rounding mode goes with the operation: `fpAdd
> RoundNearestTiesToEven 2.5 6.4`. This is the "cleanest" and the
> functional solution, but could get quite verbose; and might be costly
> if the implementation changes the rounding-mode at every issue.
>    * The other is where the operations simply assume the
> RoundNearestTiesToEven, but we have lifted IO versions that can be
> modified with a "with" like construct:  `withRoundingMode
> RoundTowardsPositive $ fpAddRM 2.5 6.4`. Note that `fpAddRM` (*not*
> `fpAdd` as before) will have to return some sort of a monadic value
> (probably in the IO monad) since it'll need to access the rounding
> mode currently active.
> Neither choice jumps out at me as the best one; and a hybrid might
> also be possible. I'd love to hear any insight you gain regarding
> rounding-modes during your experiment.

The monadic alternative is more readily extensible to handle IEEE 754's
sticky flags: inexact, overflow, underflow, divide-by-zero, and invalid.

More information about the Libraries mailing list