Hi everyone, I believe that there is a small bug in src/port/rint.c when the input parameter has a fractional part of 0.5 which is demonstrated by the attached program. It appears that the PG version of rint() rounds in the wrong direction with respect to glibc.
[EMAIL PROTECTED]:~$ ./test rint(-1.5): -2.000000 pg_rint(-1.5): -1.000000 rint(1.5): 2.000000 pg_rint(1.5): 1.000000 The fix is, of course, to add an equals into the if() comparisons on lines 21 and 26, so that when the fractional part is 0.5, it rounds in the opposite direction instead. I'm sure that this will have practically zero effect on the code, however it may be worth applying for correctness and consistency with other platform implementations. ATB, Mark. -- ILande - Open Source Consultancy http://www.ilande.co.uk
/* * rint() test program * * Compile on gcc using: * gcc -o test test.c -lm */ #include <math.h> #include <stdio.h> double pg_rint(double x) { double f, n = 0.; f = modf(x, &n); if (x > 0.) { if (f > .5) n += 1.; } else if (x < 0.) { if (f < -.5) n -= 1.; } return n; } int main() { printf("rint(-1.5): %f\n", rint(-1.5)); printf("pg_rint(-1.5): %f\n", pg_rint(-1.5)); printf("rint(1.5): %f\n", rint(1.5)); printf("pg_rint(1.5): %f\n", pg_rint(1.5)); }
---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster