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

float.IsNegativeInfinity() and double.IsNegativeInfinity() do not correctly identify negative infinity #1397

Open
CoryCharlton opened this issue Nov 5, 2023 · 4 comments

Comments

@CoryCharlton
Copy link
Member

Library/API/IoT binding

PAL?

Visual Studio version

No response

.NET nanoFramework extension version

No response

Target name(s)

No response

Firmware version

No response

Device capabilities

No response

Description

I noticed several unit tests in System.Math we failing (before I touched it, I swear ;-)). The root cause appears to be that IsNegativeInfinity returns false even though the parameter is negative infinity.

The code in System::Double::IsNegativeInfinity looks correct and I reproduced the logic in an online compiler https://godbolt.org/z/5PWKhhf81 (although not everything is the same)

Given that the code is correct, and the debugger shows the correct value before executing the method, I have to assume something is changing the parameter in between the caller and the callee 🤷

How to reproduce

Run the sample code (see screenshot below for results)

Expected behaviour

IsNegativeInfinity() returns true when value is negative infinity.

Screenshots

image

Sample project or code

double d_nan = 0.0 / 0.0;
double d_pos_inf = (3.0 / 0.0);
double d_neg_inf = (-3.0 / 0.0);

Console.WriteLine($"Expect d_nan={d_nan} - {double.IsNaN(d_nan)}, d_pos_inf={d_pos_inf} - {double.IsPositiveInfinity(d_pos_inf)}, d_neg_inf={d_neg_inf} - {double.IsNegativeInfinity(d_neg_inf)}");

float f_nan = 0.0f / 0.0f;
float f_pos_inf = (3.0f / 0.0f);
float f_neg_inf = (-3.0f / 0.0f);

Console.WriteLine($"Expect f_nan={f_nan} - {float.IsNaN(f_nan)}, f_pos_inf={f_pos_inf} - {float.IsPositiveInfinity(f_pos_inf)}, f_neg_inf={f_neg_inf} - {float.IsNegativeInfinity(f_neg_inf)}");

Aditional information

No response

@josesimoes
Copy link
Member

josesimoes commented Nov 6, 2023

I noticed several unit tests in System.Math we failing (before I touched it, I swear ;-)).

That's curious... because these run on the AZDO pipeline last May (last time the lib was updated) and they all run fine... 😯

@CoryCharlton
Copy link
Member Author

I noticed several unit tests in System.Math we failing (before I touched it, I swear ;-)).

That's curious... because these run on the AZDO pipeline last May (last time the lib was updated) and they all run fine... 😯

Curious indeed. That gives me a point in history to start investigating from (although a very wide point, maybe an integration test suite would be useful here 🤷 )

@josesimoes
Copy link
Member

If you revert to the commit just before your changes, any of the Unit Tests fail?

@CoryCharlton
Copy link
Member Author

Yes these same tests were failing before I started making any changes. I just switched back to main and reconfirmed that they fail with the latest firmware version/emulator.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants