File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
quaddtype/numpy_quaddtype Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 1818 'set_num_threads' , 'get_num_threads' , 'get_quadblas_version'
1919]
2020
21- import numpy as np
22-
2321def SleefQuadPrecision (value ):
2422 return QuadPrecision (value , backend = 'sleef' )
2523
@@ -42,6 +40,6 @@ def LongDoubleQuadPrecDType():
4240epsilon = get_sleef_constant ("epsilon" )
4341smallest_normal = get_sleef_constant ("smallest_normal" )
4442smallest_subnormal = get_sleef_constant ("smallest_subnormal" )
45- bits = SleefQuadPrecDType (). itemsize * 8
46- precision = int ( - np . log10 ( epsilon ) )
47- resolution = SleefQuadPrecision ( 10 ) ** ( - precision )
43+ bits = get_sleef_constant ( "bits" )
44+ precision = get_sleef_constant ( "precision" )
45+ resolution = get_sleef_constant ( "resolution" )
Original file line number Diff line number Diff line change @@ -73,6 +73,22 @@ get_sleef_constant(PyObject *self, PyObject *args)
7373 else if (strcmp (constant_name , "smallest_subnormal" ) == 0 ) {
7474 result -> value .sleef_value = SLEEF_QUAD_DENORM_MIN ;
7575 }
76+ else if (strcmp (constant_name , "bits" ) == 0 ) {
77+ Py_DECREF (result );
78+ return PyLong_FromLong (sizeof (Sleef_quad ) * CHAR_BIT );
79+ }
80+ else if (strcmp (constant_name , "precision" ) == 0 ) {
81+ Py_DECREF (result );
82+ // precision = int(-log10(epsilon))
83+ auto precision = Sleef_cast_to_int64q1 (Sleef_negq1 (Sleef_log10q1_u10 (SLEEF_QUAD_EPSILON )));
84+ return PyLong_FromLong (precision );
85+ }
86+ else if (strcmp (constant_name , "resolution" ) == 0 ) {
87+ // precision = int(-log10(epsilon))
88+ auto precision = Sleef_cast_to_int64q1 (Sleef_negq1 (Sleef_log10q1_u10 (SLEEF_QUAD_EPSILON )));
89+ // resolution = 10 ** (-precision)
90+ result -> value .sleef_value = Sleef_powq1_u10 (Sleef_cast_from_int64q1 (10 ), Sleef_cast_from_int64q1 (- precision ));
91+ }
7692 else {
7793 PyErr_SetString (PyExc_ValueError , "Unknown constant name" );
7894 Py_DECREF (result );
You can’t perform that action at this time.
0 commit comments