I want to obtain the floating-point floor of the division of two positive floating-point numbers. In particular I'm after the greatest floating-point number not greater than the exact value of the floor of the division. The dividend can be big and the divisor small, but in my application there's no risk of overflow or underflow in the division.
If I do this:
quotient = floor(dividend / divisor);
I have the problem that, when the quotient is greater than the precision of the mantissa, the result of the division is always an integer, so the FPU rounds it rather than flooring it because it's in round-to-nearest-or-even mode; also floor()
does nothing because it's fed an integer already. Since it's rounded, sometimes the result is greater than the exact floor, and that's not what I'm after.
Changing the FPU's rounding mode during the division would be a solution, but that is not an option, so barring that, how can I obtain the correct floor?
(Related: How to correctly floor the floating point pair sum)