roundのヘルプ・マニュアル
日本語 英語
round --help
man round
ROUND(3) Linux Programmer’s Manual ROUND(3)
名前
round, roundf, roundl - 最も近い整数値に丸める (2 つの整数の中間値の場
合は 0 から遠い方に丸める)
書式
#include
double round(double x);
float roundf(float x);
long double roundl(long double x);
-lm でリンクする。
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
round(), roundf(), roundl(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or
cc -std=c99
説明
こ れらの関数は x を最も近い整数値に丸める。 2 つの整数の中間値の場合は
、 rint(3) のように最も近い偶数に丸めたりせずに、 (現在の丸め方向に関係
なく) 0 から遠い方に丸める (丸め方向については fenv(3) を参照)。
例えば、 round(0.5) は 1.0 で、 round(-0.5) は -1.0 である。
返り値
これらの関数は丸めた整数値を返す。
x が整数、+0、-0、NaN、無限のいずれかの場合、 x そのものが返される。
エラー
エ ラ ー は 発 生しない。 POSIX.1-2001 にはオーバーフローでの範囲エラー
(range error) の記載がある。「注意」の節を参照のこと。
バージョン
これらの関数は glibc バージョン 2.1 で初めて登場した。
準拠
C99, POSIX.1-2001.
注意
POSIX.1-2001 にはオーバーフローに関する記述があり、オーバーフローの場合
に は、 errno を ERANGE に設定するか、 FE_OVERFLOW 例外を発生することと
されている。実際のところ、どの現行のマシンでは結果がオーバーフローを 起
こ すことはないので、このエラー処理は意味がない。 (より正確に言うと、オ
ーバーフローは指数部の最大値が仮数部を表すビットの数より小さい場合に し
か 起こらない。 IEEE-754 規格の 32 ビットと 64 ビットの浮動小数では、指
数部の最大値はそれぞれ 128 と 1024 であり、仮数部のビット数はそれ ぞ れ
24 と 53 である。)
丸 めた値を整数型に格納した場合には、おそらくこの関数ではなく lround(3)
に載っている関数のどれかを使いたいのだろう。
関連項目
ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
2008-08-11 ROUND(3)
ROUND(3) Linux Programmer’s Manual ROUND(3)
NAME
round, roundf, roundl - round to nearest integer, away from zero
SYNOPSIS
#include
double round(double x);
float roundf(float x);
long double roundl(long double x);
Link with -lm.
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
round(), roundf(), roundl(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or
cc -std=c99
DESCRIPTION
These functions round x to the nearest integer, but round halfway cases
away from zero (regardless of the current rounding direction, see
fenv(3)), instead of to the nearest even integer like rint(3).
For example, round(0.5) is 1.0, and round(-0.5) is -1.0.
RETURN VALUE
These functions return the rounded integer value.
If x is integral, +0, -0, NaN, or infinite, x itself is returned.
ERRORS
No errors occur. POSIX.1-2001 documents a range error for overflows,
but see NOTES.
VERSIONS
These functions first appeared in glibc in version 2.1.
CONFORMING TO
C99, POSIX.1-2001.
NOTES
POSIX.1-2001 contains text about overflow (which might set errno to
ERANGE, or raise an FE_OVERFLOW exception). In practice, the result
cannot overflow on any current machine, so this error-handling stuff is
just nonsense. (More precisely, overflow can happen only when the max-
imum value of the exponent is smaller than the number of mantissa bits.
For the IEEE-754 standard 32-bit and 64-bit floating-point numbers the
maximum value of the exponent is 128 (respectively, 1024), and the num-
ber of mantissa bits is 24 (respectively, 53).)
If you want to store the rounded value in an integer type, you probably
want to use one of the functions described in lround(3) instead.
SEE ALSO
ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2008-08-11 ROUND(3)