Numbers

Abstraction of numeric types with a natural total order, including the built-in numeric types `Integer` and `Float`.

A `Number` has a well-defined `magnitude` together with a `sign` of type `Integer`, defined for any instance `x` as follows:

- if `x==0` then `x.sign==0` and `x.magnitude==0`,
- if `x>0` then `x.sign==1` and `x.magnitude==x`, or
- if `x<0` then `x.sign==-1` and `x.magnitude==-x`,

where `0` is the additive identity of the numeric type.

Not every value commonly considered to be a “number” is a `Number`. For example, complex numbers aren't `Number`s since they don't have a total order.

By: Gavin
See also `Integer`, `Float`

no type hierarchy

- `Number`
  - `Comparable`
  - `Numeric`
    - `Invertible`
      - `Summable`

- `Number` of
  - `Float`
  - `Integral`
    - `Integer`

Attributes
`absolute` | See `magnitude`
`fractionalPart` | Source Code `shared formal Other fractionalPart` The fractional part of this number, after truncation of the integral part. For `Integral` numeric types, the fractional part is always zero.
`magnitude` | Source Code `shared default Other magnitude` The magnitude of this number, defined for any instance `x` as: `-x` if `x<0`, or `x` otherwise, where `0` is the additive identity. Hence: `x.magnitude >= 0` for any `x`, and `x.magnitude == 0` if and only if `x==0`. Aliases: `absolute`
`negative` | Source Code `shared formal Boolean negative` Determine if the number is strictly negative, that is, if `this<0`, where `0` is the additive identity.
`positive` | Source Code `shared formal Boolean positive` Determine if the number is strictly positive, that is, if `this>0`, where `0` is the additive identity.
`sign` | Source Code `shared default Integer sign` The sign of this number: `1` if the number is `positive`, `-1` if it is `negative`, or `0` if it is the additive identity. Must satisfy:
    x.magnitude.timesInteger(x.sign) == x
`wholePart` | Source Code `shared formal Other wholePart` The integral value of the number after truncation of the fractional part. For `Integral` numeric types, the integral value of a number is the number itself.

Inherited Attributes
Attributes inherited from: `Object` `hash`, `string`
Attributes inherited from: `Invertible<Other>` `negated`

Methods
`plusInteger` | Source Code `shared formal Other plusInteger(Integer integer)` The result of adding this number to the given `Integer`.
`powerOfInteger` | Source Code `shared formal Other powerOfInteger(Integer integer)` The result of raising this number to the given non-negative `Integer` power. For a negative power, the behavior is implementation-dependent. Throws `AssertionError` if the exponent is a negative power and this is an integral numeric type
`timesInteger` | Source Code `shared formal Other timesInteger(Integer integer)` The result of multiplying this number by the given `Integer`.

Inherited Methods
Methods inherited from: `Object` `equals()`
Methods inherited from: `Comparable<Other>` `compare()`, `largerThan()`, `notLargerThan()`, `notSmallerThan()`, `smallerThan()`
Methods inherited from: `Invertible<Other>` `minus()`
Methods inherited from: `Numeric<Other>` `divided()`, `times()`
Methods inherited from: `Summable<Other>` `plus()`