Topic: DMD0098

Help File Version: 2.9.4.37

MATH Multiply Operator


The Math Multiply operator ( * ) will calculate the product of two or more numbers or expressions by multiplying the value on the left side with the value on the right side.

 

The numbers and expressions can be any mix of signed integers, unsigned integers, real (floating point) numbers or discrete values. They can be any numeric or discrete memory location or any numeric or discrete structure member.

 

All discrete and 16-bit integer values are promoted to 32-bit 2's complement signed integer values. If a Real value is included in the equation then all of the values will be promoted to Real values and all calculations will be performed using Real numbers.

 

Refer to the examples below for caveats when using numbers of different types:

 

 

Signed Integers: assume D1 = 100 and D2 = 24

 

D0 = D1 * D2

D0 = 100 * 24
D0 = 2400

 

Both values are integer memory locations.

 

The result is placed in an integer memory location.

 

D0 = D1 * D2 * 251

D0 = 100 * 24 * 251
D0 = 602400
 

Two values are memory locations, the third is an integer constant.

 

The result is placed in an integer memory location.

 

 

Mixing Signed Integers and Floating Point values: assume D1 = 100 and R1 = 2.51

 

D0 = D1 * R1

D0 = 100 * 2.51

D0 = 251
 

One value is an integer memory location, the other is a Real memory location.

 

D1 will be promoted to a Real number then multiplied by R1.

 

The result is placed in an integer which WILL NOT retain the portion after the decimal point.
 

R0 = D1 * R1

R0 = 100 * 2.51

R0 = 251.00
 

One value is a memory location, the other is a Real memory location.

 

D1 will be promoted to a Real number then multiplied by R1.

 

The result is placed in a floating point memory location which WILL retain the portion after the decimal point.
 

 

Mixing 32-bit Integers and 16-bit Integers: assume D3 = 2

 

D0 = D3 * 32768

D0 = 2 * 32768

D0 = 65536

 

One value is a memory location, the other is an integer constant.

 

The result is stored in a 32-bit Signed memory location.

 

V0 = D3 * 32768

V0 = 2 * 32768
V0 = 0

 

One value is a memory location, the other is an integer constant.

 

The result is stored in a 16-bit Unsigned memory location.

 

A 16-bit Unsigned memory location can stored values from 0 to 65535. The value of 65536 CAN NOT be stored in a 16-bit location, only the lowest 16 bits of the result will be stored in the Unsigned memory location.

 

N0 = D3 * 32767

N0 = 2 * 32767

N0 = -2

 

One value is a memory location, the other is an integer constant.

 

The result is 65534, but will be stored in a 16-bit Signed memory location.

 

A 16-bit Signed memory location stores 2's-complement values from -32768 to 32767. The result's value of 65534 in 16-bit, 2's complement form is -2.

 

 

Numeric Structure Members: assume D1 = 1000 and Timer T0.Acc = 567ms

 

D0 = D1 * T0.Acc

 

D0 = 1000 * 567

D0 = 567000

 

One value is a memory location, the other is a structure member.

 

The .Acc member of a Timer structure contains the amount of time in milliseconds that has accumulated in a Timer.

 

The result is placed in an integer memory location.
 

 

Discrete memory locations: assume D1 = 1000 and X0 is OFF

 

D0 = D1 * X0

D0 = 1000 * 0

D0 = 0
 

One value is a memory location, the other is a discrete input.

 

The result is placed in an integer memory location.
 

A discrete location will have a value of 0 if the status of that location is OFF.

A discrete location will have a value of 1 if the status of that location is ON.

 

 

Casting Numeric Values: assume R1 = 2.51, and DLV2000 and DLV2001 as a 32-bit Real = 1234.56

 

R0 = R1 * DLV2000:RD

 

R0 = 2.51 * 1234.56

R0 = 3098.75

 

One value is a floating point memory location, the other is using the 'Real and DWord' cast operators.

 

The result is placed in a floating point memory location.

 

DLV memory locations are 16-bit Unsigned used by external DirectLOGIC devices. In this example a remote DirectLOGIC CPU has written a 32-bit floating point value into two successive DLV memory locations. Using the :RD cast operator will interpret the 32-bit value in DLV2000 and DLV2001 as a REAL number.

 

 


See Also:

Add

Subtract

Multiply

Divide

 

Modulus / Remainder

Raise to a Power

 

Less Than

Less than or Equal To

 

Equal To

Not Equal To

 

Greater Than

Greater Than or Equal To

 

Logical AND

Logical OR

 

Bit-wise AND

Bit-wise OR

Bit-wise XOR

 

Shift Left

Shift Right

Unsigned Shift Right

 

Negate

Bit-wise Invert

Logical NOT

 


Related Topics:

MATH - Calculate Expression