Chapter 12 of 14

Mathematics

Creole supports readable calculations and compact math operations. Use the form that makes the work easiest to understand.

Basic calculations

Set total to 10 plus 5.
Set difference to 20 minus 8.
Set area to 4 times 8.
Set half to 20 divided by 2.
Set left to 17 remainder of 5.

Save important results under descriptive names.

Powers and roots

Set power to 2 to the power of 8.
Set root to square root of 144.

Percentages

Set discount to 15 percent of 240.
Set tax to 5 percent of 100.

Keep the original value when it is still needed:

Set price to 240.
Set discount to 15 percent of price.
Set final_price to price minus discount.

Round a result

Set neat to 3.14159 rounded to 2 decimal places.
Show neat.

Round for display when needed. Keep the unrounded value for later calculations when accuracy matters.

Compact math

Compact operations begin with a dot and use & between inputs:

.add 1 & 2 as total.
.mul 2 & 3 & 4 as product.
.avg 10 & 20 & 30 as mean.
.round 3.14159 & 2 as neat.

Use compact math when it is clearer than a long sentence. It does not introduce another source format; it is native Creole syntax inside .crlo files.

Choose readable names

Set width to 12.
Set height to 8.
Set area to width times height.
Show area.

Names such as area, price, and average teach the reader what the result means.

Check difficult inputs

Think about:

  • division by zero
  • negative inputs
  • very large numbers
  • decimal rounding
  • missing values

Test calculations with normal values and edge cases.

Learning checklist

  • I can add, subtract, multiply, and divide.
  • I can calculate powers, roots, and percentages.
  • I can round a number.
  • I can use leading-dot compact math.
  • I use & between compact inputs.
  • My result names explain their meaning.

Next step

Continue to Checking programs to find problems before code runs and keep projects reliable.