Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some return values for MathF.Pow() are wrong #9571

Merged
merged 6 commits into from
Feb 2, 2024
Merged

Conversation

Psychpsyo
Copy link
Contributor

Summary

MathF.Pow(float.NaN,0f) returns 1, not NaN.
MathF.Pow(1f,float.NaN) returns 1, not NaN.

using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.WriteLine(System.MathF.Pow(float.NaN,0f));
        Console.WriteLine(System.MathF.Pow(1f,float.NaN));
    }
}

This outputs 1 twice.

@Psychpsyo Psychpsyo requested a review from a team as a code owner January 24, 2024 02:20
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 24, 2024
Copy link

Learn Build status updates of commit e0d581a:

✅ Validation status: passed

File Status Preview URL Details
xml/System/MathF.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

@tannergooding
Copy link
Member

The full set of rules for pow (as required by IEEE 754 2019) is:

  • pow (x, ±0) is 1 if x is not a signaling NaN
  • pow (±0, y) is ±∞ and signals the divideByZero exception for y an odd integer < 0
  • pow (±0, −∞) is +∞ with no exception
  • pow (±0, +∞) is +0 with no exception
  • pow (±0, y) is ±0 for finite y > 0 an odd integer
  • pow (−1, ±∞) is 1 with no exception
  • pow (+1, y) is 1 for any y (even a quiet NaN)
  • pow (x, +∞) is +0 for −1 < x < 1
  • pow (x, +∞) is +∞ for x < −1 or for 1 < x (including ±∞)
  • pow (x, −∞) is +∞ for −1 < x < 1
  • pow (x, −∞) is +0 for x < −1 or for 1 < x (including ±∞)
  • pow (+∞, y) is +0 for a number y < 0
  • pow (+∞, y) is +∞ for a number y > 0
  • pow (−∞, y) is −0 for finite y < 0 an odd integer
  • pow (−∞, y) is −∞ for finite y > 0 an odd integer
  • pow (−∞, y) is +0 for finite y < 0 and not an odd integer
  • pow (−∞, y) is +∞ for finite y > 0 and not an odd integer
  • pow (±0, y) is +∞ and signals the divideByZero exception for finite y < 0 and not an odd integer
  • pow(±0, y) is +0 for finite y > 0 and not an odd integer
  • pow(x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.

It would be good to see if we can make all of this match up with the docs

@Psychpsyo
Copy link
Contributor Author

It would be good to see if we can make all of this match up with the docs

Except for the parts about signaling NaNs, I'd say, since I don't think we even have access to signaling NaNs.

Co-authored-by: Genevieve Warren <[email protected]>
Copy link

Learn Build status updates of commit 4ebb77c:

✅ Validation status: passed

File Status Preview URL Details
xml/System/MathF.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

@gewarren gewarren merged commit 2793ea8 into dotnet:main Feb 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants