title: Worst case time complexity of Math.sqrt in java
body: <p>We have a test exercise where you need to find out whether a given N number is a square of another number or no, with the smallest time complexity.</p>
  
  <p>I wrote:</p>
  
  <pre><code>public static boolean what2(int n) {
      double newN = (double)n;
      double x = Math.sqrt(newN);
      int y = (int)x;
      if (y * y == n)
          return false;
      else
          return true;
  }
  </code></pre>
  
  <p>I looked online and specifically on SO to try and find the complexity of <code>sqrt</code> but couldn't find it. <a href="https://stackoverflow.com/questions/34580158/time-complexity-of-math-sqrt">This SO post</a> is for C# and says its O(1), and <a href="https://stackoverflow.com/questions/28815339/time-complexity-of-math-sqrt-java">this Java post</a> says its O(1) but could potentially iterate over all doubles.</p>
  
  <p>I'm trying to understand the worst time complexity of this method. All other operations are O(1) so this is the only factor.
  Would appreciate any feedback!</p>