The ratio of a circle's circumference to its diameter, exactly.
Every number the tower holds: an Integer, a Rational, an Algebraic or a Transcendental.
The name is for reading. Assignability ignores it, so a value of any member Type is a Number whether or not it was written as one.
Taught on: Numbers and Unions and type aliases.
At a glance
- Declared
namespace Number for Number- Views
ScalarforScalarin Mixed arithmetic
A view is a namespace for a narrower type. A value of that type has the view's methods on top of its own.
The tower
Number
Irrational
The numbers of the tower that are not ratios of Integers: an Algebraic or a Transcendental.
Algebraic and Transcendental are complements, since transcendental means not algebraic. The alias covers exactly the irrationals the tower holds.
Scalar
An Integer or a Rational: the two numeric kinds a Program computes with exactly.
Every Number is a Scalar or an Irrational. The two Methods below answer a Scalar for any two Scalars, which is what the mixed aggregates fold on.
Constants
Pi
on Number
Tau
on Number
Twice Pi, which is the ratio of a circle's circumference to its radius.
E
on Number
Euler's number, the base of the natural logarithm, exactly.
GoldenRatio
on Number
The golden ratio (1 + √5) / 2, the positive solution of x² = x + 1, exactly.
Aggregates
sum
on Number
Adds up every Number in the List.
The empty List sums to zero. A mixed List answers an Integer when its total is whole, and a Rational otherwise.
Returns the exact total.
Adds up every Integer in the List.
The sum is an Integer, since whole numbers add to a whole number. The empty List sums to zero.
List<Integer>the Integers to add upReturns the total.
Adds up every Rational in the List.
The sum is a Rational, since it need not be whole. A whole total stays a Rational here, so [1/2, 1/2]::sum() answers 1/1. The mixed entry below collapses one to an Integer. The empty List sums to zero.
List<Rational>the Rationals to add upReturns the total.
Adds up a List holding both Integers and Rationals.
The sum is an Integer when the total is whole, and a Rational otherwise. The empty List sums to zero.
List<Scalar>the Numbers to add upReturns the total.
product
on Number
Multiplies every Number in the List together.
The empty List multiplies to one. A mixed List answers an Integer when its product is whole, and a Rational otherwise.
Returns the exact product.
Multiplies every Integer in the List together.
The product is an Integer, since whole numbers multiply to a whole number. The empty List multiplies to one.
List<Integer>the Integers to multiplyReturns the product.
Multiplies every Rational in the List together.
The product is a Rational, since it need not be whole. A whole product stays a Rational here, as a whole sum does. The mixed entry below collapses one to an Integer. The empty List multiplies to one.
List<Rational>the Rationals to multiplyReturns the product.
Multiplies a List holding both Integers and Rationals together.
The product is an Integer when it is whole, and a Rational otherwise. The empty List multiplies to one.
List<Scalar>the Numbers to multiplyReturns the product.
average
on Number
The arithmetic mean of the Numbers in the List: their sum divided by their count, as an exact Rational.
The empty List has no mean, and the defaultingTo: entries answer the given Rational in place of nothing. A List proven to have an item answers the mean itself.
The arithmetic mean of the Integers: their sum divided by their count.
The mean is a Rational, since it need not be whole. The empty List has no mean.
List<Integer>the Integers to averageReturns the mean, or nothing for the empty List.
The arithmetic mean of the Rationals: their sum divided by their count.
The mean is a Rational. The empty List has no mean.
List<Rational>the Rationals to averageReturns the mean, or nothing for the empty List.
The arithmetic mean of a List holding both Integers and Rationals.
The mean is a Rational, since it need not be whole. The empty List has no mean.
List<Scalar>the Numbers to averageReturns the mean, or nothing for the empty List.
The arithmetic mean of the Integers, with a value to answer for the empty List.
List<Integer>the Integers to averageRationalthe value to answer with when there is no meanReturns the mean, or the given value in its place.
The arithmetic mean of the Rationals, with a value to answer for the empty List.
List<Rational>the Rationals to averageRationalthe value to answer with when there is no meanReturns the mean, or the given value in its place.
The arithmetic mean of the Numbers, with a value to answer for the empty List.
List<Scalar>the Numbers to averageRationalthe value to answer with when there is no meanReturns the mean, or the given value in its place.
The arithmetic mean of the Integers in a List proven to have an item.
The count is above zero, so the answer is the mean itself rather than an Optional.
Returns the mean.
The arithmetic mean of the Rationals in a List proven to have an item.
The count is above zero, so the answer is the mean itself rather than an Optional.
Returns the mean.
The arithmetic mean of the Numbers in a List proven to have an item.
The count is above zero, so the answer is the mean itself rather than an Optional.
Returns the mean.
lowest
on Number
The lower of two Numbers, or the lowest in a List of them.
The answer for two equal Numbers is the first of them. A List answers the earliest of its lowest items. The empty List has none, and the defaultingTo: entries answer the given Number in place of nothing. A List proven to have an item answers the item itself. A pair the four kind-preserving entries do not fit falls to the widest entry, which answers a Number.
The lower of two Integers.
The answer is an Integer. Two equal Integers answer the first of them.
Integerthe first Integer to compareIntegerthe second Integer to compareReturns the lower Integer.
The lower of two Rationals.
The answer is a Rational. Two equal Rationals answer the first of them.
Rationalthe first Rational to compareRationalthe second Rational to compareReturns the lower Rational.
The lower of an Integer and a Rational.
The answer keeps the kind of the Number it picks, so it is an Integer or a Rational. Two equal Numbers answer the Integer.
Integerthe Integer to compareRationalthe Rational to compareReturns the lower Number.
The lower of a Rational and an Integer.
The answer keeps the kind of the Number it picks, so it is an Integer or a Rational. Two equal Numbers answer the Rational.
Rationalthe Rational to compareIntegerthe Integer to compareReturns the lower Number.
The lowest of the Integers in the List.
The answer is the earliest of the lowest items. The empty List has none.
List<Integer>the Integers to compareReturns the lowest Integer, or nothing for the empty List.
The lowest of the Rationals in the List.
The answer is the earliest of the lowest items. The empty List has none.
List<Rational>the Rationals to compareReturns the lowest Rational, or nothing for the empty List.
The lowest Number in a List holding both Integers and Rationals.
The answer keeps the kind of the item it picks, and is the earliest of the lowest items. The empty List has none.
List<Scalar>the Numbers to compareReturns the lowest Number, or nothing for the empty List.
The lowest of the Integers, with a value to answer for the empty List.
List<Integer>the Integers to compareIntegerthe value to answer with when there is no lowestReturns the lowest Integer, or the given value in its place.
The lowest of the Rationals, with a value to answer for the empty List.
List<Rational>the Rationals to compareRationalthe value to answer with when there is no lowestReturns the lowest Rational, or the given value in its place.
The lowest of the Numbers, with a value to answer for the empty List.
List<Scalar>the Numbers to compareScalarthe value to answer with when there is no lowestReturns the lowest Number, or the given value in its place.
The lowest of the Integers in a List proven to have an item.
The List has a lowest item, so the answer is that item rather than an Optional.
Returns the lowest Integer.
The lowest of the Rationals in a List proven to have an item.
The List has a lowest item, so the answer is that item rather than an Optional.
Returns the lowest Rational.
The lowest of the Numbers in a List proven to have an item.
The List has a lowest item, so the answer is that item rather than an Optional.
Returns the lowest Number.
The lower of two Numbers, of any kind the tower holds.
The answer is a Number, since the two can be of different kinds. Two equal Numbers answer the first of them.
Numberthe first Number to compareNumberthe second Number to compareReturns the lower Number.
highest
on Number
The higher of two Numbers, or the highest in a List of them.
The answer for two equal Numbers is the first of them. A List answers the earliest of its highest items. The empty List has none, and the defaultingTo: entries answer the given Number in place of nothing. A List proven to have an item answers the item itself. A pair the four kind-preserving entries do not fit falls to the widest entry, which answers a Number.
The higher of two Integers.
The answer is an Integer. Two equal Integers answer the first of them.
Integerthe first Integer to compareIntegerthe second Integer to compareReturns the higher Integer.
The higher of two Rationals.
The answer is a Rational. Two equal Rationals answer the first of them.
Rationalthe first Rational to compareRationalthe second Rational to compareReturns the higher Rational.
The higher of an Integer and a Rational.
The answer keeps the kind of the Number it picks, so it is an Integer or a Rational. Two equal Numbers answer the Integer.
Integerthe Integer to compareRationalthe Rational to compareReturns the higher Number.
The higher of a Rational and an Integer.
The answer keeps the kind of the Number it picks, so it is an Integer or a Rational. Two equal Numbers answer the Rational.
Rationalthe Rational to compareIntegerthe Integer to compareReturns the higher Number.
The highest of the Integers in the List.
The answer is the earliest of the highest items. The empty List has none.
List<Integer>the Integers to compareReturns the highest Integer, or nothing for the empty List.
The highest of the Rationals in the List.
The answer is the earliest of the highest items. The empty List has none.
List<Rational>the Rationals to compareReturns the highest Rational, or nothing for the empty List.
The highest Number in a List holding both Integers and Rationals.
The answer keeps the kind of the item it picks, and is the earliest of the highest items. The empty List has none.
List<Scalar>the Numbers to compareReturns the highest Number, or nothing for the empty List.
The highest of the Integers, with a value to answer for the empty List.
List<Integer>the Integers to compareIntegerthe value to answer with when there is no highestReturns the highest Integer, or the given value in its place.
The highest of the Rationals, with a value to answer for the empty List.
List<Rational>the Rationals to compareRationalthe value to answer with when there is no highestReturns the highest Rational, or the given value in its place.
The highest of the Numbers, with a value to answer for the empty List.
List<Scalar>the Numbers to compareScalarthe value to answer with when there is no highestReturns the highest Number, or the given value in its place.
The highest of the Integers in a List proven to have an item.
The List has a highest item, so the answer is that item rather than an Optional.
Returns the highest Integer.
The highest of the Rationals in a List proven to have an item.
The List has a highest item, so the answer is that item rather than an Optional.
Returns the highest Rational.
The highest of the Numbers in a List proven to have an item.
The List has a highest item, so the answer is that item rather than an Optional.
Returns the highest Number.
The higher of two Numbers, of any kind the tower holds.
The answer is a Number, since the two can be of different kinds. Two equal Numbers answer the first of them.
Numberthe first Number to compareNumberthe second Number to compareReturns the higher Number.
Creating
parse
on Number
Reads a Number from its text form, as an Integer where the text holds one.
The text form is what Integer.parse reads, or what Rational.parse reads: a fraction like 3/4, a decimal like 0.75, or a whole number like 3. A whole number answers an Integer, and every other shape a Rational. Text of another shape answers empty, and the defaultingTo: entry answers the given Number instead.
Stringthe text to readReturns the Number, or nothing when the text has any other shape.
Reads a Number from its text form, with a value to answer when the text has another shape.
Stringthe text to readScalarthe value to answer with when the text is no NumberReturns the Number, or the given value in its place.
Cross-kind equality, ordering and printing
is
on Number
Answers whether the Number has the same numeric value as another Number.
An Integer and a Rational are the same Number when their values are equal, so 1 is 1/1 holds. The answer is read off compare. So two Transcendentals that both carry π and e can stop the Program at the precision cutoff compare names.
Numberthe Number to compare againstReturns true when both Numbers have the same numeric value.
compare
on Number
Orders the Number against another Number by numeric value, across every member of the tower.
Every pair is ordered exactly, with one exception. A Transcendental carrying both π and e is ordered against another Number by refining enclosures, and the refinement stops at 32768 decimal places. A pair that still agrees there stops the Program with an error, since deciding it exactly is an open problem. The bounded form is Transcendental::compare(to:withPrecision:), which answers empty instead.
Numberthe Number to order againstReturns Ordering#Less, Ordering#Equal or Ordering#Greater.
toString
on Number
Answers the Number as a String, in the notation of the member Type it holds.
Returns the String representation of the Number.
isNot
on Number · provided by Equatable
Answers whether the values differ.
Numberthe value to compare withReturns true when the values differ.
Comparing
isLessThan
on Number · provided by Comparable
Answers whether the value is strictly below another.
Numberthe value to compare withReturns true when the value is below the given one.
isLessThanOrEqualTo
on Number · provided by Comparable
Answers whether the value is below another, or equal to it.
Numberthe value to compare withReturns true when the value is below the given one or equal to it.
isGreaterThan
on Number · provided by Comparable
Answers whether the value is strictly above another.
Numberthe value to compare withReturns true when the value is above the given one.
isGreaterThanOrEqualTo
on Number · provided by Comparable
Answers whether the value is above another, or equal to it.
Numberthe value to compare withReturns true when the value is above the given one or equal to it.
isBetween
on Number · provided by Orderable
Answers whether the value lies between the two given ones, both included.
The two bounds name the same range in either order: 7::isBetween(10, and 1) is true, and 15::isBetween(10, and 1) is false.
Numberone bound of the range, includedNumberthe other bound of the range, includedReturns true when the value is within the bounds.
clamp
on Number · provided by Orderable
Answers the value, pulled into the given bounds.
The answer is the lower bound when the value is below it. It is the upper bound when the value is above it, and the value itself otherwise. The two bounds name the same range in either order: 7::clamp(between 10, and 1) is 7, and 15::clamp(between 10, and 1) is 10.
Numberone bound of the rangeNumberthe other bound of the rangeReturns the clamped value.
Mixed arithmetic
add
on Scalar
Adds two Scalars.
The answer is an Integer for two Integers, and a Rational for every other pair.
Scalarthe Scalar to addReturns the exact sum.
multiply
on Scalar
Multiplies two Scalars.
The answer is an Integer for two Integers, and a Rational for every other pair.
Scalarthe Scalar to multiply withReturns the exact product.