Boost logo

Boost Users :

From: james.jones_at_[hidden]
Date: 2006-08-18 12:05:21


From: Minkoo Seo <minkoo.seo_at_[hidden]>
[code snipped]
> for (unsigned i = 0; i < 3; i++)
> m(i, i) = -i;
>
> In this code, I'm trying to initialize the diagonal with
> -1, -2, -3. But, the result is obviously different from
> what I expected:
>
> [3,3]((0,0,0),(0,4.29497e+09,0),(0,0,4.29497e+09))

If you must use unsigned, then change to:

m(i, i) = -1.0 * static_cast<double>(i);

What it's doing now is this:

i = 1;
-i = 4294967295; // it's unsigned, after all
double(-i) = 4.295e+9

Probably clearer to use int instead of unsigned, though.

-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net