|
|
Am 19.07.2018 um 03:38 schrieb Alain:
>> I did find the topic of rounding to be more complex than my initial naive
>> concept. There are different ways to do it, and it would be useful and
>> instructive to see examples of code that performed all the different
>> variations.
>
> Mostly, there are 3 ways : Round down, or truncate, round to the closest
> and round up.
Actually there are a few more commonly used:
- Round towards negative infinity (round down)
- Round towards positive infinity (round up)
- Round towards zero (truncate)
- Round towards infinity of same sign
- Round to nearest ("proper" rounding)
In the latter mode, there is again a host of ways to handle values smack
in the middle between the nearest representable numbers (think 0.5):
- Round towards negative infinity (round down)
- Round towards positive infinity (round up)
- Round towards zero (truncate)
- Round towards infinity of same sign
- Round up if even, down if odd
- Round down if even, up if odd
Post a reply to this message
|
|