-
Notifications
You must be signed in to change notification settings - Fork 201
Open
swiftlang/swift-corelibs-foundation
#5259Labels
enhancementNew feature or requestNew feature or request
Description
The problem
The following math operations can be performed on Decimal
with FoundationEssentials:
import FoundationEssentials
let number: Decimal = 2.0
let added = number + number
let subtracted = number - number
let multiplied = number * number
let divided = number / number
However, raising aDecimal
to a power requires Foundation:
import Foundation
let number: Decimal = 2.0
let raised = pow(number, 2)
The solution
- The power operation should be available in FoundationEssentials alongside the basic decimal arithmetic operations.
- An exponentiation operator could be offered here to be consistent with the existing inline operator support (Python uses
**
, for example).
Additional context
- My app is particularly sensitive to binary size, so it's unfortunate that I have to import Foundation on non-Darwin platforms just for this somewhat essential function.
func pow(_ x: Decimal, _ y: Int) -> Decimal
in Foundation appears to be a wrapper aroundNSDecimalPower()
.- The
NSDecimalX()
functions are part of Foundation, not FoundationEssentials. NSDecimalAdd
,NSDecimalSubtract
,NSDecimalMultiply
, andNSDecimalDivide
are available in FoundationEssentials via operators, but an equivalent forNSDecimalPower()
is not offered.
lovetodream
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request