// TestInterval101.cpp // // Tests for Interval arithmetic. // // (C) Datasim Education BV 2009-2011 #include template std::ostream &operator<<(std::ostream &os, const boost::numeric::interval &x) { os << "[" << x.lower() << ", " << x.upper() << "]"; return os; } typedef boost::numeric::interval Range; int main() { using namespace boost::numeric; // Create and manipulate some numbers. Range r1(0.0, 1,0); Range r2(-10.0, 20.0); Range r3(20.8, 44.9); double t = 2.0; r1 += t; r1 -= t; r1 *= t; r1 /= t; Range rTmp(2.0, 3.0); r1 += rTmp; r1 -= rTmp; r1 *= rTmp; r1 /= rTmp; // Numeric operations. Range r4 = r1 + r2; Range r5 = r1 - r2; Range r6 = r1 * r2; Range r7 = r1 / r2; // More numeric operations. t = 3.0; r4 = r1 + t; r5 = r1 - t; r6 = r1 * t; r7 = r1 / t; // Algebraic functions. r4 = abs(r1); r5 = sqrt(r2); r6 = square(r3); r7 = pow(r1, 2); // r1^2 Range r8 = nth_root(r1, 4); // NONE COMPILES // Transcendental functions // r4 = exp(r1); // boost::numeric::interval > myI; // myI = boost::numeric::exp(myI); //r5 = log(r2); // Trigonometric functions /* r4 = sin(r1); r5 = cos(r1); r6 = tan(r1); r7 = asin(r2); r7 = acos(r2); r7 = atan(r2); // Hyperbolic trigonometric functions r4 = sinh(r1); r5 = cosh(r1); r6 = tanh(r1); r7 = asinh(r2); r8 = acosh(r2); r6 = atanh(r2);*/ return 0; }