bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] GAWK 4.1.60 DIV() Remainder Bug


From: Andrew J. Schorr
Subject: Re: [bug-gawk] GAWK 4.1.60 DIV() Remainder Bug
Date: Tue, 5 Aug 2014 10:20:06 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

On Tue, Aug 05, 2014 at 04:25:23PM +0300, Aharon Robbins wrote:
> Some quick experimentation convinced me that MPFR was getting this wrong
> also. Andy, your analysis down to mpz_mod is great and has saved me some
> time.  Now we have to figure out WHY mpz_mod isn't doing what it is
> supposed to be doing.

I'm glad my initial troubleshooting was helpful.  I ran out of time and
had to get back to work. :-)

> In the worst case, I'll just switch out to use the div_mod function that
> div() uses, but I'd like to try for a bit to understand why mpz_mod
> isn't working.

Please keep in mind that '%' works with floating-point values, whereas
div is restricted to integers.  So you can't simply use the same code
for both.  For example:

bash-4.2$ echo -15.1 6.9 | ./gawk '{div($1, $2, r); print ($1 % $2), 
r["remainder"]; }'
-1.3 -3
bash-4.2$ echo -15.1 6.9 | ./gawk -M '{div($1, $2, r); print ($1 % $2), 
r["remainder"]; }'
-1.3 -3

That works correctly as is.  The ugly fix to mpfr.c:mpg_mod might be to use
mpfr_fmod in all cases.  If the operands are integers, convert them to floats,
then use mpfr_fmod, and then convert the result back to an mpg_integer.  That
seems suboptimal, but it might work.  Is it possible that there's actually
a bug in mpz_mod?  I guess we need a simple test program to figure it out...

Regards,
Andy



reply via email to

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