Question

I am having issues with an apex code we are trying to get working. I keep getting the error;

"System.MathException: Cannot represent Double 'Infinity' as a Decimal: (System Code)"

decimal rho = 1000;
decimal mu = 0.0019;
beta = 0.0757;
decimal r_b_eq8 =   (0.33 * math.exp(0.76 * math.log(9.81) * math.exp(0.52 * math.log(rho / mu)) * math.exp(1.28 * math.log((math.exp((1/3)*math.log(beta))))))); 

The issue occurs when we try to compute the math.log(rho / mu) portion of the code. I have tried rounding the result of rho / mu, defining it as a double, many other things. I have tried setting the division portion of the problem equal to another variable and substituted,

alpha = rho / mu;
... * math.log(alpha) ... 

with little succes. Is this an issue with the way we have defined our variables as decimals? The math.log works just fine with the 9.81 and also with "beta" as the end.

We do the calculations with excel and many other programs and never have an issue like this. We are running our code this way due to the inability to compute (rho / mu) ^ 0.52 in salesforce without the math.log/exp trick. Is there a way around this or another way to computer the raising of (rho / mu) ^ 0.52 which wouldn't give us this error?

Was it helpful?

Solution

I finally got an answer to this ... Thx. Mike Chale on salesforce.stackexchange.com

It was a silly mistake really, the ultimate issue is that there should have been () around 0.76 * math.log(9.81) (0.33 * (math.exp(0.76 * math.log(9.81)) * math.exp(0.52 * math.log(rho / mu)) * It represents 9.81^0.76.

The final problem was that this calculation seems to be overflowing what Apex can handle.

I think it would still be nice to not have to use the work around for raising to powers.

https://salesforce.stackexchange.com/questions/21112/cannot-represent-double-infinity-as-a-decimal-salesforce

Thanks Mike Chale again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top