Thank you very much for the answer and explanation!
I just tested it with double-precision and indeed the error is much smaller now, only in the range of 1e-17.
So this is just neglectable precision error and not an error with my code.