Assigning rank to rows of numbers with directionality

I have a tab-delimited text file where the second column contains in increasing order and includes negative and positive numbers.

I want to assign ranks to the rows based on the value of the second column. The tricky part is that the row where the second column is "0", will be assigned "0", the rows with negative values in the second column ranks of increasingly negative values and the rows with positive values in the second column ranks of increasingly positive values. If two rows have the same value in their second column, they will have the same rank. Example:

Input:

A -5
B -4
C -4 
D -2
E 0
F 1
G 1
H 2
Output: 
A -5 -3
B -4 -2
C -4 -2
D -2 -1
E 0 0
F 1 1 
G 1 1 
H 2 2 

How do I go about doing this? Thanks!

how do you determine the 'rank'?

Basically it is based on the value of the second column. The greater the value in the second column, the higher the rank. If two rows have the same value though, they have the same rank. The rank of the row with "0" in the second column is set to 0.

Try:

awk 'NR==FNR&&$2<=0&&!a[$2]++{i--}NR!=FNR{$3=$2==tmp?i:++i;print;tmp=$2}' file file

Note that filename is specified twice.