frexp

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
frexp
(C99)(C99)
(C99)
Classification
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       frexpf( float arg, int* exp );
(since C99)
double      frexp( double arg, int* exp );
long double frexpl( long double arg, int* exp );
(since C99)

Decomposes given floating point value arg to significand and exponent.

Contents

[edit] Parameters

arg - floating point value
exp - pointer to integer value to store the exponent to

[edit] Return value

Significand of the given floating point number in the range of [0.5; 1). The exponent is put into integer value pointed to by exp.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <float.h>
 
int main(void)
{
    int exp;
    printf("frexp(1.0,&exp)       = %+f * 2^", frexp(1.0,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(+0.0,&exp)      = %+f * 2^", frexp(+0.0,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(-0.0,&exp)      = %+f * 2^", frexp(-0.0,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(+INFINITY,&exp) = %+f * 2^", frexp(+INFINITY,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(-INFINITY,&exp) = %+f * 2^", frexp(-INFINITY,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(NAN,&exp)       = %+f * 2^", frexp(NAN,&exp));
    printf("(%+2d)\n", exp);
    printf("\n");
 
    printf("frexp(DBL_MIN,&exp) = %+f * 2^", frexp(DBL_MIN,&exp));
    printf("(%+2d)\n", exp);
    printf("frexp(DBL_MAX,&exp) = %+f * 2^", frexp(DBL_MAX,&exp));
    printf("(%+2d)\n", exp);
 
    return 0;
}

Possible output:

frexp(1.0,&exp)       = +0.500000 * 2^(+1)
frexp(+0.0,&exp)      = +0.000000 * 2^(+0)
frexp(-0.0,&exp)      = -0.000000 * 2^(+0)
frexp(+INFINITY,&exp) = +inf * 2^(+0)
frexp(-INFINITY,&exp) = -inf * 2^(+0)
frexp(NAN,&exp)       = +nan * 2^(+0)
 
frexp(DBL_MIN,&exp) = +0.500000 * 2^(-1021)
frexp(DBL_MAX,&exp) = +1.000000 * 2^(+1024)

[edit] See also

(C99)(C99)
multiplies a number by 2 raised to a power
(function)
(C99)(C99)(C99)
extracts exponent of the given number
(function)
(C99)(C99)(C99)
extracts exponent of the given number
(function)
(C99)(C99)
breaks a number into integer and fractional parts
(function)
C++ documentation for frexp