bug-gawk
[Top][All Lists]
Advanced

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

Re: complie with mpfr support


From: Wolfgang Laun
Subject: Re: complie with mpfr support
Date: Thu, 11 Feb 2021 11:39:55 +0100

Do you have any foundation for thinking that gawk 5.0.1 will fail the test
as you describe it?

$ gawk -W version
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
$ echo 1.8e-1000 | gawk -M '$1<0.05 {print "true"}'
true
$ echo 1.8e-1000000 | gawk -M '$1<0.05 {print "true"}'
true
$ echo
'0.04999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'
| gawk -M '$1<0.05 {print "true"}'
true

Try harder with this script:

#! /usr/bin/bash
for dig in 1000000 10000000 100000000 1000000000
do
   n=$dig
   for i in {1..1}
   do
     echo -n '0.04'
     while test $n -gt 0;
     do
       echo -n
'9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'
       n=$[$n-100]
     done
   done | gawk -M '$1<0.05 {print "true"}'
   echo "test $dig digits done."
done

All tests passed.

Data with so many decimal digits, either in the mantissa or in the exponent
isn't likely to have any relation to the real world.

Wolfgang






On Thu, 11 Feb 2021 at 10:58, Ivan Molineris <ivan.molineris@gmail.com>
wrote:

> This answer makes me very sad.
> I very appreciate your work and I would like to continue using gawk in
> data science.
> But if you think the inclusion of MPFR was a mistake you probably do not
> think that gawk has a future in my field of work, probably I should
> re-implement many of its features in python.
>
> Thanks for the advice.
>
>
>
> On Thu, Feb 11, 2021 at 10:48 AM <arnold@skeeve.com> wrote:
>
>> Hi.
>>
>> Ivan Molineris <ivan.molineris@gmail.com> wrote:
>>
>> > Arnold pointed me to the PERC variable. The unexpected behavior that now
>>
>> PREC :-)
>>
>> > 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?
>>
>> MPFR provides arbitrary precision, based on the setting of PREC.
>> So I don't think there is a single answer to your question.
>>
>> MPFR is not a panacea, nor is it magical. You need to understand
>> floating point math to understand how it works. The gawk manual has
>> some explicative text, but it is probably not enough, since I don't
>> have a deep understanding of these issues.
>>
>> If you want "bignums" you may be better off using Python and one
>> of its packages than MPFR and gawk.
>>
>> MPFR support was contributed by a developer who left the project 8+
>> years ago. In retrospect, adding it was a mistake. But it's too late to
>> remove it, so I do the best I can to make it work well.
>>
>> Sorry,
>>
>> Arnold
>>
>

-- 
Wolfgang Laun


reply via email to

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