464,372 Members | 1,230 Online Need help? Post your question and get tips & solutions from a community of 464,372 IT Pros & Developers. It's quick & easy.

# Large Numbers?

 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 Jul 17 '05 #1
11 Replies

 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 platform-dependent, 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 platform-dependent, 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. Jul 17 '05 #2

 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. Jul 17 '05 #3

 P: n/a In article , 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 Jul 17 '05 #4

 P: n/a Tim Van Wassenhove wrote: In article , Michael Austin wrote:and if you are thinking I was wrong that 2^32 is 2147483648, integer issigned - 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... Jul 17 '05 #5

 P: n/a In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote: Tim Van Wassenhove wrote: In article , Michael Austin wrote:and if you are thinking I was wrong that 2^32 is 2147483648, integer issigned - 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^31-1 represent a positive integers. And from from 2^31 to 2^32-1 represent negative integers. -- Tim Van Wassenhove Jul 17 '05 #6

 P: n/a Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:Tim Van Wassenhove wrote:In article , Michael Austin wrote: and if you are thinking I was wrong that 2^32 is 2147483648, integer issigned - 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 integerand 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 isnegative... I think that if you were to use your calculator, you justsaid the same thing I did.. bit 32 (MSB) is for +/-. The maximum valuein an integer is +/- 2147483648 If you use your calculater 2^32 is2147483648*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^31-1 represent a positive integers. And from from 2^31 to 2^32-1 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: http://www.firstdbasource.com/ma.php :) ;) Michael Austin. Jul 17 '05 #7

 P: n/a Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:Tim Van Wassenhove wrote:In article , Michael Austin wrote: and if you are thinking I was wrong that 2^32 is 2147483648, integer issigned - 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 integerand 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 isnegative... I think that if you were to use your calculator, you justsaid the same thing I did.. bit 32 (MSB) is for +/-. The maximum valuein an integer is +/- 2147483648 If you use your calculater 2^32 is2147483648*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^31-1 represent a positive integers. And from from 2^31 to 2^32-1 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. Jul 17 '05 #8

 P: n/a In article , Michael Austin wrote: Tim Van Wassenhove wrote: In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote:Tim Van Wassenhove wrote:In article , 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 integerand 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 isnegative... I think that if you were to use your calculator, you justsaid the same thing I did.. bit 32 (MSB) is for +/-. The maximum valuein an integer is +/- 2147483648 If you use your calculater 2^32 is2147483648*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^31-1 represent a positive integers. And from from 2^31 to 2^32-1 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 Jul 17 '05 #9

 P: n/a Tim Van Wassenhove wrote: In article , Michael Austin wrote:Tim Van Wassenhove wrote:In article <1e*****************@newssvr24.news.prodigy.com> , Michael Austin wrote: Tim Van Wassenhove wrote: >In article , 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 isnegative... I think that if you were to use your calculator, you justsaid the same thing I did.. bit 32 (MSB) is for +/-. The maximum valuein an integer is +/- 2147483648 If you use your calculater 2^32 is2147483648*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^31-1 represent apositive integers. And from from 2^31 to 2^32-1 represent negativeintegers. 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 bi-endian :) Michael Austin. Jul 17 '05 #10

 P: n/a "Andrew" 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. Jul 17 '05 #11

 P: n/a Hi Chung, On Tue, 22 Jun 2004 18:38:12 -0400, "Chung Leong" wrote: "Andrew" wrote in messagenews: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'rejust 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/ Jul 17 '05 #12

### This discussion thread is closed

Replies have been disabled for this discussion. 