Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ldexp, ldexpf, ldexpl - Calculate binary value

&pagelevel(4)&pagelevel

Definition   

#include <math.h>

double ldexp(double x, int exp);
float ldexpf(floatx, int exp); (C11)
long double ldexpl(long double x, int exp); (C11)

Given its arguments x (mantissa) and exp (exponent), these functions calculate the number:

x * 2exp

ldexp is the inverse function of frexp.

Return val. 

x * 2exp

if successful.


+/-HUGE_VAL
+/-HUGE_VALF
+/-HUGE_VALL

depending on the function type and the sign of x, if an overflow occurs.
In addition, errno is set to ERANGE (result too large).                                                                   

Example

ldexp is the inverse function of frexp: frexp splits its floating-point argument into mantissa and exponent to the base 2, while ldexp uses these parts to calculate the original value in its internal floating-point representation.
This is shown below for the number 5.342:

#include <stdio.h>
#include <math.h>
int main(void)
{
  double x;
  int ex;
  x = frexp(5.342, &ex);
  printf("Mantissa : %f\nexponent : %d\n", x, ex);
  printf("Initial value : %f\n", ldexp(x, ex));
  return 0;
}

See also

frexp, modf