Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118449 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35726 invoked from network); 21 Aug 2022 18:25:56 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 21 Aug 2022 18:25:56 -0000 To: internals@lists.php.net Date: Sun, 21 Aug 2022 14:30:34 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 97.118.64.184 Subject: Proposal for floored division and modulo functions From: dwo@the-wolfeden.com (Daniel Wolfe) Message-ID: Hello, Before I submit an RFC, I’d like to see what others’ thoughts are. Should PHP implement functions for floor division and floor modulo? To keep it simple, in some programming languages such as PHP and C, the result of integer division will be rounded towards zero, and result of the modulo operation will have the same sign as the dividend (i.e., the first operand). This is the “truncation technique”. In other programming languages (e.g., Python, Ruby, Tcl), the result of integer division will be rounded instead towards negative infinity and result of the modulo operation will have the same sign as the divisor (i.e., the second operand). This is the “floor technique”. In Java, the division and modulo operators use the truncation technique, but there also exist static methods (`Math.floorDiv` and `Math.floorMod`) that provide the functionality for the floor technique. I have a fork on Github that adds functions named `floor_div` and `floor_mod` which implement the floor technique. Before I submit a pull request and write up an RFC, what are your thoughts or concerns about adding this to PHP? * * *