I am trying to test for overflow and underflow scenarios of max positive and min negative of 32 bit integer .
- I am updating the counters based on credit processing .
- To avoid wrapping when it overflows or underflows I am using type longint .
- End of the test I am checking for the count and I am trying to cap to max positive if the value is greater than max positive . If its less than min negative I am capping it to min negative value to mimic RTL behavior .
Issue I am seeing :
I am saving my count in a longint type . But when I call getcount function and assign the count to another variable of type long int , it gets converted to signed value .
longint HdrCreditCount[a]
function int GetCount (Type, int a=0);
longint Count ;
Count = HdrCount[a];
endfunction
function int Inc
HdrCount[a] += lIncval;
endfunction
longint data;
longint header;
data = Getcount[HdrCount]
Ex values :
Hdrcount : 2147671192
When I assign to data ; data = -2147296104
Since I am checking for both max and min , i can just convert to unsigned and then cap .
How can I resolve this ?