0

I just learned about the IEEE 754 floating-point standard, it says that if the least significant bit retained in the halfway case would be odd, add one; if even, truncate.

So +23.5 and +24.5 both round to +24, while -23.5 and -24.5 to -24

can I override the python built-in round behavior to work always going up when the float number is {number}.5?

  • 3
    Are you looking for [How do you round UP a number?](/q/2356501/15497888) or you actually want to override the built-in round behaviour for your python instance? – Henry Ecker Jul 25 '22 at 03:09
  • I doubt IEEE 754 says anything about Python's `round` function. – Kelly Bundy Jul 25 '22 at 03:18
  • Hello Henry, I would like to override the built-in round behavior – Jorge Eduardo Jiménez Álvarez Jul 25 '22 at 10:47
  • Hello Kelly you're right, IEEE754 doesn't say anything about python, but python follows that standard, I would like to change it – Jorge Eduardo Jiménez Álvarez Jul 25 '22 at 10:55
  • Isn't IEEE 754 only concerned about rounding at the last bit (e.g., the 53rd in binary64) because that's needed after operations? Python's `round` rounding at an artificially early digit just because you want it, I don't think that comes from IEEE 754. People have been rounding before IEEE 754, it doesn't have the monopoly/authority over all things rounding. And if you look at `sys.float_info`, you can see the rounding mode can be one of several (I think related to IEEE 754), whereas `round` only has its one. Anyway, you get get Python's source code and modify it to your liking. – Kelly Bundy Jul 25 '22 at 15:27
  • if you always want to round up use the math.ceil function – itprorh66 Jul 25 '22 at 19:01

0 Answers0