Within 2 % tolerance implies the use of fabs might be a good idea.

if (fabs(1 - N/D) < 0.02)

The correct value is the one I normally use for D. So, I would use the user value for N. In other...