[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] inside awk script check that -M/--bignum given on command
From: |
arnold |
Subject: |
Re: [bug-gawk] inside awk script check that -M/--bignum given on command line? |
Date: |
Fri, 05 Jan 2018 03:02:42 -0700 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
There is also PROCINFO["argv"] in 4.2.0, which lets you
see the command line arguments passed to gawk.
HTH,
Arnold
"Andrew J. Schorr" <address@hidden> wrote:
> Hi,
>
> On Thu, Jan 04, 2018 at 11:57:05PM +0100, Jannick wrote:
> > I am running gawk (4.2.0) against an awk script requiring that the --bignum
> > mode (-M) is effectively switched on. Otherwise no meaningful, but rather
> > confusing results are produced.
> >
> > Is there any way (1) to run a check inside the script that the -M/--bignum
> > flag was provided on the command line (if negative exit my script) or (2) to
> > switch on/off the bignum mode inside the script (like IGNORECASE=1 or =0; I
> > wouldn't mind if it could be switched on only)?
> >
> > To make sure that the MPR lib is compiled into gawk can be checked iff
> > PROCINFO["mpfr_version"] is given. However the default values of PREC (=5)
> > and ROUNDMODE(="N") do not appear to provide any insight if -M was given I
> > think.
>
> This issue has arisen in the past. There is a section in the documentation
> about this:
>
> https://www.gnu.org/software/gawk/manual/html_node/Checking-for-MPFR.html
>
> Occasionally, you might like to be able to check if 'gawk' was invoked
> with the '-M' option, enabling arbitrary-precision arithmetic. You can
> do so with the following function, contributed by Andrew Schorr:
>
> # adequate_math_precision --- return true if we have enough bits
>
> function adequate_math_precision(n)
> {
> return (1 != (1+(1/(2^(n-1)))))
> }
>
> Here is code that invokes the function in order to check if
> arbitrary-precision arithmetic is available:
>
> BEGIN {
> # How many bits of mantissa precision are required
> # for this program to function properly?
> fpbits = 123
>
> # We hope that we were invoked with MPFR enabled. If so, the
> # following statement should configure calculations to our desired
> # precision.
> PREC = fpbits
>
> if (! adequate_math_precision(fpbits)) {
> print("Error: insufficient computation precision available.\n" \
> "Try again with the -M argument?") > "/dev/stderr"
> exit 1
> }
> }
>
> Does this solve your problem?
>
> Regards,
> Andy
- Re: [bug-gawk] abort keyword, (continued)
- Re: [bug-gawk] abort keyword, Andrew J. Schorr, 2018/01/08
- Re: [bug-gawk] abort keyword, Neil R. Ormos, 2018/01/08
- Re: [bug-gawk] abort keyword, Arnold Robbins, 2018/01/11
- Re: [bug-gawk] abort keyword, Neil R. Ormos, 2018/01/12
- Re: [bug-gawk] abort keyword, Andrew J. Schorr, 2018/01/13
- Re: [bug-gawk] abort keyword, Neil R. Ormos, 2018/01/19
- Re: [bug-gawk] abort keyword, Andrew J. Schorr, 2018/01/19
- Re: [bug-gawk] abort keyword, arnold, 2018/01/20
- Re: [bug-gawk] abort keyword, Andrew J. Schorr, 2018/01/20
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Manuel Collado, 2018/01/08
Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?,
arnold <=