develooper Front page | perl.perl5.porters | Postings from September 2010

Fwd: Incorrect handling of very small doubles?

Thread Next
Shlomi Fish
September 21, 2010 03:19
Fwd: Incorrect handling of very small doubles?
Message ID:
Hi all!

This seems like a bug. As someone demonstrated in a followup, saying $m * 10 
** $e explicitly works fine.

Can anyone shed some light about it?


	Shlomi Fish

----------  Forwarded Message  ----------

Subject: Incorrect handling of very small doubles?
Date: Monday 20 September 2010, 22:30:18
From: Abu Yoav <>


I wanted to port a small c program to perl. However, the two programs behave
differently with respect to very small "double" values. The behavior seems
like a bug to me, but since I'm very new to perl, I thought I might ask the
list first.

Relevant code and output follows. Thanks!

--- c code ---

int main (int argc, char** argv)
double d1, d2, sum;

d1 = 6.892964e-309;
d2 = 1.102874e-307;

sum = d1 + d2;

printf("d1 = %e\n", d1);
printf("d2 = %e\n", d2);
printf("sum = %e\n", sum);

return 0;

--- perl code ---

my $d1, $d2, $sum;

$d1 = "6.892964e-309";
$d2 = "1.102874e-307";

$sum = $d1 + $d2;

printf("d1 = %e\n", $d1);
printf("d2 = %e\n", $d2);
printf("sum = %e\n", $sum);

--- c output ---
d1 = 6.892964e-309
d2 = 1.102874e-307
sum = 1.171804e-307

--- perl output ---
d1 = 0.000000e+00
d2 = 1.000000e-307
sum = 1.000000e-307

Shlomi Fish
Rethinking CPAN -

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - .

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About