Julia Arithmetic Operations
kodingwindow@kw:~$ julia ... julia> 10+20 30 julia> 10-20 -10 julia> 10*20 200 julia> 10/20 0.5 julia> 2^10 1024 julia> mod(-7,4) 1 julia> mod(7,4) 3 julia> rem(-7,4) -3 julia> rem(7,4) 3 julia> div(-7,4) -1 julia> div(7,4) 1 julia> divrem(-7,4) (-1, -3) julia> divrem(7,4) (1, 3) julia> 2//3 2//3 julia> numerator(2//3) 2 julia> denominator(2//3) 3 julia> 10//30 1//3 julia> Inf Inf julia> NaN NaN julia> Inf*0 NaN julia> gcd(18,21) 3 julia> lcm(24,36) 72
Arithmetic operations on complex numbers
julia> complex(4+5im)+complex(2+6im) 6 + 11im julia> c1=4+5im 4 + 5im julia> c2=2+6im 2 + 6im julia> c1+c2 6 + 11im julia> c1-c2 2 - 1im julia> c1*c2 -22 + 34im julia> c1/c2 0.95 - 0.35000000000000003im julia> c1^2 -9 + 40im julia> 10(c1) 40 + 50im
round(), floor(), ceil() and trunc() functions
julia> round(2.3) 2.0 julia> round(2.8) 3.0 julia> round(-2.3) -2.0 julia> round(-2.8) -3.0
julia> floor(2.3) 2.0 julia> floor(2.8) 2.0 julia> floor(-2.3) -3.0 julia> floor(-2.8) -3.0
julia> ceil(2.3) 3.0 julia> ceil(2.8) 3.0 julia> ceil(-2.3) -2.0 julia> ceil(-2.8) -2.0
julia> trunc(2.3) 2.0 julia> trunc(2.8) 2.0 julia> trunc(-2.3) -2.0 julia> trunc(-2.8) -2.0
typeof() function
julia> typeof(2) Int64 julia> typeof(2.3) Float64 julia> typeof(-1) Int64 julia> typeof(0x02) UInt8 julia> typeof(pi) Irrational{:π} julia> typeof(Inf) Float64 julia> typeof(NaN) Float64
Advertisement