MongooseA text-based world full of questionable inventions.

All help topics · Link to this topic

Showing help on '$math_utils'

math utilities ($math_utils #26)

Trigonometric/Exponential functions:
sin -- returns 10000*(the value of the corresponding
trigonometric function) angle a is in degrees.
arctan -- returns arctan(y/x) in degrees in the range -179..180.
x defaults to 10000. Quadrant is that of (x,y).
exp -- calculates e^x with an nth order taylor polynomial
aexp -- calculates 10000 e^(x/10000)

Statistical functions:
combinations -- returns the number of combinations given n objects
taken r at a time.
permutations -- returns the number of permutations possible given
n objects taken r at a time.

Number decomposition:
div -- correct version of / (handles negative numbers correctly)
mod -- correct version of % (handles negative numbers correctly)
divmod -- {div(n,d),mod(n,d)}
parts -- returns a list of two elements {integer,decimal fraction}

Other math functions:
sqrt -- returns the largest integer n <= the square root of x
pow -- returns x^n
factorial -- returns x!
norm -- returns sqrt(a^2+b^2+c^2+...)
sum -- returns the sum of all arguments.

Series:
fibonacci -- returns the 1st n fibonacci numbers in a list
geometric -- returns the value of the nth order geometric series at x

Integer Properties:
gcd -- find the greatest common divisor of the two numbers
lcm -- find the least common multiple of the two numbers
are_relatively_prime -- return 1 if a and b are relatively prime
is_prime -- returns 1 if the number is a prime and 0 otherwise

Miscellaneous:
random -- returns a random number from 0..n if n > 0 or n..0 if n < 0
random_range -- returns a random number from mean - n..mean + n
with mean defaulting to 0
simpson -- returns the numerical
approximation of an integral using simpson's rule
base_conversion -- converts the number
given as first arg from oldbase to the newbase.

Bitwise Arithmetic:
AND -- returns x AND y
OR -- returns x OR y
XOR -- returns x XOR y (XOR is the exclusive-or function)
NOT -- returns the complement of x
All bitwise manipulation is of 32-bit values.

Bitwise Conversions:
BlFromInt -- converts a decimal number d to a list of 1's and 0's, 32-bit
IntFromBl -- converts a list of 1's and 0's (any precision) to decimal

:xsin - xsin(INT x) -- calculates the taylor approximation for the sine function
:xcos - xcos(INT x) -- calculates the taylor approximation for the cosine function
:factorial - factorial(INT n) -- returns n factorial for 0 <= n (<= 12).
:pow - pow(INT|FLOAT x,(INT)|(INT|FLOAT) n) -- returns x raised to the nth power.
:fibonacci - fibonacci(INT n) -- calculates the fibonacci numbers to the nth term
:geometric - geometric(INT|FLOAT x [,INT n]) -- calculates the value of the geometric series at x to the nth term.
:divmod - divmod(INT n, INT d) => {q,r} such that n = dq + r
:combinations - combinations(INT n, INT r) -- returns the number of ways one can choose r
:permutations - permutations(INT n, INT r) -- returns the number of ways possible for one to
:simpson - simpson({a,b},{f(a),f((a+b)/2),f(b)} [,INT ret-float])
:parts - parts(INT n, INT q [,INT i]) -- returns a decomposition of n by q into integer and floating point parts with i = the number of digits after the decimal.
:sqrt - sqrt(INT|FLOAT n) => largest integer <= square root of n.
:div - div(INT n, INT d) => q such that n = dq + r and (0<=r<d if d>0, -d<r<=0 if d<0).
:mod - A correct mod function.
:exp - exp(INT|FLOAT x[,INT n]) -- calculates an nth order taylor approximation for e^x.
:aexp - returns 10000 exp (x/10000)
:random - random(INT n): returns a random integer in the following manner:
:random_range - random_range(INT range [,INT mean]): returns a random integer within the given range from the mean.
:is_prime - is_prime(INT number) returns 1 if the number is prime or 0 if it isn't.
:AND - Only useful for integer input.
:BLFromInt - BLFromInt(INT x) => 32-element {0/1} list (sign bit + 31 bits) for x in [0, 2^31).
:IntFromBL - IntFromBl(LIST of 1's and 0's) => converts the 32 bit binary representation given by the list of 1's and 0's and converts it to a normal decimal number.
:gcd - gcd(INT num1,INT num2): find the greatest common divisor of the two numbers
:lcm - lcm(INT num1,INT num2): find the least common multiple of the two numbers.
:are_rel_prime - are_rel_prime(INT num1,INT num2): returns 1 if num1 and num2 are relatively
:base_conversion - Synopsis: :base_conversion(number, current_base, desired_base)
:norm(a,b,c,d...) => sqrt(a^2+b^2+c^2+...)
:deg2rad(FLOAT Degrees) => FLOAT Radians
:rads2deg(FLOAT Radians) => FLOAT Degrees
:precision(FLOAT Number, INT Digits of Precision) => FLOAT Number
:round - Usage: round(INT number, INT round)
:mean - Usage: mean(INT, INT, ...
:sum_float(FLOAT num, num, num ...) => Total of all arguments added together.
:sum_int(INT num, num, num ...) => Total of all arguments added together.
:rint(FLOAT Number) => FLOAT Number
:sign - Returns 1 if the number is positive, -1 if it's negative, and 0 if it's zero.;

Also from $generic_utils: 1 documented verb. help $generic_utils