I am attempting to Perlize a simple arithmetic expression that returns the pressure of CO2 gas in PSI needed to carbonate beer with a given number of gas volumes at a given temperature.
Volumes and Temperature are both known. So we have an expressions akin to:
X = 1 + 2^3 + 4*5 - 6*7^8
The full expression is:
Pressures=-16.6999-(0.0101059*Temperature)+(0.00116512*(Temperature^2) +)+(0.1733554*(Temperature)*(Volumes))+(4.24267*(Volumes))-(0.0684226* +(Volumes^2))
This works in Excel yielding a pressure of 12.27462975 for a temperature of 40 and 2.5 volumes of CO2. This does not work in Perl..
$temp = 40; $vol = 2.5; $pressure=(-16.6999)-(0.0101059*$temp)+(0.00116512*($temp^2))+(0.17335 +4*$temp*$vol)+(4.24267*$vol)-(0.0684226*($vol^2));
Here I get a pressure of 10.88687404 which is definitely wrong. (I am matching values on a known table for testing).
Is this an issue with floating point precision? I couldn't find a floating point module... Please help.
Janitored by Arunbear - added code tags, and changed title from 'Problems with floating point arithmetic. Please Help!'
In reply to Convert arithmetic expression from Excel to Perl syntax by ameyer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |