sqrt (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

3.10 / 1.00.00


This function will calculate the square root of the argument.

 

Note: This function works with DOUBLE, but can also work with FLOAT as described in the Floating-point math introductory section.

 

Input:

V : DOUBLE

Value to calculate the square root of.

 

Returns: DOUBLE

The square root of the value. If the value is less than 0, NaN is returned.

 

Declaration:

FUNCTION sqrt : DOUBLE;
VAR_INPUT
v : DOUBLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
  a : DOUBLE;
  b : DOUBLE;
  c : DOUBLE;
END_VAR;
 
a := 3.0;
b := 4.0;
c := sqrt(v:= a**2.0 + b**2.0);
DebugMsg( message := doubleToStr(v := a) + "^2 + "
  + doubleToStr(v := b) + "^2 = " + doubleToStr(v := c) + "^2");
 
END_PROGRAM;