still slow but more precise than c version