calcPow (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

2.32 / 1.00.00


The "calcPow" function calculates the power functions of two values given as scaled floating point values.

 

The values "x" and "y" are integers interpreted as floating point with the scaling factor given in the "scale" parameter.

When, for example, (x=812 y=215, scale=100), this is interpreted as (x=8.12, y=2.15), and the returned value from calcPow will be 9027 which is equal to 90.27 with the specified scaling.

 

For large values overflow may occur in the calculation, and the returned value will be undefined. For calculations yielding a complex number, 0 will be returned.
 

It is also possible to use floating-point with the exponent operator.

 

Input:

x   : DINT

Scaled floating point number.

 

y   : DINT

Scaled floating point number.

 

scale  : INT (default 1)

The scale that is used for the floating point numbers to convert them to integers.

 

Returns: DINT

The resulting scaled floating point number.

 

Declaration:

FUNCTION calcPow : DINT;
VAR_INPUT
  x     : DINT;
  y     : DINT;
  scale : INT := 1;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  res : DINT;
END_VAR;
 
  res := calcPow(x := 200, y := 247, scale := 100);
  DebugFmt(message := "Power function: 2.00 ** 2.47 = \4.\1", v4 := res, v1 := INT(res / 100));
 
BEGIN
END;
END_PROGRAM;