the compiler from Portland Group.
unsigned int ret = 0;
unsigned int shift = 0;
do {
- is.get(b);
+ char b2;
+ is.get(b2);
+ b = b2;
ret |= (b & 0x7f) << shift;
shift += 7;
} while (b & 0x80);
#include <string>
#include <vector>
-
-namespace std {
- class ostream;
- class istream;
-}
+#include <iostream>
#ifndef NO_NAMESPACE_GINAC
namespace GiNaC {
#else
;
#endif // def INLINE_BASIC_CONSTRUCTORS
-
- virtual const basic & operator=(const basic & other);
+
+ const basic & operator=(const basic & other);
protected:
void copy(const basic & other)
GINAC_ASSERT(other.bp!=0);
GINAC_ASSERT(other.bp->flags & status_flags::dynallocated);
++other.bp->refcount;
- basic * tmpbp=other.bp;
- if (--bp->refcount==0) {
- delete bp;
- }
- bp=tmpbp;
+ basic * tmpbp = other.bp;
+ if (--bp->refcount==0)
+ delete bp;
+ bp = tmpbp;
return *this;
}
--bp->refcount;
bp = bp2;
}
- GINAC_ASSERT(bp->refcount == 1);
+ GINAC_ASSERT(bp->refcount==1);
}
void ex::construct_from_basic(const basic & other)
bp->setflag(status_flags::dynallocated);
++bp->refcount;
GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount=1);
+ GINAC_ASSERT(bp->refcount==1);
}
}
void ex::construct_from_uint(unsigned int i)
{
switch (i) { // some tiny efficiency-hack
- case -2:
- bp = _ex_2().bp;
- ++bp->refcount;
- break;
- case -1:
- bp = _ex_1().bp;
- ++bp->refcount;
- break;
case 0:
bp = _ex0().bp;
++bp->refcount;
bp->setflag(status_flags::dynallocated);
++bp->refcount;
GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount=1);
+ GINAC_ASSERT(bp->refcount==1);
}
}
bp->setflag(status_flags::dynallocated);
++bp->refcount;
GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount=1);
+ GINAC_ASSERT(bp->refcount==1);
}
}
void ex::construct_from_ulong(unsigned long i)
{
switch (i) { // some tiny efficiency-hack
- case -2:
- bp = _ex_2().bp;
- ++bp->refcount;
- break;
- case -1:
- bp = _ex_1().bp;
- ++bp->refcount;
- break;
case 0:
bp = _ex0().bp;
++bp->refcount;
bp->setflag(status_flags::dynallocated);
++bp->refcount;
GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount=1);
+ GINAC_ASSERT(bp->refcount==1);
}
}
bp->setflag(status_flags::dynallocated);
++bp->refcount;
GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
- GINAC_ASSERT(bp->refcount=1);
+ GINAC_ASSERT(bp->refcount==1);
}
void ex::construct_from_string_and_lst(const std::string &s, const ex &l)
#include <algorithm>
#include <string>
#include <stdexcept>
-#include <cmath>
#include "expairseq.h"
#include "lst.h"
<<'END_OF_EVALF_SWITCH_STATEMENT','eseq[${N}-1]','');
case ${N}:
return ((evalf_funcp_${N})(registered_functions()[serial].evalf_f))(${SEQ1});
- break;
END_OF_EVALF_SWITCH_STATEMENT
$diff_switch_statement=generate(
<<'END_OF_DIFF_SWITCH_STATEMENT','seq[${N}-1]','');
case ${N}:
return ((derivative_funcp_${N})(registered_functions()[serial].derivative_f))(${SEQ1},diff_param);
- break;
END_OF_DIFF_SWITCH_STATEMENT
$series_switch_statement=generate(
res = basic::series(r, order, options);
}
return res;
- break;
END_OF_SERIES_SWITCH_STATEMENT
$eval_func_implementation=generate(
/** Implementation of ex::series for functions.
* \@see ex::series */
-ex function::series(const relational & r, int order, unsigned options = 0) const
+ex function::series(const relational & r, int order, unsigned options) const
{
GINAC_ASSERT(serial<registered_functions().size());
GINAC_ASSERT(serial<registered_functions().size());
if (registered_functions()[serial].derivative_f==0) {
- return Derivative(*this, lst(diff_param));
+ return Derivative(*this, lst(ex(diff_param)));
}
switch (registered_functions()[serial].nparams) {
// the following lines have been generated for max. ${maxargs} parameters
if (i == syms.end()) {
syms[yytext] = sym_def(ginac_yylval = *(new symbol(yytext)), false);
} else
- ginac_yylval = i->second.sym;
+ ginac_yylval = (*i).second.sym;
return T_SYMBOL;
}
if (i == syms.end())
return false;
else
- return i->second.predefined;
+ return (*i).second.predefined;
}
#ifndef NO_NAMESPACE_GINAC
* @exception range_error (index out of range) */
const ex & matrix::operator() (unsigned ro, unsigned co) const
{
- if (ro<0 || ro>=row || co<0 || co>=col)
+ if (ro>=row || co>=col)
throw (std::range_error("matrix::operator(): index out of range"));
return m[ro*col+co];
* @exception range_error (index out of range) */
matrix & matrix::set(unsigned ro, unsigned co, ex value)
{
- if (ro<0 || ro>=row || co<0 || co>=col)
+ if (ro>=row || co>=col)
throw (std::range_error("matrix::set(): index out of range"));
-
+
ensure_if_modifiable();
m[ro*col+co] = value;
return *this;
void ncmul::printraw(std::ostream & os) const
{
debugmsg("ncmul printraw",LOGLEVEL_PRINT);
-
os << "%(";
for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
(*it).bp->printraw(os);
os << ")";
}
-void ncmul::printcsrc(std::ostream & os, unsigned upper_precedence) const
+void ncmul::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
{
debugmsg("ncmul print csrc",LOGLEVEL_PRINT);
exvector::const_iterator it;
basic * duplicate() const;
void print(std::ostream & os, unsigned upper_precedence) const;
void printraw(std::ostream & os) const;
- void printcsrc(std::ostream & os, unsigned upper_precedence) const;
+ void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
bool info(unsigned inf) const;
int degree(const symbol & s) const;
int ldegree(const symbol & s) const;
status_flags::hash_calculated);
}
-
/** ctor from C-style string. It also accepts complex numbers in GiNaC
* notation like "2+5*I". */
numeric::numeric(const char *s) : basic(TINFO_numeric)
bool imaginary = false;
delim = ss.find_first_of(std::string("+-"),1);
// Do we have an exponent marker like "31.415E-1"? If so, hop on!
- if (delim != std::string::npos
- && ss.at(delim-1) == 'E')
+ if ((delim != std::string::npos) && (ss.at(delim-1) == 'E'))
delim = ss.find_first_of(std::string("+-"),delim+1);
term = ss.substr(0,delim);
if (delim != std::string::npos)
} while(delim != std::string::npos);
calchash();
setflag(status_flags::evaluated |
- status_flags::hash_calculated);
+ status_flags::expanded |
+ status_flags::hash_calculated);
}
/** Ctor from CLN types. This is for the initiated user or internal use
if (this->is_real() && other.is_real())
return (The(::cl_R)(*value) < The(::cl_R)(*other.value)); // -> CLN
throw std::invalid_argument("numeric::operator<(): complex inequality");
- return false; // make compiler shut up
}
/** Numerical comparison: less or equal.
if (this->is_real() && other.is_real())
return (The(::cl_R)(*value) > The(::cl_R)(*other.value)); // -> CLN
throw std::invalid_argument("numeric::operator>(): complex inequality");
- return false; // make compiler shut up
}
/** Numerical comparison: greater or equal.
if (this->is_real() && other.is_real())
return (The(::cl_R)(*value) >= The(::cl_R)(*other.value)); // -> CLN
throw std::invalid_argument("numeric::operator>=(): complex inequality");
- return false; // make compiler shut up
}
/** Converts numeric types to machine's int. You should check with
numeric smod(const numeric & a, const numeric & b)
{
if (a.is_integer() && b.is_integer()) {
- cl_I b2 = The(::cl_I)(ceiling1(The(::cl_I)(*b.value) / 2)) - 1;
+ cl_I b2 = The(::cl_I)(ceiling1(The(::cl_I)(*b.value) >> 1)) - 1;
return ::mod(The(::cl_I)(*a.value) + b2, The(::cl_I)(*b.value)) - b2;
} else
return _num0(); // Throw?
ex relational::evalf(int level) const
{
- if (level==1) {
+ if (level==1)
return *this;
- }
- if (level == -max_recursion_level) {
+
+ if (level==-max_recursion_level)
throw(std::runtime_error("max recursion level reached"));
- }
+
return (new relational(lh.eval(level-1),rh.eval(level-1),o))->setflag(status_flags::dynallocated);
}
int cmpval;
if (o == oth.o) {
- cmpval=lh.compare(oth.lh);
- if (cmpval==0) {
+ cmpval = lh.compare(oth.lh);
+ if (cmpval==0)
return rh.compare(oth.rh);
- } else {
+ else
return cmpval;
- }
}
- if (o<oth.o) {
+ if (o<oth.o)
return -1;
- } else {
+ else
return 1;
- }
}
unsigned relational::return_type(void) const
// please note that (a<b) == false does not imply (a>=b) == true
// a false result means the comparison is either false or undecidable
// (except for !=, where true means unequal or undecidable)
- ex df=lh-rh;
- if (!is_ex_exactly_of_type(df,numeric)) {
- return o==not_equal ? true : false; // cannot decide on non-numerical results
- }
- int cmpval=ex_to_numeric(df).compare(_num0());
+ ex df = lh-rh;
+ if (!is_ex_exactly_of_type(df,numeric))
+ // cannot decide on non-numerical results
+ return o==not_equal ? true : false;
+
+ int cmpval = ex_to_numeric(df).compare(_num0());
switch (o) {
case equal:
return cmpval==0;
- break;
case not_equal:
return cmpval!=0;
- break;
case less:
return cmpval<0;
- break;
case less_or_equal:
return cmpval<=0;
- break;
case greater:
return cmpval>0;
- break;
case greater_or_equal:
return cmpval>=0;
- break;
default:
throw(std::logic_error("invalid relational operator"));
}
- return 0;
}
//////////
#include <stdexcept>
#include "function.h"
-#include "utils.h" // for log_2
+#include "utils.h"
#include "remember.h"
#ifndef NO_NAMESPACE_GINAC
remember_table_entry::remember_table_entry(function const & f, ex const & r)
: hashvalue(f.gethash()), seq(f.seq), result(r)
{
- ++last_access=access_counter;
- successful_hits=0;
+ ++last_access = access_counter;
+ successful_hits = 0;
}
bool remember_table_entry::is_equal(function const & f) const
{
GINAC_ASSERT(f.seq.size()==seq.size());
if (f.gethash()!=hashvalue) return false;
- for (unsigned i=0; i<seq.size(); ++i) {
+ for (unsigned i=0; i<seq.size(); ++i)
if (!seq[i].is_equal(f.seq[i])) return false;
- }
- ++last_access=access_counter;
+ ++last_access = access_counter;
++successful_hits;
return true;
}
remember_table_list::remember_table_list(unsigned as, unsigned strat)
{
- max_assoc_size=as;
- remember_strategy=strat;
+ max_assoc_size = as;
+ remember_strategy = strat;
}
(size()>=max_assoc_size)) {
// table is full, we must delete an older entry
GINAC_ASSERT(size()>0); // there must be at least one entry
-
+
switch (remember_strategy) {
- case remember_strategies::delete_cyclic:
+ case remember_strategies::delete_cyclic: {
// delete oldest entry (first in list)
erase(begin());
break;
- case remember_strategies::delete_lru:
- {
- // delete least recently used entry
- iterator it=begin();
- iterator lowest_access_it=it;
- unsigned long lowest_access=it->get_last_access();
- ++it;
- while (it!=end()) {
- if (it->get_last_access()<lowest_access) {
- lowest_access=it->get_last_access();
- lowest_access_it=it;
- }
- ++it;
+ }
+ case remember_strategies::delete_lru: {
+ // delete least recently used entry
+ iterator it = begin();
+ iterator lowest_access_it = it;
+ unsigned long lowest_access = (*it).get_last_access();
+ ++it;
+ while (it!=end()) {
+ if ((*it).get_last_access()<lowest_access) {
+ lowest_access = (*it).get_last_access();
+ lowest_access_it = it;
}
- erase(lowest_access_it);
+ ++it;
}
+ erase(lowest_access_it);
break;
- case remember_strategies::delete_lfu:
- {
- // delete least frequently used entry
- iterator it=begin();
- iterator lowest_hits_it=it;
- unsigned lowest_hits=it->get_successful_hits();
- ++it;
- while (it!=end()) {
- if (it->get_successful_hits()<lowest_hits) {
- lowest_hits=it->get_successful_hits();
- lowest_hits_it=it;
- }
- ++it;
+ }
+ case remember_strategies::delete_lfu: {
+ // delete least frequently used entry
+ iterator it = begin();
+ iterator lowest_hits_it = it;
+ unsigned lowest_hits = (*it).get_successful_hits();
+ ++it;
+ while (it!=end()) {
+ if ((*it).get_successful_hits()<lowest_hits) {
+ lowest_hits = (*it).get_successful_hits();
+ lowest_hits_it = it;
}
- erase(lowest_hits_it);
+ ++it;
}
+ erase(lowest_hits_it);
break;
+ }
default:
throw(std::logic_error("remember_table_list::add_entry(): invalid remember_strategy"));
- }
+ }
GINAC_ASSERT(size()==max_assoc_size-1);
}
push_back(remember_table_entry(f,result));
-}
+}
bool remember_table_list::lookup_entry(function const & f, ex & result) const
{
for (const_iterator cit=begin(); cit!=end(); ++cit) {
- if (cit->is_equal(f)) {
- result=cit->get_result();
+ if ((*cit).is_equal(f)) {
+ result = (*cit).get_result();
return true;
}
}
// all entries
// use some power of 2 next to s
- table_size=1 << log2(s);
+ table_size = 1 << log2(s);
init_table();
}
bool remember_table::lookup_entry(function const & f, ex & result) const
{
- unsigned entry=f.gethash() & (table_size-1);
+ unsigned entry = f.gethash() & (table_size-1);
GINAC_ASSERT(entry<size());
return operator[](entry).lookup_entry(f,result);
}
void remember_table::add_entry(function const & f, ex const & result)
{
- unsigned entry=f.gethash() & (table_size-1);
+ unsigned entry = f.gethash() & (table_size-1);
GINAC_ASSERT(entry<size());
operator[](entry).add_entry(f,result);
}
void remember_table::init_table(void)
{
reserve(table_size);
- for (unsigned i=0; i<table_size; ++i) {
+ for (unsigned i=0; i<table_size; ++i)
push_back(remember_table_list(max_assoc_size,remember_strategy));
- }
}
std::vector<remember_table> & remember_table::remember_tables(void)
ex scalar_products::evaluate(const simp_lor & v1, const simp_lor & v2) const
{
- if (v1.compare_same_type(v2)>0) {
- return evaluate(v2,v1);
- }
- return spm.find(make_key(v1,v2))->second;
+ if (v1.compare_same_type(v2)>0)
+ return evaluate(v2, v1);
+
+ return (*spm.find(make_key(v1,v2))).second;
}
void scalar_products::debugprint(void) const
// wrapper functions around member functions
inline void unassign(symbol & symarg)
-{ return symarg.unassign(); }
+{ symarg.unassign(); }
inline int degree(const symbol & a, const symbol & s)
{ return a.degree(s); }