only calculate sqrt if it is really necessary