CKTIS / C
frexp — C23 mathematical function
`frexp(value, exp)` from `<math.h>` decomposes a finite value so `value == fraction * 2^*exp`; for a nonzero result, the fraction magnitude lies in `[0.5, 1)`. It returns the fraction and stores the exponent through the valid `exp` pointer.
Version: C23
Syntax
double frexp(double value, int *exp);frexp(value, exp) from <math.h> decomposes a finite value so value == fraction * 2^*exp; for a nonzero result, the fraction magnitude lies in [0.5, 1). It returns the fraction and stores the exponent through the valid exp pointer.
The example decomposes 40.0 and -8.0. Output 0.625 6 -0.500 4 demonstrates exact reconstructions 0.625*64 and -0.5*16, with the sign retained in the fraction.
For zero, the function returns zero and stores zero as exponent; the output pointer must be valid. frexpf and frexpl serve other types. Annex F specifies NaN and infinity propagation with an unspecified exponent; do not use that exponent to reconstruct a finite value.
Examples
#include <math.h>
#include <stdio.h>
int main(void){int a=0,b=0;double x=frexp(40.0,&a),y=frexp(-8.0,&b);printf("%.3f %d %.3f %d\n",x,a,y,b);return 0;}
Result
0.625 6 -0.500 4
The example decomposes `40.0` and `-8.0`. Output `0.625 6 -0.500 4` demonstrates exact reconstructions `0.625*64` and `-0.5*16`, with the sign retained in the fraction.