gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, gawk-5.3-stable, updated. gawk-4.1.0-5578-gf50e920c


From: Arnold Robbins
Subject: [SCM] gawk branch, gawk-5.3-stable, updated. gawk-4.1.0-5578-gf50e920c
Date: Sun, 20 Oct 2024 08:18:48 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, gawk-5.3-stable has been updated
       via  f50e920cbff8f163d5a7f8ffa58f69a9db5f76c4 (commit)
      from  3b4d466117be48c47562b94c0560bb216e8b0d88 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=f50e920cbff8f163d5a7f8ffa58f69a9db5f76c4

commit f50e920cbff8f163d5a7f8ffa58f69a9db5f76c4
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Sun Oct 20 15:18:27 2024 +0300

    Add commentary on adjust_uint from Paul Eggert.

diff --git a/ChangeLog b/ChangeLog
index d0b6fa8c..4434aa91 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-10-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * floatcomp.c (adjust_uint): Add commentary.
+
 2024-10-13         Arnold D. Robbins     <arnold@skeeve.com>
 
        * NEWS: Updated.
@@ -13,7 +17,7 @@
        match is exactly at the end.
        * re.c (make_regexp): Add backslash to the list of
        characters which sets the maybe_long field.
-       
+
 2024-09-25         Arnold D. Robbins     <arnold@skeeve.com>
 
        Clean up spurious newlines in pretty printer output.
diff --git a/floatcomp.c b/floatcomp.c
index e7eafc90..65f2f3ab 100644
--- a/floatcomp.c
+++ b/floatcomp.c
@@ -95,8 +95,36 @@ adjust_uint(uintmax_t n)
         * values, strip leading nonzero bits of integers that are so large
         * that they cannot be represented exactly as AWKNUMs, so that their
         * low order bits are represented exactly, without rounding errors.
-        * This is more desirable in practice, since it means the user sees
-        * integers that are the same width as the AWKNUM fractions.
+        *
+        * When computing with integers that AWKNUM cannot represent exactly,
+        * GAWK uses AWKNUM to approximate wraparound integer arithmetic
+        * using the widest integer that AWKNUM can represent this time.
+        * GAWK prefers to lose excess high-order information instead of
+        * the more-usual rounding that would lose low-order information.
+        *
+        * Typically uintmax_t is 64-bit and AWKNUM is IEEE 754 binary64,
+        * so AWKNUM_FRACTION_BITS is DBL_MANT_DIG (i.e., 53) and
+        * some 64-bit uintmax_t values have nonzero bits that are too widely
+        * spread apart to fit into AWKNUM's 53-bit significand.
+        * For example, let N = 8 + 2**62 (0x4000000000000008), one such value.
+        * Then ((AWKNUM) N) equals 2**62 (0x4000000000000000) due to rounding,
+        * whereas ((AWKNUM) adjust_uint (N)) exactly equals (adjust_uint (N))
+        * which is 8 (in other words, N modulo 2**56),
+        * because N's low-order 3 bits are zero and 56 = 53 + 3.
+        * In this example, adjust_uint implements 56-bit wraparound
+        * integer arithmetic (not counting the sign bit).
+        * Other examples implement wider or narrow wraparound arithmetic,
+        * depending on how many low-order bits are zero.
+        *
+        * Using adjust_uint better matches expectations
+        * with GAWK expressions like compl(1).
+        * With adjust_uint, compl(1) evaluates to 0x3ffffffffffffe
+        * which makes sense if the word size is 54 bits this time;
+        * without it, compl(1) would evaluate to 0x40000000000000
+        * which is nonsense no matter what the word size would be.
+        * (Perhaps it would be even better if compl(1) evaluated to -2,
+        * i.e., two's complement in an infinitely wide word,
+        * but that is a matter for another day.)
         */
        int wordbits = CHAR_BIT * sizeof n;
        if (AWKNUM_FRACTION_BITS < wordbits) {

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog   |  6 +++++-
 floatcomp.c | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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