15 Floating calculation

Last modified by Wecon on 2025/09/03 21:03

6.15.1 DECMP instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DECMPCompares two floating point values - results of <, = and > are given32NoDECM S1 S2 D13
DECMPP32Yes13

The data of S1 is compared to the data of S2. The result is indicated by 3 bit devices specified with the head address entered as D. The bit devices indicate:

  • S2 is less than < S1 - bit device D is ON
  • S2 is equal to = S1 - bit device D +1 is ON
  • S2 is greater than > S1 - bit device D+2 is ON
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
D             

Program example

7-14 Floating calculation_html_59dd4b117c854f2c.jpg

  • When X10 is ON, one of M10~M12 will be on.
  • When X10 turns from ON to OFF, DECP is not executed. M10~M12 keep the initial value. User could use RST or ZRST to reset M10~M12.
  • If S1 and S2 are not floating number, they will be converted into floating number automatically.

6.15.2 DEZCP instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEZCPCompares a float range with a float value.32NoDECM S1 S2 S D9
DEZCPP32Yes17

The instruction compares the inter-zoning variables of binary floating-points, and then exports the result to the three (3) initiative variables

  • S1: the inter-zoning minimum of the binary floating-point variables.
  • S2: the inter-zoning maximum of the binary floating-point variables.
  • S: the binary floating-point variable that is to be compared.
  • D: the storage unit for comparison results, occupying three variable units.
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
S             
D             

Program example

7-14 Floating calculation_html_64d9e6cb502f6cbb.jpg

6.15.3 DEBCD instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEBCDConverts binary floating point to decimal floating point32NoDBCD S D9
DEBCDP32Yes9

It converts a floating point value at S into separate mantissa and exponent parts at D and D+1(decimal floating).

  • S: The binary floating variable;
  • D: The storage unit for converted decimal floating result;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S              
D               

Program example

7-14 Floating calculation_html_db6409b02ed2ea12.jpg

The binary floating value in (D3, D2) is converted to decimal floating value and the saved to (D11, D10).

There are 23 bits real number, 8 bits exponent, and 1 bit signal in binary floating (D3, D2), which will be converted to decimal floating (D11, D10), and it could be expressed with science formula of D2*10D3.

The floating data calculation is PLC is all in binary format, and it is converted to decimal for ease of monitoring.

6.15.4 DEBIN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEBINConverts decimal floating point to binary floating point32NoDBIN S D9
DEBINP32Yes9

This instruction converts decimal floating to binary floating

  • S: The decimal floating variable.
  • D: The storage unit for converted binary floating result.
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S              
D               

Program example

7-14 Floating calculation_html_9811e03fe36c1d7f.jpg

The decimal floating 3.142, which is saved in D11, D10, is converted to binary floating and then saved in (D3, D2).

6.15.5 DEADD instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEADDAdds two floating point numbers together32NoDEADD S1 S2 D13
DEADDP32Yes13

The floating point values stored in the source devices S1 and S2 are algebraically added and the result is stored in the destination device D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
D               

The instruction must use the double word format; i.e., DEADD or DEADDP. All source data and destination data will be double word.

K or H will be regarded as being in floating point format and the result stored in the destination will also be in floating point format.

If the result of the calculation is larger than the largest floating point number then the carry flag, M8021 is set ON and the result is set to the largest value.

If the result of the calculation is smaller than the smallest floating point number then the borrow flag, M8022 is set ON and the result is set to the smallest value.

Program example

7-14 Floating calculation_html_6e0a9f3042cd967d.jpg

For DEADD, when X10 is ON, the add operation will be executed in every scouldning cycle. For DEADDP, when X11 is ON, the add operation will be executed only once.

6.15.6 DESUB instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
DESUBSubtracts one floating point number from another32NoDESUB S1 S2 D13
DESUBP32Yes13

The floating point value of S2 is subtracted from the floating point value of S1and the result stored in destination device D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
D               

K or H will be regarded as being in floating point format and the result stored in the destination will also be in floating point format.

If the result of the calculation is 0, M8020 will set ON.

If the result of the calculation is larger than the largest floating point number then the carry flag, M8022 is set ON and the result is set to the largest value.

If the result of the calculation is smaller than the smallest floating point number then the borrow flag, M8021 is set ON and the result is set to the smallest value.

Program example

7-14 Floating calculation_html_ceb10b83f7b7dc78.jpg

When X10 = ON, after the binary floating-point (D3, D2) subtracts the other binary floating-point (D5, D4), the difference result will be stored in (D11, D10).

When X11 turns from OFF to ON, the value of the binary floating-point requires to subtract 123.The constant K123 is automatically converted to binary floating value before calculation.

The storing unit for the subtraction difference could be seemed as same one unit with the subtrahend and minuend. Please use the pulse execution instruction DESUBP under this circumstance. Otherwise, if selected the progressive execution instruction, the subtraction operation will be carried out again every time when the program is scouldned.

6.15.7 DEMUL instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEMULMultiplies two floating point numbers together32NoDEMUL S1 S2 D13
DEMULP32Yes13

The floating point value of S1 is multiplied with the floating point value of S2. The result of the multiplication is stored at D as a floating point value.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
D               

K or H will be regarded as being in floating point format and the result stored in the destination will also be in floating point format.

If the result of the calculation is 0, M8020 will set ON.

If the result of the calculation is larger than the largest floating point number then the carry flag, M8022 is set ON and the result is set to the largest value.

If the result of the calculation is smaller than the smallest floating point number then the borrow flag, M8021 is set ON and the result is set to the smallest value.

Program example

7-14 Floating calculation_html_672d0ac63015ab0d.jpg

When X12 = ON, after the binary floating-point (D3, D2) multiplies the other binary floating-point (D5, D4), the product will be stored in (D11, D10).

When X13 turns from OFF to ON, the binary floating-point (D21, D20) value will be multiplied by 3 (three) and saved back in (D21, D20) the constant K3 has already been automatically converted to a binary floating-point value prior to the calculation.

The storing unit for the multiplication product could be treated as one unit with the multiplicouldd and the multiplier. Please use the pulse execution instruction DEMULP under this circumstance. Otherwise, if selected the progressive execution instruction, the multiplication operation will be carried out again every time when the program is scouldned.

6.15.8 DEDIV instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DEDIVDivides one floating point number by another32NoDEDIV S1 S2 D13
DEDIVP32Yes13

The floating point value of S1 is divided by the floating point value of S2. The result of the division is stored in D as a floating point value. No remainder is calculated.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1            
S2            
D               

K or H will be regarded as being in floating point format and the result stored in the destination will also be in floating point format.

If the result of the calculation is 0, M8020 will set ON.

If the result of the calculation is larger than the largest floating point number then the carry flag, M8022 is set ON and the result is set to the largest value.

If the result of the calculation is smaller than the smallest floating point number then the borrow flag, M8021 is set ON and the result is set to the smallest value.

Program example

7-14 Floating calculation_html_2df6bb9f838f7890.jpg

When X14=ON and the binary floating variable (D3, D2) are divided by the binary floating variable (D5, D4), the result will be saved in (D11, D10).

When X15 is set from OFF to ON, the binary floating (D11, D10) is divided by 10 and then the result is saved back to (D11, D10).The constant K10 is automatically converted to a binary floating value before calculation.

The storage unit for the result could be the storage unit for the dividend or divisor, in which the pulse-type DEDIVP instruction is recommended, or the continued implementation instruction will be applied, in which the calculation will be implemented every time when the program is scouldned.

6.15.9 DESQR instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DESQRCalculates the square root of a floating point value.32NoDESQR S D9
DESQRP32Yes9

A square root is performed on the floating point value of S, the result is stored in D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S            
D               
  • If S is K or H, it will be regarded as being in floating point format.
  • If the result of the calculation is 0, M8020 will set ON.
  • S must be greater than 0, if not, M8067 and M8068 will be set ON.

Program example

7-14 Floating calculation_html_b7ea1c9bea221dfa.jpg

  • Solution 1: The binary floating radiation result is saved to (D11, D10)
  • Solution 2: The binary floating number K6789 is implemented with radiation calculation and then the result is saved to (D21, D20), where the constant K6789 is automatically converted to binary floating data before implementation;

6.15.10 DINT instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
INTConverts a number from floating point format to decimal format16NoINT S D5
INTP16Yes5
DINT32No9
DINTP32Yes9

The floating point value of S is rounded down to the nearest integer value and stored in normal binary format in D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S              
D               
  • If the result is 0, M8020 will be set ON.
  • If the source data is not a whole number, it must be rounded down. In this case the borrow flag M8021 is set ON to indicate a rounded value.
  • If the resulting integer value is outside the valid range (16-bit: -32768~32767, 32-bit: -2147483648~2147483647); for the destination device then an overflow occurs. In this case the carry flag M8022 is set on to indicate overflow.

Program example

7-14 Floating calculation_html_d853c52fad455e69.jpg

When M10 is triggered, (D51, D50) are rounded down to the nearest integer value and stored in normal binary format in D100.

When M11 is triggered, (D11, D10) are rounded down to the nearest integer value and stored in normal binary format in (D21, D20).

6.15.11 DSIN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DSINCalculates the sine of a floating point value32NoDSIN S D9
DSINP32Yes9

This instruction performs the mathematical SIN operation on the floating point.

  • S: The angle variable that needs to be calculated in order to obtain SIN value. The unit is in RAD, and the value is expressed in binary floating points. ValueRange0<=α<=2π;
  • D: The storage unit for the SIN calculation results after its conversion. It is in binary floating point format.
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1:

7-14 Floating calculation_html_963ccbe774e748a4.jpg

The unit of S is rad, the range is from 0 to 2π.

RAD=DEGREE*π/180°

Example 2:

7-14 Floating calculation_html_d455c2ae27aa129.jpg

6.15.12 DCOS instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DCOSDCOS Calculates the cosine of a floating point value32NoDCOS S D9
DCOSP32Yes9

This instruction performs the mathematical cos operation on the floating point value in S. The result is stored in D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_295ef53bc0089ac6.jpg

When M10 is triggered, radian (D21, D20) are implement with COS calculation and saved to (D31, D30).

The calculated source data and COS results are in binary floating format.

RAD (radian) value= angle×π/180°,for example, the radian correspondingtoangle360°=360°×π/180°=2π.

For the program instruction for the COS calculation of an angle, please refer to examples in the SIN instruction.

6.15.13 DTAN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DTANCalculates the tangent of a floating point value32NoDTAN S D9
DTANP32Yes9

This instruction performs the mathematical TAN operation on the floating point value in S. The result is stored in D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_c0af762b1c289e7a.jpg

When X2 is triggered, it calculations the TAN value of radian (D21, D20) and saved it to (D31, D30).

The calculated source data and SIN results are all in binary floating point value format.

RAD(radian)value=angle × π/180°,for example, the radian corresponding to angle 360° = 360°× π/180° = 2π.

In regards to the programming statements used to calculate the TAN value, please refer to the example in the SIN instruction section.

6.15.14 DASIN instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DASINCalculate the corresponding radian value based on the SIN value32NoDASIN S D9
DASINP32Yes9

This instruction performs the mathematical ARCSIN operation on the floating point.

  • S: The value of SIN, it is in binary floating-point format, the range is-1.0<=α<= 1.0;
  • D: It used for store result, the range is -0.5π~+0.5π
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1:

7-14 Floating calculation_html_94f1cc58dbe83556.jpg

When M0= 0, SIN -1 operation (D1, D0) carried out, and result is saved in (D3, D2).

SIN -1 (D1, D0) -> (D3, D2)

The source data and results are binary floating-point format.

Angle in radians=angle in degree*π/180°

Example 2:

7-14 Floating calculation_html_9f567ad283ddcac6.jpg

If (D1, D0) is 0.707106781, when M10 turns from OFF to ON, (D3, D2) will be 0.78539815, (D5,D4) will be 45, (D7,D6) will be 45.

6.15.15 DACOS instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DACOSCalculate the corresponding radian value based on the COS value32NoDACOS S D9
DACOSP32Yes9

Calculate radian value, according to the corresponding value of COS.

  • S: The value of COS, it is in binary floating-point format, the range is-1.0<=α<= 1.0;
  • D: It used for store result, the range is 0~π
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1:

7-14 Floating calculation_html_2497e02e1e0db818.jpg

When M0=0, COS-1 operation (D1, D0) carried out, and result is saved in (D3, D2).

COS-1(D1, D0)->(D3, D2).

The source data and results are binary floating-point format.

Angle in radians=angle in degree*π/180°

Example 2:

7-14 Floating calculation_html_32eefe65f5859cfb.jpg

If (D1, D0) is 0.866025404, when M10 turns from OFF to ON, (D3, D2) will be 0.52359877, (D5, D4) will be 30, (D7, D6) will be 30.

6.15.16 DATAN instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DATANCalculate the corresponding radian value based on the TAN value32NoDATAN S D9
DATANP32Yes9

Calculate radian value, according to the corresponding value of TAN.

  • S: The value of TAN, it is in binary floating-point format;
  • D: It used for store result, the range is –π/2~+π/2
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1:

7-14 Floating calculation_html_a6de4d2d38b3be81.jpg

When M0= 0, TAN -1 operation (D1, D0) carried out, and result is saved in (D3, D2).

TAN -1 (D1、D0) -> (D3、D2)

The source data and results are binary floating-point format.

Angle in radians=angle in degree*π/180°

Example 2:

7-14 Floating calculation_html_6871c67fd5729c91.jpg

If (D1, D0) is 1.732050808, when M10 turns from OFF to ON, (D3, D2) will be 1.04719753, (D5, D4) will be 60, (D7, D6) will be 60.

6.15.17 DSINH instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DSINHThe operation of Hyperbolic Sine function SINH (Binary floating)32NoDSINH S D9
DSINHP32Yes9

This instruction performs the mathematical SINH operation on the floating point value. D= (es-e-s)/2

  • S: The binary floating-point for SINH;
  • D: It used to save result;
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_8a7af241e1911830.jpg

When M10 turn ON, calculate value (D1, D0) of SINH, and saved the result in (D3, D2). DSINH (D1, D0) → (D3, D2)

6.15.18 DCOSH instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DCOSHBinary floating point hyperbolic sine function COSH operation32NoDCOSH S D9
DCOSHP32Yes9

This instruction performs the mathematical COSH operation on the floating point. D= (es+e-s)/2

  • S: The binary floating-point for COSH;
  • D: The used to store result;
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_25ea140aba809656.jpg

When M10 turn ON, calculate value (D1, D0) of COSH, and saved the result in (D3, D2).

DCOSH (D1, D0) → (D3, D2)

6.15.19 DTANH instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DTANHThe operation of Hyperbolic Tangent function TANH32NoDTANH S D9
DTANHP32Yes9

This instruction performs the mathematical TANH operation on the floating point. D= (es-e-s)/ (es+e-s)

  • S: The binary floating-point for TANH;
  • D: It used to save result;
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_8db16e8375c14eab.jpg

When M10 is triggered, calculate value (D1, D0) of TANH, and saved the result in (D3, D2). DTANH (D1, D0) → (D3, D2)

6.15.20 DDEG Instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DDEGThe operation of converting radian to angle (Binary floating-point)32NoDDEG S D9
DDEGP32Yes9

This instruction is used for converting radian to angle (Binary floating-point). The formula is RAD value= Angle*π/180°

  • S: The radian;
  • D: It used to save result;
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1

7-14 Floating calculation_html_4e15943e8299afef.jpg

When M10 turn ON, convert radian (D1, D0) to angle, and saved the result in (D3, D2). DDEG (D1, D0) → (D3, D2)

RAD (radian) value= angle×π/180°, for example, the radiancorrespondingtoangle360°=360°×π/180°= 2π.

Example 2

7-14 Floating calculation_html_ea1287ee46570a37.jpg

If the value of (D1, D0) is 3.1415926, when M10 turn ON, the value of (D3, D2) is 180; the value of (D5, D4) is 180.

6.15.21 DRAD instruction

Instruction description

NameFunctionBits (bits)Pulse typeInstruction formatStep
DRADThe operation of Hyperbolic Tangent function TANH32NoDTANH S D9
DRADP32Yes9

This instruction is used for converting angle to radian (Binary floating-point). The formula is RAD value= Angle*π/180°

  • S: The angle;
  • D: It used to save result.
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

Example 1:

7-14 Floating calculation_html_f2d1c89f0d4e3df8.jpg

When M10 turn ON, convert angle (D1, D0) to radian, and saved the result in (D3, D2). DRAD (D1, D0) → (D3, D2)

RAD (radian) value= angle×π/180°,for example, the radian corresponding to angle 360°= 360°× π/ 180°= 2π.

Example 2:

7-14 Floating calculation_html_8335cdb30d5097cb.jpg

When M10 is ON, (D5, D4) is π/2, i.e. 1.570796

6.15.22 DEXP instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
DEXPExponential operation of binary floating number with e as the base number32NoDEXP S D5
DEXPP32Yes9

This instruction performs the exponential operation on S with e(2.71828) as the base number and store the result in D.

When D is not within 2-126 ~2128 , an error will occur. The error code is K6707 that is stored in D8067, and M8067 will set ON.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_7cf0ad6018381a72.jpg

When X0 is triggered, E (D1, D0) →(D3,D2). Because loge2128=88.7, so when (D1, D0) is greater than 88.7, D8067 is k6706, M8067 will set ON.

6.15.23 DLOG10 instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
DLOG10Logarithmic operations of binary floating numbers with 10 as the base number32NoDLOG10 S D9
DLOG10P32Yes9

This instruction performs common logarithm operation of binary floating-point number to base 10.

  • S: the binary floating-point variables of common logarithm in exponent binary floating-point number.
  • D: the storage unit for saving the operation result of common logarithm
  • Note: the value in could only be positive number. Operational error will occur when the value in is 0 or negative number. Error code K6706 is saved in D8067 and error flag M8067 turns ON.
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_b470f3fc3392644c.jpg

When M10 turns ON, the common logarithm operation of binary floating-point number in (D1, D0) to base 10 is performed, and save the result in (D3, D2)

Log10 (D1, D0) →(D3, D2).

6.15.24 DLOGE instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
DLOGEThe natural logarithmic operation of binary floating number with e (2.71828) as the base number32NoDLOGE S D9
DLOGEP32Yes9

This instruction performs common logarithm operation of binary floating-point number to base 10.

  • S: the binary floating-point variables of common logarithm in exponentiated binary floating-point number.
  • D: the storage unit for saving the operation result of common logarithm
  • Note: the value in S could only be positive number. Operational error will occur when the value in S is 0 or negative number. Error code K6706 is saved in D8067 and error flag M8067 turns ON.
OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example

7-14 Floating calculation_html_6010c4df672fabfe.jpg

 

When X0 is triggered, Loge(D1,D0) →(D3,D2).

The conversation between natural logarithmic operation and common logarithmic operation is as below:

7-14 Floating calculation_html_c324d50ac54002e0.jpg