From ef56b86d61bbe7ae1cb0a3265f80ea34a6ac9d78 Mon Sep 17 00:00:00 2001 From: "brade%netscape.com" Date: Wed, 15 Nov 2000 10:54:41 +0000 Subject: [PATCH] use inline methods rather than typecasting directly to floats to prevent rounding errors (bug #56022); r=jst; sr=buster --- content/html/content/src/nsGenericHTMLElement.cpp | 13 ++++++++++--- layout/html/content/src/nsGenericHTMLElement.cpp | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 4abe29f3c3c..886eb59a6cf 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1606,7 +1606,8 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, case eHTMLUnit_Percent: { nsAutoString intStr; - intStr.AppendInt(PRInt32(value->GetPercentValue() * 100.0f)); + float percentVal = value->GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Assign(intStr); aResult.Append(PRUnichar('%')); @@ -2202,10 +2203,13 @@ nsGenericHTMLElement::ValueOrPercentToString(const nsHTMLValue& aValue, aResult.Append(intStr); return PR_TRUE; case eHTMLUnit_Percent: - intStr.AppendInt(PRInt32(aValue.GetPercentValue() * 100.0f)); + { + float percentVal = aValue.GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Append(intStr); aResult.Append(PRUnichar('%')); return PR_TRUE; + } default: break; } @@ -2228,10 +2232,13 @@ nsGenericHTMLElement::ValueOrPercentOrProportionalToString(const nsHTMLValue& aV aResult.Append(intStr); return PR_TRUE; case eHTMLUnit_Percent: - intStr.AppendInt(PRInt32(aValue.GetPercentValue() * 100.0f)); + { + float percentVal = aValue.GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Append(intStr); aResult.Append(NS_LITERAL_STRING("%")); return PR_TRUE; + } case eHTMLUnit_Proportional: intStr.AppendInt(aValue.GetIntValue()); aResult.Append(intStr); diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index 4abe29f3c3c..886eb59a6cf 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -1606,7 +1606,8 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, case eHTMLUnit_Percent: { nsAutoString intStr; - intStr.AppendInt(PRInt32(value->GetPercentValue() * 100.0f)); + float percentVal = value->GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Assign(intStr); aResult.Append(PRUnichar('%')); @@ -2202,10 +2203,13 @@ nsGenericHTMLElement::ValueOrPercentToString(const nsHTMLValue& aValue, aResult.Append(intStr); return PR_TRUE; case eHTMLUnit_Percent: - intStr.AppendInt(PRInt32(aValue.GetPercentValue() * 100.0f)); + { + float percentVal = aValue.GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Append(intStr); aResult.Append(PRUnichar('%')); return PR_TRUE; + } default: break; } @@ -2228,10 +2232,13 @@ nsGenericHTMLElement::ValueOrPercentOrProportionalToString(const nsHTMLValue& aV aResult.Append(intStr); return PR_TRUE; case eHTMLUnit_Percent: - intStr.AppendInt(PRInt32(aValue.GetPercentValue() * 100.0f)); + { + float percentVal = aValue.GetPercentValue() * 100.0f; + intStr.AppendInt(NSToCoordRoundExclusive(percentVal)); aResult.Append(intStr); aResult.Append(NS_LITERAL_STRING("%")); return PR_TRUE; + } case eHTMLUnit_Proportional: intStr.AppendInt(aValue.GetIntValue()); aResult.Append(intStr);