Am 01.06.2012 09:58, schrieb Bharath M R:
> Exactly my problem. Multiplying and using ceil might cause inaccuracy.
> Is it possible to round to the nearest floating point value, but rounding
> up.
> Something like `round`, but which always rounds up or rounds down.
You seem to be assuming that round(n) is accurate, but is it?
IEEE does not define that function AFAIK.
If that's correct, Python is pretty much forced to do the
multiply-round-divide routine, and may have errors.
It's not even easy to test whether Python is accurate. You'd need some
way to make sure that you test with both the lower and higher machine
number that's around your 0.05-like test value.
I know of no way to reliably produce these from a programming language
(since these produce their constants from a decimal representations and
programming languages usually don't define the conversion rules very
well). You'd probably have to start with a hexadecimal representation of
the double that you want to test. Or construct your test values
algorithmically (that will eliminate coding errors in the hex values,
I'd suggest doing that).