Extend template's mod and modBool functions to accept any int types

This fixes #575