apple / apple/swift-numerics

Add `compound` function

Open
#161 4 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue question
Dominant language
Swift
Stars
1.9k
Forks
181
Avg merge
2d 5h
Merged PRs (30d)
6

Description

IEEE 754 recommends (but does not require) a `compound` function, which is in the process of being standardized for C and C++; we should expose it in swift-numerics. The simplest, most literal translation of the operation into Swift would be:

```swift
extension RealFunctions {
/// (1+x)ⁿ
///
/// Returns NaN if x < -1.
static func compound(_ x: Self, _ n: Int) -> Self {
// not quite production-quality implementation
// (good for well-scaled results, loses precision
// near overflow and underflow, also misbehaves
// when n cannot be represented as Self).
exp(Self(n) * log(onePlus: x))
}
}
```

A good implementation is somewhat subtle, but we can come up with a good solution. I'm initially mainly interested in feedback on what the API should look like for this operation, both the naming and whether to put it on RealFunctions or ElementaryFunctions (where it can also be defined).

Contributor guide

Open the contributing guide

Research direction

Review the proposed compound API and compare whether it belongs on RealFunctions or ElementaryFunctions. Check the IEEE 754 recommendation and the related C and C++ standardization context first. Done means reaching agreement on the name, placement, and behavior before implementing the numerically robust operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.