Ticket #5498: TestBug.cc

File TestBug.cc, 1.6 KB (added by anonymous, 12 years ago)
Line 
1// TestInterval101.cpp
2//
3// Tests for Interval arithmetic.
4//
5// (C) Datasim Education BV 2009-2011
6
7#include <boost/numeric/interval.hpp>
8
9
10template<class T, class Policies>
11std::ostream &operator<<(std::ostream &os,
12 const boost::numeric::interval<T, Policies> &x) {
13 os << "[" << x.lower() << ", " << x.upper() << "]";
14 return os;
15}
16
17typedef boost::numeric::interval<double> Range;
18
19
20
21int main()
22{
23
24 using namespace boost::numeric;
25
26 // Create and manipulate some numbers.
27 Range r1(0.0, 1,0);
28
29 Range r2(-10.0, 20.0);
30 Range r3(20.8, 44.9);
31
32 double t = 2.0;
33 r1 += t; r1 -= t; r1 *= t; r1 /= t;
34
35 Range rTmp(2.0, 3.0);
36 r1 += rTmp; r1 -= rTmp; r1 *= rTmp; r1 /= rTmp;
37
38 // Numeric operations.
39 Range r4 = r1 + r2;
40 Range r5 = r1 - r2;
41 Range r6 = r1 * r2;
42 Range r7 = r1 / r2;
43
44 // More numeric operations.
45 t = 3.0;
46 r4 = r1 + t;
47 r5 = r1 - t;
48 r6 = r1 * t;
49 r7 = r1 / t;
50
51 // Algebraic functions.
52 r4 = abs(r1);
53 r5 = sqrt(r2);
54 r6 = square(r3);
55 r7 = pow(r1, 2); // r1^2
56 Range r8 = nth_root(r1, 4);
57
58 // NONE COMPILES
59 // Transcendental functions
60// r4 = exp(r1);
61// boost::numeric::interval<double, boost::numeric::interval_lib::default_policies<double> > myI;
62// myI = boost::numeric::exp(myI);
63 //r5 = log(r2);
64
65 // Trigonometric functions
66/* r4 = sin(r1);
67 r5 = cos(r1);
68 r6 = tan(r1);
69 r7 = asin(r2);
70 r7 = acos(r2);
71 r7 = atan(r2);
72
73 // Hyperbolic trigonometric functions
74 r4 = sinh(r1);
75 r5 = cosh(r1);
76 r6 = tanh(r1);
77 r7 = asinh(r2);
78 r8 = acosh(r2);
79 r6 = atanh(r2);*/
80
81
82
83
84 return 0;
85}