Skip to content

Conversation

@dvdvgt
Copy link
Collaborator

@dvdvgt dvdvgt commented Dec 17, 2025

Since this is based on effekt definitions and not FFI, this has the added side-effect of also unifying the behavior across all backends.

@dvdvgt
Copy link
Collaborator Author

dvdvgt commented Dec 17, 2025

All backends except LLVM used to use floor-based integer division prior to this PR such that 8 / -3 = -3 and not 8 / -3 = -2. Thus, I changed the infixDiv implementations for JS and Chez to make it consistent with LLVM

def div(x: Int, y: Int): Int = {
val q = x / y
val r = x.rem(y)
q - (r.bitwiseShr(31).bitwiseAnd(y.bitwiseShr(31).bitwiseOr(1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid question: Will this work on LLVM where Int is i64 as opposed to f64 (~i32 for the purposes of bin ops) like in JS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants