Floating Point Types
For floating point numbers, Haskell offers the Float
and Double
types.
They are the direct equivalents of C's float
and double
types and thus
represent 32-bit and 64-bit IEEE floating point numbers, respectively.
Again, you have the basic arithmetic operations, only this time, division is written as you'd expect.
Addition
GHCi
>>> 3.0 + 5.0
8.0
Subtraction
GHCi
>>> 3.0 - 5.0
-2.0
Multiplication
GHCi
>>> 3.0 * 5.0
15.0
Division
GHCi
>>> 3.0 / 5.0
0.6
Exponentiation
GHCi
>>> 3.0 ** 5.0
243.0
And we also have all the basic comparison operators at our disposal, just as for integers. For example,
GHCi
>>> 3.0 == 5.0
False
>>> 3.0 < 5.0
True