Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.88k stars 151 forks source link

incorrect/inconsistent evaluation of some exponents #624

Closed cyn4289 closed 8 months ago

cyn4289 commented 8 months ago
> (-1)^(1/3)

  (-1)^(1 / 3) = (i * sqrt(3) + 1) / 2 = approx. 0.5000000000 + 0.8660254038i

> cbrt(-1)

  cbrt(-1) = -1

> root(-1,3)

  root(-1, 3) = -1

expected behavior: (-1)^(1/3) = cbrt(-1) = -1

issue: cbrt(-1) evaluates correctly to -1, however (-1)^(1/3) unexpectedly evaluates to a different value including an imaginary part. I suspect that whatever handles simplifying expressions including imaginary numbers is messing this up.

version info: Qalc version 4.9.0 (CLI) Windows 11 10.0.22621

edit: -1 and 0.5+0.8660254038i are both correct answers, and other programs sometimes do this as well-- it'd still be nice to show both or at least show the same one.

hanna-kn commented 8 months ago

(-1)^(1/3), and other fractional exponents, returns the principal root, while cbrt() and root() returns the real-valued root, for negative bases.

This is common behaviour among mathematical software.

cyn4289 commented 8 months ago

(-1)^(1/3), and other fractional exponents, returns the principal root, while cbrt() and root() returns the real-valued root, for negative bases.

This is common behaviour among mathematical software.

You're totally right, I tested it with a few different programs and it's pretty inconsistent and often this behavior is there, should've done more than check against chrome's calculator before opening the issue