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?