Topic: DMD0196

Help File Version: 2.10.0.636

Math Not Equal Operator


 

The Math Not Equal operator ( != ) will determine if the number or expression on the left side of the operator is not equal to the number or expression on the right side of the operator. The result will be a value of 1 if the values are Not Equal or a value of 0 if the values are Equal. The result can be placed in any writable discrete memory location or any writable numeric location.

 

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.

 

Signed Integers: assume D1 = 1000 and D2 = 1024

 

C0 = D1 != D2

C0 = (1000 != 1024)
C0 = ON

 

Both values are integer memory locations.

 

The result is placed in a discrete memory location.

 

D0 = D1 != 1000

D0 = (1000 != 1000)
D0 = 0
 

The left side value is an integer memory location, the right side value is an integer constant.

 

The result is placed in an integer memory location.

 

 

Using Real Values

 

C0 = ((1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0) + (1.0 / 10.0)) != 1.0

 

C0 = (1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001 + 1.00000e-001) == 1.0

C0 = 1.0000001E+000 == 1.0

C0 = ON

 

Both values are floating point constants

 

The result is placed in a discrete memory location.

 

When doing math calculations using very small Real numbers or very large Real numbers be aware that approximate results from the calculations may not generate the desired result. In this example, adding ten instances of (1.0 / 10.0) does not yield exactly 1.0, it yields approximately 10.0000001e+000 (when viewed in exponent form). So the Not Equal To comparison will pass.

 

 

 

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

 

C0 = D1 != T0.Acc

 

C0 = (1000 != 567)

C0 = ON

 

One value is an integer 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 a discrete memory location.
 

 

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

 

C0 = R1 != DLV2000:RD

 

C0 = (2.51 != 1234.56)

C0 = ON

 

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

 

The result is placed in a discrete 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