Since pi is an irrational number and cannot be represented exactly by a finite number of binary digits, there is always going to be an infintesimal error assocated with doing math with irrational numbers (really, there is always an error doing arithmetic on a computer). If you really want it to be zero you can compare it to a tolerance and say that any number smaller than your tolerance is set to zero. For example:
tol = 1e-15;
z = sin(pi);
if abs(z) < tol
z = 0;
end
Alternatively, you could use
will return 0
Best Answer