float.__mod__ and float.__divmod__ produce incorrect results for negative numbers
Open
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 603
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
## Description
The current `__mod__` implementation for all float types uses LLVM's `frem` instruction, which computes the IEEE 754 remainder (truncated toward zero). However, `__floordiv__` is implemented as `floor(a / b)`, which follows Python's floored division semantics. This mismatch causes the fundamental identity `(a // b) * b + (a % b) == a` to break when negative numbers are involved.
## Example
```python
a = -1.0
b = 3.0
print(a % b) # Codon outputs: -1.0, expected (Python): 2.0
print(a // b) # Codon outputs: -1.0, which is correct
```
Contributor guide
Assessment
This issue has not been assessed yet.