Math.Atan2(double.NegativeInfinity, double.PositiveInfinity) - bug, or undocumented breaking change?

80 Views Asked by At

Consider double result = Math.Atan2(double.NegativeInfinity, double.PositiveInfinity);.

In .net 4.8 this returns NaN.

In .net Core 3.1 or later this returns -0.7853981633974483.

The documentation for Math.Atan2() states:

If x or y is NaN, or if x and y are either PositiveInfinity or NegativeInfinity, the method returns NaN.

I suppose "either PositiveInfinity or NegativeInfinity" could mean "both PositiveInfinity or both NegativeInfinity" in which case it would not apply to my example (because x is NegativeInfinity and y is PositiveInfinity) but that seems rather subtle - and in any case, it still seems to be a bug or a breaking change.

So is this a bug or an undocumented breaking change - or am I just misunderstanding things?

(I discovered this because after porting one of our unit test libraries to .net 5 some unit tests started failing because of this change in behaviour.)

1

There are 1 best solutions below

0
harold On BEST ANSWER

This looks to be the result of a fix of a mismatch between the old behaviour and the IEEE 754 specified behaviour. But the documention hasn't caught up to the new behaviour yet.