Package it.unimi.di.prog2.h19
Class DensePoly
java.lang.Object
it.unimi.di.prog2.h19.AbstractPoly
it.unimi.di.prog2.h19.DensePoly
A dense polynomial with integer coefficients.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate final int[]
The array of coefficients, thecoeffs[i]
is the coefficient of \( x^i \). -
Constructor Summary
-
Method Summary
Methods inherited from class it.unimi.di.prog2.h19.AbstractPoly
degree, equals, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
coeffs
private final int[] coeffsThe array of coefficients, thecoeffs[i]
is the coefficient of \( x^i \).
-
-
Constructor Details
-
DensePoly
public DensePoly()Initializes this to be the zero polynomial, that is \( p = 0 \). -
DensePoly
Initializes this to be the polynomial \(p = cx^n\).- Parameters:
coeff
- the coefficient.degree
- the degree.- Throws:
IllegalArgumentException
- ifn
< 0.
-
DensePoly
private DensePoly(int degree) Initializes a polynomial of given degree (with all coefficients equal to 0).- Parameters:
degree
- the degree.
-
-
Method Details
-
coeff
public int coeff(int degree) Description copied from interface:Poly
Returns the coefficient of the term of given exponent.- Parameters:
degree
- the exponent of the term to consider.- Returns:
- the coefficient of the considered term.
-
add
Description copied from interface:Poly
Performs polynomial addition.If \( p \) is this polynomial, returns \( p + q \).
- Parameters:
q
- the polynomial to add to this one.- Returns:
- the sum among this and the given polynomial.
- Throws:
NullPointerException
- ifq
isnull
.
-
mul
Description copied from interface:Poly
Performs polynomial multiplication.If \( p \) is this polynomial, returns \( p q \).
- Parameters:
q
- the polynomial to multiply by this one.- Returns:
- the product among this and the given polynomial.
- Throws:
NullPointerException
- ifq
isnull
.
-
minus
Description copied from interface:Poly
Returns the negated polynomial.If \( p \) is this polynomial, returns \( -p \).
- Returns:
- this polynomial multiplied by \( -1 \).
-
iterator
-