
Boost : 
From: Paul A. Bristow (boost_at_[hidden])
Date: 20030411 06:20:05
In sucessfully using intervals with Stats code from Neal Becker, I had some
minor dificulties:
1 abs
It took me some fumbling to see that I needed
using namespace boost::numeric; // BEFORE
#include "stats.hpp"
In doing do, I found that
typedef boost::numeric::interval<double> I;
I x = 2.;
I x = boost::numeric::abs(x);
works as expected, but I was puzzled that
using boost::numeric::abs;
T absx = abs(x); // failed (with MSVC 7.0) because interval policies not found.
I absx = boost::numeric::abs< boost::numeric::interval<double> >(x);
testInterval.cpp(96) : error C2783: 'boost::numeric::interval<T,Policies>
boost::numeric::abs(const boost::numeric::interval<T,Policies> &)'
: could not deduce template argument for 'Policies'
or
I absx = abs(x);
testInterval.cpp(96) : error C2664: 'abs' : cannot convert parameter 1 from 'I'
to 'int'
No userdefinedconversion operator available that can perform this
conversion, or the operator cannot be called
2 I found several places where expressions like T mean/integer count failed
when T was an interval type. This is because there is no conversion from
integer, though there is from double etc. writing mean/T(count) works OK.
I half_x = x/2; // fails
I half_x = x/2.0; // OK
I half_x = x/ I(2); // OK
This is a very common situation and would be helpful to avoid widespread changes
to existing code  but perhaps this is an exercise for the student :)
3 I found
using boost::numeric::pow;
x1 = pow(x, 2); // multiplicative_inverse undeclared in arith2.hpp
required addition of explicit interval_lib::
return interval_lib::multiplicative_inverse(pow(x, pwr));
// return multiplicative_inverse(pow(x, pwr)); // was
4 x1 = exp(x); // fails  exp_up and exp_down not a member ...
I:/boost_1_30_0\boost\numeric\interval\transc.hpp(39) : error C2039: 'exp_up' :
is not a member of 'boost::numeric::interval_lib::rounded_math<T>'
with
[
T=double
]
I:/boost_1_30_0\boost\numeric\interval\hw_rounding.hpp(50) : see
declaration of 'boost::numeric::interval_lib::rounded_math<T>'
with
[
T=double
]
5 similarly with log_up and log_down.
6 Using interval pi I was puzzled that:
using boost::numeric::interval_lib::pi< boost::numeric::interval<double> >; //
triggers compile fail at pi<I>()
using boost::numeric::interval_lib::pi; // illegal use of expression
I pi_d = pi<I>();
whereas
using namespace boost::numeric::interval_lib;
I pi_d = pi<I>();
and
I pi_d = boost::numeric::interval_lib::pi< boost::numeric::interval<double>
>();
are fine.
But overall I hope this shows a reallife use of interval arithmetic which I
believe has considerable potential usefulness.
Thanks
Paul
> Original Message
> From: boostbounces_at_[hidden]
> [mailto:boostbounces_at_[hidden]]On Behalf Of Paul A. Bristow
> Sent: Thursday, April 10, 2003 3:30 PM
> To: Boost mailing list
> Subject: RE: [boost] Statistics code example
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk