bug-gawk
[Top][All Lists]
Advanced

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

Re: complie with mpfr support


From: Ivan Molineris
Subject: Re: complie with mpfr support
Date: Thu, 11 Feb 2021 10:33:52 +0100

Dear Wolfgang and Arnold,
my question is a bit more complicated.
I'm using GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2) and I
found some strange behaviours related to numeric precision, some are
described here
https://stackoverflow.com/questions/20684195/awk-and-numeric-comparison-with-number-less-than-1-7e-308

Recently I underwood that, if I give -M option to gawk, these problems seem
solved.
As an example:
$ echo 1.8e-308 | gawk '$1<0.05 {print "true"}'
does not print true
$ echo 1.8e-308 | gawk -M '$1<0.05 {print "true"}'
print true, as expected

Arnold pointed me to the PERC variable. The unexpected behavior that now
seems solved with -M, is only shifted to a smaller number.

$ echo 1.8e-508 | gawk -M '$1<0.05 {print "true"}'
does not print true

So my question is: what is the biggest number that will fail the above
test, even if in theory is lower than 0.05?

Best regards.





On Wed, Feb 10, 2021 at 5:29 AM Wolfgang Laun <wolfgang.laun@gmail.com>
wrote:

> Oops. Too long hours. Here is the Java program:
>
> public class Jiffy {
>      public static  void main( String[] args ){
>          System.out.printf( "%30.28f\n", Math.nextAfter( 0.05, 0 ) );
>      }
> }
>
> 0.0499999999999999960000000000
>
> Whether this string works in the intended way (whatever that is) depends
> on the intricacies of the conversion between the string representation of a
> decimal and the machine number.
> -W
>
> On Wed, 10 Feb 2021 at 05:14, <arnold@skeeve.com> wrote:
>
>> Thanks.
>>
>> Note that Ivan asked about 0.05 (5/100) and not 0.5 (1/2)... :-)
>>
>> Arnold
>>
>> Wolfgang Laun <wolfgang.laun@gmail.com> wrote:
>>
>> > The maximum double smaller than 0.5 is:
>> > 0.4999999999999999400000000000
>> >
>> > -W
>> >
>> > On Tue, 9 Feb 2021 at 17:03, <arnold@skeeve.com> wrote:
>> >
>> > > Hi.
>> > >
>> > > Ivan Molineris <ivan.molineris@gmail.com> wrote:
>> > >
>> > > > Thanks Arnold,
>> > > > I now understand that in modern linux distribution the gawk binary
>> is
>> > > > compiled by default with MPFR support, and all works well if -M is
>> given.
>> > > >
>> > > > In particular my version is
>> > > > GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
>> > >
>> > > That's pretty old, but that's a separate issue.
>> > >
>> > > > And
>> > > > $ echo 1.8e-308 | gawk -M '$1<0.05'
>> > > > return "1.8e-308" as expected.
>> > > >
>> > > > With the default PREC, what is the biggest number that will fail the
>> > > above
>> > > > test, even if in theory is lower than 0.05?
>> > >
>> > > I don't really know. I'm not an expert on this stuff. Sorry.
>> > >
>> > > Glad you're straightened out.
>> > >
>> > > Arnold
>> > >
>> > >
>> >
>> > --
>> > Wolfgang Laun
>>
>
>
> --
> Wolfgang Laun
>
>


reply via email to

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