exaloop / exaloop/codon

float.__mod__ and float.__divmod__ produce incorrect results for negative numbers

Open
#775 2 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.