C Language: frexp function
(Split into Fraction and Exponent)
In the C Programming Language, the frexp function splits a floating-point value into a fraction and an exponent. The fraction is returned by the frexp function and the exponent is stored in the exp variable.
Syntax
The syntax for the frexp function in the C Language is:
double frexp(double value, int *exp);
Parameters or Arguments
- value
- The floating-point value to split into a fraction and an exponent.
- exp
- A pointer to an integer variable where the exponent will be stored.
Returns
The frexp function returns the fractional part of value based on the equation: fraction x 2 exponent
The fraction must be greater than or equal to 0.5 and less than 1, or the fraction must be equal to 0.
Required Header
In the C Language, the required header for the frexp function is:
#include <math.h>
Applies To
In the C Language, the frexp function can be used in the following versions:
- ANSI/ISO 9899-1990
frexp Example
/* Example using frexp by TechOnTheNet.com */ #include <stdio.h> #include <math.h> int main(int argc, const char * argv[]) { /* Define temporary variables */ double value; int e; double f; /* Assign the value we will find the exp of */ value = 1.5; /* Calculate the fraction and exponential of the value */ f = frexp(value, &e); /* Display the result of the calculation */ printf("The Fraction and Exponential of %f are %f and %d\n", value, f, e); return 0; }
When compiled and run, this application will output:
The Fraction and Exponential of 1.500000 are 0.750000 and 1
Similar Functions
Other C functions that are similar to the frexp function:
See Also
Other C functions that are noteworthy when dealing with the frexp function:
Advertisements