d * 10000 can cause type overflow. Don't forget about this tricky place.