The result is very small, but not exactly zero, which is the correct answer. The reason
is that 0.2 cannot be exactly represented in binary using a finite number of digits (it is
0.0011001100 . . . ). This is for exactly the same reasons that 1/3 cannot be exactly written
as a base 10 number. Octave (and all other computer programs) represent these numbers
with the closest one they can, but repeated uses of these approximations, as seen here,
can cause problems. For this reason, you should think very carefully before checking that
a number is exactly equal to another. It is usually best to check that it is the same to
within a tolerance. We will return to this problem throughout this tutorial.
The result is very small, but not exactly zero, which is the correct answer. The reasonis that 0.2 cannot be exactly represented in binary using a finite number of digits (it is0.0011001100 . . . ). This is for exactly the same reasons that 1/3 cannot be exactly writtenas a base 10 number. Octave (and all other computer programs) represent these numberswith the closest one they can, but repeated uses of these approximations, as seen here,can cause problems. For this reason, you should think very carefully before checking thata number is exactly equal to another. It is usually best to check that it is the same towithin a tolerance. We will return to this problem throughout this tutorial.
การแปล กรุณารอสักครู่..
