Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      scalbn, scalbnf, scalbnl, scalbln, scalblnf, scalblnl

      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
      scalbnscalbln
      (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       scalbnf(float arg,intexp);
      (1)(since C99)
      double      scalbn(double arg,intexp);
      (2)(since C99)
      longdouble scalbnl(longdouble arg,intexp);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define scalbn( arg, exp )
      (4)(since C99)
      Defined in header<math.h>
      float       scalblnf(float arg,longexp);
      (5)(since C99)
      double      scalbln(double arg,longexp);
      (6)(since C99)
      longdouble scalblnl(longdouble arg,longexp);
      (7)(since C99)
      Defined in header<tgmath.h>
      #define scalbln( arg, exp )
      (8)(since C99)
      1-3,5-7) Multiplies a floating-point valuearg byFLT_RADIX raised to powerexp.
      4,8) Type-generic macros: Ifarg has typelongdouble,scalbnl orscalblnl is called. Otherwise, ifarg has integer type or the typedouble,scalbn orscalbln is called. Otherwise,scalbnf orscalblnf is called, respectively.

      Contents

      [edit]Parameters

      arg - floating-point value
      exp - integer value

      [edit]Return value

      If no errors occur,arg multiplied byFLT_RADIX to the power ofexp (arg×FLT_RADIXexp
      ) is returned.

      If a range error due to overflow occurs,±HUGE_VAL,±HUGE_VALF, or±HUGE_VALL is returned.

      If a range error due to underflow occurs, the correct result (after rounding) is returned.

      [edit]Error handling

      Errors are reported as specified inmath_errhandling.

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

      • Unless a range error occurs,FE_INEXACT is never raised (the result is exact).
      • Unless a range error occurs, thecurrent rounding mode is ignored.
      • Ifarg is ±0, it is returned, unmodified.
      • Ifarg is ±∞, it is returned, unmodified.
      • Ifexp is 0, thenarg is returned, unmodified.
      • Ifarg is NaN, NaN is returned.

      [edit]Notes

      On binary systems (whereFLT_RADIX is2),scalbn is equivalent toldexp.

      Althoughscalbn andscalbln are specified to perform the operation efficiently, on many implementations they are less efficient than multiplication or division by a power of two using arithmetic operators.

      Thescalbln function is provided because the factor required to scale from the smallest positive floating-point value to the largest finite one may be greater than32767, the standard-guaranteedINT_MAX. In particular, for the 80-bitlongdouble, the factor is32828.

      [edit]Example

      Run this code
      #include <errno.h>#include <fenv.h>#include <float.h>#include <math.h>#include <stdio.h> // #pragma STDC FENV_ACCESS ON int main(void){printf("scalbn(7, -4) = %f\n", scalbn(7,-4));printf("scalbn(1, -1074) = %g (minimum positive subnormal double)\n",            scalbn(1,-1074));printf("scalbn(nextafter(1,0), 1024) = %g (largest finite double)\n",            scalbn(nextafter(1,0),1024)); // special valuesprintf("scalbn(-0, 10) = %f\n", scalbn(-0.0,10));printf("scalbn(-Inf, -1) = %f\n", scalbn(-INFINITY,-1)); // error handlingerrno=0;feclearexcept(FE_ALL_EXCEPT);printf("scalbn(1, 1024) = %f\n", scalbn(1,1024));if(errno==ERANGE)perror("    errno == ERANGE");if(fetestexcept(FE_OVERFLOW))puts("    FE_OVERFLOW raised");}

      Possible output:

      scalbn(7, -4) = 0.437500scalbn(1, -1074) = 4.94066e-324 (minimum positive subnormal double)scalbn(nextafter(1,0), 1024) = 1.79769e+308 (largest finite double)scalbn(-0, 10) = -0.000000scalbn(-Inf, -1) = -infscalbn(1, 1024) = inf    errno == ERANGE: Numerical result out of range    FE_OVERFLOW raised

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.12.6.13 The scalbn functions (p: TBD)
      • 7.25 Type-generic math <tgmath.h> (p: TBD)
      • F.10.3.13 The scalbn functions (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.12.6.13 The scalbn functions (p: TBD)
      • 7.25 Type-generic math <tgmath.h> (p: TBD)
      • F.10.3.13 The scalbn functions (p: TBD)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.12.6.13 The scalbn functions (p: 247)
      • 7.25 Type-generic math <tgmath.h> (p: 373-375)
      • F.10.3.13 The scalbn functions (p: 523)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.12.6.13 The scalbn functions (p: 228)
      • 7.22 Type-generic math <tgmath.h> (p: 335-337)
      • F.9.3.13 The scalbn functions (p: 460)

      [edit]See also

      breaks a number into significand and a power of2
      (function)[edit]
      multiplies a number by2 raised to a power
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/scalbn&oldid=172061"

      [8]ページ先頭

      ©2009-2025 Movatter.jp