Skip to content

Error in -1² operation when zero in imaginary part is represented in scientific notation #1

Description

@josecelano

Basically pow function does not work when Complex is instantiated using this notation 0E-42 for zero.

For exmaple:

$c2 = Complex::fromStringNumber('-1.0000000000000000000000000000', '0E-42');

You get that representation of zero internally, for example after another operation like: -0² - 1

I have added a test to reproduce the problem:

    /** @test */
    public function work_using_zero_with_scientific_notation_but_it_does_not_for_some_cases() {
        $_1 = Complex::fromInt(1, 0);

        $zero = new Decimal('0E-42');
        $this->assertTrue($zero->isZero());

        // Different ways to represent number 1 real. = imaginary part in scientific notation
        $c1 = Complex::fromStringNumber('-1.000000000000000000000000000000', '0E-84');  // 0 * 10^⁻84
        $c2 = Complex::fromStringNumber('-1.0000000000000000000000000000', '0E-42');    // 0 * 10^⁻42

        // 1² = 1
        $f1 = $c1->pow(2);
        $f2 = $c2->pow(2);

        $this->assertEqualWithDelta($_1, $f1);
        $this->assertEqualWithDelta($_1, $f2);
    }

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions