System verilog / UVM integer Overflow , Underflow

I am trying to test for overflow and underflow scenarios of max positive and min negative of 32 bit integer .

  1. I am updating the counters based on credit processing .
  2. To avoid wrapping when it overflows or underflows I am using type longint .
  3. 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 ?

Your code makes very little sense. Did you cut & paste it correctly?

I am trying to test for overflow and underflow scenarios of max positive and min negative of 32 bit integer . I have a checker at end of test which compares my counter values with register value . RTL caps the counter to max positive and min negative when overflow or underflow occurs .
I am trying to cap and then compare at end of test and not at every counter increment or decrement .The counters could keep incrementing which could go over the max positive value or decrementing below min negative value . Hence to avoid wrapping I am using type longint .
When I try to get the counter value at end of test and assign it to a longint type variable it gets automatically converted to signed value .
What are the ways I can preserve the values of counter [Positive and negative values ] and then compare at end of test ?