TITLE: When Jensen's inequality is equality
QUESTION [31 upvotes]: One form of Jensen's inequality is

If $X$ is a random variable and $g$ is a convex function, then
  $\mathbb{E}(g(X))\geq g(\mathbb{E}(X))$.

Just out of curiosity, when do we have equality? If and only if $g$ is constant?

REPLY [13 votes]: Just for the sake of having an "answered" question (thanks to @hardmath and @Did), Jensen's inequality is equality when $g$ is affine or $X$ is constant almost surely.