Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > printf vs. big numbers

Reply
Thread Tools

printf vs. big numbers

 
 
jidanni@jidanni.org
Guest
Posts: n/a
 
      09-21-2009
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
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      09-21-2009
>>>>> "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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net 0 12-26-2008 09:29 AM
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net Web Controls 0 12-26-2008 06:11 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Python 0 12-24-2008 07:35 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Ruby 0 12-24-2008 05:07 AM
Printf problem with big numbers.... pasukaru@gmail.com C Programming 6 01-24-2006 03:52 AM



Advertisments