Abu Yoav wrote:
Hi,
Hello,
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
$ perl -le' my $d1 = 6.892964e-309; my $d2 = 1.102874e-307; my $sum = $d1 + $d2; printf "d1 = %e\n", $d1; printf "d2 = %e\n", $d2; printf "sum = %e\n", $sum; ' d1 = 6.892964e-309 d2 = 1.102874e-307 sum = 1.171804e-307 It seems to work OK here. John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/