Value

com.phasmidsoftware.number.core.inner.Value
object Value

This object provides methods related to the type Value.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Value.type

Members list

Value members

Concrete methods

def abs(value: Value): Value

Method to get the sign of a Value.

Method to get the sign of a Value.

Value parameters

value

the value whose sign we need.

Attributes

Returns

an Int.

def add(v1: Value, v2: Value): Value

Adds two Value instances and returns the result.

Adds two Value instances and returns the result.

The method attempts to perform addition by considering various combinations of Value types. If the addition cannot be performed, an invalid Value is returned.

Value parameters

v1

the first Value to be added

v2

the second Value to be added

Attributes

Returns

a Value representing the sum of v1 and v2

def asJavaNumber(x: Value): Option[Number]

Converts a Value into an optional java.lang.Number. This method attempts to map the given Value to a corresponding Number type in the following order:

Converts a Value into an optional java.lang.Number. This method attempts to map the given Value to a corresponding Number type in the following order:

  • If the Value can be represented as an Int, the result will be wrapped as a java.lang.Number.
  • If the Value is a Rational that can be accurately represented as a Double, it is converted and wrapped as a java.lang.Number.
  • If the Value is already a Double, it will be directly wrapped as a java.lang.Number.
  • If none of the above conversions are applicable, None is returned.

CONSIDER using other methods from this class to get an appropriate Double.

Value parameters

x

the Value to be converted.

Attributes

Returns

an Option containing the java.lang.Number representation of the given Value, or None if conversion is not possible.

def fromDouble(xo: Option[Double]): Value

Convert an Option[Double] to a Value.

Convert an Option[Double] to a Value.

Value parameters

xo

a Double.

Attributes

Returns

a Value.

def fromInt(x: Int): Value

Convert an Int to a Value.

Convert an Int to a Value.

Value parameters

x

an Int.

Attributes

Returns

a Value.

Converts a Rational number into a Value.

Converts a Rational number into a Value.

Value parameters

x

the Rational number to be converted.

Attributes

Returns

a Value, which is either a Right containing an Int if the Rational can be precisely represented as an Int, or a Left containing the original Rational if not.

def inverse(value: Value): Option[Value]

Computes the inverse of the given Value, if possible.

Computes the inverse of the given Value, if possible.

For numeric values, this method attempts to determine their inverse. If the input Value is a Double, None is returned.

Value parameters

value

the Value to invert.

Attributes

Returns

an Option containing the inverted Value, or None if the inversion cannot be performed.

def isEqual(v1: Value, v2: Value): Boolean

Compares two Value instances to check if they are equal based on specific transformations and operations.

Compares two Value instances to check if they are equal based on specific transformations and operations.

Value parameters

v1

the nominal Value against which v is compared.

v2

the Value to be compared with the nominalValue.

Attributes

Returns

true if the transformed and composed values result in equality after performing operations, otherwise false.

def isZero(value: Value): Boolean

Determines whether the given Value represents the numeric value zero. It doesn't matter whether the Value is a Double, Int or a Rational.

Determines whether the given Value represents the numeric value zero. It doesn't matter whether the Value is a Double, Int or a Rational.

Value parameters

value

the Value to be checked.

Attributes

Returns

true if the Value represents zero, otherwise false.

def maybeDouble(value: Value): Option[Double]

Method to (optionally) convert a Value into a Double.

Method to (optionally) convert a Value into a Double.

Value parameters

value

the Value to be represented as a Double.

Attributes

Returns

Some(x) where x is a Double if the conversion was possible, otherwise None.

def maybeInt(value: Value): Option[Int]

An optional Int that corresponds to the value of this Number (but ignoring the factor).

An optional Int that corresponds to the value of this Number (but ignoring the factor).

CONSIDER using query

Attributes

def maybeRational(value: Value): Option[Rational]

An optional Rational that corresponds to the value of this Number (but ignoring the factor). A Double value is not converted to a Rational since, if it could be done exactly, it already would have been. CONSIDER using query

An optional Rational that corresponds to the value of this Number (but ignoring the factor). A Double value is not converted to a Rational since, if it could be done exactly, it already would have been. CONSIDER using query

Attributes

def multiply(v1: Value, v2: Value): Value

Multiplies two Value instances and returns the result.

Multiplies two Value instances and returns the result.

This method attempts to perform multiplication by considering various combinations of Value types. If the multiplication cannot be performed, an invalid Value is returned.

Value parameters

v1

the first Value to be multiplied

v2

the second Value to be multiplied

Attributes

Returns

a Value representing the product of v1 and v2

def negate(value: Value): Value

Negates the given Value.

Negates the given Value.

Value parameters

value

the Value to be negated.

Attributes

Returns

a Value representing the negation of the given Value.

def negateConditional(neg: Boolean)(value: Value): Value

Conditionally negates the provided Value based on the boolean parameter neg. If neg is true, the Value is negated using the negate method. Otherwise, the original Value is returned unchanged.

Conditionally negates the provided Value based on the boolean parameter neg. If neg is true, the Value is negated using the negate method. Otherwise, the original Value is returned unchanged.

Value parameters

neg

a Boolean indicating whether the Value should be negated.

value

the Value to be conditionally negated.

Attributes

Returns

the negated Value if neg is true, otherwise the original Value.

def scaleDouble(x: Double, fThis: Double, fResult: Double): Double

Method to scale the given Double according to the provided scaling factors.

Method to scale the given Double according to the provided scaling factors.

Value parameters

fResult

the value of the factor that the result will be associated with.

fThis

the value of the factor that x is associated with.

x

the Double to be scaled.

Attributes

Returns

a Double which will be paired with fResult.

def scaleRational(x: Rational)(value: Value): Value

Scales a Value by the given Rational factor.

Scales a Value by the given Rational factor.

The method attempts to scale a Value based on its internal type (e.g., Rational or Double). If the Value can be represented as a Rational, it is multiplied by the given scaling factor. Otherwise, if it can be represented as a Double, the scaling is applied in the Double domain.

Value parameters

value

the Value to be scaled.

x

the Rational factor by which the Value is scaled.

Attributes

Returns

a new scaled Value. The result is based on either the Rational or Double representation of the input value.

def signum(value: Value): Int

Method to get the sign of a Value.

Method to get the sign of a Value.

Value parameters

value

the value whose sign we need.

Attributes

Returns

an Int.

def unapplySeq(v: Value): Option[List[Any]]

A variable-element unapply method which will yield an optional array. If there is only one item returned, it is an Int; if there are two items returned, they are null followed by a Rational; if there are three items returned, they are two nulls followed by a Double; otherwise, if the given value is not defined, then None is returned.

A variable-element unapply method which will yield an optional array. If there is only one item returned, it is an Int; if there are two items returned, they are null followed by a Rational; if there are three items returned, they are two nulls followed by a Double; otherwise, if the given value is not defined, then None is returned.

Value parameters

v

the value.

Attributes

Returns

Some(List[Int](x)) or Some(List[Rational](null,x)) or Some(List[Double](null,null,x)) or None.

def valueToString(v: Value, skipOne: Boolean, exact: Boolean = ...): String

Converts a given Value into its string representation, with options to skip certain outputs or use exact formatting.

Converts a given Value into its string representation, with options to skip certain outputs or use exact formatting.

Value parameters

exact

a Boolean (default is true) specifying whether the string representation should be exact or adjusted with additional formatting (e.g., appending a "*").

skipOne

a Boolean indicating whether to skip returning the string representation if the value equals "1" (only when exact is true).

v

the Value to be converted into a string.

Attributes

Returns

a String representing the Value, formatted according to the given parameters.

Concrete fields

val half: Value

A pre-defined constant Value representing one-half. This Value is derived from the Rational representation of half (1/2).

A pre-defined constant Value representing one-half. This Value is derived from the Rational representation of half (1/2).

It is created using the fromRational method to ensure an appropriate Value representation of the rational number one-half.

Attributes

val one: Value

Represents a predefined Value wrapping the integer 1 as a Right.

Represents a predefined Value wrapping the integer 1 as a Right.

Attributes

val two: Value

Represents the value 2 as a Value type, where Right(2) signifies a valid integer representation wrapped in a Right, indicating successful creation as a Value.

Represents the value 2 as a Value type, where Right(2) signifies a valid integer representation wrapped in a Right, indicating successful creation as a Value.

Attributes

val zero: Value

Represents a predefined constant Value instance associated with the numeric value zero. The Value is constructed as a Right type containing the integer 0.

Represents a predefined constant Value instance associated with the numeric value zero. The Value is constructed as a Right type containing the integer 0.

Attributes