Difference between revisions of "Language Reference/Built-in entities/Operators"
From wiki.visual-prolog.com
m (1 revision(s)) |
m (spell & grammar) |
||
Line 19: | Line 19: | ||
| <vp>div</vp>, <vp>mod</vp> | | <vp>div</vp>, <vp>mod</vp> | ||
| The quotient and remainder of an integral division rounded towards minus infinity | | The quotient and remainder of an integral division rounded towards minus infinity | ||
| Not defined for | | Not defined for real's | ||
|- | |- | ||
| <vp>quot</vp>, <vp>rem</vp> | | <vp>quot</vp>, <vp>rem</vp> | ||
| The quotient and remainder of an integral division rounded towards zero | | The quotient and remainder of an integral division rounded towards zero | ||
| Not defined for | | Not defined for real's | ||
|- | |- | ||
| <vp>+</vp>, <vp>-</vp> | | <vp>+</vp>, <vp>-</vp> |
Revision as of 12:49, 21 October 2008
Operator | Description | Remark |
---|---|---|
- (unary) | Unary minus | |
^ | Power operation | Not defined for 64 bit integral numbers |
*, / | 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 |
- 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 for positive results they work the same, but if the result is negative div rounds towards minus infinitive, while quot rounds towards zero.
mod is the remainder corresponding to div, and rem is the remainder corresponding to quot.
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 |