Non-zero DFT components where zero is expected?
These are just rounding errors, and you only get a flipped sign for phase values of $\pm\pi$, which is not an issue because the phase value is ambiguous, i.e., adding or subtracting multiples of $2\pi$ doesn't change the value of the complex coefficient.
I assume that your code is just for an educational purpose, because it is neither efficient nor numerically accurate.