Swift package adding fraction and percentage types.

Overview

swift-rationals

Rationals is a package containing Fraction and Percentage types for the Swift programming language.

Contents

The package currently provides the following extensions:

BinaryFloatingPoint

  • isInteger: A boolean value indicating whether this instance is an integer.
  • integral: The integral part of this instance.
  • fractional: The fractional part of this instance.
  • decimal: The decimal part of this instance.
  • totalDigits: The number of total digits in this instance.
  • decimalPlaces: The number of decimal places in this instance.
  • truncated(to:): Returns this instance truncated to the specified decimal place.
  • truncate(to:): Truncates this instance to the specified decimal place.

And the following implementations:

Fraction: A representation of a fraction, or the quotient of two numbers without loss of precision.

  • init(_:on:): Creates a new instance with the specified numerator and denominator.
  • init(_:and:on:): Creates a new instance with the specified integral, numerator and denominator.
  • init(approximately:withPrecision:): Creates a new instance with the specified approximate value.
  • isDyadic: A boolean value indicating whether this fraction is dyadic.
  • isImproper: A boolean value indicating whether this fraction is improper.
  • isMixed: A boolean value indicating whether this fraction is improper.
  • isNormalized: A boolean value indicating whether this fraction is normalized.
  • isProper: A boolean value indicating whether this fraction is proper.
  • isSimplified: A boolean value indicating whether this fraction is simplified.
  • isUnit: A boolean value indicating whether this fraction is a unit.
  • isWhole: A boolean value indicating whether this instance is whole.
  • isEquivalent(to:): Returns a boolean value indicating whether the two specified fractions are equivalent.
  • isLike(_:): Returns a boolean value indicating whether the two specified fractions are like fractions.

Simplified: A property wrapper that keeps a fraction at its lowest terms.

Percentage: A representation of a percentage, or the quotient of a fraction with a denominator of 100.

  • init(_:): Creates a new instance with the specified numerator.

Increasable: Representing values that can be increased by n percent.

  • increasing(by:): Returns this instance increased by the specified value.
  • increase(by:): Increases this instance by the specified value and produces their sum.

Decreasable: Representing values that can be decreased by n percent.

  • decreasing(by:): Returns this instance decreased by the specified value.
  • decrease(by:): Decreases this instance by the specified value and produces their difference.

Installation

To use this package in a SwiftPM project:

  1. Add it to the dependencies in your Package.swift file:
let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/alexandrehsaad/swift-rationals.git", from: "main")
    ],
    ...
)
  1. Add it as a dependency for your target in your Package.swift file:
let package = Package(
    ...
    targets: [
        .target(name: "MyTarget", dependencies: [
            .product(name: "Rationals", package: "swift-rationals")
        ]),
    ],
    ...
)
  1. Import the package in your source code.
import Rationals

Contribution

Reporting a bug

If you find a bug, please open a bug report.

Contacting the maintainers

The current code owner of this package is Alexandre H. Saad (@alexandrehsaad). You can contact him by writing an email to alexandresaad at icloud dot com.

Supporting

If you like our work, show your support by staring this repository.

Feedback

We would love to hear your thoughts or feedback on how we can improve Swift Rationals!

You might also like...
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

A Swift μ-Library for Somewhat Dependent Types

Validated Validated is a μ-library (~50 Source Lines of Code) that allows you make better use of Swift's type system by providing tools for easily gen

The ISO 8601 period/duration types missing in Foundation

PeriodDuration This library introduces a close equivalent to Java's PeriodDuration, motivated by the lack of support for this standard in Foundation.

Unboxing - An extension for KeyedDecodingContainer class to decode a collection of heterogeneous types.

Unboxing An extension for KeyedDecodingContainer class to decode a collection of heterogeneous types. Usage Start by creating an enum that has variant

MediaType is a library that can be used to create Media Types in a type-safe manner.

This is a general purpose Swift library for a concept of typed treatment for Media Types. We use this library on clients and servers to speak the same dialect and to enjoy all the comfort strong types provide over raw strings.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

A command-line tool and Swift Package for generating class diagrams powered by PlantUML
A command-line tool and Swift Package for generating class diagrams powered by PlantUML

SwiftPlantUML Generate UML class diagrams from swift code with this Command Line Interface (CLI) and Swift Package. Use one or more Swift files as inp

A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Units is a Swift package to manipulate, compare, and convert between physical quantities.

Units 📏 Units is a Swift package to manipulate, compare, and convert between physical quantities. This package models measurements, which are a numer

Releases(0.0.1)
Owner
Alexandre H. Saad
Student @ Apple Developer Academy | Software Engineer | Graphic Designer | iOS | Swift | UI/UX
Alexandre H. Saad
Arbitrary precision fraction in Swift.

Fraction Arbitrary precision fraction in Swift. Usage Fraction can be converted from BinaryInteger, BinaryFloatingPoint or String. It supports nearly

Vaida 0 Dec 10, 2021
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Mathias Quintero 9 Sep 25, 2022
Numerals is a package containing additional numeric types for the Swift programming language.

swift-numerals Numerals is a package containing additional numeric types for the Swift programming language. Contents The package currently provides t

Alexandre H. Saad 0 Jul 28, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 2022
A lightweight extension to Swift's CollectionDifference, supporting moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

DifferenceTracker is a lightweight extension to Swift's CollectionDifference. It defines moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

Giles Hammond 2 Nov 25, 2022
How Swift standard types and classes were supposed to work.

How Swift standard types and classes were supposed to work. A collection of useful extensions for the Swift Standard Library, Foundation, and UIKit.

Goktug Yilmaz 3k Dec 22, 2022
Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Alonso Alvarez 1 Jan 9, 2022
Extensions for Swift Standard Types and Classes

Cent Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. Dollar is a Swif

Ankur Patel 225 Dec 7, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022