Seems like the lower limit for minval should be much lower for a log encoder, maybe close to epsilon.