bug-gawk
[Top][All Lists]

## Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers

 From: Manuel Collado Subject: Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers Date: Wed, 07 Aug 2013 10:35:55 +0200 User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0

```El 06/08/2013 22:07, Katherine Wasserman escribiÃ³:
```
```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.
```
```
Yes. This seems the simplest approach.

```
```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
```
```
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
```
```
```
BTW, the Pascal language (and some derivatives) has always had two division operators for integers:
```
integer / integer -> float
integer div integer -> integer

So "div" seems a common name for the integer division operator/function.

```
```
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
```
```
Regards,

--