Skip to content

Mutate between modulo and floor division #5642

Description

@casperdewith

Among the supported mutators, the modulo (remainder) operation only occurs once: a % b can be mutated to a * b, and the assignment expression a %= b to a *= b.

But when dealing with modulo, the most similar operator – the one that’s easiest to confuse – is floor division. That’s why I suggest the addition of the following mutators, using // to mean floor division:

  • a % b to a // b
  • a // b to a % b
  • a %= b to a //= b
  • a //= b to a %= b

This could be implemented just like the other mutators in Scala and C#.

JavaScript unfortunately does not have a built-in integer-division operation for numbers – only for BigInts. So perhaps in that case, the pattern Math.floor(n / d) can be recognised and mutated to n % d, and vice versa.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions