C語言math頭文件(math.h)中llrint函數的用法及代碼示例。
用法:
long long int llrint (double x);
long long int llrintf (float x);
long long int llrintl (long double x);
舍入並轉換為long long整數
long long int
。看lrint對於返回a的等效函數
long int
。標頭<tgmath.h>提供此函數的type-generic宏版本。
參數
- x
- 取舍價值。
返回值
的價值x四舍五入為附近的整數,轉換為類型的值long long int
。如果四舍五入的值超出了返回類型的範圍,則返回的值未指定,並且域錯誤或溢出範圍誤差可能會發生(或不發生,具體取決於實現方式)。
如果一個域錯誤發生:
- 和math_errhandling已MATH_ERRNO設置:全局變量errno被設定為EDOM。
- 和math_errhandling已MATH_ERREXCEPT設置:FE_INVALID被拋出
如果溢出範圍誤差發生:
- 和math_errhandling已MATH_ERRNO設置:全局變量errno被設定為ERANGE。
- 和math_errhandling已MATH_ERREXCEPT設置:FE_OVERFLOW被拋出
示例
/* llrint example */
#include <stdio.h> /* printf */
#include <fenv.h> /* fegetround, FE_* */
#include <math.h> /* llrint */
int main ()
{
printf ("rounding using ");
switch (fegetround()) {
case FE_DOWNWARD: printf ("downward"); break;
case FE_TONEAREST: printf ("to-nearest"); break;
case FE_TOWARDZERO: printf ("toward-zero"); break;
case FE_UPWARD: printf ("upward"); break;
default: printf ("unknown");
}
printf (" rounding:\n");
printf ( "llrint (2.3) = %lld\n", llrint(2.3) );
printf ( "llrint (3.8) = %lld\n", llrint(3.8) );
printf ( "llrint (-2.3) = %lld\n", llrint(-2.3) );
printf ( "llrint (-3.8) = %lld\n", llrint(-3.8) );
return 0;
}
可能的輸出:
Rounding using to-nearest rounding: llrint (2.3) = 2 llrint (3.8) = 4 llrint (-2.3) = -2 llrint (-3.8) = -4 |
相關用法
- C語言 cos用法及代碼示例
- C語言 sin用法及代碼示例
- C語言 tan用法及代碼示例
- C語言 acos用法及代碼示例
- C語言 asin用法及代碼示例
- C語言 atan用法及代碼示例
- C語言 atan2用法及代碼示例
- C語言 cosh用法及代碼示例
- C語言 sinh用法及代碼示例
- C語言 tanh用法及代碼示例
- C語言 acosh用法及代碼示例
- C語言 asinh用法及代碼示例
- C語言 atanh用法及代碼示例
- C語言 exp用法及代碼示例
- C語言 frexp用法及代碼示例
- C語言 ldexp用法及代碼示例
- C語言 log用法及代碼示例
- C語言 log10用法及代碼示例
- C語言 modf用法及代碼示例
- C語言 exp2用法及代碼示例
- C語言 expm1用法及代碼示例
- C語言 ilogb用法及代碼示例
- C語言 log1p用法及代碼示例
- C語言 log2用法及代碼示例
- C語言 logb用法及代碼示例
- C語言 scalbn用法及代碼示例
- C語言 scalbln用法及代碼示例
- C語言 pow用法及代碼示例
- C語言 sqrt用法及代碼示例
- C語言 cbrt用法及代碼示例
- C語言 hypot用法及代碼示例
- C語言 erf用法及代碼示例
- C語言 erfc用法及代碼示例
- C語言 tgamma用法及代碼示例
- C語言 lgamma用法及代碼示例
- C語言 ceil用法及代碼示例
- C語言 floor用法及代碼示例
- C語言 fmod用法及代碼示例
- C語言 trunc用法及代碼示例
- C語言 round用法及代碼示例
- C語言 lround用法及代碼示例
- C語言 llround用法及代碼示例
- C語言 rint用法及代碼示例
- C語言 lrint用法及代碼示例
- C語言 nearbyint用法及代碼示例
- C語言 remainder用法及代碼示例
- C語言 remquo用法及代碼示例
- C語言 copysign用法及代碼示例
- C語言 nextafter用法及代碼示例
- C語言 nexttoward用法及代碼示例
- C語言 fdim用法及代碼示例
- C語言 fmax用法及代碼示例
- C語言 fmin用法及代碼示例
- C語言 fabs用法及代碼示例
- C語言 abs用法及代碼示例
- C語言 fma用法及代碼示例
- C語言 isfinite用法及代碼示例
- C語言 isgreater用法及代碼示例
- C語言 isgreaterequal用法及代碼示例
- C語言 isless用法及代碼示例
- C語言 islessequal用法及代碼示例
- C語言 islessgreater用法及代碼示例
- C語言 isunordered用法及代碼示例
注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C llrint function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。