tahoe-lafs/src/allmydata/util/mathutil.py

29 lines
884 B
Python
Raw Normal View History

2006-12-29 20:50:42 +00:00
"""
A few commonly needed functions.
Backwards compatibility for direct imports.
2006-12-29 20:50:42 +00:00
Ported to Python 3.
"""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from future.utils import PY2
if PY2:
2020-08-05 15:53:23 +00:00
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
# The API importers expect:
2020-07-08 16:13:19 +00:00
from pyutil.mathutil import div_ceil, next_multiple, pad_size, is_power_of_k, next_power_of_k, ave, log_ceil, log_floor
# This function is not present in pyutil.mathutil:
def round_sigfigs(f, n):
fmt = "%." + str(n-1) + "e"
return float(fmt % f)
2020-07-09 17:12:30 +00:00
__all__ = ["div_ceil", "next_multiple", "pad_size", "is_power_of_k", "next_power_of_k", "ave", "log_ceil", "log_floor", "round_sigfigs"]