]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Don't compare floating point numbers directly, but via std::fabs. 869/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 24 Apr 2015 01:24:27 +0000 (20:24 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 24 Apr 2015 01:24:27 +0000 (20:24 -0500)
examples/step-42/step-42.cc

index 8567b2429ff0d1b9554f739db89ae595103daeab..1453429020ab3a67cfc1939bd5ff07219105df7e 100644 (file)
@@ -952,14 +952,14 @@ namespace Step42
                ++face_no)
             if (cell->face(face_no)->at_boundary())
               {
-                if (cell->face(face_no)->center()[2] == p2(2))
+                if (std::fabs(cell->face(face_no)->center()[2] - p2[2]) < 1e-12)
                   cell->face(face_no)->set_boundary_id(1);
-                if (cell->face(face_no)->center()[0] == p1(0)
-                    || cell->face(face_no)->center()[0] == p2(0)
-                    || cell->face(face_no)->center()[1] == p1(1)
-                    || cell->face(face_no)->center()[1] == p2(1))
+                if (std::fabs(cell->face(face_no)->center()[0] - p1[0]) < 1e-12
+                    || std::fabs(cell->face(face_no)->center()[0] - p2[0]) < 1e-12
+                    || std::fabs(cell->face(face_no)->center()[1] - p1[1]) < 1e-12
+                    || std::fabs(cell->face(face_no)->center()[1] - p2[1]) < 1e-12)
                   cell->face(face_no)->set_boundary_id(8);
-                if (cell->face(face_no)->center()[2] == p1(2))
+                if (std::fabs(cell->face(face_no)->center()[2] - p1[2]) < 1e-12)
                   cell->face(face_no)->set_boundary_id(6);
               }
       }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.