Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Mausoleum: The final and funniest folly of the rich. -- Ambrose Bierce


devel / comp.lang.awk / awk not outputting in scientific notation despite %e

SubjectAuthor
* awk not outputting in scientific notation despite %eRoss
+- Re: awk not outputting in scientific notation despite %eKaz Kylheku
+- Re: awk not outputting in scientific notation despite %eJanis Papanagnou
`* Re: awk not outputting in scientific notation despite %eKeith Thompson
 `* Re: awk not outputting in scientific notation despite %eKeith Thompson
  +* Re: awk not outputting in scientific notation despite %eKeith Thompson
  |`- Re: awk not outputting in scientific notation despite %eKaz Kylheku
  `* Re: awk not outputting in scientific notation despite %eRoss
   +- Re: awk not outputting in scientific notation despite %eRoss
   `* Re: awk not outputting in scientific notation despite %eKeith Thompson
    `* Re: awk not outputting in scientific notation despite %eKaz Kylheku
     `* Re: awk not outputting in scientific notation despite %eAndrew Schorr
      `* Re: awk not outputting in scientific notation despite %eKaz Kylheku
       `* Re: awk not outputting in scientific notation despite %eBen Bacarisse
        `* Re: awk not outputting in scientific notation despite %eAndrew Schorr
         `- Re: awk not outputting in scientific notation despite %eKpop 2GM

1
awk not outputting in scientific notation despite %e

<2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1437&group=comp.lang.awk#1437

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:622a:408:b0:3f3:8459:956c with SMTP id n8-20020a05622a040800b003f38459956cmr2544587qtx.3.1683495365072;
Sun, 07 May 2023 14:36:05 -0700 (PDT)
X-Received: by 2002:a05:622a:1b89:b0:3ef:3cdf:c291 with SMTP id
bp9-20020a05622a1b8900b003ef3cdfc291mr3782122qtb.13.1683495364805; Sun, 07
May 2023 14:36:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Sun, 7 May 2023 14:36:04 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=198.11.30.72; posting-account=ZhrElQoAAAAtGhDcjT_0NQ3OeIks2UZd
NNTP-Posting-Host: 198.11.30.72
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
Subject: awk not outputting in scientific notation despite %e
From: chaudhry.ross@gmail.com (Ross)
Injection-Date: Sun, 07 May 2023 21:36:05 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2009
 by: Ross - Sun, 7 May 2023 21:36 UTC

I am using awk for some basic calculations and want to force my output to be in scientific notation. I am using OFMT="%.15e" to accomplish this. On most machines, I get the expected output:

$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
4.483923595133619e+26

But a version of awk on my cluster gives:

$ awk --version | head --lines=2
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.

$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
448392359513361882871234560

Why is this version/configuration of awk not outputting to scientific notation as requested? How can I portably get my desired result (4.483923595133619e+26)?

(This question was originally posted to stackexchange at https://stackoverflow.com/questions/76187717/awk-not-outputting-in-scientific-notation-despite-e but it didn't get much attention and I was directed here instead.)

Re: awk not outputting in scientific notation despite %e

<20230507150910.467@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1438&group=comp.lang.awk#1438

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Sun, 7 May 2023 22:24:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <20230507150910.467@kylheku.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
Injection-Date: Sun, 7 May 2023 22:24:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4fdb655e6734bca337e87695bb769c87";
logging-data="3742349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9dmYqcEsxDxt9HYWPrmqy3XxWBWwy9oo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:xY52jX3r3SBFgm6NDZEpVl4WH04=
 by: Kaz Kylheku - Sun, 7 May 2023 22:24 UTC

On 2023-05-07, Ross <chaudhry.ross@gmail.com> wrote:
> I am using awk for some basic calculations and want to force my output to be in scientific notation. I am using OFMT="%.15e" to accomplish this. On most machines, I get the expected output:
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 4.483923595133619e+26
>
> But a version of awk on my cluster gives:
>
> $ awk --version | head --lines=2
> GNU Awk 4.0.2
> Copyright (C) 1989, 1991-2012 Free Software Foundation.
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 448392359513361882871234560

Can repro on Ubutu 18:

0:[0507:150838]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 3.1 }'
3.100000e+00
0:[0507:150845]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 10e50 }'
999999999999999993220948674361627976461708441944064

$ awk --version | head -2
GNU Awk 5.1.60, API: 3.2
Copyright (C) 1989, 1991-2021 Free Software Foundation.

This seems to be a "feature". It's as if the format is ignored for
integers (that being numbers which have a zero fractional part).

0:[0507:151109]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 1 }'
1 0:[0507:151117]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 100 }'
100
0:[0507:151121]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 300 }'
300
0:[0507:151123]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 1.0 }'
1 0:[0507:151128]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 1.0001 }'
1.000100e+00
0:[0507:151131]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 300.0001
}'
3.000001e+02

If so, I'd expect that to be documented. I don't see it. Moreover, OFMT
comes from POSIX, which say anything like this either.

It doesn't seem to have anything to do with whether the value is the
result of arithmetic:

0:[0507:152027]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 300.0 +
1.0 - 1.0 }'
300
0:[0507:152035]:sun-go:~/gawk$ awk 'BEGIN { OFMT = "%e"; print 0.25 * 4
}'
1

However, gawk could be constant-folding these expressions. Let's use
run-time data:

$ awk 'BEGIN { OFMT = "%e" }; { print $1 }'
1 1
1.5
1.5

$ awk 'BEGIN { OFMT = "%e" }; { print $1 + 0 }'
1 1
1.5
1.500000e+00

So the OFMT is ignored entirely unless the input is converted to a
numeric string by a forced calculation, and then it's still ignored for
values with a zero fractional part.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: awk not outputting in scientific notation despite %e

<u398ob$3i8oh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1439&group=comp.lang.awk#1439

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Mon, 8 May 2023 00:29:30 +0200
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <u398ob$3i8oh$1@dont-email.me>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 7 May 2023 22:29:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0e44f2f46869eab47ef143062b976597";
logging-data="3744529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BYyaX1IH6f0h71skSkIzl"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:H2JdpYVaPKOvHBCpXc2hSLPXfZ4=
In-Reply-To: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
 by: Janis Papanagnou - Sun, 7 May 2023 22:29 UTC

On 07.05.2023 23:36, Ross wrote:
> I am using awk for some basic calculations and want to force my
> output to be in scientific notation. I am using OFMT="%.15e" to
> accomplish this. On most machines, I get the expected output:
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 4.483923595133619e+26
>
> But a version of awk on my cluster gives:
>
> $ awk --version | head --lines=2
> GNU Awk 4.0.2
> Copyright (C) 1989, 1991-2012 Free Software Foundation.
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 448392359513361882871234560
>

> Why is this version/configuration of awk not outputting to scientific
> notation as requested? How can I portably get my desired result
> (4.483923595133619e+26)?
>
> (This question was originally posted to stackexchange at
> https://stackoverflow.com/questions/76187717/awk-not-outputting-in-scientific-notation-despite-e
> but it didn't get much attention and I was directed here instead.)
>

I can reproduce that with a GNU awk version 3, 4, and 5, respectively.
You've already got some analysis and explanations from Kaz. I suggest
to resort to printf (instead of using print) then...

$ awk 'BEGIN { printf "%.15e\n", 4.483923595133619e+29 / 1000 }'
4.483923595133619e+26

Janis

Re: awk not outputting in scientific notation despite %e

<87r0rrbrzd.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1440&group=comp.lang.awk#1440

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Sun, 07 May 2023 17:13:10 -0700
Organization: None to speak of
Lines: 81
Message-ID: <87r0rrbrzd.fsf@nosuchdomain.example.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4721a668038f60b2fde1557d72b01f29";
logging-data="3783201"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199qq/GzLJku+bnQ3XuTWYy"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:A34BJ06xmONhQ69Fz/JKRhCfSGU=
sha1:CeL3+h2trXr7+ErveigqftkMt1M=
 by: Keith Thompson - Mon, 8 May 2023 00:13 UTC

Ross <chaudhry.ross@gmail.com> writes:
> I am using awk for some basic calculations and want to force my output
> to be in scientific notation. I am using OFMT="%.15e" to accomplish
> this. On most machines, I get the expected output:
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 4.483923595133619e+26
>
> But a version of awk on my cluster gives:
>
> $ awk --version | head --lines=2
> GNU Awk 4.0.2
> Copyright (C) 1989, 1991-2012 Free Software Foundation.
>
> $ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
> 448392359513361882871234560
>
> Why is this version/configuration of awk not outputting to scientific
> notation as requested? How can I portably get my desired result
> (4.483923595133619e+26)?
>
> (This question was originally posted to stackexchange at
> https://stackoverflow.com/questions/76187717/awk-not-outputting-in-scientific-notation-despite-e
> but it didn't get much attention and I was directed here instead.)

I think you've found a longstanding bug in gawk.

Here's the test program I used:
```
BEGIN {
x = 9
y = 9.001
z = 9e50

printf("Using printf: %.15e\n", x)
printf(" %.15e\n", y)
printf(" %.15e\n", z)

OFMT="%.15e"
printf("Using OFMT: "); print(x)
printf(" "); print(y)
printf(" "); print(z)
} ```

The output should (I think) be the same for printf and print with OFMT.

On my Ubuntu system, all versions of gawk (I tried versions from 3.1.8
to 5.2.1 and the latest version from git) produced the same (incorrect)
output:
```
Using printf: 9.000000000000000e+00
9.000999999999999e+00
9.000000000000000e+50
Using OFMT: 9
9.000999999999999e+00
900000000000000027129553701548362001410714104758272
```

/usr/bin/original-awk has a similar bug but it shows up with different
values.

BTW, in your example you could replace "483923595133619e+29 / 1000" by
"4.83923595133619e+43"; it produces the same result and is a bit
simpler. With a bit of experimenting, I found that the output is
incorrect for 9, correct for values slightly larger than 9, and
incorrect for very large values.

I don't know what caused the bug. Looking into the gawk source, it does
its own output formatting rather than relying on sprintf, to avoid
problems with things like OFMT="%s" (not sure that's worthwhile, since
the behavior is undefined if OFMT isn't a floating-point conversion
specification).

I've submitted a bug report to the bug-gawk mailing list. I'll post the
URL when the archive updates.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: awk not outputting in scientific notation despite %e

<87bkivbogw.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1441&group=comp.lang.awk#1441

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Sun, 07 May 2023 18:29:03 -0700
Organization: None to speak of
Lines: 13
Message-ID: <87bkivbogw.fsf@nosuchdomain.example.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4721a668038f60b2fde1557d72b01f29";
logging-data="3924175"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195tU33055SeKPnypnSuL61"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:AByI6EL4vFtJ+NWMwfBh3cNsdX0=
sha1:Y6S5uA86Et9DaNH7d89yePlUUQw=
 by: Keith Thompson - Mon, 8 May 2023 01:29 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
> I've submitted a bug report to the bug-gawk mailing list. I'll post the
> URL when the archive updates.

Here's the bug report:

https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: awk not outputting in scientific notation despite %e

<877ctjbkaf.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1442&group=comp.lang.awk#1442

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Sun, 07 May 2023 19:59:20 -0700
Organization: None to speak of
Lines: 62
Message-ID: <877ctjbkaf.fsf@nosuchdomain.example.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4721a668038f60b2fde1557d72b01f29";
logging-data="3949846"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+s5K9eU4/lccojqK3VR3rV"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:OE87eZfyV0oUzVeLYkivIP6ZtaM=
sha1:9JaCy7asp0v9RUvzvAcFaznNOYc=
 by: Keith Thompson - Mon, 8 May 2023 02:59 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> [...]
>> I've submitted a bug report to the bug-gawk mailing list. I'll post the
>> URL when the archive updates.
>
> Here's the bug report:
>
> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html

And thanks to a reply on the mailing list from Andrew J. Schorr:
https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00011.html
I no longer believe this is a bug.

What I should have noticed is that the values for which setting
"OFMT=.15e" *doesn't* produce output in scientific notation are
precisely the values that are mathematically integers. Sufficiently
large floating-point values are always equal to integers.

Here's what POSIX says:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html

A numeric value that is exactly equal to the value of an integer
(see Concepts Derived from the ISO C Standard) shall be converted to
a string by the equivalent of a call to the sprintf function (see
String Functions) with the string "%d" as the fmt argument and the
numeric value being converted as the first and only expr argument.

And here's a demonstration showing what's happening:
```
$ cat foo.awk
#!/usr/bin/awk -f

BEGIN {
OFMT="%.16e"
for (i = 50; i <= 55; i ++) {
x = 2 ** i - 0.5
printf("2**%d - 0.5 = %.3f = ", i, x)
print(x)
}
} $ ./foo.awk
2**50 - 0.5 = 1125899906842623.500 = 1.1258999068426235e+15
2**51 - 0.5 = 2251799813685247.500 = 2.2517998136852475e+15
2**52 - 0.5 = 4503599627370495.500 = 4.5035996273704955e+15
2**53 - 0.5 = 9007199254740992.000 = 9007199254740992
2**54 - 0.5 = 18014398509481984.000 = 18014398509481984
2**55 - 0.5 = 36028797018963968.000 = 36028797018963968
$ ```

The value in the parent article was 4.483923595133619e+29 / 1000, which
is an exact integer value (whether evaluated mathematically or in double
precision floating point).

Using printf rather than setting OFMT is the *solution* to the original
problem, not a workaround for a bug.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: awk not outputting in scientific notation despite %e

<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1443&group=comp.lang.awk#1443

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:622a:1445:b0:3f3:9080:dfa2 with SMTP id v5-20020a05622a144500b003f39080dfa2mr617134qtx.12.1683514946514;
Sun, 07 May 2023 20:02:26 -0700 (PDT)
X-Received: by 2002:a05:622a:4ce:b0:3ef:8159:5ec4 with SMTP id
q14-20020a05622a04ce00b003ef81595ec4mr4125265qtx.9.1683514946242; Sun, 07 May
2023 20:02:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Sun, 7 May 2023 20:02:25 -0700 (PDT)
In-Reply-To: <87bkivbogw.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=198.11.30.72; posting-account=ZhrElQoAAAAtGhDcjT_0NQ3OeIks2UZd
NNTP-Posting-Host: 198.11.30.72
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com> <87bkivbogw.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
Subject: Re: awk not outputting in scientific notation despite %e
From: chaudhry.ross@gmail.com (Ross)
Injection-Date: Mon, 08 May 2023 03:02:26 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: Ross - Mon, 8 May 2023 03:02 UTC

On Sunday, 7 May 2023 at 19:30:47 UTC-6, Keith Thompson wrote:
> Keith Thompson <Keith.S.T...@gmail.com> writes:
> [...]
> > I've submitted a bug report to the bug-gawk mailing list. I'll post the
> > URL when the archive updates.
> Here's the bug report:
>
> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html
> --
> Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
> Working, but not speaking, for XCOM Labs
> void Void(void) { Void(); } /* The recursive call of the void */

Ok, thanks for the quick and comprehensive response, everybody. I'll use printf as a workaround and keep an eye on the bug report.

Re: awk not outputting in scientific notation despite %e

<251e2de8-983b-4e28-b232-4e6dfba668cen@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1444&group=comp.lang.awk#1444

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ad4:4f86:0:b0:5f4:5ed:22cd with SMTP id em6-20020ad44f86000000b005f405ed22cdmr4195536qvb.0.1683515188384;
Sun, 07 May 2023 20:06:28 -0700 (PDT)
X-Received: by 2002:ac8:5c4d:0:b0:3ef:59ab:6775 with SMTP id
j13-20020ac85c4d000000b003ef59ab6775mr4013369qtj.10.1683515188125; Sun, 07
May 2023 20:06:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Sun, 7 May 2023 20:06:27 -0700 (PDT)
In-Reply-To: <071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=198.11.30.72; posting-account=ZhrElQoAAAAtGhDcjT_0NQ3OeIks2UZd
NNTP-Posting-Host: 198.11.30.72
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com> <87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <251e2de8-983b-4e28-b232-4e6dfba668cen@googlegroups.com>
Subject: Re: awk not outputting in scientific notation despite %e
From: chaudhry.ross@gmail.com (Ross)
Injection-Date: Mon, 08 May 2023 03:06:28 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 15
 by: Ross - Mon, 8 May 2023 03:06 UTC

On Sunday, 7 May 2023 at 21:02:27 UTC-6, Ross wrote:
> On Sunday, 7 May 2023 at 19:30:47 UTC-6, Keith Thompson wrote:
> > Keith Thompson <Keith.S.T...@gmail.com> writes:
> > [...]
> > > I've submitted a bug report to the bug-gawk mailing list. I'll post the
> > > URL when the archive updates.
> > Here's the bug report:
> >
> > https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html
> > --
> > Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
> > Working, but not speaking, for XCOM Labs
> > void Void(void) { Void(); } /* The recursive call of the void */
> Ok, thanks for the quick and comprehensive response, everybody. I'll use printf as a workaround and keep an eye on the bug report.

Ah, that response from Andrew makes sense and I appreciate the clarification.

Re: awk not outputting in scientific notation despite %e

<873547bjro.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1445&group=comp.lang.awk#1445

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Sun, 07 May 2023 20:10:35 -0700
Organization: None to speak of
Lines: 23
Message-ID: <873547bjro.fsf@nosuchdomain.example.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4721a668038f60b2fde1557d72b01f29";
logging-data="3949846"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/b7CyIwvJlb+l3jGHXyKSk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:TiG7HxAHFR9HgjoWpaVoLqwgeI4=
sha1:i+EEJpCZfHhZBgIO4fpbxijj7lA=
 by: Keith Thompson - Mon, 8 May 2023 03:10 UTC

Ross <chaudhry.ross@gmail.com> writes:
> On Sunday, 7 May 2023 at 19:30:47 UTC-6, Keith Thompson wrote:
>> Keith Thompson <Keith.S.T...@gmail.com> writes:
>> [...]
>> > I've submitted a bug report to the bug-gawk mailing list. I'll post the
>> > URL when the archive updates.
>> Here's the bug report:
>>
>> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html
>
> Ok, thanks for the quick and comprehensive response, everybody. I'll
> use printf as a workaround and keep an eye on the bug report.

See my latest followup. It's not a bug, and using printf is the correct
solution, not just a workaround. (One could argue that it's a
misfeature in the awk language, but it's hard to avoid in a language
that distinguishes integers from non-integers by value rather than by
type.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Re: awk not outputting in scientific notation despite %e

<20230507220642.766@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1446&group=comp.lang.awk#1446

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Mon, 8 May 2023 05:14:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <20230507220642.766@kylheku.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
<877ctjbkaf.fsf@nosuchdomain.example.com>
Injection-Date: Mon, 8 May 2023 05:14:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4fdb655e6734bca337e87695bb769c87";
logging-data="3980274"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cciD+Xh7VJfANO/j7HbsqHn+qOBKpTzc="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:/mOv58XicdmgCRzjW37oxjNLX74=
 by: Kaz Kylheku - Mon, 8 May 2023 05:14 UTC

On 2023-05-08, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> [...]
>>> I've submitted a bug report to the bug-gawk mailing list. I'll post the
>>> URL when the archive updates.
>>
>> Here's the bug report:
>>
>> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html
>
> And thanks to a reply on the mailing list from Andrew J. Schorr:
> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00011.html
> I no longer believe this is a bug.
>
> What I should have noticed is that the values for which setting
> "OFMT=.15e" *doesn't* produce output in scientific notation are
> precisely the values that are mathematically integers.

That doesn't mean formatting should break.

I don't see the requirement in POSIX that OFMT should bypass the format
for values without a fractional part.

In TXR Lisp, I made sure that even bignums work with ~e:

1> (typeof (expt 2 300))
bignum
2> (fmt "~e" (expt 2 300))
"2.037e90"

There are limitations: it works by conversion to floating-point.

So no, you cannot use it on arbitrarily large integers:

1> (fmt "~e" (expt 2 1000))
"1.072e301"
2> (fmt "~e" (expt 2 2000))
** out-of-range floating-point result
** during evaluation at expr-2:1 of form (fmt "~e" (expt 2 2000))

Better than nothing.

> large floating-point values are always equal to integers.
>
> Here's what POSIX says:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
>
> A numeric value that is exactly equal to the value of an integer
> (see Concepts Derived from the ISO C Standard) shall be converted to
> a string by the equivalent of a call to the sprintf function (see
> String Functions) with the string "%d" as the fmt argument and the
> numeric value being converted as the first and only expr argument.

I think that means, shall be converted to a string *when needed to be
one*. Not that integers should be considered to be strings, so that
OFMT is then bypassed.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: awk not outputting in scientific notation despite %e

<20230508003519.599@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1447&group=comp.lang.awk#1447

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Mon, 8 May 2023 07:36:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20230508003519.599@kylheku.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
<873547bjro.fsf@nosuchdomain.example.com>
Injection-Date: Mon, 8 May 2023 07:36:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4fdb655e6734bca337e87695bb769c87";
logging-data="4020738"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rLxZtrGivBkIl+X8M6njWR5RSnZaSVOE="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:ZzgU0B/5woGbip0nHFdsqfpreD4=
 by: Kaz Kylheku - Mon, 8 May 2023 07:36 UTC

On 2023-05-08, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Ross <chaudhry.ross@gmail.com> writes:
>> On Sunday, 7 May 2023 at 19:30:47 UTC-6, Keith Thompson wrote:
>>> Keith Thompson <Keith.S.T...@gmail.com> writes:
>>> [...]
>>> > I've submitted a bug report to the bug-gawk mailing list. I'll post the
>>> > URL when the archive updates.
>>> Here's the bug report:
>>>
>>> https://lists.gnu.org/archive/html/bug-gawk/2023-05/msg00010.html
>>
>> Ok, thanks for the quick and comprehensive response, everybody. I'll
>> use printf as a workaround and keep an eye on the bug report.
>
> See my latest followup. It's not a bug, and using printf is the correct
> solution, not just a workaround. (One could argue that it's a
> misfeature in the awk language, but it's hard to avoid in a language
> that distinguishes integers from non-integers by value rather than by
> type.)

But printf is in the language, and printf("%e", expr) handles it fine.

The OFMT feature just has to treat numeric-valued expressions
using whatever logic that is already making printf("%e", expr) work.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: awk not outputting in scientific notation despite %e

<06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1448&group=comp.lang.awk#1448

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:622a:1823:b0:3ef:47d1:70f6 with SMTP id t35-20020a05622a182300b003ef47d170f6mr4090430qtc.0.1683558501820;
Mon, 08 May 2023 08:08:21 -0700 (PDT)
X-Received: by 2002:a05:620a:2490:b0:74e:3a3c:2da3 with SMTP id
i16-20020a05620a249000b0074e3a3c2da3mr4297622qkn.1.1683558501134; Mon, 08 May
2023 08:08:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Mon, 8 May 2023 08:08:20 -0700 (PDT)
In-Reply-To: <20230508003519.599@kylheku.com>
Injection-Info: google-groups.googlegroups.com; posting-host=38.76.0.51; posting-account=n5ws7AoAAADMJDAWfsygCPkNAonhHPfT
NNTP-Posting-Host: 38.76.0.51
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com> <87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com> <873547bjro.fsf@nosuchdomain.example.com>
<20230508003519.599@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>
Subject: Re: awk not outputting in scientific notation despite %e
From: aschorr@telemetry-investments.com (Andrew Schorr)
Injection-Date: Mon, 08 May 2023 15:08:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2780
 by: Andrew Schorr - Mon, 8 May 2023 15:08 UTC

Hi,

On Monday, May 8, 2023 at 3:36:57 AM UTC-4, Kaz Kylheku wrote:
> But printf is in the language, and printf("%e", expr) handles it fine.
>
> The OFMT feature just has to treat numeric-valued expressions
> using whatever logic that is already making printf("%e", expr) work.

I thought Keith clarified this issue above. The POSIX spec says that integer values
should be converted with an implicit "%d" instead of using CONVFMT.
It is also discussed here in the gawk manual:
https://www.gnu.org/software/gawk/manual/html_node/Strings-And-Numbers.html
"As a special case, if a number is an integer, then the result of converting it to a string is always an integer, no matter what the value of CONVFMT may be."

You may ask why OFMT and CONVFMT are handled the same way. I can think of 3 reasons:
1. It's the same code path inside gawk.
2. Historically, there was no distinction between OFMT and CONVFMT, but it was added to address
some corner cases. You can find a discussion of this in the Posix AWK spec.
3. The POSIX awk spec simply codifies how Unix awk has always worked, and this is how it works.

If you don't like it, please use printf to request explicitly what you want.. The OFMT and CONVFMT logic
is intended to do the right thing, and it does so in the vast majority of usage cases.

Regards,
Andy

Re: awk not outputting in scientific notation despite %e

<20230508160934.318@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1449&group=comp.lang.awk#1449

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Mon, 8 May 2023 23:31:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <20230508160934.318@kylheku.com>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
<873547bjro.fsf@nosuchdomain.example.com> <20230508003519.599@kylheku.com>
<06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 8 May 2023 23:31:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="14910b78f634c098f11cba26610d12a1";
logging-data="18483"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NhSbfmSCXBnWnoFQvrTJ/Nglr6IDrwRU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:wy+t1KN+MMiM+szpJqLcFyBtTI4=
 by: Kaz Kylheku - Mon, 8 May 2023 23:31 UTC

On 2023-05-08, Andrew Schorr <aschorr@telemetry-investments.com> wrote:
> Hi,
>
> On Monday, May 8, 2023 at 3:36:57 AM UTC-4, Kaz Kylheku wrote:
>> But printf is in the language, and printf("%e", expr) handles it fine.
>>
>> The OFMT feature just has to treat numeric-valued expressions
>> using whatever logic that is already making printf("%e", expr) work.
>
> I thought Keith clarified this issue above. The POSIX spec says that integer values
> should be converted with an implicit "%d" instead of using CONVFMT.

The requirement applies to CONVFMT; it isn't written that it applies to
OFMT.

It is written that CONVFMT is newer: OFMT came first and then CONVFMT
was derived from it as a kind of fork to separate the messy semantics
of field conversion from printing arbitrary arguments (or something
like that).

It is not clear that requirements applying to the derivative CONVFMT
should flow backwards into OFMT. Generally speaking, if a document
introduces some Y that is a new entity, similar to and inheriting
requirements from an existing X, and then also gives requirements only
about Y, those Y requirements do not propagate back to X; they
are one of the attributes of Y that distinguish it from X.

Under CONVFMT, the results of conversion are not going to the display;
they loop back into the program. CONVFMT controls how numbers convert to
strings. If the floating-point format applies to integer values, it can
mess up associative array keys involving integers, which is quite
common.

Therefore, it's easy to see why a hack like that would be in CONVFMT,
but not required in OFMT.

Upon reading the rationale, one might have the impression that
this is one of those corner cases that originally existed in OFMT
that were separated out into CONVFMT.

Therfore, historic knowledge that OFMT implementations before CONFVMT
existed had this hack behavior doesn't amount to anything. POSIX
changed the behavior by introducing an entirely new variable,
such that OFMT no longer controlled conversions, breaking programs
depending on that. At that time, OFMT should have been considered
to not have the %d requirement any more, in the same stroke.

Re: awk not outputting in scientific notation despite %e

<878rdy9v5t.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1450&group=comp.lang.awk#1450

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.awk
Subject: Re: awk not outputting in scientific notation despite %e
Date: Tue, 09 May 2023 01:59:42 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <878rdy9v5t.fsf@bsb.me.uk>
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com>
<87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com>
<873547bjro.fsf@nosuchdomain.example.com>
<20230508003519.599@kylheku.com>
<06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>
<20230508160934.318@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="f9cd3c4579f69aace78c15188c9190a2";
logging-data="37217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NYHPB+lb080l5lam6Hm7ceVzPlfnLYnM="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:zE6Nzt+vJ0C9Fuz1UGwb+l1F4KQ=
sha1:lSMgeTafpPzG0xNoputfQKddDCo=
X-BSB-Auth: 1.78123f77bbfe51847021.20230509015942BST.878rdy9v5t.fsf@bsb.me.uk
 by: Ben Bacarisse - Tue, 9 May 2023 00:59 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-05-08, Andrew Schorr <aschorr@telemetry-investments.com> wrote:
>> Hi,
>>
>> On Monday, May 8, 2023 at 3:36:57 AM UTC-4, Kaz Kylheku wrote:
>>> But printf is in the language, and printf("%e", expr) handles it fine.
>>>
>>> The OFMT feature just has to treat numeric-valued expressions
>>> using whatever logic that is already making printf("%e", expr) work.
>>
>> I thought Keith clarified this issue above. The POSIX spec says that
>> integer values should be converted with an implicit "%d" instead of
>> using CONVFMT.
>
> The requirement applies to CONVFMT; it isn't written that it applies to
> OFMT.

I think it is. Where OFMT applies (in print) the text refers to the
conversion that otherwise uses CONVFMT:

"All expression arguments shall be taken as strings, being converted if
necessary; this conversion shall be as described in Expressions in
awk, with the exception that the printf format in OFMT shall be used
instead of the value in CONVFMT."

and it's the referenced text that has the integer exception with CONVFMT
used for other values. Using OFMT in place of CONVFMT in that text does
not remove the exception.

Of course, if the integer exception was added to the "Exceptions in awk"
section at some later stage, the effect on the use of OFMT in print
statements might have been unintentional.

--
Ben.

Re: awk not outputting in scientific notation despite %e

<cee11942-12b6-4864-b764-f9ba0d2df11en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1451&group=comp.lang.awk#1451

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:3910:b0:757:9fb7:5317 with SMTP id qr16-20020a05620a391000b007579fb75317mr81038qkn.14.1683637430490;
Tue, 09 May 2023 06:03:50 -0700 (PDT)
X-Received: by 2002:a05:622a:1a1d:b0:3e3:8172:ff23 with SMTP id
f29-20020a05622a1a1d00b003e38172ff23mr5145716qtb.13.1683637430095; Tue, 09
May 2023 06:03:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Tue, 9 May 2023 06:03:49 -0700 (PDT)
In-Reply-To: <878rdy9v5t.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=38.76.0.51; posting-account=n5ws7AoAAADMJDAWfsygCPkNAonhHPfT
NNTP-Posting-Host: 38.76.0.51
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com> <87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com> <873547bjro.fsf@nosuchdomain.example.com>
<20230508003519.599@kylheku.com> <06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>
<20230508160934.318@kylheku.com> <878rdy9v5t.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cee11942-12b6-4864-b764-f9ba0d2df11en@googlegroups.com>
Subject: Re: awk not outputting in scientific notation despite %e
From: aschorr@telemetry-investments.com (Andrew Schorr)
Injection-Date: Tue, 09 May 2023 13:03:50 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2500
 by: Andrew Schorr - Tue, 9 May 2023 13:03 UTC

On Monday, May 8, 2023 at 8:59:47 PM UTC-4, Ben Bacarisse wrote:
> I think it is. Where OFMT applies (in print) the text refers to the
> conversion that otherwise uses CONVFMT:
>
> "All expression arguments shall be taken as strings, being converted if
> necessary; this conversion shall be as described in Expressions in
> awk, with the exception that the printf format in OFMT shall be used
> instead of the value in CONVFMT."
>
> and it's the referenced text that has the integer exception with CONVFMT
> used for other values. Using OFMT in place of CONVFMT in that text does
> not remove the exception.

I think that's right. It also says this:

"The intent has been to specify historical practice in almost all cases."

And I think the history is that all implementations of awk have always converted
integral values using the equivalent of "%d", regardless of the CONVFMT or OFMT setting.

Regards,
Andy

Re: awk not outputting in scientific notation despite %e

<a5b592e4-99d4-43c6-a046-34ab79109454n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1641&group=comp.lang.awk#1641

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ac8:6608:0:b0:41b:aeda:d186 with SMTP id c8-20020ac86608000000b0041baedad186mr74314qtp.4.1698444839165;
Fri, 27 Oct 2023 15:13:59 -0700 (PDT)
X-Received: by 2002:a9d:6015:0:b0:6b7:3eba:59d3 with SMTP id
h21-20020a9d6015000000b006b73eba59d3mr934887otj.6.1698444838976; Fri, 27 Oct
2023 15:13:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 27 Oct 2023 15:13:58 -0700 (PDT)
In-Reply-To: <cee11942-12b6-4864-b764-f9ba0d2df11en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:ac80:1475:6079:42f9;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:ac80:1475:6079:42f9
References: <2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com>
<87r0rrbrzd.fsf@nosuchdomain.example.com> <87bkivbogw.fsf@nosuchdomain.example.com>
<071b289a-0c63-44c7-bab7-9b1aa07ccf8bn@googlegroups.com> <873547bjro.fsf@nosuchdomain.example.com>
<20230508003519.599@kylheku.com> <06f41b41-3e4a-4b2c-9d8e-5887dede212cn@googlegroups.com>
<20230508160934.318@kylheku.com> <878rdy9v5t.fsf@bsb.me.uk> <cee11942-12b6-4864-b764-f9ba0d2df11en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a5b592e4-99d4-43c6-a046-34ab79109454n@googlegroups.com>
Subject: Re: awk not outputting in scientific notation despite %e
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Fri, 27 Oct 2023 22:13:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4004
 by: Kpop 2GM - Fri, 27 Oct 2023 22:13 UTC

On Tuesday, May 9, 2023 at 9:03:51 AM UTC-4, Andrew Schorr wrote:
> On Monday, May 8, 2023 at 8:59:47 PM UTC-4, Ben Bacarisse wrote:
> > I think it is. Where OFMT applies (in print) the text refers to the
> > conversion that otherwise uses CONVFMT:
> >
> > "All expression arguments shall be taken as strings, being converted if
> > necessary; this conversion shall be as described in Expressions in
> > awk, with the exception that the printf format in OFMT shall be used
> > instead of the value in CONVFMT."
> >
> > and it's the referenced text that has the integer exception with CONVFMT
> > used for other values. Using OFMT in place of CONVFMT in that text does
> > not remove the exception.
> I think that's right. It also says this:
>
> "The intent has been to specify historical practice in almost all cases."
>
> And I think the history is that all implementations of awk have always converted
> integral values using the equivalent of "%d", regardless of the CONVFMT or OFMT setting.
>
> Regards,
> Andy

That would *nearly* be true if not for gawk + GMP's lovely behavior with parsing the decimal dot :

gawk -Mbe 'BEGIN { OFS = RS;

.. . . . . print x = 10.^10 * 5^12 * 3, --x, "--------------",
.. . . . . . . . . . y = 10^10 * 5^12 * 3, --y, "-----------------", 2^63-1 }'

7324218750000000000
7324218750000000000
--------------
7324218750000000000
7324218749999999999
-----------------
9223372036854775807

everything about "x" and "y" are mathematically identical - both are ***supposed*** to be integers,

but the mere presence of an extra dot (".") at the 1st "10" ( "10." instead of "10") causes gawk + GMP to treat the whole thing as double-precision floating point value instead of GMP's arbitrary precision integers.

which can be confirmed when using the -d- flag to dump variables to /dev/stdout :

x: 7.32421875e+18
y: 7324218749999999999

The same undesirable effect also occurs when the exponent is written as "10^10." instead of "10^10". but interestingly enough, if one adds a

.. . . x = int(x)

before

.. . . . --x

then it circumvents this annoyance and returns a properly decremented integer value instead

— The 4Chan Teller

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor