home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
s
/
snip1292.zip
/
DBLROUND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-26
|
632b
|
35 lines
/*
** DBLROUND.C - Rounds a double to the nearest whole number
** public domain by Ross Cottrell
*/
#include <float.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 */