Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Haskell have isIEEE if it always evaluates to True?

Tags:

haskell

The Haskell RealFloat typeclass has a function called isIEEE which, according to the documentation, gives 'True if the argument is an IEEE floating point number' (and, one would imagine, False otherwise).

But here's the implementation of isIEEE for Float:

instance RealFloat Float where
  ...
  isIEEE _ = True

And here's the implementation for Double:

instance RealFloat Double where
  ...
  isIEEE _ = True

If isIEEE is always unconditionally True, why use it? Why have it in the Prelude at all?

like image 630
Wander Nauta Avatar asked Nov 06 '15 10:11

Wander Nauta


1 Answers

As leftaroundabout and Koterpillar mentioned in the comments, it is possible to define your own instances of RealFloat. These custom-made float types do not necessarily have to follow the IEEE standards.

instance RealFloat MyFloat where
  isIEEE _ = False
  ...

Additionally, if your floating-point type isn't IEEE, you are allowed to have all RealFloat predicates return False:

(...) The functions isNaN, isInfinite, isDenormalized, isNegativeZero, and isIEEE all support numbers represented using the IEEE standard. For non-IEEE floating point numbers, these may all return false.

Haskell 98 Report, 6.4.6

like image 111
2 revs Avatar answered Oct 24 '22 22:10

2 revs