[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ensure numeric comparison
From: |
Peng Yu |
Subject: |
ensure numeric comparison |
Date: |
Fri, 6 May 2022 17:28:39 -0500 |
Hi,
I want to make sure whether the following code is guaranteed to
compare $1 and $2 numerically as long as the input of the 1st and 2nd
fields are legitimate numbers or empty strings (which are considered
as 0).
awk -e '{ print ($1 < $2) }' < input
Or there is any corner case when even the 1st and 2nd fields are
legitimate numbers or empty strings, they may be compared as strings.
Note although an empty string compared with an empty string is a
string comparison, the result is the same as 0 and 0 comparison, so it
is still effectively considered as a numerical comparison for the
current discussion.
--
Regards,
Peng
- ensure numeric comparison,
Peng Yu <=
- Re: ensure numeric comparison, david kerns, 2022/05/06
- Re: ensure numeric comparison, Peng Yu, 2022/05/07
- Re: ensure numeric comparison, david kerns, 2022/05/07
- Re: ensure numeric comparison, Peng Yu, 2022/05/08
- Re: ensure numeric comparison, Neil R. Ormos, 2022/05/08
- Re: ensure numeric comparison, Peng Yu, 2022/05/08
- Re: ensure numeric comparison, Neil R. Ormos, 2022/05/08
Re: ensure numeric comparison, Andrew J. Schorr, 2022/05/08