diff options
Diffstat (limited to 'odoo/tools/float_utils.py')
| -rw-r--r-- | odoo/tools/float_utils.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/odoo/tools/float_utils.py b/odoo/tools/float_utils.py index c5c2946a5ce..12881503f32 100644 --- a/odoo/tools/float_utils.py +++ b/odoo/tools/float_utils.py @@ -2,28 +2,25 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from __future__ import print_function +import builtins import math -if not pycompat.PY2: - import builtins - def round(f): - # P3's builtin round differs from P2 in the following manner: - # * it rounds half to even rather than up (away from 0) - # * round(-0.) loses the sign (it returns -0 rather than 0) - # * round(x) returns an int rather than a float - # - # this compatibility shim implements Python 2's round in terms of - # Python 3's so that important rounding error under P3 can be - # trivially fixed, assuming the P2 behaviour to be debugged and - # correct. - roundf = builtins.round(f) - if builtins.round(f + 1) - roundf != 1: - return f + math.copysign(0.5, f) - # copysign ensures round(-0.) -> -0 *and* result is a float - return math.copysign(roundf, f) -else: - round = round +def round(f): + # P3's builtin round differs from P2 in the following manner: + # * it rounds half to even rather than up (away from 0) + # * round(-0.) loses the sign (it returns -0 rather than 0) + # * round(x) returns an int rather than a float + # + # this compatibility shim implements Python 2's round in terms of + # Python 3's so that important rounding error under P3 can be + # trivially fixed, assuming the P2 behaviour to be debugged and + # correct. + roundf = builtins.round(f) + if builtins.round(f + 1) - roundf != 1: + return f + math.copysign(0.5, f) + # copysign ensures round(-0.) -> -0 *and* result is a float + return math.copysign(roundf, f) def _float_check_precision(precision_digits=None, precision_rounding=None): assert (precision_digits is not None or precision_rounding is not None) and \ |
