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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.