I htink this
looks horrible, but is not :-)
You noticed the first time the error gets less than zero! If you
calculate the error, you'll see it's around 10E-15 at this point (at last on my pc).
#!/usr/bin/perl
my $x=0.0;
my $y=0;
my $e_min=1.0;
my $e_max=0.0;
my $n=0;
my $e;
for ( 1 .. 999 ) {
$x += 0.05;
$y += 5;
$e = abs($x - $y / 100);
$n++ if $e == 0.0;
$e_min = $e if $e > 0.0 && $e < $e_min;
$e_max = $e if $e > $e_max;
printf "%4d x = %.30f e = %E\n", $_, $x, $e;
}
printf "min %E max %E exact %d\n", $e_min, $e_max, $n;
result
998 x = 49.899999999999302247033483581617 e = 6.963319E-13
999 x = 49.949999999999299404862540541217 e = 7.034373E-13
min 2.775558E-17 max 7.034373E-13 exact 16
You'll find the lines arround 190 interesting:
189 x = 9.449999999999999289457264239900 e = 0.000000E+00
190 x = 9.500000000000000000000000000000 e = 0.000000E+00
191 x = 9.550000000000000710542735760100 e = 0.000000E+00