473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Large Numbers?

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

Jul 17 '05 #5
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^31-1 represent a
positive integers. And from from 2^31 to 2^32-1 represent negative
integers.

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #6
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^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:

<?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.
Jul 17 '05 #7
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^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
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^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 <http://home.mysth.be/~timvw>
Jul 17 '05 #9
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^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:)


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
"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.
Jul 17 '05 #11
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/
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: koray | last post by:
hi, i need to show large numbers seperated by commas. since i'm using variables from speedscript, i cannot know their values, since the user should enter them. how should i code to show these...
3
by: Alex Vinokur | last post by:
Dann Corbit has implemented function int ilog2 (unsigned long) at http://groups.google.com/groups?selm=lkPa4.2165%24I41.1498%40client Is exist a similar C++-function for very large numbers,...
5
by: Todd Steury | last post by:
Greetings Python'ers: I'm just an amature who occasionally uses Python for complex mathematical models. The current model I'm working with occasionally generates really large numbers that are...
10
by: Tuvas | last post by:
I've been thinking about writing a program to generate the world's largest prime numbers, just for the fun of it. This would require being able to hold an 8000000 digit number into memory (25...
18
by: Brad | last post by:
I have a problem in that I need to change a large decimal value into its hex equivalent. The largest decimal value I need to represent as hex is 25516777215. The problem here is that this number...
18
by: Zero | last post by:
Hi, I am calculating an integer to the pwer of a large integer, e.g. 2^5000. It turns out that the result I always get is zero. I am sure that the result is too large to store in such type...
22
by: Frinton | last post by:
Hi, I am trying to do some calculations on large numbers (ie 7,768,489,957,892,578,474,792,094 / 12,280) and no matter what I do it doesn't get it quite right. Its always somewhere between 10...
3
by: CFonville | last post by:
I was wondering if there is any way to store large numbers in a variable? With this simple script: var bigpi = 1234567890123456789012345678901234567890123456789012345678901234567890;...
57
by: Chris Foote | last post by:
Hi all. I have the need to store a large (10M) number of keys in a hash table, based on a tuple of (long_integer, integer). The standard python dictionary works well for small numbers of keys,...
0
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.