fixed ``sqrt_mod`` for negative modulus