Angle

com.phasmidsoftware.number.algebra.eager.Angle
See theAngle companion object

A case class representing an angle in radians. This class implements the Additive and Radians traits, allowing operations such as addition, subtraction, and various type conversions. Angle represents the "circle group," which is a compact Abelian (commutative) group under angle addition, where the addition wraps around the circle. It is compact in that it is bounded by -𝛑 and 𝛑 (-180° and 180°). It is also commutative in that the order of addition is irrelevant. The circle group is a subset of the real numbers. The degrees attribute of an Angle is only of interest in the following situations:

  • when the Angle is parsed from a String, the degrees attribute is set according to whether the degree symbol is present.
  • when the Angle is converted to a String, the degrees attribute is used to determine whether to use degrees or radians.

Angle does not support ordering or (general) comparison.

Value parameters

degrees

whether the angle is in radians or degrees. In the latter case, the number attribute is unchanged (1 is still half of a full circle).

number

the value of the angle in radians

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait CanAdd[Angle, Angle]
trait Can[Angle]
trait Scalable[Angle]
trait Circle
trait R
trait Radians
trait Functional
trait Ordered[Functional]
trait Comparable[Functional]
trait MaybeFuzzy
trait Scalar
trait Structure
trait Eager
trait DyadicOps
trait Approximate
trait Valuable
trait TypeSafe
trait Exactitude
trait Unitary
trait Zeroable
trait Numeric
trait Renderable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def *(factor: Rational): Angle

Scales the current instance by the given factor.

Scales the current instance by the given factor.

This method applies a scaling operation on the instance using the provided rational factor and returns the resulting scaled instance.

Value parameters

factor

the rational number representing the scale factor

Attributes

Returns

the scaled instance of type T

def +(a: Angle): Angle

Adds the specified Angle to the current Angle instance.

Adds the specified Angle to the current Angle instance.

This method combines the current angle with the provided angle by adding their respective number, returning a new Angle instance representing the sum.

CONSIDER Extract this method to an Additive trait (not to be confused with CanAdd).

Value parameters

a

the Angle to be added to the current Angle

Attributes

Returns

a new Angle representing the sum of the current Angle and the specified Angle

def add(other: Angle): Try[Angle]

Adds the given Angle to this Angle and returns the result wrapped in a Try.

Adds the given Angle to this Angle and returns the result wrapped in a Try.

Value parameters

other

The Angle to be added to this Angle.

Attributes

Returns

A Try containing the resulting Angle if the operation is successful, or an exception if an error occurs.

def compare(that: Functional): Int

Compares the current Functional instance with another Functional instance.

Compares the current Functional instance with another Functional instance.

The comparison is based on the numeric value contained within each Functional object and the sign of the derivative function at the numeric value.

TODO check this as it won't work with all other Functional types.

Value parameters

that

the Functional instance to compare with the current instance

Attributes

Returns

an Int where: - A negative value indicates that the current instance is less than that - Zero indicates that both instances are equal - A positive value indicates that the current instance is greater than that

def compareExact(that: Scalar): Option[Int]

Compares the current Angle instance with another Number to determine their exact order.

Compares the current Angle instance with another Number to determine their exact order.

If the provided Number is an Angle, this method compares their underlying radian values. If the provided Number is not an Angle, the comparison cannot be performed, and None is returned.

Value parameters

that

the Number instance to compare with the current Angle instance

Attributes

Returns

an Option[Int], where Some(-1) indicates that the current Angle is less than the provided Angle, Some(0) indicates that both angles are equal, Some(1) indicates that the current Angle is greater, and None is returned if the comparison cannot be made

def convert[T <: Structure : ClassTag](t: T): Option[T]

Converts this Angle to a representation of the specified type T, if possible.

Converts this Angle to a representation of the specified type T, if possible.

This method attempts to convert the number to a type T that has implicit evidence of Ordering. If the conversion is successful, it returns an Option containing the resulting typed value. If the conversion is not valid or not possible for the given type T, it returns None.

Attributes

Returns

an Option containing the converted value of type T if successful, or None if the conversion is not possible.

def divide(other: Angle): Try[Number]

Divides the current Angle by the specified Angle.

Divides the current Angle by the specified Angle.

This operation is not supported for Angle instances and will always result in a failure containing an AlgebraException.

Value parameters

other

the Angle by which the current Angle is to be divided

Attributes

Returns

a Try[Number] containing a failure with an AlgebraException indicating that the division operation is not supported

def divide(n: Number): Try[Angle]

Attempts to divide the current Angle by the specified Number.

Attempts to divide the current Angle by the specified Number.

This operation is not supported and will always return a failure.

Value parameters

n

the Number by which the current Angle is to be divided

Attributes

Returns

a Try[Angle], which will always be a Failure containing an AlgebraException

infix def doPlus(that: Scalar): Option[Scalar]

Adds the specified Scalar to the current Scalar and returns the result as an Option[Scalar]. This method handles addition based on the type of Scalar provided. If the input is an Angle, it computes the sum of the current Angle and the provided Angle. If the input is a Number, the addition is delegated to the doPlus implementation of the Number. CONSIDER eliminating this method (only used by unit tests).

Adds the specified Scalar to the current Scalar and returns the result as an Option[Scalar]. This method handles addition based on the type of Scalar provided. If the input is an Angle, it computes the sum of the current Angle and the provided Angle. If the input is a Number, the addition is delegated to the doPlus implementation of the Number. CONSIDER eliminating this method (only used by unit tests).

Value parameters

that

the Scalar to be added to the current instance

Attributes

Returns

an Option[Scalar] containing the result of the addition, or None if the operation is not valid

override def eqv(that: Eager): Try[Boolean]

Compares two instances of Eager for equality.

Compares two instances of Eager for equality.

This method is intended to check if the provided instances, x and y, are equivalent. Currently, this functionality is not implemented and will return a failure with an appropriate exception message.

Value parameters

that

the first Eager instance to compare

Attributes

Returns

a Try[Boolean] where: - Success(true) indicates the objects are equivalent - Success(false) indicates the objects are not equivalent - Failure indicates this functionality is not implemented

Definition Classes
def multiply(n: Number): Try[Angle]

Multiplies the current Angle instance by a given Number.

Multiplies the current Angle instance by a given Number.

This operation is currently not supported and will always return a failure.

Value parameters

n

the Number to multiply with the current Angle

Attributes

Returns

a Try[Angle] containing a failure with an AlgebraException indicating that the multiply operation is not supported

def scale(r: Rational): Angle

Scales the current scalar instance by the specified rational factor.

Scales the current scalar instance by the specified rational factor.

Value parameters

r

the Rational factor by which to scale the scalar

Attributes

Returns

a new Angle instance representing the scaled value

def subtract(other: Angle): Try[Angle]

Subtracts the specified Angle from the current Angle instance.

Subtracts the specified Angle from the current Angle instance.

This method is not implemented and always returns a failure with a corresponding exception message.

Value parameters

other

the Angle to be subtracted from the current instance

Attributes

Returns

a Try[Angle] containing a failure with an exception indicating that the operation is not supported

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

infix def *(factor: Int): Angle

Multiplies the current instance by the specified integer factor.

Multiplies the current instance by the specified integer factor.

Value parameters

factor

the integer value to multiply with the current instance

Attributes

Returns

a new instance of type T representing the result of the multiplication

Inherited from:
Scalable
def +(that: Angle)(using AdditiveCommutativeMonoid[Angle], Convertible[Angle, Angle]): Angle

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Adds the given instance of the same type to this instance, leveraging the properties of an AdditiveCommutativeMonoid to ensure associativity, commutativity, and identity. CONSIDER keeping percentage if both are percentages. CONSIDER rewriting this in such a way that no exception will ever be thrown (use compiler to check, not runtime).

Value parameters

that

The instance of the same type to be added to this instance.

Attributes

Returns

The result of adding this instance and the provided instance.

Inherited from:
CanAdd
def <(that: Functional): Boolean

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
def <=(that: Functional): Boolean

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
def >(that: Functional): Boolean

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
def >=(that: Functional): Boolean

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
def add(y: Structure): Try[Structure]

Adds the specified Structure instance to the current instance, producing a new Structure.

Adds the specified Structure instance to the current instance, producing a new Structure.

Value parameters

y

The Structure instance to be added.

Attributes

Returns

A Try wrapping the resulting Structure instance, or a failure if the operation cannot be completed.

Inherited from:
Structure
infix def add(y: Eager): Try[Eager]

Adds the current Eager instance to another Eager instance using the DyadicOperator mechanism. The addition operation is implemented by delegating to the addEagers function for specific behavior, ensuring proper handling of various subtypes of Eager.

Adds the current Eager instance to another Eager instance using the DyadicOperator mechanism. The addition operation is implemented by delegating to the addEagers function for specific behavior, ensuring proper handling of various subtypes of Eager.

Value parameters

y

the Eager instance to be added to this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the addition if successful, or a failure if the operation fails

Inherited from:
Eager
infix def add[B <: Scalar](y: B): Try[Scalar]

Adds the specified Scalar instance to this Scalar and returns the result. The addition operation is performed for compatible scalar types. If the types are incompatible or the operation fails, a Failure is returned.

Adds the specified Scalar instance to this Scalar and returns the result. The addition operation is performed for compatible scalar types. If the types are incompatible or the operation fails, a Failure is returned.

Value parameters

y

the Scalar instance to add to this instance

Attributes

Returns

a Try[Scalar] containing the resulting Scalar if the addition is successful, or a Failure if the operation cannot be performed

Inherited from:
Scalar

Computes an approximate representation of the current value.

Computes an approximate representation of the current value.

This method utilizes the approximation mechanism to derive the most likely value in the form of a Real. Should the approximation fail, an AlgebraException will be raised to indicate the error.

Attributes

Returns

the approximate value as a Real if successful; throws an AlgebraException otherwise.

Inherited from:
Approximate
def approximation(force: Boolean = ...): Option[Real]

Attempts to approximate the current instance to a Real value. If the instance is already of type Real, it is simply returned, wrapped inside Some. Otherwise, depending on the value of force, it either attempts a conversion to a default Real (if force is true), or returns None.

Attempts to approximate the current instance to a Real value. If the instance is already of type Real, it is simply returned, wrapped inside Some. Otherwise, depending on the value of force, it either attempts a conversion to a default Real (if force is true), or returns None.

NOTE that this method tries to keep exact quantities exact.

Value parameters

force

a boolean flag indicating whether to force the conversion to a default Real value when the current instance is not of type Real

Attributes

Returns

an Option[Real] containing the approximated value if successful, or None if approximation fails

Inherited from:
Structure
def approximationComplex(force: Boolean = ...): Option[Eager]

Attempts to compute an approximate complex representation of the current value.

Attempts to compute an approximate complex representation of the current value.

This method provides an optional approximation in the form of an Eager type. By default, it does not perform the computation unless explicitly requested through the force flag. The method may return None if no approximation can be computed or if the operation fails.

Value parameters

force

a boolean flag indicating whether to force computation of the approximation. If true, the method will attempt to perform a complex approximation even if it is resource-intensive or otherwise unwarranted.

Attributes

Returns

an Option containing the approximate value as an Eager if successful, or None if no approximation is available.

Inherited from:
Approximate
def asJavaNumber: Option[Number]

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

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

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

  • If the Structure object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the Structure object is a Real 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:
Structure
def asT: Angle

Casts the current instance to the type parameter T of the enclosing Can trait.

Casts the current instance to the type parameter T of the enclosing Can trait.

This method performs a type-safe cast using the ClassTag to verify at runtime that the cast is valid. If the current instance cannot be cast to type T, an AlgebraException is thrown.

Attributes

Returns

the current instance as an instance of type T

Throws
AlgebraException

if the cast is invalid

Inherited from:
Can
def category: String

Returns the category of this value in the Valuable type hierarchy.

Returns the category of this value in the Valuable type hierarchy.

Attributes

Returns

a string indicating the high-level category (e.g., "Expression", "Structure", "Nat", "Complex")

Inherited from:
TypeSafe
override def compare(x: Eager, y: Eager): Try[Int]

Compares two instances of Eager and determines their relative ordering. This method is not yet implemented and will raise an com.phasmidsoftware.number.algebra.util.AlgebraException if called.

Compares two instances of Eager and determines their relative ordering. This method is not yet implemented and will raise an com.phasmidsoftware.number.algebra.util.AlgebraException if called.

Value parameters

x

the first Eager instance to compare

y

the second Eager instance to compare

Attributes

Returns

a Try[Int] that contains the comparison result: - 0 if x and y are equal, - a negative result if x is less than y, - and a positive result if x is greater than y. As the method is unimplemented, it will always return a failure with an AlgebraException.

Definition Classes
Inherited from:
Scalar
def compareTo(that: Functional): Int

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
def describe: String

Returns a descriptive string combining category and type name. Useful for debugging to understand both the hierarchy level and concrete type.

Returns a descriptive string combining category and type name. Useful for debugging to understand both the hierarchy level and concrete type.

Attributes

Returns

a string in the format "Category.TypeName" (e.g., "Structure.WholeNumber")

Inherited from:
TypeSafe
def divide(y: Structure): Try[Structure]

Divides the current Structure instance by another Structure instance. The operation is performed using the DyadicOperator defined for Structure. The result is wrapped in a Try to handle potential failures during the operation.

Divides the current Structure instance by another Structure instance. The operation is performed using the DyadicOperator defined for Structure. The result is wrapped in a Try to handle potential failures during the operation.

Value parameters

y

the Structure instance to divide the current instance by

Attributes

Returns

a Try[Structure] containing the result of the division if successful, or a failure if the operation cannot be performed

Inherited from:
Structure
infix def divide(y: Eager): Try[Eager]

Performs division of the current Eager instance by another Eager instance. This operation is implemented using the DyadicOperator mechanism, delegating the actual division logic to the divideEagers function.

Performs division of the current Eager instance by another Eager instance. This operation is implemented using the DyadicOperator mechanism, delegating the actual division logic to the divideEagers function.

Value parameters

y

the Eager instance to divide the current instance by

Attributes

Returns

a Try[Eager] containing the result of the division if successful, or a failure if the operation cannot be performed

Inherited from:
Eager
def divide[B <: Scalar](y: B): Try[Scalar]

Divides this Scalar instance by another Scalar instance of type B. The result of the division is wrapped in a Try to safely handle potential failures.

Divides this Scalar instance by another Scalar instance of type B. The result of the division is wrapped in a Try to safely handle potential failures.

Value parameters

y

The Scalar instance to divide by. Must be a subtype of Scalar.

Attributes

Returns

A Try containing the result of the division as a Scalar, or a failure if the division cannot be performed.

Inherited from:
Scalar
def fuzzy: Eager

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attempts to convert the current object to an instance of Eager using an approximation method. If the conversion fails, it recovers by throwing an AlgebraException with a descriptive error message.

Attributes

Returns

An instance of Eager if the approximation is successful.

Inherited from:
Eager
def fuzzyCompare(p: Double)(x: Eager, y: Eager): Try[Int]

Performs a fuzzy comparison between two Eager instances. The comparison is based on a specified tolerance and determines their relative ordering. If the comparison cannot be performed, an AlgebraException is returned as a failure.

Performs a fuzzy comparison between two Eager instances. The comparison is based on a specified tolerance and determines their relative ordering. If the comparison cannot be performed, an AlgebraException is returned as a failure.

Value parameters

p

the tolerance (as a Double) to be used for the comparison

x

the first Eager instance to be compared

y

the second Eager instance to be compared

Attributes

Returns

a Try[Int] representing the result of the comparison: - A negative integer if x is less than y - Zero if x is approximately equal to y within the tolerance p - A positive integer if x is greater than y - A Failure(AlgebraException) if the comparison cannot be performed

Inherited from:
Eager
override def fuzzyEqv(confidence: Double)(that: Eager): Try[Boolean]

Performs a fuzzy equality comparison between the current Structure instance and another Eager instance. The comparison is based on a specified tolerance level.

Performs a fuzzy equality comparison between the current Structure instance and another Eager instance. The comparison is based on a specified tolerance level.

If both instances are of type Structure, this method attempts to convert them to Real and performs a fuzzy equality check with the specified tolerance. If the conversion or comparison fails, a failure with an appropriate AlgebraException is returned.

If either of the instances is not of type Structure, a failure with an AlgebraException is returned.

Value parameters

confidence

the tolerance level (as a Double) to be used for the fuzzy equality comparison.

that

the Eager instance to compare against the current instance.

Attributes

Returns

a Try[Boolean] indicating whether the two instances are fuzzy equal within the specified tolerance. Returns a Success(true) or Success(false) if the comparison completes successfully, or a Failure(AlgebraException) if an error occurs.

Definition Classes
Inherited from:
Structure
def maybeFactor(context: Context): Option[Factor]

Retrieves an optional factor associated with the specified context. The factor may represent a transformation or scaling associated with a computation in a particular evaluation context.

Retrieves an optional factor associated with the specified context. The factor may represent a transformation or scaling associated with a computation in a particular evaluation context.

Value parameters

context

the evaluation context within which the factor is to be determined.

Attributes

Returns

an Option containing the factor if it exists; None otherwise.

Inherited from:
Radians
def multiply(y: Structure): Try[Structure]

Multiplies the current Structure instance by the specified Structure operand. The result of the operation is wrapped in a Try, allowing for safe handling of failures.

Multiplies the current Structure instance by the specified Structure operand. The result of the operation is wrapped in a Try, allowing for safe handling of failures.

Value parameters

y

the Structure operand with which the current instance is multiplied

Attributes

Returns

a Try[Structure] containing the result of the multiplication if successful, or a failure if the operation is not valid or cannot be performed

Inherited from:
Structure
infix def multiply(y: Eager): Try[Eager]

Multiplies the current Eager instance with another Eager instance. The multiplication operation is carried out using the DyadicOperator mechanism, which delegates to the multiplyEagers function for specific behavior. This ensures proper handling of various subtypes of Eager.

Multiplies the current Eager instance with another Eager instance. The multiplication operation is carried out using the DyadicOperator mechanism, which delegates to the multiplyEagers function for specific behavior. This ensures proper handling of various subtypes of Eager.

Value parameters

y

the Eager instance to multiply with this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the multiplication if successful, or a failure if the operation cannot be performed

Inherited from:
Eager
def multiply[B <: Scalar](y: B): Try[Scalar]

Multiplies this Scalar instance by another Scalar of type B. The operation uses a dyadic operator to compute the product of the two scalars. The result is wrapped in a Try to handle any potential failures during the operation.

Multiplies this Scalar instance by another Scalar of type B. The operation uses a dyadic operator to compute the product of the two scalars. The result is wrapped in a Try to handle any potential failures during the operation.

Value parameters

y

the Scalar instance to multiply with this instance. Must be a subtype of Scalar.

Attributes

Returns

a Try[Scalar] representing the product of the multiplication, or a failure if the operation is not possible.

Inherited from:
Scalar

Returns a new instance of Structure that is the negation of the current instance. CONSIDER sorting out the use of CanNegate so that we can extend that for Structure.

Returns a new instance of Structure that is the negation of the current instance. CONSIDER sorting out the use of CanNegate so that we can extend that for Structure.

Attributes

Returns

a Structure representing the negation of this instance

Inherited from:
Scalar
infix def plus(that: Structure)(using AdditiveCommutativeMonoid[Angle]): Option[Angle]

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

Computes the addition of this object and the given Structure object using the additive properties of an AdditiveCommutativeMonoid. The operation returns an optional result where the addition succeeds if a valid transformation and combination can be performed.

CONSIDER eliminate this method and use with + instead.

Value parameters

that

the Structure object to be added to this object.

Attributes

Returns

an Option containing the result of the addition if successful, or None if the operation cannot be completed.

Inherited from:
CanAdd
def product(other: Valuable): Valuable

Obtains the product of this Valuable instance and another Valuable instance. The behavior of the method is determined by whether the instances are of type Lazy or Eager. If the provided instances do not conform to the expected types, an AlgebraException is thrown. CONSIDER supporting sum also.

Obtains the product of this Valuable instance and another Valuable instance. The behavior of the method is determined by whether the instances are of type Lazy or Eager. If the provided instances do not conform to the expected types, an AlgebraException is thrown. CONSIDER supporting sum also.

CONSIDER using lazify

Value parameters

other

the other Valuable instance to compute the product with

Attributes

Returns

a Valuable instance representing the product of this and the other instance

Note

throws AlgebraException if the computation involves unsupported Valuable types

Inherited from:
Valuable
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
def scale(x: Int): Scalar

Scales the current scalar instance by a factor derived from the specified integer.

Scales the current scalar instance by a factor derived from the specified integer.

Value parameters

x

the integer factor by which to scale the scalar

Attributes

Returns

a new Scalar instance representing the scaled value

Inherited from:
Scalar
def subtract(y: Structure): Try[Structure]

Subtracts the given Structure instance (y) from the current instance. The operation is performed using a dyadic operator that ensures type safety and handles any failures during the subtraction via a Try.

Subtracts the given Structure instance (y) from the current instance. The operation is performed using a dyadic operator that ensures type safety and handles any failures during the subtraction via a Try.

Value parameters

y

the Structure instance to be subtracted from the current instance

Attributes

Returns

a Try[Structure] containing the result of the subtraction if successful, or a failure if the subtraction operation cannot be performed

Inherited from:
Structure
infix def subtract(y: Eager): Try[Eager]

Subtracts the given Eager instance y from the current Eager instance. This operation is performed using the DyadicOperator mechanism, which delegates to the subtractEagers function to handle the specific subtraction behavior.

Subtracts the given Eager instance y from the current Eager instance. This operation is performed using the DyadicOperator mechanism, which delegates to the subtractEagers function to handle the specific subtraction behavior.

Value parameters

y

the Eager instance to be subtracted from this Eager instance

Attributes

Returns

a Try[Eager] containing the result of the subtraction if successful, or a failure if the operation fails

Inherited from:
Eager
def subtract[B <: Scalar](y: B): Try[Scalar]

Subtracts the given scalar from this scalar and returns the result wrapped in a Try. The operation is performed using the dyadic operator logic powered by DyadicOperator, with the subtraction behavior provided by subtractScalars.

Subtracts the given scalar from this scalar and returns the result wrapped in a Try. The operation is performed using the dyadic operator logic powered by DyadicOperator, with the subtraction behavior provided by subtractScalars.

Value parameters

y

The scalar value to subtract, which must be a subtype of Scalar.

Attributes

Returns

A Try[Scalar] containing the result of the subtraction if successful, or a failure if the operation cannot be completed (e.g., type mismatch or invalid operation).

Inherited from:
Scalar
def toReal: Real

Converts the current instance of Functional into a Real representation.

Converts the current instance of Functional into a Real representation.

The conversion is achieved by applying the scaleFunction to the value derived from the number method, and optionally utilizing maybeFuzz if available. This process encapsulates the numerical transformation, resulting in the Real type.

Attributes

Returns

a Real object representing the scaled and transformed value of the current instance.

Inherited from:
Functional
def typeName: String

Returns a simple string representation of the runtime type. Useful for debugging and logging.

Returns a simple string representation of the runtime type. Useful for debugging and logging.

Attributes

Returns

the simple class name (e.g., "WholeNumber", "RationalNumber")

Inherited from:
TypeSafe

Concrete fields

lazy val approximation: Option[Real]

Provides an approximation of this number, if applicable.

Provides an approximation of this number, if applicable.

This method attempts to compute an approximate representation of the number in the form of a Real, which encapsulates uncertainty or imprecision in its value. If no meaningful approximation is possible for the number, it returns None.

Attributes

Returns

an Option[Real] containing the approximate representation of this Number, or None if no approximation is available.

lazy val asDouble: Double

Converts the current instance to a Double representation. CONSIDER may be able to eliminate this method and use nominalValue instead.

Converts the current instance to a Double representation. CONSIDER may be able to eliminate this method and use nominalValue instead.

Attributes

Returns

the Double value corresponding to the current instance

val derivativeFunction: Double => Double

Represents the derivative function associated with this Functional instance. That's to say d(f(number)) by d(number) where f is this Functional. For a Structure, the derivative should be positive, however, it is possible that it is not positive for certain types of Functional.

Represents the derivative function associated with this Functional instance. That's to say d(f(number)) by d(number) where f is this Functional. For a Structure, the derivative should be positive, however, it is possible that it is not positive for certain types of Functional.

The derivativeFunction provides a mathematical operation that computes the derivative with respect to a given input value. It is typically used to evaluate rates of change or sensitivity in the context of numerical transformations.

Attributes

Returns

A function that accepts a Double value and returns the computed derivative as a Double.

lazy val fuzz: Option[Fuzziness[Double]]

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 Option containing the Fuzziness[Double] value if defined, or None if no fuzziness is specified.

lazy val isExact: Boolean

Method to determine if this Structure 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 Structure 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 Structure object is exact in the context of No factor, else false.

lazy val isUnity: Boolean

Determines whether this object represents unity.

Determines whether this object represents unity.

Attributes

Returns

true if the object represents unity, false otherwise

lazy val isZero: Boolean

Determines if the current number is equal to zero.

Determines if the current number is equal to zero.

Attributes

Returns

true if the number is zero, false otherwise

val maybeName: Option[String]

Retrieves an optional name associated with this instance.

Retrieves an optional name associated with this instance.

Attributes

Returns

an Option[String] containing the name if present, otherwise None

lazy val maybeQ: Option[Q]

Determines if the number value can be interpreted as an instance of Q. If number matches the type Q, it returns an Option containing the value of Q. Otherwise, it returns None.

Determines if the number value can be interpreted as an instance of Q. If number matches the type Q, it returns an Option containing the value of Q. Otherwise, it returns None.

Attributes

Returns

an Option[Q] where Some(Q) is returned if number is of type Q, otherwise None.

lazy val normalize: Angle

Normalizes an angle instance to its equivalent value within the standard range of radians.

Normalizes an angle instance to its equivalent value within the standard range of radians.

This method processes the number value of the current Angle and adjusts it to lie within the expected range, typically between 0 and 2π or -π to π, depending on the implementation of the Radian.modulate logic. Various specific cases are covered based on the type of the input:

  • Rational numbers are converted using their rational representation.
  • Reals are adjusted using their double value, with fuzz consideration awaiting implementation.
  • Whole numbers are directly handled using their integer representation.

CONSIDER we lose information regarding degrees here (perhaps fix that?)

Attributes

Returns

a new instance of Angle representing the normalized value

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the input type is not recognized.

lazy val render: String

Renders this Angle instance as a string representation of radians in terms of π.

Renders this Angle instance as a string representation of radians in terms of π.

The method formats the radius equivalent to π, omitting the numeric coefficient if it is 1.

Attributes

Returns

a string representation of the Angle in terms of π

lazy override val show: String

Renders and returns a string representation of the object. By default, this is the same as render but it can be overridden in subclasses.

Renders and returns a string representation of the object. By default, this is the same as render but it can be overridden in subclasses.

Attributes

Returns

a string representing the object

lazy val signum: Int

Determines the sign of the scalar value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.

Determines the sign of the scalar value represented by this instance. Returns an integer indicating whether the value is positive, negative, or zero.

Attributes

Returns

1 if the value is positive, -1 if the value is negative, and 0 if the value is zero

lazy val unary_-: Angle

Computes the additive inverse of the current Angle instance.

Computes the additive inverse of the current Angle instance.

This method negates the current angle, returning a new Angle instance with the opposite value, relative to Angle.zero.

Attributes

Returns

a new Angle instance representing the additive inverse of the current angle.

val zero: Angle

Represents the zero value of the Angle class.

Represents the zero value of the Angle class.

This is a predefined constant that corresponds to an Angle of zero radians. It is used as the additive identity in operations involving angles.

Attributes

Inherited fields

lazy val asMonotone: Structure

Casts this Valuable instance into a Structure type if it already is a Structure. If the instance is not a Structure, an AlgebraException is thrown. CONSIDER returning Option[Structure] instead.

Casts this Valuable instance into a Structure type if it already is a Structure. If the instance is not a Structure, an AlgebraException is thrown. CONSIDER returning Option[Structure] instead.

Attributes

Returns

the current instance as a Structure

Note

Throws com.phasmidsoftware.number.algebra.util.AlgebraException if the instance is not of type Structure

Inherited from:
Valuable
lazy val asNumber: Option[Number]

Attempts to cast this instance to a Number. If the instance is of type Number, it is wrapped in an Option and returned. Otherwise, returns None.

Attempts to cast this instance to a Number. If the instance is of type Number, it is wrapped in an Option and returned. Otherwise, returns None.

Attributes

Returns

an Option containing the instance as a Number if applicable, or None if not.

Inherited from:
Valuable
lazy val materialize: Eager

Converts the current Lazy instance into an Eager instance by forcing the resolution or evaluation of its underlying value.

Converts the current Lazy instance into an Eager instance by forcing the resolution or evaluation of its underlying value.

The materialize method ensures that the computation of the value represented by this Lazy instance is completed and encapsulated within an appropriate Eager representation. This is particularly useful in scenarios where deferred computation needs to be explicitly resolved prior to further processing.

Attributes

Returns

the materialized Eager instance representing the resolved value

Inherited from:
Eager
lazy override val maybeDouble: Option[Double]

If this Valuable is exact, it returns the exact value as a Double. Otherwise, it returns None. NOTE: do NOT implement this method to return a Double for a fuzzy Real--only for exact numbers.

If this Valuable is exact, it returns the exact value as a Double. Otherwise, it returns None. NOTE: do NOT implement this method to return a Double for a fuzzy Real--only for exact numbers.

Attributes

Returns

Some(x) where x is a Double if this is exact, else None.

Inherited from:
Functional
lazy val maybeFuzz: Option[Fuzziness[Double]]

Retrieves an optional fuzziness value for a given number.

Retrieves an optional fuzziness value for a given number.

Attributes

Returns

An Option containing the fuzziness representation of the number, or None if not available.

Inherited from:
Functional
lazy val nominalValue: Double

Retrieves the nominal (non-fuzzy) value associated with the entity.

Retrieves the nominal (non-fuzzy) value associated with the entity.

This value represents the precise or primary measurement or parameter of the entity, without considering any associated fuzziness or uncertainty.

Attributes

Returns

The nominal value as a Double.

Inherited from:
Functional
val scaleFactor: Double

Represents the scalar value for converting radians to a pure number, using Pi as the scaling factor.

Represents the scalar value for converting radians to a pure number, using Pi as the scaling factor.

Attributes

Inherited from:
Radians
val scaleFunction: Double => Double

This yields the scale function for this Functional.

This yields the scale function for this Functional.

Attributes

Returns

a function to transform the nominal value into the actual value as it would appear in a PureNumber context.

Inherited from:
Radians
lazy val toDouble: Double

Converts the approximate representation of this number into a Double.

Converts the approximate representation of this number into a Double.

This method attempts to approximate the value of this number by invoking the approximation method with force = true. If the approximation exists, it is converted to a Double. If no approximation can be obtained, an AlgebraException is thrown to indicate a logic error.

Attributes

Returns

the approximate value as a Double.

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if no approximation can be obtained.

Inherited from:
Approximate