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 Numbers since they don't have a total order.

By: Gavin
See also Integer, Float

no type hierarchy

Attributes
fractionalPartSource Codeshared 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.

magnitudeSource Codeshared 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.
negativeSource Codeshared formal Boolean negative

Determine if the number is strictly negative, that is, if this<0, where 0 is the additive identity.

positiveSource Codeshared formal Boolean positive

Determine if the number is strictly positive, that is, if this>0, where 0 is the additive identity.

signSource Codeshared 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
wholePartSource Codeshared 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
Attributes inherited from: Invertible<Other>
Methods
plusIntegerSource Codeshared formal Other plusInteger(Integer integer)

The result of adding this number to the given Integer.

powerOfIntegerSource Codeshared 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

timesIntegerSource Codeshared formal Other timesInteger(Integer integer)

The result of multiplying this number by the given Integer.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Comparable<Other>
Methods inherited from: Invertible<Other>
Methods inherited from: Numeric<Other>
Methods inherited from: Summable<Other>