Trait to model numbers as a sub-class of Field and such that we can order Numbers. That's to say that Numbers have linear domain and all belong, directly or indirectly, to the set R (real numbers).
Every number has three properties:
- nominalValue: Value
- factor: Factor
- fuzz: (from extending Fuzz[Double]).
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Numericaltrait NumberLiketrait Ordered[Number]trait Comparable[Number]trait Fuzz[Double]trait WithFuzzinessclass Objecttrait Matchableclass AnyShow all
- Known subtypes
Members list
Value members
Abstract methods
Method to yield the absolute value of this Number.
Method to yield the absolute value of this Number.
Attributes
- Returns
-
this if its positive, else - this.
Method to apply a function to this Number.
Method to apply a function to this Number.
Value parameters
- dfByDx
-
the first derivative of f.
- f
-
a function Double=>Double.
Attributes
- Returns
-
a Try[Number] which is the result of applying f to this Number.
Return optional Fuzziness of Box shape, such that this would be considered just within the resulting tolerance.
Return optional Fuzziness of Box shape, such that this would be considered just within the resulting tolerance.
Value parameters
- other
-
another Number: the ideal or target value.
Attributes
- Returns
-
an optional relative Fuzziness.
Calculate the angle whose opposite length is y and whose adjacent length is this.
Calculate the angle whose opposite length is y and whose adjacent length is this.
Value parameters
- y
-
the opposite length
Attributes
- Returns
-
the angle defined by x = this, y = y
Evaluate a dyadic operator on this and other, using either plus, times, ... according to the value of op. NOTE: this and other must have been aligned by type so that they have the same structure.
Evaluate a dyadic operator on this and other, using either plus, times, ... according to the value of op. NOTE: this and other must have been aligned by type so that they have the same structure.
Value parameters
- f
-
the factor to apply to the result.
- op
-
the appropriate DyadicOperation.
- other
-
the other operand, a Number.
Attributes
- Returns
-
a new Number which is result of applying the appropriate function to the operands this and other.
Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.
Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.
Attributes
- Returns
-
the cosine.
Add this Number to n.
Add this Number to n.
Value parameters
- n
-
another Number.
Attributes
- Returns
-
the sum of this and n.
Divide this Number by n.
Divide this Number by n.
Value parameters
- n
-
another Number.
Attributes
- Returns
-
this quotient of this and n, i.e., this/n.
Multiply this Number by n.
Multiply this Number by n.
Value parameters
- n
-
another Number.
Attributes
- Returns
-
the product of this and n.
Raise this Number to the power p.
Raise this Number to the power p.
Value parameters
- p
-
a Number.
Attributes
- Returns
-
this Number raised to the power of p.
Method to raise e to the power of this number. The result will be a Number with NatLog factor.
Method to raise e to the power of this number. The result will be a Number with NatLog factor.
Attributes
- Returns
-
the e to the power of this.
The factor of this Number. Ordinary numbers are of PureNumber factor, angles have factor Radian, and natural logs have factor NatLog.
The factor of this Number. Ordinary numbers are of PureNumber factor, angles have factor Radian, and natural logs have factor NatLog.
Attributes
- Returns
-
the factor.
Perform a fuzzy comparison where we only require p confidence to know that this and other are effectively the same.
Perform a fuzzy comparison where we only require p confidence to know that this and other are effectively the same.
Value parameters
- confidence
-
the confidence expressed as a fraction of 1 (oneSigma would be a typical value).
- other
-
the Number to be compared with.
Attributes
- Returns
-
-1, 0, 1 as usual.
Method to determine if this is an imaginary Number, that's to say a number with negative value and SquareRoot as its factor.
Method to determine if this is an imaginary Number, that's to say a number with negative value and SquareRoot as its factor.
Attributes
- Returns
-
true if imaginary.
Method to determine if this Number is actually represented is an Integer.
Method to determine if this Number is actually represented is an Integer.
Attributes
- Returns
-
true if exact and integral.
Method to determine if this Number is positive. Use case: does the String representation not start with a "-"?
Method to determine if this Number is positive. Use case: does the String representation not start with a "-"?
CONSIDER evaluating toString instead.
Attributes
- Returns
-
true if this Number is greater than or equal to 0.
Value parameters
- confidence
-
the confidence desired. Ignored if isZero is true.
Attributes
- Returns
-
true if this Number is equivalent to zero with at least p confidence.
Method to determine if this Number is actually represented as a Rational.
Method to determine if this Number is actually represented as a Rational.
Attributes
- Returns
-
true if exact and rational.
Method to determine if this is a valid Number. An invalid number has a value of form Left(Left(Left(None)))
Method to determine if this is a valid Number. An invalid number has a value of form Left(Left(Left(None)))
Attributes
- Returns
-
true if this is a valid Number
Method to determine the natural log of this Number. The result will be a Number with PureNumber factor. CONSIDER renaming this as "ln" but keep in mind that the Java library calls the function "log."
Method to determine the natural log of this Number. The result will be a Number with PureNumber factor. CONSIDER renaming this as "ln" but keep in mind that the Java library calls the function "log."
Attributes
- Returns
-
the natural log of this.
Returns the log of this Number in base b.
Returns the log of this Number in base b.
Value parameters
- b
-
the base for which to calculate the logarithm
Attributes
- Returns
-
the logarithm of the input number to base b
Make a copy of this Number, given the same degree of fuzziness as the original. Both the value and the factor will be changed.
Make a copy of this Number, given the same degree of fuzziness as the original. Both the value and the factor will be changed.
Value parameters
- f
-
the factor.
- v
-
the value.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the factor will change. This method does not need to be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the factor will change. This method does not need to be followed by a call to specialize.
Value parameters
- f
-
the factor.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Value parameters
- v
-
the value.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Value parameters
- f
-
Factor.
- v
-
the value.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Value parameters
- v
-
the value.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and the factor will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and the factor will change. This method should be followed by a call to specialize.
Value parameters
- f
-
Factor.
- r
-
a Rational.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value will change. This method should be followed by a call to specialize.
Value parameters
- v
-
the value.
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.
Value parameters
- f
-
Factor.
- v
-
the value (a Double).
Attributes
- Returns
-
either a Number.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.
Make a copy of this Number, given the same degree of fuzziness as the original. Only the value and factor will change. This method should be followed by a call to specialize.
Value parameters
- f
-
Factor.
- fo
-
optional fuzz.
- v
-
the value (a Double).
Attributes
- Returns
-
either a Number.
Make a copy of this Number, with the same value and factor but with a different value of fuzziness.
Make a copy of this Number, with the same value and factor but with a different value of fuzziness.
Value parameters
- fo
-
the (optional) fuzziness.
Attributes
- Returns
-
a Number.
Negative of this Number.
Negative of this Number.
Attributes
An optional Double that corresponds to the value of this Number (but ignoring the factor).
An optional Double that corresponds to the value of this Number (but ignoring the factor).
Attributes
Method to ensure that the value is within some factor-specific range. In particular, Radian=based numbers are modulated to the range 0..2
Method to ensure that the value is within some factor-specific range. In particular, Radian=based numbers are modulated to the range 0..2
Attributes
- Returns
-
this or an equivalent Number.
The nominal value of this Number.
The nominal value of this Number.
Attributes
- Returns
-
the nominalValue.
Calculates the probability of an event resulting in zero under the given conditions. The method returns an optional value to represent cases where the probability cannot be determined.
Calculates the probability of an event resulting in zero under the given conditions. The method returns an optional value to represent cases where the probability cannot be determined.
Attributes
- Returns
-
An Option containing the probability as a Double if it can be computed, or None if the probability is indeterminate.
Evaluate a query operator on this.
Evaluate a query operator on this.
Value parameters
- op
-
the appropriate QueryOperation.
Attributes
- Returns
-
a T.
Method to create a new version of this, but with factor f. NOTE: the result will have the same absolute magnitude as this. In other words, in the case where f is not factor, the numerical value of the result's value will be different from this value.
Method to create a new version of this, but with factor f. NOTE: the result will have the same absolute magnitude as this. In other words, in the case where f is not factor, the numerical value of the result's value will be different from this value.
Value parameters
- f
-
the new factor for the result.
Attributes
- Returns
-
a Number based on this and factor.
Method to determine the sense of this number: negative, zero, or positive. If this FuzzyNumber cannot be distinguished from zero with p confidence, then
Method to determine the sense of this number: negative, zero, or positive. If this FuzzyNumber cannot be distinguished from zero with p confidence, then
Value parameters
- confidence
-
the confidence desired.
Attributes
- Returns
-
an Int which is negative, zero, or positive according to the magnitude of this.
Method to determine the sense of this number: negative, zero, or positive.
Method to determine the sense of this number: negative, zero, or positive.
Attributes
- Returns
-
an Int which is negative, zero, or positive according to the magnitude of this.
Method to make some trivial simplifications of this Number (only if exact).
Method to make some trivial simplifications of this Number (only if exact).
Attributes
- Returns
-
either this Number or a simplified Number.
Method to determine the sine of this Number. The result will be a Number with PureNumber factor.
Method to determine the sine of this Number. The result will be a Number with PureNumber factor.
Attributes
- Returns
-
the sine of this.
Return a Number which uses the most restricted type possible. A Number based on a Double will yield a Number based on a Rational (if the conversion is exact). A Number based on a Rational will yield a Number based on a BigInt (if there is a unit denominator). A Number based on a BigInt will yield a Number based on a Int (if it is sufficiently small).
Return a Number which uses the most restricted type possible. A Number based on a Double will yield a Number based on a Rational (if the conversion is exact). A Number based on a Rational will yield a Number based on a BigInt (if there is a unit denominator). A Number based on a BigInt will yield a Number based on a Int (if it is sufficiently small).
CONSIDER do we really need this in Number?
Attributes
- Returns
-
a Number with the same magnitude as this.
Retrieves the optional threshold value for confidence, which can be used to determine a cut-off point for decision-making or validation processes.
Retrieves the optional threshold value for confidence, which can be used to determine a cut-off point for decision-making or validation processes.
Attributes
- Returns
-
An
Option[Double]representing the confidence threshold.Some(value)indicates a
Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.
Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.
Attributes
- Returns
-
an Option of BigDecimal.
Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.
Method to get the value of this Number as an (optional) BigInt. This will return Some(x) only if this is an Int, or a Rational with unit denominator.
Attributes
- Returns
-
an Option of BigInt.
Method to get the value of this Number as an Int.
Method to get the value of this Number as an Int.
Attributes
- Returns
-
an Option of Int. If this Number cannot be converted to an Int, then None will be returned.
Method to get the value of this Number as an (optional) Rational. If this is actually a Double, it will be converted to a Rational according to the implicit conversion from Double to Rational. See Rational.convertDouble(x).
Method to get the value of this Number as an (optional) Rational. If this is actually a Double, it will be converted to a Rational according to the implicit conversion from Double to Rational. See Rational.convertDouble(x).
Attributes
- Returns
-
an Option of Rational.
Evaluate a monadic operator on this.
Evaluate a monadic operator on this.
Value parameters
- f
-
the factor to apply to the result.
- op
-
the appropriate MonadicOperation.
Attributes
- Returns
-
a new Number which is result of applying the appropriate function to the operand this.
Concrete methods
Add x to this Number and return the result.
Add x to this Number and return the result.
Value parameters
- x
-
the addend.
Attributes
- Returns
-
the sum.
Divide this Number by x and return the result.
Divide this Number by x and return the result.
Value parameters
- x
-
the divisor.
Attributes
- Returns
-
the quotient.
Perform an exact scalar multiplication of this Number by the scale factor x. Implemented by doMultiple(Rational) where you should consult NOTE
Perform an exact scalar multiplication of this Number by the scale factor x. Implemented by doMultiple(Rational) where you should consult NOTE
Value parameters
- x
-
an Int.
Attributes
- Returns
-
a new Number which is this Number scaled by z.
Perform an exact scalar multiplication of this Number by the scale factor r.
Perform an exact scalar multiplication of this Number by the scale factor r.
NOTE that numbers with Logarithmic factors cannot be scaled exactly in this way.
Value parameters
- r
-
a Rational.
Attributes
- Returns
-
a new Number which is this Number scaled by z.
Subtract n from this Number
Subtract n from this Number
Value parameters
- n
-
another Number.
Attributes
- Returns
-
the difference of this and n.
Retrieves an optional Factor instance.
Retrieves an optional Factor instance.
Attributes
- Returns
-
Some(factor).
Multiplies the current instance by another Field and returns the result. Handles special cases such as multiplication with zero, one, or specific constants.
Multiplies the current instance by another Field and returns the result. Handles special cases such as multiplication with zero, one, or specific constants.
NOTE this code seems almost identical to the times method in GeneralNumber CONSIDER combining them and using the Factor facilities more.
Value parameters
- x
-
the Field instance to be multiplied with the current instance
Attributes
- Returns
-
the result of the multiplication as a Field
Negates the value of the instance conditionally based on the input parameter.
Negates the value of the instance conditionally based on the input parameter.
Value parameters
- cond
-
A boolean parameter that determines whether to negate the value. If true, the negation function
makeNegativeis applied. Otherwise, the current instance is returned unchanged.
Attributes
- Returns
-
The negated value as a
Numberif the condition is true, or the current instance if the condition is false.
Raise this Number to the power p.
Raise this Number to the power p.
Value parameters
- p
-
a Field.
Attributes
- Returns
-
this Number raised to power p.
Method to get the value of this Number as an Long.
Method to get the value of this Number as an Long.
Attributes
- Returns
-
an Option of Long. If this Number cannot be converted to a Long, then None will be returned.
Inherited methods
Returns true if this is less than that
Returns true if this is less than that
Value parameters
- that
-
the instance to compare against
Attributes
- Inherited from:
- Ordered
Returns true if this is less than or equal to that.
Returns true if this is less than or equal to that.
Attributes
- Inherited from:
- Ordered
Returns true if this is greater than that.
Returns true if this is greater than that.
Value parameters
- that
-
the instance to compare against
Attributes
- Inherited from:
- Ordered
Returns true if this is greater than or equal to that.
Returns true if this is greater than or equal to that.
Attributes
- Inherited from:
- Ordered
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
NumberLikeobject is anExactNumberand its factor isPureNumber, the result is converted usingValue.asJavaNumber. - If the
NumberLikeobject is aFuzzyNumberwith awigglevalue below a specified tolerance, the result is also converted usingValue.asJavaNumber. - In all other cases,
Noneis returned.
Attributes
- Returns
-
an optional
java.lang.Numberrepresentation of this object. The result isSome(java.lang.Number)if the conversion is successful under the stated conditions; otherwise,None. - Inherited from:
- NumberLike
Result of comparing this with operand that.
Result of comparing this with operand that.
Value parameters
- that
-
the instance to compare against
Attributes
- Inherited from:
- Ordered
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
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
Creates a fuzziness value with zero magnitude and a Gaussian distribution. This method provides a representation of deterministic or non-fuzzy values by ensuring that the fuzziness magnitude is explicitly zero.
Creates a fuzziness value with zero magnitude and a Gaussian distribution. This method provides a representation of deterministic or non-fuzzy values by ensuring that the fuzziness magnitude is explicitly zero.
Type parameters
- U
-
a supertype of T that also satisfies the HasValue type class constraint.
Attributes
- Returns
-
a Fuzziness[U] instance with zero magnitude and Gaussian shape.
- Inherited from:
- Fuzz
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
Adds the provided fuzziness to the current Fuzz[T] and returns the resulting value. This method may utilize the fuzziness parameter for calculations where applicable.
Adds the provided fuzziness to the current Fuzz[T] and returns the resulting value. This method may utilize the fuzziness parameter for calculations where applicable.
Value parameters
- f
-
the fuzziness to add, represented as a Fuzziness[T].
Attributes
- Returns
-
a Number that represents the result of adding the provided fuzziness.
- Inherited from:
- Fuzz
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].
- Inherited from:
- Numerical
Result of comparing this with operand that.
Result of comparing this with operand that.
Implement this method to determine how instances of A will be sorted.
Returns x where:
-
x < 0whenthis < that -
x == 0whenthis == that -
x > 0whenthis > that
Value parameters
- that
-
the instance to compare against
Attributes
- Returns
-
an integer whose sign indicates the ordering relation between
thisandthat - Inherited from:
- Ordered
Retrieves an optional fuzziness value associated with this instance.
Retrieves an optional fuzziness value associated with this instance.
The fuzziness value, if present, provides information about the level of uncertainty or imprecision, modeled as a Fuzziness[Double].
Attributes
- Returns
-
an
Optioncontaining theFuzziness[Double]value if defined, orNoneif no fuzziness is specified. - Inherited from:
- WithFuzziness
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
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.
- Inherited from:
- Numerical
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.
- Inherited from:
- Numerical
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.
- Inherited from:
- Numerical
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.
- Inherited from:
- Numerical
Method to "normalize" a field.
Method to "normalize" a field.
Attributes
- Returns
-
a Field which is in canonical form.
- Inherited from:
- Numerical
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
Abstract fields
Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.
Method to determine the cosine of this Number. The result will be a Number with PureNumber factor.
Attributes
- Returns
-
the cosine.
Method to determine the sine of this Number. The result will be a Number with PureNumber factor.
Method to determine the sine of this Number. The result will be a Number with PureNumber factor.
Attributes
- Returns
-
the sine of this.
Concrete fields
Method to return this Number as a Complex.
Method to return this Number as a Complex.
Attributes
- Returns
-
Complex(this) as appropriate.
Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.
Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.
CONSIDER allowing logarithmic numbers to be inverted simply by changing the sign of the value.
Attributes
Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.
Yields the inverse of this Number. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors.
CONSIDER allowing logarithmic numbers to be inverted simply by changing the sign of the value.
Attributes
Calculates the square of a number by multiplying the number by itself. CONSIDER different implementations according to the factor.
Calculates the square of a number by multiplying the number by itself. CONSIDER different implementations according to the factor.
Attributes
- Returns
-
the result of squaring this number
Method to determine the tangent of this Number. The result will be a Number with PureNumber factor. NOTE that not all cases have been tested.
Method to determine the tangent of this Number. The result will be a Number with PureNumber factor. NOTE that not all cases have been tested.
Attributes
- Returns
-
the tangent
Method to get the nominalValue of this Number as an optional Double.
Method to get the nominalValue of this Number as an optional Double.
Attributes
- Returns
-
an Some(Double) which is the closest possible nominalValue to the nominal nominalValue, otherwise None if this is invalid.
Converts the current number instance into a pure number representation. The conversion is based on the factor and fuzz values associated with the number. NOTE that even if this Number is exact, the result may not be.
Converts the current number instance into a pure number representation. The conversion is based on the factor and fuzz values associated with the number. NOTE that even if this Number is exact, the result may not be.
Attributes
- Returns
-
A new instance of Number in pure number representation, performing the necessary conversion and scaling if required.