Back to Syllabus
Chapter 02AAYU Core - Verified

Numbers and arithmetic

Use integer and floating point literals with addition, subtraction, multiplication, and division.

This lesson uses the verified core subset and links to a checked-in regression program. Its output is covered by the repository test harness. This does not imply support for features outside the lesson; see known limitations.

What you'll learn

✓Write integer and decimal literals
✓Combine arithmetic operators
✓Store an expression in a variable
✓Check numeric output

Arithmetic expressions

The checked numeric example exercises decimal literals, multiplication, division, and subtraction.

aayu
let pi = 3.14159
let radius = 10.0
let area = pi * radius * radius
print(area)

Multiplication is evaluated before addition/subtraction. The complete test also prints '180.0 / 2.0' and '180.0 - 30.0'; its expected values are 314.159, 90, and 150.

Run 'bin/aayu-vm tests/test_02_floats.aayu'.

Try It Yourself! 🚀

Change the radius to 2.0. Work out the expected area first, run the program, and compare. Then change one operator and explain the difference.