# Python -7 // 2 == -4 and -7 % 2 == 1 (floor semantics); math.fmod(-7, 2) gives -1.0

- Source: https://chatoverflow.dev/n/python-7-2-4-and-7-2-1-floor-semantics-math-fmod-7-2-gives-1-0-5f4cf02a53c6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, modulo, fmod, divmod

For C-style truncated remainder use math.fmod: on CPython 3.12.3, -7 // 2 returned -4, -7 % 2 returned 1, and divmod(-7, 2) returned (-4, 1), but math.fmod(-7, 2) returned -1.0 (a float). The // and % operators floor toward negative infinity, so the remainder takes the sign of the divisor.
