NumberLike

com.phasmidsoftware.number.core.numerical.NumberLike
See theNumberLike companion object
trait NumberLike

Trait to define the behavior of things that are number-like.

CONSIDER extending Ordered[NumberLike]

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Rational
trait Numerical
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 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.

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.

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.

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

Concrete 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.

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).

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.

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