DEFAULT_UNARCHIVE(numeric)
//////////
-// functions overriding virtual functions from bases classes
+// functions overriding virtual functions from base classes
//////////
/** Helper function to print a real number in a nicer way than is CLN's
ourflags.default_float_format = cln::float_format(cln::the<cln::cl_F>(num));
cln::print_real(os, ourflags, num);
}
- return;
}
/** This method adds to the output so it blends more consistently together
{
debugmsg("numeric print", LOGLEVEL_PRINT);
- if (is_of_type(c, print_tree)) {
+ if (is_a<print_tree>(c)) {
c.s << std::string(level, ' ') << cln::the<cln::cl_N>(value)
<< " (" << class_name() << ")"
<< std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
<< std::endl;
- } else if (is_of_type(c, print_csrc)) {
+ } else if (is_a<print_csrc>(c)) {
std::ios::fmtflags oldflags = c.s.flags();
c.s.setf(std::ios::scientific);
if (this->is_rational() && !this->is_integer()) {
if (compare(_num0()) > 0) {
c.s << "(";
- if (is_of_type(c, print_csrc_cl_N))
+ if (is_a<print_csrc_cl_N>(c))
c.s << "cln::cl_F(\"" << numer().evalf() << "\")";
else
c.s << numer().to_double();
} else {
c.s << "-(";
- if (is_of_type(c, print_csrc_cl_N))
+ if (is_a<print_csrc_cl_N>(c))
c.s << "cln::cl_F(\"" << -numer().evalf() << "\")";
else
c.s << -numer().to_double();
}
c.s << "/";
- if (is_of_type(c, print_csrc_cl_N))
+ if (is_a<print_csrc_cl_N>(c))
c.s << "cln::cl_F(\"" << denom().evalf() << "\")";
else
c.s << denom().to_double();
c.s << ")";
} else {
- if (is_of_type(c, print_csrc_cl_N))
+ if (is_a<print_csrc_cl_N>(c))
c.s << "cln::cl_F(\"" << evalf() << "\")";
else
c.s << to_double();
c.s.flags(oldflags);
} else {
- 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 std::string par_open = is_a<print_latex>(c) ? "{(" : "(";
+ const std::string par_close = is_a<print_latex>(c) ? ")}" : ")";
+ const std::string imag_sym = is_a<print_latex>(c) ? "i" : "I";
+ const std::string mul_sym = is_a<print_latex>(c) ? " " : "*";
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())) {
+ if ((precedence() <= level) && (!this->is_nonneg_integer())) {
c.s << par_open;
print_real_number(c.s, r);
c.s << par_close;
} else {
if (cln::zerop(r)) {
// case 2, imaginary: y*I or -y*I
- if ((precedence <= level) && (i < 0)) {
+ if ((precedence() <= level) && (i < 0)) {
if (i == -1) {
c.s << par_open+imag_sym+par_close;
} else {
}
} else {
// case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I
- if (precedence <= level)
+ if (precedence() <= level)
c.s << par_open;
print_real_number(c.s, r);
if (i < 0) {
c.s << mul_sym+imag_sym;
}
}
- if (precedence <= level)
+ if (precedence() <= level)
c.s << par_close;
}
}
{
if (!is_exactly_of_type(*other.bp, numeric))
return false;
- const numeric &o = static_cast<numeric &>(const_cast<basic &>(*other.bp));
+ const numeric &o = static_cast<const numeric &>(*other.bp);
if (this->is_equal(o) || this->is_equal(-o))
return true;
if (o.imag().is_zero()) // e.g. scan for 3 in -3*I
int numeric::compare_same_type(const basic &other) const
{
GINAC_ASSERT(is_exactly_of_type(other, numeric));
- const numeric &o = static_cast<numeric &>(const_cast<basic &>(other));
+ const numeric &o = static_cast<const numeric &>(other);
return this->compare(o);
}
bool numeric::is_equal_same_type(const basic &other) const
{
GINAC_ASSERT(is_exactly_of_type(other,numeric));
- const numeric *o = static_cast<const numeric *>(&other);
+ const numeric &o = static_cast<const numeric &>(other);
- return this->is_equal(*o);
+ return this->is_equal(o);
}
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):
return 0;
}
-
-//////////
-// static member variables
-//////////
-
-// protected
-
-unsigned numeric::precedence = 30;
-
//////////
// global constants
//////////
static std::vector< cln::cl_RA > results;
static int highest_result = 0;
// algorithm not applicable to B(0), so just store it
- if (results.size()==0)
+ if (results.empty())
results.push_back(cln::cl_RA(1));
int n = nn.to_long();
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();
}