# Math Functions

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

### random

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

#### Params

 range the 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

 x1 x coordinate of first point y1 y coordinate of first point x2 x coordinate of second point y2 y 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

 x an 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

 x value top numerator bottom denominator

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

 x a value exp_top the numerator of the exponent exp_bottom the 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

 y Y axis x X axis

#### Returns

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

### log10

Computes the base-10 logarithm of the provided number.

#### Params

 x the number

#### Returns

The logarithm, rounded down.

### ln

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

#### Params

 x the number

#### Returns

The natural logarithm, rounded down.

### log

Computes the base-Y logarithm of the provided number.

#### Params

 x the number base the base

#### Returns

The logarithm, rounded down.

### gcd

Computes the greatest common divisor of the provided two numbers.

#### Params

 x first number y second number

#### Returns

The greatest common divisor.