With regard to CPython, there is a recent discussion on this topic: https://discuss.python.org/t/trying-to-understand-rounding-in-python/28014
Le jeu. 28 déc. 2023, à 21 h 43, Stefano Miccoli via NumPy-Discussion < [email protected]> a écrit : > I have always been puzzled about how to correctly define the python > built-in `round(number, ndigits)` when `number` is a binary float and > `ndigits` is greater than zero. > Apparently CPython and numpy disagree: > >>> round(2.765, 2) > 2.77 > >>> np.round(2.765, 2) > 2.76 > > My question for the numpy devs are: > - Is there an authoritative source that explains what `round(number, > ndigits)` means when the digits are counted in a base different from the > one used in the floating point representation? > - Which was the first programming language to implement an intrinsic > function `round(number, ndigits)` where ndgits are always decimal, > irrespective of the representation of the floating point number? (I’m not > interested in algorithms for printing a decimal representation, but in > languages that allow to store and perform computations with the rounded > value.) > - Is `round(number, ndigits)` a useful function that deserves a rigorous > definition, or is its use limited to fuzzy situations, where accuracy can > be safely traded for speed? > > Personally I cannot think of sensible uses of `round(number, ndigits)` for > binary floats: whenever you positively need `round(number, ndigits)`, you > should use a decimal floating point representation. > > Stefano_______________________________________________ > NumPy-Discussion mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ > Member address: [email protected] >
_______________________________________________ NumPy-Discussion mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: [email protected]
