Quatsch Reference

Basic


operator operation example
+ addition (+ 1 2) // == 3
- subtraction (- 1 2) // == -1
* multiplication (* 1 2 3) // == 6
/ division (/ 10 2 2) // == 2.5
^ power (^ 2 2) // == 4
sqrt square root (sqrt 4) // == 2
min minimum (min 2 4 3 0.5) // == 0.5
max maximum (max 2 4 3 0.5) // == 4
lerp linear interpolation (lerp x 0 2 0) // == 0 for x=0, 2 for x==0.5, 0 for x==1
log logarithm (log x)
log10 logarithm to base 10 (log10 x)
exp exponential function (exp x)


Predicates (Comparison)


operator operation example remarks
< less (< x y 2) // == 1 when x<y and y<2, 0 otherwise
<= less-equal (<= x y 2) // == 1 when x<=y and y<=2, 0 otherwise
> greater (> x y 2) // == 1 when x>y and y>2, 0 otherwise
>= greater-equal (>= x y 2) // == 1 when x>=y and y>=2, 0 otherwise
= equal (= x y 2) // == 1 when x=y and y=2, 0 otherwise Discouraged for floating point values
!= not equal (!= x y 2) // == 1 when x<>y and y<>2, 0 otherwise Discouraged for floating point values


Range-Predicates


operator operation example
[] inclusive range ([] 0 1 x) // 1 if x>=0 and x<=1, 0 otherwise
[[ inclusive/exclusive range ([[ 0 1 x) // 1 if x>=0 and x<1, 0 otherwise
][ exclusive range (][ 0 1 x) // 1 if x>0 and x<1, 0 otherwise
]] exclusive/inclusive range (]] 0 1 x) // 1 if x>0 and x<=1, 0 otherwise

Predicate Combiners


operator operation example remarks
and logical and (and (< x 0) (> x -1)) // 1 if x<0 and x>-1, 0 otherwise
or logical or (or (> x 0) (< x -1)) // 1 if x>0 or x<-1, 0 otherwise
xor logical xor (xor (> x y) (< x -1)) // 1 if only one of the operands is true works with two parameters only (that's a quirk in the design of this instruction)
not logical not (not (> x 0)) // 0 if (> x 0), 0 otherwise

Trigonometric Functions


operator operation example
sin sine (sin x)
cos cosine (cos x)

Other Functions


operator operation example remarks
inv inverse (inv x) // == (/ 1 x)
floor floor (floor 2.5) // == 2
trunc truncation (trunc -7.5) // == -7 for positive numbers, this is the same as floor; see also Wikipedia on truncation(external link) and examples on Wikipedia(external link)
abs absolute (abs -7) // == 7
frac fractional part (frac 3.123) // == 0.123 see also wikipedia(external link)
neg negation (neg 4) // == -4

Control Flow


operator syntax operation example
if (if #condition #then #else) If-Then/Else (if 1 (+10 10) 101) // == 20