[PPL-devel] [GIT] ppl/ppl(master): Restore the pre-PPL rounding mode before using libm functions.

Roberto Bagnara bagnara at cs.unipr.it
Thu Jun 21 17:41:50 CEST 2012


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

Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date:   Thu Jun 21 17:41:01 2012 +0200

Restore the pre-PPL rounding mode before using libm functions.

---

 tests/Box/interval1.cc         |   13 ++++++++++---
 tests/Box/membytes1.cc         |   11 +++++++++--
 tests/Polyhedron/randphull1.cc |    7 +++++++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/tests/Box/interval1.cc b/tests/Box/interval1.cc
index ff5fae7..4c59a54 100644
--- a/tests/Box/interval1.cc
+++ b/tests/Box/interval1.cc
@@ -115,9 +115,16 @@ solve(const std::vector<N>& P,
   // Initial estimates are given by roots of unity.
   std::vector<std::complex<N> > x(5);
   double theta = 2*M_PI/degree;
-  for (int i = 0; i < degree; ++i)
-    x[i] = std::complex<N>(N(cos(i*theta)),
-                                     N(sin(i*theta)));
+  for (int i = 0; i < degree; ++i) {
+    // Many libm implementations only work with round-to-nearest.
+    // See, e.g, http://sources.redhat.com/bugzilla/show_bug.cgi?id=3976
+    restore_pre_PPL_rounding();
+    N cos_i_theta = N(cos(i*theta));
+    N sin_i_theta = N(sin(i*theta));
+    set_rounding_for_PPL();
+
+    x[i] = std::complex<N>(cos_i_theta, sin_i_theta);
+  }
 
   for (int iteration = 0; iteration < 50; ++iteration) {
     for (int i = 0; i < degree; ++i)
diff --git a/tests/Box/membytes1.cc b/tests/Box/membytes1.cc
index 8a0093b..4649659 100644
--- a/tests/Box/membytes1.cc
+++ b/tests/Box/membytes1.cc
@@ -75,9 +75,16 @@ bool test02() {
     ix.join_assign(boundary_type(d-0.015));
     ix.join_assign(boundary_type(d+0.015));
 
+    // Many libm implementations only work with round-to-nearest.
+    // See, e.g, http://sources.redhat.com/bugzilla/show_bug.cgi?id=3976
+    restore_pre_PPL_rounding();
+    boundary_type sdm = boundary_type(sin(d-0.015));
+    boundary_type sdp = boundary_type(sin(d-0.015));
+    set_rounding_for_PPL();
+
     iy.assign(EMPTY);
-    iy.join_assign(boundary_type(sin(d-0.015)));
-    iy.join_assign(boundary_type(sin(d+0.015)));
+    iy.join_assign(sdm);
+    iy.join_assign(sdp);
 
     box.set_interval(x, ix);
     box.set_interval(y, iy);
diff --git a/tests/Polyhedron/randphull1.cc b/tests/Polyhedron/randphull1.cc
index 6fab90a..44103a5 100644
--- a/tests/Polyhedron/randphull1.cc
+++ b/tests/Polyhedron/randphull1.cc
@@ -98,6 +98,11 @@ point_on_the_unit_n_sphere(unsigned n,
 			   const std::vector<float>& theta,
 			   std::vector<float>& coordinate) {
   assert(n >= 2);
+
+  // Many libm implementations only work with round-to-nearest.
+  // See, e.g, http://sources.redhat.com/bugzilla/show_bug.cgi?id=3976
+  restore_pre_PPL_rounding();
+
   if (n == 2) {
     coordinate[0] *= sin(theta[0]);
     coordinate[1] *= cos(theta[0]);
@@ -109,6 +114,8 @@ point_on_the_unit_n_sphere(unsigned n,
       coordinate[i] *= sin_theta_n_2;
     coordinate[n-1] *= cos(theta[n-2]);
   }
+
+  set_rounding_for_PPL();
 }
 
 void




More information about the PPL-devel mailing list