Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Why does printf() do this to big numbers?

by ikegami (Patriarch)
on Mar 17, 2010 at 16:06 UTC ( [id://829213]=note: print w/replies, xml ) Need Help??


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

Max 32-bit signed integer: 2,147,483,647
Max 32-bit unsigned integer: 4,294,967,295

You want to print 2,810,337,464, which lands between the two. You have a 32-bit build of Perl and you told Perl to print a signed integer. It started by converting the input to an integer if it wasn't already, then it treated the result as a signed integer. The result is 2810337464 - 2**32

Ask for an unsigned integer or a floating point number:

$ perl -e'printf( "%d\n", 2810337464 );' -1484629832 $ perl -e'printf( "%u\n", 2810337464 );' 2810337464 $ perl -e'printf( "%.0f\n", 2810337464 );' 2810337464

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://829213]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found