c.s.flags(oldflags);
} else {
-
- cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
- cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
+ const std::string par_open = is_of_type(c, print_latex) ? "{(" : "(";
+ const std::string par_close = is_of_type(c, print_latex) ? ")}" : ")";
+ const std::string imag_sym = is_of_type(c, print_latex) ? "i" : "I";
+ const std::string mul_sym = is_of_type(c, print_latex) ? " " : "*";
+ const cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
+ const cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
if (cln::zerop(i)) {
// case 1, real: x or -x
if ((precedence <= level) && (!this->is_nonneg_integer())) {
- c.s << "(";
+ c.s << par_open;
print_real_number(c.s, r);
- c.s << ")";
+ c.s << par_close;
} else {
print_real_number(c.s, r);
}
// case 2, imaginary: y*I or -y*I
if ((precedence <= level) && (i < 0)) {
if (i == -1) {
- c.s << "(-I)";
+ c.s << par_open+imag_sym+par_close;
} else {
- c.s << "(";
+ c.s << par_open;
print_real_number(c.s, i);
- c.s << "*I)";
+ c.s << mul_sym+imag_sym+par_close;
}
} else {
if (i == 1) {
- c.s << "I";
+ c.s << imag_sym;
} else {
if (i == -1) {
- c.s << "-I";
+ c.s << "-" << imag_sym;
} else {
print_real_number(c.s, i);
- c.s << "*I";
+ c.s << mul_sym+imag_sym;
}
}
}
} else {
// case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I
if (precedence <= level)
- c.s << "(";
+ c.s << par_open;
print_real_number(c.s, r);
if (i < 0) {
if (i == -1) {
- c.s << "-I";
+ c.s << "-"+imag_sym;
} else {
print_real_number(c.s, i);
- c.s << "*I";
+ c.s << mul_sym+imag_sym;
}
} else {
if (i == 1) {
- c.s << "+I";
+ c.s << "+"+imag_sym;
} else {
c.s << "+";
print_real_number(c.s, i);
- c.s << "*I";
+ c.s << mul_sym+imag_sym;
}
}
if (precedence <= level)
- c.s << ")";
+ c.s << par_close;
}
}
}
bool numeric::operator==(const numeric &other) const
{
- return equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
+ return cln::equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
}
bool numeric::operator!=(const numeric &other) const
{
- return !equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
+ return !cln::equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
}
if (this->is_integer())
return _num1();
- if (instanceof(value, cln::cl_RA_ring))
+ if (cln::instanceof(value, cln::cl_RA_ring))
return numeric(cln::denominator(cln::the<cln::cl_RA>(value)));
if (!this->is_real()) { // complex case, handle Q(i):
const numeric iquo(const numeric &a, const numeric &b)
{
if (a.is_integer() && b.is_integer())
- return truncate1(cln::the<cln::cl_I>(a.to_cl_N()),
- cln::the<cln::cl_I>(b.to_cl_N()));
+ return cln::truncate1(cln::the<cln::cl_I>(a.to_cl_N()),
+ cln::the<cln::cl_I>(b.to_cl_N()));
else
return _num0();
}