My factorial is hitting a wall, and it is a huge decimal (I put it under 1). How do I use BigDecimal? Here is what I am using to solve these factorials:
public static double factorial(double n) {
if (n < 0) throw new RuntimeException("Can't be negative stupid.");
else if (n > 250) throw new RuntimeException("Number too big at the moment! :(");
else if (n == 0) return 1;
else return (1 / (n * factorial(n-1)));
double z = 200
factorial(z);
I get errors because I don't think double can handle something so large. How do I change that snippet of code to BigDecimal, rather how do I use it? The API sort of tells me this is much different from regular number types. Also, can a BigDecimal have a value in the ones or tens place, like 23.839281.... or is it strictly the decimal end, 0.839281... ?
Edited by: kavon89 on Oct 9, 2007 10:49 PM