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

Next revision
Previous revision
Next revisionBoth sides next revision
rounding [2017/03/15 16:39] – created korshunrounding [2019/04/18 22:05] korshun
Line 1: Line 1:
-===== Rounding =====+===== Rounding functions ===== 
 + 
 +ACSUtils provides a full set of functions to round fixed-point numbers to integers.
  
 There are four rounding modes: There are four rounding modes:
Line 8: Line 10:
   * ''round'' -- rounds the number to the closest integer   * ''round'' -- rounds the number to the closest integer
  
-Rounding table:+Example rounding table:
  
 ^  x   ^ round(x) ^ floor(x) ^ ceil(x) ^ trunc(x) ^ ^  x   ^ round(x) ^ floor(x) ^ ceil(x) ^ trunc(x) ^
-^   2.3|         2|         2|        3|         2+^   1.3|         1|         1|        2|         1
-^   3.8|         4|         3|        4|         3+^   1.5|         2|         1|        2|         1
-^   5.5|         6|         5|        6|         5+^   1.8|         2|         1|        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| 
 + 
 +Every rounding mode is available as two functions: 
 +  * 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''
 + 
 +^ 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)''
 + 
 +<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** as a result.
  
-Every rounding mode is available as two functions. The ones with the "i" in the name return an integer, while the ones without the "i" return a fixed. 
  
 +</note>
rounding.txt · Last modified: 2019/08/26 21:02 by korshun