[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Basic question from a raw recruit



Brian segal <astro@juliet.stfx.ca>
>I am writing a little test program to convert a tax included amount to a 
>net amount. It works just fine...except if the gross amount is an even 
>integer - then it returns an erroneous result. For example, if the tax is 
>7% and I divide through by 1.07 ($net = $gross/1.07) and $gross = 107, I 
>get a net of 9!! (instead of 100).

Sorry, can't reproduce that. Which version of Perl are you using?
Can you reduce the offending program to a few lines that will always fail?

>Now, a friend, who is an experienced programmer, but who doesn't know 
>Perl, says it is because Perl is treating the number like an integer 
>instead of a floating point number (probably because it IS an integer, 
>having no decimal remainder).

A few people have asserted that Perl treats everything as a floating point
number. While this is true for Perl4, Perl5 actually uses integers occasionally
(especially with the "use integer" pragma), and this has led to some bugs.

Matthias

-----
Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
   "I'm set free to find a new illusion" -- Velvet Underground