How to eliminate inf value in AWK

Hi,

I have the calculations which return me infinity (inf), -inf, other very larger number when I printed them out.

I did try to insert some control condition not to print these out if the above condition is met. The code I implemented is something like:-

for (i=0;i<=1000;i++){
if(count [i]!="inf"|| count [i]!="-inf" ||count[i]!<0 ||count[i]!>0){
printf("%.2f %0d\n", count[i], i);}}
}
However the above doesnt work. It still prints out these condition. Anyone here know what is the most likely mistakes I made here.

Thanks.

-Jason

It looks like a logic error here. You've written a tautology (if "it's not inf" or "it's not -inf" then print)
Try using && instead of || to get it to only print if all of the predecates match (if "it's not inf" and "it's not -inf" then print)

Hi,

At least, I managed to get rid of INF using this tautology suggested. Can I know the exact reason of why the logic is wrong. Because ultimately I am just comparing the "INF" or "-INF" which is seen in the file, if these appear, it wont print out the information related to "INF" or "-INF".

Besides, one thing I found out that by changing the data type from "f" (float) to "g", the INF and -INF data are eliminated as well.

Please advise. Thanks.

-Jason

A tautology means a statement that will always evaluate to true - it's like a useless comment. In programming, it's always a mistake to have a tautology as it's wasted cycles.

The regular expression you are using (count [i]!="inf"|| count [i]!="-inf" ||count[i]!<0 ||count[i]!>0) is one big tautology.

Look at it this way, you want it to print if the value is not equal to "info" and not equal to "-inf".
I can't figure out what you are looking for with the compares with 0 you are doing. Your current script will print if the value is not less than 0 or not greater than 0 (which is the same as saying it will always print).