Safe math evaluation