[Top][All Lists]

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

Re: Support of log10?

From: Peng Yu
Subject: Re: Support of log10?
Date: Thu, 24 Jun 2021 09:31:03 -0500

On 6/24/21, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Peng Yu <pengyu.ut@gmail.com>
>> Date: Thu, 24 Jun 2021 09:01:47 -0500
>> Cc: ormos-gnulists17@ormos.org, bug-gawk@gnu.org
>> > Who said you will always get exactly 3 if you have log10?
>> Because the number 1000 can be represent in float exactly, and the
>> answer 3 can be represent in float exactly. Therefore, the correct
>> result for log10(1000) must be exact 3 in float. Anything that
>> deviated from it, no matter how small, is not exactly correct.
> But there's no guarantee the function log10 of any particular C
> library will give you that exact result.  You just expect that, but
> there's no guarantee.

How do you know there is no guarantee? I tried with log10 in C, it
gives 3 for 1000.

>> > And why are exact powers of 10 even interesting enough to justify yet
>> > another built-in function?
>> I can ask the same question. Why it is justified not include it. Given
>> it is trivial to include it?
> Because we don't want to bloat Gawk unnecessarily.  (And no, it is not
> "trivial".)

I don't understand why it is not simple. It seems to be trivial, given
some math.h functions have already been included. It sounds like it is
just to add almost the same code except for the change of function

I am not asking any random functions.

Given some functions in math.h are already in, intuitively, people
could assume other math.h functions should also be in. It is a
surprise that not all functions are in.

If none math.h functions were in awk, then I can accept your argument
of not bloating awk features. But including some math.h functions but
not all, yet saying yon don't want to bloat its interface is
illogical, unless you can demonstrate how the functions are selected
and how often each function is used in practice (backed up by real
data). Otherwise, the choice of what functions to add is just a
personal opinion. People can always argue they should be included.

>> > After all, if you are only interested in
>> > exact powers of 10, you don't need a math function at all, you simply
>> > count the zero digits in the string representation of the number.
>> No. 1000 is just an example that has an exact result in float. There
>> can be other examples that has exact answers in float.
> Only integral powers of 10 will have an exact result from log10.

Another issue is when rounding has to occur that has to be rounded to
the closest numbers that can be represented in float. When the
rounding is not so, I would consider it an error, no matter how small
the rounding deviation is.


reply via email to

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