Difference between revisions of "Language Reference/Built-in entities/Operators"

From wiki.visual-prolog.com
m (1 revision(s))
m (duplicated word)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
See also {{lang2|Terms|Operators|Operators}}.
{|{{prettytable}}
{|{{prettytable}}
|-
|-
Line 4: Line 6:
! Description
! Description
! Remark
! Remark
|-
| <vp>^</vp>
| Power operation
| Not defined for 64 bit integral numbers
|-
|-
| <vp>-</vp> (unary)
| <vp>-</vp> (unary)
| Unary minus
| Unary minus
|
|
|-
| <vp>^</vp>
| Power operation
| Not defined for 64 bit integral numbers
|-
|-
| <vp>*</vp>, <vp>/</vp>
| <vp>*</vp>, <vp>/</vp>
Line 19: Line 21:
| <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 reals
| 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 reals
| Not defined for real's
|-
|-
| <vp>+</vp>, <vp>-</vp>
| <vp>+</vp>, <vp>-</vp>
| Addition and subtraction
| Addition and subtraction
|
|-
| <vp>otherwise</vp>
| Otherwise expression
|
|
|}
|}
Line 32: Line 38:
* The operators are listed from highest to lowest precedence
* The operators are listed from highest to lowest precedence
* All division and multiplication operators have same precedence.
* All division and multiplication operators have same precedence.
* The the power operator is right associative
* The power operator <vp>^</vp> and <vp>otherwise</vp> are right associative.
* All other operators are left associative.
* All other operators are left associative.


Line 39: Line 45:
==== Integral division ====
==== Integral division ====


<vp>div</vp> and <vp>quot</vp> for positive results they work the same, but if the result is negative <vp>div</vp> rounds towards minus infinitive, while <vp>quot</vp> rounds towards zero.
<vp>div</vp> and <vp>quot</vp> are different integral division operators.
 
* <vp>div</vp> truncates towards minus infinite. <vp>mod</vp> is the remainder corresponding to <vp>div</vp>.
* <vp>quot</vp> truncates towards zero. <vp>rem</vp> is the remainder corresponding to <vp>quot</vp>.
 
For positive results <vp>div</vp> and <vp>quot</vp> have same functionality.


<vp>mod</vp> is the remainder corresponding to <vp>div</vp>, and <vp>rem</vp> is the remainder corresponding to <vp>quot</vp>.
The difference can be seen in this table:


{|border="2" cellspacing="0" cellpadding="5" rules="all" style="border:solid 1px #AAAAAA; border-collapse:collapse; empty-cells:show; text-align: center;"
{|border="2" cellspacing="0" cellpadding="5" rules="all" style="border:solid 1px #AAAAAA; border-collapse:collapse; empty-cells:show; text-align: center;"
Line 80: Line 91:
| <vp>-1</vp>
| <vp>-1</vp>
|}
|}
<noinclude>{{LanguageReferenceSubarticle|Built-in entities/Operators}}</noinclude>

Latest revision as of 12:07, 4 August 2020

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 power operator ^ and otherwise are 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