[Haskell-cafe] Ordering of BigFloats in numbers-3000.0.0.0

Chaddaï Fouché chaddai.fouche at gmail.com
Tue Oct 9 18:29:19 CEST 2012


On Sun, Oct 7, 2012 at 8:00 PM, Michael Orlitzky <michael at orlitzky.com> wrote:
> I'm trying to use,
>
>   http://hackage.haskell.org/package/numbers-3000.0.0.0
>
> to get better precision "for free" out of some numerical code. I ran
> into an issue pretty quickly, though. In Data.Number.BigFloat, we have,
>
>   data BigFloat e = BF (Fixed e) Integer
>     deriving (Eq, Ord)
>
> and the derived Ord is obviously incorrect:
>
>   Prelude Data.Number.BigFloat> let x = 0.1 :: BigFloat Prec50
>   Prelude Data.Number.BigFloat> let y = 0.02 :: BigFloat Prec50
>   Prelude Data.Number.BigFloat> x < y
>   True
>

That's pretty strange since the derived Ord should be the same as
Fixed Ord, which itself is just a newtype over Rational (and 1%10 <
2%100 == False), did you try to convert those BigFloat back to
Rational to see if they're still correct ? That may be worse than a
misbehaving Ord instance.

-- 
Jedaï



More information about the Haskell-Cafe mailing list