title: c++ continued fractions output error
body: <p>I have written this Java code that works very well:</p>
  
  <pre><code>static String getFraction(double x) {
          double limit = 1.0E-6;     
          double h1 = 1, h2 = 0, k1 = 0, k2 = 1;
          double y = x;
  
          do {
  
              double a = Math.floor(y);
              double aux = h1;
              h1 = a*h1+h2;
              h2 = aux;
              aux = k1;
              k1 = a*k1+k2;
              k2 = aux;
              y = 1/(y-a);
  
          } while (Math.abs(x-h1/k1) &gt; x*limit );
  
          return ((int) h1) + "/" + ((int) k1);  
      }
  </code></pre>
  
  <p>It takes a double (6.45) and returns its fractional representation using continued fractions (129/20). This is the C++ code:</p>
  
  <pre><code> void calc(double x) {
  
      double limit = 1.0E-6;     
      double h1 = 1, h2 = 0, k1 = 0, k2 = 1;
      double y = x;
  
      do {
  
          double a = floor(y);
          double aux = h1;
          h1 = a*h1+h2;
          h2 = aux;
          aux = k1;
          k1 = a*k1+k2;
          k2 = aux;
          y = 1/(y-a);
  
      } while (abs(x-h1/k1) &gt; x*limit );
  
      std::cout &lt;&lt; (h1) &lt;&lt; "/" &lt;&lt; (k1) &lt;&lt; std::endl;  
   }
  </code></pre>
  
  <p>The C++ translation is in my opinion identical to the Java version. The problem is this output:</p>
  
  <pre><code>Java (input 6.45) --&gt; 129/20
  C++ (input 6.45) --&gt; 6/1
  </code></pre>
  
  <p>Any idea? Do I have to static cast something to double to allow floating point operations?</p>