Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!husc6!rice!sun-spots-request From: bugs@shire.cs.psu.edu Newsgroups: comp.sys.sun Subject: Awk -- gets math wrong Keywords: SunOS Message-ID: <819@brazos.Rice.edu> Date: 10 Aug 89 04:17:18 GMT Sender: root@rice.edu Organization: Sun-Spots Lines: 58 Approved: Sun-Spots@rice.edu X-Sun-Spots-Digest: Volume 8, Issue 97, message 5 of 14 Serial Number: 824E0190 Machine Type: Sun 4/260S O/S Version: SunOS 4.0.3 Organization: Computer Science Department, The Pennsylvania State University 333 Whitmore Laboratory, University Park, PA 16802 Phone Number: +1 814 865 9723 Description: Awk gets math wrong, in sevaral ways. Symptoms are: -- cosine is computed incorrectly. -- expressions involving expressions in sin and cosine are computed strangely. The first problem is not tolerable. The second is annoying but potentially defensible depending on how the expression is parsed. In any case, Sun's documentation does not mention whether or not Awk even supports transcendental math functions, a serious bug in the documentation. [ A possibly pedantic, but very surprising obervation is that Sun's man page omits the reference to the paper by Kernighan, et.al. which describes the actual language. BSD's man page sites this paper: why did Sun delete that reference? Sun's repackaging of the traditional Unix supporting documentation (found in /usr/doc on BSD) into anonymous offline collections ("Pattern Scanning and Processing with AWK" in this case) is quite irritating. These documents should be available online, unadulterated, and with authorship correctly cited. ] Repeat-By: % awk ' BEGIN { ang = 0.15 rad = (ang) / (57.2958) s = sin(rad) c = cos(rad) print "s " s print "c " c print "t " s/c print "sin/cos " sin(rad) / cos(rad) } ' s 0.00261799 # Okay c 0.00261799 # Wrong! t 1 # Okay awk: division by zero # Wrong? Parsed as (sin(rad)/cos)(rad) Fix: Writing parantheses around the denominator works around the second failure: print "sin/cos " sin(rad) / (cos(rad)) GUN awk gets it right. I presume the new SysV awk will too. Replace old awk with a modern version. (Is this planned for 4.1?)