Overflow/Underflow detecting functions!

I am performing arithmetic operations on very large integers that operate around the threshold of the maximum positive integer an int variable can handle (i.e. 2147483647) for a 32-bit machine. I have been studying the in-built functions in the C++ Standard Library for some time now where I came across some error detecting functions in the <cmath> and <cerrno> header files. The impression I got from the literature is that they are solely used in conjunction with functions contained in the <cmath> header file and not necessarily with fundamental arithmetic operations like addition and subtraction. My ambitious attempt later to use them for my problem failed!

I need a means to know when my arithmetic operations generate overflows/underflows! Is there any way I can adapt the functionalities of these functions to my needs?
The impression I got from the literature is that they are solely used in conjunction with functions contained in the <cmath> header file
No. Many functions in the C standard library set errno.
... and not necessarily with fundamental arithmetic operations like addition and subtraction.
Yes. errno is not set for integer overflow/underflow errors.
I need a means to know when my arithmetic operations generate overflows/underflows!
either define functions sum/substract/... whick would check on overflow and report. Or define your own SafeInteger class with overloaded operators which would do the same.

Also you need to know if operation would generate overflow. Letting signed overflow happen leads to undefined behavior and potentially can wreak your program.
@ OP: In case you haven't seen it yet, the "numeric_limits" template from the 'limits' header can help you a lot with this. If you aren't comfortable with templates yet then now is a good time to start learning about them. Just for the sake of completeness, the 'climits' header would not be completely useless either. I recommend the first solution though.
Thanks guys for your replies!

What I'm doing is actually similar to the idea of defining a new class suggested by MiiNiPaa; I am designing a new class to handle very very large integers. I am overloading a few arithmetic operators and the stream operators for the class. It just came across to me as strange(the reason for my original post) that, given the seeming vastness of the Standard Library, error-detecting functions to detect overflows/underflows in simple arithmetic operations would be non-existent!!
error-detecting functions to detect overflows/underflows in simple arithmetic operations would be non-existent!!
As I said, if you let signed overflow happens, you have UB and your program now in undefined state. You will need to check if operation would lead to the overflow before actually attempting it.
This could help you:
http://stackoverflow.com/a/1514309/3410396
http://www.fefe.de/intof.html
Topic archived. No new replies allowed.