forked from jamesbowman/sincos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
30 lines (25 loc) · 840 Bytes
/
analyze.py
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
import math
def _sin(y):
s1 = math.pi
s3 = math.pi**3 / math.factorial(3)
s5 = math.pi**5 / math.factorial(5)
s7 = math.pi**7 / math.factorial(7)
z = y * y
prod = (z * s7)
sum = s5 - prod
prod = (z * sum)
sum = s3 - prod
prod = (z * sum)
sum = s1 - prod
return y * sum
if __name__ == '__main__':
errors = []
for l in open("results.txt"):
(angle, sine) = [int(f) for f in l.split()]
th = angle * 2 * math.pi / 0x10000
expected = 32767.0 * math.sin(th)
# print angle, sine, expected
errors.append((abs(sine - expected), angle, sine, expected))
print len(errors), 'values tested'
print 'max error %f for angle=%d: actual=%d expected=%f' % max(errors)
print 'rms error', math.sqrt(sum([e[0]**2 for e in errors]) / len(errors))