64 bit integers print error on 32 bits machine

52 views
Skip to first unread message

Mariusz Grecki

unread,
Mar 1, 2019, 7:50:34 PM3/1/19
to tumbi
Hi Jean-Philippe,
on 32 bits machine, printing (with printf) of 64 bits integers exceeding 2^31-1 with native integer format (%d, %x, %u) prints 2^31-1 (signed INTMAX). Adding the size modifier ("l") does not help and "ll" is not allowed. With floating point formats (%f,%g) it works well (but how to print hex then?).

-nsp->b=ishift(2u64,33,"l")
b       =                i (1x1,uint64)

-nsp->printf("%ld\n", b)
-nsp->printf("%lf\n", b)

on 64 bit machine, it works well.

Jean-Philippe Chancelier

unread,
Mar 14, 2019, 8:22:04 AM3/14/19
to tu...@googlegroups.com
Dear Mariusz,
I have found a bug and corrected something for the %ld format which should solve your problem (my machine is 64bits Linux and the problem you pointed out was present).
A way for you to solve the problem is to use the %li format which is similar to %ld for printing but which is correctly managed in nsp. Let me know if it's ok with %li
Regards
jpc
--
You received this message because you are subscribed to the Google Groups "tumbi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tumbi+un...@googlegroups.com.
To post to this group, send email to tu...@googlegroups.com.
Visit this group at https://groups.google.com/group/tumbi.
For more options, visit https://groups.google.com/d/optout.

Mariusz Grecki

unread,
Apr 20, 2019, 1:28:06 PM4/20/19
to tumbi
Dear Jean-Philippe,
I have checked on 32b (Debian 9.8 Linux uname -a => Linux mghs 4.9.0-7-686-pae #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) i686 GNU/Linux) machine with a newly checked out cvs sources. Unfortunately it is still not OK, however, the result is different (-2147483648 instead of 2147483647).
Greetings
Mariusz

-nsp->b=ishift(2u64,33,"l")
b = i (1x1,uint64)

-nsp->printf("%ld\n", b)
-nsp->printf("%lf\n", b)
-nsp->printf("%li\n", b)
-nsp->



W dniu czwartek, 14 marca 2019 13:22:04 UTC+1 użytkownik Jean-Philippe Chancelier napisał:
Dear Mariusz,
I have found a bug and corrected something for the %ld format which should solve your problem (my machine is 64bits Linux and the problem you pointed out was present).
A way for you to solve the problem is to use the %li format which is similar to %ld for printing but which is correctly managed in nsp. Let me know if it's ok with %li
Regards
jpc




On 02/03/2019 01:50, 'Mariusz Grecki' via tumbi wrote:
Hi Jean-Philippe,
on 32 bits machine, printing (with printf) of 64 bits integers exceeding 2^31-1 with native integer format (%d, %x, %u) prints 2^31-1 (signed INTMAX). Adding the size modifier ("l") does not help and "ll" is not allowed. With floating point formats (%f,%g) it works well (but how to print hex then?).

-nsp->b=ishift(2u64,33,"l")
b       =                i (1x1,uint64)

-nsp->printf("%ld\n", b)
-nsp->printf("%lf\n", b)

on 64 bit machine, it works well.
--
You received this message because you are subscribed to the Google Groups "tumbi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tu...@googlegroups.com.

Mariusz Grecki

unread,
Apr 22, 2019, 7:09:53 PM4/22/19
to tumbi
Dear Jean-Philippe,
after small changes in "switch (AST (ast_cnt, pf_type))" at line 2796 in the file src/objects/File.c it seems that format "lld" works fine on 32b architectures. The modifications are presented below:

case AST (0, PF_LLD):
  retval += (*printer) ( target, p, (long long int) dval);
  break;

case AST (1, PF_LLD):
  retval += (*printer) ( target, p, ast[0], (long long int) dval);
  break;

case AST (2, PF_LLD):
  retval += (*printer) ( target, p, ast[0], ast[1], (long long int) dval);
  break;

....



case AST (0, PF_LLUD):
  retval += (*printer) ( target, p, (long long unsigned int) dval);
  break;

case AST (1, PF_LLUD):
  retval += (*printer) ( target, p, ast[0], (long long unsigned int) dval);
  break;

case AST (2, PF_LLUD):
  retval += (*printer) ( target, p, ast[0], ast[1], (long long unsigned int) dval);
  break;

I am not sure about side effects on 64b architectures.... Are there formats like "lld" allowed?
Greetings
Mariusz

Jean-Philippe Chancelier

unread,
Apr 26, 2019, 9:01:42 AM4/26/19
to tu...@googlegroups.com
Dear Mariusz,
I have added the changes in th ecvs version
Regards
jpc
To unsubscribe from this group and stop receiving emails from it, send an email to tumbi+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages