Why does math.cos(math.pi/2) not return zero?
Why does math.cos(math.pi/2) not return zero? Question: I came across some weird behavior by math.cos() (Python 3.11.0): >>> import math >>> math.cos(math.pi) # expected to get -1 -1.0 >>> math.cos(math.pi/2) # expected to get 0 6.123233995736766e-17 I suspect that floating point math might play a role in this, but I’m not sure how. And if …