Subject: | Zero polynomial stringifies to empty string in verbose mode |
Distribution: M/MH/MHASCH/Math-Polynomial-0.04.tar.gz
The zero polynomial gets converted to the empty string when verbose
mode is turned on:
perl -MMath::Polynomial -e 'Math::Polynomial->verbose(1); $p =
Math::Polynomial->new(0); print "$p\n"'
This is certainly unexpected and arguably a bug.
Attached is a patch to return "0" in this case.
Subject: | Polynomial.pm.diff |
--- Polynomial.pm.orig 2007-08-26 18:46:44.000000000 +0200
+++ Polynomial.pm 2007-08-26 19:05:46.000000000 +0200
@@ -419,12 +419,19 @@
$exp--;
}
- if (@terms && $terms[0] eq $CONFIG{PLUS}) {
- # If there's a plus first, drop it.
- shift(@terms);
- } elsif (@terms) {
- # Otherwise, remove any spaces around the first minus.
- $terms[0] =~ tr/ //d;
+ if (@terms) {
+ if ($terms[0] eq $CONFIG{PLUS}) {
+ # If there's a plus first, drop it.
+ shift(@terms);
+ } else {
+ # Otherwise, remove any spaces around the first minus.
+ $terms[0] =~ tr/ //d;
+ }
+ }
+ else {
+ # We are dealing with the zero polynomial,
+ # so show the term '0'.
+ push(@terms, 0);
}
return join('', @terms);
} else {