Square Root (SQRT)

The SQRT instruction and operator computes the square root of the Source and places the result in Dest.
If the Dest is not an LREAL/REAL, the instruction handles the fractional portion of the result as follows:
If the Source is:
The fractional portion of the result:
Example
any elementary integer tag/value
Rounds
Source
DINT
3
Dest
DINT
2
any floating point tag/value
Rounds
Source
REAL
3.0
Dest
DINT
2
If the Source is negative, the instruction takes the absolute value of the Source before calculating the square root.
If the Source is a real data type and the Dest is an integer type, the instruction rounds the result. For example, if the real Source value is 3.0, the result is 1.732, and the Dest value becomes 2.
SQRT is used as an operator in ladder diagram expressions.
Available Languages
Ladder Diagram
SQRT ladder instruction
Operands
IMPORTANT: Unexpected operation may occur if:
  • Output tag operands are overwritten
  • Members of a structure operand are overwritten
  • Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data conversions.
Ladder Diagram
Operand
Data Type
Format
Description
Source
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
immediate
tag
Computes the square root of this value.
Dest
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
tag
Tag to store the result of the instruction.
Affects Math Status Flags
Major/Minor Faults
None specific to this instruction. See Index through arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A
Rung-condition-in is false
Set Rung-condition-out to Rung-condition-in.
Rung-condition-in is true
Set Rung-condition-out to Rung-condition-in.
Dest = square root of Source.
Postscan
N/A
Examples
Ladder Diagram
SQRT ladder instruction example
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.