div function for safe dividing