Skip to content

Numbers and Math

Hedge Fleming edited this page Sep 15, 2022 · 2 revisions

Floats or integers?

In MochaScript, numbers are represented as floats. There is no native integer type. Whole numbers' repr() method chops off the '.0' at the end for a nicer string representation.

MochaScript's mathematical expressions look just like any others. Here are the math operators:

  • +: Addition
  • -: Subtraction
  • *: Multiplication
  • /: Division
  • %: Modulus
  • **: Exponentiation

Here are some examples of MochaScript's math:

>>> 1 + 1
2
>>> 4 - 3
1
>>> 9 * 10
90
>>> 5 / 2
2.5
>>> 6 % 3
0
>>> 2 ** 3
8
Clone this wiki locally