Skip to content

Commit 8423bc1

Browse files
committed
update fp64 code
1 parent 38d3780 commit 8423bc1

File tree

7 files changed

+66672
-60033
lines changed

7 files changed

+66672
-60033
lines changed

ErrorFunctionFP64/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
[assembly: AssemblyTitle("ErrorFunctionFP64")]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using ErrorFunctionFP64;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using MultiPrecision;
4+
5+
namespace ErrorFunctionFP64Tests {
6+
[TestClass()]
7+
public class ErrorSummary {
8+
[TestMethod()]
9+
public void PlotErf() {
10+
using StreamWriter sw = new("../../../../results/erf_approx.csv");
11+
12+
sw.WriteLine("x,y_expected,y_actual,error(abs),error(rate)");
13+
14+
MultiPrecision<Pow2.N8> maxrateerror = 0;
15+
16+
for (double x = -10; x <= 10; x += 1d / 1024) {
17+
double actual = ErrorFunction.Erf((double)x);
18+
MultiPrecision<Pow2.N8> expetected = MultiPrecision<Pow2.N8>.Erf(x);
19+
MultiPrecision<Pow2.N8> error = MultiPrecision<Pow2.N8>.Abs(expetected - actual);
20+
MultiPrecision<Pow2.N8> rateerror = (error != 0) ? error / MultiPrecision<Pow2.N8>.Abs(expetected) : 0;
21+
22+
if (double.IsNormal(actual)) {
23+
maxrateerror = MultiPrecision<Pow2.N8>.Max(rateerror, maxrateerror);
24+
}
25+
26+
sw.WriteLine($"{x},{expetected:e20},{actual},{error:e8},{rateerror:e8}");
27+
}
28+
29+
Console.WriteLine($"max error (rate): {maxrateerror:e8}");
30+
}
31+
32+
[TestMethod()]
33+
public void PlotErfc() {
34+
using StreamWriter sw = new("../../../../results/erfc_approx.csv");
35+
36+
sw.WriteLine("x,y_expected,y_actual,error(abs),error(rate)");
37+
38+
MultiPrecision<Pow2.N8> maxrateerror = 0;
39+
40+
for (double x = -10; x <= 30; x += 1d / 1024) {
41+
double actual = ErrorFunction.Erfc((double)x);
42+
MultiPrecision<Pow2.N8> expetected = MultiPrecision<Pow2.N8>.Erfc(x);
43+
MultiPrecision<Pow2.N8> error = MultiPrecision<Pow2.N8>.Abs(expetected - actual);
44+
MultiPrecision<Pow2.N8> rateerror = (error != 0) ? error / MultiPrecision<Pow2.N8>.Abs(expetected) : 0;
45+
46+
if (double.IsNormal(actual)) {
47+
maxrateerror = MultiPrecision<Pow2.N8>.Max(rateerror, maxrateerror);
48+
}
49+
50+
sw.WriteLine($"{x},{expetected:e20},{actual},{error:e8},{rateerror:e8}");
51+
}
52+
53+
Console.WriteLine($"max error (rate): {maxrateerror:e8}");
54+
}
55+
56+
[TestMethod()]
57+
public void PlotInverseErf() {
58+
using StreamWriter sw = new("../../../../results/inverf_approx.csv");
59+
60+
sw.WriteLine("x,y_expected,y_actual,error(abs),error(rate)");
61+
62+
MultiPrecision<Pow2.N8> maxrateerror = 0;
63+
64+
for (double x = -1023d / 1024; x < 1; x += 1d / 1024) {
65+
double actual = ErrorFunction.InverseErf((double)x);
66+
MultiPrecision<Pow2.N8> expetected = MultiPrecision<Pow2.N8>.InverseErf(x);
67+
MultiPrecision<Pow2.N8> error = MultiPrecision<Pow2.N8>.Abs(expetected - actual);
68+
MultiPrecision<Pow2.N8> rateerror = (error != 0) ? error / MultiPrecision<Pow2.N8>.Abs(expetected) : 0;
69+
70+
if (double.IsNormal(actual)) {
71+
maxrateerror = MultiPrecision<Pow2.N8>.Max(rateerror, maxrateerror);
72+
}
73+
74+
sw.WriteLine($"{x},{expetected:e20},{actual},{error:e8},{rateerror:e8}");
75+
}
76+
77+
Console.WriteLine($"max error (rate): {maxrateerror:e8}");
78+
}
79+
80+
[TestMethod()]
81+
public void PlotInverseErfc() {
82+
using StreamWriter sw = new("../../../../results/inverfc_approx.csv");
83+
84+
sw.WriteLine("x,y_expected,y_actual,error(abs),error(rate)");
85+
86+
MultiPrecision<Pow2.N8> maxrateerror = 0;
87+
88+
for (double x = Math.ScaleB(1, -1024); x < Math.ScaleB(1, -10); x *= 2) {
89+
double actual = ErrorFunction.InverseErfc((double)x);
90+
MultiPrecision<Pow2.N8> expetected = MultiPrecision<Pow2.N8>.InverseErfc(x);
91+
MultiPrecision<Pow2.N8> error = MultiPrecision<Pow2.N8>.Abs(expetected - actual);
92+
MultiPrecision<Pow2.N8> rateerror = (error != 0) ? error / MultiPrecision<Pow2.N8>.Abs(expetected) : 0;
93+
94+
if (double.IsNormal(actual)) {
95+
maxrateerror = MultiPrecision<Pow2.N8>.Max(rateerror, maxrateerror);
96+
}
97+
98+
sw.WriteLine($"{x},{expetected:e20},{actual},{error:e8},{rateerror:e8}");
99+
}
100+
101+
for (double x = 1d / 1024; x < 2; x += 1d / 1024) {
102+
double actual = ErrorFunction.InverseErfc((double)x);
103+
MultiPrecision<Pow2.N8> expetected = MultiPrecision<Pow2.N8>.InverseErfc(x);
104+
MultiPrecision<Pow2.N8> error = MultiPrecision<Pow2.N8>.Abs(expetected - actual);
105+
MultiPrecision<Pow2.N8> rateerror = (error != 0) ? error / MultiPrecision<Pow2.N8>.Abs(expetected) : 0;
106+
107+
if (double.IsNormal(actual)) {
108+
maxrateerror = MultiPrecision<Pow2.N8>.Max(rateerror, maxrateerror);
109+
}
110+
111+
sw.WriteLine($"{x},{expetected:e20},{actual},{error:e8},{rateerror:e8}");
112+
}
113+
114+
Console.WriteLine($"max error (rate): {maxrateerror:e8}");
115+
}
116+
}
117+
}

README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ Let N be the recursion times (Fn+4(z) to Fn(z)), and N until convergence is as f
8181
![erfc convergence bitwise](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_convergence_bitswise.svg)
8282

8383
## Double Precision (IEEE 754) Approx
84-
### Taylor Series
85-
86-
[C# code](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/ErrorFunctionApproximation/ErrorFunction.cs)
87-
[erf result](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/erf_approx.csv)
88-
[erfc result](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/erfc_approx.csv)
89-
[inverse erf result](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/inverf_approx.csv)
90-
[inverse erfc result](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/inverfc_approx.csv)
84+
[C# code](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/ErrorFunctionFP64/ErrorFunction.cs)
9185

9286
The following is used to approximate the error of machine epsilon in the entire domain.
9387

@@ -101,24 +95,7 @@ near zero:
10195

10296
![erfc az diff](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_diff.svg)
10397

104-
A(z) taylor series (z0=1.5)
105-
![erfc az 12](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_approx_az_12.svg)
106-
107-
A(z) taylor series (z0=2.5)
108-
![erfc az 23](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_approx_az_23.svg)
109-
110-
A(z) taylor series (z0=3.5)
111-
![erfc az 34](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_approx_az_34.svg)
112-
113-
4 to 27.25:
114-
![erfc x20](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_approx_x20.svg)
115-
116-
larger 27.25:
117-
![erfc tolarge](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/erfc_approx_tolarge.svg)
118-
119-
### Pade Approximant Base
12098
![pade definition](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/figures/pade_definition.svg)
121-
[C# code](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/ErrorFunctionApproximation/ErrorFunctionMarkII.cs)
12299

123100
[pade erf precision16](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/pade_erf_e16.txt)
124101
[pade erf precision32](https://github.com/tk-yoshimura/ErrorFunctionApproximation/blob/main/results/pade_erf_e32.txt)

0 commit comments

Comments
 (0)