in reply to Why does printf() do this to big numbers?

Because that's what you asked for.

%d is asking for a signed int. On pretty much any platform out there, int is 32 bits. 2.8 billion is larger than can be represented in a signed int, ergo wraparound.

Replies are listed 'Best First'.
Re^2: Why does printf() do this to big numbers?
by almut (Canon) on Mar 17, 2010 at 09:26 UTC
    On pretty much any platform out there, int is 32 bits

    Not necessarily.  With a "64-bit perl", "%d" can handle ints larger than 32 bits just fine:

    $ perl -e "printf qq(%d\n), 2810337464" 2810337464
    $ perl -V ... intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 ... Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_64_BIT_ +ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES ...

      Ah, true. I guess my C-brain leaks through sometimes :) I guess that's probably the USE_64_BIT_INT.

      But at any rate, overflow is what the OP is seeing.

Re^2: Why does printf() do this to big numbers?
by Anonymous Monk on Mar 18, 2010 at 05:01 UTC
    $ perl -V:.+?size d_chsize='define'; d_malloc_good_size='undef'; d_malloc_size='undef'; doublesize='8'; fpossize='8'; gidsize='4'; i16size='2'; i32size='4'; i64size='8'; i8size='1'; intsize='4'; ivsize='4'; longdblsize='12'; longlongsize='8'; longsize='4'; lseeksize='8'; nvsize='8'; ptrsize='4'; shortsize='2'; sig_size='27'; sizesize='4'; u16size='2'; u32size='4'; u64size='8'; u8size='1'; uidsize='4'; uvsize='4';