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 18
18
'set_num_threads' , 'get_num_threads' , 'get_quadblas_version'
19
19
]
20
20
21
- import numpy as np
22
-
23
21
def SleefQuadPrecision (value ):
24
22
return QuadPrecision (value , backend = 'sleef' )
25
23
@@ -42,6 +40,6 @@ def LongDoubleQuadPrecDType():
42
40
epsilon = get_sleef_constant ("epsilon" )
43
41
smallest_normal = get_sleef_constant ("smallest_normal" )
44
42
smallest_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)
73
73
else if (strcmp (constant_name , "smallest_subnormal" ) == 0 ) {
74
74
result -> value .sleef_value = SLEEF_QUAD_DENORM_MIN ;
75
75
}
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
+ }
76
92
else {
77
93
PyErr_SetString (PyExc_ValueError , "Unknown constant name" );
78
94
Py_DECREF (result );
You can’t perform that action at this time.
0 commit comments