Numbers & Arithmetic

5.1 Operators

arithmetic (/ always returns float for ints) ÷ or div(a, b) integer division (\div<Tab>) % or rem(a, b) remainder; mod(a, b) modulo left division (A \ b solves linear systems) comparison (≠ ≤ ≥ also work) identity (egal) logical (short-circuit)

7 / 2        # 3.5
7 ÷ 2        # 3
-7 % 3       # -1
mod(-7, 3)   # 2
2^10         # 1024
2^64         # 0 — integer overflow wraps around!
big(2)^64    # 18446744073709551616
1 // 3 + 1 // 6   # 1//2
0.1 + 0.2 == 0.3  # false
0.1 + 0.2 ≈ 0.3   # true (isapprox, \approx<Tab>)
1 < 2 < 3         # chained comparison: true
2x + 3            # numeric literal coefficient: 2*x + 3
√16, ∛27          # 4.0, 3.0

5.2 Math functions

abs(-3), sqrt(2), cbrt(8), exp(1), log(ℯ), log10(100), log2(8), log(2, 8)
sin(π/2), cos(0), tan(π/4), asin(1), sinpi(0.5), hypot(3, 4)
round(3.14159, digits=2), round(1234, sigdigits=2), floor(2.7), ceil(2.1)
max(1, 5, 3), min(1, 5), minmax(5, 1), clamp(15, 0, 10)
gcd(12, 18), lcm(4, 6), factorial(5), binomial(5, 2), isprime  # isprime: Primes.jl
sign(-3), signbit(-0.0), copysign(1, -2), flipsign(5, -1)
isnan(NaN), isinf(Inf), isfinite(1.0), iseven(4), isodd(3), iszero(0)
real(1+2im), imag(1+2im), abs(3+4im), angle(1im), conj(1+2im)
numerator(3//4), denominator(3//4)
divrem(7, 3)  # (2, 1)

5.3 Numeric type promotion

1 + 2.0          # 3.0 (Int promoted to Float64)
promote(1, 2.5)  # (1.0, 2.5)
promote_type(Int, Float32)   # Float32