Skip to content

A compiled zero imaginary part keeps its sign and crosses a branch cut: ln(cos(x)) at 2 is the conjugate #2236

Closed

Description

@Rafael-SOWNet

A compiled real number can carry -0 as its imaginary part, and that puts a logarithm or a root on the wrong side of its branch cut. The value comes out as the conjugate of evaluation's.

master b8a6a6f evaluated FastExpression and LINQ over Complex
ln(cos(x)) at 2 -0.8767 + 3.1416 i -0.8767 - 3.1416 i
sqrt(cos(x)) at 2 0.6451 i -0.6451 i
ln(conj(x)) at -2 0.6931 + 3.1416 i 0.6931 - 3.1416 i
sqrt(conj(x)) at -4 2 i -2 i
ln(-x) at 2 0.6931 + 3.1416 i the same, right

Complex.Cos((2, 0)) is (cos 2, -sin 2 · sinh 0), which is (-0.416, -0). Complex.Conjugate((-2, 0)) is (-2, -0). Complex.Log and Complex.Sqrt read the -0 as below the negative real axis. The library has no signed zero, so evaluation takes the principal value, +pi i. ln(-x) is right only because #2226 gives a real product a +0.

A branch-cut function compiled over Complex should read a zero part as +0. That covers ln, log, a power that is not whole, sqrt, arcsin, arccos, arctan and the rest of the inverses, and lambertw.

Found by work/compilesweep.

Part of #2195.

🤖 Generated with Claude Code

Activity

  1. added this to the 2.7.0 milestone on Oct 30, 2026
  2. moved this from Todo to In Progress in AngouriMathon Oct 30, 2026
  3. moved this from In Progress to Done in AngouriMathon Oct 30, 2026
  4. added a commit that references this issue on Nov 4, 2026
    5d4a300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions