Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Bug? 1+1 != 2

by fglock (Vicar)
on Jun 19, 2003 at 06:45 UTC ( #267098=note: print w/replies, xml ) Need Help??

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


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
    I figured as much, though I am still curious about the stringified representations. I've never thought too deeply about it. How does Perl determine the formatting for numbers when stringifying? $#?


    "To be civilized is to deny one's nature."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://267098]
[choroba]: Rama!
[shmem]: hm. That should be "an artist's expression"
[RonW]: Happy Thanksgiving Eve

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-11-22 16:48 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (327 votes). Check out past polls.