Avoid overflows in free-energy kernel