[goffice] Math: fix rounding also for long double.



commit 934bf378c245401ff6c102538633d9fc91daf8b1
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 2 20:15:31 2014 -0400

    Math: fix rounding also for long double.

 ChangeLog              |    1 +
 goffice/math/go-math.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f974ee2..7d973c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * goffice/math/go-math.c (go_fake_round): Fix problem for 2^51 and
        like integers.
+       (go_fake_roundl): Ditto, although for different set of numbers.
 
        * tests/test-format.c: New test program.
 
diff --git a/goffice/math/go-math.c b/goffice/math/go-math.c
index ffaaddb..926bc52 100644
--- a/goffice/math/go-math.c
+++ b/goffice/math/go-math.c
@@ -886,7 +886,16 @@ go_fake_ceill (long double x)
 long double
 go_fake_roundl (long double x)
 {
-       long double y = go_fake_floorl (fabsl (x) + 0.5L);
+       long double y;
+
+       if (x == floorl (x))
+               return x;
+
+       /*
+        * Adding a half here is ok.  The only problematic non-integer
+        * case is nextafter(0.5,-1) for which we want to produce 1 here.
+        */
+       y = go_fake_floorl (fabsl (x) + 0.5L);
        return (x < 0) ? -y : y;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]