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

Sqrt on complex number loops #181

Open
andriusstank opened this issue Feb 18, 2025 · 0 comments
Open

Sqrt on complex number loops #181

andriusstank opened this issue Feb 18, 2025 · 0 comments

Comments

@andriusstank
Copy link

Sqrt enters infinite loop for some complex numbers, for example:

ghci> import NumHask.Prelude 
ghci> sqrt ((-1) +: 1) :: Complex Double
Complex {complexPair = (*** Exception: stack overflow

I have traced it to log from EuclideanPair here:

instance (Ord a, TrigField a, ExpField a) => ExpField (EuclideanPair a) where
  ...
  log (EuclideanPair (x, y)) = EuclideanPair (log (sqrt (x * x + y * y)), atan2' y x)
    where
      atan2' y x
        | ...
        | (x P.<= zero P.&& y P.< zero) || (x P.< zero) =
            negate (atan2' (negate y) x)
        | ...

A clause before in atan2' is | x P.< one P.&& y P.> one = ..., it seems to have a typo - there should be zeros instead of ones. I have fixed that, but it still loops with log (EuclideanPair (-1, 0)), so there must be something more. There are many tricky cases, I'm not sure how to fix it properly.

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