September 12, 2019 [Issue 20206] New: potential bug in complex power operator | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20206 Issue ID: 20206 Summary: potential bug in complex power operator Product: D Version: D2 Hardware: Other OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody@puremagic.com Reporter: dlang@croco-puzzle.com 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; } -- |
Copyright © 1999-2021 by the D Language Foundation