frexp (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

3.10 / 1.00.00


This function will break the value into its binary significand and an integral exponent for 2.

The values will follow the following formula:

V = significant * 2^exp

 

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 decompose.

 

Output:

exp : DOUBLE

Exponent

 

Returns: DOUBLE

The binary significant of v.

 

Declaration:

FUNCTION frexp : DOUBLE;
VAR_INPUT
v   : DOUBLE;
exp : ACCESS DOUBLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
  a : DOUBLE;
  b : DOUBLE;
END_VAR;
 
a := frexp(v:= 1024.0, exp := b);
DebugMsg( message := " 1024 = " + doubleToStr(v := a) + " * 2 ^ " + doubleToStr(v := b));
DebugMsg( message := " 0.5 * 2 ^ 11 = " + doubleToStr(v := ldexp(a := a, b := b)));
 
 
END_PROGRAM;