[fpc-pascal] math round vs banker's round
Sven Barth
pascaldragon at googlemail.com
Wed Aug 14 09:33:13 CEST 2013
Am 13.08.2013 23:47, schrieb David Emerson:
> Hi all,
>
> I have just discovered that the system.round function has this very
> odd behavior of rounding towards an even number when the fractional
> part is .5 -- in the system.round documentation this is described as
> "banker's rounding"
>
> I do not like this behavior. How can I use a more
> mathematically-traditional round function, which always rounds .5 up,
> and everything below .5 down?
>
> Do I need to write this function myself?
Just checked again, most FPUs only seem to support "banker's rounding",
"round up", "round down" and "truncate", so these four are the only ones
supported by FPC's and Delphi's rounding mechanism. So if you want
normal mathematical rounding then you'll need to write your own function.
Regards,
Sven
More information about the fpc-pascal
mailing list