Mail Archives: djgpp/1999/05/29/20:13:33
In a message dated 5/29/99 7:03:52 PM EST, klaas AT ns DOT sympatico DOT ca writes:
> How about:
> #define ROUND(x) ((x) + SGN(x)*0.5)
Looks good to me. Probably what you could do also is
sgn(x) * ((int) fabs(x) + 0.5)
The reason is simple. There is a discontinuity about 0.
0.6 -> 1
0.6-1 = -0.4 -> -1 using your rule (or my previous which is the same)
so now the delta between the integer numbers of 0.6 and -0.4 is 2
which seems incorrect considering the true delta is 1.0. This is what
you need to watch for in any case.
- Raw text -