function
<cmath> <ctgmath>

frexp

double frexp (double x, int* exp);
     double frexp  (double x     , int* exp);      float frexpf (float x      , int* exp);long double frexpl (long double x, int* exp);
     double frexp (double x     , int* exp);      float frexp (float x      , int* exp);long double frexp (long double x, int* exp);
     double frexp (double x     , int* exp);      float frexp (float x      , int* exp);long double frexp (long double x, int* exp);     double frexp (T x          , int* exp); // additional overloads for integral types
Get significand and exponent
Breaks the floating point number x into its binary significand (a floating point with an absolute 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.
If x is negative, the significand returned by this function is negative.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Value to be decomposed.
exp
Pointer to an int where the value of the exponent is stored.

Return Value

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

Example

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

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

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

Output:

8.000000 = 0.500000 * 2^4


See also