This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rounding [2017/04/15 17:47] – korshun | rounding [2019/04/20 03:13] – korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Rounding ===== | ===== Rounding ===== | ||
+ | |||
+ | ACSUtils provides a full set of functions to round fixed-point numbers to integers. | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | Before using ACSUtils, rename either the built-in functions (by editing '' | ||
+ | </ | ||
+ | |||
+ | ==== Rounding modes ==== | ||
There are four rounding modes: | There are four rounding modes: | ||
Line 8: | Line 17: | ||
* '' | * '' | ||
- | Rounding | + | A table that demonstrates the differences between rounding modes: |
^ x ^ round(x) ^ floor(x) ^ ceil(x) ^ trunc(x) ^ | ^ x ^ round(x) ^ floor(x) ^ ceil(x) ^ trunc(x) ^ | ||
- | ^ 2.3| 2| 2| | + | ^ 1.3| 1| 1| |
- | ^ 3.8| 4| 3| | + | ^ 1.5| 2| 1| |
- | ^ 5.5| 6| 5| | + | ^ 1.8| 2| 1| |
- | ^ -2.3| -2| -3| -2| -2| | + | ^ -1.3| -1| -2| -1| -1| |
- | ^ -3.8| -4| -4| -3| -3| | + | ^ -1.5| -1| -2| -1| -1| |
- | ^ -5.5| -5| -6| -5| -5| | + | ^ -1.8| -2| -2| -1| -1| |
+ | |||
+ | ==== Rounding functions in ACSUtils ==== | ||
+ | |||
+ | Every rounding mode is available as two functions: | ||
+ | * Functions without the '' | ||
+ | * Functions with the '' | ||
- | Every rounding mode is available as two functions. The ones with the '' | + | ^ Mode ^ fixed result ^ int result ^ |
+ | ^ floor | '' | ||
+ | ^ ceil | '' | ||
+ | ^ round | '' | ||
+ | ^ trunc | '' | ||
- | ^ Mode ^ as fixed ^ as int ^ | ||
- | ^ floor | [[functions: | ||
- | ^ ceil | [[functions: | ||
- | ^ round | [[functions: | ||
- | ^ trunc | [[functions: | ||