[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers

**From**: |
Andrew J. Schorr |

**Subject**: |
Re: [bug-gawk] GAWK 4.1: Division with Arbitrary Precision Integers |

**Date**: |
Tue, 6 Aug 2013 14:08:39 -0400 |

**User-agent**: |
Mutt/1.5.21 (2010-09-15) |

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