Have sin_cos pipeline use bigfloat calculated atan table
[ieee754fpu.git] / src / ieee754 / cordic / sin_cos_pipe_stage.py
index 79ad65904ace4c38441a735f8f9dc51e34302fc5..94916abfbd5d49f9f988bac0e39c7725a816d1c6 100644 (file)
@@ -2,6 +2,8 @@ from nmigen import Module, Signal
 from nmutil.pipemodbase import PipeModBase
 from ieee754.cordic.pipe_data import CordicData, CordicInitialData
 import math
+import bigfloat as bf
+from bigfloat import BigFloat
 
 
 class CordicInitialStage(PipeModBase):
@@ -47,8 +49,11 @@ class CordicStage(PipeModBase):
         dx = Signal(self.i.x.shape())
         dy = Signal(self.i.y.shape())
         dz = Signal(self.i.z.shape())
-        angle = int(round(self.pspec.M *
-                          math.atan(2**(-self.stagenum))))
+        with bf.quadruple_precision:
+            x = bf.atan(BigFloat(2) ** BigFloat(-self.stagenum))
+            x = x/(bf.const_pi()/2)
+            x = x * self.pspec.M
+            angle = int(round(x))
 
         comb += dx.eq(self.i.y >> self.stagenum)
         comb += dy.eq(self.i.x >> self.stagenum)