bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Awk cannot properly deal with too small numbers.


From: arnold
Subject: Re: [bug-gawk] Awk cannot properly deal with too small numbers.
Date: Sat, 16 Apr 2016 20:44:25 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Hi.

Thanks for the bug report.

Zhengyu Guo <address@hidden> wrote:

> Hi,
>
> I encountered a problem when dealing with very small numbers. The test case
> this shown below
>
> ~~~
> $ echo 1.1e-307 | awk '$1<0.05{print}'
> 1.1e-307
> $ echo 1.1e-309 | awk '$1<0.05{print}’
> ~~~
>
> Both commands should print out the input number. However, the second
> command print out nothing.
>
> It seems that when the numeric number is too small, AWK cannot process it
> correctly.

There are two things interacting here.

First, awk (and gawk) are limited by the capabilities of hardware
double precision floating point, and the second number is too small
to be represented numerically.

Once that's true, $1 is treated just as a string, and the string comparison

        "1.1e-309" < "0.05"

fails.

There isn't much else to do.

Thanks,

Arnold



reply via email to

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