XP is just a number | |
PerlMonks |
64 bit numbers in a 32 bit world.by TedYoung (Deacon) |
on Apr 24, 2007 at 20:47 UTC ( [id://611847]=perlquestion: print w/replies, xml ) | Need Help?? |
TedYoung has asked for the wisdom of the Perl Monks concerning the following question: Hi, I am using perl 5.8.4 (compiled 32 bit). I want to create 64 bit numbers and insert them into a mysql db using DBI. Until now, I have always used mysql's bigint column (64 bit int) with Perl/DBI with no problem. But, I never actually used numbers greater than 32 bits. Now I need to. Is there a way to create a number between 1 << 32 and 1 << 64 without using bigint? I don't have any reason not to use bigint, other than I don't need infinite precision, and would expect (emulated) 64 bit arithmetic to be faster. That may not actually be true, though. So, I asked DBI and DBD::mysql what they thought about this. Here is my code. The comments show the output of each print.
Some comments: The last statement (0 + $i) rounds the number to a floating point if I don't use bigint (as expected). But, printing $i still seems to hold the large number despite $i not being a Math::BigInt. Even using biging in the second do does not cast the $i to a Math::BigInt (but at least arithmetic works). How does DBI make that? <whine>I want to too!!!</whine> FWIW, perlop says the shift opts are undefined for counts larger than 31 outside of bigint Update: Thanks monks! I am not sure why string didn't occur to me! That makes a lot of sense. I will check out Math::Int64 too. Thanks, Ted Young ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Back to
Seekers of Perl Wisdom
|
|