Number

com.phasmidsoftware.number.core.numerical.Number
See theNumber companion trait
object Number

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Number.type

Members list

Type members

Classlikes

implicit class FuzzOps(x: Double)

Implicit class which takes a Double, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String.

Implicit class which takes a Double, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String.

Value parameters

x

a Double.

Attributes

Supertypes
class Object
trait Matchable
class Any
implicit class FuzzStringOps(w: String)

Implicit class which takes a String, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String. Really, the only function it provides is the ability to put the error bounds after the exponent. It is parallel to FuzzOps except for two differences: the input is a String, and this is is so that trailing zeros in the fractional part don't get ignored, thus messing up the fuzziness; And, secondly, the result of ~ is a Try[Number], not just a Number.

Implicit class which takes a String, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String. Really, the only function it provides is the ability to put the error bounds after the exponent. It is parallel to FuzzOps except for two differences: the input is a String, and this is is so that trailing zeros in the fractional part don't get ignored, thus messing up the fuzziness; And, secondly, the result of ~ is a Try[Number], not just a Number.

Value parameters

w

a String.

Attributes

Supertypes
class Object
trait Matchable
class Any

Provides an implicit object for handling operations on Number with fractional, numeric, and ordering capabilities.

Provides an implicit object for handling operations on Number with fractional, numeric, and ordering capabilities.

This implicit object combines the functionality of NumberIsFractional, NumberIsNumeric, and NumberIsOrdering, enabling division operations along with general numeric and ordering functionalities for the Number type.

Attributes

Companion
trait
Supertypes
trait Fractional[Number]
trait Numeric[Number]
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Self type
trait NumberIsFractional extends Fractional[Number], NumberIsNumeric

Following are the definitions required by Fractional[Number]

Following are the definitions required by Fractional[Number]

Attributes

Companion
object
Supertypes
trait Fractional[Number]
trait Numeric[Number]
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Known subtypes
trait NumberIsNumeric extends Numeric[Number], NumberIsOrdering

Following are the definitions required by Numeric[Number]

Following are the definitions required by Numeric[Number]

Attributes

Supertypes
trait Numeric[Number]
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Known subtypes

Attributes

Companion
trait
Supertypes
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Self type
trait NumberIsOrdering extends Ordering[Number]

Following are the definitions required by Ordering[Number]

Following are the definitions required by Ordering[Number]

Attributes

Companion
object
Supertypes
trait Ordering[Number]
trait PartialOrdering[Number]
trait Equiv[Number]
trait Serializable
trait Comparator[Number]
class Object
trait Matchable
class Any
Show all
Known subtypes
implicit class NumberOps(x: Int)

Implicit class to operate on Numbers introduced as integers. CONSIDER reinstating the ∧ operator definitions (but they were never used). CONSIDER generalizing this to inputs of Values (or Rationals, Doubles).

Implicit class to operate on Numbers introduced as integers. CONSIDER reinstating the ∧ operator definitions (but they were never used). CONSIDER generalizing this to inputs of Values (or Rationals, Doubles).

Value parameters

x

an Int to be treated as a Number.

Attributes

Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

Applies the given input to create a Number instance.

Applies the given input to create a Number instance.

Value parameters

x

the input value of type NumberLike, which can be a Rational, a Number, or another acceptable form from which a Number can be created.

Attributes

Returns

a Number instance created from the input x if its type matches the expected forms. Throws a CoreException otherwise.

def apply(x: Double, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from a Double.

Method to construct a Number from a Double.

Value parameters

factor

the appropriate factor

x

the Double value.

Attributes

Returns

a Number based on x.

def apply(xo: Option[Double], factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from an optional Double.

Method to construct a Number from an optional Double.

Value parameters

factor

the appropriate factor

xo

an optional Double.

Attributes

Returns

a Number based on xo.

def apply(x: String, factor: Factor): Number

Method to construct a Number from a String. This is by far the best way of creating the number that you really want.

Method to construct a Number from a String. This is by far the best way of creating the number that you really want.

Value parameters

x

the String representation of the value.

Attributes

Returns

a Number based on x.

def apply(x: String): Number

Method to construct a Number from a String. This is by far the best way of creating the number that you really want.

Method to construct a Number from a String. This is by far the best way of creating the number that you really want.

CONSIDER why does this not invoke apply(String,Factor) in turn?

Value parameters

x

the String representation of the value.

Attributes

Returns

a Number based on x.

def apply(factor: Factor): Number

Method to construct a unit Number with explicit factor.

Method to construct a unit Number with explicit factor.

Value parameters

factor

the appropriate factor

Attributes

Returns

a unit Number with the given factor.

def apply(x: Int, factor: Factor): Number

Method to construct a Number from an Int.

Method to construct a Number from an Int.

Value parameters

factor

the appropriate factor

x

the Int value.

Attributes

Returns

a Number based on x.

def apply(x: Int, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from an Int.

Method to construct a Number from an Int.

Value parameters

factor

the appropriate factor

x

the Int value.

Attributes

Returns

a Number based on x.

def apply(x: Int): Number

Method to construct a Number from an Int.

Method to construct a Number from an Int.

Value parameters

x

the Int value.

Attributes

Returns

a Number based on x.

def apply(x: BigInt): Number

Method to construct a Number from a BigInt.

Method to construct a Number from a BigInt.

Value parameters

x

a BigInt value.

Attributes

Returns

a Number based on x.

def apply(x: BigInt, factor: Factor): Number

Method to construct a Number from a BigInt.

Method to construct a Number from a BigInt.

Value parameters

factor

the appropriate factor

x

the BigInt value.

Attributes

Returns

a Number based on x.

def apply(x: BigInt, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from a BigInt.

Method to construct a Number from a BigInt.

Value parameters

factor

the appropriate factor

x

the BigInt value.

Attributes

Returns

a Number based on x.

def apply(x: Rational): Number

Method to construct a Number from a Rational.

Method to construct a Number from a Rational.

Value parameters

x

a Rational value.

Attributes

Returns

a Number based on x.

def apply(x: Rational, factor: Factor): Number

Method to construct a Number from a Rational.

Method to construct a Number from a Rational.

Value parameters

factor

the appropriate factor

x

the BigInt value.

Attributes

Returns

a Number based on x.

def apply(x: Long, factor: Factor): Number

Applies the given factor to the specified long x and returns a Number result.

Applies the given factor to the specified long x and returns a Number result.

Value parameters

factor

the Factor to be applied to the input value

x

the input value as a Long to be processed

Attributes

Returns

a Number instance derived from the input value and factor

def apply(x: Long): Number

Constructs a Number instance from the given long value.

Constructs a Number instance from the given long value.

Value parameters

x

the input long value

Attributes

Returns

a Number instance representing the provided long value

def apply(x: BigDecimal): Number

Method to construct a Number from a BigDecimal.

Method to construct a Number from a BigDecimal.

Value parameters

x

the BigDecimal value.

Attributes

Returns

a Number based on x.

def apply(x: BigDecimal, factor: Factor): Number

Method to construct a Number from a BigDecimal.

Method to construct a Number from a BigDecimal.

Value parameters

factor

the appropriate factor

x

the BigDecimal value.

Attributes

Returns

a Number based on x.

def apply(x: BigDecimal, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from a BigDecimal.

Method to construct a Number from a BigDecimal.

Value parameters

factor

the appropriate factor

x

the BigDecimal value.

Attributes

Returns

a Number based on x.

def apply(x: Rational, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a Number from a Rational. NOTE: this method is invoked indirectly by parse(String).

Method to construct a Number from a Rational. NOTE: this method is invoked indirectly by parse(String).

Value parameters

factor

the appropriate factor

x

the BigInt value.

Attributes

Returns

a Number based on x.

def apply(xo: Option[Double]): Number

Method to construct a Number from an optional Double.

Method to construct a Number from an optional Double.

Value parameters

xo

an optional Double.

Attributes

Returns

a Number based on xo.

def apply(xo: Option[Double], factor: Factor): Number

Method to construct a Number from an optional Double.

Method to construct a Number from an optional Double.

Value parameters

factor

the appropriate factor

xo

an optional Double.

Attributes

Returns

a Number based on xo.

def apply(x: Double): Number

Method to construct a Number from a Double.

Method to construct a Number from a Double.

Value parameters

x

the Double value.

Attributes

Returns

a Number based on x.

def apply(): Number

Method to construct an invalid Number.

Method to construct an invalid Number.

Attributes

Returns

a invalid Number.

def apply(x: Double, factor: Factor): Number

Method to construct a Number from a Double.

Method to construct a Number from a Double.

Value parameters

factor

the appropriate factor

x

the Double value.

Attributes

Returns

a Number based on x.

def atan(x: Number, y: Number): Number

Calculates the arctangent of the angle specified by the ratio of y to x. The result is an angle expressed in radians. CONSIDER checking here for x being zero.

Calculates the arctangent of the angle specified by the ratio of y to x. The result is an angle expressed in radians. CONSIDER checking here for x being zero.

Value parameters

x

the horizontal coordinate of the point

y

the vertical coordinate of the point

Attributes

Returns

the arctangent of the angle, in radians

def cosh(x: Number): Number
def create(value: Value, actualFuzz: Fuzziness[Double]): Number

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Value parameters

actualFuzz

the fuzziness of this Number.

value

the value of the Number, expressed as a nested Either type.

Attributes

Returns

a Number.

def create(value: Value): Number

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Value parameters

value

the value of the Number, expressed as a nested Either type.

Attributes

Returns

a Number.

def create(value: Value, factor: Factor): Number

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Value parameters

factor

the scale factor of the Number: valid scales are: PureNumber, Radian, and NatLog.

value

the value of the Number, expressed as a nested Either type.

Attributes

Returns

a Number.

def create(value: Value, factor: Factor, fuzz: Option[Fuzziness[Double]]): Number

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

Method to construct a new Number from value, factor and fuzz, according to whether there is any fuzziness.

CONSIDER modulate the result so that, in the case of a multiple of Radian, we restrict the range to 0 to 2pi immediately. However, note that this will change the behavior such that it is no longer possible to have the constant 2pi.

Value parameters

factor

the scale factor of the Number: valid scales are: PureNumber, Radian, and NatLog.

fuzz

the fuzziness of this Number, wrapped in Option.

value

the value of the Number, expressed as a nested Either type.

Attributes

Returns

a Number.

def createFromDouble(x: Double): Number
def createFromDouble(x: Double, factor: Factor): Number

CONSIDER why do we need this method?

CONSIDER why do we need this method?

NOTE not all double values should be given fuzz.

Value parameters

factor

a Factor.

x

a Double.

Attributes

Returns

a Number formed from x and factor using standard double precision fuzziness.

def doCompare(x: Number, y: Number): Int

CONSIDER inlining this method or making it private.

CONSIDER inlining this method or making it private.

Value parameters

x

the first number.

y

the second number.

Attributes

Returns

the order.

def exp(x: Number): Number

Yield the exponential of x i.e., e to the power of x. If the factor is PureNumber, then we force the factor to be NatLog and simplify. Otherwise, we convert to a PureNumber number and call exp recursively.

Yield the exponential of x i.e., e to the power of x. If the factor is PureNumber, then we force the factor to be NatLog and simplify. Otherwise, we convert to a PureNumber number and call exp recursively.

Value parameters

x

a (real) Number whose factor is NatLog.

Attributes

Returns

the value of e raised to the power of x.

def inverse(x: Number): Number

Computes the inverse of the given number based on its factor type.

Computes the inverse of the given number based on its factor type.

Value parameters

x

the number to be inverted

Attributes

Returns

the inverted number, processed according to its factor type

def log(x: Number): Field

Yield the natural log of x. If the factor is NatLog, then we force the factor to be PureNumber and simplify. Otherwise, if the factor is PureNumber, we first convert it to a NatLog number, then call log recursively. Otherwise, we convert to a PureNumber number and call log recursively.

Yield the natural log of x. If the factor is NatLog, then we force the factor to be PureNumber and simplify. Otherwise, if the factor is PureNumber, we first convert it to a NatLog number, then call log recursively. Otherwise, we convert to a PureNumber number and call log recursively.

CONSIDER using x.factor.log(x.nominalValue)

Value parameters

x

a Number.

Attributes

Returns

the natural log of x.

This method returns a Number equivalent to x but with the value in an explicit factor-dependent range. Only Radian is currently fixed within a range (-1 -> 1).

This method returns a Number equivalent to x but with the value in an explicit factor-dependent range. Only Radian is currently fixed within a range (-1 -> 1).

Value parameters

x

the Number to operate on.

Attributes

Returns

either x or a number equivalent to x with value in defined range.

def negate(x: Number): Number

Method to change the sign of this Number. The meaning of "change the sign" is in terms of pure numbers (PureNumber, Radian). For any other factor, we convert x into PureNumber form (which will most likely introduce fuzziness). Imaginary numbers cannot be negated--they must first be converted to Complex form and then negated.

Method to change the sign of this Number. The meaning of "change the sign" is in terms of pure numbers (PureNumber, Radian). For any other factor, we convert x into PureNumber form (which will most likely introduce fuzziness). Imaginary numbers cannot be negated--they must first be converted to Complex form and then negated.

Value parameters

x

a Number to be negated.

Attributes

Returns

-x unless the negative cannot be represented, in which case a CoreException will be thrown.

def parse(w: String): Try[Number]

Method to parse a String and yield a Try[Number].

Method to parse a String and yield a Try[Number].

NOTE: this method indirectly invokes apply(Rational, Factor, Option of Fuzz[Double] )

Value parameters

w

the String to be parsed.

Attributes

Returns

a Number.

def prepare(no: Option[Number]): Number

Prepares a valid Number based on the provided optional input.

Prepares a valid Number based on the provided optional input.

Value parameters

no

An optional Number that may or may not be defined.

Attributes

Returns

The provided Number if it exists, otherwise a default Number instance.

def prepareWithSpecialize(no: Option[Number]): Number

Prepares and specializes a given optional number.

Prepares and specializes a given optional number.

Value parameters

no

An optional value of type Number to be prepared.

Attributes

Returns

A specialized Number derived from the prepared input.

def scale(n: Number, factor: Factor): Number

Method to deal with a Scale factor change.

Method to deal with a Scale factor change.

TODO: this will work for FuzzyNumber but only if the fuzz is relative, and even then perhaps not for NatLog conversions.

Value parameters

factor

the factor to which it should be converted.

n

the Number to be scaled.

Attributes

Returns

the resulting Number (equivalent in value, but with a potentially different scale factor).

def signum(x: Number): Int

CONSIDER move this to GeneralNumber as an instance method.

CONSIDER move this to GeneralNumber as an instance method.

Value parameters

x

a Number.

Attributes

Returns

-1, 0, or 1 according to its sign.

def sin(x: Number): Number

Implement sin of a Number. See https://en.wikipedia.org/wiki/Sine_and_cosine.

Implement sin of a Number. See https://en.wikipedia.org/wiki/Sine_and_cosine.

CONSIDER implementing this (and cos) as part of exp method (providing a Complex parameter, of course).

CONSIDER implementing this (and cos) by using MonadicOperationSin throughout. But NOTE that said operation will need enhancement before it can work identically.

CONSIDER returning an Expression rather than a Number. That would enable an exact result for 1/12 and 5/12 pi.

Value parameters

x

a Number, typically in Radians, but if not, then will be converted.

Attributes

Returns

a PureNumber Number which represents the sine of x.

def sinh(x: Number): Number
def sqrt(x: Number): Number

Method to yield the square root of a Number.

Method to yield the square root of a Number.

Value parameters

x

the Number whose square root we need.

Attributes

Returns

the square root of x.

def tanh(x: Number): Number
def unapply(arg: Number): Option[(Value, Factor)]

NOTE: this unapply method does not match on the fuzz of a Number.

NOTE: this unapply method does not match on the fuzz of a Number.

Value parameters

arg

a Number to be unapplied.

Attributes

Returns

optional Value and Factor.

def √(x: Int): Number

Computes the square root of the given integer value.

Computes the square root of the given integer value.

Value parameters

x

The integer value for which the square root is to be computed.

Attributes

Returns

A Number representing the square root of the input value.

Concrete fields

lazy val Infinity: Number

Represents a constant value for positive infinity. This value is defined using a Number wrapper around Double.PositiveInfinity.

Represents a constant value for positive infinity. This value is defined using a Number wrapper around Double.PositiveInfinity.

Attributes

lazy val NaN: Number

Invalid number.

Invalid number.

Attributes

lazy val e: Number

Exact value of e

Exact value of e

Attributes

lazy val half: Number

Exact value of 1/2

Exact value of 1/2

Attributes

lazy val i: Number

Exact value of i

Exact value of i

Attributes

lazy val minusPi: Number

Exact value of -pi

Exact value of -pi

Attributes

lazy val negOne: Number

Exact value of -1

Exact value of -1

Attributes

lazy val negZero: Number

Exact value of -0

Exact value of -0

Attributes

lazy val one: Number

Exact value of 1

Exact value of 1

Attributes

lazy val pi: Number

Exact value of pi

Exact value of pi

Attributes

lazy val piBy2: Number

Exact value of pi/2

Exact value of pi/2

Attributes

lazy val piBy3: Number

Represents the mathematical constant π/3. It is defined as a Number with a rational value of 1/3 and a unit of measurement as Radian.

Represents the mathematical constant π/3. It is defined as a Number with a rational value of 1/3 and a unit of measurement as Radian.

Attributes

lazy val piBy4: Number

Exact value of pi/4

Exact value of pi/4

Attributes

lazy val root2: Number

Exact value of the Number √2 (not Complex)

Exact value of the Number √2 (not Complex)

Attributes

lazy val root3: Number

Exact value of √3

Exact value of √3

Attributes

lazy val root5: Number

Exact value of √5

Exact value of √5

Attributes

lazy val ten: Number

Exact value of 10

Exact value of 10

Attributes

lazy val three: Number

A constant value representing the number three as a Number type.

A constant value representing the number three as a Number type.

Attributes

lazy val two: Number

Exact value of 2

Exact value of 2

Attributes

lazy val twoPi: Number

Exact value of 2 pi

Exact value of 2 pi

Attributes

lazy val zero: Number

Exact value of 0

Exact value of 0

Attributes

lazy val zeroR: Number

Exact value of zero radians

Exact value of zero radians

Attributes

lazy val ∞: Number

Represents the mathematical concept of infinity as a lazy value of type Number. The value is constructed using an exact representation of infinity via the ExactNumber class.

Represents the mathematical concept of infinity as a lazy value of type Number. The value is constructed using an exact representation of infinity via the ExactNumber class.

Attributes

lazy val 𝛑: Number

Exact value of 𝛑

Exact value of 𝛑

Attributes

Implicits

Implicits

final implicit def FuzzOps(x: Double): FuzzOps

Implicit class which takes a Double, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String.

Implicit class which takes a Double, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String.

Value parameters

x

a Double.

Attributes

final implicit def FuzzStringOps(w: String): FuzzStringOps

Implicit class which takes a String, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String. Really, the only function it provides is the ability to put the error bounds after the exponent. It is parallel to FuzzOps except for two differences: the input is a String, and this is is so that trailing zeros in the fractional part don't get ignored, thus messing up the fuzziness; And, secondly, the result of ~ is a Try[Number], not just a Number.

Implicit class which takes a String, and using method ~ and an Int parameter, yields a Number with the appropriate degree of fuzziness. This class provides an alternative to having to parse a fuzzy number from a String. Really, the only function it provides is the ability to put the error bounds after the exponent. It is parallel to FuzzOps except for two differences: the input is a String, and this is is so that trailing zeros in the fractional part don't get ignored, thus messing up the fuzziness; And, secondly, the result of ~ is a Try[Number], not just a Number.

Value parameters

w

a String.

Attributes

final implicit def NumberOps(x: Int): NumberOps

Implicit class to operate on Numbers introduced as integers. CONSIDER reinstating the ∧ operator definitions (but they were never used). CONSIDER generalizing this to inputs of Values (or Rationals, Doubles).

Implicit class to operate on Numbers introduced as integers. CONSIDER reinstating the ∧ operator definitions (but they were never used). CONSIDER generalizing this to inputs of Values (or Rationals, Doubles).

Value parameters

x

an Int to be treated as a Number.

Attributes

implicit def convertDouble(x: Double): Number

Implicit converter from Double to Number.

Implicit converter from Double to Number.

Value parameters

x

the Double to be converted.

Attributes

Returns

the equivalent Number.

implicit def convertInt(x: Int): Number

Implicit converter from Int to Number.

Implicit converter from Int to Number.

Value parameters

x

the Int to be converted.

Attributes

Returns

the equivalent Number.