Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential bug in complex power operator #9778

Open
dlangBugzillaToGithub opened this issue Sep 12, 2019 · 0 comments
Open

potential bug in complex power operator #9778

dlangBugzillaToGithub opened this issue Sep 12, 2019 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

dlang reported this on 2019-09-12T08:15:07Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20206

Description

During Phobos PR #7173, all 32bit machines failed in a unittest for the complex power operator, while all 64bit machines did not. This might be due to a bug in complex ^^.

The following program will probably reproduce the error, but I had no opportunity to check this, because I did not succeed in installing dmd on my old 32bit machine. (Got segmentation fault, whenever I started dmd. I think, a library is missing. ldc2 complained about not finding gcc, although being installed and in $PATH. And gdc did not reproduce the error, but used an older version of phobos.)

void main()
{
    import std.complex;

    auto rec3a = 0.79 ^^ complex(6.8, 5.7);
    auto rec3b = complex(0.79, 0.0) ^^ complex(6.8, 5.7);

    assert(approxEqual(rec3a.re, rec3b.re, double.epsilon));
}

bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff = 1e-9, V maxAbsDiff = 0)
{
    import std.traits:isIntegral;
    import std.math:fabs;

    if (isIntegral!T || isIntegral!U)
    {
        return approxEqual(real(lhs), real(rhs), maxRelDiff, maxAbsDiff);
    }

    if (lhs == rhs) return true;

    static if (is(typeof(lhs.infinity)) && is(typeof(rhs.infinity)))
    {
        if (lhs == lhs.infinity || rhs == rhs.infinity ||
            lhs == -lhs.infinity || rhs == -rhs.infinity) return false;
    }

    auto diff = fabs(lhs - rhs);

    return diff <= maxRelDiff*fabs(lhs) || diff <= maxRelDiff*fabs(rhs) || diff <= maxAbsDiff;
}
@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants