Issue 20206 - potential bug in complex power operator
Summary: potential bug in complex power operator
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-12 08:15 UTC by Berni
Modified: 2024-12-01 16:35 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Berni 2019-09-12 08:15:07 UTC
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;
}
Comment 1 dlangBugzillaToGithub 2024-12-01 16:35:33 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9778

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB