frexp
Break down x into a mantissa (a floating point with an absolute value between [1/2, 1)) and an integral exponent for 2, and return the mantissa. The exponent is stored in the position pointed by exp.
Interface Definition
C interface:
float frexpf(float x, int *exp);
double frexp(double x, int *exp);
long double frexpl(long double x, int *exp);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
exp |
An integer pointer. |
Exponent. |
Output |
Return Value
- x is broken down into a mantissa (a floating point with an absolute value between [1/2, 1)) and an integral exponent for 2, and the mantissa is returned. The exponent is stored in the position pointed by exp.
- If input x is inf, the return value is inf, and the return value of exp is meaningless.
- If input x is -inf, the return value is -inf, and the return value of exp is meaningless.
- If input x is NaN, the return value is NaN, and the return value of exp is meaningless.
Dependency
C: "km.h"
Example
C interface:
// print result
int32_t exp;
printf("frexp(3.4, &exp) = %.15f, exp = %d\n", frexp(3.4, &exp), exp);
printf("frexp(-4.8, &exp) = %.15f, exp = %d\n", frexp(-4.8, &exp), exp);
printf("frexp(NAN, &exp) = %.15f, exp = %d\n", frexp(NAN, &exp), exp);
printf("frexp(-NAN, &exp) = %.15f, exp = %d\n", frexp(-NAN, &exp), exp);
printf("frexp(INFINITY, &exp) = %.15f, exp = %d\n", frexp(INFINITY, &exp), exp);
printf("frexp(-INFINITY, &exp) = %.15f, exp = %d\n", frexp(-INFINITY, &exp), exp);
result
/*
* frexp(3.4, &exp) = 0.850000000000000, exp = 2
* frexp(-4.8, &exp) = -0.600000000000000, exp = 3
* frexp(NAN, &exp) = nan, exp = 3
* frexp(-NAN, &exp) = -nan, exp = 3
* frexp(INFINITY, &exp) = inf, exp = 3
* frexp(-INFINITY, &exp) = -inf, exp = 3
* */
Parent topic: Exponential and Logarithmic Functions