fegetround, fesetround
提供: cppreference.com
ヘッダ <fenv.h> で定義
|
||
int fesetround( int round ); |
(1) | (C99以上) |
int fegetround(); |
(2) | (C99以上) |
1) 引数 round
と等しい浮動小数点の丸め方向の確立を試みます。 round
は浮動小数点丸めマクロのひとつであることが期待されます。
2) 現在の丸め方向に対応する浮動小数点丸めマクロの値を返します。
目次 |
[編集] 引数
round | - | 丸め報告、浮動小数点丸めマクロのひとつ |
[編集] 戻り値
1) 成功した場合は 0、そうでなければ非ゼロ。
2) 現在の丸め方向を表す浮動小数点丸めマクロ、または方向が決められない場合は負の値。
[編集] ノート
最も最近の fesetround
の効果を反映する現在の丸めモードは、 FLT_ROUNDS で問い合わせることもできます。
[編集] 例
Run this code
#include <stdio.h> #include <math.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON void show_fe_current_rounding_method(void) { printf("current rounding method: "); switch (fegetround()) { case FE_TONEAREST: printf ("FE_TONEAREST"); break; case FE_DOWNWARD: printf ("FE_DOWNWARD"); break; case FE_UPWARD: printf ("FE_UPWARD"); break; case FE_TOWARDZERO: printf ("FE_TOWARDZERO"); break; default: printf ("unknown"); }; printf("\n"); } int main(void) { /* Default rounding method */ show_fe_current_rounding_method(); printf("+11.5 -> %+4.1f\n", rint(+11.5)); /* midway between two integers */ printf("+12.5 -> %+4.1f\n", rint(+12.5)); /* midway between two integers */ /* Save current rounding method. */ int curr_method = fegetround(); /* Temporarily change current rounding method. */ fesetround(FE_DOWNWARD); show_fe_current_rounding_method(); printf("+11.5 -> %+4.1f\n", rint(+11.5)); printf("+12.5 -> %+4.1f\n", rint(+12.5)); /* Restore default rounding method. */ fesetround(curr_method); show_fe_current_rounding_method(); return 0; }
出力例:
current rounding method: FE_TONEAREST +11.5 -> +12.0 +12.5 -> +12.0 current rounding method: FE_DOWNWARD +11.5 -> +11.0 +12.5 -> +12.0 current rounding method: FE_TONEAREST
[編集] 参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.6.3.1 The fegetround function (p: 212)
- 7.6.3.2 The fesetround function (p: 212-213)
- C99 standard (ISO/IEC 9899:1999):
- 7.6.3.1 The fegetround function (p: 193)
- 7.6.3.2 The fesetround function (p: 193-194)
[編集] 関連項目
(C99)(C99)(C99) |
現在の丸めモードを使用して整数に丸めます (関数) |
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
現在の丸めモードを使用して整数に丸めますが、結果が異なる場合は例外を発生します (関数) |
fegetround, fesetround の C++リファレンス
|