BFraction
The BFraction structure
struct BFraction
Overview
Please, see About BFraction
Constants
static let ZERO: BFraction
BFraction(0, 1)
static let ONE: BFraction
BFraction(1, 1)
Properties
var abs: BFraction
The absolute value of
self
var denominator: BInt
The denominator - a positive
BInt
valuevar description: String
String value of
self
var isInteger: Bool
Is
true
ifself
is an integer, that is, the denominator is 1var isNegative: Bool
Is
true
ifself
< 0,false
otherwisevar isPositive: Bool
Is
true
ifself
> 0,false
otherwisevar isZero: Bool
Is
true
ifself
= 0,false
otherwisevar numerator: BInt
The numerator - a
BInt
valuevar signum: Int
Is 0 if
self
= 0, 1 ifself
> 0, and -1 ifself
< 0
Constructors
init(BInt, BInt
) Constructs a
BFraction
from numerator and denominatorinit(BInt, Int
) Constructs a
BFraction
from numerator and denominatorinit(Int, BInt
) Constructs a
BFraction
from numerator and denominatorinit(Int, Int
) Constructs a
BFraction
from numerator and denominatorinit([BInt]
) Constructs a
BFraction
from a continued fraction - BInt versioninit([Int]
) Constructs a
BFraction
from a continued fraction - Int versioninit?(Double
) Constructs a
BFraction
from a decimal value,nil
ifd
is infinite or NaNinit?(String
) Constructs a
BFraction
from a String representation,nil
ifx
does not represent a decimal number
Conversion
func asString(
) -> String self
as a Stringfunc asDecimalString(precision: Int, exponential: Bool
) -> String self
as a Decimal String with a specified precision, possibly using exponential notationfunc asDouble(
) -> Double self
as a Doublefunc asContinuedFraction(
) -> [BInt] self
as a Continued Fraction
Addition
static func + (x: BFraction
) -> BFraction Prefix plus
static func + (x: BFraction, y: BFraction
) -> BFraction Addition
static func + (x: BFraction, y: BInt
) -> BFraction Addition
static func + (x: BInt, y: BFraction
) -> BFraction Addition
static func + (x: BFraction, y: Int
) -> BFraction Addition
static func + (x: Int, y: BFraction
) -> BFraction Addition
static func += (x: inout BFraction, y: BFraction
) x = x + y
static func += (x: inout BFraction, y: BInt
) x = x + y
static func += (x: inout BFraction, y: Int
) x = x + y
Subtraction
static func - (x: BFraction, y: BFraction
) -> BFraction Subtraction
static func - (x: BFraction, y: BInt
) -> BFraction Subtraction
static func - (x: BInt, y: BFraction
) -> BFraction Subtraction
static func - (x: BFraction, y: Int
) -> BFraction Subtraction
static func - (x: Int, y: BFraction
) -> BFraction Subtraction
static func -= (x: inout BFraction, y: BFraction
) x = x - y
static func -= (x: inout BFraction, y: BInt
) x = x - y
static func -= (x: inout BFraction, y: Int
) x = x - y
Negation
static func - (x: BFraction
) -> BFraction Negation
func negate(
) Negates
self
Multiplication
static func * (x: BFraction, y: BFraction
) -> BFraction Multiplication
static func * (x: BFraction, y: BInt
) -> BFraction Multiplication
static func * (x: BInt, y: BFraction
) -> BFraction Multiplication
static func * (x: BFraction, y: Int
) -> BFraction Multiplication
static func * (x: Int, y: BFraction
) -> BFraction Multiplication
static func *= (x: inout BFraction, y: BFraction
) x = x * y
static func *= (x: inout BFraction, y: BInt
) x = x * y
static func *= (x: inout BFraction, y: Int
) x = x * y
Division
/(_:_:)-3syd2
/(_:_:)-36e09
/(_:_:)-f4k1
/(_:_:)-nbpu
/(_:_:)-6s4x9
/=(_:_:)-5kwdi
/=(_:_:)-9882z
/=(_:_:)-an0e
func invert(
) -> BFraction Invert
self
Exponentiation
static func ** (a: BFraction, x: Int
) -> BFraction Exponentiation
Modulus
func mod(BInt
) -> BInt? Modulus - BInt version
func mod(Int
) -> Int? Modulus - Int version
Comparison
static func == (x: BFraction, y: BFraction
) -> Bool Equal
static func == (x: BFraction, y: BInt
) -> Bool Equal
static func == (x: BInt, y: BFraction
) -> Bool Equal
static func == (x: BFraction, y: Int
) -> Bool Equal
static func == (x: Int, y: BFraction
) -> Bool Equal
static func != (x: BFraction, y: BFraction
) -> Bool Not equal
static func != (x: BFraction, y: BInt
) -> Bool Not equal
static func != (x: BInt, y: BFraction
) -> Bool Not equal
static func != (x: BFraction, y: Int
) -> Bool Not equal
static func != (x: Int, y: BFraction
) -> Bool Not equal
static func < (x: BFraction, y: BFraction
) -> Bool Less than
static func < (x: BFraction, y: BInt
) -> Bool Less than
static func < (x: BInt, y: BFraction
) -> Bool Less than
static func < (x: BFraction, y: Int
) -> Bool Less than
static func < (x: Int, y: BFraction
) -> Bool Less than
static func > (x: BFraction, y: BFraction
) -> Bool Greater than
static func > (x: BFraction, y: BInt
) -> Bool Greater than
static func > (x: BInt, y: BFraction
) -> Bool Greater than
static func > (x: BFraction, y: Int
) -> Bool Greater than
static func > (x: Int, y: BFraction
) -> Bool Greater than
static func <= (x: BFraction, y: BFraction
) -> Bool Less than or equal
static func <= (x: BFraction, y: BInt
) -> Bool Less than or equal
static func <= (x: BInt, y: BFraction
) -> Bool Less than or equal
static func <= (x: BFraction, y: Int
) -> Bool Less than or equal
static func <= (x: Int, y: BFraction
) -> Bool Less than or equal
static func >= (x: BFraction, y: BFraction
) -> Bool Greater than or equal
static func >= (x: BFraction, y: BInt
) -> Bool Greater than or equal
static func >= (x: BInt, y: BFraction
) -> Bool Greater than or equal
static func >= (x: BFraction, y: Int
) -> Bool Greater than or equal
static func >= (x: Int, y: BFraction
) -> Bool Greater than or equal
Rounding
func round(
) -> BInt Round to nearest
func truncate(
) -> BInt Round towards 0
func ceil(
) -> BInt Round towards +Infinity
func floor(
) -> BInt Round towards -Infinity
Miscellaneous
static func bernoulli(Int
) -> BFraction Bernoulli number
static func bernoulliSequence(Int
) -> [BFraction] Bernoulli numbers
static func harmonic(Int
) -> BFraction Harmonic number: 1 + 1 / 2 + … + 1 / n
static func harmonicSequence(Int
) -> [BFraction] Harmonic sequence: The first n harmonic numbers