Goonstation 13 - Modules - TypesDefine Details

_std/math.dm

eulerse
piπ
ceil2ceil, with second argument being the multiple to use for rounding
nroundrounds down to the nearest integer, note that the built-in round() function alwys roundsd to the lower integer
posfractdecimal part of a number but always positive. Basically modulo 1 in a way
fractmodulox % y but without rounding x first (i.e. fractmodulo(5.7, 2) = 1.7), also always positive
signReturns the sign of the given number (1 or -1)
cotcotangent
percentmultTakes 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.
angledifferencedifference in degrees from angle x to angle y
isnum_safeNaN isn't a number, damn it. Infinity is a problem too.
/proc/text2num_safeParses a number except for NaNs and infinities
randfloatrand() but for floats, returns a random floating point number between L and H
EXTRACT_BITprovides the bit at a position (starting from 0) in a binary number example: EXTRACT_BIT(9, 1)
TOGGLE_BITtoggles the bit at a position (starting from 0) in a binary number example: TOGGLE_BIT(9, 1)
CREATE_FULL_BINARY_NUMcreates a binary number that is length bits long. all bits in the number are turned on
CREATE_EMPTY_BINARY_NUMcreates a binary number that is length bits long. all bits in the number are turned off
lerpLinearly interpolates a and b based on t
/proc/fixed_randompseudorandom number based on x, y in range 0 to 1

Define Details

CREATE_EMPTY_BINARY_NUM

creates a binary number that is length bits long. all bits in the number are turned off

CREATE_FULL_BINARY_NUM

creates a binary number that is length bits long. all bits in the number are turned on

EXTRACT_BIT

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)

TOGGLE_BIT

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

angledifference

difference in degrees from angle x to angle y

ceil2

ceil, with second argument being the multiple to use for rounding

cot

cotangent

eulers

e

fractmodulo

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

isnum_safe

NaN isn't a number, damn it. Infinity is a problem too.

lerp

Linearly interpolates a and b based on t

nround

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

percentmult

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.

pi

π

posfract

decimal part of a number but always positive. Basically modulo 1 in a way

randfloat

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

sign

Returns the sign of the given number (1 or -1)