[Lemon-commits] Alpar Juttner: Fix usage of sqrt() (#268)

Lemon HG hg at lemon.cs.elte.hu
Fri Apr 24 13:15:14 CEST 2009


details:   http://lemon.cs.elte.hu/hg/lemon/rev/0c8e5c688440
changeset: 644:0c8e5c688440
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Thu Apr 23 10:44:35 2009 +0100
description:
	Fix usage of sqrt() (#268)

diffstat:

 demo/graph_to_eps_demo.cc |   2 +-
 lemon/network_simplex.h   |  11 +++++++----
 tools/lgf-gen.cc          |   8 ++++----
 3 files changed, 12 insertions(+), 9 deletions(-)

diffs (93 lines):

diff --git a/demo/graph_to_eps_demo.cc b/demo/graph_to_eps_demo.cc
--- a/demo/graph_to_eps_demo.cc
+++ b/demo/graph_to_eps_demo.cc
@@ -182,7 +182,7 @@
   ListDigraph::NodeMap<int> hcolors(h);
   ListDigraph::NodeMap<Point> hcoords(h);
 
-  int cols=int(sqrt(double(palette.size())));
+  int cols=int(std::sqrt(double(palette.size())));
   for(int i=0;i<int(paletteW.size());i++) {
     Node n=h.addNode();
     hcoords[n]=Point(1+i%cols,1+i/cols);
diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
--- a/lemon/network_simplex.h
+++ b/lemon/network_simplex.h
@@ -381,7 +381,8 @@
         const double BLOCK_SIZE_FACTOR = 2.0;
         const int MIN_BLOCK_SIZE = 10;
 
-        _block_size = std::max( int(BLOCK_SIZE_FACTOR * sqrt(_arc_num)),
+        _block_size = std::max( int(BLOCK_SIZE_FACTOR *
+                                    std::sqrt(double(_arc_num))),
                                 MIN_BLOCK_SIZE );
       }
 
@@ -457,7 +458,8 @@
         const double MINOR_LIMIT_FACTOR = 0.1;
         const int MIN_MINOR_LIMIT = 3;
 
-        _list_length = std::max( int(LIST_LENGTH_FACTOR * sqrt(_arc_num)),
+        _list_length = std::max( int(LIST_LENGTH_FACTOR *
+                                     std::sqrt(double(_arc_num))),
                                  MIN_LIST_LENGTH );
         _minor_limit = std::max( int(MINOR_LIMIT_FACTOR * _list_length),
                                  MIN_MINOR_LIMIT );
@@ -577,7 +579,8 @@
         const double HEAD_LENGTH_FACTOR = 0.1;
         const int MIN_HEAD_LENGTH = 3;
 
-        _block_size = std::max( int(BLOCK_SIZE_FACTOR * sqrt(_arc_num)),
+        _block_size = std::max( int(BLOCK_SIZE_FACTOR *
+                                    std::sqrt(double(_arc_num))),
                                 MIN_BLOCK_SIZE );
         _head_length = std::max( int(HEAD_LENGTH_FACTOR * _block_size),
                                  MIN_HEAD_LENGTH );
@@ -1225,7 +1228,7 @@
       }
 
       // Store the arcs in a mixed order
-      int k = std::max(int(sqrt(_arc_num)), 10);
+      int k = std::max(int(std::sqrt(double(_arc_num))), 10);
       int i = 0;
       for (ArcIt e(_graph); e != INVALID; ++e) {
         _arc_ref[i] = e;
diff --git a/tools/lgf-gen.cc b/tools/lgf-gen.cc
--- a/tools/lgf-gen.cc
+++ b/tools/lgf-gen.cc
@@ -65,7 +65,7 @@
 double totalLen(){
   double tlen=0;
   for(EdgeIt e(g);e!=INVALID;++e)
-    tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare());
+    tlen+=std::sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare());
   return tlen;
 }
 
@@ -188,7 +188,7 @@
       (q.x * q.x + q.y * q.y) * (r.x * p.y - p.x * r.y) +
       (r.x * r.x + r.y * r.y) * (p.x * q.y - q.x * p.y);
 
-    return d / (2 * a) + sqrt((d * d + e * e) / (4 * a * a) + f / a);
+    return d / (2 * a) + std::sqrt((d * d + e * e) / (4 * a * a) + f / a);
   }
 
   inline bool circle_form(const Point& p, const Point& q, const Point& r) {
@@ -206,7 +206,7 @@
     double a = q.x - p.x;
     double b = (q.x - sx) * p.y - (p.x - sx) * q.y;
     double d = (q.x - sx) * (p.x - sx) * (p - q).normSquare();
-    return (b - sqrt(d)) / a;
+    return (b - std::sqrt(d)) / a;
   }
 
   struct YLess {
@@ -813,7 +813,7 @@
   std::cout << "Number of arcs    : " << countEdges(g) << std::endl;
   double tlen=0;
   for(EdgeIt e(g);e!=INVALID;++e)
-    tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare());
+    tlen+=std::sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare());
   std::cout << "Total arc length  : " << tlen << std::endl;
 
   if(ap["eps"])



More information about the Lemon-commits mailing list