in reply to Getting stranger values in subtraction
In both Python and Ruby, the result is -1.4210854715202004e-14, which might seem more accurate (3 more digits), but happens to be in fact a very little bit further from truth.DB<1> $x = 319.02 - 112.09 - 69.75 - 113.57 - 23.61; DB<2> p $x -1.4210854715202e-14
The same in Perl 6:
Not only does Perl 6 give the correct result, even when printing 50 decimal digits, but even comparing the result with 0 gives the correct answer.> my $x = 319.02 - 112.09 - 69.75 - 113.57 - 23.61; 0 > say sprintf "%.50f", $x 0.00000000000000000000000000000000000000000000000000 > say $x == 0; True
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting stranger values in subtraction
by BillKSmith (Monsignor) on Feb 06, 2016 at 14:52 UTC | |
by Laurent_R (Canon) on Feb 06, 2016 at 15:04 UTC |