Commit 373c84a8 authored by Adam Blank's avatar Adam Blank
Browse files

Re-write arctan(x)

parent a0b3acfd
No related merge requests found
Showing with 5 additions and 10 deletions
+5 -10
......@@ -61,21 +61,16 @@ def estimate(func_name, x, a, func_at_a, N):
PI = 3.14159265358979323846264338327950288419716939937510582097494
@cache
def arctan(x):
N = 10
if x == 0:
return 0, 0
elif x == 1:
return pi/4, Decimal(10**-16)
a = 0
total_error = Decimal(0)
prev_value = 0
while a + 1 <= x:
prev_value = estimate('arctan', a + 1, a, prev_value, N)
total_error += max_error('arctan', a, a + 1, N)
a += 1
return estimate('arctan', x, floor(x), prev_value, N), total_error + max_error('arctan', floor(x), x, N)
return PI/4, 10**(-1)
total_error = max_error('arctan', floor(x), x, N)
prev_value, total_error = arctan(floor(float(x) - 0.0001))
return float(estimate('arctan', x, floor(x), prev_value, N)), total_error + float(max_error('arctan', floor(x), x, N))
if __name__ == "__main__":
for i in range(0, 4):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment