[Top][All Lists]

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

Re: Why inf is not supported by gawk?

From: Bob Proulx
Subject: Re: Why inf is not supported by gawk?
Date: Fri, 25 Jun 2021 14:46:30 -0600

Peng Yu wrote:
> The question is why it makes sense not to support inf in awk.

That was answered in the documentation.  I will repeat an abbreviated
version here.  The full wording is in the documenation.

    Historically, 'awk' has converted any nonnumeric-looking string to the
    numeric value zero, when required.
       The first problem is that both of these are clear changes to
    historical practice:
       * Allowing completely alphabetic strings to have valid numeric values
         is also a very severe departure from historical practice.
    The solution implemented in 'gawk' is as follows:

       * Without '--posix', 'gawk' interprets the four string values '+inf',
         '-inf', '+nan', and '-nan' specially, producing the corresponding
         special numeric values.  The leading sign acts a signal to 'gawk'
         (and the user) that the value is really numeric.  Hexadecimal
         floating point is not supported (unless you also use
         '--non-decimal-data', which is _not_ recommended).  For example:

The above is very clear.  I could rewrite it using my own words but
that would simply introduce possible error.  Therefore I suggest you
read the documentation directly.

> What is the disadvantage of support inf besides that with "+" and "-" in awk?

It is a disadvantage because it breaks historical use.  Broken.  If it
did so then bug reports saying that it broke that usage would be
valid.  Adding bugs to awk is not good.

> Besides C, ruby supports it without "+".

That does not matter.  AWK is neither C nor Ruby.

However if you wish to use either C or Ruby, or Python or Javascript,
then you are encouraged to do so.  Different languages are different.
They each have advantages and disadvantages.  They were each developed
with different goals in mind.

> https://stackoverflow.com/questions/5778295/how-to-express-infinity-in-ruby
> python also supports it.

C, Ruby, Python, Perl, Javascript, AWK, those are all different and
unique languages and each have their own rules.  They are different.

> The list goes on.

These languages are not the same.  Making this comparison is very
similar to a child begging to go to a party because "other parents are
letting their children go."  We have all tried that argument before.
That argument is not productive.  It doesn't work with parents either.

> It is an anomaly that awk does not support the version of inf without
> + and - signs.

When AWK was created there was no support for these constructs.  Now
that these constructs have been added to the language they must
coexist with the existing structure of the language.  Doing anything
else would be introducing bugs.  Therefore, NO.

> > This is explained in detail in the documentation.  I'll quote it.
> >     ...
> These just explain what is it but not why is it so.

Why is anything?  Why is why?  Why is anything the way anything is so?
We have been searching for the answer to why for as long as we have
been alive.  We will not find it here on the Internet.


reply via email to

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