Open roytu opened 10 years ago
This really is a deficiency of Haskell's Floating
class. It gives a default implementation for (**)
which is
x ** y = exp ((log x) * y)
and of course log 0
is undefined. For a similar reason, an error also occurs for sqrt (0 :: Fixed Prec10)
.
In some cases the behavior is not the same as built-in types:
> (-1) ** (-5) :: Double
-1.0
> (-1) ** (-5) :: BigFloat Prec50
*** Exception: Fraction.log
Would that be why doing this is wrong?:
> floor (2 ** (1 / 2) :: CReal) :: Integer
0
> ceiling (2 ** (1 / 2) :: CReal) :: Integer
1
whilst doing this is right?
> floor (sqrt 2 :: CReal) :: Integer
1
> round (sqrt 2 :: CReal) :: Integer
1
> ceiling (sqrt 2 :: CReal) :: Integer
2
> round (2 ** (1 / 2) :: CReal) :: Integer
1
The \ operator triggers an exception when the base is 0 or negative. Tested with Prec10 and Prec50 for epsilon values.
Probably makes sense that negative values crash, but 0 shouldn't.