[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers
From: |
Katherine Wasserman |
Subject: |
Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers |
Date: |
Tue, 06 Aug 2013 16:07:41 -0400 |
Hi Andy
>Perhaps something like div(numerator, denominator, result) where
>the result will be an array with a "quot" element and a "rem"
>element. I don't think it's possible to have a function that returns
>an array, but I'm not certain...
Maybe div() could just return the quotient and an optional third argument could
return the remainder. This would save the extra steps needed to pull apart an
array and most often throw out the remainder portion. Also the '%' operator
seems to work ok with bignums so there already is a useable remainder function.
Thanks,
-Katie
At 02:08 PM 8/6/2013, Andrew J. Schorr wrote:
>Hi,
>
>On Tue, Aug 06, 2013 at 01:01:40AM -0400, Katherine Wasserman wrote:
>> There is currently no way to preform division of arbitrary precision
>> integers in gawk, the system will always convert numbers to floating point
>> when using the '/' operator.
>>
>> Per Aharon , there appear to be at least two ways around this:
>>
>> 1) change the semantics of the '/' operator.
>
>I don't think we could change the behavior of the '/' operator unless we
>introduced a new option to select this behavior. That doesn't sound
>workable to me...
>
>> 2) introduce a new function for integer division.
>>
>> I think that the later is both cleaner and useful as a function even without
>> the MPFR/MP extensions loaded.
>
>I think this is the right solution. There is a "div" function in
>ISO C that does what we want:
>
>http://pubs.opengroup.org/onlinepubs/9699919799/functions/div.html
>
>Perhaps something like div(numerator, denominator, result) where
>the result will be an array with a "quot" element and a "rem"
>element. I don't think it's possible to have a function that returns
>an array, but I'm not certain...
>
>Regards,
>Andy