dblround.c
来自「由8051/8096/8099/8048单片机汇编工具、 汇编语言、摩托罗拉m」· C语言 代码 · 共 36 行
C
36 行
/*
** DBLROUND.C - Rounds a double to the nearest whole number
** public domain by Ross Cottrell
*/
#include <float.h>
#include <limits.h>
#include <assert.h>
double round(double x)
{
assert(1 == FLT_ROUNDS);
x += 1.0 / DBL_EPSILON;
return x - 1.0 / DBL_EPSILON;
}
#ifdef TEST
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
double val;
char *dummy;
while (--argc)
{
val = strtod((const char *)(*(++argv)), &dummy);
printf("round(%g) = ", val);
printf("%.12g\n", round(val));
}
}
#endif /* TEST */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?