Exemplo n.º 1
0
 interval interval_relation_plugin::widen(interval const& src1, interval const& src2) {
     bool l_open = src1.is_lower_open();
     bool r_open = src1.is_upper_open();
     ext_numeral low = src1.inf();
     ext_numeral high = src1.sup();
     
     if (src2.inf() < low || (low == src2.inf() && l_open && !src2.is_lower_open())) {
         low = ext_numeral(false);
         l_open = true;
     }
     if (high < src2.sup() || (src2.sup() == high && !r_open && src2.is_upper_open())) {
         high = ext_numeral(true);
         r_open = true;
     }
     return interval(dep(), low, l_open, nullptr, high, r_open, nullptr);
 }
Exemplo n.º 2
0
/**
   \brief Create intervals (-oo, val], (-oo, val), [val, oo), (val, oo)
*/
interval::interval(v_dependency_manager & m, rational const & val, bool open, bool lower, v_dependency * d):
    m_manager(m) {
    if (lower) {
        m_lower      = ext_numeral(val);
        m_lower_open = open;
        m_lower_dep  = d;
        m_upper      = ext_numeral(true);
        m_upper_open = true;
        m_upper_dep  = 0;
    }
    else {
        m_lower      = ext_numeral(false);
        m_lower_open = true;
        m_lower_dep  = 0;
        m_upper      = ext_numeral(val);
        m_upper_open = open;
        m_upper_dep  = d;
    }
}
Exemplo n.º 3
0
static void tst1() {
    ext_numeral inf(true);
    ext_numeral minus_inf(false);
    ext_numeral zero(0);

    SASSERT(ext_numeral(10) + ext_numeral(3) == ext_numeral(13));
    SASSERT(inf + zero == inf);
    SASSERT(minus_inf + zero == minus_inf);
    SASSERT(minus_inf + ext_numeral(3) == minus_inf);
    SASSERT(inf + inf == inf);
    SASSERT(minus_inf + minus_inf == minus_inf);
    SASSERT(minus_inf + ext_numeral(10) == minus_inf);
    SASSERT(minus_inf + ext_numeral(-10) == minus_inf);
    SASSERT(inf + ext_numeral(10) == inf);
    SASSERT(inf + ext_numeral(-10) == inf);

    SASSERT(ext_numeral(10) - ext_numeral(3) == ext_numeral(7));
    SASSERT(inf - zero == inf);
    SASSERT(minus_inf - zero == minus_inf);
    SASSERT(minus_inf - ext_numeral(3) == minus_inf);
    SASSERT(inf - minus_inf == inf);
    SASSERT(minus_inf - inf == minus_inf);
    SASSERT(zero - minus_inf == inf);
    SASSERT(zero - inf == minus_inf);
    SASSERT(ext_numeral(-10) - minus_inf == inf);
    SASSERT(ext_numeral(10) - minus_inf == inf);
    SASSERT(ext_numeral(-10) - inf == minus_inf);
    SASSERT(ext_numeral(10) - inf == minus_inf);

    SASSERT(ext_numeral(10) * inf == inf);
    SASSERT(ext_numeral(-10) * inf == minus_inf);
    SASSERT(zero * inf == zero);
    SASSERT(zero * minus_inf == zero);
    SASSERT(zero * ext_numeral(10) == zero);
    SASSERT(ext_numeral(10) * ext_numeral(-20) == ext_numeral(-200));
    SASSERT(ext_numeral(3) * ext_numeral(2) == ext_numeral(6));
    SASSERT(inf * inf == inf);
    SASSERT(inf * minus_inf == minus_inf);
    SASSERT(minus_inf * minus_inf == inf);
    SASSERT(minus_inf * inf == minus_inf);
    SASSERT(minus_inf * ext_numeral(10) == minus_inf);
    SASSERT(minus_inf * ext_numeral(-10) == inf);

    SASSERT(minus_inf < inf);
    SASSERT(!(inf < minus_inf));
    SASSERT(minus_inf < ext_numeral(10));
    SASSERT(ext_numeral(-3) < inf);
    SASSERT(ext_numeral(-10) < ext_numeral(4));
    SASSERT(ext_numeral(2) < ext_numeral(10));
    SASSERT(!(inf < ext_numeral(30)));
    SASSERT(!(ext_numeral(10) < minus_inf));
    SASSERT(!(inf < inf));
    SASSERT(!(minus_inf < minus_inf));
    SASSERT(!(zero < zero));
    SASSERT(!(ext_numeral(10) < ext_numeral(10)));
    SASSERT(inf > minus_inf);
    SASSERT(inf > zero);
    SASSERT(inf > ext_numeral(10));
    SASSERT(ext_numeral(10) > minus_inf);
    SASSERT(zero > minus_inf);
    SASSERT(!(zero > inf));
    SASSERT(!(minus_inf > inf));
    SASSERT(inf >= minus_inf);
    SASSERT(inf >= inf);
    SASSERT(minus_inf >= minus_inf);
    SASSERT(inf >= zero);
    SASSERT(zero >= minus_inf);
    SASSERT(inf <= inf);
    SASSERT(minus_inf <= minus_inf);
    SASSERT(zero <= inf);
    SASSERT(minus_inf <= zero);

    ext_numeral val(10);
    val.neg();
    SASSERT(val == ext_numeral(-10));
    val = inf;
    val.neg();
    SASSERT(val == minus_inf);
    val.neg();
    SASSERT(val == inf);

    SASSERT(minus_inf.sign());
    SASSERT(!zero.sign());
    SASSERT(!inf.sign());
    SASSERT(ext_numeral(-10).sign());
    SASSERT(!ext_numeral(10).sign());
    
    SASSERT(inf.is_infinite());
    SASSERT(minus_inf.is_infinite());
    SASSERT(!zero.is_infinite());
    SASSERT(!ext_numeral(10).is_infinite());
    SASSERT(!inf.is_zero());
    SASSERT(!minus_inf.is_zero());
    SASSERT(zero.is_zero());
    SASSERT(!ext_numeral(10).is_zero());
}