Blame test/compare2.awk

Packit 575503
# From beebe@math.utah.edu  Thu Aug  2 15:35:07 2001
Packit 575503
# Received: from mail.actcom.co.il [192.114.47.13]
Packit 575503
# 	by localhost with POP3 (fetchmail-5.7.4)
Packit 575503
# 	for arnold@localhost (single-drop); Thu, 02 Aug 2001 15:35:07 +0300 (IDT)
Packit 575503
# Received: by actcom.co.il (mbox arobbins)
Packit 575503
#  (with Cubic Circle's cucipop (v1.31 1998/05/13) Thu Aug  2 16:02:36 2001)
Packit 575503
# X-From_: beebe@sunshine.math.utah.edu Thu Aug  2 15:41:13 2001
Packit 575503
# Received: from lmail.actcom.co.il by actcom.co.il  with ESMTP
Packit 575503
# 	(8.9.1a/actcom-0.2) id PAA01349 for <arobbins@actcom.co.il>;
Packit 575503
# 	Thu, 2 Aug 2001 15:41:06 +0300 (EET DST)  
Packit 575503
# 	(rfc931-sender: mail.actcom.co.il [192.114.47.13])
Packit 575503
# Received: from billohost.com (www.billohost.com [209.196.35.10])
Packit 575503
# 	by lmail.actcom.co.il (8.11.2/8.11.2) with ESMTP id f72Cf3I21032
Packit 575503
# 	for <arobbins@actcom.co.il>; Thu, 2 Aug 2001 15:41:05 +0300
Packit 575503
# Received: from fencepost.gnu.org (we-refuse-to-spy-on-our-users@fencepost.gnu.org [199.232.76.164])
Packit 575503
# 	by billohost.com (8.9.3/8.9.3) with ESMTP id IAA28585
Packit 575503
# 	for <arnold@skeeve.com>; Thu, 2 Aug 2001 08:34:38 -0400
Packit 575503
# Received: from sunshine.math.utah.edu ([128.110.198.2])
Packit 575503
# 	by fencepost.gnu.org with esmtp (Exim 3.22 #1 (Debian))
Packit 575503
# 	id 15SHjG-00036x-00
Packit 575503
# 	for <arnold@gnu.org>; Thu, 02 Aug 2001 08:37:30 -0400
Packit 575503
# Received: from suncore.math.utah.edu (IDENT:GsUbUdUYCtFLRE4HvnnvhN4JsjooYcfR@suncore0.math.utah.edu [128.110.198.5])
Packit 575503
# 	by sunshine.math.utah.edu (8.9.3/8.9.3) with ESMTP id GAA00190;
Packit 575503
# 	Thu, 2 Aug 2001 06:37:04 -0600 (MDT)
Packit 575503
# Received: (from beebe@localhost)
Packit 575503
# 	by suncore.math.utah.edu (8.9.3/8.9.3) id GAA20469;
Packit 575503
# 	Thu, 2 Aug 2001 06:37:03 -0600 (MDT)
Packit 575503
# Date: Thu, 2 Aug 2001 06:37:03 -0600 (MDT)
Packit 575503
# From: "Nelson H. F. Beebe" <beebe@math.utah.edu>
Packit 575503
# To: arnold@gnu.org
Packit 575503
# Cc: beebe@math.utah.edu
Packit 575503
# X-US-Mail: "Center for Scientific Computing, Department of Mathematics, 322
Packit 575503
#         INSCC, University of Utah, 155 S 1400 E RM 233, Salt Lake City, UT
Packit 575503
#         84112-0090, USA"
Packit 575503
# X-Telephone: +1 801 581 5254
Packit 575503
# X-FAX: +1 801 585 1640, +1 801 581 4148
Packit 575503
# X-URL: http://www.math.utah.edu/~beebe
Packit 575503
# Subject: awk implementations: a bug, or new dark corner?
Packit 575503
# Message-ID: <CMM.0.92.0.996755823.beebe@suncore.math.utah.edu>
Packit 575503
# Status: RO
Packit 575503
# 
Packit 575503
# Consider the following program:
Packit 575503
# 
Packit 575503
# % cat bug.awk
Packit 575503
BEGIN {
Packit 575503
    split("00/00/00",mdy,"/")
Packit 575503
    if ((mdy[1] == 0) && (mdy[2] == 0) && (mdy[3] == 0))
Packit 575503
    {
Packit 575503
        print "OK: zero strings compare equal to number zero"
Packit 575503
        exit(0)
Packit 575503
    }
Packit 575503
    else
Packit 575503
    {
Packit 575503
        print "ERROR: zero strings compare unequal to number zero"
Packit 575503
        exit(1)
Packit 575503
    }
Packit 575503
}
Packit 575503
# 
Packit 575503
# Here are the awk implementation versions (on Sun Solaris 2.7):
Packit 575503
# 
Packit 575503
# 	% awk -V
Packit 575503
# 	awk version 19990416
Packit 575503
# 
Packit 575503
# 	% mawk -W version
Packit 575503
# 	mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
Packit 575503
# 
Packit 575503
# 	% nawk -V
Packit 575503
# 	awk version 20001115
Packit 575503
# 
Packit 575503
# 	% gawk --version
Packit 575503
# 	GNU Awk 3.1.10
Packit 575503
# 	...
Packit 575503
# 
Packit 575503
# Here's what they say about the test program:
Packit 575503
# 
Packit 575503
# 	foreach f (awk mawk nawk gawk gawk-*)
Packit 575503
# 		echo ======== $f
Packit 575503
# 		$f -f ~/bug.awk
Packit 575503
# 	end
Packit 575503
# 
Packit 575503
# 	======== awk
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== mawk
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== nawk
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.0
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.1
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.3
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.4
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.5
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.6
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.60
Packit 575503
# 	OK: zero strings compare equal to number zero
Packit 575503
# 	======== gawk-3.0.90
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.91
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.92
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.93
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.94
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.95
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.96
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.0.97
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.1.0
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 	======== gawk-3.1.10
Packit 575503
# 	ERROR: zero strings compare unequal to number zero
Packit 575503
# 
Packit 575503
# Identical results were obtained on Apple Rhapsody, Apple Darwin,
Packit 575503
# Compaq/DEC Alpha OSF/1, Intel x86 GNU/Linux, SGI IRIX 6.5, DEC Alpha
Packit 575503
# GNU/Linux, and Sun SPARC GNU/Linux, so it definitely is not a C
Packit 575503
# compiler problem.
Packit 575503
# 
Packit 575503
# However, the gray awk book, p. 44, says:
Packit 575503
# 
Packit 575503
# 	In a comparison expression like:
Packit 575503
# 		x == y
Packit 575503
# 	if both operands have a numeric type, the comparison is numeric;
Packit 575503
# 	otherwise, any numeric operand is converted to a string and the
Packit 575503
# 	comparison is made on the string values.
Packit 575503
# 
Packit 575503
# and the new green gawk book, p. 95, says:
Packit 575503
# 
Packit 575503
# 	When comparing operands of mixed types, numeric operands are
Packit 575503
# 	converted to strings using the value of `CONVFMT'
Packit 575503
# 
Packit 575503
# This suggests that the OK response in bug.awk is wrong, and the ERROR
Packit 575503
# response is correct.  Only recent gawk releases do the right thing,
Packit 575503
# and it is awk, mawk, and nawk that have a bug.
Packit 575503
# 
Packit 575503
# If I change the test program from "00/00/00" to "0/0/0", all versions
Packit 575503
# tested produce the OK response.
Packit 575503
# 
Packit 575503
# Comments?
Packit 575503
# 
Packit 575503
# After reading the two book excerpts, I changed my code to read
Packit 575503
# 
Packit 575503
#     if (((0 + mdy[1]) == 0) && ((0 + mdy[2]) == 0) && ((0 + mdy[3]) == 0))
Packit 575503
# 
Packit 575503
# and output from all implementations now agrees.
Packit 575503
# 
Packit 575503
# -------------------------------------------------------------------------------
Packit 575503
# - Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
Packit 575503
# - Center for Scientific Computing       FAX: +1 801 585 1640, +1 801 581 4148 -
Packit 575503
# - University of Utah                    Internet e-mail: beebe@math.utah.edu  -
Packit 575503
# - Department of Mathematics, 322 INSCC      beebe@acm.org  beebe@computer.org -
Packit 575503
# - 155 S 1400 E RM 233                       beebe@ieee.org                    -
Packit 575503
# - Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe  -
Packit 575503
# -------------------------------------------------------------------------------
Packit 575503
#