Rounding
The Kingdom of Loathing uses several different algorithms for rounding non-integer values to integers.
Floor
In some cases, non-integer values are simply floored, which for positive inputs means the fractional part is dropped. E.g. an input of 1.9 is rounded down to 1.
In code, this is often written as floor(x)
.
Ceiling
In some cases, non-integer values are rounded up; this is often written as ceil(x)
. E.g. an input of 1.3 is rounded up to 2.
Random Rounding
In some cases, non-integer values are rounded either up or down, using a simple algorithm that compares the fractional part to a random number between 0 and 1. In Kingdom of Loathing code, this is believed to be written as rround(x)
. E.g. an input of 1.2 is rounded down to 1 (80% of the time), or rounded up to 2 (20% of the time).
Random rounding is believed to be used in a very large number of places.