?
This document uses PHP Chinese website manual Release
在頭文件<fenv.h>中定義 | ||
---|---|---|
int fesetround(int round); | (1) | (自C99以來) |
int fegetround(); | (2) | (自C99以來) |
1)嘗試建立等于參數參數輪的浮點舍入方向,該循環(huán)方向預計是浮點舍入宏之一。
2)返回對應于當前舍入方向的浮點舍入宏的值。
round | - | rounding direction, one of floating point rounding macros |
---|
1)成功時為0,否則為非零。
2)描述當前舍入方向的浮點舍入宏,或者如果方向不能確定,則為負值。
當前的舍入模式反映了最近的情況,也可以用FLT_ROUNDS查詢。
#include <stdio.h>#include <math.h>#include <fenv.h> #pragma STDC FENV_ACCESS ONvoid 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.0current rounding method: FE_DOWNWARD+11.5 -> +11.0+12.5 -> +12.0current rounding method: FE_TONEAREST
C11標準(ISO / IEC 9899:2011):
7.6.3.1 fegetround函數(p:212)
7.6.3.2 fesetround函數(p:212-213)
C99標準(ISO / IEC 9899:1999):
7.6.3.1 fegetround函數(p:193)
7.6.3.2 fesetround函數(p:193-194)
(C99)(C99)(C99) | 使用當前舍入模式(函數)舍入為整數 |
---|---|
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) | 使用當前舍入模式舍入為整數,除非結果不同(函數) |
| 用于fegetround,fesetround的C ++文檔 |