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()
C Programming: Tips of the Day
What's the point of const pointers?
const is a tool which you should use in pursuit of a very important C++ concept:
Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.
Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:
void foo(int* ptr) { ptr = 0;// oops, I meant *ptr = 0 }
If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.
Ref : https://bit.ly/33Cdn3Q
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises