Skip to content

Arithmetic expressions¤

Overview¤

Arithmetic expressions are used for basic arithmetic operations with data.

  • !ADD: Addition.
  • !SUB: Subtraction.
  • !MUL: Multiplication.
  • !DIV: Division.
  • !MOD: Modulo (remainder after division).
  • !POW: Exponentiation.
  • !ABS: Absolute value.

!ADD¤

Type: Sequence

You can add following types:

  • Numbers (Integers and floats)
  • Strings
  • Lists
  • Sets
  • Tuples
  • Records

Example

!ADD
- 4
- -5
- 6

Calculates 4+(-5)+6, the result is 5.


!SUB¤

Type: Sequence

Example

!SUB
- 3
- 1
- -5

Calculates 3-1-(-5), the result is 7.


!MUL¤

Type: Sequence

Example

!MUL
- 7
- 11
- 13

Calculates 7*11*13, the result is 1001 (which happens to be the Scheherazade constant).


!DIV¤

Type: Sequence

Example

!DIV
- 21
- 1.5

Calculates 21/5, the result is 14.0.

Division by zero¤

Division by zero produces the error, which can cascade thru the expression.

!TRY expression can be used to handle this situation. The first item in !TRY is a !DIV that can produce division by zero error. The second item is a value that will be returned when such an error occurs.

!TRY
- !DIV
  - !ARG input
  - 0.0
- 5.0

!MOD¤

Type: Sequence

Calculate the signed remainder of a division (aka modulo operation).

Info

Read more about modulo on Wikipedia.

Example

!MOD
- 21
- 4

Calculates 21 mod 4, the result is 1.

Example

!MOD
- -10
- 3

Calculates -10 mod 3, the result is 2.


!POW¤

Type: Sequence

Calculate the exponent.

Example

!POW
- 2
- 8

Calculates 2^8, the result is 16.


!ABS¤

Type: Mapping

!ABS
what: <x>

Calculate the absolute value of input x, which is the non-negative value of x without regard to its sign.

Example

!ABS
what: -8.5

The result is a value 8.5.