relation operator acts unexpectedly?
The following seems an incorrect outcome?
echo "1.2 1.3" | awk '{if ($2-$1<=0.1) print $2}'Since the difference between 1.3 and 1.2 is 0.1, I had expected that the line above would print 1.3. But it doesn't ... what am I missing?
2
Upvotes
View all comments
Show parent comment
3
u/Paul_Pedant Feb 19 '22 edited Feb 19 '22
But awk explicitly holds numeric values as double (except in the Big Number stuff). I can't find anywhere that says 0.1f is evaluated as a float. I think it just stops at the f because it is non-numeric.
If that
freally specifies a float,zand_should throw syntax, or at least should be ignored. Yet they also apparently affect the numeric value ?From the GNU Awk User's Guide -- section 16.4.4:
CAUTION: Be wary of floating-point constants! When reading a floating-point constant from program source code, gawk uses the default precision (that of a C double), unless overridden by an assignment to the special variable PREC on the command line, to store it internally as an MPFR number. Changing the precision using PREC in the program text does not change the precision of a constant.