Mark Dickinson added the comment:

Tom: there's no reasonable way to define all 3 of /, // and % for 
floating-point numbers that avoids all user surprises.  There are a couple of 
notes (nos 2 and 3) at the bottom of the documentation page you refer to that 
attempt to explain some of the potential difficulties here.

> I cannot think of a reasonable use case for the floor division.

Indeed, one has to be careful when using floating-point for *anything* where 
tiny numerical errors can significant:  rounding is another example of this.

What's your application?  There may be better ways of doing what you're trying 
to do.  If you're working with financial data, you might want to look at the 
decimal module.  If you're working with Python floats (or floating-point 
arithmetic in *any* programming language), your code has to be robust in the 
face of small errors.

> math.floor(1/0.1) returns the expected 10.0

Yep.  What happens here is that the exact result of 1 / 0.1 is just a touch 
under 10.0, but the closest representable float to that exact result is 10.0 
itself.  So the result of the division is rounded up to 10.0, and then the 
floor returns 10.0

> and the doc says that the floor division should behave the same.

Where do the docs say that?


Python tracker <>
Python-bugs-list mailing list

Reply via email to