ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new: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
new:rounding [2018/02/17 00:23] korshunnew:rounding [2019/04/20 00:41] (current) – removed korshun
Line 1: Line 1:
-===== Rounding functions ===== 
  
-These functions round fixed-point numbers to one of the two nearby integers. 
- 
-There are four rounding modes: 
- 
-  * ''trunc'' -- zeroes the fractional part of the number 
-  * ''floor'' -- rounds the number down 
-  * ''ceil'' -- round the number up 
-  * ''round'' -- rounds the number to the closest integer 
- 
-Example rounding table: 
- 
-^  x   ^ round(x) ^ floor(x) ^ ceil(x) ^ trunc(x) ^ 
-^   1.3|         1|         1|        2|         1| 
-^   1.8|         2|         1|        2|         1| 
-^   1.5|         2|         1|        2|         1| 
-^  -1.3|        -1|        -2|       -1|        -1| 
-^  -1.8|        -2|        -2|       -1|        -1| 
-^  -1.5|        -1|        -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: 
- 
-^ Mode  ^ as fixed ^ as int ^ 
-^ floor | ''floor()'' | ''ifloor()'' | 
-^ ceil  | ''ceil()'' | ''iceil()'' | 
-^ round | ''round()'' | ''iround()'' | 
-^ trunc | ''trunc()'' | ''itrunc()'' | 
- 
-Example of the difference: 
- 
-  * ''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)'' 
new/rounding.1518819804.txt.gz · Last modified: 2018/02/17 00:23 by korshun