English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and Example of C Library Function frexp()

C Standard Library - <math.h>

C Library Function double frexp(double x, int *exponent) Split the floating-point number x into the mantissa and exponent. The return value is the mantissa, and the exponent is stored in exponent . The obtained value is x = mantissa * 2 ^ exponent.

Declaration

Below is the declaration of the frexp() function.

double frexp(double x, int *exponent)

Parameter

  • x  -- The floating-point value to be calculated.

  • exponent  -- A pointer to an object that stores the value of the exponent.

Return Value

The function returns the normalized decimal. If the parameter x is not zero, the normalized decimal is the square of x, and its absolute value range is from 1/2Contains) to 1If x is zero, the normalized decimal is zero, and zero is stored in exp.

Online Example

The following example demonstrates the usage of the frexp() function.

#include <stdio.h>
#include <math.h>
int main ()
{
   double x = 2048, fraction;
   int e;
   
   fraction = frexp(x, &e);
   printf("x = %."2lf = %.2lf * 2^%d\n", x, fraction, e);
   
   return(0);
}

Let's compile and run the above program, which will produce the following result:

x = 2048.00 = 0.50 * 2^12

C Standard Library - <math.h>