Table of Contents

Rounding

Introduction

ACSUtils provides a full set of functions to round fixed-point numbers to integers.

Current GZDoom provides built-in functions floor, ceil and round, but these functions aren't available in Zandronum 3.0 and silently return 0 there, because all unimplemented built-in ACS functions return 0.

Before using ACSUtils, rename either the built-in functions (by editing zspecial.acs) or the ACSUtils functions (by editing acsutils.acs) to something else. Otherwise, ACSUtils won't compile.

Rounding modes

There are four rounding modes:

A table that demonstrates the differences between rounding modes:

x round(x) floor(x) ceil(x) trunc(x)
1.3 1 1 2 1
1.5 1 or 2 1 2 1
1.8 2 1 2 1
-1.3 -1 -2 -1 -1
-1.5 -2 or -1 -2 -1 -1
-1.8 -2 -2 -1 -1

Functions

Every rounding mode is available as two functions:

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)