Latest 0.1.0
Homepage https://github.com/erikstrottmann/Rations
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0, watchos 2.0
Authors

Build Status
Version
Supported Package Managers
Supported Platforms

A rational number type for Swift.

Rations is a rational number value type for Swift. It allows you to perform calculations on fractional numbers without the loss of precision caused by floating-point arithmetic. Rational numbers are useful for representing currency and for other applications where exact results, not approximations, are desired.

For example, the fraction 1/3 can be exactly represented as a rational number, but not as a floating point number:

let x: Rational = 1 / 3
// x == 1/3
let y: Double = 1 / 3
// y == 0.3333333333333333

Rations does have a performance penalty compared to Swift’s native floating point types. You might not want to use Rations in performance-sensitive areas. Each operation that returns a rational number involves calculating the greatest common divisor of the numerator and denominator using the Euclidean algorithm.

Install

Rations requires Swift 4.2 or higher. It supports iOS, macOS, tvOS, watchOS, and Linux.

Swift Package Manager

Add the following line to your Package.swift:

.package(url: "https://github.com/erikstrottmann/Rations.git", from: "0.1.0"),

CocoaPods

Add the following line to your Podfile:

pod 'Rations', '~> 0.1.0'

Carthage

Add the following line to your Cartfile:

github "erikstrottmann/Rations" ~> 0.1.0

Usage

let x: Rational = 1 / 4
let y: Rational = 2 / 3
let z = x + y
// z == 11/12

Contributing

Open an issue or a pull request!

License

MIT licensed, © 2018 Erik Strottmann.

Latest podspec

{
    "name": "Rations",
    "version": "0.1.0",
    "summary": "A rational number type for Swift.",
    "description": "Rations is a rational number value type for Swift. It allows you tonperform calculations on fractional numbers without the loss of precisionncaused by floating-point arithmetic. Rational numbers are useful fornrepresenting currency and for other applications where exact results,nnot approximations, are desired.",
    "homepage": "https://github.com/erikstrottmann/Rations",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "authors": {
        "Erik Strottmann": "[email protected]"
    },
    "source": {
        "git": "https://github.com/erikstrottmann/Rations.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/erikstrottmann",
    "swift_version": "4.2",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source_files": "Sources/Rations/**/*"
}

Pin It on Pinterest

Share This