Class Integer
java.lang.Object
java.lang.Number
org.episteme.core.mathematics.numbers.integers.Integer
- All Implemented Interfaces:
Serializable, Comparable<Integer>, AbelianGroup<Integer>, AbelianMonoid<Integer>, Group<Integer>, Magma<Integer>, Monoid<Integer>, Ring<Integer>, RingElement<Integer>, Semiring<Integer>, Set<Integer>
public abstract class Integer
extends Number
implements Ring<Integer>, Comparable<Integer>, RingElement<Integer>
Abstract base class for integers (ℤ = {..., -2, -1, 0, 1, 2, ...}).
Integers form a Ring under addition and multiplication. This class provides a smart factory that automatically chooses the most efficient backing implementation:
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabstract Integerabs()Returns the absolute value of this integer.abstract IntegerAdds another integer.abstract BigIntegerConverts this integer to a BigInteger.abstract intabstract IntegerDivides by another integer (integer division).doubleConverts this integer to a double.abstract booleanReturns the greatest common divisor of absolute value of this integer and absolute value of other integer.abstract inthashCode()abstract booleanisOne()Returns true if this integer is one.abstract booleanisZero()Returns true if this integer is zero.abstract longConverts this integer to a long.abstract IntegerReturns the remainder of the division of this integer by the specified integer.abstract IntegerMultiplies by another integer.abstract Integernegate()Returns the negation of this integer.static Integerof(int value) Creates an integer from an int value.static Integerof(long value) Creates an integer from a long value.static Integerof(BigInteger value) Creates an integer from a BigInteger.one()Returns the multiplicative identity (one element).abstract IntegerComputes the remainder of division.intsignum()Returns the signum function of this integer.abstract IntegerSubtracts another integer.Returns the rational number equivalent to this integer.abstract StringtoString()static IntegerCreates an integer from a String representation.zero()Returns the additive identity (zero element).Methods inherited from class Number
byteValue, floatValue, intValue, shortValueMethods inherited from interface AbelianGroup
isCommutative, negate, subtractMethods inherited from interface AbelianMonoid
add, identity, isCommutativeMethods inherited from interface Monoid
isAssociativeMethods inherited from interface Semiring
isMultiplicationCommutative, multiply, powMethods inherited from interface Set
contains, description, isEmpty
-
Field Details
-
ZERO
The integer 0 -
ONE
The integer 1 -
MINUS_ONE
The integer -1
-
-
Method Details
-
of
Creates an integer from an int value.- Parameters:
value- the value- Returns:
- the Integer instance
-
of
Creates an integer from a long value. Automatically selects optimal backing implementation.- Parameters:
value- the value- Returns:
- the Integer instance
-
of
Creates an integer from a BigInteger. Automatically selects optimal backing implementation.- Parameters:
value- the value- Returns:
- the Integer instance
- Throws:
IllegalArgumentException- if value is null
-
valueOf
-
add
Adds another integer.- Specified by:
addin interfaceRingElement<Integer>- Parameters:
other- the addend- Returns:
- this + other
-
subtract
Subtracts another integer.- Specified by:
subtractin interfaceRingElement<Integer>- Parameters:
other- the subtrahend- Returns:
- this - other
-
multiply
Multiplies by another integer.- Specified by:
multiplyin interfaceRingElement<Integer>- Parameters:
other- the multiplicand- Returns:
- this × other
-
divide
Divides by another integer (integer division).- Parameters:
other- the divisor- Returns:
- this / other (truncated towards zero)
- Throws:
ArithmeticException- if other is zero
-
remainder
Computes the remainder of division.- Parameters:
other- the divisor- Returns:
- this % other
- Throws:
ArithmeticException- if other is zero
-
negate
Returns the negation of this integer.- Specified by:
negatein interfaceRingElement<Integer>- Returns:
- -this
-
abs
-
isZero
public abstract boolean isZero()Returns true if this integer is zero.- Specified by:
isZeroin interfaceRingElement<Integer>- Returns:
- true if this equals zero()
-
isOne
public abstract boolean isOne()Returns true if this integer is one.- Specified by:
isOnein interfaceRingElement<Integer>- Returns:
- true if this equals one()
-
longValue
public abstract long longValue()Converts this integer to a long.- Specified by:
longValuein classNumber- Returns:
- the long value
- Throws:
ArithmeticException- if the value doesn't fit in a long
-
bigIntegerValue
Converts this integer to a BigInteger.- Returns:
- the BigInteger value (never null)
-
mod
Returns the remainder of the division of this integer by the specified integer.- Parameters:
divisor- the divisor- Returns:
- this % divisor
- Throws:
ArithmeticException- if divisor is zero
-
equals
-
hashCode
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<Integer>
-
signum
public int signum()Returns the signum function of this integer.- Returns:
- -1, 0 or 1 as the value of this integer is negative, zero or positive.
-
doubleValue
public double doubleValue()Converts this integer to a double.- Specified by:
doubleValuein classNumber- Returns:
- this integer as a double
-
gcd
-
zero
Description copied from interface:AbelianMonoidReturns the additive identity (zero element).Delegates to
AbelianMonoid.identity().- Specified by:
zeroin interfaceAbelianMonoid<Integer>- Specified by:
zeroin interfaceRingElement<Integer>- Returns:
- the zero element
-
one
Description copied from interface:SemiringReturns the multiplicative identity (one element).Satisfies: 1 × a = a × 1 = a for all elements a.
-
toRational
Returns the rational number equivalent to this integer.- Returns:
- the rational instance
-