Why does math.acos result in ValueError: math domain error?
Question:
I am using math.acos() function :
math.acos(1.0000000000000002)
This throws a math domain error. Can someone tell the reason? I am getting this value calculated before and here this value gives error but if I remove 2 at the end it does not throw error. I did not get the reason to this.
See also:
* Why does math.log result in ValueError: math domain error?
* Why does math.sqrt result in ValueError: math domain error?
Answers:
You are trying to do acos
of a number for which the acos
does not exist.
Acos – Arccosine , which is the inverse of cosine function.
The value of input for acos range from -1 <= x <= 1
.
Hence, when trying to do math.acos(1.0000000000000002)
, you are getting the error.
If you try higher numbers, you will keep getting the same error – math.acos(2)
leads to ValueError: math domain error
Inverse cosine is defined only between -1 and 1, inclusive. The arc-cosine of 1.0000000000000002 has no mathematical or semantic meaning other than “does not exist” or “undefined”.
Of course, since inverse cosine of 1 does exist, acos(1) doesn’t throw any error.
I am using math.acos() function :
math.acos(1.0000000000000002)
This throws a math domain error. Can someone tell the reason? I am getting this value calculated before and here this value gives error but if I remove 2 at the end it does not throw error. I did not get the reason to this.
See also:
* Why does math.log result in ValueError: math domain error?
* Why does math.sqrt result in ValueError: math domain error?
You are trying to do acos
of a number for which the acos
does not exist.
Acos – Arccosine , which is the inverse of cosine function.
The value of input for acos range from -1 <= x <= 1
.
Hence, when trying to do math.acos(1.0000000000000002)
, you are getting the error.
If you try higher numbers, you will keep getting the same error – math.acos(2)
leads to ValueError: math domain error
Inverse cosine is defined only between -1 and 1, inclusive. The arc-cosine of 1.0000000000000002 has no mathematical or semantic meaning other than “does not exist” or “undefined”.
Of course, since inverse cosine of 1 does exist, acos(1) doesn’t throw any error.