Language Reference/Built-in entities/Operators
From wiki.visual-prolog.com
< Language Reference | Built-in entities
Revision as of 01:28, 17 February 2019 by Thomas Linder Puls (talk | contribs) (integral division round => truncates)
See also Operators.
Operator | Description | Remark |
---|---|---|
^ | Power operation | Not defined for 64 bit integral numbers |
- (unary) | Unary minus | |
*, / | Multiplication and division | |
div, mod | The quotient and remainder of an integral division rounded towards minus infinity | Not defined for real's |
quot, rem | The quotient and remainder of an integral division rounded towards zero | Not defined for real's |
+, - | Addition and subtraction | |
otherwise | Otherwise expression |
- The operators are listed from highest to lowest precedence
- All division and multiplication operators have same precedence.
- The the power operator is right associative
- All other operators are left associative.
All binary operators takes two arguments of same base type and returns a value of that base type. Operands and result may be converted using ordinary subtype rules.
Integral division
div and quot are different integral division operators.
- div truncates towards minus infinite. mod is the remainder corresponding to div.
- quot truncates towards zero. rem is the remainder corresponding to quot.
For positive results div and quot have same functionality.
The difference can be seen in this table:
A | B | A div B | A mod B | A quot B | A rem B |
15 | 7 | 2 | 1 | 2 | 1 |
-15 | 7 | -3 | 6 | -2 | -1 |
15 | -7 | -3 | -6 | -2 | 1 |
-15 | -7 | 2 | -1 | 2 | -1 |