Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unusable with Data.Complex #41

Open
Abbath opened this issue Aug 30, 2024 · 0 comments
Open

Unusable with Data.Complex #41

Abbath opened this issue Aug 30, 2024 · 0 comments

Comments

@Abbath
Copy link

Abbath commented Aug 30, 2024

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

exponent _ = 0

and it works just fine, tests are passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant