C frexp() function
C frexp() function - Extract mantissa and exponent from a double precision number
Syntax:
double frexp(double x, int *exponent)
The frexp() function is used to break down the floating-point value x into a term m for the mantissa and another term n for the exponent.
Parameters:
Name | Description | Required /Optional |
---|---|---|
x | Floating-point value. | Required |
exponent | Pointer to stored integer exponent. | Required |
Return value from frexp()
- Returns the mantissa term m.
- If x is 0, frexp() returns 0 for both the mantissa and exponent. The mantissa has the same sign as the argument x.
Example: frexp() function
The following example shows the usage of frexp() function.
#include <math.h>
#include <stdio.h>
int main( void )
{
double x, y;
int n;
x = 16.4;
y = frexp( x, &n );
printf( "frexp( %f, &n ) = %f, n = %d\n", x, y, n );
x = 25.9;
y = frexp( x, &n );
printf( "frexp( %f, &n ) = %f, n = %d\n", x, y, n );
x = 100.2;
y = frexp( x, &n );
printf( "frexp( %f, &n ) = %f, n = %d\n", x, y, n );
}
Output:
frexp( 16.400000, &n ) = 0.512500, n = 5 frexp( 25.900000, &n ) = 0.809375, n = 5 frexp( 100.200000, &n ) = 0.782813, n = 7
C Programming Code Editor:
Previous C Programming: C exp()
Next C Programming: C ldexp()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming/math/c-frexp.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics