Skip to content

Fix sNaN behavior of .minimum, .maximum, .minimumMagnitude and .maximumMagnitude. #3361

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

Merged
merged 2 commits into from
Jul 8, 2016
Merged

Fix sNaN behavior of .minimum, .maximum, .minimumMagnitude and .maximumMagnitude. #3361

merged 2 commits into from
Jul 8, 2016

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Jul 6, 2016

Specifically, if either argument is a signaling NaN, the result should be a quiet NaN. Previously, signaling NaN inputs were treated identically to quiet NaN inputs.

Some other changes folded in with this:

  • Formally define which argument is returned if lhs == hrs or abs(lhs) == abs(rhs) in the case of the Magnitude versions. This guarantees that the set {min,max} is identical to the set {lhs,rhs} so long as neither argument is NaN. This is not only a nod to formalism; it's also a critical property for generic head-tail arithmetic to simulate wider types.
  • Added test coverage for these four operations.

Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

and .maximumMagnitude in line with the IEEE 754 rules.

Specifically, if either argument is a signaling NaN, the result
should be a quiet NaN.  Previously, signaling NaN inputs were
treated identically to quiet NaN inputs.

Some other changes folded in with this:
- Formally define which argument is returned if lhs == rhs or
  abs(lhs) == abs(rhs) in the case of the Magnitude versions.
  This guarantees that the set {min,max} is identitical to
  the set {lhs,rhs} so long as neither argument is NaN.  This
  is not only a nod to formalism; it's also a critical property
  for generic head-tail arithmetic to simulate wider types.
- Added test coverage for these four operations.
@stephentyrone
Copy link
Contributor Author

@swift-ci please test.

@stephentyrone
Copy link
Contributor Author

@gribozavr I would appreciate another set of eyes on this if you can spare a few minutes.

@stephentyrone
Copy link
Contributor Author

OS X build failure is Foundation noise unrelated to this.

// IEEE 754 basic operations, this property is critical to ensure
// that clamping to a valid range behaves as expected.
else if lhs.isNaN && !rhs.isNaN {
print("lhs is \(lhs.bitPattern). rhs is \(rhs.bitPattern).")
Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, thanks. Will push a fix shortly.

@gribozavr
Copy link
Contributor

LGTM, that's how these operations signal an invalid operation exception.

@stephentyrone stephentyrone merged commit 5f47048 into swiftlang:master Jul 8, 2016
@stephentyrone stephentyrone deleted the min-max-snan-behavior branch July 11, 2016 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants