From d577709ddca2fc572bca5f09381ffad8b1f2d254 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Fri, 17 Apr 2020 13:46:05 -0400 Subject: [PATCH] Use python bigfloat to calculate atan tables --- setup.py | 1 + src/ieee754/cordic/fpsin_cos.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 95367ed0..4693b5f7 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ version = '0.0.1' install_requires = [ 'nmutil', # 'sfpy', # XXX temporarily disabled + 'bigfloat' ] test_requires = [ diff --git a/src/ieee754/cordic/fpsin_cos.py b/src/ieee754/cordic/fpsin_cos.py index c61e6bf2..e75cbccc 100644 --- a/src/ieee754/cordic/fpsin_cos.py +++ b/src/ieee754/cordic/fpsin_cos.py @@ -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, -- 2.30.2