Namespaces
Variants

roundeven, roundevenf, roundevenl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
roundeven
(C23)
(C99)

(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
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
Arguments and return values
Error handling
Fast operation indicators
헤더 파일에 정의됨 <math.h>
float roundevenf ( float arg ) ;
(1) (C23부터)
double roundeven ( double arg ) ;
(2) (C23부터)
long double roundevenl ( long double arg ) ;
(3) (C23부터)
헤더 파일에 정의됨 <tgmath.h>
#define roundeven( arg )
(4) (C23부터)
1-3) arg (부동 소수점 형식)에 가장 가까운 정수 값을 계산하며, 중간 값의 경우 현재 반올림 모드와 관계없이 가장 가까운 짝수 정수로 반올림합니다.
4) 타입-제네릭 매크로: 만약 arg long double 타입을 가지면, roundevenl 가 호출됩니다. 그렇지 않고 arg 가 정수 타입이나 double 타입을 가지면, roundeven 가 호출됩니다. 그 외의 경우에는 각각 roundevenf 가 호출됩니다.

목차

매개변수

arg - 부동소수점 값

반환값

오류가 발생하지 않으면, 가장 가까운 정수 값으로 arg 를 반환하며(중간 값은 가장 가까운 짝수 정수로 반올림).

오류 처리

이 함수는 math_errhandling 에 지정된 어떤 오류에도 영향을 받지 않습니다.

구현체가 IEEE 부동 소수점 연산(IEC 60559)을 지원하는 경우:

  • FE_INEXACT 는 절대 발생하지 않습니다.
  • 만약 arg 가 ±∞이면, 수정 없이 그대로 반환됩니다.
  • 만약 arg 가 ±0이면, 수정 없이 그대로 반환됩니다.
  • 만약 arg 가 NaN이면, NaN이 반환됩니다.

예제

#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));
}

가능한 출력:

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

참고문헌

  • C23 표준 (ISO/IEC 9899:2024):
  • 7.12.9.8 roundeven 함수들 (p: 265-266)
  • 7.27 타입-제네릭 수학 <tgmath.h> (p: 386-390)
  • F.10.6.8 roundeven 함수들 (p: 532)

참고 항목

(C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99)
현재 반올림 모드를 사용하여 정수로 반올림하며,
결과가 다를 경우 예외를 발생시킴
(함수)
(C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99)
가장 가까운 정수로 반올림하며, 중간값인 경우 0에서 멀어지는 방향으로 반올림
(함수)