[Top][All Lists]

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

[bug-gawk] Stale cache of MPFR formatted+rounded strings

From: Nethox
Subject: [bug-gawk] Stale cache of MPFR formatted+rounded strings
Date: Sun, 31 Dec 2017 12:09:17 +0100

Compiled from the tarball on GNU/Linux x86:
$ gawk -V | head -1
GNU Awk 4.2.0, API: 2.0 (GNU MPFR 3.1.5, GNU MP 6.1.2)

Minimal reproducible test:
$ cat mpfrrndeval.min.awk
        pi = 3.1416
        OFMT = "%.f"
        print pi  # ROUNDMODE = "N" by default.
        ROUNDMODE = "U"
        print pi
$ gawk -M -f ./mpfrrndeval.min.awk
$ cat mpfrrndeval.min.ok

GAWK seems to cache the MPFR formatted+rounded string for each variable printed with OFMT or CONVFMT (not printf). However, this cache is not discarded when ROUNDMODE is assigned to a different mode, so only the first printing is correct for certain.
Workarounds: reassigning pi=3.1416 or pi=pi+0 before every print evaluation; reassigning OFMT/CONVFMT to a different precision before every print evaluation; replacing each print lvalue argument with rvalues like the literal 3.1416 or pi+0.
Useless things: --lint, --no-optimize.

I attach a more complete test and results (filenames without .min).


Attachment: mpfrrndeval.awk
Description: Binary data

Attachment: mpfrrndeval.min.awk
Description: Binary data

Attachment: mpfrrndeval.min.ok
Description: Binary data

Attachment: mpfrrndeval.ok
Description: Binary data

reply via email to

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