Chaining works with elementwise comparison.
Operators can be referenced as values by preceding them with a : .
To convert floats to integers without throwing, use round(), ceil(), floor(), or trunc() . These can be passed a value: round(1.2), or a type and then a value: round(UInt8, 1.2).
fld(x,y) floored division; quotient rounded towards -Inf
cld(x,y) ceiling division; quotient rounded towards +Inf
rem(x,y) remainder; satisfies x == div(x,y)*y + rem(x,y); sign matches x
mod(x,y) modulus; satisfies x == fld(x,y)*y + mod(x,y); sign matches y
mod1(x,y) mod with offset 1; returns r∈(0,y] for y>0 or r∈[y,0) for y<0, where mod(r, y) == mod(x, y)
mod2pi(x) modulus with respect to 2pi; 0 <= mod2pi(x) < 2pi
divrem(x,y) returns (div(x,y),rem(x,y))
fldmod(x,y) returns (fld(x,y),mod(x,y))
gcd(x,y...) greatest positive common divisor of x, y,...
lcm(x,y...) least positive common multiple of x, y,...
Sign and absolute value functions
Function Description
abs(x) a positive value with the magnitude of x
abs2(x) the squared magnitude of x
sign(x) indicates the sign of x, returning -1, 0, or +1
signbit(x) indicates whether the sign bit is on (true) or off (false)
copysign(x,y) a value with the magnitude of x and the sign of y
flipsign(x,y) a value with the magnitude of x and the sign of x*y
Powers, logs and roots
Function Description
sqrt(x), √x square root of x
cbrt(x), ∛x cube root of x
hypot(x,y) hypotenuse of right-angled triangle with other sides of length x and y
exp(x) natural exponential function at x
expm1(x) accurate exp(x)-1 for x near zero
ldexp(x,n) x*2^n computed efficiently for integer values of n
log(x) natural logarithm of x
log(b,x) base b logarithm of x
log2(x) base 2 logarithm of x
log10(x) base 10 logarithm of x
log1p(x) accurate log(1+x) for x near zero
exponent(x) binary exponent of x
significand(x) binary significand (a.k.a. mantissa) of a floating-point number x
sin cos tan cot sec csc
sinh cosh tanh coth sech csch
asin acos atan acot asec acsc
asinh acosh atanh acoth asech acsch
sinc cosc
, with atan also accepting two arguments corresponding to a traditional atan2 function.
sinpi(x) and cospi(x) are provided for more accurate computations of sin(pi*x) and cos(pi*x) respectively.
In order to compute trigonometric functions with degrees instead of radians, suffix the function with d.
sind cosd tand cotd secd cscd
asind acosd atand acotd asecd acscd
More functions:
Homework: Write a julia script that produces a 2x2 matrix containing pixels for a raytraced sphere.