I would like to find the integer x that minimizes a function. That is:
$$ x_{min} = \min_{x \in \mathbb{Z}}{(n - e^x)^2} $$
The goal is to write a program that computes the integer $x$ such that $e^x$ is closest to $n$, preferably avoiding conditionals.
Without the integer constraint, obviously $x_{min} = \ln{n}$, but how to go about this with the integer constraint?