Skip to content

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

Description

@pauvrepetit

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions