本文整理汇总了C++中rational类的典型用法代码示例。如果您正苦于以下问题:C++ rational类的具体用法?C++ rational怎么用?C++ rational使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rational类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assign
void assign(contains_app & x,expr * fml,const rational & v) {
SASSERT(v.is_unsigned());
eq_atoms& eqs = get_eqs(x.x(), fml);
unsigned uv = v.get_unsigned();
uint64 domain_size;
if (is_small_domain(x, eqs, domain_size)) {
SASSERT(v < rational(domain_size, rational::ui64()));
assign_small_domain(x, eqs, uv);
}
else {
assign_large_domain(x, eqs, uv);
}
}
示例2: is_target_core
bool is_target_core(expr * n, rational & u) {
if (!is_uninterp_const(n))
return false;
rational l; bool s;
if (m_bm.has_lower(n, l, s) &&
m_bm.has_upper(n, u, s) &&
l.is_zero() &&
!u.is_neg() &&
u.get_num_bits() <= m_max_bits) {
return true;
}
return false;
}
示例3: subst
void subst(contains_app & x,const rational & v,expr_ref & fml, expr_ref* def) {
SASSERT(v.is_unsigned());
eq_atoms& eqs = get_eqs(x.x(), fml);
unsigned uv = v.get_unsigned();
uint64 domain_size;
if (is_small_domain(x, eqs, domain_size)) {
SASSERT(uv < domain_size);
subst_small_domain(x, eqs, uv, fml);
}
else {
subst_large_domain(x, eqs, uv, fml);
}
if (def) {
*def = 0; // TBD
}
}
示例4: is_target
bool is_target(expr * var, rational & val) {
bool strict;
return
is_uninterp_const(var) &&
(!m_normalize_int_only || m_util.is_int(var)) &&
m_bm.has_lower(var, val, strict) &&
!val.is_zero();
}
示例5: squareRoot
// **** 1.Add a square root function to the rational class. ****
rational squareRoot(const rational &r)
{
assert(r.numerator()>0);
double top = r.numerator();
double bot = r.denominator();
double topSqrt = sqrt(top);
double botSqrt = sqrt(bot);
// Estimate if not a perfect square
if ((fmod(topSqrt,1)!=0) ||(fmod(botSqrt,1)!=0))
{
topSqrt = sqrt(100*top);
botSqrt = sqrt(100*bot);
}
return rational((int)topSqrt, (int)botSqrt);
}
示例6: is_diff_term
bool static_features::is_diff_term(expr const * e, rational & r) const {
// lhs can be 'x' or '(+ k x)'
if (!is_arith_expr(e)) {
r.reset();
return true;
}
if (is_numeral(e, r))
return true;
return m_autil.is_add(e) && to_app(e)->get_num_args() == 2 && is_numeral(to_app(e)->get_arg(0), r) && !is_arith_expr(to_app(e)->get_arg(1));
}
示例7: print
void print(rational a){
if(a.get_chisl()==0)std::cout<<"\n 0 ";else{
if(a.get_chisl()==a.get_znam())std::cout<<"\n 1";else{
if(a.get_znam()==1)std::cout<<"\n "<<a.get_chisl();else{
std::cout<<"\n "<<a.get_chisl()<<"/"<<a.get_znam();
}
}
}
}
示例8: default_exception
unsigned context::scoped_state::add(expr* f, rational const& w, symbol const& id) {
if (w.is_neg()) {
throw default_exception("Negative weight supplied. Weight should be positive");
}
if (w.is_zero()) {
throw default_exception("Zero weight supplied. Weight should be positive");
}
if (!m.is_bool(f)) {
throw default_exception("Soft constraint should be Boolean");
}
if (!m_indices.contains(id)) {
m_objectives.push_back(objective(m, id));
m_indices.insert(id, m_objectives.size() - 1);
}
SASSERT(m_indices.contains(id));
unsigned idx = m_indices[id];
m_objectives[idx].m_terms.push_back(f);
m_objectives[idx].m_weights.push_back(w);
m_objectives_term_trail.push_back(idx);
return idx;
}
示例9: result
rational operator - (const rational &left, const rational &right)
{
rational result(
left.numerator() * right.denominator() -
right.numerator() * left.denominator(),
left.denominator() * right.denominator());
return result;
}
示例10: main
int main()
{
int shift = 20;
hashset hset;
hashset::iterator iter;
i64 mup = (1LL<<(2*shift))-1;
i64 mdown = (1LL<<shift)-1;
mup -= mdown;
vector<rational> vr;
for(int di = 2; di <= 35; ++di)
for(int ni = 1; ni < di; ++ni){
int common = gcd(ni, di);
if(common> 1) continue;
vr.push_back(rational(ni, di));
}
sort(vr.begin(), vr.end());
for(unsigned int i = 0; i < vr.size(); ++i){
for(unsigned int j = i; j < vr.size(); ++j){
rational& r1 = vr[i];
rational& r2 = vr[j];
const rational xr = r1 + r2;
//x+y=z
if(xr.pnum() >= xr.pden()) break;
if(xr.pden() <= 35){
rational xr2 = xr + xr;
i64 value = (xr2.pden()<<shift)+(xr2.pnum());
assert(((value & mup)>>shift) == xr2.pden());
assert((value & mdown) == xr2.pnum());
iter = hset.find(value);
if(iter == hset.end()){
hset.insert(value);
//printf("a %lld %lld %lld %lld %lld %lld %lld %lld\n", r1.pnum(), r1.pden(),
// r2.pnum(), r2.pden(), xr.pnum(), xr.pden(), xr2.pnum(), xr2.pden());
}
}
}
}
示例11: pow
sym pow(const sym &s,const rational &q) {
if(typeid(*s.expr)==typeid(sym::sym_num))
return sym(pow(((sym::sym_num *)s.expr)->value,q.eval()));
sym snew;
snew.context=s.check_context();
delete snew.expr;
snew.expr=s.expr->clone();
snew.expr=snew.expr->pow(q)->reduce();
return snew;
}
示例12: rational
BOOST_CONSTEXPR explicit
rational(rational<NewType> const &r)
: num(r.numerator()), den(is_normalized(int_type(r.numerator()),
int_type(r.denominator())) ? r.denominator() :
(BOOST_THROW_EXCEPTION(bad_rational("bad rational: denormalized conversion")), 0)){}
示例13:
bool operator==(const rational<T2> &f) const
{
return ((this->_numerator == f.numerator()) &&
(this->_denominator == f.denominator()));
}
示例14:
sym::sym(const rational &q) {
context=NULL;
expr=new sym::sym_num(q.eval());
}
示例15: rational
rational rational::operator /(const rational& second) const {
return rational(getNum() * second.getDenom(), getDenom() * second.getNum());
}