
On Thu, Apr 11, 2013 at 2:50 AM, Levent Erkok
Great catch! To be IEEE-754 compliant, signum *should* return NaN on NaN. Here's the new code:
instance Num Float where signum x | isNegativeZero x = x | isNaN x = x | x == 0 = 0 | x > 0.0 = 1 | otherwise = negate 1 abs x | isNegativeZero x = 0 | x >= 0 = x | otherwise = negate x
Of course, this extra test makes Simon's point even more relevant; i.e.; these should map to underlying CPU's native signum/abs functions if available.
-Levent.
Maybe it would be simpler to say: signum x | x == 0 = x | isNaN x = x | x > 0 = 1 | otherwise = negate 1 Shachaf