Arithmetic Expression Evaluation in print

H

Harlan Grove

I'm using Perl 5.8.3 (ActiveState Build 809 for Windows).

perl -e "print (1-(1+(5.2/100/12))**-(30*12))/(5.2/100/12);"

gives 0.789154519316799, which is incorrect, while

perl -e "print ((1-(1+(5.2/100/12))**-(30*12))/(5.2/100/12));"

gives 182.1125813808, which is correct.

I also get the same results from Perl 5.8.7 (Cygwin).

Why is there a difference? In the former script, it's as if the
denominator term (5.2/100/12) was ignored.
 
A

Anno Siegel

Harlan Grove said:
I'm using Perl 5.8.3 (ActiveState Build 809 for Windows).

perl -e "print (1-(1+(5.2/100/12))**-(30*12))/(5.2/100/12);"

gives 0.789154519316799, which is incorrect, while

perl -e "print ((1-(1+(5.2/100/12))**-(30*12))/(5.2/100/12));"

gives 182.1125813808, which is correct.

I also get the same results from Perl 5.8.7 (Cygwin).

Why is there a difference? In the former script, it's as if the
denominator term (5.2/100/12) was ignored.

Try the same thing with warnings enabled. Then read perldoc -f print.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top