Math Functions

Summary
Generate a random value between 1 and the specified limit (inclusive)
Perform the ‘distance’ formula using floating point math.
A floating point implementation of a square root function.
Perform a floating point fractional multiplication.
Return the value of an integer raised to a given power.
Computes the arc tangent of y/x, determining the quadrant based on signs of the two values.
Computes the base-10 logarithm of the provided number.
Computes the natural (base e) logarithm of the provided number.
Computes the base-Y logarithm of the provided number.
Computes the greatest common divisor of the provided two numbers.

random

Generate a random value between 1 and the specified limit (inclusive)

Params

rangethe largest possible random value

Returns

An integer between 1 and range inclusive.

mdist

Perform the ‘distance’ formula using floating point math.  The distance formula is typically used to find the distance between two points and is:

dist = sqrt( (x1 - x2)^2 + (y1 - y2)^2 )

The math is done internally using floating point math to minimize roundoff.  The end result is then rounded to the nearest integer.

Params

x1x coordinate of first point
y1y coordinate of first point
x2x coordinate of second point
y2y coordinate of second point

Returns

The closest integer value after peforming the distance formula.

msqrt

A floating point implementation of a square root function.  The math is done using floats, but rounded after.  Be warned, that for smaller values, the roundoff can be quite significant.  The value of the sqrt of a negative number in this case is undefined.

Params

xan integer

Returns

The approximate square root of a value.

mfrac

Perform a floating point fractional multiplication.  The formula for this is:

value = x * top / bottom

Params

xvalue
topnumerator
bottomdenominator

Returns

The value after both multiplying with top and dividing by bottom.  The result is rounded to the closest integer.

mpow

Return the value of an integer raised to a given power.  The result is calculating using the formula:

value = x ^ ( top / bottom )

Params

xa value
exp_topthe numerator of the exponent
exp_bottomthe denominator of the exponent

Returns

The value after rounding the exponentiation.

matan2

Computes the arc tangent of y/x, determining the quadrant based on signs of the two values.  The result is in degrees, in the -180 ..  180 range.

value = atan( y / x )

Params

yY axis
xX axis

Returns

The resulting arc tangent, in degrees (-180 ..  180).

log10

Computes the base-10 logarithm of the provided number.

Params

xthe number

Returns

The logarithm, rounded down.

ln

Computes the natural (base e) logarithm of the provided number.

Params

xthe number

Returns

The natural logarithm, rounded down.

log

Computes the base-Y logarithm of the provided number.

Params

xthe number
basethe base

Returns

The logarithm, rounded down.

gcd

Computes the greatest common divisor of the provided two numbers.

Params

xfirst number
ysecond number

Returns

The greatest common divisor.