Opinion on Overloading < and > For My Number Class

This is a discussion on Opinion on Overloading < and > For My Number Class within the C++ Programming forums, part of the General Programming Boards category; I have two ideas in mind on how to overload these operators. One would involve using the subtraction operator and ...

Opinion on Overloading < and > For My Number Class

I have two ideas in mind on how to overload these operators. One would involve using the subtraction operator and checking the sign of the result. The other would involve comparing the values and signs (as the sign is stored separately from the value). Which would you go with?

If speed is an issue, I would code it both ways and profile to see which is faster... the one that uses the fewest operations (assuming they're all bitwise operations and they all take the same amount of time) would obviously be the best...

I'd need to know a little more about your number class (big integer/float type thing, I'm guessing, using an array to store the values). If so, then I think individual comparison would work faster on average.

For example, check the sign bits, and if one is positive, and the other negative, return immediately. Then, compare the most significant byte/block, and continue until you can determine one is larger/smaller than the other. That way, you do not need to perform operations on all blocks of the number (except worst case scenario), where you do if you do the subtraction. Also, if the numbers vary greatly, then the temporary created by the subtraction may be quite large.

Yeah, I'm storing them as string objects with a bool representing the sign. From what I'm thinking, the subtraction is probably gonna be slower. So, I'm probably gonna use the .length function along with the sign.