I want to have an operator for true division (like /
in python) giving a float as the result and floor division (like //
in python) giving an integer regardless of the input data types.
For example,
5 / 2
= 2.5 and 5.0 // 2.0
= 2.
I would prefer not to use //
as I'm using that for line comments (with /* ... */
for block comments). What other options are there to have both true/'real' division and floor division operators?
x / y
andfloor(x / y)
for doubles, or(double)x / y
andx / y
for ints, just fine. $\endgroup$/
for integer division (which floors or truncates) is that this leads to confusion when people write2 / 3
and are surprised that the result is zero. There are many questions on Stack Overflow about exactly that, across multiple languages. Many people consider it a footgun. $\endgroup$