Proposal for floored division and modulo functions

From: Date: Sun, 21 Aug 2022 20:30:34 +0000
Subject: Proposal for floored division and modulo functions
Groups: php.internals 
Request: Send a blank email to internals+get-118449@lists.php.net to get a copy of this message
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? * <https://en.wikipedia.org/wiki/Modulo_operation> * <https://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html> * <https://www.microsoft.com/en-us/research/publication/division-and-modulus-for-computer-scientists/>

« previous php.internals (#118449) next »