#!/bin/sh -eu

echo "1 =" $((1))
echo "2*5 =" $((2*5))
echo "2/5 =" $((2/5))
echo "2%5 =" $((2%5))
echo "2+5 =" $((2+5))
echo "2-5 =" $((2-5))
echo "2<<5 =" $((2<<5))
echo "2>>5 =" $((2>>5))
echo "2<5 =" $((2<5))
echo "2<=5 =" $((2<=5))
echo "2>5 =" $((2>5))
echo "2>=5 =" $((2>=5))
echo "2==5 =" $((2==5))
echo "2!=5 =" $((2!=5))
echo "2&5 =" $((2&5))
echo "2^5 =" $((2^5))
echo "2|5 =" $((2|5))
echo "2&&5 =" $((2&&5))
echo "2||5 =" $((2||5))

# Associativity
echo "1+2+3 =" $((1+2+3))
echo "5-1-2 =" $((5-1-2))
echo "1+2*3 =" $((1+2*3))
echo "2*3+1 =" $((2*3+1))
echo "6/3/2 =" $((6/3/2))
echo "2*(3+1) =" $((2*(3+1)))
echo "2*(3+1)+1 =" $((2*(3+1)+1))
echo "1+(1+(1+1))+1 =" $((1+(1+(1+1))+1))
echo "2|(1||1)" $((2|(1||1))) # 3
echo "(2|1)||1" $(((2|1)||1)) # 1
echo "2|1||1" $((2|1||1)) # 1
echo "1||1|2" $((1||1|2)) # 1

# Variables
a=42
echo "a =" $((a))
echo "a+2 =" $((a+2))
echo "2*a-10 =" $((2*a-10))
echo "\$a =" $(($a))
echo "\$a+2 =" $(($a+2))

# Assignments
a=0
echo "(a=42) =" $((a=42)) "->" $a
echo "(a+=1) =" $((a+=1)) "->" $a
echo "(a-=4) =" $((a-=4)) "->" $a
echo "(a*=9) =" $((a*=9)) "->" $a
echo "(a/=3) =" $((a/=3)) "->" $a
