http://www.perlmonks.org?node_id=1016160

Biker1971 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to calculate some values in the IEEE 754 format, incl. the restrictions of accuracy. For example, if I multiply 0.29 with 50, I get 14.5:
my $num1 = 0.29; my $num2 = 50; my $num3 = $num1 * $num2; print "num3=$num3\n"; # is '14.5'
Only with this line:
my $num4 = sprintf ("%.64f", $num7);
I get the exact result in "double" (14.999...). Is there are way to enable to get the same result without the sprintf instruction? Also if I use "eval", the result differs from the IEEE-754 calculation. What I want to do is to calculate everything with IEEE-754 numbers ("double" in C).
my $num1 = 0.29; my $num2 = sprintf ("%.64f", $num1); my $num3 = 50; my $num4 = sprintf ("%.64f", $num3); my $num5 = $num2 * $num4; my $num6 = sprintf ("%.64f", $num5); my $num7 = $num1 * $num3; my $num8 = sprintf ("%.64f", $num7); my $num9 = eval(eval($num1) * eval($num3)); my $num10 = sprintf ("%.64f", $num9); results in num1=0.29 num2=0.2899999999999999800159855567471822723746299743652343750000... num3=50 num4=50.000000000000000000000000000000000000000000000000000000000... num5=14.5 num6=14.499999999999998223643160599749535322189331054687500000000... num7=14.5 num8=14.499999999999998223643160599749535322189331054687500000000... num9=14.5 num10=14.50000000000000000000000000000000000000000000000000000000...