on Transcendental
compare(
to other: Transcendental,
withPrecision digits: PositiveInteger,
) -> Optional<Ordering>
Orders the Transcendental against another one, to a given number of decimal places.
The difference of the two is enclosed in an interval under one unit of the last decimal place wide. The answer is read off that interval. Two values one unit of that place or more apart are always told apart. The answer is empty only for two values closer than that. Two values whose π and e terms cancel differ by a Rational, and compare exactly at any width. No call here reaches the precision cutoff that Number::compare can, since nothing is refined past the width given.
NameTypeDescription
toTranscendentalthe Transcendental to order against
withPrecisionPositiveIntegerthe number of decimal places the two are told apart to Returns Ordering#Less, Ordering#Equal or Ordering#Greater, or nothing when the two are not told apart at that width.
Example
constant nearPi = Number.E::add(0.42331)
expect Number.Pi::compare(to Number.E, withPrecision 2)::is(#Greater)
expect Number.Pi::compare(to nearPi, withPrecision 7)::is(#Greater)
on Transcendental
Answers the Transcendental as a String, in the exact symbolic form or in the named format.
The form is π, 2·π, e or 1 + π + e when no format is named, and #Fraction names that same form. The #Decimal format writes the expansion, to at most 80 digits, which is the cap a Rational writes a non-terminating expansion at. A count of places writes exactly that many digits after the point.
Answers the Transcendental as a String, in the exact symbolic form: π, 2·π, e or 1 + π + e.
Example
expect Number.Tau::toString()::is("2·π")
expect Number.E::add(1)::toString()::is("1 + e")
Answers the Transcendental as a decimal, or in the exact symbolic form, in the named format.
The #Decimal format rounds the expansion at the eightieth digit and writes it. An irrational expansion never ends, so the cap is always reached. Trailing zeros the rounding leaves are dropped, as they are for any Rational. The #Percent format writes one hundred times that same reading, taken two digits deeper so that eighty still stand after the point. The #Scientific format writes eighty digits after the point of the mantissa, and the power of ten after an e. The reading is taken at the eightieth digit of the mantissa, wherever the value falls. A value below one is read deeper than eighty places. The #Fraction format writes the symbolic form, since no ratio of two Integers is this number.
Returns the String representation of the Transcendental.
Example
expect Number.Pi::toString(as #Decimal)::starts(with "3.14159265358")
expect Number.Pi::toString(as #Fraction)::is("π")
toString(
as format: NumberFormat,
toPlaces count: Integer,
toward direction: Rounding = #Nearest,
) -> String
Answers the Transcendental as a decimal with exactly that many places.
The digits are padded with zeroes where the rounded value is shorter. The last digit kept is rounded in the named direction, and #Nearest is what a call that names none is given. A count below one rounds to a whole number, and no point is written. The #Percent format takes the count the same way, on one hundred times the value. The #Scientific format counts the digits of the mantissa after the point, at every magnitude. The value is read as many digits past the count as its own power of ten falls below zero. The #Fraction format ignores both the count and the direction, and writes the symbolic form.
NameTypeDescription
toPlacesIntegerhow many digits to write after the point
towardRounding = #Nearestthe direction to round the last digit in, #Nearest when it is left out Returns the String representation of the Transcendental.
Example
constant pi = Number.Pi
expect pi::toString(as #Decimal, toPlaces 2)::is("3.14")
expect pi::toString(as #Decimal, toPlaces 2, toward #Up)::is("3.15")
expect pi::toString(as #Percent, toPlaces 1)::is("314.2%")
on Transcendental
Answers the exact sum of the Transcendental and a number.
Two Transcendentals can cancel their π and e terms, which leaves a Rational.
add(_ other: Integer) -> Transcendental
Adds an Integer to the Transcendental.
The sum is a Transcendental, since an Integer changes the rational part alone.
NameTypeDescription
_Integerthe Integer to add
Returns the sum, as a Transcendental.
Example
expect Number.Pi::add(1)::toString()::is("1 + π")
add(_ other: Rational) -> Transcendental
Adds a Rational to the Transcendental.
The sum is a Transcendental, since a Rational changes the rational part alone.
NameTypeDescription
_Rationalthe Rational to add
Returns the sum, as a Transcendental.
Example
expect Number.Pi::add(1/2)::toString()::is("1/2 + π")
add(_ other: Transcendental) -> Rational | Transcendental
Answers the exact sum of the two Transcendentals.
The π and e parts can cancel, which leaves a Rational.
NameTypeDescription
_Transcendentalthe Transcendental to add
Returns the exact sum, a Rational or a Transcendental.
Example
expect Number.Pi::add(Number.E)::toString()::is("π + e")
expect Number.Pi::add(Number.Pi::negate())::is(0)
on Transcendental
Answers the exact difference of the Transcendental and a number.
Subtracting equal π and e terms leaves a Rational.
subtract(_ other: Integer) -> Transcendental
Subtracts an Integer from the Transcendental.
The difference is a Transcendental, since an Integer changes the rational part alone.
NameTypeDescription
_Integerthe Integer to subtract
Returns the difference, as a Transcendental.
Example
expect Number.Pi::subtract(3)::toString()::is("-3 + π")
subtract(_ other: Rational) -> Transcendental
Subtracts a Rational from the Transcendental.
The difference is a Transcendental, since a Rational changes the rational part alone.
NameTypeDescription
_Rationalthe Rational to subtract
Returns the difference, as a Transcendental.
Example
expect Number.Pi::subtract(1/2)::toString()::is("-1/2 + π")
subtract(_ other: Transcendental) -> Rational | Transcendental
Subtracts one Transcendental from another.
Equal π and e terms cancel, which leaves a Rational. Every other difference is a Transcendental.
NameTypeDescription
_Transcendentalthe Transcendental to subtract
Returns the difference, as a Rational or a Transcendental.
Example
expect Number.Tau::subtract(Number.Pi)::is(Number.Pi)
expect Number.Pi::subtract(Number.Pi)::is(0)
on Transcendental
Answers the exact product of the Transcendental and an Integer or a Rational.
Multiplying by zero answers zero. Multiplying by a NonZeroInteger or a NonZeroRational keeps every base term, so those entries answer a Transcendental. Two Transcendentals can not be multiplied: π·π and π·e leave the linear grammar.
multiply(with other: Integer) -> Transcendental | Rational
Multiplies the Transcendental with an Integer.
The product is a Transcendental, since an Integer scales the rational part and every base term. A zero factor answers zero, which is a Rational.
NameTypeDescription
withIntegerthe Integer to multiply with
Returns the product, as a Transcendental or a Rational.
Example
constant turns = 2
expect Number.Pi::multiply(with turns)::is(Number.Tau)
expect Number.Pi::multiply(with 0)::is(0)
multiply(with other: Rational) -> Transcendental | Rational
Multiplies the Transcendental with a Rational.
The product is a Transcendental, since a Rational scales the rational part and every base term. A zero factor answers zero, which is a Rational.
NameTypeDescription
withRationalthe Rational to multiply with
Returns the product, as a Transcendental or a Rational.
Example
constant half = 1/2
expect Number.Tau::multiply(with half)::is(Number.Pi)
expect Number.Pi::multiply(with 0/1)::is(0)
Answers the exact product of the Transcendental and a factor proven not to be zero.
A non-zero Integer scales the rational part and every base term, and no coefficient reaches zero. The answer is again a Transcendental rather than a Union.
Returns the exact product.
Example
expect Number.Pi::multiply(with 2)::is(Number.Tau)
expect Number.E::multiply(with 3)::toString()::is("3·e")
Answers the exact product of the Transcendental and a Rational factor proven not to be zero.
A Rational that is not zero scales the rational part and every base term, and no coefficient reaches zero. The answer is again a Transcendental rather than a Union.
Returns the exact product.
Example
expect Number.Tau::multiply(with 1/2)::is(Number.Pi)
expect Number.Pi::multiply(with 3/2)::toString()::is("3/2·π")
on Transcendental
Answers the exact quotient of the Transcendental and a number.
Dividing by an Integer or a Rational is empty only for zero. Dividing by a NonZeroInteger or a NonZeroRational can not fail, because those divisors are proven. Dividing by another Transcendental answers a Rational when the two are proportional: Tau::divide(by Pi) is 2. Anything else is empty. The defaultingTo: entries answer the given value in place of empty.
divide(by other: Integer) -> Optional<Transcendental>
Divides the Transcendental by an Integer.
The quotient is a Transcendental, since an Integer scales the rational part and every base term. A zero divisor answers empty, and the defaultingTo: entry answers the given value instead.
NameTypeDescription
byIntegerthe Integer to divide by
Returns the quotient, or nothing when the divisor is zero.
Example
constant divisor = 2
expect Number.Tau::divide(by divisor)::is(Number.Pi)
expect Number.Pi::divide(by 0)::isEmpty()
divide(by other: Rational) -> Optional<Transcendental>
Divides the Transcendental by a Rational.
The quotient is a Transcendental, since a Rational scales the rational part and every base term. A zero divisor answers empty, and the defaultingTo: entry answers the given value instead.
NameTypeDescription
byRationalthe Rational to divide by
Returns the quotient, or nothing when the divisor is zero.
Example
constant half = 1/2
expect Number.Pi::divide(by half)::is(Number.Tau)
expect Number.Pi::divide(by 0/1)::isEmpty()
divide(by other: Transcendental) -> Optional<Rational>
Answers the exact quotient of the two Transcendentals.
Proportional values answer a Rational: Tau::divide(by Pi) is 2. Anything else is empty, including π divided by e.
NameTypeDescription
byTranscendentalthe Transcendental to divide by
Returns the quotient, or nothing when the two are not proportional.
Example
expect Number.Tau::divide(by Number.Pi)::is(2/1)
expect Number.Pi::divide(by Number.E)::isEmpty()
divide(
by other: Integer,
defaultingTo fallback: Transcendental,
) -> Transcendental
Answers the exact quotient of the Transcendental and an Integer.
A zero divisor answers the given value.
NameTypeDescription
byIntegerthe divisor
defaultingToTranscendentalthe value to answer with when there is no quotient
Returns the quotient, or the given value in its place.
Example
constant tau = Number.Tau
constant divisor = 2
expect tau::divide(by divisor, defaultingTo tau)::is(Number.Pi)
expect tau::divide(by 0, defaultingTo tau)::is(tau)
divide(
by other: Rational,
defaultingTo fallback: Transcendental,
) -> Transcendental
Answers the exact quotient of the Transcendental and a Rational.
A zero divisor answers the given value.
NameTypeDescription
byRationalthe divisor
defaultingToTranscendentalthe value to answer with when there is no quotient
Returns the quotient, or the given value in its place.
Example
constant pi = Number.Pi
constant half = 1/2
expect pi::divide(by half, defaultingTo pi)::is(Number.Tau)
expect pi::divide(by 0/1, defaultingTo pi)::is(pi)
divide(
by other: Transcendental,
defaultingTo fallback: Rational,
) -> Rational
Answers the exact quotient of the two Transcendentals.
Where the two are not proportional, the answer is the given value.
NameTypeDescription
byTranscendentalthe divisor
defaultingToRationalthe value to answer with when there is no quotient
Returns the quotient, or the given value in its place.
Example
expect Number.Tau::divide(by Number.Pi, defaultingTo 0/1)::is(2)
expect Number.Pi::divide(by Number.E, defaultingTo 0/1)::is(0)
Answers the exact quotient of the Transcendental and a divisor proven not to be zero.
The division can not fail, so the answer is the quotient itself rather than an Optional.
Returns the exact quotient.
Example
expect Number.Tau::divide(by 2)::is(Number.Pi)
expect Number.Pi::divide(by 2)::toString()::is("1/2·π")
Answers the exact quotient of the Transcendental and a Rational divisor proven not to be zero.
The division can not fail, so the answer is the quotient itself rather than an Optional.
Returns the exact quotient.
Example
expect Number.Pi::divide(by 1/2)::is(Number.Tau)
on Transcendental
Answers the Transcendental as a Rational on a decimal grid of the given width.
Five places answer the value rounded to hundred-thousandths, so Number.Pi over five places answers 314159/100000. This Method is where a Program asks for digits in place of the exact value. The answer is exact all the same: it is the step of that grid the value rounds to. A width of no places answers a whole number, as a Rational.
A value over a single base is always answered for. A value carrying both π and e can not be shown to miss every step of the grid. Deciding that would settle an open problem. A call on such a value is answered while the enclosure the width needs stays inside the cutoff Number::compare names. A width past that cutoff stops the Program.
NameTypeDescription
towardRounding = #Nearestthe direction to round in, #Nearest when it is left out Returns the value on the grid the width names.
Example
expect Number.Pi::approximate(toPlaces 5)::is(3.14159)
expect Number.E::approximate(toPlaces 2, toward #Down)::is(2.71)
expect Number.Pi::approximate(toPlaces 0)::is(3/1)
on Transcendental
Answers the Transcendental rounded in the named direction.
The direction is #Nearest when a call names none. An irrational is never exactly halfway between two steps, so #Nearest and #NearestEven answer alike here. The other directions answer the floor for #Down, the ceiling for #Up, and the step towards zero for #TowardZero. Naming a count of places rounds to a decimal grid of that width instead, and answers a Rational.
round(toward direction: Rounding = #Nearest) -> Integer
Answers the Transcendental as an Integer, rounded in the named direction.
NameTypeDescription
towardRounding = #Nearestthe direction to round in, #Nearest when it is left out Returns the rounded Integer.
Example
expect Number.Pi::round()::is(3)
expect Number.Pi::round(toward #Up)::is(4)
round(
toPlaces places: Integer,
toward direction: Rounding = #Nearest,
) -> Rational
Answers the Transcendental rounded to a decimal grid of the given width.
Two places round to hundredths. The answer is what approximate(toPlaces:toward:) answers, and a count below one rounds to a whole number. The entry stands here so that a Number receiver reaches round at every width, whichever kind it holds.
NameTypeDescription
toPlacesIntegerhow many decimal places to keep
towardRounding = #Nearestthe direction to round in, #Nearest when it is left out Returns the rounded Rational.
Example
expect Number.Pi::round(toPlaces 2)::is(3.14)
expect Number.Pi::round(toPlaces 2, toward #Up)::is(3.15)
on Transcendental
decimalExponent() -> Integer
Answers the power of ten at or below the Transcendental's distance from zero.
This is the exponent the #Scientific format writes after the e. A value between one and ten answers zero, and a value between a tenth and one answers minus one. The enclosure widens until it falls inside one such power of ten. A value over a single base always falls inside one, since it is never a power of ten itself. A value carrying both π and e reaches the cutoff Number::compare names where it does not, and stops the Program there.
Returns the exponent of the power of ten the value falls on.
Example
expect Number.Pi::decimalExponent()::is(0)
expect Number.Pi::subtract(3)::decimalExponent()::is(-1)
expect Number.Pi::multiply(with 100)::decimalExponent()::is(2)