OPERATORS 1g 2023-05-05 laplante@plcb.ca GOWEB/Language

– title: “Operators” author: “Pierre Laplante laplante@plcb.ca” date: “2023-05-05” version: “1.0.0” section: “1g”

category: “GOWEB”/Language

Description

The following operators exist in goweb:

  1. + : if both operands are strings, they will be concatenated.
  2. -
  3. *
  4. /
  5. %!<(MISSING)/code> (modulo)
  6. ** (power) — always returns a float.
  7. - (unary minus)
  8. ( ... ) — parentheses to enforce operator precedence.

Operator Precedence

The order of operators in goweb is:

  1. +, -
  2. *, /
  3. %!<(MISSING)/code>, **
  4. Unary -

For example:

1 + 2 * 3 ** 4

Output:

163

Parentheses can be used to explicitly enforce operator precedence.

For the modulo operator %!<(MISSING)/code>, if one operand is a float, it returns the floating-point remainder of x / y.
The magnitude of the result is less than y and its sign matches that of x.

Examples

Modulo

res={{
    5 %!;(MISSING)
    5.2 %!;(MISSING)
}}.

Output:

res=1
0.7999999999999998

Power

res={{
    0 ** 0; "\n";
    2 ** 5; "\n";
    2 ** -5; "\n";
}}.

Output:

1
32
0.03125

Addition

res={{
    5 + 7; "\n";
    5 + 7.2; "\n";
    5 + "7.3"; "\n";
}}.

Output:

12
12.2
12.3

Subtraction

res={{
    5 - 7; "\n";
    5 - 7.2; "\n";
    5 - "7.3"; "\n";
}}.

Output:

-2
-2.2
-2.3

Multiplication

res={{
    5 * 7; "\n";
    5 * 7.2; "\n";
    5 * "7.3"; "\n";
}}.

Output:

35
36
36.5

Division

res={{
    14 / 7; "\n";
    5 / 7.2; "\n";
    5 / "7.3"; "\n";
}}.

Output:

2
0.6944444444444444
0.684931506849315

Division by zero

res={{
    7.3 / 0.0; "\n";
}}.

Output:

*division by zero.*

See also

Version

  • 1.0.0 — 2023-05-05 — Initial version by laplante@plcb.ca