I have the following code
double a = 29.0;
double b = 9.0;
double c = 4.0;
BigDecimal sum= new BigDecimal(0.0);
sum=sum.add(new BigDecimal(Math.log10((a)/(b*c) /Math.log10(2)));
I tried to use double for sum instead of BigDecimal but it gives me infinity as a result. when I used BigDecimal I got no results but error says:
Exception in thread “main” java.lang.NumberFormatException: Infinite or NaN
at java.math.BigDecimal.(Unknown Source)
any help please cause this is the first time I deal with large numbers
Note: a, b, anc c values will be changed through a loop and because of that I have to save the total sum.
Actually, that’s nonsense, it’s not negative. I don’t know why you’d be getting an exception there.(a)/(b*c) /Math.log10(2)is negative, so taking the log of that givesNaN.It looks like you’re really just trying to do log2, in which case you’ve just put your parentheses in the wrong place,