[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: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] inside awk script check that -M/--bignum given on command line? |
Date: |
Thu, 4 Jan 2018 18:20:48 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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
- [bug-gawk] inside awk script check that -M/--bignum given on command line?, Jannick, 2018/01/04
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?,
Andrew J. Schorr <=
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Jannick, 2018/01/04
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Andrew J. Schorr, 2018/01/05
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Jannick, 2018/01/05
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Andrew J. Schorr, 2018/01/05
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, arnold, 2018/01/08
- Re: [bug-gawk] inside awk script check that -M/--bignum given on command line?, Andrew J. Schorr, 2018/01/08