rintのヘルプ・マニュアル
日本語 英語
rint --help
man rint
RINT(3) Linux Programmer’s Manual RINT(3)
名前
nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl - 最も近い整数に
丸める
書式
#include
double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x);
double rint(double x);
float rintf(float x);
long double rintl(long double x);
-lm でリンクする。
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
nearbyint(), nearbyintf(), nearbyintl(): _XOPEN_SOURCE >= 600 ||
_ISOC99_SOURCE; or cc -std=c99
rint(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
_ISOC99_SOURCE; or cc -std=c99
rintf(), rintl(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600
|| _ISOC99_SOURCE; or cc -std=c99
説明
nearbyint() 関数群は、現在の丸め方向 (fesetround(3) 参照) で引き数を浮
動小数点形式の整数に丸める。 inexact 例外を出さない。
rint() 関数群も同じような動作をするが、結果が引き数と異なる場合に inex-
act 例外 (FE_INEXACT) を出す (この例外は fetestexcept(3) 経由で確認可
能)。
返り値
これらの関数は丸めた整数値を返す。
x が整数、+0、-0、NaN、無限大のいずれかの場合、 x そのものを返す。
エラー
エラーは発生しない。 POSIX.1-2001 にはオーバーフローでの 範 囲 エ ラ ー
(range error) の記載がある。「注意」の節を参照のこと。
準拠
C99, POSIX.1-2001.
注意
SUSv2 と POSIX.1-2001 にはオーバーフローに関する記述があり、オーバーフ
ローの場合には、 errno を ERANGE に設定するか、 FE_OVERFLOW 例外を発 生
す ることとされている。実際のところ、どの現行のマシンでも結果がオーバー
フローを起こすことはないので、このエラー処理は意味がない。 (より正確 に
言 うと、オーバーフローは指数部の最大値が仮数部を表すビットの数より小さ
い場合にしか起こらない。 IEEE-754 規格の 32 ビットと 64 ビットの浮動 小
数では、指数部の最大値はそれぞれ 128 と 1024 であり、仮数部のビット数は
それぞれ 24 と 53 である。)
丸めた値を整数型に格納した場合には、おそらくこの関数ではな く lrint(3)
に載っている関数のどれかを使いたいのだろう。
関連項目
ceil(3), floor(3), lrint(3), round(3), trunc(3)
2008-08-05 RINT(3)
RINT(3) Linux Programmer’s Manual RINT(3)
NAME
nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl - round to near-
est integer
SYNOPSIS
#include
double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x);
double rint(double x);
float rintf(float x);
long double rintl(long double x);
Link with -lm.
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
nearbyint(), nearbyintf(), nearbyintl(): _XOPEN_SOURCE >= 600 ||
_ISOC99_SOURCE; or cc -std=c99
rint(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
_ISOC99_SOURCE; or cc -std=c99
rintf(), rintl(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 600
|| _ISOC99_SOURCE; or cc -std=c99
DESCRIPTION
The nearbyint() functions round their argument to an integer value in
floating-point format, using the current rounding direction (see fes-
etround(3)) and without raising the inexact exception.
The rint() functions do the same, but will raise the inexact exception
(FE_INEXACT, checkable via fetestexcept(3)) when the result differs in
value from the argument.
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.
CONFORMING TO
C99, POSIX.1-2001.
NOTES
SUSv2 and POSIX.1-2001 contain 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 maximum value of the exponent is smaller than the number of man-
tissa 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 number 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 lrint(3) instead.
SEE ALSO
ceil(3), floor(3), lrint(3), round(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-05 RINT(3)