frexp


function
<cmath>
     double frexp (      double x, int * exp );
      float frexp (       float x, int * exp );
long double frexp ( long double x, int * exp );

Get significand and exponent

Breaks the floating point number x into its binary significand (a floating point value between 0.5(included) and 1.0(excluded)) and an integral exponent for 2, such that:

x = significand * 2 exponent

The exponent is stored in the location pointed by exp, and the significand is the value returned by the function.

If x is zero, both parts (significand and exponent) are zero.

Parameters

x
Floating point value to be computed.
exp
Pointer to an int object where the value of the exponent is to be stored.


Return Value

The binary significand of x.
This value is the floating point value in the interval [0.5,1) which, once multiplied by 2 raised to the power of exp, yields x.

Portability

In C, only the double version of this function exists with this name.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* frexp example */
#include <stdio.h>
#include <math.h>

int main ()
{
  double param, result;
  int n;

  param = 8.0;
  result = frexp (param , &n);
  printf ("%lf * 2^%d = %f\n", result, n, param);
  return 0;
}


Output:

0.500000 * 2^4 = 8.000000


See also