Rational
A numeric type supporting precise division.
struct Rational
A numeric type supporting precise division.
struct Rational
import Utils
protocol Absolutable
protocol Addable
protocol AdditiveArithmetic : Equatable
A type with values that support addition and subtraction.
protocol Comparable : Equatable
A type that can be compared using the relational operators <
, <=
, >=
, and >
.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Divisible
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByIntegerLiteral
A type that can be initialized with an integer literal.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Multipliable
protocol Negatable
Describes a (signed) type that has an additive inverse.
protocol Numeric : AdditiveArithmetic, ExpressibleByIntegerLiteral
A type with values that support multiplication.
protocol Sendable
protocol SignedNumeric : Numeric
A numeric type with a negation operation.
protocol Subtractable
init?(_ string: String)
init(_ numerator: Int, _ denominator: Int, isPrecise: Bool = true)
init(approximately value: Double, accuracy: Int = 10_000)
init<T>(exactly value: T) where T : BinaryInteger
init(integerLiteral value: Int)
var absolute: Double { get }
var asDouble: Double { get }
var denominator: Int
var description: String { get }
var directDescription: String { get }
var isDisplayedAsFraction: Bool { get }
var isPrecise: Bool
var magnitude: Rational { get }
var numerator: Int
static func * (lhs: Rational, rhs: Rational) -> Rational
static func *= (lhs: inout Rational, rhs: Rational)
static func + (lhs: Rational, rhs: Rational) -> Rational
static func += (lhs: inout Rational, rhs: Rational)
static func - (operand: Rational) -> Rational
static func - (lhs: Rational, rhs: Rational) -> Rational
static func -= (lhs: inout Rational, rhs: Rational)
static func / (lhs: Rational, rhs: Rational) -> Rational
static func /= (lhs: inout Rational, rhs: Rational)
static func < (lhs: Rational, rhs: Rational) -> Bool
static func == (lhs: Rational, rhs: Rational) -> Bool
mutating func autoReduce()
func autoReduced() -> Rational
mutating func expand(by factor: Int)
func expanded(by factor: Int) -> Rational
func hash(into hasher: inout Hasher)
mutating func negate()
mutating func reduce()
mutating func reduce(by factor: Int)
func reduced() -> Rational
func reduced(by factor: Int) -> Rational
func signum() -> Int
static var zero: Self { get }
The zero value.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
static func + (x: Self) -> Self
Returns the given number unchanged.
static func += (lhs: inout Self, rhs: Self)
static func - (operand: Self) -> Self
Returns the additive inverse of the specified value.
static func -= (lhs: inout Self, rhs: Self)
static func ... (minimum: Self) -> PartialRangeFrom<Self>
Returns a partial range extending upward from a lower bound.
static func ... (maximum: Self) -> PartialRangeThrough<Self>
Returns a partial range up to, and including, its upper bound.
static func ... (minimum: Self, maximum: Self) -> ClosedRange<Self>
Returns a closed range that contains both of its bounds.
static func ..< (maximum: Self) -> PartialRangeUpTo<Self>
Returns a partial range up to, but not including, its upper bound.
static func ..< (minimum: Self, maximum: Self) -> Range<Self>
Returns a half-open range that contains its lower bound but not its upper bound.
static func <= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.
static func > (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.
static func >= (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.
mutating func negate()
Replaces this value with its additive inverse.