This is an old revision of the document!
ACSUtils provides a full set of functions to round fixed-point numbers to integers.
There are four rounding modes:
trunc – zeroes the fractional part of the numberfloor – rounds the number downceil – round the number upround – rounds the number to the closest integerExample rounding table:
| x | round(x) | floor(x) | ceil(x) | trunc(x) |
|---|---|---|---|---|
| 1.3 | 1 | 1 | 2 | 1 |
| 1.5 | 2 | 1 | 2 | 1 |
| 1.8 | 2 | 1 | 2 | 1 |
| -1.3 | -1 | -2 | -1 | -1 |
| -1.5 | -1 | -2 | -1 | -1 |
| -1.8 | -2 | -2 | -1 | -1 |
Every rounding mode is available as two functions:
i prefix return a fixed, e.g. floor(2.3) == 2.0.i prefix return an int, e.g ifloor(2.3) == 2.| Mode | fixed result | int result |
|---|---|---|
| floor | fixed floor(fixed x) | int ifloor(fixed x) |
| ceil | fixed ceil(fixed x) | int iceil(fixed x) |
| round | fixed round(fixed x) | int iround(fixed x) |
| trunc | fixed trunc(fixed x) | int itrunc(fixed x) |
Before using ACSUtils, rename either the built-in functions (by editing zcommon.acs) or the ACSUtils functions (by editing acsutils.acs) to something else.