Operators: -

Minus operator.

Syntax

Unary form:

-integer‑operandor-float‑operandor-point‑operand

Binary form:

integer‑operand-integer‑operand

float‑operand-float‑operand

float‑operand-integer‑operandorinteger‑operand-float‑operand

point‑operand-point‑operand

rect‑operand-point‑operand

color‑operand-color‑operand

char‑operand-char‑operand

char‑operand-integer‑operandorinteger‑operand-char‑operand

styles‑operand-styles‑operand

user‑defined‑set‑operand-user‑defined‑set‑operand

Unary negative prefix

In its first, unary version the - operator expects one signed integer, unsigned integer, floating-point or point operand and results in the value of this operand with its sign inverted. Precisely, an operand with a positive value will become negative and a negative operand will become positive.

Applied on a signed int8, int16, int32 or unsigned uint8, uint16 integer operand, the operation always results in an int32 value. If the operand is int64, the operation results consequently in int64. Exceptions occur in context of uint32 or uint64 operands. In this case the resulting data type will remain unchanged unsigned uint32 or uint64 and an adequate warning is reported. Applied on a floating-point operand, the operation always results in a float value. Finally, when applied on a point operand, the operation results in a point value. Please note, performing the operation on a point operand, negates the x and y point elements individually. For example:

var float a = -1369.1251; var uint32 b = 4032; var uint64 c = 15746432301; var point d = <100,-200>; var float result = -a; // result = 1369.1251 var int32 result = -b; // result = -4032 var int64 result = -c; // result = -15746432301 var point result = -d; // result = <-100,200>

Integer subtraction

In its second version, the - operator calculates an arithmetic difference between the left and the right operand. If used in combination with 8-, 16- or 32-bit signed integer operands, the data type resulting from the operation is consequently int32. When mixing signed and unsigned integer operands, the operation results in the unsigned uint32 value. In the case, one of the operands is 64-bit large, the resulting data type is int64 or uint64 according to whether the 64-bit operand is signed or unsigned. For example:

var int32 a = 1369; var int32 b = -1496; var uint32 c = 1369; var uint32 d = 1251; var uint64 e = 897546641189; var int64 f = -149613691251; var int32 result = a - b; // result = 2865 var uint32 result = c - d; // result = 118 var uint32 result = b - d; // result = 0xFFFFF545 var int64 result = f - c; // result = -149613692620 var uint64 result = e - a; // result = 897546639820

Floating point subtraction

In its third version, the - operator calculates an arithmetic difference between the left and the right floating-point operand. If used in combination with a signed or unsigned integer operand, the integer operand is automatically converted to float before performing the subtraction. The resulting data type of the operation is always a float. For example:

var float a = 1369.1251; var float b = -1496.158; var int32 c = 260; var float result = a - b; // result = 2865.283203 var float result = b - c; // result = -1756.157958

Point subtraction

In its fourth version, the - operator calculates an arithmetic difference between the left and the right point operand. The operation is performed individually for the x and y point elements. The subtraction of two point operands can be considered as a translation of the point in the left operand by a negative offset specified in the right operand. The resulting data type of the operation is always a point. For example:

var point a = <100,200>; var point b = <50,70>; var point result = a - b; // result = <50,130>

Rectangle negative displacement

In its fifth version, the - operator translates the left rectangle operand by an offset specified in the right point operand. During the operation, the x and y point elements are subtracted from the corresponding coordinates of the rectangle's top-left and bottom-right corners. The resulting data type of the operation is always a rect. For example:

var rect a = <100,200,110,220>; var point b = <50,70>; var rect result = a - b; // result = <50,130,60,150> var rect result = b - a; // This operand combination is not allowed. Chora error

Color subtraction with saturation

In its sixth version, the - operator calculates an arithmetic difference between the left and the right color operand. The operation is performed individually for every red, green, blue and alpha color components by respecting the lower limit of the value range 0 .. 255. The resulting data type of the operation is always a color. For example:

var color a = #10C050FF; var color b = #225F2200; var color result = a - b; // result = #00612EFF

Char subtraction

In its seventh version, the - operator calculates an arithmetic difference between the codes of the left and the right character operand. Please note, in Chora all characters are handled as 16-bit UNICODE entities - they are represented as 16-bit UNICODE numbers. The resulting data type of the operation is always a int32. For example:

var char a = 'D'; var char b = 'A'; var int32 result = a - b; // result = 3

Char integer subtraction

In its eighth version, the - operator performs an arithmetic difference between a signed or unsigned integer value and the character code stored in a char operand. The result of the operation is again char value. In this way, it is possible to calculate new character codes from given character code and an offset. For example:

var char c = 'a'; var char result = c - 32; // result = 'A'

Styles difference

In its ninth version, the - operator determines the difference between the left and the right styles operand. Please note, styles operands can be considered as collections containing multiple elements you can individually include or exclude. Thus, the - operation results in a new styles value including all elements available in the left but not in the right operand. The resulting data type of the operation is always styles. For example:

var styles a = [ Style1, Style3, Style16 ]; var styles b = [ Style3, Style16 ]; var styles c = [ Style1, Style8 ]; var styles result = a - b; // result = [ Style1 ] var styles result = b - c; // result = [ Style3, Style16 ]

Set difference

In its tenth version, the - operator determines the difference between the left and the right user-defined set operand. Please note, set operands can be considered as collections containing multiple elements you can individually include or exclude. Thus, the - operation results in a new set value including all elements available in the left but not in the right operand. The resulting data type of the operation corresponds to the data type of the operands. For example:

var Core::Layout a = Core::Layout[ AlignToTop, ResizeHorz ]; var Core::Layout b = Core::Layout[ ResizeHorz ]; var Core::Layout c = Core::Layout[ AlignToTop, ResizeHorz ]; var Core::Layout result = a - b; // result = Core::Layout[ AlignToTop ] var Core::Layout result = b - c; // result = Core::Layout[]