Skip to content

Commit

Permalink
_n_word_max and _max_error at __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
francof2a committed Jul 29, 2020
1 parent 3088204 commit fc909ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
15 changes: 14 additions & 1 deletion fxpmath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
__version__ = '0.3.7'

import sys
__maxsize__ = sys.maxsize

# max size constant
try:
__maxsize__ = sys.maxsize
_n_word_max = int(np.log2(__maxsize__)) + 1
except:
# print("Max size for integer couldn't be found for this computer. n_word max = 64 bits.")
_n_word_max = 64

try:
_max_error = 1 / (1 << (_n_word_max - 1))
except:
_max_error = 1 / 2**63


from . import objects
from .objects import *
Expand Down
16 changes: 1 addition & 15 deletions fxpmath/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,7 @@
import numpy as np
import copy
from . import utils

import sys

# max size constant
try:
__maxsize__ = sys.maxsize
_n_word_max = int(np.log2(__maxsize__)) + 1
except:
# print("Max size for integer couldn't be found for this computer. n_word max = 64 bits.")
_n_word_max = 64

try:
_max_error = 1 / (1 << (_n_word_max - 1))
except:
_max_error = 1 / 2**63
from . import _n_word_max, _max_error

#%%
class Fxp():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_sum():
vals = np.array([-2, -1, 0, 1, 2, 3, 4])

x = Fxp(vals, True, 32, 2)
x = Fxp(vals, True, 16, 2)
y = fxp.sum(x)
assert (y() == np.sum(vals)).all()

Expand Down Expand Up @@ -42,7 +42,7 @@ def test_sum():
vals = np.array([
[-2, -1, 0],
[1, 2, 3]])
x = Fxp(vals, True, 32, 2)
x = Fxp(vals, True, 16, 2)

y = fxp.sum(x, axis=0)
assert (y() == np.sum(vals, axis=0)).all()
Expand Down

0 comments on commit fc909ba

Please sign in to comment.