1*e6d6c189SCody Peter Mello# From beebe@math.utah.edu Thu Aug 2 15:35:07 2001 2*e6d6c189SCody Peter Mello# Received: from mail.actcom.co.il [192.114.47.13] 3*e6d6c189SCody Peter Mello# by localhost with POP3 (fetchmail-5.7.4) 4*e6d6c189SCody Peter Mello# for arnold@localhost (single-drop); Thu, 02 Aug 2001 15:35:07 +0300 (IDT) 5*e6d6c189SCody Peter Mello# Received: by actcom.co.il (mbox arobbins) 6*e6d6c189SCody Peter Mello# (with Cubic Circle's cucipop (v1.31 1998/05/13) Thu Aug 2 16:02:36 2001) 7*e6d6c189SCody Peter Mello# X-From_: beebe@sunshine.math.utah.edu Thu Aug 2 15:41:13 2001 8*e6d6c189SCody Peter Mello# Received: from lmail.actcom.co.il by actcom.co.il with ESMTP 9*e6d6c189SCody Peter Mello# (8.9.1a/actcom-0.2) id PAA01349 for <arobbins@actcom.co.il>; 10*e6d6c189SCody Peter Mello# Thu, 2 Aug 2001 15:41:06 +0300 (EET DST) 11*e6d6c189SCody Peter Mello# (rfc931-sender: mail.actcom.co.il [192.114.47.13]) 12*e6d6c189SCody Peter Mello# Received: from billohost.com (www.billohost.com [209.196.35.10]) 13*e6d6c189SCody Peter Mello# by lmail.actcom.co.il (8.11.2/8.11.2) with ESMTP id f72Cf3I21032 14*e6d6c189SCody Peter Mello# for <arobbins@actcom.co.il>; Thu, 2 Aug 2001 15:41:05 +0300 15*e6d6c189SCody Peter Mello# Received: from fencepost.gnu.org (we-refuse-to-spy-on-our-users@fencepost.gnu.org [199.232.76.164]) 16*e6d6c189SCody Peter Mello# by billohost.com (8.9.3/8.9.3) with ESMTP id IAA28585 17*e6d6c189SCody Peter Mello# for <arnold@skeeve.com>; Thu, 2 Aug 2001 08:34:38 -0400 18*e6d6c189SCody Peter Mello# Received: from sunshine.math.utah.edu ([128.110.198.2]) 19*e6d6c189SCody Peter Mello# by fencepost.gnu.org with esmtp (Exim 3.22 #1 (Debian)) 20*e6d6c189SCody Peter Mello# id 15SHjG-00036x-00 21*e6d6c189SCody Peter Mello# for <arnold@gnu.org>; Thu, 02 Aug 2001 08:37:30 -0400 22*e6d6c189SCody Peter Mello# Received: from suncore.math.utah.edu (IDENT:GsUbUdUYCtFLRE4HvnnvhN4JsjooYcfR@suncore0.math.utah.edu [128.110.198.5]) 23*e6d6c189SCody Peter Mello# by sunshine.math.utah.edu (8.9.3/8.9.3) with ESMTP id GAA00190; 24*e6d6c189SCody Peter Mello# Thu, 2 Aug 2001 06:37:04 -0600 (MDT) 25*e6d6c189SCody Peter Mello# Received: (from beebe@localhost) 26*e6d6c189SCody Peter Mello# by suncore.math.utah.edu (8.9.3/8.9.3) id GAA20469; 27*e6d6c189SCody Peter Mello# Thu, 2 Aug 2001 06:37:03 -0600 (MDT) 28*e6d6c189SCody Peter Mello# Date: Thu, 2 Aug 2001 06:37:03 -0600 (MDT) 29*e6d6c189SCody Peter Mello# From: "Nelson H. F. Beebe" <beebe@math.utah.edu> 30*e6d6c189SCody Peter Mello# To: arnold@gnu.org 31*e6d6c189SCody Peter Mello# Cc: beebe@math.utah.edu 32*e6d6c189SCody Peter Mello# X-US-Mail: "Center for Scientific Computing, Department of Mathematics, 322 33*e6d6c189SCody Peter Mello# INSCC, University of Utah, 155 S 1400 E RM 233, Salt Lake City, UT 34*e6d6c189SCody Peter Mello# 84112-0090, USA" 35*e6d6c189SCody Peter Mello# X-Telephone: +1 801 581 5254 36*e6d6c189SCody Peter Mello# X-FAX: +1 801 585 1640, +1 801 581 4148 37*e6d6c189SCody Peter Mello# X-URL: http://www.math.utah.edu/~beebe 38*e6d6c189SCody Peter Mello# Subject: awk implementations: a bug, or new dark corner? 39*e6d6c189SCody Peter Mello# Message-ID: <CMM.0.92.0.996755823.beebe@suncore.math.utah.edu> 40*e6d6c189SCody Peter Mello# Status: RO 41*e6d6c189SCody Peter Mello# 42*e6d6c189SCody Peter Mello# Consider the following program: 43*e6d6c189SCody Peter Mello# 44*e6d6c189SCody Peter Mello# % cat bug.awk 45*e6d6c189SCody Peter MelloBEGIN { 46*e6d6c189SCody Peter Mello split("00/00/00",mdy,"/") 47*e6d6c189SCody Peter Mello if ((mdy[1] == 0) && (mdy[2] == 0) && (mdy[3] == 0)) 48*e6d6c189SCody Peter Mello { 49*e6d6c189SCody Peter Mello print "OK: zero strings compare equal to number zero" 50*e6d6c189SCody Peter Mello exit(0) 51*e6d6c189SCody Peter Mello } 52*e6d6c189SCody Peter Mello else 53*e6d6c189SCody Peter Mello { 54*e6d6c189SCody Peter Mello print "ERROR: zero strings compare unequal to number zero" 55*e6d6c189SCody Peter Mello exit(1) 56*e6d6c189SCody Peter Mello } 57*e6d6c189SCody Peter Mello} 58*e6d6c189SCody Peter Mello# 59*e6d6c189SCody Peter Mello# Here are the awk implementation versions (on Sun Solaris 2.7): 60*e6d6c189SCody Peter Mello# 61*e6d6c189SCody Peter Mello# % awk -V 62*e6d6c189SCody Peter Mello# awk version 19990416 63*e6d6c189SCody Peter Mello# 64*e6d6c189SCody Peter Mello# % mawk -W version 65*e6d6c189SCody Peter Mello# mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan 66*e6d6c189SCody Peter Mello# 67*e6d6c189SCody Peter Mello# % nawk -V 68*e6d6c189SCody Peter Mello# awk version 20001115 69*e6d6c189SCody Peter Mello# 70*e6d6c189SCody Peter Mello# % gawk --version 71*e6d6c189SCody Peter Mello# GNU Awk 3.1.10 72*e6d6c189SCody Peter Mello# ... 73*e6d6c189SCody Peter Mello# 74*e6d6c189SCody Peter Mello# Here's what they say about the test program: 75*e6d6c189SCody Peter Mello# 76*e6d6c189SCody Peter Mello# foreach f (awk mawk nawk gawk gawk-*) 77*e6d6c189SCody Peter Mello# echo ======== $f 78*e6d6c189SCody Peter Mello# $f -f ~/bug.awk 79*e6d6c189SCody Peter Mello# end 80*e6d6c189SCody Peter Mello# 81*e6d6c189SCody Peter Mello# ======== awk 82*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 83*e6d6c189SCody Peter Mello# ======== mawk 84*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 85*e6d6c189SCody Peter Mello# ======== nawk 86*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 87*e6d6c189SCody Peter Mello# ======== gawk 88*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 89*e6d6c189SCody Peter Mello# ======== gawk-3.0.0 90*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 91*e6d6c189SCody Peter Mello# ======== gawk-3.0.1 92*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 93*e6d6c189SCody Peter Mello# ======== gawk-3.0.3 94*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 95*e6d6c189SCody Peter Mello# ======== gawk-3.0.4 96*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 97*e6d6c189SCody Peter Mello# ======== gawk-3.0.5 98*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 99*e6d6c189SCody Peter Mello# ======== gawk-3.0.6 100*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 101*e6d6c189SCody Peter Mello# ======== gawk-3.0.60 102*e6d6c189SCody Peter Mello# OK: zero strings compare equal to number zero 103*e6d6c189SCody Peter Mello# ======== gawk-3.0.90 104*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 105*e6d6c189SCody Peter Mello# ======== gawk-3.0.91 106*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 107*e6d6c189SCody Peter Mello# ======== gawk-3.0.92 108*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 109*e6d6c189SCody Peter Mello# ======== gawk-3.0.93 110*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 111*e6d6c189SCody Peter Mello# ======== gawk-3.0.94 112*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 113*e6d6c189SCody Peter Mello# ======== gawk-3.0.95 114*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 115*e6d6c189SCody Peter Mello# ======== gawk-3.0.96 116*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 117*e6d6c189SCody Peter Mello# ======== gawk-3.0.97 118*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 119*e6d6c189SCody Peter Mello# ======== gawk-3.1.0 120*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 121*e6d6c189SCody Peter Mello# ======== gawk-3.1.10 122*e6d6c189SCody Peter Mello# ERROR: zero strings compare unequal to number zero 123*e6d6c189SCody Peter Mello# 124*e6d6c189SCody Peter Mello# Identical results were obtained on Apple Rhapsody, Apple Darwin, 125*e6d6c189SCody Peter Mello# Compaq/DEC Alpha OSF/1, Intel x86 GNU/Linux, SGI IRIX 6.5, DEC Alpha 126*e6d6c189SCody Peter Mello# GNU/Linux, and Sun SPARC GNU/Linux, so it definitely is not a C 127*e6d6c189SCody Peter Mello# compiler problem. 128*e6d6c189SCody Peter Mello# 129*e6d6c189SCody Peter Mello# However, the gray awk book, p. 44, says: 130*e6d6c189SCody Peter Mello# 131*e6d6c189SCody Peter Mello# In a comparison expression like: 132*e6d6c189SCody Peter Mello# x == y 133*e6d6c189SCody Peter Mello# if both operands have a numeric type, the comparison is numeric; 134*e6d6c189SCody Peter Mello# otherwise, any numeric operand is converted to a string and the 135*e6d6c189SCody Peter Mello# comparison is made on the string values. 136*e6d6c189SCody Peter Mello# 137*e6d6c189SCody Peter Mello# and the new green gawk book, p. 95, says: 138*e6d6c189SCody Peter Mello# 139*e6d6c189SCody Peter Mello# When comparing operands of mixed types, numeric operands are 140*e6d6c189SCody Peter Mello# converted to strings using the value of `CONVFMT' 141*e6d6c189SCody Peter Mello# 142*e6d6c189SCody Peter Mello# This suggests that the OK response in bug.awk is wrong, and the ERROR 143*e6d6c189SCody Peter Mello# response is correct. Only recent gawk releases do the right thing, 144*e6d6c189SCody Peter Mello# and it is awk, mawk, and nawk that have a bug. 145*e6d6c189SCody Peter Mello# 146*e6d6c189SCody Peter Mello# If I change the test program from "00/00/00" to "0/0/0", all versions 147*e6d6c189SCody Peter Mello# tested produce the OK response. 148*e6d6c189SCody Peter Mello# 149*e6d6c189SCody Peter Mello# Comments? 150*e6d6c189SCody Peter Mello# 151*e6d6c189SCody Peter Mello# After reading the two book excerpts, I changed my code to read 152*e6d6c189SCody Peter Mello# 153*e6d6c189SCody Peter Mello# if (((0 + mdy[1]) == 0) && ((0 + mdy[2]) == 0) && ((0 + mdy[3]) == 0)) 154*e6d6c189SCody Peter Mello# 155*e6d6c189SCody Peter Mello# and output from all implementations now agrees. 156*e6d6c189SCody Peter Mello# 157*e6d6c189SCody Peter Mello# ------------------------------------------------------------------------------- 158*e6d6c189SCody Peter Mello# - Nelson H. F. Beebe Tel: +1 801 581 5254 - 159*e6d6c189SCody Peter Mello# - Center for Scientific Computing FAX: +1 801 585 1640, +1 801 581 4148 - 160*e6d6c189SCody Peter Mello# - University of Utah Internet e-mail: beebe@math.utah.edu - 161*e6d6c189SCody Peter Mello# - Department of Mathematics, 322 INSCC beebe@acm.org beebe@computer.org - 162*e6d6c189SCody Peter Mello# - 155 S 1400 E RM 233 beebe@ieee.org - 163*e6d6c189SCody Peter Mello# - Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe - 164*e6d6c189SCody Peter Mello# ------------------------------------------------------------------------------- 165*e6d6c189SCody Peter Mello# 166