Still waiting for Integer Division

# Michael Haufe (7 years ago)

In 2008 I first proposed the addition of an integer division operator to the language. At the time Brendan noted his regret for this oversight and desire for the operator as well. I am not seeing this operator available in the current draft. Can/will this be rectified?

a div b = (a - a % b) / b
# Brendan Eich (7 years ago)

This turns out to be equivalent to


which is how asm.js optimizes to avoid the FPU already.

# Waldemar Horwat (7 years ago)

It's not equivalent for values greater than 2^31. The | version wraps around; div would give the correct answer.

# Oliver Hunt (7 years ago)

I presume brendan meant


Which seems to be the asm.js way -- although that said, there shouldn't be any requirement on a compile flag to tell us what we can simply turn this into an idiv...

# Brendan Eich (7 years ago)

There's no need, right. My "asm.js optimizes" was about the type system at -- not about any JS change or VM flag or whatever.

And yes, to Waldemar's point, this is for int32.

Michael, were you looking for integer-domain double div? I suppose we were back in 2008. It's still missing.

# Michael Haufe (7 years ago)

As long as the domain is consistent with (%) or potentially strawman:modulo_operator I'm indifferent as my applications are within int32