Goonstation 13 - Modules - TypesDefine Details

# _std/math.dm eulers e Ï Gets the ceiling (maps x to the least integer greater than or equal to x) ceil, with second argument being the multiple to use for rounding rounds down to the nearest integer rounds down to the nearest integer, note that the built-in round() function alwys roundsd to the lower integer decimal part of a number but always positive. Basically modulo 1 in a way x % y but without rounding x first (i.e. fractmodulo(5.7, 2) = 1.7), also always positive Returns the sign of the given number (1 or -1) cotangent Takes a probability 'x' (0-100) and returns the probability (0-100) of seeing at least 1 success were you to test 'x' 'mult' times. Used for lag-compensating prob rolls. difference in degrees from angle x to angle y isnum() returns TRUE for NaN. Also, NaN != NaN. Checkmate, BYOND. Returns true if the number is infinity or -infinity NaN isn't a number, damn it. Infinity is a problem too. Parses a number except for NaNs and infinities rand() but for floats, returns a random floating point number between L and H provides the bit at a position (starting from 0) in a binary number example: `EXTRACT_BIT(9, 1)` toggles the bit at a position (starting from 0) in a binary number example: `TOGGLE_BIT(9, 1)` creates a binary number that is length bits long. all bits in the number are turned on creates a binary number that is length bits long. all bits in the number are turned off Linearly interpolates a and b based on t pseudorandom number based on x, y in range 0 to 1

## Define Details

### #define CREATE_EMPTY_BINARY_NUM (length) creates a binary number that is length bits long. all bits in the number are turned off

### #define CREATE_FULL_BINARY_NUM (length) creates a binary number that is length bits long. all bits in the number are turned on

### #define EXTRACT_BIT (number, position) provides the bit at a position (starting from 0) in a binary number example: `EXTRACT_BIT(9, 1)`

9 in binary is `1001` if i want to check the value of the 2nd bit in 9, i would use a value of 1 for position this is because binary numbers start at 0 and bits are counted from right to left then the << operator shifts that bit a number of bits to the left in this case, it shifts it 1 bit to the left, turning 1 into 10 (in binary) so what the macro looks like now (in binary) is `1001 & 0010` the binary and operator (&) multiplies the values of the bits together so doing `1001 & 0010` returns a value of `0000` this tells us that the 2nd bit of `1001` is 0 (off) if we did this with 11 (`1011`) instead, it would be `1011 & 0010`, which would return `0010`, which tells us that the 2nd bit of `1001` is 1 (on)

### #define TOGGLE_BIT (number, position) toggles the bit at a position (starting from 0) in a binary number example: `TOGGLE_BIT(9, 1)`

9 in binary is `1001` if i want to toggle the value of the 2nd bit in 9, i would use a value of 1 for position this is because binary numbers start at 0 and bits are counted from right to left then the << operator shifts that bit a number of bits to the left in this case, it shifts it 1 bit to the left, turning 1 into 10 (in binary) so what the macro looks like now (in binary) is `1001 ^ 0010` the binary xor operator (`^`) sets a bit to 0 if the values of the bits are the same and sets a bit to 1 if the values are different so doing `1001 & 0010` returns a value of `1011` this just toggles the 2nd bit in the number from 0 to 1, or from 1 to 0 if we did this with 11 (`1011`) instead, it would be `1011 & 0010`, which would return `1001`

### #define angledifference (x, y) difference in degrees from angle x to angle y

### #define ceil (x) Gets the ceiling (maps x to the least integer greater than or equal to x)

### #define ceil2 (x, y) ceil, with second argument being the multiple to use for rounding

cotangent

e

### #define fractmodulo (x, y) x % y but without rounding x first (i.e. fractmodulo(5.7, 2) = 1.7), also always positive

### #define isinf (x) Returns true if the number is infinity or -infinity

### #define isnan (x) isnum() returns TRUE for NaN. Also, NaN != NaN. Checkmate, BYOND.

### #define isnum_safe (x) NaN isn't a number, damn it. Infinity is a problem too.

### #define lerp (a, b, t) Linearly interpolates a and b based on t

### #define nround (x) rounds down to the nearest integer, note that the built-in round() function alwys roundsd to the lower integer

### #define percentmult (x, mult) Takes a probability 'x' (0-100) and returns the probability (0-100) of seeing at least 1 success were you to test 'x' 'mult' times. Used for lag-compensating prob rolls.

Ï

### #define posfract (x) decimal part of a number but always positive. Basically modulo 1 in a way

### #define randfloat (L, H) rand() but for floats, returns a random floating point number between L and H

### #define roundfloor (x) rounds down to the nearest integer

### #define sign (x) Returns the sign of the given number (1 or -1)