shithub: trueawk

Download patch

ref: 4b1b2d6357efbfbf037409e17e91ccdbbae642c1
parent: 1a7797e938dc2b0a52b2d4116a98c019c447660b
author: Brian Kernighan <fakeuser@fake.com>
date: Sun Jun 25 07:51:25 EDT 2023

fixed (I think) the behavior of Nan, thanks to code from Arnold Robbins; also updated awk.1 (ditto), though I think it needs more work

--- a/awk.1
+++ b/awk.1
@@ -76,6 +76,12 @@
 .I fs
 option defines the input field separator to be the regular expression
 .IR fs .
+The
+.B \-\^\-csv
+option causes
+.I awk
+to process records using (more or less) standard comma-separated values
+(CSV) format.
 .PP
 An input line is normally made up of fields separated by white space,
 or by the regular expression
@@ -576,7 +582,8 @@
 The scope rules for variables in functions are a botch;
 the syntax is worse.
 .PP
-Only eight-bit characters sets are handled correctly.
+Input is expected to be UTF-8 encoded. Other multibyte
+character sets are not handled.
 .SH UNUSUAL FLOATING-POINT VALUES
 .I Awk
 was designed before IEEE 754 arithmetic defined Not-A-Number (NaN)
--- a/run.c
+++ b/run.c
@@ -884,10 +884,15 @@
 	int i;
 	Cell *x, *y;
 	Awkfloat j;
+	bool x_is_nan, y_is_nan;
 
 	x = execute(a[0]);
 	y = execute(a[1]);
+	x_is_nan = isnan(x->fval);
+	y_is_nan = isnan(y->fval);
 	if (x->tval&NUM && y->tval&NUM) {
+		if ((x_is_nan || y_is_nan) && n != NE)
+			return(False);
 		j = x->fval - y->fval;
 		i = j<0? -1: (j>0? 1: 0);
 	} else {
@@ -900,7 +905,8 @@
 			else return(False);
 	case LE:	if (i<=0) return(True);
 			else return(False);
-	case NE:	if (i!=0) return(True);
+	case NE:	if (x_is_nan && y_is_nan) return(True);
+			else if (i!=0) return(True);
 			else return(False);
 	case EQ:	if (i == 0) return(True);
 			else return(False);
--