Arithmetic ∞
Earlier examples which just passed constants had no parentheses, but when “doing stuff” for the printf, parentheses are required.
printf "%d" ( 1 + 2 ); # => # 3
You can also use named values (see Mythryl tutorial, naming values).
a = 2; b = 4; printf "%d" ( a + b ); # => # 6
Aside from + for addition, other possibilities are:
-(dash) – subtration/(slash) – division-
*(asterisk) – multiplication
Floating point arithmetic ∞
A floating point number is something like 1.02.
Be careful with floating point arithmetic. What a computer or calculator shows you is not necessarily the correct answer.
Mythryl uses double-precision floats almost everywhere, so you should have something like twelve significant digits.
In my case, I get six displayed digits. Perhaps this is a compiler default on my particular computer. Note that what is displayed is not necessarily what is accurate, and what is displayed is not necessarily significant.
Paraphrased from Cynbe’s explanation:
Don’t confuse the number of places printed by default with the number computed internally. One of the first things we teach students in physics is to keep track of how many digits of a result are meaningful.
printf "%g" ( 1.12 * 2.09 ); # => # 2.3408.. but any student who turns that in flunks — the real answer is
2.34because everything beyond three places is meaningless junk —you cannot have more significant digits out than you put in.
“Adding” Strings ∞
printf "%s" ( "abc" + "def" ); # => # abcdef
All the usual variations will work the way you’d expect.
a = ( "abc" + "def" ); printf "%s" a; # => # abcdef
.. or:
a = "abc"; b = "def"; printf "%s" ( a + b ); # => # abcdef
