zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Wrong Python float division

Open mikir opened this issue 5 years ago • 1 comments

The Python emitter currently uses floor division operator '//' regardless of the operand types.

Example:

5 // 2 = 2 (correct)
5.0 // 2 = 2.0 (wrong!)

It will be necessary to fix Python emitter to check the operand types and to use both division operators ('/' or '//').

mikir avatar Nov 22 '19 12:11 mikir

Please be careful to Python division operator for negative numbers:

3 // 2 = 1
-3 // 2 = -2

Because of that we should probably consider to use something like

(int)(-3 / 2) = -1

Because of that, modulo operator in Python gives different results compared to Java/C++.

mikir avatar May 25 '22 09:05 mikir