frexp in c

What is frexp in c programming?

frexp in c is used to calculate the mantissa and the integer pointed to by exponent i.e. x=mantissa*2^exponent.

This function is defined in math.h header file.

Prototype

double frexp(double x, int *exponent);

Prameters

frexp takes one floating point value, pointer to an int object.

Return value

It returns mantissa and the integer pointed to by exponent i.e. x=mantissa*2^exponent.


Example program for frexp in c

#include<stdio.h>
#include<math.h>
int main()
{
  double x=1000,fract;
  int a;
  fract=frexp(x,&a);
  printf("Fraction is %lf and exponent value is %d\n",fract,a);
  return 0;
}
Example for frexp in c programming
Output for example for frexp in c programming

While using gcc use below command to add math header.

gcc file_name.c -lm

Code explanation

The mantissa and fractional value of a given number is found by passing it to the frexp function. The result is being printed onto the console.

frexp() Man page


Difference between frexp and exp in c

frexp in c is used to calculate the mantissa and the integer pointed to by exponent i.e. x=mantissa*2^exponent. exp function is used to calculate the exponential value of a given number.

frexp takes two parameters. exp takes one parameter.

Prototypes are as follows

double frexp(double x, int *exponent);

double exp(double value1);
frexp( )exp( )
Used to calculate the mantissa and the integer pointed to by exponent.Used to calculate exponential value of a given number.
double frexp(double x, int *exponent);double exp(double value1);

People also ask for

What is the difference between frexp and Idexp in c?

frexp in c is used to calculate the mantissa and the integer pointed to by the exponent. Idexp function is used to calculate x multiplied by 2 raised to the power of the exponent.