Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion quaddtype/numpy_quaddtype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
'SleefQuadPrecDType', 'LongDoubleQuadPrecDType', 'is_longdouble_128',
# Constants
'pi', 'e', 'log2e', 'log10e', 'ln2', 'ln10', 'max_value', 'epsilon',
'smallest_normal', 'smallest_subnormal',
'smallest_normal', 'smallest_subnormal', 'bits', 'precision', 'resolution',
# QuadBLAS related functions
'set_num_threads', 'get_num_threads', 'get_quadblas_version'
]

import numpy as np

def SleefQuadPrecision(value):
return QuadPrecision(value, backend='sleef')

Expand All @@ -40,3 +42,6 @@ def LongDoubleQuadPrecDType():
epsilon = get_sleef_constant("epsilon")
smallest_normal = get_sleef_constant("smallest_normal")
smallest_subnormal = get_sleef_constant("smallest_subnormal")
bits = SleefQuadPrecDType().itemsize * 8
precision = int(-np.log10(epsilon))
resolution = SleefQuadPrecision(10) ** (-precision)
7 changes: 6 additions & 1 deletion quaddtype/tests/test_quaddtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ def test_math_constant(name, expected):
assert np.float64(getattr(numpy_quaddtype, name)) == expected


@pytest.mark.parametrize("name", ["max_value", "epsilon", "smallest_normal", "smallest_subnormal"])
@pytest.mark.parametrize("name", ["max_value", "epsilon", "smallest_normal", "smallest_subnormal", "resolution"])
def test_finfo_constant(name):
assert isinstance(getattr(numpy_quaddtype, name), QuadPrecision)


@pytest.mark.parametrize("name,value", [("bits", 128), ("precision", 33)])
def test_finfo_int_constant(name, value):
assert getattr(numpy_quaddtype, name) == value


def test_basic_equality():
assert QuadPrecision("12") == QuadPrecision(
"12.0") == QuadPrecision("12.00")
Expand Down
Loading