# code/__DEFINES/maths.dm

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

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

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

RANDOM_DECIMAL | Returns a random decimal between x and y. |

## 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

### RANDOM_DECIMAL

Returns a random decimal between x and y.

### SIGN

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

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

.