title: NumberFormatException: Infinite or NaN
body: <p>I have a method that takes n and returns nth Fibonacci number. Inside the method implementation I use <code>BigDecimal</code> to get the nth Fibonacci number then I use method <code>toBigInteger()</code> to get the number as a <code>BigInteger</code> object and that's surely because I am working with huge numbers in my application.</p>
  
  <p>I keep getting correct results until I pass <strong>1475</strong> as an argument for my method. I get <code>NumberFormatException: Infinite or NaN</code> in this case without any clear reason for me.</p>
  
  <p><strong>Could you please explain me why am I getting this exception?</strong></p>
  
  <p>Here's my method:</p>
  
  <pre><code>BigInteger getFib(int n){
       double phi = (1 + Math.sqrt(5))/2;
       double squareRoot = (Math.sqrt(5)) + (1/2);
       BigDecimal bd = new BigDecimal(Math.floor(Math.pow(phi, n)/(squareRoot)));
       return bd.toBigInteger();
  }
  </code></pre>