Skip to content

complex number function errors (all platforms)

Summary

Several mathematical functions (e.g. sqrt) give incorrect values for some complex numbers.

Steps to reproduce

Evaluate the following in GHCi:

> :m +Data.Complex
> sqrt $ (-4) :+ (-0)
0.0 :+ 2.0

Expected behavior

> sqrt $ (-4) :+ (-0)
0.0 :+ (-2.0)

Environment

  • GHC version used: 8.10.7

Optional:

  • Operating System: Windows and Linux
  • System Architecture:

The above is one example but there are several more errors. I've coded some fixes here, though these are work in progress.

The github repo also includes some tests (and I'm trying to develop more and may uncover additional issues). I'd like to include a fuller set of tests in GHC.

(I've also just raised #20424 for related issues on real numbers in Windows. Some of the fixes for complex numbers depend on these working correctly).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information