-
Notifications
You must be signed in to change notification settings - Fork 11
/
SzelStat.cs
64 lines (59 loc) · 1.97 KB
/
SzelStat.cs
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
using Microsoft.VisualBasic.FileIO;
using System.Runtime.CompilerServices;
namespace CSV
{
internal static class Program
{
internal static void Main()
{
KahanBabuska sinsum = new(), cossum = new(); int hit = 0;
using TextFieldParser parser = new(@"F:\szel.csv")
{
TrimWhiteSpace = true,
Delimiters = new string[] { "," },
HasFieldsEnclosedInQuotes = false,
TextFieldType = FieldType.Delimited
};
parser.ReadLine(); // Header
while (!parser.EndOfData)
{
var line = parser.ReadFields();
if (line?.Length == 7 &&
float.TryParse(line[5], out float ws) &&
ws > 0f &&
ushort.TryParse(line[6], out ushort wd))
{
(double Sin, double Cos) sincos = double.SinCos((Math.Tau / 360d) * wd);
sinsum.Add(sincos.Item1); cossum.Add(sincos.Item2);
hit++;
}
}
parser.Close();
Console.WriteLine((360 / double.Tau) * double.Atan2(sinsum.GetResult() / hit, cossum.GetResult() / hit));
}
}
internal class KahanBabuska
{
private double sum, com;
internal KahanBabuska(double startValue = 0) =>
sum = startValue;
[SkipLocalsInit]
internal void Add(double value)
{
double sum = this.sum,
n = sum + value;
com += Math.Abs(sum) >= Math.Abs(value) ?
(sum - n) + value :
(value - n) + sum;
this.sum = n;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void Reset()
{
com = 0; sum = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal double GetResult() =>
sum + com;
}
}