Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      frexp, frexpf, frexpl

      From cppreference.com
      <c‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Functions
      Basic operations
      (C99)
      (C99)
      (C99)
      (C99)(C99)(C99)(C23)
      Maximum/minimum operations
      (C99)
      (C99)
      Exponential functions
      (C23)
      (C99)
      (C99)
      (C23)
      (C23)

      (C99)
      (C99)(C23)
      (C23)
      (C23)
      Power functions
      (C99)
      (C23)
      (C23)

      (C99)
      (C23)
      (C23)
      Trigonometric and hyperbolic functions
      (C23)
      (C23)
      (C23)
      (C23)
      (C99)
      (C99)
      (C99)
      Nearest integer floating-point
      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      frexp
      (C99)(C99)
      (C99)(C23)
      (C99)
      Narrowing operations
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      (C23)
      Quantum and quantum exponent
      Decimal re-encoding functions
      Total order and payload functions
      Classification
      Error and gamma functions
      (C99)
      (C99)
      (C99)
      (C99)
      Types
      Macro constants
      Special floating-point values
      (C99)(C23)
      Arguments and return values
      Error handling
      Fast operation indicators
       
      Defined in header<math.h>
      float       frexpf(float arg,int*exp);
      (1)(since C99)
      double      frexp(double arg,int*exp);
      (2)
      longdouble frexpl(longdouble arg,int*exp);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define frexp( arg, exp )
      (4)(since C99)
      1-3) Decomposes given floating-point valuex into a normalized fraction and an integral power of two.
      4) Type-generic macro: Ifarg has typelongdouble,frexpl is called. Otherwise, ifarg has integer type or the typedouble,frexp is called. Otherwise,frexpf is called, respectively.

      Contents

      [edit]Parameters

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

      [edit]Return value

      Ifarg is zero, returns zero and stores zero in*exp.

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

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

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

      [edit]Error handling

      This function is not subject to any errors specified inmath_errhandling.

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

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

      [edit]Notes

      On a binary system (whereFLT_RADIX is2),frexp may be implemented as

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

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

      [edit]Example

      Run this code
      #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.45frexp() makes 0.964453 * 2^7logb()/ilogb() make 1.92891 * 2^6

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 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)
      • C17 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)
      • C11 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)
      • C99 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)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 4.5.4.2 The frexp function

      [edit]See also

      multiplies a number by2 raised to a power
      (function)[edit]
      (C99)(C99)(C99)
      extracts exponent of the given number
      (function)[edit]
      (C99)(C99)(C99)
      extracts exponent of the given number
      (function)[edit]
      (C99)(C99)
      breaks a number into integer and fractional parts
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/frexp&oldid=172021"

      [8]ページ先頭

      ©2009-2025 Movatter.jp