Bring general sketch commits upstream

Move the general parts of PR #1178 upstream decrease the maintenance work.
Great opportunity to replace this by std::numeric_limits.