dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

Math.Pow behaviour difference (.Net Framework/.Net Core) #69632

Open andreasmuellergin opened 2 years ago

andreasmuellergin commented 2 years ago

Describe the bug

While Migrating from .Net Framework to .Net Core i noticed the following difference during program execution:

In .Net Framework Math.Pow(1,double.NaN) results in double.NaN, whereas

In .Net Core Math.Pow(1,double.NaN) results in 1.0

According to the documentation .Net Framework behaviour is the correct one.

To Reproduce

Open and run the Test classes from here

Further technical details

VS2022 dotnet --info .NET SDK (gemäß "global.json"): Version: 6.0.300 Commit: 8473146e7d

Laufzeitumgebung: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.300\

Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6

.NET SDKs installed: 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.201 [C:\Program Files\dotnet\sdk] 6.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-numerics See info in area-owners.md if you want to be subscribed.

Issue Details
### Describe the bug While Migrating from .Net Framework to .Net Core i noticed the following difference during program execution: In .Net Framework Math.Pow(1,double.NaN) results in double.NaN, whereas In .Net Core Math.Pow(1,double.NaN) results in 1.0 According to the [documentation](https://docs.microsoft.com/de-de/dotnet/api/system.math.pow?view=net-6.0) .Net Framework behaviour is the correct one. ### To Reproduce Open and run the Test classes from [here](https://github.com/andreasmuellergin/MathPowWithNan) ### Further technical details VS2022 dotnet --info .NET SDK (gemäß "global.json"): Version: 6.0.300 Commit: 8473146e7d Laufzeitumgebung: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.300\ Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6 .NET SDKs installed: 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.201 [C:\Program Files\dotnet\sdk] 6.0.300 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Author: andreasmuellergin
Assignees: marcpopMSFT
Labels: `area-System.Numerics`, `untriaged`
Milestone: -
tannergooding commented 2 years ago

The documentation here is incorrect and .NET Framework's behavior is not IEEE 754 compliant.

The IEEE 754 spec defines a series of special-cases for pow, including:

IEEE 754 also defines a pown(x, n) which operates only on integral n and a powr(x, y) which operates only over positive x. The latter would have powr(x, qNaN) return qNaN but since Math.Pow allows both positive and negative x these are different functions.

We should update the documentation to ensure that the correct behavior is covered for .NET Core 2.1 and later (some specific fixes may have gone in around 3.1 instead and may need checking when exactly the change occurred).