bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] missing function powm and friends


From: Michael Plugge
Subject: Re: [bug-gawk] missing function powm and friends
Date: Wed, 03 Dec 2014 22:54:12 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

Hi Arnold,
thank you for your friendly mai. It was a little laziness to ask for inclusion of powm() and next_prime() to the basic functions of gawk :-) - you are right, the gawk function set is compact and limited, and should remain so. Bundling the functions into an extension is the better way. Invocation and performance are the same, but the basic function set is clearly defined and separated from more specialized function sets.

Am 27.11.2014 um 21:27 schrieb Aharon Robbins:
Hi Michael.

Thank you for your offer of the new functions. I appreciate your
willingness to contribute.

Date: Thu, 27 Nov 2014 14:45:24 -0500
From: "Andrew J. Schorr" <address@hidden>
To: Michael Plugge <address@hidden>
Cc: address@hidden
Subject: Re: [bug-gawk] missing function powm and friends

On Thu, Nov 27, 2014 at 03:49:37PM +0100, Michael Plugge wrote:
I wrote a small patch to use the powm() function (and also gcd() and
next_prime()) of gmp; this works even for very large parameters and
exponents. The appended patch file includes also an integer version of the
routines. It would be really great if it could be integrated into gawk :-).
I wish we could simply package this as a shared library extension, but the
problem is that the extension mechanism passes numeric values as double
precision numbers and does not expose the MPFR/GMP numbers used with -M.  The
gawk-mpfr extension converts numbers to strings in order to pass them between
gawk and the library, so that is one approach to dealing with this.
I would recommend this as the way to make a first attempt at
packaging up these functions as an extension.

My sense is that there's a limited appetite for adding new functions to
gawk, and a preference for adding new functionality through extensions.
That is exactly right. I think these functions would be useful if
available as an extension.  Michael, can you work with Andy to package
them into gawkextlib, either as part of the MPFR extension or as a small
standalone extension?
yes. First I'll read the extension code, mpfr.c and gawkextlib. Maybe that will need a while...

Another option might be to write them entirely in awk using basic
mathematical operations and assuming the availability of -M.
That could be a first quick way to implement some functions. powm(), gcd() and friends are easy, I'll write a little awk file for them. But the final goal should be to include the gmp functions because they are much more efficient (and there are many nice-to-have functions in gmp... :-) ).

But it is challenging when considering extensions that would benefit
from the arbitrary-precision representation.  Maybe it's worth giving
some thought to how to enhance the shared library interface to support
alternate numeric representations.  That may be a big job.
This is worth some thought, but since it's not likely to happen very
soon, I suggest that you and Michael work to get his code into gawkextlib
now. It can be revised later once the gawk team figures out if and how
to pass MPFR values to/from an extension.
Would it be possible (some day) to pass a node* to an extension, perhaps as read-only variable?

Kind regards, and thanks again

Michael


Thanks!

Arnold




reply via email to

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