Numerical

com.phasmidsoftware.number.core.numerical.Numerical
trait Numerical extends NumberLike

Trait defining the behavior of "numerical" objects.

Attributes

Graph
Supertypes
trait NumberLike
class Object
trait Matchable
class Any
Known subtypes
trait Field
trait Multivariate
trait Complex
class BaseComplex
class ComplexPolar
class Real
object NaN
trait Number
class ExactNumber
class FuzzyNumber
Show all

Members list

Value members

Abstract methods

def abs: Numerical

Computes the absolute value of this Numerical instance. The result is a Numerical object representing a non-negative magnitude of this instance.

Computes the absolute value of this Numerical instance. The result is a Numerical object representing a non-negative magnitude of this instance.

Attributes

Returns

a Numerical object representing the absolute value of this instance.

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Attributes

Returns

a Complex.

def asReal: Option[Real]

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Attributes

Returns

an Option[Real].

def invert: Field

Yields the inverse of this Field. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors. TODO note that this method does not belong in Numerical: it belongs in Field.

Yields the inverse of this Field. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors. TODO note that this method does not belong in Numerical: it belongs in Field.

Attributes

def isInfinite: Boolean

Method to determine if this Field has infinite magnitude.

Method to determine if this Field has infinite magnitude.

Attributes

Returns

true if the magnitude of this Field is infinite.

def isProbablyZero(confidence: Double = ...): Boolean

Determines whether the magnitude of this Numerical instance is probably zero based on a given probability threshold.

Determines whether the magnitude of this Numerical instance is probably zero based on a given probability threshold.

Value parameters

confidence

the probability threshold (default is oneSigma). A higher value increases the confidence needed to determine that the magnitude is zero.

Attributes

Returns

true if the magnitude is considered to be probably zero based on the probability threshold, false otherwise.

def isSame(x: Numerical, confidence: Double = ...): Boolean

Method to determine if this Numerical is equivalent to another Numerical object (x).

Method to determine if this Numerical is equivalent to another Numerical object (x).

Value parameters

x

the other Numerical.

Attributes

Returns

true if they are most probably the same, otherwise false.

def isUnity: Boolean

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Attributes

Returns

true if the magnitude of this Field is one.

def isZero: Boolean

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Attributes

Returns

true if the magnitude of this Field is zero.

Method to "normalize" a field.

Method to "normalize" a field.

Attributes

Returns

a Field which is in canonical form.

def signum: Int

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Attributes

Returns

+1 if to the right of the origin, -1 if to the left, 0 if at the origin.

def unary_-: Field

Change the sign of this Field.

Change the sign of this Field.

Attributes

Inherited methods

def asJavaNumber: Option[Number]

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

The method determines whether the current NumberLike object can be represented as a java.lang.Number by leveraging the asNumber method and further evaluating certain conditions:

  • If the NumberLike object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the NumberLike object is a FuzzyNumber with a wiggle value below a specified tolerance, the result is also converted using Value.asJavaNumber.
  • In all other cases, None is returned.

Attributes

Returns

an optional java.lang.Number representation of this object. The result is Some(java.lang.Number) if the conversion is successful under the stated conditions; otherwise, None.

Inherited from:
NumberLike
def memberOf(set: NumberSet): Boolean

Method to determine if this NumberLike object is a member of the given set.

Method to determine if this NumberLike object is a member of the given set.

Value parameters

set

the candidate NumberSet.

Attributes

Returns

true if this is exact and belongs to set.

Inherited from:
NumberLike
def memberOf: Option[NumberSet]

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Attributes

Returns

Some(numberSet) or None if it doesn't belong to any (for example, it is fuzzy).

Inherited from:
NumberLike
def show: String

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Attributes

Returns

a String

Inherited from:
NumberLike

Inherited and Abstract methods

def asNumber: Option[Number]

Method to represent this NumberLike object as an optional Number. The result will be defined if: (1) we do not lose precision and (2) this object is not complex.

Method to represent this NumberLike object as an optional Number. The result will be defined if: (1) we do not lose precision and (2) this object is not complex.

NOTE: to force this as a Number, use convertToNumber in the companion Object.

CONSIDER redefining this as Option[Field] or Option[Real].

Attributes

Returns

a Some(x) if this is a Number; otherwise return None.

Inherited from:
NumberLike
def isExact: Boolean

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in the context of No factor, else false.

Inherited from:
NumberLike
def maybeFactor: Option[Factor]

Method to determine what Factor, if there is such, this NumberLike object is based on. Unlike context, a None result is not permissive.

Method to determine what Factor, if there is such, this NumberLike object is based on. Unlike context, a None result is not permissive.

Attributes

Returns

an optional Factor.

Inherited from:
NumberLike
def render: String

Method to render this NumberLike in a presentable manner.

Method to render this NumberLike in a presentable manner.

Attributes

Returns

a String

Inherited from:
NumberLike