google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.56k stars 106 forks source link

Fix sqrt for complex numbers when x.im == 0 #1336

Closed vilchy closed 7 months ago

vilchy commented 9 months ago

Currently, if the imaginary part of a complex number is zero, then the imaginary part of the result of sqrt is always zero (because sign(0) = 0):

import complex
sqrt Complex(-1., 0.)
> Complex(0., 0.)

After the fix, sqrt returns the correct values:

import complex
sqrt Complex(-1., 0.)
> Complex(0., 1.)