Use python bigfloat to calculate atan tables
authorMichael Nolan <mtnolan2640@gmail.com>
Fri, 17 Apr 2020 17:46:05 +0000 (13:46 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Fri, 17 Apr 2020 17:59:53 +0000 (13:59 -0400)
setup.py
src/ieee754/cordic/fpsin_cos.py

index 95367ed01906d4179a76e14e7c9ad9594e739871..4693b5f7a938aee73f399dfefe47657f9895b251 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -11,6 +11,7 @@ version = '0.0.1'
 install_requires = [
     'nmutil',
 #    'sfpy',  # XXX temporarily disabled
+    'bigfloat'
 ]
 
 test_requires = [
index c61e6bf2648bfe530855e54fb8ae110e4eb7fb72..e75cbccc0cdc30e25975040cb6a20cbfd9acc64a 100644 (file)
@@ -7,6 +7,8 @@ from nmigen.cli import rtlil
 import math
 from enum import Enum, unique
 from ieee754.fpcommon.fpbase import FPNumBaseRecord, FPNumDecode
+import bigfloat as bf
+from bigfloat import BigFloat
 
 
 @unique
@@ -25,8 +27,13 @@ class CordicROM(Elaboratable):
         self.addr = Signal(range(iterations))
         self.data = Signal(range(-M, M-1))
 
-        angles = [int(round(M*math.atan(2**(-i))/(math.pi/2)))
-                  for i in range(self.iterations)]
+        angles = []
+        with bf.quadruple_precision:
+            for i in range(self.iterations):
+                x = bf.atan(BigFloat(2) ** BigFloat(-i))
+                x = x/(bf.const_pi()/2)
+                x = x * M
+                angles.append(int(round(x)))
 
         self.mem = Memory(width=self.data.width,
                           depth=self.iterations,