Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Some cleanup of the Math functions from #20788 #20912

Merged
merged 6 commits into from
Nov 12, 2018
Merged

Some cleanup of the Math functions from #20788 #20912

merged 6 commits into from
Nov 12, 2018

Conversation

tannergooding
Copy link
Member

This fixes a few issues that were in #20788:

  • The new PAL tests were not actually running
  • Max, MaxMagnitude, Min, and MinMagnitude were not doing the right thing

if (val1 > val2)
// When val1 and val2 are both finite or infinite, return the larger
// * We count +0.0 as larger than -0.0 to match MSVC
// When val1 or val2, but not both, are NaN return the opposite
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change, but matches what the C Runtime does and what the IEEE spec defines

@tannergooding
Copy link
Member Author

The PAL_ilogb and PAL_ilogbf methods will need to be updated to return the same result as Windows for 0.0, -0.0, and NaN.

{
return val1;
}

return val2;
// We do this comparison first and separately to handle the -0.0 to +0.0 comparision
Copy link
Member Author

@tannergooding tannergooding Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note here: This optimization is completely fine for the JIT to do since the IEEE spec indicates that comparisons shall ignore the sign of zero and for Min/Max, the JIT specifies that either x or y can be returned if x == y.

I opted to respect the sign of zero here since the MSVC/GCC/Clang implementation does and since Annex F of the C Language specification (which dictates IEC 60559 compliance) has a footnote indicating that respecting the sign of zero here would be "ideal".

@tannergooding
Copy link
Member Author

CC. @AndyAyersMS, @eerhardt who have reviewed the past Math API additions. Also CC. @ViktorHofer who is a System.Numerics area owner and @danmosemsft who raised the ILogB casing issue.

#if !HAVE_COMPATIBLE_ILOGB0
if (x == 0.0)
{
ret = -2147483648;
Copy link
Member

@eerhardt eerhardt Nov 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if we had a constant with a descriptive name for these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are existing constants (FP_ILOGB0 and FP_ILOGBNAN) and they have incorrect values. I don't think we want to have another name which might cause more confusion for what is only handled in two places here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we also couldn't consume the constant everywhere, such as the configure.cmake files; which might make it even more confusing)

// When x or y, but not both, are NaN return the opposite
// * We return the opposite if either is NaN to match MSVC

if (double.IsNaN(x))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is super unfortunate that we went from val1 and val2 in other methods to x and y here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x and y are likely the better choices here overall. They are the terms used in C/C++ (and a number of other languages), in the IEEE spec, and commonly in mathematics when referring to these functions and their parameters.

If we had the ability to standardize on one, without it being a breaking change, x and y are likely the names I would push for.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@tannergooding tannergooding merged commit a49296e into dotnet:master Nov 12, 2018
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corefx that referenced this pull request Nov 12, 2018
* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corert that referenced this pull request Nov 12, 2018
* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
stephentoub pushed a commit to dotnet/corefx that referenced this pull request Nov 12, 2018
* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corert that referenced this pull request Nov 13, 2018
* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jlennox pushed a commit to jlennox/corefx that referenced this pull request Dec 16, 2018
* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…coreclr#20912)

* Fixing Max, MaxMagnitude, Min, and MinMagnitude for Math/MathF to be IEEE compliant

* Disabling the System.Math.Max/Min tests

* Adding the new c_runtime PAL tests to the CMakeLists to ensure they actually get run.

* Fixing the casing of IlogB to ILogB

* Fixing the new PAL tests to match the correct/expected outputs

* Fixing up PAL_ilogb to correctly handle 0 and NaN


Commit migrated from dotnet/coreclr@a49296e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants