title: Specific right-angled Triangles are not being recognized as right-angled in Cpp
body: <p>I have to take the coordinates of the vertices of a triangle from the user and tell if it is a right-angled triangle or not. I'm using Pythagoras Theorem to Find out i.e. <code>h * h = b * b + p * p</code></p>
  <p>But surprisingly this <strong>doesn't work for some specific right-angled triangles</strong>.
  Here is one such Triangle:</p>
  <p>Vertex A: (x, y) = (1, 3)</p>
  <p>Vertex B: (x, y) = (1, 1)</p>
  <p>Vertex C: (x, y) = (5, 1)</p>
  <p>It <strong>calculates perfectly</strong>, which I figured out by printing the calculation, but <strong>still doesn't work</strong>.</p>
  <p>Then I tried by using <code>sqrt()</code> function from the <code>cmath</code> library this way:
  h = sqrt(b * b + p * p)</p>
  <p><strong>Logically it is the same, but it worked.</strong></p>
  <p>I want to understand, <strong>why the earlier method is not working?</strong></p>
  <p>Here is a simplified version of <strong>My Code:</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  
  class Vertex {
  
      double x, y;
  
  public:
      void take_input(char obj) {
          cout &lt;&lt; endl &lt;&lt; &quot;   Taking Coordinates of Vertex &quot; &lt;&lt; obj &lt;&lt; &quot;: &quot; &lt;&lt; endl;
  
          cout &lt;&lt; &quot;       Enter the x component: &quot;;
          cin &gt;&gt; x;
          cout &lt;&lt; &quot;       Enter the y component: &quot;;
          cin &gt;&gt; y;
      }
  
      double distance(Vertex p) {
          double dist = sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y));
  
          return dist;
      }
  };
  
  class Triangle {
      Vertex a, b, c;
  
  public:
  
      void take_inp(string obj) {
          cout &lt;&lt; endl &lt;&lt; &quot;Taking Vertices of the Triangle &quot; &lt;&lt; obj &lt;&lt; &quot;: &quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;   Verteces should be in a counter clockwise order (as per convention).&quot; &lt;&lt; endl;
  
          a.take_input('A');
          b.take_input('B');
          c.take_input('C');
      }
  
      void is_rt_ang() {
  
          double h = a.distance(c)*a.distance(c);
          double bp = a.distance(b)*a.distance(b) + b.distance(c)*b.distance(c);
  
          /*
              // Strangely this attempt works which is logically the same: 
              double h = a.distance(c);
              double bp = sqrt(a.distance(b)*a.distance(b) + b.distance(c)*b.distance(c));
          */
  
          if (h == bp) {
              cout &lt;&lt; &quot;Angle is 90&quot; &lt;&lt; endl;
              cout &lt;&lt; h &lt;&lt; &quot; = &quot; &lt;&lt; bp &lt;&lt; endl;
              cout &lt;&lt; &quot;It is Right-Angled&quot; &lt;&lt; endl;
          }
          else {
              cout &lt;&lt; &quot;Angle is not 90!&quot; &lt;&lt; endl;
              cout &lt;&lt; h &lt;&lt; &quot; != &quot; &lt;&lt; bp &lt;&lt; endl;
              cout &lt;&lt; &quot;It is Not a Right-Angled&quot; &lt;&lt; endl;
          }
      }
  };
  
  int main()
  {
      Triangle tri1, tri2;
  
      tri1.take_inp(&quot;tri1&quot;);
  
      tri1.is_rt_ang();
  
      return 0;
  }
  </code></pre>