Determination of Madelung constants for infinite and semi-infinite lattices by direct summation