Shouldn’t the following statement hold?
assertTrue(Double.isNaN(Math.tan(Math.acos(0d))));
But instead of Double.NaN Java returns
6.123233995736766 * 10^-17
on my 64-bit box.
EDIT:
This was a Copy and Paste error. In fact Java returns 1.633123935319537E16
I’m aware that this is because of the floating point representation, but i was under the impression that those undefined values of the tangent function would get the same treatment as e.g. Math.sqrt(-1d) but I guess in this case java.lang.Math just checks if the argument is positive before evaluating.
I get something different.
prints
A 64-bit floating point cannot represent PI/2 exactly (it has an infinite number of digits) it represents a number close to this value and the tan() of this value is finite.