# Doing Math

caution

The documentation that you're reading is a design document where most of the features you're reading are yet to be implemented. Check the Note on the Docs

As the Professor Walter White said once, "Jesse, let's cook some math", or something like that, I don't know.

Anyways, let's get to the point.

## Basic Math ​

Here's a table of the typical math operators in NeoHaskell and what they do:

OperatorDescription
+Adds two numbers
-Subtracts two numbers
*Multiplies two numbers
/Divides two numbers
**Raises a number to a power
%Gets the remainder of a division
>>Shift right binary operation
<<Shift left binary operation

## Trying it in the REPL​

Lets say that I want to add 56 and 72 and find its result, I can do it as shown:

neo> 56+72128

### Subtraction Example​

In this example I am subtracting 64 from 112

neo> 112-6448

### Division Example​

Lets say I want to divide 117 by 12 and find the quotient, I can do it in NeoHaskell like this:

neo> 117/129

### Power Example​

Lets say I want to find what we will get by cubing five (five raised to the power of three), I can do it in NeoHaskell as shown:

neo> 5**3125

### Remainder Example​

I want to know what we will get as remainder when we divide -21 by 4, I can do it as shown:

neo> 21%4-1

### Right Shift Example​

This operator shifts the bits (the 1's and 0's of the computer representation) of a number to the right by a specified number of bits. For example, if we shift the bits of 5 to the right by 2 bits, we will get 1. This is because 5 in binary is 101, and when we shift it to the right by 2 bits, we get 1, which is 001 in binary.

neo> 5>>21

### Left Shift Example​

This operator shifts the bits (the 1's and 0's of the computer representation) of a number to the left by a specified number of bits. For example, if we shift the bits of 5 to the left by 2 bits, we will get 20. This is because 5 in binary is 101, and when we shift it to the left by 2 bits, we get 20, which is 10100 in binary.

neo> 5<<220

### Spacing doesn't matter​

NeoHaskell doesn't care about spacing, you can write the above examples as shown below and it will still work:

neo> 56 + 72128neo> 112         - 6448neo> 117 /              129neo> 5 **3125

More advanced math functions are available in the Math module. It is available by default, so you don't need to import it.
neo> Math.sin 900.8939966636005579neo> Math.sqrt 648neo> Math.log 102.302585092994046
You can experiment and explore the advanced math functions available by typing Math. and then pressing TAB to see the list of functions.