NumberIsAdditiveCommutativeMonoid

com.phasmidsoftware.number.algebra.eager.Number.NumberIsAdditiveCommutativeMonoid
object NumberIsAdditiveCommutativeMonoid extends AdditiveCommutativeMonoid[Number]

Provides an implicit additive commutative monoid implementation for the Number type.

This object defines the zero element and the plus operation for the Number type, conforming to the algebraic structure of an additive commutative monoid.

The zero element acts as the additive identity, and the plus operation is both associative and commutative, enabling addition of two Number instances.

Attributes

Graph
Supertypes
trait AdditiveCommutativeMonoid[Number]
trait AdditiveCommutativeSemigroup[Number]
trait AdditiveMonoid[Number]
trait AdditiveSemigroup[Number]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

Members list

Value members

Concrete methods

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

Adds two Number instances together.

Adds two Number instances together.

The method determines the type of the given Number instances and performs the appropriate addition operation. It supports addition for Real, RationalNumber, and WholeNumber types. If the types are incompatible or cannot be converted to corresponding types, it throws a AlgebraException.

This method is marked as @tailrec to optimize recursive addition operations.

Value parameters

x

the first Number instance

y

the second Number instance

Attributes

Returns

a Number instance representing the result of the addition of x and y

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the types of x and y cannot be added

Inherited methods

override def additive: CommutativeMonoid[Number]

Attributes

Definition Classes
AdditiveCommutativeMonoid -> AdditiveCommutativeSemigroup -> AdditiveMonoid -> AdditiveSemigroup
Inherited from:
AdditiveCommutativeMonoid
def isZero(a: Number)(implicit ev: Eq[Number]): Boolean

Tests if a is zero.

Tests if a is zero.

Attributes

Inherited from:
AdditiveMonoid
def sum(as: IterableOnce[Number]): Number

Given a sequence of as, compute the sum.

Given a sequence of as, compute the sum.

Attributes

Inherited from:
AdditiveMonoid
override def sumN(a: Number, n: Int): Number

Attributes

Definition Classes
AdditiveMonoid -> AdditiveSemigroup
Inherited from:
AdditiveMonoid
override def trySum(as: IterableOnce[Number]): Option[Number]

Given a sequence of as, combine them and return the total.

Given a sequence of as, combine them and return the total.

If the sequence is empty, returns None. Otherwise, returns Some(total).

Attributes

Definition Classes
AdditiveMonoid -> AdditiveSemigroup
Inherited from:
AdditiveMonoid

Concrete fields

lazy val zero: Number

Returns the additive identity element for the Number type.

Returns the additive identity element for the Number type.

This method provides the zero element, which serves as the neutral element in addition operations for instances of Number. Adding zero to any Number instance will result in the same Number instance.

Attributes

Returns

the additive identity element for Number