Skip to content

Prefer idiv

SuggestionAuto-fixableRoblox
small-rules/prefer-idiv

Prefer .idiv() for integer division instead of math.floor(x / y) or math.floor(x * 0.5).

Rationale

roblox-ts has x.idiv(y). It does what math.floor(x / y) does, and it compiles to x // y. That skips a floor call. It should be a bit faster, and it says what you meant.

Auto-fixes math.floor(x / y) to x.idiv(y). It only reports when the right side is a division. It skips odd cases.

Diagnostic Messages

useIdiv
Use .idiv() instead of math.floor(x / y) or math.floor(x * 0.5) for integer division.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/prefer-idiv": "error"
}
}

Examples

floor division expression
math.floor(x / y);

After auto-fix

x.idiv(y);
integer division method
x.idiv(y);