S
Starx
I am writing a fraction class and I was testing my addition operator to
find out how big the numerator and denominator can be before an
overflow occurs. I was doing it like this:
fraction frac1(10001, 10000); //Creates 10001/10000
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
I then proceeded to add zero's to the first line and kept executing the
program and looking for an obviously wrong result as an indication of
overflow. A curious thing happened. This test:
fraction frac1(1000000001, 1000000000);
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
compiles fine and outputs a correct result. This test:
fraction frac1(10000000001, 10000000000);
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
which has 1 extra 0 added to the both the numerator and denominator,
doesn't compile. It gives me error C2668: 'fraction::fraction' :
ambiguous call to overloaded function. Now my fraction constructors
can handle int and long int which can be either signed or unsigned and
the numerator doesn't have to be the same type as the denominator, you
can mix and match. I'm running VC++ 6.0 and normally when I just type
numbers into the source code (as I've done here) and those numbers have
no decimal, they are interpreted as type int. So when the numbers get
large enough are they interpreted as a different type?? If so how do I
find out what type that is?
find out how big the numerator and denominator can be before an
overflow occurs. I was doing it like this:
fraction frac1(10001, 10000); //Creates 10001/10000
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
I then proceeded to add zero's to the first line and kept executing the
program and looking for an obviously wrong result as an indication of
overflow. A curious thing happened. This test:
fraction frac1(1000000001, 1000000000);
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
compiles fine and outputs a correct result. This test:
fraction frac1(10000000001, 10000000000);
cout << frac1 << " * 2 = " << frac1 + frac1 << endl;
which has 1 extra 0 added to the both the numerator and denominator,
doesn't compile. It gives me error C2668: 'fraction::fraction' :
ambiguous call to overloaded function. Now my fraction constructors
can handle int and long int which can be either signed or unsigned and
the numerator doesn't have to be the same type as the denominator, you
can mix and match. I'm running VC++ 6.0 and normally when I just type
numbers into the source code (as I've done here) and those numbers have
no decimal, they are interpreted as type int. So when the numbers get
large enough are they interpreted as a different type?? If so how do I
find out what type that is?