From a35f193f67449520b47d663124eda13851579171 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 12 Nov 2009 22:48:28 -0500 Subject: [PATCH] Fix flonum case of ROUND to use IEEE round-to-even, per the R5RS. --- src/microcode/artutl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/microcode/artutl.c b/src/microcode/artutl.c index cd6addc5f..9c4ed7544 100644 --- a/src/microcode/artutl.c +++ b/src/microcode/artutl.c @@ -126,7 +126,15 @@ double_truncate (double x) double double_round (double x) { - return (double_truncate ((x < 0) ? (x - 0.5) : (x + 0.5))); + double integral; + double fractional = (fabs (modf (x, (&integral)))); + + if ((fractional == 0.5) + ? ((fmod (integral, 2.0)) == 0.0) + : (! (0.5 < fractional))) + return (integral); + else + return (integral + (copysign (x, 1.0))); } /* Conversions between Scheme types and Scheme types. */ -- 2.25.1