pdf-devel
[Top][All Lists]
Advanced

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

[pdf-devel] Issues with bug FS#105


From: gerel
Subject: [pdf-devel] Issues with bug FS#105
Date: Tue, 30 Mar 2010 17:07:13 -0300

Hi,

I've tried to reproduce the bug there named. I couldn't.
However, I believe there is some issue with signs.
I made some tests myself regarding the number sign that should be returned.  The
mod operator native implementation works like this:

INPUT
##
#include <stdio.h>
int main (){
        printf ("5 % 3: %d\n",  5%3);
        printf ("5 % -3: %d\n",  5%-3);
        printf ("-5 % 3: %d\n", -5%3);
        printf ("-5 % -3: %d\n\n", -5%-3);

        printf ("3 % 5: %d\n",  3%5);
        printf ("3 % -5: %d\n",  3%-5);
        printf ("-3 % 5: %d\n", -3%5);
        printf ("-3 % -5: %d\n", -3%-5);
}
##
OUTPUT:
address@hidden:~$ ./a.out 
5 % 3: 2
5 % -3: 2
-5 % 3: -2
-5 % -3: -2

3 % 5: 3
3 % -5: 3
-3 % 5: -3
-3 % -5: -3
##

That means that the result sign is _only_ decided on the dividend sign.  In the
current code for pdf_i64_mod() (built-in implementation), It says:
##
      [...]

      /*Now check the signs fo divisor and dividend*/
      if (pdf_i64_cmp(divisor,zero) < 0)
        {
          result_sign = -1;
          pdf_i64_abs(&divisor,divisor, p_status);
        }
      if (pdf_i64_cmp(dividend,zero) < 0)
        {
          pdf_i64_abs(&dividend,dividend, p_status);
          if (result_sign == -1)
            {
              result_sign = -1;
            }
          else
            {
              result_sign = -1;
            }
        }

      [...]
###

If the variable named "result_sign" is deciding the returned number sign.
I believe it should be something like this instead,

##
      [...]

      /*Now check the signs fo divisor and dividend*/
      if (pdf_i64_cmp(divisor,zero) < 0)
        {
          pdf_i64_abs(&divisor,divisor, p_status);
        }
      if (pdf_i64_cmp(dividend,zero) < 0)
        {
          pdf_i64_abs(&dividend,dividend, p_status);
          result_sign = -1;
        }

      [...]
###

I may be wrong, I didn't read the whole function code, because I'm not familiar
with the Knuth method.

Despite that, I tried the above proposed modification and no new test fails. It
seems to work fine or do nothing. :-)

Any comments ?

cheers,

-gerel




reply via email to

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