Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ythecombinator/gammafn
🔢 Gamma function (Γ) from mathematics in Swift.
https://github.com/ythecombinator/gammafn
approximation factorial gamma lanczos mathematics
Last synced: 15 days ago
JSON representation
🔢 Gamma function (Γ) from mathematics in Swift.
- Host: GitHub
- URL: https://github.com/ythecombinator/gammafn
- Owner: ythecombinator
- License: mit
- Created: 2017-08-07T06:51:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-16T03:49:40.000Z (over 7 years ago)
- Last Synced: 2024-11-17T15:34:52.208Z (3 months ago)
- Topics: approximation, factorial, gamma, lanczos, mathematics
- Language: Swift
- Homepage:
- Size: 51.8 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
🔢 gamma function (Γ) from mathematics in Swift 🔢
---
## đź“š Table of Contents
- [Installation](#-installation)
- [Getting Started](#-getting-started)
- [License](#️-license)## 📦 Installation
You just need to add this package as a dependency in your `Package.swift`:
```swift
let package = Package(
name: "MyProject",
dependencies: [
.Package(url: "https://github.com/ythecombinator/GammaFn.git", majorVersion: 1),
// ...
]
// ...
)
```## 🚀 Getting Started
### `gamma(for: Double) -> Double`
It returns the gamma function over `z`.
> *Note*: Complex ( `ℂ` ) numbers aren't supported–only Reals ( `ℝ` ).
```swift
import GammaFn// Creating a simple `Double` value which we intend to pass to our Γ function–which is a static method from `Double`:
let simpleValue1: Double = 6.0
let resultValue1 = Double.gamma(for value: simpleValue1)
// => 120.0000000000002// Another valid approach is accessing the property `gammaValue` from any `Double` value:
let simpleValue2: Double = 12.0
let resultValue2 = simpleValue2.gammaValue
// => 39916800.00000004
```### `logForGamma(of: Double) -> Double`
It returns the natural log of the gamma function for `z`.
> *Note*: This function is used internally by the [spouge approximation](https://en.wikipedia.org/wiki/Spouge's_approximation) to compute large values.
```swift
import GammaFn// Creating a simple `Double` value which we intend to pass to our Γ function–which is a static method from `Double`:
let simpleValue3: Double = 9.0
let resultValue3 = Double.gamma(for value: simpleValue3)
// => 10.64917311666183// Accessing the property `logValueForGamma` from any `Double` value is valid as well:
let simpleValue4: Double = 112.0
let resultValue4 = simpleValue4.logValueForGamma
// => 415.0403783916892
```## ⚖️ License
[GammaFn](https://github.com/ythecombinator/GammaFn) is distributed under
the MIT License, available in this repository.All contributions are assumed to be also licensed under the same.