[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

int(5.0 / 2.0);

The behavior is documented (in of the Limbo manual)
but you might want to understand the rationale.

Careful scientific programmers have long documented the
intended direction of real-to-int rounding by making explicit
calls to floor, ceil, or rint.  This alerts the reader that
rounding matters and has been analyzed.  A simple cast is         
supposed to mean "give me some nearby integer; I don't really
care which one, but make it deterministic."

So in a scope that includes   "rint: import math;"   you can
change your code to    "i = rint(5.0/2.0);"   to get the
desired round-to-nearest-even semantics.

If it had been easy to provide rint semantics for casts without
any runtime penalty, I would have pushed for it on the principle
of minimum surprise.  But the balance we finally struck gives
maximum portable speed for the case when the floating value is
already integral or doesn't matter, and full descriptive power
for people who know and care about rounding.