Skip to content

Expose Decimal.pow() as a public API on FoundationEssentials #1471

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 1 commit into from
Aug 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Sources/FoundationEssentials/Decimal/Decimal+Compatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,13 @@ extension Decimal : _ObjectiveCBridgeable {
// MARK: - Bridging code to C functions
// We have one implementation function for each, and an entry point for both Darwin (cdecl, exported from the framework), and swift-corelibs-foundation (SPI here and available via that package as API)

#if FOUNDATION_FRAMEWORK
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public func pow(_ x: Decimal, _ y: Int) -> Decimal {
let result = try? x._power(
exponent: y, roundingMode: .plain
)
return result ?? .nan
}
#else
Copy link
Contributor

Choose a reason for hiding this comment

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

Is pow available as API on Decimal itself instead of just via the free function?

Copy link
Contributor

Choose a reason for hiding this comment

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

My read is that this has always been a free function, both on Darwin and non-Darwin. This PR just unifies the code and makes it available for FoundationEssentials too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

@_spi(SwiftCorelibsFoundation)
public func _pow(_ x: Decimal, _ y: Int) -> Decimal {
let result = try? x._power(
exponent: y, roundingMode: .plain
)
return result ?? .nan
}
#endif

private func __NSDecimalAdd(
_ result: UnsafeMutablePointer<Decimal>,
Expand Down