Fix lossgain calculation to match docs.