This utility method is used to make a copy of a coefficient
list, and add zeroes on the right if necessary to pad it out
to the standard length, which is len(self.factors)+1.
# - - - M i x e d U n i t s . _ _ p a d
def __pad ( self, coeffs ):
"""Pad coefficient lists to standard length.
[ coeffs is a sequence of numbers ->
if len(coeffs) > len(self.factors)+1 ->
raise ValueError
else ->
return a list containing the elements of coeff,
plus additional zeroes on the right if necessary
so that the result has length len(self.factors)+1 ]
"""
First we set stdLen to the standard length,
then set shortage to the number of elements
we have to add to coeffs to reach that
length. If shortage is negative, that's an
error: coeffs is too long for this system.
We use the fact that Python's list() function
makes a copy of its argument, even if the argument is a
list. If the argument is a tuple, it is converted to a
list.
#-- 1 --
# [ stdLen := 1 + len(self.factors)
# shortage := 1 + len(self.factors) - len(coeffs)
# result := a copy of coeffs as a list ]
stdLen = 1 + len(self.factors)
shortage = stdLen - len(coeffs)
result = list(coeffs)
#-- 2 --
# [ if shortage < 0 ->
# raise ValueError
# else ->
# result := result + (a list of shortage zeroes) ]
if shortage < 0:
raise ValueError, ( "Value %s has too many elements; "
"max is %d." % (coeffs, stdLen) )
elif shortage > 0:
result += [0.0] * shortage
#-- 3 --
return result