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

[SR-8070] remainder(dividingBy:) returns negative numbers #50603

Closed
swift-ci opened this issue Jun 21, 2018 · 6 comments
Closed

[SR-8070] remainder(dividingBy:) returns negative numbers #50603

swift-ci opened this issue Jun 21, 2018 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8070
Radar None
Original Reporter thirstyice (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

Mac Pro 3,1 (Early 2008)

OS X 10.11.6 El Capitan

Playground in Xcode 8.2.1

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: b3d158018dcb18a29275569d3bac18a5

Issue Description:

For some inputs, remainder(dividingBy🙂 returns a negative number. Tested specifically with dividingBy: 2, the results seem to alternate between 1 and -1 as the input increases.

e.g.

1.remainder(dividingBy: 2) == 1

3.remainder(dividingBy: 2) == -1

5.remainder(dividingBy: 2) == 1

7.remainder(dividingBy: 2) == -1

etc.

I would expect the remainder when dividing by 2 to be 1 for all positive odd numbers.

@belkadan
Copy link
Contributor

cc @moiseev

@belkadan
Copy link
Contributor

That is a pretty old version of Swift at this point, though, so it's entirely possible we fixed this already.

@moiseev
Copy link
Mannequin

moiseev mannequin commented Jun 22, 2018

/cc @stephentyrone

@moiseev
Copy link
Mannequin

moiseev mannequin commented Jun 22, 2018

Still reproducible. The tricky part though is that in these expressions what looks like integer literals, turn out to be Double values. The regular % operator when applied to 3 and 2 gives the expected 1 as a result.

@stephentyrone
Copy link
Member

What Max said. Why does `Double.remainder` behave like that? Here's the original proposal from way back when: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003410.html

@moiseev
Copy link
Mannequin

moiseev mannequin commented Jun 22, 2018

Resolving the issue as "Invalid" which really means "Behaves as designed".

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants