}
// The method print adds to the output so it blends more consistently together
-// with the other routines.
+// with the other routines and produces something compatible to Maple input.
void numeric::print(ostream & os, unsigned upper_precedence) const
{
debugmsg("numeric print", LOGLEVEL_PRINT);
if (is_real()) {
// case 1, real: x or -x
- if ((realpart(*value) < 0) && (precedence <= upper_precedence)) {
+ if ((precedence<=upper_precedence) && (!is_pos_integer())) {
os << "(" << *value << ")";
} else {
os << *value;
} else {
// case 2, imaginary: y*I or -y*I
if (realpart(*value) == 0) {
- if ((imagpart(*value) < 0) && (precedence <= upper_precedence)) {
+ if ((precedence<=upper_precedence) && (imagpart(*value) < 0)) {
if (imagpart(*value) == -1) {
os << "(-I)";
} else {
}
} else {
// case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I
- if ((realpart(*value) < 0) && (precedence <= upper_precedence)) {
- os << "(" << realpart(*value);
- if (imagpart(*value) < 0) {
- if (imagpart(*value) == -1) {
- os << "-I)";
- } else {
- os << imagpart(*value) << "*I)";
- }
+ if (precedence <= upper_precedence) os << "(";
+ os << realpart(*value);
+ if (imagpart(*value) < 0) {
+ if (imagpart(*value) == -1) {
+ os << "-I";
} else {
- if (imagpart(*value) == 1) {
- os << "+I)";
- } else {
- os << "+" << imagpart(*value) << "*I)";
- }
+ os << imagpart(*value) << "*I";
}
} else {
- os << realpart(*value);
- if (imagpart(*value) < 0) {
- if (imagpart(*value) == -1) {
- os << "-I";
- } else {
- os << imagpart(*value) << "*I";
- }
+ if (imagpart(*value) == 1) {
+ os << "+I";
} else {
- if (imagpart(*value) == 1) {
- os << "+I";
- } else {
- os << "+" << imagpart(*value) << "*I";
- }
+ os << "+" << imagpart(*value) << "*I";
}
}
+ if (precedence <= upper_precedence) os << ")";
}
}
}