Add separate spoolup calculator

This commit is contained in:
DarkPhoenix
2018-12-10 13:50:22 +03:00
parent 5b60abf4b6
commit 3228c7f74d
4 changed files with 107 additions and 15 deletions

26
eos/utils/float.py Normal file
View File

@@ -0,0 +1,26 @@
"""
Sometimes use of floats may lead to undesirable results, e.g.
int(2.3 / 0.1) = 22.
We cannot afford to use different number representations (e.g. representations
provided by decimal or fraction modules), thus consequences are worked around by
this module.
"""
import math
import sys
# As we will be rounding numbers after operations (which introduce higher error
# than base float representation error), we need to keep less significant
# numbers than for single float number w/o operations
keepDigits = int(sys.float_info.dig / 2)
def floatUnerr(value):
"""Round possible float number error, killing some precision in process."""
if value == 0:
return value
# Find round factor, taking into consideration that we want to keep at least
# predefined amount of significant digits
roundFactor = int(keepDigits - math.ceil(math.log10(abs(value))))
return round(value, roundFactor)