[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>
- Support of log10?, Peng Yu, 2021/06/23
- Re: Support of log10?,
Neil R. Ormos <=
- Re: Support of log10?, Peng Yu, 2021/06/23
- Re: Support of log10?, Eli Zaretskii, 2021/06/24
- Re: Support of log10?, Peng Yu, 2021/06/24
- Re: Support of log10?, Ed Morton, 2021/06/24
- Re: Support of log10?, Eli Zaretskii, 2021/06/24
- Re: Support of log10?, Peng Yu, 2021/06/24
Re: Support of log10?, Nelson H. F. Beebe, 2021/06/23
Re: Support of log10?, arnold, 2021/06/24