Square Root (SQRT)

This table lists the controllers and applications that support this instruction.
Architecture
Standard applications
Safety applications
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
No
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Yes
Yes
The Square Root (SQRT) instruction and operator computes the square root of the Source and places the result in Dest.
TIP: In Logix Designer version 36, the mnemonic for this instruction changed from SQR to SQRT.
Available Languages
Ladder Diagram
Function Block Diagram
Function Block Diagram supports these elements:
FBD Block
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
SQRT fbd function
Structured Text
This instruction is not available in structured text.
TIP:
Use SQRT as an operator in an expression to compute the same result. Refer to Structured Text Syntax for more information on the syntax of expressions and assignments within structured text.
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
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Format
Description
Source
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
immediate
tag
Computes the square root of this value.
Dest
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
tag
Tag to store the result of the instruction.
Function Block Diagram
FBD Block
Operand
Data Type
Format
Description
SQRT
FBD_MATH_ADVANCED
tag
SQRT structure
FBD_MATH_ADVANCED Structure
Input Members
Data Type
Description
EnableIn
BOOL
Enable input. If false, the instruction does not execute and outputs are not updated.
Default is true.
Source
REAL
Find the square root of this value.
Output Members
Data Type
Description
EnableOut
BOOL
Indicates if the instruction executed without fault when it was enabled.
Dest
REAL
Result of the instruction.
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
Input Operand (Left Pin)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
SourceA
SINT
USINT
INT
UINT
DINT
UDINT
LINT
ULINT
REAL
LREAL
Computes the square root of this value.
Output Operand (Right Pin)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
Dest
DINT
UDINT
LINT
ULINT
REAL
LREAL
Result of the function.
Description
If the Dest is not an LREAL/REAL, the instruction handles the fractional portion of the result as follows:
If the Source is:
(For CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers)
The fractional portion of the result:
Example
(For CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers)
The fractional portion of the result:
Example
any elementary integer tag/value
Truncates
Source
DINT
3
Rounds
Source
DINT
3
Dest
DINT
1
Dest
DINT
2
any floating point tag/value
Rounds
Source
REAL
3.0
Rounds
Source
REAL
3.0
Dest
DINT
2
Dest
DINT
2
If the Source is negative, the instruction takes the absolute value of the Source before calculating the square root.
For the
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers, if the Source is an integer data type and the Dest is an integer data type, the instruction truncates the result. For example, if the integer Source value is 3, the result is 1.732, and the Dest value becomes 1.
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.
Affects Math Status Flags
Controllers
Affects Math Status Flags
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Conditional
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
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
Function Block Diagram
FBD Block
Condition/State
Action Taken
Prescan
N/A
EnableIn is false
Set EnableOut to EnableIn.
EnableIn is true
Dest. = square root of Source.
If overflow occurs
Clear EnableOut to false
else
Set EnableOut to true
Instruction first run
N/A
Instruction first scan
N/A
Postscan
N/A
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
Condition/State
Action Taken
Prescan
N/A
Normal Scan
Dest = square root of Source
Instruction first run
N/A
Instruction first scan
N/A
Postscan
N/A
Examples
Ladder Diagram
Function Block Diagram
FBD Block
FBD Function
SQR _fbd fun example
Structured Text
REAL_dest := SQRT(INT_src);
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.