code/__DEFINES/math.dm 
| SIGNED_FLOOR_DIVISION | Returns the integer closest to 0 from a division |
|---|---|
| ROUND_PROB | Probabilistic rounding: Adds 1 to the integer part of x with a probability equal to the decimal part of x. ie. ROUND_PROB(40.25) returns 40 with 75% probability, and 41 with 25% probability. |
| DIGITS | Returns the number of digits in a number. Only works on whole numbers. This is marginally faster than string interpolation -> length |
| WRAP_UP | Increments a value and wraps it if it exceeds some value. Can be used to circularly iterate through a list through idx = WRAP_UP(idx, length_of_list). |
| WRAP_UID | Helper that increments and wraps the passed in number when it hits the integer limit |
| INVERSE_LERP | Performs an inverse linear interpolation between a, b, and a provided value between a and b This returns the amount that you would need to feed into a lerp between A and B to return the third value |
| TOBITSHIFT | Gets shift x that would be required the bitflag (1<<x) We need the round because log has floating-point inaccuracy, and if we undershoot at all on list indexing we'll get the wrong index. |
| SPT_PROB_RATE | Converts a probability/second chance to probability/seconds_per_tick chance
For example, if you want an event to happen with a 10% per second chance, but your proc only runs every 5 seconds, do if(prob(100*SPT_PROB_RATE(0.1, 5))) |
| SPT_PROB | Like SPT_PROB_RATE but easier to use, simply put if(SPT_PROB(10, 5)) |
| DIAMOND_AREA | The number of cells in a taxicab circle (rasterized diamond) of radius X. |
| randfloat | rand() but for floats, returns a random floating point number between L and H |
| IS_IN_BOUNDS | Tests if the value is in the given range. |
Define Details
DIAMOND_AREA 
The number of cells in a taxicab circle (rasterized diamond) of radius X.
DIGITS 
Returns the number of digits in a number. Only works on whole numbers. This is marginally faster than string interpolation -> length
INVERSE_LERP 
Performs an inverse linear interpolation between a, b, and a provided value between a and b This returns the amount that you would need to feed into a lerp between A and B to return the third value
IS_IN_BOUNDS 
Tests if the value is in the given range.
ROUND_PROB 
Probabilistic rounding: Adds 1 to the integer part of x with a probability equal to the decimal part of x. ie. ROUND_PROB(40.25) returns 40 with 75% probability, and 41 with 25% probability.
SIGNED_FLOOR_DIVISION 
Returns the integer closest to 0 from a division
SPT_PROB 
Like SPT_PROB_RATE but easier to use, simply put if(SPT_PROB(10, 5))
SPT_PROB_RATE 
Converts a probability/second chance to probability/seconds_per_tick chance
For example, if you want an event to happen with a 10% per second chance, but your proc only runs every 5 seconds, do if(prob(100*SPT_PROB_RATE(0.1, 5)))
TOBITSHIFT 
Gets shift x that would be required the bitflag (1<<x) We need the round because log has floating-point inaccuracy, and if we undershoot at all on list indexing we'll get the wrong index.
WRAP_UID 
Helper that increments and wraps the passed in number when it hits the integer limit
WRAP_UP 
Increments a value and wraps it if it exceeds some value. Can be used to circularly iterate through a list through idx = WRAP_UP(idx, length_of_list).
randfloat 
rand() but for floats, returns a random floating point number between L and H