Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      roundeven, roundevenf, roundevenl

      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)
      roundeven
      (C23)
      (C99)

      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      (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       roundevenf(float arg);
      (1)(since C23)
      double      roundeven(double arg);
      (2)(since C23)
      longdouble roundevenl(longdouble arg);
      (3)(since C23)
      Defined in header<tgmath.h>
      #define roundeven( arg )
      (4)(since C23)
      1-3) Computes the nearest integer value toarg (in floating-point format), rounding halfway cases to nearest even integer, regardless of the current rounding mode.
      4) Type-generic macro: Ifarg has typelongdouble,roundevenl is called. Otherwise, ifarg has integer type or the typedouble,roundeven is called. Otherwise,roundevenf is called, respectively.

      Contents

      [edit]Parameters

      arg - floating-point value

      [edit]Return value

      If no errors occur, the nearest integer value toarg, rounding halfway cases to nearest even integer, is returned.

      [edit]Error handling

      This function is not subject to any of the errors specified inmath_errhandling.

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

      • FE_INEXACT is never raised.
      • Ifarg is ±∞, it is returned, unmodified.
      • Ifarg is ±0, it is returned, unmodified.
      • Ifarg is NaN, NaN is returned.

      [edit]Example

      Run this code
      #include <math.h>#include <stdio.h> int main(void){printf("roundeven(+2.4) = %+.1f\n", roundeven(2.4));printf("roundeven(-2.4) = %+.1f\n", roundeven(-2.4));printf("roundeven(+2.5) = %+.1f\n", roundeven(2.5));printf("roundeven(-2.5) = %+.1f\n", roundeven(-2.5));printf("roundeven(+2.6) = %+.1f\n", roundeven(2.6));printf("roundeven(-2.6) = %+.1f\n", roundeven(-2.6));printf("roundeven(+3.5) = %+.1f\n", roundeven(3.5));printf("roundeven(-3.5) = %+.1f\n", roundeven(-3.5));printf("roundeven(-0.0) = %+.1f\n", roundeven(-0.0));printf("roundeven(-Inf) = %+f\n",   roundeven(-INFINITY));}

      Possible output:

      roundeven(+2.4) = +2.0roundeven(-2.4) = -2.0roundeven(+2.5) = +2.0roundeven(-2.5) = -2.0roundeven(+2.6) = +3.0roundeven(-2.6) = -3.0roundeven(+3.5) = +4.0roundeven(-3.5) = -4.0roundeven(-0.0) = -0.0roundeven(-Inf) = -inf

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.12.9.8 The roundeven functions (p: 265-266)
      • 7.27 Type-generic math <tgmath.h> (p: 386-390)
      • F.10.6.8 The roundeven functions (p: 532)

      [edit]See also

      (C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)
      rounds to an integer using current rounding mode with
      exception if the result differs
      (function)[edit]
      (C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)
      rounds to nearest integer, rounding away from zero in halfway cases
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/roundeven&oldid=172060"

      [8]ページ先頭

      ©2009-2025 Movatter.jp