Digital Signal Processing Reference
In-Depth Information
computer
will
do
exactly
what
we
tell
it,
and
conclude
that
0.000000000000000000000000000000000000000001 is not equal to 0.
>> % mynumber should be 0.0 after the next statement
mynumber = sqrt(7)^2 - 7;
% Here we confirm that mynumber is zero, right?
if (mynumber == 0.0)
sprintf(mynumber is zero)
else
sprintf(mynumber is not zero)
end
ans =
mynumber is not zero
>>
What is this? If mynumber is not zero, then what is it?
>> mynumber
mynumber =
8.8818e-016
The number is very, very small, but not quite zero. It should be zero, but due
to realities of precision, there is a little error.
2.10.1
Comparing Numbers with a Tolerance
When a value is very close to zero, but technically not zero, we can compare it with
a certain tolerance, as the following example demonstrates.
Search WWH ::




Custom Search