Can i do this

(a,a?) <- (a?, a-qa?)
(u, u?, v, v?) <- (u?,u-qu?,v?,v-qv?)


Like this in C++  ???

a=ap+(0*(ap=a-q*ap));
u=up+(0*(up=u-q*up)*(v=vp)*(vp=v-q*vp));


because the result is bad and i don't know if it's my mistake or the algo is wrong.
Posted on 2005-06-14 12:50:30 by AceEmbler

Can i do this

(a,a?) <- (a?, a-qa?)
(u, u?, v, v?) <- (u?,u-qu?,v?,v-qv?)


Like this in C++  ???

a=ap+(0*(ap=a-q*ap));
u=up+(0*(up=u-q*up)*(v=vp)*(vp=v-q*vp));



No. In this case, the order of evaluation of the operands is unspecified.


because the result is bad and i don't know if it's my mistake or the algo is wrong.


Huh?
You're supposed to be sure about an algorithm's correctness before implementing it.
You should write the simplest expressions possible if you're unsure about the correctness of more complex expressions.
Posted on 2005-06-14 14:33:04 by death
Eek, assignments as expressions!!! :shock:

Try something like this:


int olda = a;
int oldu = u;
int oldv = v;
a = ap;
u = up;
v = uv;
ap = olda - q*ap;
up = oldu - q*up;
vp = oldv - q*vp;


Not too elegant but sure to work... :|
Posted on 2005-06-14 14:39:39 by QvasiModo

Eek, assignments as expressions!!! :shock:

Try something like this:


int olda = a;
int oldu = u;
int oldv = v;
a = ap;
u = up;
v = uv;
ap = olda - q*ap;
up = oldu - q*up;
vp = oldv - q*vp;


Not too elegant but sure to work... :|


I know i can do it that way. But i hate this temporary variables. It's strange that they didn't implement something helpful for such a problem in c++ language  :sad:
Posted on 2005-06-14 15:28:16 by AceEmbler

I know i can do it that way. But i hate this temporary variables. It's strange that they didn't implement something helpful for such a problem in c++ language  :sad:


The code is simple and the meaning is clear.. That's as helpful as it gets.
Posted on 2005-06-14 15:50:29 by death

Not too elegant but sure to work... :|


How about:


template<typename T, typename U, typename V>
void foo(T & a, U & ap, V q)
{
    T t(a);
    a = ap;
    ap = t - q * ap;
}

foo(a, ap, q);
foo(u, up, q);
foo(v, vp, q);


(it's a template because I don't know the types)

A bit more elegant, I'd think.
Posted on 2005-06-14 16:07:45 by death