##
**MathModule**

The MathModule is a module in which developers can easily access an ever-expanding library of mathematical formulas, constants, and functions. Use it in your games to acquire a variety of all things math in an efficient and easy to use manner.

##
**What does the MathModule do?**

Before I created the module, I thought to myself, “I wish there were more math functions built into lua scripting.” Soon after I began scripting the module that you see today. The MathModule contains mainly functions, with a few constants. The functions range in usefulness, including geometry, algebra, and lots of number manipulation.

##
**Accessing the MathModule**

The MathModule can be accessed in two ways. Inserting the module into the game manually, and requiring it from a script, or requiring the id.

https://www.roblox.com/library/5737882098/Matts-MathModule-Math-Library

The model link is shown above. You can take this model and insert it manually into the game. For covenience, I would recommend placing in ReplicatedStorage or the Workspace, as these replicate to both the server and client.

The second method, is requiring the id within a script. The code below can load the MathModule into your game through a script.

`local MathModule = require(5737882098)`

Which method is best? They both have benefits. Manual insertion of the model allows for a module in a single place, able to be required from any script in the game. On the other hand, requiring by id ensures that you have access to the most up-to-date version of the module. Remember, changes are always being made. If you encounter any mistakes with the MathModule, please message MattPrograms on ROBLOX.

##
**Constants**

Currently, there are very few constants.

**e** - Euler’s number (2.71828182845…)

**phi** - Golden Ratio (1.61803398875…)

##
**Functions**

**Rand**(`double`

min, `double`

max, `bool`

round) - Returns a random number between the minimum (min) and maximum (max) values. If the bool round is true, it will return a random integer. This can be used in place of math.random, as it uses a different method of obtaining random numbers, resulting in less repetitiveness.

(Additional identifiers: **Random**, **RandomNumber**)

**Rnd**(`double`

n, `int`

p) - Returnsn, rounded to the p decimal place. Leave p blank or as 0 to round to the nearest whole number.

(Additional identifiers: **Round**)

**Add**(`tuple`

…) - Returns the sum of all values. Input types include numbers and arrays.

**Mult**(`tuple`

…) - Returns the product of all values. Input types include numbers and arrays.

(Additional identifiers: **Multply**)

**Even**(`int`

n) - Returns a bool. True if the number is even, false otherwise.

**Odd**(`int`

n) - Returns a bool. True if the number is odd, false otherwise.

**EvenOrOdd**(`int`

n) - Returns 0 if n is even, 1 if n is odd.

**Comp**(`int`

n) - Returns a bool. True if the number is composite, false if it is prime.

(Additional identifiers: **Composite**)

**Prime**(`int`

n) - Returns a bool. True if the number is prime, false if it is composite.

**Recip**(`double`

n) - Returns the reciprocal, or multiplicative inverse, of a number.

(Additional identifiers: **Reciprocal**, **Inv**, **Inverse**

**Fact**(`int`

n) - Returns the factorial of n (n!).

(Additional identifiers: **Factorial**)

**Diag**(`tuple`

…) - Returns the diagonal of the shape created based on the lengths provided. If two numbers are input, it returns the diagonal of a rectangle with the provided length and width. If three numbers are input, it returns the diagonal of a rectangular prism with the provided length, width, and height. Also known as Pythagorean Theorem.

(Additional identifiers: **Diagonal**)

**Root**(`double`

x, `double`

n) - Returns the nth root of x. Root is better than math.sqrt, as it can use root other than the square. These include cube roots, 4th roots, and so on.

**Mean**(`tuple`

…) - Returns the mean (the average) of the data set. Input types can include numbers and arrays.

**Median**(`tuple`

…) - Returns the median (center of numerically ordered sets) of the data set.

**Mode**(`tuple`

…) - Returns the mode (most commonly occurring number) of the data set.

- More is to be added to this post.