Skip to content

Commit ce2b9e0

Browse files
committed
Add bits, precision, resolution constants
1 parent 116a605 commit ce2b9e0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

quaddtype/numpy_quaddtype/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
'SleefQuadPrecDType', 'LongDoubleQuadPrecDType', 'is_longdouble_128',
1414
# Constants
1515
'pi', 'e', 'log2e', 'log10e', 'ln2', 'ln10', 'max_value', 'epsilon',
16-
'smallest_normal', 'smallest_subnormal',
16+
'smallest_normal', 'smallest_subnormal', 'bits', 'precision', 'resolution',
1717
# QuadBLAS related functions
1818
'set_num_threads', 'get_num_threads', 'get_quadblas_version'
1919
]
2020

21+
import numpy as np
22+
2123
def SleefQuadPrecision(value):
2224
return QuadPrecision(value, backend='sleef')
2325

@@ -40,3 +42,6 @@ def LongDoubleQuadPrecDType():
4042
epsilon = get_sleef_constant("epsilon")
4143
smallest_normal = get_sleef_constant("smallest_normal")
4244
smallest_subnormal = get_sleef_constant("smallest_subnormal")
45+
bits = SleefQuadPrecDType().itemsize * 8
46+
precision = int(-np.log10(epsilon))
47+
resolution = SleefQuadPrecision(10) ** (-precision)

quaddtype/tests/test_quaddtype.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ def test_math_constant(name, expected):
1919
assert np.float64(getattr(numpy_quaddtype, name)) == expected
2020

2121

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

2626

27+
@pytest.mark.parametrize("name,value", [("bits", 128), ("precision", 33)])
28+
def test_finfo_int_constant(name, value):
29+
assert getattr(numpy_quaddtype, name) == value
30+
31+
2732
def test_basic_equality():
2833
assert QuadPrecision("12") == QuadPrecision(
2934
"12.0") == QuadPrecision("12.00")

0 commit comments

Comments
 (0)