ldexpf Function

Calculates the result of a single precision floating-point number multiplied by an exponent of 2.

Include

<math.h>

Prototype

float ldexpf(float x, int exp);

Arguments

x
floating-point value
exp
integer exponent

Return Value

Returns x * 2^exp.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  float x,y;
  int n;

  x = -0.625F;
  n = 2;
  y = ldexpf(x, n);
  printf("For a number = %f and an exponent = %d\n", x, n);
  printf("  ldexpf(%f, %d) = %f\n\n", x, n, y);

  x = 2.5F;
  n = 3;
  y = ldexpf(x, n);
  printf("For a number = %f and an exponent = %d\n", x, n);
  printf("  ldexpf(%f, %d) = %f\n\n", x, n, y);

  x = 15.0F;
  n = 10000;
  y = ldexpf(x, n);
  printf("For a number = %f and an exponent = %d\n", x, n);
  printf("  ldexpf(%f, %d) = %f\n\n", x, n, y);
}

Example Output

For a number = -0.625000 and an exponent = 2
  ldexpf(-0.625000, 2) = -2.500000

For a number = 2.500000 and an exponent = 3
  ldexpf(2.500000, 3) = 20.000000

For a number = 15.000000 and an exponent = 10000
  ldexpf(15.000000, 10000) = inf