Re: [PHP] Declaring vars as INT ?

2005-10-22 Thread Richard Lynch
On Fri, October 21, 2005 2:39 pm, Chris Knipe wrote:
 Function DoSomething($Blah) {
   $Blah = (int) $Blah;
   return $Blah
 }

 $Blah, cannot be larger than 2147483647, and sometimes, I get negative
 integers back from the above function.

 This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
 confirm this, and if it is indeed true, is this a bug, or a limitation
 somewhere on PHP?  Any other ways to confirm that *large* numbers, are
 indeed integers?  I'm working with numbers in the form of mmddsss
 (20051025001 for today for example)

PHP integers are limited by 32-bit hardware and a simplicity of design
to -2147483648 to 2147483647.

There are no unsigned, long, double long, or google ungle longles.
[I made that last one up, but it sure sounds good, don't it?]

Your options are, however, several.

1. Use BCMATH or that fancy new-fangled big-number package to deal
with numbers as big as you want, subject only to the amount of RAM in
your box and the number of values you want to use at one time.
Performance will not be integer-fast as these packages use
string-manipulation to compute mathematical values, but they can get
VERY big numbers, with whatever precision you specify.

2. In this particular instance, it's a *DATE* so you should consider
converting it to a Unix time-stamp.  This does limit you to 1/1/1970
midnight to somewhere in March 2038, however, as that is the same
32-bit limited range in number of seconds between 1/1/1970 midnight
and 2 * 2147483647 seconds later than that.  Note that this is
strictly hardware-based, so if you get a 64-bit machine, your date
range goes until, like, 1970 + 2 * (2038 - 1970)

If your dates range beyond 1/1/1970 and/or 2038, you may want to
simply NOT convert them to integer in the first place.

Also note that database software can generally provide more options
for date storage, date arithmetic and date-handling in general.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Declaring vars as INT ?

2005-10-21 Thread Chris Knipe
Hi,

Uhm... Let's take the below quickly:

Function DoSomething($Blah) {
  $Blah = (int) $Blah;
  return $Blah
} 

$Blah, cannot be larger than 2147483647, and sometimes, I get negative
integers back from the above function.

This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
confirm this, and if it is indeed true, is this a bug, or a limitation
somewhere on PHP?  Any other ways to confirm that *large* numbers, are
indeed integers?  I'm working with numbers in the form of mmddsss
(20051025001 for today for example)

Thanks,
Chris.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Declaring vars as INT ?

2005-10-21 Thread Jasper Bryant-Greene
On Fri, 2005-10-21 at 21:39 +0200, Chris Knipe wrote:
 Function DoSomething($Blah) {
   $Blah = (int) $Blah;
   return $Blah
 } 
 
 $Blah, cannot be larger than 2147483647, and sometimes, I get negative
 integers back from the above function.
 
 This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
 confirm this, and if it is indeed true, is this a bug, or a limitation
 somewhere on PHP?  Any other ways to confirm that *large* numbers, are
 indeed integers?  I'm working with numbers in the form of mmddsss
 (20051025001 for today for example)

It's not a PHP bug. I'm guessing you're on a 32-bit platform. 2147483647
is the maximum length of a signed integer on a 32-bit platform, and PHP
doesn't do unsigned integers.

A date in the form of mmddsss etc. isn't really a number, so if it
was me I'd probably treat it as a string. If you really *have* to treat
it as a number, then use float and get all the precision errors that
come with floating-point, or use binary coded decimal or another
arbitrary precision system.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: [EMAIL PROTECTED]
w: http://www.album.co.nz/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Declaring vars as INT ?

2005-10-21 Thread Chris Knipe
Aha :)

Thanks.
 

 -Original Message-
 From: Jasper Bryant-Greene [mailto:[EMAIL PROTECTED] 
 Sent: 21 October 2005 22:04
 To: [EMAIL PROTECTED]
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Declaring vars as INT ?
 
 On Fri, 2005-10-21 at 21:39 +0200, Chris Knipe wrote:
  Function DoSomething($Blah) {
$Blah = (int) $Blah;
return $Blah
  }
  
  $Blah, cannot be larger than 2147483647, and sometimes, I 
 get negative 
  integers back from the above function.
  
  This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone 
 else perhaps 
  confirm this, and if it is indeed true, is this a bug, or a 
 limitation 
  somewhere on PHP?  Any other ways to confirm that *large* 
 numbers, are 
  indeed integers?  I'm working with numbers in the form of 
 mmddsss
  (20051025001 for today for example)
 
 It's not a PHP bug. I'm guessing you're on a 32-bit platform. 
 2147483647 is the maximum length of a signed integer on a 
 32-bit platform, and PHP doesn't do unsigned integers.
 
 A date in the form of mmddsss etc. isn't really a number, 
 so if it was me I'd probably treat it as a string. If you 
 really *have* to treat it as a number, then use float and get 
 all the precision errors that come with floating-point, or 
 use binary coded decimal or another arbitrary precision system.
 
 --
 Jasper Bryant-Greene
 General Manager
 Album Limited
 
 e: [EMAIL PROTECTED]
 w: http://www.album.co.nz/
 p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
 a: PO Box 579, Christchurch 8015, New Zealand
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Declaring vars as INT ?

2005-10-21 Thread Jordan Miller

Hello,

you could treat your variable as a string, and use the is_numeric()  
function (but this will include floats, too). To answer your question  
precisely and accurately, you may have to do regex matching since you  
are out of the bounds of int.


However, why, *exactly*, are you trying to confirm that your string  
is an integer? It seems to me kind of cumbersome and unnecessary. If  
you provide more explicit information on what you are trying to do,  
your overarching goal for the script, including what are your inputs  
and intended outputs, along with some real code, we can probably find  
a solution that will do what you want without mucking about like  
this. Just my two cents.


Jordan




On Oct 21, 2005, at 2:39 PM, Chris Knipe wrote:


Hi,

Uhm... Let's take the below quickly:

Function DoSomething($Blah) {
  $Blah = (int) $Blah;
  return $Blah
}

$Blah, cannot be larger than 2147483647, and sometimes, I get negative
integers back from the above function.

This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
confirm this, and if it is indeed true, is this a bug, or a limitation
somewhere on PHP?  Any other ways to confirm that *large* numbers, are
indeed integers?  I'm working with numbers in the form of mmddsss
(20051025001 for today for example)

Thanks,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Declaring vars as INT ?

2005-10-21 Thread Jordan Miller

Also, look at this function:
http://www.php.net/ctype_digit

Jordan


On Oct 21, 2005, at 2:39 PM, Chris Knipe wrote:


Hi,

Uhm... Let's take the below quickly:

Function DoSomething($Blah) {
  $Blah = (int) $Blah;
  return $Blah
}

$Blah, cannot be larger than 2147483647, and sometimes, I get negative
integers back from the above function.

This is with PHP 4.4.0 on FreeBSD 5.4-STABLE.  Can anyone else perhaps
confirm this, and if it is indeed true, is this a bug, or a limitation
somewhere on PHP?  Any other ways to confirm that *large* numbers, are
indeed integers?  I'm working with numbers in the form of mmddsss
(20051025001 for today for example)

Thanks,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php