# Quick Start

## Table of Contents

[[toc]]

## Features

- ### Blazing fast
  - `@enginemirage/math` is fast and extremely simple to use. All methods follow a simple-to-understand format: `math.[method]( [arguments] )`.
- ### Super lightweight
  - `@enginemirage/math` is extremely lightweight, meaning installing it wouldn't make a difference in your project. We are actively making changes to the project to make it more lightweight.
- ### Customizable
  - `@enginemirage/math` is fully customizable. This means, all of the methods and constants are able to be customized. How is this possible? All methods/constants rest in a single class, meaning you can import the class and update it however you'd like.

## Class Customization

As just mentioned earlier, all methods/constants are able to be modified however you would like.
::: tip
If you are already familiar with Object-Oriented Programming, you can skip the following. The class customization section is nothing new if you are already familiar with classes in JavaScript.

**Just make sure, if you rewrite something inside the class, the rewritten change will only appear if you reference it after it's rewritten.** For example, this won't return `5`.

```js
console.log(math.newConstant);
math.newConstant = 5;
```

:::

### Modifying existing methods

All you have to do is rewrite the method.

```js{14-27}
import { MirageMath } from "@enginemirage/math";
const math = new MirageMath();

const square = (n, i, j) => {
  let mid = (i + j) / 2;
  let mul = mid * mid;
  if (mul === n || Math.abs(mul - n) < 0.000001) {
    return mid;
  } else if (mul < n) {
    return square(n, mid, j);
  }
};

math.sqrt = (n) => {
  let i = 1;
  const found = false;
  while (!found) {
    // If n is a perfect square
    if (i * i === n) {
      return i;
    } else if (i * i > num) {
      let res = square(num, i - 1, i);
      return res;
    }
    i++;
  }
};
```

The code above rewrites the default `math.sqrt()` method provided by Mirage Math to custom code. Mirage Math uses a Newtonian method to calculate square roots, so the code above is considered different to the original code. If you want to see a more noticable change, you can make it print something random into the terminal.

```js
math.sqrt = (msg) => {
  console.log(msg);
};
```

This would print the `msg` parameter into the terminal whenever the method is called **after** the rewrite.

### Modifying constants

Similarly, you have to import the package and rewrite the constructor variable.

```js
math.E = 0.23487238472848;
```

In reality, this isn't the actual Euler's Constant, we just updated it to some random float. To view the updated version, you have to reference it **after** you rewrite it.

### Adding custom methods

Not only can you modify methods and constants, you can also add your own methods and constants. To add a new method, make sure you call it something that isn't already taken. If you do, your code will throw an error.

```js
math.something = (parameter) => {
  // .. do something here
  // for example:
  console.log(parameter);
};
```

The method: `something`, isn't already taken. This means that you could run it and it would work properly.

### Adding custom constants

Similarly, you can add constants by just setting it to a value you'd like.

```js
math.someConstant = 18567165761;
```

Now, you can reference the constant anytime after you rewrite it.
