Operator | Performs |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
mod | Get the remainder |
rem | Get the remainder, Sign of the result is same as sign of x. |
^ | Calculates power, a^x return a to the power x. |
*Main> let a = 10
*Main> let b = 5
*Main>
*Main> a + b
15
*Main>
*Main> a - b
5
*Main>
*Main> a * b
50
*Main>
*Main> a / b
2.0
*Main>
*Main> mod a b
0
*Main>
*Main> mod b a
5
*Main>
*Main> rem a b
0
*Main>
*Main> rem b a
5
*Main>
*Main> a ^ b
100000
*Main>
*Main> b ^ a
9765625
As you observe, I used mod, rem operators in prefix form. By using `backtics`, you can use mod and rem operators in infix notation.
*Main> 10 `mod` 3
1
*Main> 10 `rem` 3
1
Always surround negative numbers in parenthesis, other wise you will end up in following kind of error.
*Main> 10 / -3
<interactive>:86:1:
Precedence parsing error
cannot mix ‘/’ [infixl 7] and prefix `-' [infixl 6] in the same infix expression
To solve above problem, we need to put negative number in parenthesis like below.
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here