Thursday, November 5, 2009

Big Integers

The runtime recently underwent its first change that is not 100% compatible with Zend based PHP: arbitrary precision integers.

In Zend PHP, an integer (represented as a long, which is generally 32 bits or 64 bits big, depending on the platform) will overflow to a float. This happens when you specify a large literal integer in the source code, or upon certain arithmetical operations.

We've decided to integrate seamless "bignums" into Roadsend PHP instead. This means you can specify an integer as big as you want (only limited by memory), and that arithmetical operations will yield accurate results even when the numbers get large.

Internally, integers that can fit into a hardware word are still represented this way, for speed. They will convert to a bignum (using GMP library) only when necessary.

Zend PHP 5.x and current 6 has support for this now only through the GMP or BC math extensions. This is awkward since you have to juggle the numbers as resources. But, according to recent developer notes, this same functionality may end up in Zend PHP at some point as well.

So, either we're a little ahead of the curve, or we're diverging slightly. Either way we think this is a win for the language as a whole.

3 comments:

web design hampshire said...

Hey it’s so nice I really want to appreciate to this site. It’s so much interesting matter I like your work. Please carry on with your work and post me such a wonderful article.

website melbourne said...

The BigDecimal class is similar to the BigInteger class but it allows you to use decimal values. Give this code a shot:

PHP programming said...

Great thinking about globalization issue . I appreciate with your blog fully,so give inform me when you have update your blog. PHP Programming