-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPowerAndRootTests.cs
More file actions
145 lines (133 loc) · 4.69 KB
/
Copy pathPowerAndRootTests.cs
File metadata and controls
145 lines (133 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright 2026 Chosen Few Software
* This file is part of QuadrupleLib.
*
* QuadrupleLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QuadrupleLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QuadrupleLib. If not, see <https://www.gnu.org/licenses/>.
*/
using QuadrupleLib.Accelerators;
using QuadrupleLib.Tests.Assertions.Types;
using Xunit;
namespace QuadrupleLib.Tests.Math
{
public abstract class PowerAndRootTests<TAccelerator>
where TAccelerator : IAccelerator
{
[Theory]
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
public void IsSqrtCorrect(double x)
{
double y = double.Sqrt(x);
AssertX.NearlyEqual(y, Float128<TAccelerator>.Sqrt(x), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
public void IsCbrtCorrect(double x)
{
double y = double.Cbrt(x);
AssertX.NearlyEqual(y, Float128<TAccelerator>.Cbrt(x), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0, 2)]
[InlineData(2.1, 2)]
[InlineData(3.676, 2)]
[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 IsRootNCorrect(double x, int n)
{
double y = double.RootN(x, n);
AssertX.NearlyEqual(y, Float128<TAccelerator>.RootN(x, n), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0, 2)]
[InlineData(2.1, 2)]
[InlineData(3.676, 2)]
[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);
AssertX.NearlyEqual(y0, y1, Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0, 2.0)]
[InlineData(2.1, 2.0)]
[InlineData(3.676, 2.0)]
[InlineData(1.0, 3.111)]
[InlineData(2.1, 3.111)]
[InlineData(3.676, 3.111)]
[InlineData(1.0, 0.4)]
[InlineData(2.1, 0.4)]
[InlineData(3.676, 0.4)]
[InlineData(1.0, -1.0)]
[InlineData(2.1, -1.0)]
[InlineData(3.676, -1.0)]
public void IsPowCorrect(double x, double y)
{
double z = double.Pow(x, y);
AssertX.NearlyEqual(z, Float128<TAccelerator>.Pow(x, y), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
public void IsPowZeroEqualToOne(double x)
{
AssertX.NearlyEqual(Float128<TAccelerator>.One, Float128<TAccelerator>.Pow(x, 0), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(0.0)]
[InlineData(-2.1)]
[InlineData(-0.1)]
public void IsPowZeroEqualToNaN(double x)
{
Float128<TAccelerator> y = Float128<TAccelerator>.Pow(x, 0);
Assert.True(Float128<TAccelerator>.IsNaN(y));
}
[Theory]
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
public void IsPowOneIdentity(double x)
{
AssertX.NearlyEqual(x, Float128<TAccelerator>.Pow(x, Float128<TAccelerator>.One), Precision.NearestTenThousandth);
}
[Theory]
[InlineData(1.0)]
[InlineData(2.1)]
[InlineData(3.676)]
public void IsPowNegativeOneReciprocal(double x)
{
AssertX.NearlyEqual(Float128<TAccelerator>.One / x, Float128<TAccelerator>.Pow(x, Float128<TAccelerator>.NegativeOne), Precision.NearestTenThousandth);
}
}
public class PowerAndRootTests_DefaultAccelerator :
PowerAndRootTests<DefaultAccelerator>
{ }
public class PowerAndRootTests_SoftwareAccelerator :
PowerAndRootTests<SoftwareAccelerator>
{ }
}