bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Incorrect output with OFMT="%.15e"


From: Keith Thompson
Subject: Incorrect output with OFMT="%.15e"
Date: Sun, 7 May 2023 16:50:40 -0700

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -DNDEBUG
uname output: Linux bomb20 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17
17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Gawk Version: 5.2.1

Attestation 1:
I have read https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
Yes

Attestation 2:
I have not modified the sources before building gawk.
True

Description:
References:
https://stackoverflow.com/q/76187717/827263
comp.lang.awk, message-id
<2e2d8865-c983-4388-a7a0-0e5ca7c5d67en@googlegroups.com> 2023-05-07
Subject: awk not outputting in scientific notation despite %"

Repeat-By:
I ran the following program:

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)
}

on Ubuntu using versions of awk from 3.1.8 to 5.2.1.  The output was
consistently:
```
Using printf: 9.000000000000000e+00
              9.000999999999999e+00
              9.000000000000000e+50
Using OFMT:   9
              9.000999999999999e+00
              900000000000000027129553701548362001410714104758272
```

The output should be in scientific notation for all values.
Note that the behavior differs for different values.
(/usr/bin/original-awk and mawk have a similar bug, but the
output is slightly different.)

Using printf rather than setting OAWK is a straightforward
workaround.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]