printf vs. big numbers

Discussion in 'Perl Misc' started by jidanni@jidanni.org, Sep 21, 2009.

  1. Guest

    What does one need to do to make this not blow up when $k reaches 10?
    $ perl -wle 'for $k(10){for(qw/b d lld ld Ld o u x/){printf "%%$_\t%$_\n",10**$k}}'
    %b 11111111111111111111111111111111
    %d -1
    %lld -1
    %ld -1
    %Ld -1
    %o 37777777777
    %u 4294967295
    %x ffffffff
     
    , Sep 21, 2009
    #1
    1. Advertising

  2. Uri Guttman Guest

    >>>>> "j" == jidanni <> writes:

    j> What does one need to do to make this not blow up when $k reaches 10?
    j> $ perl -wle 'for $k(10){for(qw/b d lld ld Ld o u x/){printf "%%$_\t%$_\n",10**$k}}'
    j> %b 11111111111111111111111111111111
    j> %d -1
    j> %lld -1
    j> %ld -1
    j> %Ld -1
    j> %o 37777777777
    j> %u 4294967295
    j> %x ffffffff

    perl -wle 'for $k(10){for(qw/f g b d lld ld Ld o u x/){printf "%%$_\t%$_\n",10**$k}}'
    %f 10000000000.000000
    %g 1e+10
    %b 1001010100000010111110010000000000
    %d 10000000000
    %lld 10000000000
    %ld 10000000000
    %Ld 10000000000
    %o 112402762000
    %u 10000000000
    %x 2540be400

    get a 64 bit machine!

    perl overflows integers to floats and you are seeing that. notice i
    added f and g formats. try those. printing an integer format of a too
    large float is going to generate nonsense since there aren't enough bits
    to convert the number correctly.

    uri
     
    Uri Guttman, Sep 21, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    401
  2. Shaguf
    Replies:
    0
    Views:
    367
    Shaguf
    Dec 24, 2008
  3. Shaguf
    Replies:
    0
    Views:
    463
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    250
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    227
    Shaguf
    Dec 24, 2008
Loading...

Share This Page