I am using procedural generation with the fibonacci sequence and I need to input numbers ranging into the thousands, except when I do so, I keep getting the error Infinite or Nan on this line : "BigDecimal placeholder = new BigDecimal((Math.pow( 1+Math.sqrt(5), n ) - Math.pow( 1-Math.sqrt(5), n)));"
public static BigDecimal fibonacci(double n){
n = Math.floor(n);
BigDecimal placeholder = new BigDecimal((Math.pow( 1+Math.sqrt(5), n ) - Math.pow( 1-Math.sqrt(5), n)));
placeholder.divide(new BigDecimal((Math.pow(2, n)*Math.sqrt(5))), RoundingMode.HALF_UP);
return placeholder;
}
I would love some help or redirection to another thread and or a better way of going about this.