I am currently having some problems involving trigonometric functions with Python's Math library. What I am trying to do is to get the tangent of 45°, which is equal to 1. Since math.tan
only accepts values in radians, I convert 45 to radians, as shown below:
math.tan(math.radians(45))
The value returned, however, is not equal to 1, but almost: 0.9999999999999999
. This can be proofed comparing:
math.tan(math.radians(45)) == 1
# >>> False
I am aware that this concerns float imprecision and its tricky nature (plus function concatenation, which increases imprecision), but I would like to know how to mitigate it, and, if it is possible, to get 1
as the result.