frexp, frexpf, frexpl

Header: <math.h>

1-3) Decomposes given floating-point value x into a normalized fraction and an integral power of two.

# Declarations

float frexpf( float arg, int* exp );

(since C99)

double frexp( double arg, int* exp );
long double frexpl( long double arg, int* exp );

(since C99)

#define frexp( arg, exp )

(since C99)

# Parameters

# Return value

If arg is zero, returns zero and stores zero in *exp.

# Notes

On a binary system (where FLT_RADIX is 2), frexp may be implemented as

The function frexp, together with its dual, ldexp, can be used to manipulate the representation of a floating-point number without direct bit manipulations.

# Example

#include <float.h>
#include <math.h>
#include <stdio.h>
 
int main(void)
{
    double f = 123.45;
    printf("Given the number %.2f or %a in hex,\n", f, f);
 
    double f3;
    double f2 = modf(f, &f3);
    printf("modf() makes %.0f + %.2f\n", f3, f2);
 
    int i;
    f2 = frexp(f, &i);
    printf("frexp() makes %f * 2^%d\n", f2, i);
 
    i = ilogb(f);
    printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i);
}

# See also