Is there a constant or a definition for a maximum number in perl? And the same question for a minimum value? Alon
Is there a constant or a definition for a maximum number in perl? And the same question for a minimum value? Alon
You have some constants available through the %Config hash in Config.pm: % perl -MConfig -le 'print "$_ = $Config{$_}" for grep /size$/, keys % Config' charsize = 1 d_chsize = doublesize = 8 fpossize = 8 gidsize = 4 i16size = 2 i32size = 4 i64size = 8 i8size = 1 intsize = 4 ivsize = 4 longdblsize = 16 longlongsize = 8 longsize = 4 ... So in this machine an int is 4 bytes (ivsize). Nevertheless, Perl internally may switch to some floating-point type if it needs to: % perl -MDevel::Peek -wle '$a = 1 << 31; Dump($a); $a *= 2; Dump($a)' SV = IV(0x180cac8) at 0x1800f4c REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 2147483648 SV = PVNV(0x1803850) at 0x1800f4c REFCNT = 1 FLAGS = (NOK,pNOK) IV = -2147483648 NV = 4294967296 PV = 0 and in consequence the number may look like an integer but not be accurate. So this limit is well-defined in the sense of %Config, but at the level of Perl code the actual "type" of an integer depends on the implementation of the interpreter, and hence that limit has to be used carefully. The pragma integer adds some control: % perl -Minteger -MDevel::Peek -wle '$a = 1 << 31; Dump($a); $a *= 2; Dump($a)' SV = IV(0x180cad0) at 0x180061c REFCNT = 1 FLAGS = (IOK,pIOK) IV = -2147483648 SV = IV(0x180cad0) at 0x180061c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 And, lastly, the pragma bigint removes the limit for integers in practice. -- fxn
This may work for you the biggest unsigned integer $ perl -e 'print ~0' 18446744073709551615 # 64-bit integers the maximum signed integer $ perl -MConfig -e 'print( (1<<$Config{ivsize}*8-1)-1 )' 9223372036854775807 the minimum signed integer $ perl -MConfig -e 'print -(1<<$Config{ivsize}*8-1)' -9223372036854775808 I am not sure how general these expressions are. The illustrated values are for 64bit integers. Adriano.
I don't think so ----- Original Message ----- From: "Alon Marx" < XXXX@XXXXX.COM > To: < XXXX@XXXXX.COM > Sent: Tuesday, December 27, 2005 5:28 PM Subject: maximum int value
Seems like a good solution for my needs, but how do I use it in a perl program instead of an inline command? For example, if I try to set a variable with such a value: $a = (1<<$Config{ivsize}*8-1)-1; I get an error "Global symbol "%Config" requires explicit package name at" Thanks, Alon
Alon Marx am Dienstag, 27. Dezember 2005 14.30: You have to import the Config module with use Config; Adriano imported it in the cmd line with -MConfig hth, joe [top posting history:]
1.KILL INT can not wake up $SIG{INT}
Hi list, Anyone has such experience? KILL INT pid cannot wake up $SIG{INT} sub{}. my code is like; $SIG{INT} = sub {#load pm} $SIG{ALRM} = sub {print "Driver $pm is going to sleep... bye.\n"; exit;}; the pm actually has a system call to execute something sub xxx { `perl xxx.pl` } but my $tmp = kill "INT", $pid; ## it returns number of processes, eg: 1 cannot wake up the $SIG{INT} at all after $SIG{ALRM} has been executed. does system call cause the problem? Thanks.
2.Storing a long value in an int
Hi, I need to set this flag = 0x0010000 My code is as follows: $flag = 0x0010000; print("setting flag $flag\n"); produces: 65536 But when I say $quote-SetFlag($flag); The flag is being set to 0; I see that the number I am trying to set is 65536. Is there a way I can make $flag a long int to store 65536 ? Thanks, Radhika -- It is all a matter of perspective. You choose your view by choosing where to stand. Larry Wall ---
3.Storing a long value in an int [correction]
4.Using hyperlink to pass an int value using the 'Jump to URL' f
5.Using hyperlink to pass an int value using the 'Jump to URL' featu
Users browsing this forum: No registered users and 32 guest