You are using a version without Ads of this website. Please, consider donating:

### this doesn't make sense.. need help

hello i have a very big code so i can't post it all but my problem is in this part:

 ``12345678`` `````` cout <<*this<test1) { cout <<"1 "<<*this<test1)) { cout <<"2 "<<*this<

my first if statement evaluates to true and my second if statement evaluates to false clearly but that doesn't make sense at all because the second part of it is true and theres just an or operator between them. my output therefore is:

 ``` 5 1 5 ```

can someone tell me what's going on ? if you need more code just ask me.
Last edited on
Haha, nice one. Must be some typo, or maybe there is in fact else if in second statement?
How is < and > defined for your type?
 ``1234567891011121314151617181920212223242526272829303132`` ``````void scaleby2(BigInt N) { BigInt test1=BigInt("1"); BigInt test2=BigInt("0.5"); cout <<*this<test1) { cout <<"1 "<<*this<test1)) { cout <<"2 "<<*this<test1) { if (*this test1) { cout <<" "<<*this<

this is my function which is in the BigInt class
and it looks like its not even doing anything in that while loop..
Last edited on
lines 2 and 3 can be simplified like this ` BigInt test1("1");`
 ``1234`` `````` BigInt operator< (BigInt param) { //stuff }``````
my < operator is defined like this:
 ``12345678910111213141516171819`` ``````bool operator < (BigInt a,BigInt b) { while (a.digits.size()-a.dec!=b.digits.size()-b.dec) {//add zeros at the end of the number to make sure our numbers have the same precision if (a.digits.size()-a.dec>b.digits.size()-b.dec) {b.digits.push_back(0);} else {a.digits.push_back(0);} } while (a.digits.size()!=b.digits.size()) {//add zeros at the begin of the number to make sure they have the same size. if (a.digits.size()>b.digits.size()) {b.digits.insert(b.digits.begin(),1,0);b.dec++;} else {a.digits.insert(a.digits.begin(),1,0);a.dec++;} } for (unsigned int i=0;ib.digits.at(i)) { return false; } } return false; } ``````
anyone ? /:
The only thing I can think of is that your < and/or > operator (edit: or the stream operator) is actually modifying the state of either this or test1, so that the result of the comparison at line 6 is different from the result of the seemingly identical comparison at line 9.
Last edited on
no they don't change the value /:
The zero-adding in operator< concerns me. Especially that you seem to be adding 0's at both end of the numbers, and I don't see why they need to be the same size to be compared.

1 is the same as 000000001, but it is not the same as 10000000.

Have you tested operator< to ensure that it actually works for different test cases?
Last edited on
i had some major updates in my class and i didn't even change the scaleby2 function but it works now somehow so i guess thanks for your help.
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: