I want to use Data.Complex to do tricks like this:
ghci> (-5) ** 5 :: Complex (CReal 50)
-3125.0000000000000000 :+ 0.0000000000000000
But some functions from Data.Complex (log, sqrt) use magnitude, which uses scaleFloat and exponent from RealFloat. While scaleFloat works, exponent throws an error.
magnitude :: (RealFloat a) => Complex a -> a
magnitude (x:+y) = scaleFloat k
(sqrt (sqr (scaleFloat mk x) + sqr (scaleFloat mk y)))
where k = max (exponent x) (exponent y)
mk = - k
sqr z = z * z
I have tried changing exponent to
and it works just fine, tests are passing.
I want to use
Data.Complexto do tricks like this:But some functions from
Data.Complex(log,sqrt) usemagnitude, which usesscaleFloatandexponentfromRealFloat. WhilescaleFloatworks,exponentthrows an error.I have tried changing
exponenttoand it works just fine, tests are passing.