round, roundf, roundl, roundd32, roundd64, or roundd128 Subroutine

Purpose

Rounds to the nearest integer value in a floating-point format.

Syntax

#include <math.h>

double round (x)
double x;

float roundf (x)
float x;

long double roundl (x)
long double x;

_Decimal32 roundd32(x)
_Decimal32 x;

_Decimal64 roundd64(x)
_Decimal64 x;

_Decimal128 roundd128(x)
_Decimal128 x;

Description

The round, roundf, roundl, roundd32, roundd64, and roundd128 subroutines round the x parameter to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.

An application wishing to check for error situations should set the errno global variable to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. Upon return, if errno is nonzero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, an error has occurred.

Parameters

Item Description
x Specifies the value to be rounded.

Return Values

Upon successful completion, the round, roundf, roundl, roundd32, roundd64, and roundd128 subroutines return the rounded integer value.

If x is NaN, a NaN is returned.

If x is ±0 or ±Inf, x is returned.

If the correct value would cause overflow, a range error occurs and the round, roundf, roundl, roundd32, roundd64, and roundd128 subroutines return the value of the macro ±HUGE_VAL, ±HUGE_VALF, ±HUGE_VALL, ±HUGE_VAL_D32, ±HUGE_VAL_D64 and ±HUGE_VAL_D128 (with the same sign as x), respectively.