/tg/ Station 13 - Modules - TypesDefine Details

# code/__DEFINES/maths.dm

SIGN Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive Returns the number of digits in a number. Only works on whole numbers. This is marginally faster than string interpolation -> length 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)`. 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 Gets shift x that would be required the bitflag (1<

## Define Details

### #define DIAMOND_AREA (X)

The number of cells in a taxicab circle (rasterized diamond) of radius X.

### #define DIGITS (x)

Returns the number of digits in a number. Only works on whole numbers. This is marginally faster than string interpolation -> length

### #define INVERSE_LERP (a, b, value)

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

### #define RANDOM_DECIMAL (x, y)

Returns a random decimal between x and y.

### #define SIGN (x)

Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive

### #define SPT_PROB (prob_per_second_percent, seconds_per_tick)

Like SPT_PROB_RATE but easier to use, simply put `if(SPT_PROB(10, 5))`

### #define SPT_PROB_RATE (prob_per_second, seconds_per_tick)

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)))`

### #define TOBITSHIFT (bit)

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.

### #define WRAP_UP (val, max)

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)`.