bug-gawk
[Top][All Lists]
Advanced

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

Re: Support of log10?


From: Neil R. Ormos
Subject: Re: Support of log10?
Date: Wed, 23 Jun 2021 17:48:40 -0500 (CDT)

Peng Yu wrote:

> $ seq 3 | awk -v 'OFS=\t' -v OFMT=%.20g -e 'function log10(x) { return
> log(x)/log(10); } { print "log10(" 10^$1 ")", log10(10^$1) }'
> log10(10)     1
> log10(100)    2
> log10(1000)   2.9999999999999995559

> I don't find a native support of log10(). But if
> I implement log10 with log, I got the above
> problem. The result of log10(1000) should be
> exact 3. But it is not.

> Is it worthwhile to consider the support of
> log10 in gawk?

Attention is drawn to the manual[*], which
explains the result observed and how to fix it:

| 16.3 Arbitrary-Precision Arithmetic Features in gawk

| By default, gawk uses the double-precision
| floating-point values [...]  However, if it was
| compiled to do so, and the -M command-line
| option is supplied, gawk uses the GNU MPFR and
| GNU MP (GMP) libraries for arbitrary-precision
| arithmetic on numbers.

> echo 3 | gawk -M -v 'OFS=\t' -v OFMT=%.20g           \
     -e 'function log10(x) { return log(x)/log(10); }  \
     { print "log10(" 10^$1 ")", log10(10^$1) }'

log10(1000)     3


See also footnote 98 and its referencing text.


[*] <https://www.gnu.org/software/gawk/manual/html_node/MPFR-features.html>



reply via email to

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