Skip to content

[stdlib] Fix error in nextUp and nextDown #2801

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
Jun 2, 2016

Conversation

natecook1000
Copy link
Member

What's in this pull request?

This fixes an error in the nextUp and nextDown implementation and adds a test for verification.

Before:

(swift) (10.nextUp, 10.nextDown)
// r0 : (Double, Double) = (10.000000000000002, -10.000000000000002)
(swift) ((-10).nextUp, (-10).nextDown)
// r1 : (Double, Double) = (10.000000000000002, -10.000000000000002)

After:

(swift) (10.nextUp, 10.nextDown)
// r0 : (Double, Double) = (10.000000000000002, 9.9999999999999982)
(swift) ((-10).nextUp, (-10).nextDown)
// r1 : (Double, Double) = (-9.9999999999999982, -10.000000000000002)

Resolved bug number: n/a


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.

@natecook1000 natecook1000 changed the title Nc nextup [stdlib] Fix error in nextUp and nextDown Jun 1, 2016
@natecook1000
Copy link
Member Author

@swift-ci Please test

@@ -171,6 +171,42 @@ FloatingPoint.test("Double/HashValueZero") {
expectEqual(zero.hashValue, negativeZero.hashValue)
}

FloatingPoint.test("Float/NextUp") {
let values: [Float] = [-20, -2, -1, -0, 0, 1, 2, 20]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change the tests to check the output exactly?

/// Pairs of consecutive floating point numbers as ordered by `nextUp`/`nextDown`.
let nextUpDownTests: [(Float, Float)] = [
  (Float.nan, Float.nan),
  (Float.infinity, Float.infinity),
  (-Float.infinity, -Float.infinity),
  (0x1.fffffep-1, 1.0), (1.0, 0x1.000002p+0),
  (-0x1p-149, 0.0), (0.0, 0x1p-149),
  (0x1.effffep-1, 0.96875), (0.96875, 0x1.f00002p-1),
]

FloatingPoint.test("Float.nextUp, .nextDown")
  .forEach(in: nextUpDownTests) {
  (prev, succ) in
  expectEqual(succ.bitPattern, prev.nextUp.bitPattern)
  expectEqual(prev.bitPattern, succ.nextDown.bitPattern)
  expectEqual((-succ).bitPattern, (-prev).nextDown.bitPattern)
  expectEqual((-prev).bitPattern, (-succ).nextUp.bitPattern)  
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I didn't know about that forEach method! I've updated the tests.

@lattner
Copy link
Contributor

lattner commented Jun 2, 2016

@stephentyrone just fyi

@natecook1000
Copy link
Member Author

@swift-ci Please test

@gribozavr gribozavr merged commit fb6fb95 into swiftlang:master Jun 2, 2016
@gribozavr
Copy link
Contributor

Thank you!

@natecook1000 natecook1000 deleted the nc-nextup branch June 3, 2016 01:22
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.

3 participants