ldexp (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

3.10 / 1.00.00


Returns the result of multiplying argument 1 (the significand) by 2 raised to the power of argument 2 (the exponent).

ldexp := a * 2b

 

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

 

Input:

A : DOUBLE

Significand.

 

B : DOUBLE

Exponent

 

Returns: DOUBLE

The calculated value.

 

Declaration:

FUNCTION ldexp : DOUBLE;
VAR_INPUT
a : DOUBLE;
b : 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;