Currently PHP integer is limited to 2147483647 or 9223372036854775807
(PHP_INT_MAX), depending of system bits. We can works with long
integers by using bcmath, for instance. But why not to support it
natively?
I mean, PHP can parse infinity integers, but it's converted to
cientific notation or to INF.
My suggestion is that, instead of convert it, stores the value in
another format, an int[] or string, expanding depending of parsed
length.
Then accept things like:
10000000000000000000000000000000 + 10000000000000000000000000000000 =
20000000000000000000000000000000
Yeah, I know that it should be slower than normal ints, but is an
exceptional case. It should avoid problems caused by untested code
with very large numbers, for instance.
Same for float values, but in this case I think that should have a
best implementation to defines length of mantissa, for instance (new
Float($float, $bits), for instance). But it can be part of another
discussion.
--
David Rodrigues
There was / is a proposal about bigints, see:
https://wiki.php.net/rfc/bigint
Regards //Björn Larsson
Den 2016-08-29 kl. 15:48, skrev David Rodrigues:
Currently PHP integer is limited to 2147483647 or 9223372036854775807
(PHP_INT_MAX), depending of system bits. We can works with long
integers by using bcmath, for instance. But why not to support it
natively?I mean, PHP can parse infinity integers, but it's converted to
cientific notation or to INF.My suggestion is that, instead of convert it, stores the value in
another format, an int[] or string, expanding depending of parsed
length.Then accept things like:
10000000000000000000000000000000 + 10000000000000000000000000000000 =
20000000000000000000000000000000Yeah, I know that it should be slower than normal ints, but is an
exceptional case. It should avoid problems caused by untested code
with very large numbers, for instance.Same for float values, but in this case I think that should have a
best implementation to defines length of mantissa, for instance (new
Float($float, $bits), for instance). But it can be part of another
discussion.
Hi Björn and David,
As the author of that proposal, I'd say it's more of a “was”. It was a
huge project and I gave up on it. It could be attempted again, but I
don't expect PHP 8 to be appearing very soon (and this is a change that
would have to be in a major version), and I'm not sure if there's really
such a big benefit. It's more a nice-to-have than a killer feature.
After all, if you need arbitrary-precision integers with operator
overloading and everything, ext/gmp already exists. And furthermore, the
vast majority of applications don't need more than 64-bit integers.
Thanks.
Björn Larsson wrote:
There was / is a proposal about bigints, see:
https://wiki.php.net/rfc/bigint
Regards //Björn Larsson
Den 2016-08-29 kl. 15:48, skrev David Rodrigues:
Currently PHP integer is limited to 2147483647 or 9223372036854775807
(PHP_INT_MAX), depending of system bits. We can works with long
integers by using bcmath, for instance. But why not to support it
natively?I mean, PHP can parse infinity integers, but it's converted to
cientific notation or to INF.My suggestion is that, instead of convert it, stores the value in
another format, an int[] or string, expanding depending of parsed
length.Then accept things like:
10000000000000000000000000000000 + 10000000000000000000000000000000 =
20000000000000000000000000000000Yeah, I know that it should be slower than normal ints, but is an
exceptional case. It should avoid problems caused by untested code
with very large numbers, for instance.Same for float values, but in this case I think that should have a
best implementation to defines length of mantissa, for instance (new
Float($float, $bits), for instance). But it can be part of another
discussion.
--
Andrea Faulds
https://ajf.me/