Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion QuadrupleLib.Tests/Math/PowerAndRootTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void IsSqrtCorrect(double x)
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
[InlineData(-1.0)]
[InlineData(-2.1)]
[InlineData(-3.676)]
public void IsCbrtCorrect(double x)
{
double y = double.Cbrt(x);
Expand All @@ -52,6 +55,9 @@ public void IsCbrtCorrect(double x)
[InlineData(1.0, 3)]
[InlineData(2.1, 3)]
[InlineData(3.676, 3)]
[InlineData(-1.0, 3)]
[InlineData(-2.1, 3)]
[InlineData(-3.676, 3)]
[InlineData(1.0, 4)]
[InlineData(2.1, 4)]
[InlineData(3.676, 4)]
Expand All @@ -68,13 +74,19 @@ public void IsRootNCorrect(double x, int n)
[InlineData(1.0, 3)]
[InlineData(2.1, 3)]
[InlineData(3.676, 3)]
[InlineData(-1.0, 3)]
[InlineData(-2.1, 3)]
[InlineData(-3.676, 3)]
[InlineData(1.0, 4)]
[InlineData(2.1, 4)]
[InlineData(3.676, 4)]
public void IsRootNEqualToPow(double x, int n)
{
Float128<TAccelerator> y0 = Float128<TAccelerator>.RootN(x, n);
Float128<TAccelerator> y1 = Float128<TAccelerator>.Pow(x, Float128<TAccelerator>.One / n);
Float128<TAccelerator> y1 = Float128<TAccelerator>.Pow(
Float128<TAccelerator>.Abs(x), Float128<TAccelerator>.One / n
);
if (x < 0.0) y1 = -y1;
AssertX.NearlyEqual(y0, y1, Precision.NearestTenThousandth);
}

Expand Down
6 changes: 3 additions & 3 deletions QuadrupleLib/Modules/MathOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public static Float128<TAccelerator> Exp2(Float128<TAccelerator> y)

public static Float128<TAccelerator> Pow(Float128<TAccelerator> x, Float128<TAccelerator> y)
{
if (IsZero(x) && IsZero(y))
if (IsZero(x) && IsZero(y))
{
return _sNaN;
}
Expand All @@ -574,7 +574,7 @@ public static Float128<TAccelerator> Pow(Float128<TAccelerator> x, Float128<TAcc

return result;
}
else
else
{
return Exp(y * Log(x));
}
Expand Down Expand Up @@ -629,7 +629,7 @@ public static Float128<TAccelerator> RootN(Float128<TAccelerator> x, int n)
}
else if (x < Zero)
{
return (n & 1) == 0 ? _sNaN : -Pow(-x, n);
return (n & 1) == 0 ? _sNaN : -Pow(-x, One / n);
}
else
{
Expand Down
Loading