In this Julia Tutorial, we will learn what Arithmetic Operators are available in Julia and how to use them with examples.
The following arithmetic operators are supported on all primitive numeric types:
Expression | Name | Description |
---|---|---|
+x | unary plus | the identity operation |
-x | unary minus | maps values to their additive inverses |
x + y | binary plus | performs addition |
x - y | binary minus | performs subtraction |
x * y | times | performs multiplication |
x / y | divide | performs division |
x ÷ y | integer divide | x / y, truncated to an integer |
x \ y | inverse divide | equivalent to y / x |
x ^ y | power | raises x to the y th power |
x % y | remainder | equivalent to rem(x,y) |
Unary Plus
julia> x = 10
10
julia> +x
10
Unary Minus
julia> x = 10
10
julia> -x
-10
Binary Plus
julia> x = 10
10
julia> y = 15
15
julia> x + y
25
Binary Minus
julia> x = 10
10
julia> y = 15
15
julia> x - y
-5
Multiplication
julia> x = 10
10
julia> y = 15
15
julia> x * y
150
Division
julia> x = 10
10
julia> y = 15
15
julia> x / y
0.6666666666666666
Integer Division
julia> x = 10
10
julia> y = 3
3
julia> x ÷ y
3
Inverse Division
julia> x = 10
10
julia> y = 3
3
julia> x \ y
0.3
Power
julia> x = 11
11
julia> y = 4
4
julia> x ^ y
14641
Remainder
julia> x = 11
11
julia> y = 4
4
julia> x % y
3
Conclusion
In this Julia Tutorial, we learned about Julia Arithmetic Operators with examples for each operator.