Hello all,

Ive got a weird bug somewhere and have run out of clues as to how to track it down. I was adding some math routines to a library and when I started testing them, I got a strange behavior and not sure what it could be for EX:

where I point out thats how the alg was originally, when it jumps into the division routine the values of val and current have changed (and it jumps straight from there to the division), so I changed it to see if I could figure out what was causing it.Code:MiniDec^ Sqr(MiniDec^ _val){ . . . while(_iterations<_runs){ _current=_current+(_val/_current); <------this is how the alg was originally _iterations+=1; } the alg now looks like this while(_iterations<_runs){ _temp=gcnew MiniDec(_current); <-----on the first run through _current=1 _temp=_val/_temp; _temp=_temp+_current; _current=_temp; _iterations+=1; }

As I pointed out above on the first run through _current=1 (this is not how it will run when finished, I just wanted it in a consistent state for debugging). And I know its value is 1 because I checked it in the ide before it went to the MiniDec ctor

the division routine:

MiniDec ctor:Code:static MiniDec^ operator/(MiniDec^ _val1, MiniDec^ _val2){ <-----values are not what was sent MiniDec^ _retval=gcnew MiniDec(); . . . return _retval; }

when stepping through the code I get to the part of the alg that creates a new instance of MiniDec and I checked the value in the ide before stepping into the ctor, but somehow, when it gets to creating a new instance the value has changed to some apparantly random number (and I am checking it as soon as it gets to the ctor and again after it executes the very first instruction)Code:MiniDec(MiniDec^ _val):MiniBI(){ <-------at this point _val does not equal one . . . }

This is running in a single threaded app for testing, no other apps using the library are running, everything seems to work fine till it gets to this algorithm then I have this problem about half way into the alg. The full listing for it is:

where I put it screws up there I mean when it goes into the division part, the values that make it to the division routine are not the same as the values that were sent to it.Code:MiniDec^ Sqr(MiniDec _value){ bool neg=false; MiniDec^ power=gcnew MiniDec(); MiniDec^ temp=gcnew MiniDec(_value); MiniDec^ half=gcnew MiniDec("1"); int _iterations=0; int _runs=1000; half=half/2; if(temp<0){ temp=temp*-1; neg=true; } while(temp>1){ temp=(temp-(temp%2))/2; power=power+1; } temp=gcnew MiniDec(_value); if(power==0){ power=gcnew MiniDec("1"); } MiniDec^ retval=gcnew MiniDec(); MiniDec^ last=gcnew MiniDec(); MiniDec^ current=gcnew MiniDec(); MiniDec^ _retval=gcnew MiniDec(); retval=power; current=power; power=gcnew MiniDec(); <------ everything appears to work to this point while(_iterations<_runs){ _current=_current+(_val/_current); <---but screws up here _iterations+=1; } _retval=current; return _retval; }

everything else tested so far either worked or had a small error which I fixed, but I cant figure out where this error is.

Thanks in advance