frexp, frexpf, frexpl

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Types
(哋它亢99)(哋它亢99)    

(哋它亢99)(哋它亢99)    
(哋它亢23)(哋它亢23)

Functions
Basic operations
(哋它亢99)(哋它亢99)
(哋它亢99)(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢23)
Maximum/minimum operations
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)    
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Exponential functions
(哋它亢23)
(哋它亢99)
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢99)
(哋它亢99)(哋它亢23)
(哋它亢23)
(哋它亢23)
Power functions
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Trigonometric and hyperbolic functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢99)
(哋它亢99)
(哋它亢99)
Error and gamma functions
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
Nearest integer floating-point operations
(哋它亢99)(哋它亢99)(哋它亢99)
(哋它亢23)
(哋它亢99)
(哋它亢99)
(哋它亢99)(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
Floating-point manipulation functions
frexp
(哋它亢99)(哋它亢99)
(哋它亢99)(哋它亢23)
(哋它亢99)
(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)
(哋它亢99)
(哋它亢23)
Narrowing operations
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Quantum and quantum exponent functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Decimal re-encoding functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Total order and payload functions
(哋它亢23)
(哋它亢23)
(哋它亢23)
(哋它亢23)
Classification
(哋它亢99)
(哋它亢23)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢23)
(哋它亢23)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢99)
(哋它亢23)
(哋它亢23)
Macro constants
Special floating-point values
(哋它亢99)(哋它亢99)(哋它亢23)
(哋它亢99)(哋它亢23)
(哋它亢99)(哋它亢23)
Arguments and return values
(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)    
(哋它亢23)(哋它亢23)
(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢99)(哋它亢99)    
Error handling
(哋它亢99)(哋它亢99)
(哋它亢99)    

Fast operation indicators
(哋它亢99)(哋它亢99)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)    
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢99)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
(哋它亢23)(哋它亢23)(哋它亢23)(哋它亢23)
 
Defined in header <math.h>
float       frexpf( float arg, int* exp );
(1) (since 哋它亢99)
double      frexp( double arg, int* exp );
(2)
long double frexpl( long double arg, int* exp );
(3) (since 哋它亢99)
Defined in header <tgmath.h>
#define frexp( arg, exp )
(4) (since 哋它亢99)
1-3) Decomposes given floating-point value x into a normalized fraction and an integral power of two.
4) Type-generic macro: If arg has type long double, frexpl is called. Otherwise, if arg has integer type or the type double, frexp is called. Otherwise, frexpf is called, respectively.

Parameters

arg - floating-point value
exp - pointer to integer value to store the exponent to

Return value

If arg is zero, returns zero and stores zero in *exp.

Otherwise (if arg is not zero), if no errors occur, returns the value x in the range (-1;-0.5], [0.5; 1) and stores an integer value in *exp such that x×2(*exp)
=arg
.

If the value to be stored in *exp is outside the range of int, the behavior is unspecified.

If arg is not a floating-point number, the behavior is unspecified.

Error handling

This function is not subject to any errors specified in math_errhandling.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • If arg is ±0, it is returned, unmodified, and 0 is stored in *exp.
  • If arg is ±∞, it is returned, and an unspecified value is stored in *exp.
  • If arg is NaN, NaN is returned, and an unspecified value is stored in *exp.
  • No floating-point exceptions are raised.
  • If FLT_RADIX is 2 (or a power of 2), the returned value is exact, the current rounding mode is ignored.

Notes

On a binary system (where FLT_RADIX is 2), frexp may be implemented as

{
    *exp = (value == 0) ? 0 : (int)(1 + logb(value));
    return scalbn(value, -(*exp));
}

The function frexp, together with its dual, ldexp, can be used to manipulate the representation of a floating-point number without direct bit manipulations.

Example

#include <float.h>
#include <math.h>
#include <stdio.h>
 
int main(void)
{
    double f = 123.45;
    printf("Given the number %.2f or %a in hex,\n", f, f);
 
    double f3;
    double f2 = modf(f, &f3);
    printf("modf() makes %.0f + %.2f\n", f3, f2);
 
    int i;
    f2 = frexp(f, &i);
    printf("frexp() makes %f * 2^%d\n", f2, i);
 
    i = ilogb(f);
    printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i);
}

Possible output:

Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,
modf() makes 123 + 0.45
frexp() makes 0.964453 * 2^7
logb()/ilogb() make 1.92891 * 2^6

References

  • 哋它亢23 standard (ISO/IEC 9899:2023):
  • 7.12.6.4 The frexp functions (p: TBD)
  • 7.25 Type-generic math <tgmath.h> (p: TBD)
  • F.10.3.4 The frexp functions (p: TBD)
  • 哋它亢17 standard (ISO/IEC 9899:2018):
  • 7.12.6.4 The frexp functions (p: TBD)
  • 7.25 Type-generic math <tgmath.h> (p: TBD)
  • F.10.3.4 The frexp functions (p: TBD)
  • 哋它亢11 standard (ISO/IEC 9899:2011):
  • 7.12.6.4 The frexp functions (p: 243)
  • 7.25 Type-generic math <tgmath.h> (p: 373-375)
  • F.10.3.4 The frexp functions (p: 521)
  • 哋它亢99 standard (ISO/IEC 9899:1999):
  • 7.12.6.4 The frexp functions (p: 224)
  • 7.22 Type-generic math <tgmath.h> (p: 335-337)
  • F.9.3.4 The frexp functions (p: 458)
  • 哋它亢89/C90 standard (ISO/IEC 9899:1990):
  • 4.5.4.2 The frexp function

See also

(哋它亢99)(哋它亢99)
multiplies a number by 2 raised to a power
(function)
(哋它亢99)(哋它亢99)(哋它亢99)
extracts exponent of the given number
(function)
(哋它亢99)(哋它亢99)(哋它亢99)
extracts exponent of the given number
(function)
(哋它亢99)(哋它亢99)
breaks a number into integer and fractional parts
(function)