I have researched and drafted a proposal to address the deficiencies
with the remainder operator (%) and introduce support for the proper
mathematical modulo operation.
In summary, the % operator is commonly used and referred to as a mod by
developers, but is fundamentally broken because it takes the sign of the
dividend. The proposal outlines two alternative algorithms (Euclidian
and floored division) that are commonly used within other languages and
suggests either new Math.mod or .floorMod methods, or new infix operator
such as %% or mod to address the situation.
Hi,
I have researched and drafted a proposal to address the deficiencies
with the remainder operator (%) and introduce support for the proper
mathematical modulo operation.
https://github.com/lachlanhunt/es-proposals/tree/master/modulo
In summary, the % operator is commonly used and referred to as a mod by
developers, but is fundamentally broken because it takes the sign of the
dividend. The proposal outlines two alternative algorithms (Euclidian
and floored division) that are commonly used within other languages and
suggests either new Math.mod or .floorMod methods, or new infix operator
such as %% or mod to address the situation.
--
Lachlan Hunt
https://lachy.id.au/
I have researched and drafted a proposal to address the deficiencies with the remainder operator (%) and introduce support for the proper mathematical modulo operation.
lachlanhunt/es-proposals/tree/master/modulo
In summary, the % operator is commonly used and referred to as a mod by developers, but is fundamentally broken because it takes the sign of the dividend. The proposal outlines two alternative algorithms (Euclidian and floored division) that are commonly used within other languages and suggests either new Math.mod or .floorMod methods, or new infix operator such as %% or mod to address the situation.