I'm trying to figure out how big integers in PHP can be and am having
some difficulty.
My first idea was to try something like this:
<?
for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++);
echo $bits;
?>
The result was 30. This, however, is incorrect as the following
demonstrates:
<?
$num = 1<<30;
echo "num = $num\r\n";
echo 'num<<1 = '.($num<<1)."\r \n";
echo 'num*2 = '.($num*2)."\r\ n";
?>
That my first idea would return the wrong result doesn't surprise me,
though, since bitwise operators in PHP are treated as arithematic ones
and not logical ones.
So I came up with another test.
<?
for ($bits=0; pow(2,$bits+1) > pow(2,$bits); $bits++);
echo $bits;
?>
In Windows XP, I got 1024 back. On Linux 2.6.13.2 and 2.4.28 (as
reported by phpinfo), all I get are timeout errors. So I decided to
make my script more efficient and hopefully faster:
<?
$x = 2;
$y = 1;
for ($bits=1; ($x*=2) > ($y*=2); $bits++);
echo $bits;
?>
On Windows XP, I again got 1024 back, whereas on Linux, I again got
timeout errors.
All in all, this leaves me a little confussed as to how to interpret
the results. Can integers in PHP be of an infinite precission when
running on Linux? If so, what's the point of the BCMath / GMP
functions on Linux?
Also, if this is the case, then how would I go about writting an
infinite precission integer arithmetic library that wasn't OS
dependant? I could make it work on Windows by using the bcmath
functions, since Windows builds of PHP include them by default, and use
PHP's normal integer stuff on Linux (Linux builds of PHP don't include
bcmath by default). But what about all the other platforms for which
PHP is available on? What about Mac OS X / OS/2 / etc? Would it be
safe to assume that if PHP's built-in integer functions didn't support
infinite precission that it'd include support for bcmath? 3 36897
In answer to you linux time out problem, run it on the command line
then it wont turn out. This command should do the trick I think: php -a
[file path, not remote path].
I think the length of the integer is dependant on the number of bits
the computer is so 32bit or 64 bit. You are running a 32bit computer,
yes? So 32 squared (1024) is the length, whereas if you were using
64bit then it would be 64 squared (4096)
yawnmoth wrote: I'm trying to figure out how big integers in PHP can be and am having some difficulty.
From http://us3.php.net/intval :
"The maximum value depends on the system. 32 bit systems have a maximum
signed integer range of -2147483648 to 2147483647. So for example on
such a system, intval('1000000 000000') will return 2147483647. The
maximum signed integer value for 64 bit systems is 922337203685477 5807."
Michael wrote: In answer to you linux time out problem, run it on the command line then it wont turn out. This command should do the trick I think: php -a [file path, not remote path].
I think the length of the integer is dependant on the number of bits the computer is so 32bit or 64 bit. You are running a 32bit computer, yes? So 32 squared (1024) is the length, whereas if you were using 64bit then it would be 64 squared (4096)
Since you are requesting this in the PHP newsgroup, a search for INTEGER in the
PHP docs yields: http://us2.php.net/intval
"The maximum value depends on the system. 32 bit systems have a maximum signed
integer range of -2147483648 to 2147483647. So for example on such a system,
intval('1000000 000000') will return 2147483647. The maximum signed integer value
for 64 bit systems is 922337203685477 5807."
Another point is that may have more to do with the OS you are on. So, if you
are running a 32bit OS on a 64bit CPU, the max integer value will still be
2147483647. It really has more to do with the compilers, math libraries and OS
limitations as well as those of the cpu type.
--
Michael Austin.
Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lokanathan |
last post by:
How to set Richtextbox Maximum Byte Size?
|
by: Gregory Hassett |
last post by:
Hello,
Does anyone know how to get the maximum size of a datagram for a UDP Socket
created via .NET's System.Net.Sockets.Socket class?
Thanks!
|
by: Bei |
last post by:
I would like to allow more connection to SQL servers from the web
application.
Do you know what is the code to set maximum pool size in web.config file?
Thanks
|
by: Bei |
last post by:
In web.config, will there be an issue if I set the maximum pool size to be
too large, like 1000?
I see normally people set it to 100 or less. But I want to make sure there
will be no error like "all pooled connections were in use", so I decided to
make the maximum so large that it will never be reached.
Do you think it's OK, no drawback?
Thanks
|
by: ari |
last post by:
Hi!
Normally Google helps a lot with these simple questions, but now I
cannot get correct search words. So I try here:
I have db2 udb 8.1 fix pack 6, and it is on windows 2003 server.
- what is the maximum table space size? 64GB?
- what is the maximum container size for tablespace?
| |
by: sundar261 |
last post by:
Hi,
I am using ifstream open() to open an greater than 5GB file (more 100
million record) and open() fails to open the file. But I am able to
open smaller sized files (around 1GB) with the same program
What is maximum file size that I can open. Is it dependent on number
of records or file size in bytes?
What is the best way to open big files?? Do we have any compiler
|
by: skyy |
last post by:
Hi.. i am doing some uploading of files using CGI with perl script..
the $CGI::POST_MAX is used to limit the maximum size of the upload file.
Did anyone know what is the maximum size that i can set for $CGI::POST_MAX? and thus the maximum upload size for file upload...
Thanks!
|
by: =?Utf-8?B?bXIgcGVhbnV0?= |
last post by:
At some time in the distant past I had an insufficient memory problem that
resulted as an artifact of there being a maximum allowable size for any
single object in Windows. In the case that I recall, I had an array that
exceeded the threshold. I still had plenty of physical memory available.
I cannot remember what that threshold was and I am hoping someone knows
where I can find it on the Microsoft/MSDN site(s).
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a
column of type INTEGER UNSIGNED. Is there a constant in PHP to insert
the maximum value possible into the column? The underlying OS is Red
Hat Linux, but I'm not sure about the version.
Any help you can provide is appreciated, - Dave
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |