We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f57dc45 commit 02e9178Copy full SHA for 02e9178
1 file changed
tunits/core/cython/frac.pyx
@@ -13,7 +13,7 @@
13
# limitations under the License.
14
15
cimport cython
16
-from libc.math cimport floor as c_floor, pow as c_pow, fabs as c_fabs
+from libc.math cimport floor as c_floor, pow as c_pow
17
18
# A ratio that should always be canonicalized into least terms with the sign
19
# on the numerator.
@@ -85,7 +85,9 @@ cpdef frac float_to_twelths_frac(a) except *:
85
86
cdef double d = float(a)
87
cdef long long x = <long long>c_floor(12*d + 0.5)
88
- if c_fabs(12*d - x) > 1e-5:
+ cdef double diff = 12*d - x
89
+ if max(diff, -diff) > 1e-5:
90
+ print(f'%.20f'%diff)
91
raise ValueError("Not a twelfth.")
92
93
return frac_least_terms(x, 12)
0 commit comments