P: n/a

What is the largest number (integer?)
that I can work with in PHP?
For example, I have this number:
1082655076035
This is actually a date that I need to
compare with another date.
I was just going to see if one was greater
than the other but it doesn't seem to be
working.
I can try to convert it to a date object if
that is the only way to do it...
Thanks,
Andrew  
Share this Question
P: n/a

Andrew wrote: What is the largest number (integer?) that I can work with in PHP?
For example, I have this number:
1082655076035
This is actually a date that I need to compare with another date.
I was just going to see if one was greater than the other but it doesn't seem to be working.
I can try to convert it to a date object if that is the only way to do it...
Thanks,
Andrew
By definition on almost all platforms INTEGER is 32 bits (4 bytes) or a
maximum of 2Billion your number is > 1Trillion.
from: http://www.php.net/manual/en/language.types.integer.php
"The size of an integer is platformdependent, although a maximum value
of about two billion is the usual value (that's 32 bits signed). PHP
does not support unsigned integers."
you want to use float http://www.php.net/manual/en/language.types.float.php
"The size of a float is platformdependent, although a maximum of
~1.8e308 with a precision of roughly 14 decimal digits is a common value
(that's 64 bit IEEE format)."
Michael Austin.  
P: n/a

Andrew wrote: What is the largest number (integer?) that I can work with in PHP?
For example, I have this number:
1082655076035
This is actually a date that I need to compare with another date.
I was just going to see if one was greater than the other but it doesn't seem to be working.
I can try to convert it to a date object if that is the only way to do it...
Thanks,
Andrew
.... forgot to mention that most systems now use 64 bits for date/time...
and if you are thinking I was wrong that 2^32 is 2147483648, integer is
signed  in otherwords it is 2^31 and the 32nd bit is for +/.
2^32 is 4294967296
2^64 is 18446744073709551616
Big difference...
Michael.  
P: n/a

In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote: and if you are thinking I was wrong that 2^32 is 2147483648, integer is signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here.
Complement notation, as in the first (2^32)/2 represent a positive integer
and the last (2^32)/2 represent a negative integer.

Tim Van Wassenhove <http://home.mysth.be/~timvw>  
P: n/a

Tim Van Wassenhove wrote: In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote:
and if you are thinking I was wrong that 2^32 is 2147483648, integer is signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here. Complement notation, as in the first (2^32)/2 represent a positive integer and the last (2^32)/2 represent a negative integer.
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is
negative... I think that if you were to use your calculator, you just
said the same thing I did.. bit 32 (MSB) is for +/. The maximum value
in an integer is +/ 2147483648 If you use your calculater 2^32 is
2147483648*2. So, no, I was not wrong... :) :)
Michael Austin.
 using 32 bit systems before Intel/AMD ever did...  
P: n/a

In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote: Tim Van Wassenhove wrote: In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote:
and if you are thinking I was wrong that 2^32 is 2147483648, integer is signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here. Complement notation, as in the first (2^32)/2 represent a positive integer and the last (2^32)/2 represent a negative integer.
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is negative... I think that if you were to use your calculator, you just said the same thing I did.. bit 32 (MSB) is for +/. The maximum value in an integer is +/ 2147483648 If you use your calculater 2^32 is 2147483648*2. So, no, I was not wrong... :) :)
So this means you have a +0 and a 0 ? ;)
Think about it, first (2^32)/2 thus from 0 to 2^311 represent a
positive integers. And from from 2^31 to 2^321 represent negative
integers.

Tim Van Wassenhove <http://home.mysth.be/~timvw>  
P: n/a

Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:
Tim Van Wassenhove wrote:
In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote:
and if you are thinking I was wrong that 2^32 is 2147483648, integer is signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here. Complement notation, as in the first (2^32)/2 represent a positive integer and the last (2^32)/2 represent a negative integer.
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is negative... I think that if you were to use your calculator, you just said the same thing I did.. bit 32 (MSB) is for +/. The maximum value in an integer is +/ 2147483648 If you use your calculater 2^32 is 2147483648*2. So, no, I was not wrong... :) :)
So this means you have a +0 and a 0 ? ;)
Think about it, first (2^32)/2 thus from 0 to 2^311 represent a positive integers. And from from 2^31 to 2^321 represent negative integers.
I think it is you that must think about it :)
<  32 bits  >
00000000000000000000000000000000 = 0
01111111111111111111111111111111 = +2147483647
10000000000000000000000000000000 = 2147483648 not 0.
11111111111111111111111111111111 = 1
and yes, you are missing one number because the last bit is used for the
sign...
to illustrate: try this:
<?php
$foo = 2147483647;
$bar = $foo + 1;
print "$foo\n";
print "$foo + 1 = $bar\n";
print "Now we use settype to type integer and repeat\n";
settype ($foo,"integer");
settype ($bar,"integer");
print "$foo\n";
print "$foo + 1 = $bar\n";
?> http://www.firstdbasource.com/ma.php
<snide remarks concerning the quality of education these days removed> :) ;)
Michael Austin.  
P: n/a

Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:
Tim Van Wassenhove wrote:
In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote:
and if you are thinking I was wrong that 2^32 is 2147483648, integer is signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here. Complement notation, as in the first (2^32)/2 represent a positive integer and the last (2^32)/2 represent a negative integer.
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is negative... I think that if you were to use your calculator, you just said the same thing I did.. bit 32 (MSB) is for +/. The maximum value in an integer is +/ 2147483648 If you use your calculater 2^32 is 2147483648*2. So, no, I was not wrong... :) :)
So this means you have a +0 and a 0 ? ;)
Think about it, first (2^32)/2 thus from 0 to 2^311 represent a positive integers. And from from 2^31 to 2^321 represent negative integers.
I do recall a case when supporting a particular FORTRAN complier that
there was a bug causing it to actually have a result of 0. :) It was
fixed in a patch...
Michael.  
P: n/a

In article <tC*****************@newssvr24.news.prodigy.com> , Michael Austin wrote: Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:
Tim Van Wassenhove wrote:
In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote:
>and if you are thinking I was wrong that 2^32 is 2147483648, integer is >signed  in otherwords it is 2^31 and the 32nd bit is for +/.
I think you are mistaken here. Complement notation, as in the first (2^32)/2 represent a positive integer and the last (2^32)/2 represent a negative integer.
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is negative... I think that if you were to use your calculator, you just said the same thing I did.. bit 32 (MSB) is for +/. The maximum value in an integer is +/ 2147483648 If you use your calculater 2^32 is 2147483648*2. So, no, I was not wrong... :) :)
So this means you have a +0 and a 0 ? ;)
Think about it, first (2^32)/2 thus from 0 to 2^311 represent a positive integers. And from from 2^31 to 2^321 represent negative integers.
I think it is you that must think about it :) <  32 bits  > 00000000000000000000000000000000 = 0 01111111111111111111111111111111 = +2147483647 10000000000000000000000000000000 = 2147483648 not 0. 11111111111111111111111111111111 = 1
I agree with that.
When you said that the first bit is used for the sign i thought that you meant
0 and 31 bits = +a
1 and 31 bits = a
and with that i could not agree:)

Tim Van Wassenhove <http://home.mysth.be/~timvw>  
P: n/a

Tim Van Wassenhove wrote: In article <tC*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:
Tim Van Wassenhove wrote:
In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:
Tim Van Wassenhove wrote:
>In article <UU*****************@newssvr23.news.prodigy.com> , Michael Austin wrote: > > > >>and if you are thinking I was wrong that 2^32 is 2147483648, integer is >>signed  in otherwords it is 2^31 and the 32nd bit is for +/. > > >I think you are mistaken here. >Complement notation, as in the first (2^32)/2 represent a positive integer >and the last (2^32)/2 represent a negative integer. >
That is correct! If bit 32 is 0 it is positive, if bit 32 is 1 it is negative... I think that if you were to use your calculator, you just said the same thing I did.. bit 32 (MSB) is for +/. The maximum value in an integer is +/ 2147483648 If you use your calculater 2^32 is 2147483648*2. So, no, I was not wrong... :) :)
So this means you have a +0 and a 0 ? ;)
Think about it, first (2^32)/2 thus from 0 to 2^311 represent a positive integers. And from from 2^31 to 2^321 represent negative integers.
I think it is you that must think about it :) <  32 bits  > 00000000000000000000000000000000 = 0 01111111111111111111111111111111 = +2147483647 10000000000000000000000000000000 = 2147483648 not 0. 11111111111111111111111111111111 = 1
I agree with that.
When you said that the first bit is used for the sign i thought that you meant 0 and 31 bits = +a 1 and 31 bits = a
and with that i could not agree:)
We were saying the same thing... just the perspective was skewed...
and that all depends on whether or not your CPU is little endian or big
endian or as in the case of the Alpha CPU (DEC/HP) it is biendian :)
Michael Austin.  
P: n/a

"Andrew" <an****@nowherenohow.com> wrote in message
news:Jh*****************@newsread1.news.pas.earthl ink.net... What is the largest number (integer?) that I can work with in PHP?
For example, I have this number:
1082655076035
This is actually a date that I need to compare with another date.
I was just going to see if one was greater than the other but it doesn't seem to be working.
I can try to convert it to a date object if that is the only way to do it...
Well, you can use floats for numbers beyond an int's range. Since you're
just doing comparison, the loss of precision doesn't matter.
Getting back to the question, there is practically no limit to how large a
integer PHP can handle, as there's the GMP module.  
P: n/a

Hi Chung,
On Tue, 22 Jun 2004 18:38:12 0400, "Chung Leong"
<ch***********@hotmail.com> wrote: "Andrew" <an****@nowherenohow.com> wrote in message news:Jh*****************@newsread1.news.pas.earth link.net... What is the largest number (integer?) that I can work with in PHP?
For example, I have this number:
1082655076035
This is actually a date that I need to compare with another date.
I was just going to see if one was greater than the other but it doesn't seem to be working.
I can try to convert it to a date object if that is the only way to do it...
Well, you can use floats for numbers beyond an int's range. Since you're just doing comparison, the loss of precision doesn't matter.
Well, if you compare a calculated float to a literal float you should
keep in mind that they might not be equal. You should always check if
the float is within a certain range of a literal float, due to the
limited representation of a float.
Use (1.41  sqrt(2)) < 0.01
instead of 1.41 == sqrt(2)
This problem is *not* dependent on the precision of a float.
HTH, Jochen

Jochen Daum  Cabletalk Group Ltd.
PHP DB Edit Toolkit  PHP scripts for building
database editing interfaces. http://sourceforge.net/projects/phpdbedittk/   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 11421
 replies: 11
 date asked: Jul 17 '05
