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