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

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
Contributor

@swift-ci test

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

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
Contributor

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@MaxDesiatov
Copy link
Contributor

@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
Member

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

@compnerd
Copy link
Member

@swift-ci please test macOS platform

@MaxDesiatov
Copy link
Contributor

@swift-ci test macos

1 similar comment
@MaxDesiatov
Copy link
Contributor

@swift-ci test macos

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@parkera
Copy link
Contributor

parkera commented Jul 19, 2024

This still seems relevant, and we just moved this stuff around too. @iCharlesHu can you take a look please?

@Oschly
Copy link
Author

Oschly commented Jul 27, 2024

It seems like it's still relevant, but now this issue appears in this repo and the swift-foundation. Should I close this PR and apply fix directly to swift-foundation or both PRs should be updated to the latest changes?

@parkera
Copy link
Contributor

parkera commented Jul 29, 2024

The idea here is that swift-foundation contains the canonical implementation (shared with Darwin). swift-corelibs-foundation exposes the free-standing function for Linux.

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.

5 participants