in reply to Re: Multiplying together the numers in an array
in thread Multiplying together the numers in an array
And you can also lose precision by stringifying the numbers:
outputs@a= (1/3, 3); $prod1= eval join "*", @a; $prod2= 1; $prod2*= $_ for @a; print $prod1,$/, $prod2,$/;
0.999999999999999 1
I'm not trying to attack you, but this can be a trap at other times when you store floating-point numbers as text. I learned in when I wrote the obfu Fun with duff's device and AUTOLOAD.
Also look at what happens if the numbers are object with stringification. Look:
output is:use Math::Complex; @a= (1+i, 2); $prod1= eval join "*", @a; $prod2= 1; + $prod2*= $_ for @a; print $prod1,$/, $prod2,$/;
1+2i 2+2i
|
|---|