function to compute square