in reply to Bug? 1+1 != 2
They are not exactly the same. There is a very small rounding error:
#!/usr/bin/perl use strict; use warnings; my $base = 0.0425; while ( my $line = <DATA>){ chomp $line; my ($z,$c1,$c2,$c3,$c4) = split(/,/,$line); print join("|",$z,$c1,$c2,$c3,$c4),"\n"; my $total = $c1+$c2+$c3; print $c4 == ($total + $base) ? "True\n" : "False ". sprintf("%20.18f",$c4)." != ". sprintf("%20.18f",($total+$base))."\n"; } __DATA__ 00501,0.0000,0.0425,0.0025,0.0875 00544,0.0000,0.0425,0.0025,0.0875 06390,0.0000,0.0425,0.0025,0.0875
output:
00501|0.0000|0.0425|0.0025|0.0875 False 0.087499999999999994 != 0.087500000000000008 00544|0.0000|0.0425|0.0025|0.0875 False 0.087499999999999994 != 0.087500000000000008 06390|0.0000|0.0425|0.0025|0.0875 False 0.087499999999999994 != 0.087500000000000008
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Bug? 1+1 != 2
by shotgunefx (Parson) on Jun 19, 2003 at 10:52 UTC |