Skip to content

Commit

Permalink
complex: Fix complex ln and power operator when not in radians
Browse files Browse the repository at this point in the history
When the change in complex representation was made to use internal powers of pi,
as well as to support angular modes, an internal uses of the `atan` function to
compute `pi` was left there by mistake. That function became sensitive to angle
mode. As an indirect result, the computation of `arg()` and any of its
derivative uses, including `log` or the exponentiation operator, would give the
wrong result when the angle mode was not radians.

This was not seen in the regression suite, which always runs this part of the
computation checks in radians...

Fixes: #452

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
  • Loading branch information
c3d committed Oct 22, 2023
1 parent 0c83cc4 commit eac65e6
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/complex.cc
Expand Up @@ -219,7 +219,7 @@ algebraic_g complex::convert_angle(algebraic_g a,
break;
case Settings.RADIANS:
{
algebraic_g pi = (atan::run(integer::make(1)) * integer::make(4));
algebraic_g pi = algebraic::pi();
if (a->is_fraction())
{
fraction_g f = fraction_p(a.Safe());
Expand Down Expand Up @@ -651,8 +651,6 @@ algebraic_g rectangular::arg(angle_unit unit) const
// Compute the argument in rectangular form
// ----------------------------------------------------------------------------
{
algebraic_g r = re();
algebraic_g i = im();
algebraic_g a = pifrac(); // Compute "exact" angle
a = convert_angle(a, settings::PI_RADIANS, unit);
return a;
Expand Down

0 comments on commit eac65e6

Please sign in to comment.