|
From: Per W. <pw...@ia...> - 2007-06-07 17:10:11
|
There are no formula for that. This is the normal way of doing it in C (available in the standard header files) #define MAX(a,b) ((a) >= (b) ? (a) : (b)) #define MIN(a,b) ((a) <= (b) ? (a) : (b)) Note that the above two constructs have problems if the parameters have side effects, i.e. for something like: max = MAX(*a++,*b--); For c++, there is a algorithm std::max() available in the standard template library. /pwm On Thu, 7 Jun 2007, Philip Bennefall wrote: > Hi, > Could anyone tell me the formula which is used to calculate the min and max values for a numerical data type of x bytes? Say for instance that I use the > sizeof(datatype) function and get the answer 4, which is usually an integer, how do I then programatically calculate the min and max values for a signed > and unsigned version of the data type respectively. > > Thanks in advance. > > Regards > Philip Bennefall |