[PPL-devel] [GIT] ppl/ppl(master): Fixed rounding.

Abramo Bagnara abramo.bagnara at gmail.com
Fri May 15 14:53:13 CEST 2009


Module: ppl/ppl
Branch: master
Commit: d3d07f461687f3bd4e6f381be5b52c77eb12f938
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=d3d07f461687f3bd4e6f381be5b52c77eb12f938

Author: Abramo Bagnara <abramo.bagnara at gmail.com>
Date:   Fri May 15 14:50:43 2009 +0200

Fixed rounding.

---

 src/checked_int.inlines.hh |   11 ++++-------
 src/checked_mpz.inlines.hh |   14 +++++++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/checked_int.inlines.hh b/src/checked_int.inlines.hh
index fa8939b..8b9e75c 100644
--- a/src/checked_int.inlines.hh
+++ b/src/checked_int.inlines.hh
@@ -499,15 +499,12 @@ assign_int_float(To& to, const From from, Rounding_Dir dir) {
   if (CHECK_P(To_Policy::check_overflow, (from > Extended_Int<To_Policy, To>::max)))
     return set_pos_overflow_int<To_Policy>(to, dir);
 #endif
-  From i_from = rint(from);
-  to = To(i_from);
   if (round_not_requested(dir)) {
-    if (round_direct(ROUND_UP))
-      return V_LE;
-    if (round_direct(ROUND_DOWN))
-      return V_GE;
+    to = from;
     return V_LGE;
   }
+  From i_from = rint(from);
+  to = i_from;
   if (from == i_from)
     return V_EQ;
   if (round_direct(ROUND_UP))
@@ -516,7 +513,7 @@ assign_int_float(To& to, const From from, Rounding_Dir dir) {
     return round_gt_int<To_Policy>(to, dir);
   if (from < i_from)
     return round_lt_int<To_Policy>(to, dir);
-  else if (from > i_from)
+  if (from > i_from)
     return round_gt_int<To_Policy>(to, dir);
 }
 
diff --git a/src/checked_mpz.inlines.hh b/src/checked_mpz.inlines.hh
index 0785e76..765a848 100644
--- a/src/checked_mpz.inlines.hh
+++ b/src/checked_mpz.inlines.hh
@@ -268,13 +268,17 @@ assign_mpz_float(mpz_class& to, const From from, Rounding_Dir dir) {
     to = from;
     return V_LGE;
   }
-  From n = rint(from);
-  to = n;
-  if (from == n)
+  From i_from = rint(from);
+  to = i_from;
+  if (from == i_from)
     return V_EQ;
-  if (from < 0)
+  if (round_direct(ROUND_UP))
     return round_lt_mpz<To_Policy>(to, dir);
-  else
+  if (round_direct(ROUND_DOWN))
+    return round_gt_mpz<To_Policy>(to, dir);
+  if (from < i_from)
+    return round_lt_mpz<To_Policy>(to, dir);
+  if (from > i_from)
     return round_gt_mpz<To_Policy>(to, dir);
 }
 




More information about the PPL-devel mailing list