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-14009] pow(_ x: Decimal, _ y: Int) has surprising semantics #3237

Open
saagarjha opened this issue Dec 31, 2020 · 1 comment
Open

[SR-14009] pow(_ x: Decimal, _ y: Int) has surprising semantics #3237

saagarjha opened this issue Dec 31, 2020 · 1 comment

Comments

@saagarjha
Copy link

Previous ID SR-14009
Radar rdar://problem/72864727
Original Reporter @saagarjha
Type Bug
Environment

Xcode Version 12.3 (12C33)/macOS Big Sur 11.2 Beta (20D5029f)

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: c2eacc694dc7f45ed8434ce579601972

Issue Description:

pow(_ x: Decimal, _ y: Int) is a thin wrapper around NSDecimalPower. NSDecimalPower`s power argument is an NSUInteger but Swift exposes it as an Int, which gets casted as a UInt (presumably so the code can be translated in a straightforwards way from Foundation.framework). This means that the "reasonable-looking" pow(10 as Decimal, -2) is really "pow(10 as Decimal, 18446744073709551614 as UInt)". Internally this causes an overflow which is then exposed as a NaN because it seems like Decimal doesn't actually have a way of representing infinity. In the absence of the latter being fixed, it would be nice if the function at least took a UInt or had behavior that worked for negative integers.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants