awk and stdio-common/tst-printf-format-as-double* trouble (mpfr support needed)

Vincent Lefevre vincent@vinc17.net
Wed Jan 8 12:50:26 GMT 2025


[Not sure whether libc-alpha should be kept in the Cc as this has
become off-topic, though this may still interest developers in
general.]

On 2025-01-08 05:01:56 -0700, arnold@skeeve.com wrote:
> Vincent Lefevre <vincent@vinc17.net> wrote:
> 
> > > > At the time, I thought I was getting decimal (exact) arithmetic.
> >                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Note that decimal arithmetic and exact arithmetic are two different
> > things.
> 
> Then I don't understand anything. Not that it matters.

Well, at least this matters for the manual:

https://www.gnu.org/software/gawk/manual/html_node/Computer-Arithmetic.html

where I can read:

  Decimal arithmetic

    This is the kind of arithmetic you learned in elementary school,
    using paper and pencil (and/or a calculator). In theory, numbers
    can have an arbitrary number of digits on either side (or both
    sides) of the decimal point, and the results of a computation are
    always exact.

If you think that "the results of a computation are always exact",
what is the result of 1/3 in decimal? And what is the result of
sqrt(2) in decimal?

I hope that you will be able to understand with these questions.
Perhaps you just meant "exact arithmetic" there[*], which is indeed
possible in elementary school, but just with the basic arithmetic
operations (+, -, *, /) and on simple numbers, so keeping result
in decimal when possible or as fractions (so this is actually
rational arithmetic). But gawk supports more than that.

[*] I'm not sure, because for integer arithmetic, it is said "The
advantage to integer numbers is that they represent values exactly.",
which would also be the case with exact arithmetic.

Note also that behind "decimal arithmetic", i.e. computing in base 10,
you can have things like
  * decimal integer arithmetic,
  * decimal fixed-point arithmetic,
  * decimal floating-point arithmetic,
each with their own limitations.

And in Table 16.2, "Minimum positive nonzero value" should actually
be "Minimum positive normal value". See for instance the examples
there:
  https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Double-precision_examples

Regards,

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Libc-alpha mailing list