C Standard Library
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C <math.h> - frexp() Function



The C <math.h> frexp() function is used to break the floating point number x into its binary significand (a floating point with an absolute value in range [0.5, 1.0)) and an integral exponent for 2. Mathematically, it can be expressed as:

x = significand * 2exponent

The exponent is stored in the object pointed by exp, and the function returns the significand. If x is zero, both significand and exponent are zero. If x is negative, the significand returned by the function is negative.

Syntax

double frexp (double x, int* exp);
float frexpf (float x, int* exp);
long double frexpl (long double x, int* exp);

Parameters

x Specify the value to be decomposed.
exp Specify the pointer to an int object to store the exponent.

Return Value

The binary significand of the x.

Example:

The example below shows the usage of frexp() function.

#include <stdio.h>
#include <math.h>
 
int main (){
  double x, sig;
  int y;
  x = 10;

  sig = frexp(x, &y);

  printf("Number: %lf\n", x);
  printf("Significand: %lf\n", sig);
  printf("Exponent: %i\n", y);

  return 0;
}

The output of the above code will be:

Number: 10.000000
Significand: 0.625000
Exponent: 4

❮ C <math.h> Library

5