Arithmetic Keywords

Arithmetic keywords perform mathematical operations on numbers. Each has both a textual form (readable) and symbolic form (concise).

Keywords

Keyword Symbol Operation
PLUS + Addition
MINUS - Subtraction
TIMES * Multiplication
DIVIDED BY / Division
MODULO None Remainder

PLUS

Adds two numbers.

Syntax

value1 PLUS value2
value1 + value2

Examples

Example file:

-- Arithmetic keyword examples

-- PLUS (Addition)

#EVAL 5 PLUS 3
#EVAL 5 + 3
#EVAL 10.5 + 2.5
#EVAL (-3) + 8

-- MINUS (Subtraction)

#EVAL 10 MINUS 4
#EVAL 10 - 4
#EVAL 5 - 8
#EVAL 0 - 5

-- TIMES (Multiplication)

#EVAL 6 TIMES 7
#EVAL 6 * 7
#EVAL 3.14 * 2
#EVAL (-3) * 4

-- DIVIDED BY (Division)

#EVAL 15 DIVIDED BY 3
#EVAL 15 / 3
#EVAL 10 / 4
#EVAL 7 / 2

-- MODULO (Remainder)

#EVAL 17 MODULO 5
#EVAL 10 MODULO 3
#EVAL 8 MODULO 2

-- Operator Precedence

-- Multiplication before addition
#EVAL 2 + 3 * 4

-- Parentheses override precedence
#EVAL (2 + 3) * 4

-- Division before subtraction
#EVAL 10 - 4 / 2

-- With parentheses
#EVAL (10 - 4) / 2

-- Complex Expressions

-- Circle area: pi * r^2
GIVEN r IS A NUMBER
circleArea r MEANS 3.14159 TIMES r TIMES r

#EVAL circleArea 5

-- Quadratic formula discriminant: b^2 - 4ac
GIVEN a IS A NUMBER
      b IS A NUMBER
      c IS A NUMBER
discriminant a b c MEANS
  b TIMES b MINUS 4 TIMES a TIMES c

#EVAL discriminant 1 5 6

-- Practical Examples

-- Calculate tax
GIVEN price IS A NUMBER
      taxRate IS A NUMBER
calculateTax price taxRate MEANS
  price TIMES taxRate / 100

#EVAL calculateTax 100 8.5

-- Calculate discount
GIVEN originalPrice IS A NUMBER
      discountPercent IS A NUMBER
applyDiscount originalPrice discountPercent MEANS
  originalPrice MINUS (originalPrice TIMES discountPercent / 100)

#EVAL applyDiscount 200 25

-- Combining with Comparisons

ASSUME income IS A NUMBER
ASSUME expenses IS A NUMBER

DECIDE profit IS income MINUS expenses
DECIDE isProfitable IS profit GREATER THAN 0

#CHECK isProfitable
#EVAL 5 PLUS 3        -- 8
#EVAL 5 + 3           -- 8
#EVAL 10.5 + 2.5      -- 13

MINUS

Subtracts the second number from the first.

Syntax

value1 MINUS value2
value1 - value2

Examples

#EVAL 10 MINUS 4      -- 6
#EVAL 10 - 4          -- 6
#EVAL 5 - 8           -- -3

TIMES

Multiplies two numbers.

Syntax

value1 TIMES value2
value1 * value2

Examples

#EVAL 6 TIMES 7       -- 42
#EVAL 6 * 7           -- 42
#EVAL 3.14 * 2        -- 6.28

DIVIDED BY

Divides the first number by the second.

Syntax

value1 DIVIDED BY value2
value1 / value2

Examples

#EVAL 15 DIVIDED BY 3    -- 5
#EVAL 15 / 3             -- 5
#EVAL 10 / 4             -- 2.5 (rational result)

Note: Division returns exact rational numbers, not truncated integers.

MODULO

Returns the remainder after division.

Syntax

value1 MODULO value2

Examples

#EVAL 17 MODULO 5     -- 2
#EVAL 10 MODULO 3     -- 1

Operator Precedence

Standard mathematical precedence:

  1. Parentheses () (highest)
  2. Multiplication, Division, Modulo
  3. Addition, Subtraction (+, -) (lowest)

Examples

#EVAL 2 + 3 * 4        -- 14 (not 20)
#EVAL (2 + 3) * 4      -- 20
#EVAL 10 - 4 / 2       -- 8 (not 3)
#EVAL (10 - 4) / 2     -- 3

Combining with Other Operators

Arithmetic results can be used with comparisons and logic:

ASSUME price IS A NUMBER
ASSUME quantity IS A NUMBER

-- Calculate total and check threshold
DECIDE total IS price TIMES quantity
DECIDE needsApproval IS total GREATER THAN 10000

Math Library Functions

For advanced operations, import the math library:

IMPORT math

#EVAL sqrt 16          -- 4
#EVAL exp 1            -- 2.718...

See Libraries Reference for more functions.

  • COMPARISONS - Compare arithmetic results
  • IF - Conditional arithmetic

See Also