MATLAB: The sums of cos(x) over 2*pi range not zero

sum (cos(-pi:pi))

when evaluating the following codes:
t = linspace(-pi,pi,128); s = sin(t); c = cos(t); sum(s), sum(c)
ans =
6.811558403281303e-15
ans =
-0.999999999999978
Q: should not both be zero?
and try
sum(c(2:end))
ans =
2.5313e-14
also quad(@cos,-pi,pi)
ans =
4.0143e-09
Q: Why the discrepancy?
Thank you for your input.
Thanks J

Best Answer

T = fundamental period
N = number of samples
dt = T/N sampling interval
f0 = 1/T fundamental frequency
(n-1)*f0 harmonics 1<=n <= N
Orthogonality interval
t = t0:dt:t0+T-dt;
t = t0+[0:dt:T-dt];
t = t0+dt*[0:N-1];
help fft
doc fft
Hope this helps
Greg