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.
Here's a table of the typical math operators in NeoHaskell and what they do:
|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:
In this example I am subtracting 64 from 112
Lets say I want to divide 117 by 12 and find the quotient, I can do it in NeoHaskell like this:
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:
I want to know what we will get as remainder when we divide -21 by 4, I can do it as shown:
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.
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.
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 + 72
neo> 112 - 64
neo> 117 / 12
neo> 5 **3
More Advanced Math
More advanced math functions are available in the
Math module. It is
available by default, so you don't need to import it.
Modules? Import? What??
Don't worry, we'll get to that later. For now, just know that you can use do some math operations like this:
neo> Math.sin 90
neo> Math.sqrt 64
neo> Math.log 10
You can experiment and explore the advanced math functions available by
Math. and then pressing
TAB to see the list of functions.