From: Michael Nolan Date: Fri, 17 Apr 2020 17:46:05 +0000 (-0400) Subject: Use python bigfloat to calculate atan tables X-Git-Tag: ls180-24jan2020~83 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d577709ddca2fc572bca5f09381ffad8b1f2d254;p=ieee754fpu.git Use python bigfloat to calculate atan tables --- 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,