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 revisionBoth sides next revision
rounding [2017/06/12 18:59] korshunrounding [2019/04/18 21:43] 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. The ones with the ''i'' prefix in the name return an integer, while the ones without return a fixed-point number: Every rounding mode is available as two functions. The ones with the ''i'' prefix in the name return an integer, while the ones without return a fixed-point number:
  
 ^ Mode  ^ as fixed ^ as int ^ ^ Mode  ^ as fixed ^ as int ^
-^ floor | [[functions:floor|floor()]] | [[functions:ifloor|ifloor()]] +^ floor | ''floor()'' ''ifloor()'' 
-^ ceil  | [[functions:ceil|ceil()]] | [[functions:iceil|iceil()]] +^ ceil  | ''ceil()'' ''iceil()'' 
-^ round | [[functions:round|round()]] | [[functions:iround|iround()]] +^ round | ''round()'' ''iround()'' 
-^ trunc | [[functions:trunc|trunc()]] [[functions:itrunc|itrunc()]] |+^ trunc | ''trunc()'' ''itrunc()'' | 
 + 
 +Example of the difference between ''i'' and non-''i'' functions: 
 + 
 +  * ''floor(2.3== 2.0;'' 
 +  * ''ifloor(2.3) == 2;'' 
 + 
 +So the full function list is as follows:
  
 +  * ''fixed floor(fixed x)''
 +  * ''fixed ceil(fixed x)''
 +  * ''fixed round(fixed x)''
 +  * ''fixed trunc(fixed x)''
 +  * ''int ifloor(fixed x)''
 +  * ''int iceil(fixed x)''
 +  * ''int iround(fixed x)''
 +  * ''int itrunc(fixed x)''
rounding.txt · Last modified: 2019/08/26 21:02 by korshun