Boost logo

Boost :

From: Julius Muschaweck (muschaweck_at_[hidden])
Date: 2003-01-14 04:15:32


Hi,

this is my first posting, so please give me guidance if this is going into
the wrong direction.

I'm using ublas (with Visual Studio .NET) , and I like it a lot.
However, in scalar * vector operations, ublas doesn't handle implicit int -
double conversions like the compiler, which resulted in a hard to trace bug
for me:

        using namespace boost::numeric::ublas;
        vector<double> v(3);
        v[0] = 1.1;
        v[1] = 2.2;
        v[2] = 3.7;
        vector<double> v2;
        v2 = 2.0 * v; // double times vector
        std::cout << v2 << std::endl;
        v2 = 2 * v; // integer times vector
        std::cout << v2 << std::endl; //oops
        std::cout << 2*3.7 << ' ' << 2.0 * 3.7 << std::endl;

produces

        (2.2,4.4,7.4)
        (2.,4.,7.)
        7.4 7.4

What seems to happen is that ublas first rounds the doubles in v to ints,
performs integer multiplication and then converts the result back to
double, whereas the compiler converts an int to double and then performs
floating point multiplication.

It's maybe not good style to rely on implicit conversions like this, but
I'm surely not the only one.

My opinion is that ublas should do int*vector<double> like the compiler
does int*double, or am I missing a reason why this is intended?

Julius Muschaweck


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk