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

Fix NSDecimalPower(_:_:_:_:) behavior #4799

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Fix NSDecimalPower(_:_:_:_:) behavior #4799

wants to merge 3 commits into from

Conversation

Oschly
Copy link

@Oschly Oschly commented Jul 22, 2023

NSDecimalPower accepts Int as power parameter, but internally it calls power(_:roundingMode:) method, that accepts only UInt as power value. That results in overflow error for every call of NSDecimalPower with negative power parameter.

This PR fixes that behavior by modifying power method by making p an Int and adds additional code for handling negative p.

This PR solves #3237

@MaxDesiatov
Copy link
Member

@swift-ci test

Sources/Foundation/Decimal.swift Outdated Show resolved Hide resolved
@MaxDesiatov
Copy link
Member

Either the tests or the implementation need to be updated as this test case fails on CI.

- rename power to absPower
- compare p to 0 and 1, instead of absPower (comparing absPower to 1 results in invalid results)
- extract tests for negative power method to external test method
- typecast test results to NSDecimalNumber in tests, since by default they were Int
@MaxDesiatov
Copy link
Member

@swift-ci test

@MaxDesiatov
Copy link
Member

@swift-ci test windows

@MaxDesiatov
Copy link
Member

@compnerd I'm not seeing this macOS CI failure on PRs that you merged recently. Would you agree that it's sporadic and unrelated to this change and that it can be safely merged?

@compnerd
Copy link
Collaborator

@MaxDesiatov I think it would be good to understand whats going on though, the macOS build has been somewhat fragile.

@compnerd
Copy link
Collaborator

@swift-ci please test macOS platform

@MaxDesiatov
Copy link
Member

@swift-ci test macos

1 similar comment
@MaxDesiatov
Copy link
Member

@swift-ci test macos

@MaxDesiatov
Copy link
Member

@swift-ci test

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.

None yet

3 participants