ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


rounding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rounding [2019/04/18 22:08] korshunrounding [2019/08/26 21:02] (current) korshun
Line 1: Line 1:
-===== Rounding functions =====+====== Rounding====== 
 + 
 +===== Introduction =====
  
 ACSUtils provides a full set of functions to round fixed-point numbers to integers. ACSUtils provides a full set of functions to round fixed-point numbers to integers.
 +
 +<note warning>Current GZDoom provides built-in functions [[zdoom>Floor_(ACS_function)|floor]], [[zdoom>ceil]] and [[zdoom>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.
 +</note>
 +
 +===== Rounding modes =====
  
 There are four rounding modes: There are four rounding modes:
Line 10: Line 19:
   * ''round'' -- rounds the number to the closest integer   * ''round'' -- rounds the number to the closest integer
  
-Example rounding table:+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) ^
 ^   1.3|         1|         1|        2|         1| ^   1.3|         1|         1|        2|         1|
-^   1.5|         2|         1|        2|         1|+^   1.5|    1 or 2|         1|        2|         1|
 ^   1.8|         2|         1|        2|         1| ^   1.8|         2|         1|        2|         1|
 ^  -1.3|        -1|        -2|       -1|        -1| ^  -1.3|        -1|        -2|       -1|        -1|
-^  -1.5|        -1|        -2|       -1|        -1|+^  -1.5|  -2 or -1|        -2|       -1|        -1|
 ^  -1.8|        -2|        -2|       -1|        -1| ^  -1.8|        -2|        -2|       -1|        -1|
 +
 +===== Functions =====
  
 Every rounding mode is available as two functions: Every rounding mode is available as two functions:
   * Functions without the ''i'' prefix return a fixed, e.g. ''floor(2.3) == 2.0''.   * Functions without the ''i'' prefix return a fixed, e.g. ''floor(2.3) == 2.0''.
-  * Functions with the ''i'' prefix return an int, e.g ''ifloor(2.3) == 2''.+  * Functions with the ''i'' prefix return an int, e.g''ifloor(2.3) == 2''.
  
 ^ Mode  ^ fixed result ^ int result ^ ^ Mode  ^ fixed result ^ int result ^
Line 30: Line 41:
 ^ trunc | ''fixed trunc(fixed x)'' | ''int itrunc(fixed x)'' | ^ trunc | ''fixed trunc(fixed x)'' | ''int itrunc(fixed x)'' |
  
-<note important>Current GZDoom provides built-in functions [[zdoom>Floor_(ACS_function)|floor]], [[zdoom>ceil]] and [[zdoom>round]], but these functions are not available in Zandronum 3.0 and **silently return 0**, because all unimplemented built-in ACS functions return 0. 
  
-Before using ACSUtils, rename either the built-in functions (by editing ''zcommon.acs'') or the ACSUtils functions (by editing ''acsutils.acs'') to something else. +
-</note>+
rounding.1555614499.txt.gz · Last modified: 2019/04/18 22:08 by korshun