Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 23c662f

Browse files
committed
Add checks for infinity to Complex.Pow verification
Several times now the standardNumericalFunctions_PowTest.RunTests_RandomValidValues test has failed in CI. The issue is that random values are generated that result in so large or small values that the Complex.Pow(x,y) computation results in infinity. The test then tries to verify the result by comparing it to the result of Complex.Exp(y*Complex.Log(x)). It needs to do an approximate comparison, but that approximation doesn't take infinity into account. This commit attempts to address that by checking to see if one of the values is infinity, and if it is, rather than subtracting one value from the other (which will result in infinity), it tries to nudge the other value a bit to see if it becomes a matching infinity.
1 parent 470f290 commit 23c662f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/System.Runtime.Numerics/tests/Complex/ComplexTestSupport.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,21 @@ public static double GetRandomPhaseValue(bool fIsNegative)
159159

160160
public static bool IsDiffTolerable(double d1, double d2)
161161
{
162-
double diffRatio = (d1 - d2) / d1;
163-
diffRatio *= Math.Pow(10, 6);
164-
diffRatio = Math.Abs(diffRatio);
165-
return (diffRatio < 1);
162+
if (double.IsInfinity(d1))
163+
{
164+
return d1 == (d2 * 10);
165+
}
166+
else if (double.IsInfinity(d2))
167+
{
168+
return d2 == (d1 * 10);
169+
}
170+
else
171+
{
172+
double diffRatio = (d1 - d2) / d1;
173+
diffRatio *= Math.Pow(10, 6);
174+
diffRatio = Math.Abs(diffRatio);
175+
return (diffRatio < 1);
176+
}
166177
}
167178

168179
public static void VerifyRealImaginaryProperties(Complex complex, double real, double imaginary, string message)

0 commit comments

Comments
 (0)