Originale-mail to me for new edition

 

Arithmetic operators

 

Arithmetic operators, which take real or integer operands, include +, -, *, /, div, and mod.

 

Operator

Operation

Operand types

Result type

Example

+

addition

integer, real

integer, real

X + Y

-

subtraction

integer, real

integer, real

Result - 1

*

multiplication

integer, real

integer, real

P * InterestRate

/

real division

integer, real

real

X / 2

div

integer division

integer

integer

Total div UnitSize

mod

remainder

integer

integer

Y mod 6

 

Operator

Operation

Operand types

Result type

Example

+(unary)

sign identity

integer, real

integer, real

+7

-(unary)

sign negation

integer, real

integer, real

-X

 

The following rules apply to arithmetic operators.

·  The value of x/y is of type Extended, regardless of the types of x and y. For other arithmetic operators, the result is of type Extended whenever at least one operand is a real; otherwise, the result is of type Int64 when at least one operand is of type Int64; otherwise, the result is of type Integer. If an operand’s type is a subrange of an integer type, it is treated as if it were of the integer type.

·  The value of x div y is the value of x/y rounded in the direction of zero to the nearest integer.

·  The mod operator returns the remainder obtained by dividing its operands. In other words, x mod y = x - (x div y) * y.

·  A runtime error occurs when y is zero in an expression of the form x/y, x div y, or x mod y.

 

Topic groups

 

See also

About operators

Operator precedence rules

 

 

译文

 

算术运算符

 

算术运算符接受实数或整数作为操作数。算术运算符包括+, -, *, /, div, mod

 

运算符

操作

操作数

结果类型

范例

+

整数,实数

整数,实数

X + Y

-

整数,实数

整数,实数

Result - 1

*

整数,实数

整数,实数

P * InterestRate

/

实数除

整数,实数

实数

X / 2

div

整数除

整数

整数

Total div UnitSize

mod

取模

整数

整数

Y mod 6

 

运算符

操作

操作数

结果类型

范例

+(一元)

符号等同

整数,实数

整数,实数

+7

-(一元)

符号相反

整数,实数

整数,实数

-X

 

下列规则对算术运算符试用:

·  表达式 x/y 的值始终是Extended类型,而不管 x y 是何类型。对于其他算术运算符,只要至少其中一个操作数是实数,其运算结果就是Extended类型;否则,其中一个操作数是Int64类型,其运算结果是Int64类型;否则运算结果是Integer类型。如果一个操作数的类型是整数类型的子界,那么它将被视为整数类型。

·  表达式 x div y 的值是表达式 x/y 的值向零取整(即从该值到零方向的第一个整数)。

·  mod 运算符返回操作数整除的余数。也就是说,x mod y = x - (x div y) * y

·  对于表达式x/yx div yx mod y,当 y 为零时将发生运行时错误。

 

主题组

 

相关主题

运算符

运算符优先规则