You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2010/11/05 22:18:53 UTC
svn commit: r1031800 -
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java
Author: sandygao
Date: Fri Nov 5 21:18:52 2010
New Revision: 1031800
URL: http://svn.apache.org/viewvc?rev=1031800&view=rev
Log:
Bug fix: precision decimal comparison. a) In compareTo(), if the other value is NaN, should return INDETERMINATE. b) If one value is +0 and the other -0, should return equal. c) In equals(), if both are NaN, treat as equal.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java?rev=1031800&r1=1031799&r2=1031800&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/PrecisionDecimalDV.java Fri Nov 5 21:18:52 2010
@@ -163,7 +163,11 @@ class PrecisionDecimalDV extends TypeVal
return false;
}
- final XPrecisionDecimal oval = (XPrecisionDecimal)val;
+ final XPrecisionDecimal oval = (XPrecisionDecimal)val;
+ if (sign == 0 && oval.sign == 0) {
+ // Both are NaN. Treat as "equal".
+ return true;
+ }
return this.compareTo(oval) == EQUAL;
}
@@ -204,7 +208,7 @@ class PrecisionDecimalDV extends TypeVal
public int compareTo(XPrecisionDecimal val) {
// seen NaN
- if (sign == 0) {
+ if (sign == 0 || val.sign == 0) {
return INDETERMINATE;
}
@@ -231,11 +235,20 @@ class PrecisionDecimalDV extends TypeVal
}
if (sign != val.sign) {
+ // Return equal if both are 0
+ if (isZero() && val.isZero()) {
+ return EQUAL;
+ }
return sign > val.sign ? GREATER_THAN : LESS_THAN;
}
return sign * compare(val);
}
+ private boolean isZero() {
+ // Either "000" or "0.00"
+ return totalDigits == 1 && intDigits == 0 &&
+ (fracDigits == 0 || fvalue.charAt(fracDigits-1) == '0');
+ }
// To enable comparison - the exponent part of the decimal will be limited
// to the max value of int.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org