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? Regards, Shlomi Fish ---------- Forwarded Message ---------- Subject: Incorrect handling of very small doubles? Date: Monday 20 September 2010, 22:30:18 From: Abu Yoav <abuyoav@gmail.com> To: beginners@perl.org Hi, 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 --- #include<stdio.h> 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 --- #!/usr/bin/perl 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 http://www.shlomifish.org/ Rethinking CPAN - http://shlom.in/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 - http://shlom.in/reply .Thread Next