Re: [PHP-DEV] [RFC] intdiv()

2014-07-18 Thread Andrea Faulds
On 18 Jul 2014, at 04:39, Tjerk Meesters tjerk.meest...@gmail.com wrote: This makes it more complicated because a language change requires 2/3 majority while a new function requires 50% + 1. To make things simpler - and I believe it had been proposed before - the main vote should include

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 04:23, Sara Golemon poll...@php.net wrote: Do we need a new operator for that? It feels un-php to me, and the kind of problem bigint objects should be meant to solve. On the other hand, having $a/$b != $a/$b (Off by more than 100 in this instance). But back on the first

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 01:11, Bishop Bettini bis...@php.net wrote: As another contender, how about: $x = 242 %/ 7; $x %/= 13; The % reflects the relationship to modulus, while the / reflects the division effect. I think %/ looks worse, but I think it seems more apropos. I also quite

RE: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Zeev Suraski
-Original Message- From: Andrea Faulds [mailto:a...@ajf.me] Sent: Wednesday, July 16, 2014 6:15 PM To: bis...@php.net Cc: PHP internals Subject: Re: [PHP-DEV] [RFC] intdiv() The RFC has been updated to v0.2. It now proposes a %% operator for integer division (with corresponding

RE: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Zeev Suraski
-Original Message- From: Kris Craig [mailto:kris.cr...@gmail.com] Sent: Thursday, July 17, 2014 6:02 AM To: Andrea Faulds Cc: Stas Malyshev; PHP internals Subject: Re: [PHP-DEV] [RFC] intdiv() On Tue, Jul 15, 2014 at 5:13 AM, Andrea Faulds a...@ajf.me wrote: Perhaps the RFC could

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 07:29, Zeev Suraski z...@zend.com wrote: From debating whether it's worth it to add a new function for an not-so-commonly-used-operation-to-say-the-least, we're now seriously considering adding a new language level operator? Really? Is it *really* not that common? I can

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Pierre Joye
Hi Andrea, On Thu, Jul 17, 2014 at 8:44 AM, Andrea Faulds a...@ajf.me wrote: On 17 Jul 2014, at 07:29, Zeev Suraski z...@zend.com wrote: From debating whether it's worth it to add a new function for an not-so-commonly-used-operation-to-say-the-least, we're now seriously considering adding a

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 07:56, Pierre Joye pierre@gmail.com wrote: The rare cases where I had to do that, I relied on bcmath or gmp. Yes, I needed some extra ops to actually achieve what this RFC proposes but it is good enough. The new ops overloading for extension simplifies that a lot as

RE: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Zeev Suraski
-Original Message- From: Andrea Faulds [mailto:a...@ajf.me] Sent: Thursday, July 17, 2014 9:44 AM To: Zeev Suraski Cc: bis...@php.net; PHP internals Subject: Re: [PHP-DEV] [RFC] intdiv() On 17 Jul 2014, at 07:29, Zeev Suraski z...@zend.com wrote: From debating whether it's

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 08:02, Zeev Suraski z...@zend.com wrote: I think it is, given I believe it's the first time people are asking for this after PHP's been out for almost two decades... As the RFC itself suggests, you can use the current division for most use cases, including the ones

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Stas Malyshev
Hi! * Time (actually pretty common in web apps, though we have a DateTime class) Admittedly, we're getting closer to the dreaded year 2038, but what does it actually mean to divide current Unix timestamp by 3 and why one would ever want to do this? We also have classes for real datetime

RE: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Zeev Suraski
-Original Message- From: Andrea Faulds [mailto:a...@ajf.me] Sent: Thursday, July 17, 2014 10:09 AM To: Zeev Suraski Cc: bis...@php.net; PHP internals Subject: Re: [PHP-DEV] [RFC] intdiv() On 17 Jul 2014, at 08:02, Zeev Suraski z...@zend.com wrote: I think it is, given I believe

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Lester Caine
On 17/07/14 04:23, Sara Golemon wrote: Wow. I just finally understood what your RFC was going for. I thought you were trying to cover the case where ($a%$b)==0, but you're not, you're trying to do truncated integer division regardless of remainder. I also missed the fact that div_function

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 08:19, Zeev Suraski z...@zend.com wrote: PHP's not Perl. Let's keep it that way please… I don't think it makes sense to add a specialized integer division operator when we do have a different division operator, and I don't think other dynamic languages have such an

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Lester Caine
On 17/07/14 08:02, Zeev Suraski wrote: I think it is, given I believe it's the first time people are asking for this after PHP's been out for almost two decades... As the RFC itself suggests, you can use the current division for most use cases, including the ones mentioned above - they'd work

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 08:17, Stas Malyshev smalys...@sugarcrm.com wrote: Hi! * Time (actually pretty common in web apps, though we have a DateTime class) Admittedly, we're getting closer to the dreaded year 2038, but what does it actually mean to divide current Unix timestamp by 3 and why

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Nikita Popov
On Thu, Jul 17, 2014 at 2:25 AM, Sara Golemon poll...@php.net wrote: On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds a...@ajf.me wrote: Nikita Popov doesn’t seem to be a fan of the %% syntax, so it may be subject to change, though I think it’s the best I’ve heard so far. ;) Nor am I.

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Andrea Faulds
On 17 Jul 2014, at 10:24, Nikita Popov nikita@gmail.com wrote: This is already what is currently happening, see http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.c#1067. Andreas proposal is only useful in the case that the numbers don't divide exactly and you need

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Kris Craig
On Thu, Jul 17, 2014 at 6:31 AM, Andrea Faulds a...@ajf.me wrote: On 17 Jul 2014, at 10:24, Nikita Popov nikita@gmail.com wrote: This is already what is currently happening, see http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.c#1067. Andreas proposal is only useful in the

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Tjerk Meesters
On Fri, Jul 18, 2014 at 10:47 AM, Kris Craig kris.cr...@gmail.com wrote: On Thu, Jul 17, 2014 at 6:31 AM, Andrea Faulds a...@ajf.me wrote: On 17 Jul 2014, at 10:24, Nikita Popov nikita@gmail.com wrote: This is already what is currently happening, see

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Kris Craig
On Thu, Jul 17, 2014 at 8:39 PM, Tjerk Meesters tjerk.meest...@gmail.com wrote: On Fri, Jul 18, 2014 at 10:47 AM, Kris Craig kris.cr...@gmail.com wrote: On Thu, Jul 17, 2014 at 6:31 AM, Andrea Faulds a...@ajf.me wrote: On 17 Jul 2014, at 10:24, Nikita Popov nikita@gmail.com wrote:

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Tjerk Meesters
On Fri, Jul 18, 2014 at 12:04 PM, Kris Craig kris.cr...@gmail.com wrote: On Thu, Jul 17, 2014 at 8:39 PM, Tjerk Meesters tjerk.meest...@gmail.com wrote: On Fri, Jul 18, 2014 at 10:47 AM, Kris Craig kris.cr...@gmail.com wrote: On Thu, Jul 17, 2014 at 6:31 AM, Andrea Faulds a...@ajf.me

Re: [PHP-DEV] [RFC] intdiv()

2014-07-17 Thread Kris Craig
On Thu, Jul 17, 2014 at 9:18 PM, Tjerk Meesters tjerk.meest...@gmail.com wrote: On Fri, Jul 18, 2014 at 12:04 PM, Kris Craig kris.cr...@gmail.com wrote: On Thu, Jul 17, 2014 at 8:39 PM, Tjerk Meesters tjerk.meest...@gmail.com wrote: On Fri, Jul 18, 2014 at 10:47 AM, Kris Craig

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Andrea Faulds
On 16 Jul 2014, at 02:51, Bishop Bettini bis...@php.net wrote: TL;DR -- I agree with the principal but want implemented as the infix operator %% with a test for PHP_INT_MIN %% -1 === false (and a E_WARNING). The RFC has been updated to v0.2. It now proposes a %% operator for integer division

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Bishop Bettini
As another contender, how about: $x = 242 %/ 7; $x %/= 13; The % reflects the relationship to modulus, while the / reflects the division effect. I think %/ looks worse, but I think it seems more apropos. On Jul 16, 2014 11:15 AM, Andrea Faulds a...@ajf.me wrote: On 16 Jul 2014, at 02:51,

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Sara Golemon
On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds a...@ajf.me wrote: Nikita Popov doesn’t seem to be a fan of the %% syntax, so it may be subject to change, though I think it’s the best I’ve heard so far. ;) Nor am I. Here's a thought though: How about just making / return int when there's no

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Tjerk Meesters
Hi Sara, On Thu, Jul 17, 2014 at 8:25 AM, Sara Golemon poll...@php.net wrote: On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds a...@ajf.me wrote: Nikita Popov doesn’t seem to be a fan of the %% syntax, so it may be subject to change, though I think it’s the best I’ve heard so far. ;) Nor am

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Sara Golemon
On Wed, Jul 16, 2014 at 6:51 PM, Tjerk Meesters tjerk.meest...@gmail.com wrote: Just out of curiosity, does the compiler optimise it into something like this? if (a % b) { return a / b; } else { return (double)a / b; } Ya know what? I feel dumb. FP division is a whole separate

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Andrea Faulds
On July 17, 2014 at 3:17 AM Sara Golemon poll...@php.net wrote: All that said, *I* think the tradeoff of an extra idivq in the (probably more common) remainder case is worth it in the interest keeping PHP's syntax simple. What are you suggesting you do for an integer division, then? ($a -

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Sara Golemon
On Wed, Jul 16, 2014 at 7:34 PM, Andrea Faulds a...@ajf.me wrote: What are you suggesting you do for an integer division, then? ($a - ($a % $b)) / $ b? The division operator already returns an integer. Or should I just use intdiv()? It does, but it returns the float truncated result of

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Kris Craig
On Tue, Jul 15, 2014 at 5:13 AM, Andrea Faulds a...@ajf.me wrote: On 15 Jul 2014, at 06:50, Kris Craig kris.cr...@gmail.com wrote: While a practical argument can certainly be made that existing solutions can fit the examples OP cited, I don't think that takes away from the underlying

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Sara Golemon
On Wed, Jul 16, 2014 at 7:34 PM, Andrea Faulds a...@ajf.me wrote: What are you suggesting you do for an integer division, then? ($a - ($a % $b)) / $ b? The division operator already returns an integer. Or should I just use intdiv()? Wow. I just finally understood what your RFC was going for.

Re: [PHP-DEV] [RFC] intdiv()

2014-07-16 Thread Yasuo Ohgaki
Hi all, On Thu, Jul 17, 2014 at 12:23 PM, Sara Golemon poll...@php.net wrote: On Wed, Jul 16, 2014 at 7:34 PM, Andrea Faulds a...@ajf.me wrote: What are you suggesting you do for an integer division, then? ($a - ($a % $b)) / $ b? The division operator already returns an integer. Or should

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Lester Caine
On 15/07/14 06:17, Stas Malyshev wrote: Both of those are likely not to be installed on most systems. Why do Why not? bcmath is in core since forever and has no external requirements, gmp builds practically everywhere too. AFAIR all distros have it. Taking this in isolation is wrong ... It is

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 15 Jul 2014, at 03:31, Bishop Bettini bis...@php.net wrote: I need some education. Can you elaborate on the specific situations where integer division would be used without other functions from bcmath or gmp? I see in the RFC you mention seconds to hh:mm and index to rows/cols, but can

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 15 Jul 2014, at 06:50, Kris Craig kris.cr...@gmail.com wrote: While a practical argument can certainly be made that existing solutions can fit the examples OP cited, I don't think that takes away from the underlying principle of the argument: That there's no reason *not* to include a

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 15 Jul 2014, at 08:06, Lester Caine les...@lsces.co.uk wrote: Taking this in isolation is wrong ... It is essentially linked up with all of the discussion on '64bit' processing. What seems to be ignored so far is the simple 'bigint' value. Limiting 32 bit systems to only support 32 bit

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 15 Jul 2014, at 06:17, Stas Malyshev smalys...@sugarcrm.com wrote: Why not? bcmath is in core since forever and has no external requirements, gmp builds practically everywhere too. AFAIR all distros have it. Partly practicality, partly principle. A barebones installation of PHP may not

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Yasuo Ohgaki
Hi Andrea, On Tue, Jul 15, 2014 at 11:10 AM, Yasuo Ohgaki yohg...@ohgaki.net wrote: On Tue, Jul 15, 2014 at 9:14 AM, Andrea Faulds a...@ajf.me wrote: PHP currently lacks a way to do integer division. You can floor or int cast a floating-point division, but beyond 53-bits that produces the

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 15 Jul 2014, at 23:12, Yasuo Ohgaki yohg...@ohgaki.net wrote: If we are going to have integer arithmetics, it may be better to have full set of operators/functions https://bugs.php.net/bug.php?id=30701 I’d rather not go to that length, but if someone wants to do that, they may.

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Bishop Bettini
Hi Andrea, TL;DR -- I agree with the principal but want implemented as the infix operator %% with a test for PHP_INT_MIN %% -1 === false (and a E_WARNING). As a user, I could implement intdiv and get the same functionality as proposed: function intdiv($n, $d) { return (int)($n / $d); }

Re: [PHP-DEV] [RFC] intdiv()

2014-07-15 Thread Andrea Faulds
On 16 Jul 2014, at 02:51, Bishop Bettini bis...@php.net wrote: Hi Andrea, TL;DR -- I agree with the principal but want implemented as the infix operator %% with a test for PHP_INT_MIN %% -1 === false (and a E_WARNING). %% is perhaps the only good non-keyword syntax choice. I like that.

[PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Andrea Faulds
Good evening again, PHP currently lacks a way to do integer division. You can floor or int cast a floating-point division, but beyond 53-bits that produces the wrong result: $ sapi/cli/php -r 'var_dump((int)(PHP_INT_MAX / 3));' int(3074457345618258432) Furthermore, using a floating-point

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Stas Malyshev
Hi! It elaborates a little more, so I’d suggest reading it first. What are your thoughts? I think this is a simple and obvious addition. INT_MAX is kind of an edge case, if you need arbitrary-length precision you can always use gmp or bcmath. I'm not sure this one-off use case that is already

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Andrea Faulds
On 15 Jul 2014, at 01:58, Stas Malyshev smalys...@sugarcrm.com wrote: INT_MAX is kind of an edge case, It’s just an obvious example, integers beyond 2^53 fulfill this. if you need arbitrary-length precision you can always use gmp or bcmath. I’m not asking for arbitrary-length precision,

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Yasuo Ohgaki
Hi Andrea, On Tue, Jul 15, 2014 at 9:14 AM, Andrea Faulds a...@ajf.me wrote: PHP currently lacks a way to do integer division. You can floor or int cast a floating-point division, but beyond 53-bits that produces the wrong result: $ sapi/cli/php -r 'var_dump((int)(PHP_INT_MAX / 3));'

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Bishop Bettini
Hi Andrea, I need some education. Can you elaborate on the specific situations where integer division would be used without other functions from bcmath or gmp? I see in the RFC you mention seconds to hh:mm and index to rows/cols, but can you give some actual before and after samples? Like this

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Stas Malyshev
Hi! Both of those are likely not to be installed on most systems. Why do Why not? bcmath is in core since forever and has no external requirements, gmp builds practically everywhere too. AFAIR all distros have it. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ --

Re: [PHP-DEV] [RFC] intdiv()

2014-07-14 Thread Kris Craig
On Mon, Jul 14, 2014 at 10:17 PM, Stas Malyshev smalys...@sugarcrm.com wrote: Hi! Both of those are likely not to be installed on most systems. Why do Why not? bcmath is in core since forever and has no external requirements, gmp builds practically everywhere too. AFAIR all distros have