• GAWK: Bug/mis-feature in arraymax.awk

    From Kenny McCormack@21:1/5 to All on Tue Jan 18 14:47:22 2022
    The GAWK distro contains an example program called arraymax.awk - that calculates the maximum of a series of input values. However, it uses the
    naive way of calculating the max - which fails if all the values are
    negative (Tested and verified by taking the sample data file and prefixing
    all the numbers with "-"; the program then generates no output).

    Perhaps something to fix. Note the correct algorithm in my other post,
    where you initialize the max value to the first input arg.

    --
    If there is anything more pathetic than Dr. Donald Trump, MD, giving out medical
    advice, it is the pathetic followers of Dr. Trump trying to implement said advice.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Schorr@21:1/5 to Kenny McCormack on Thu Jan 20 05:31:27 2022
    On Tuesday, January 18, 2022 at 9:47:23 AM UTC-5, Kenny McCormack wrote:
    The GAWK distro contains an example program called arraymax.awk - that calculates the maximum of a series of input values.

    Actually, it's just an inaptly-named sample program to demonstrate some array features,
    not a general-purpose max calculator. From the docs:

    https://www.gnu.org/software/gawk/manual/html_node/Array-Example.html

    The following program takes a list of lines, each beginning with a line
    number, and prints them out in order of line number. The line numbers
    are not in order when they are first read---instead, they
    are scrambled. This program sorts the lines by making an array using
    the line numbers as subscripts. The program then prints out the lines
    in sorted order of their numbers. It is a very simple program and gets confused upon encountering repeated numbers, gaps, or lines that don't
    begin with a number:
    ...

    So I don't see why it's a bug. It does what it says it does, but I agree that it certainly
    does not calculate maximum values in the general case.

    Regards,
    Andy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to aschorr@telemetry-investments.com on Thu Jan 20 15:30:09 2022
    In article <257744db-2aa0-4e4a-8434-7adadb81fdf1n@googlegroups.com>,
    Andrew Schorr <aschorr@telemetry-investments.com> wrote:
    On Tuesday, January 18, 2022 at 9:47:23 AM UTC-5, Kenny McCormack wrote:
    The GAWK distro contains an example program called arraymax.awk - that
    calculates the maximum of a series of input values.

    Actually, it's just an inaptly-named sample program to demonstrate some array features,
    not a general-purpose max calculator. From the docs:

    Agreed - and it is really no big deal. I wasn't even calling it a bug -
    just a thing that could be fixed. I'm sure that, in the fullness of time, someone (on the dev side) will notice it and decide to fix it.

    You're right about the name being misleading. But I also want to point out that when I said that it "calculates the maximum of a series of input values", that doee not necessarily mean that that is its primary purpose. In this
    case, that calculation is merely a step on the way to the actual purpose of
    the program (if you see what I mean...)

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/InsaneParty

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Andrew Schorr on Sat Jan 22 21:39:59 2022
    On 2022-01-20, Andrew Schorr <aschorr@telemetry-investments.com> wrote:
    So I don't see why it's a bug. It does what it says it does, but I agree that it certainly
    does not calculate maximum values in the general case.

    I.e. what is written on the box is a bug. The box says there are
    Cheerios inside, and by golly, there actually are. But the box should
    say Corn Flakes, damn it!

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)