Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Computes a real number from the mantissa and exponent.

double ldexp(
   double x,
   int exp 
float ldexp(
   float x,
   int exp
);  // C++ only
long double ldexp(
   long double x,
   int exp
);  // C++ only


Floating-point value.
Integer exponent.

Return Value

The ldexp function returns the value of x * 2exp if successful. On overflow (depending on the sign of x), ldexp returns +/– HUGE_VAL; the errno variable is set to ERANGE.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on this, and other, return codes.


C++ allows overloading, so you can call overloads of ldexp. In a C program, ldexp always takes a double and an int and returns a double.


Routine Required header Compatibility
ldexp <math.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_ldexp.c

#include <math.h>
#include <stdio.h>

int main( void )
   double x = 4.0, y;
   int p = 3;

   y = ldexp( x, p );
   printf( "%2.1f times two to the power of %d is %2.1f\n", x, p, y );


4.0 times two to the power of 3 is 32.0

See Also

Floating-Point Support | frexp | modf | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft