From: <et...@us...> - 2011-06-30 14:18:25
|
Revision: 4418 http://mxquery.svn.sourceforge.net/mxquery/?rev=4418&view=rev Author: etterth Date: 2011-06-30 14:18:19 +0000 (Thu, 30 Jun 2011) Log Message: ----------- - Fixed bugs in Double/Float printing - added TypeAnnotation for NodeToken Modified Paths: -------------- trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDouble.java trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryFloat.java trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java trunk/XQIB_Testing/src/ch/ethz/mxquery/testsuite/XQueryTestCase.java Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDouble.java =================================================================== --- trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDouble.java 2011-06-29 11:52:09 UTC (rev 4417) +++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryDouble.java 2011-06-30 14:18:19 UTC (rev 4418) @@ -293,7 +293,8 @@ */ protected static String toString(double value, String javaStrValue, boolean isNegativeZero) { - + + javaStrValue = javaStrValue.replace("e+", "E"); if (value==0.0) { if (javaStrValue.charAt(0) == '-' || isNegativeZero) { return "-0"; @@ -302,45 +303,65 @@ } } + if (Double.isNaN(value) ) { + return "NaN"; + } if (Double.isInfinite(value)) { return (value > 0 ? "INF" : "-INF"); } - if (Double.isNaN(value)) { - return "NaN"; - } final double absval = Math.abs(value); String s = javaStrValue; -// if (absval < 1.0e-6 || absval >= 1.0e+6) { -// if (s.indexOf('E')<0) { -// // need to use scientific notation, but Java isn't using it -// // (Java's cutoff is 1.0E7, while XPath's is 1.0E6) -// // So we have for example -2000000.0 rather than -2.0e6 -// StringBuffer sb = new StringBuffer(32); -// Matcher matcher = nonExponentialPattern.matcher(s); -// -// if (matcher.matches()) { -// sb.append(matcher.group(1)); -// sb.append('.'); -// sb.append(matcher.group(2)); -// final String fraction = matcher.group(4); -// if ("0".equals(fraction)) { -// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); -// return sb.toString(); -// } else { -// sb.append(matcher.group(3)); -// sb.append(matcher.group(4)); -// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); -// return sb.toString(); -// } -// } else { -// // fallback, this shouldn't happen -// return s; -// } -// } else { -// return s; -// } -// } + if (absval < 1.0e-6 || absval >= 1.0e+6) { + if (s.indexOf('E')<0) { + String sign; + if (s.charAt(0) == '-') { + sign = "-"; + s = s.substring(1); + } else { + sign = ""; + } + char firstchar = s.charAt(0); + s = s.substring(1); + int e = s.length(); + while (s.endsWith("0") && s.length()>1) { + s = s.substring(0, s.length()-1); + } + return sign + firstchar + "." + s + "E" + e; + } else { + return s; + } + } +// if (absval < 1.0e-6 || absval >= 1.0e+6) { +// if (s.indexOf('E')<0) { +// // need to use scientific notation, but Java isn't using it +// // (Java's cutoff is 1.0E7, while XPath's is 1.0E6) +// // So we have for example -2000000.0 rather than -2.0e6 +// StringBuffer sb = new StringBuffer(32); +// Matcher matcher = nonExponentialPattern.matcher(s); +// +// if (matcher.matches()) { +// sb.append(matcher.group(1)); +// sb.append('.'); +// sb.append(matcher.group(2)); +// final String fraction = matcher.group(4); +// if ("0".equals(fraction)) { +// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); +// return sb.toString(); +// } else { +// sb.append(matcher.group(3)); +// sb.append(matcher.group(4)); +// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); +// return sb.toString(); +// } +// } else { +// // fallback, this shouldn't happen +// return s; +// } +// } else { +// return s; +// } +// } int len = s.length(); if (s.endsWith("E0")) { @@ -351,11 +372,12 @@ } int e = s.indexOf('E'); if (e < 0) { - // For some reason, Double.toString() in Java can return strings such as "0.0040" - // so we remove any trailing zeros - while (s.charAt(len - 1) == '0' && s.charAt(len - 2) != '.') { - s = s.substring(0, --len); - } + //This problem seems not to occur in JS +// // For some reason, Double.toString() in Java can return strings such as "0.0040" +// // so we remove any trailing zeros +// while (s.charAt(len - 1) == '0' && s.charAt(len - 2) != '.') { +// s = s.substring(0, --len); +// } return s; } Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryFloat.java =================================================================== --- trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryFloat.java 2011-06-29 11:52:09 UTC (rev 4417) +++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/datamodel/MXQueryFloat.java 2011-06-30 14:18:19 UTC (rev 4418) @@ -21,6 +21,7 @@ //import java.util.Locale; //import ch.ethz.mxquery.util.browser.regex.Matcher; // + import ch.ethz.mxquery.datamodel.types.Type; import ch.ethz.mxquery.exceptions.DynamicException; import ch.ethz.mxquery.exceptions.ErrorCodes; @@ -78,7 +79,8 @@ } try { - val = Float.parseFloat(s); + //parseFloat is buggy in GWT + val = (float) Double.parseDouble(s); } catch (NumberFormatException nfe) { throw new TypeException(ErrorCodes.F0023_INVALID_VALUE_FOR_CAST_CONSTRUCTOR, "Not a double value", null); } if (val == 0.0) negativeZero = isNegative; @@ -334,110 +336,111 @@ } - /** - * Conversion of a double to a string - * @param the actual double value - * @param the double value converted to string using the Java conventions. - * This value is adjusted as necessary to cater for the differences between the Java and XPath rules. - * @return the value converted to a string, according to the XPath casting rules. - */ - - public static String toString(float val, String javaStrValue, boolean negativeZero) { - - - - if (val==0.0) { - if (javaStrValue.charAt(0) == '-'|| negativeZero) { - return "-0"; - } else { - return "0"; - } - } - - if (Float.isInfinite(val)) { - return (val > 0 ? "INF" : "-INF"); - } - if (Float.isNaN(val)) { - return "NaN"; - } - - double value = roundForOutput(val); - - String s = javaStrValue; - if (val != value) - s = ""+value; - -// //final float absval = (float)Math.abs(val); -// if ((val > 0 && (val < (1.0e-6)-5e-10 || val >= 1.0e+6))|| -// (val < 0 && (val > (-1.0e-6)+5e-10 || val <= -1.0e+6))) { -// if (s.indexOf('E')<0) { -// // need to use scientific notation, but Java isn't using it -// // (Java's cutoff is 1.0E7, while XPath's is 1.0E6) -// // So we have for example -2000000.0 rather than -2.0e6 -// StringBuffer sb = new StringBuffer(32); -// Matcher matcher = nonExponentialPattern.matcher(s); -// -// if (matcher.matches()) { -// sb.append(matcher.group(1)); -// sb.append('.'); -// sb.append(matcher.group(2)); -// final String fraction = matcher.group(4); -// if ("0".equals(fraction)) { -// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); -// return sb.toString(); -// } else { -// sb.append(matcher.group(3)); -// sb.append(matcher.group(4)); -// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); -// return sb.toString(); -// } -// } else { -// // fallback, this shouldn't happen -// return s; -// } +// /** +// * Conversion of a double to a string +// * @param the actual double value +// * @param the double value converted to string using the Java conventions. +// * This value is adjusted as necessary to cater for the differences between the Java and XPath rules. +// * @return the value converted to a string, according to the XPath casting rules. +// */ +// +// public static String toString(float val, String javaStrValue, boolean negativeZero) { +// +// +// +// if (val==0.0) { +// if (javaStrValue.charAt(0) == '-'|| negativeZero) { +// return "-0"; // } else { -// return s; +// return "0"; // } // } - - int len = s.length(); - if (s.endsWith("E0")) { - s = s.substring(0, len - 2); - } - if (s.endsWith(".0")) { - return s.substring(0, len - 2); - } - int e = s.indexOf('E'); - if (e < 0) { - // For some reason, Double.toString() in Java can return strings such as "0.0040" - // so we remove any trailing zeros - while (s.charAt(len - 1) == '0' && s.charAt(len - 2) != '.') { - s = s.substring(0, --len); - } - return s; - } - - //-- E is present in the number - int exp = Integer.parseInt(s.substring(e + 1)); - String sign; - if (s.charAt(0) == '-') { - sign = "-"; - s = s.substring(1); - --e; - } else { - sign = ""; - } - int nDigits = e - 2; - if (exp >= nDigits) { - return sign + s.substring(0, 1) + s.substring(2, e) + zeros(exp - nDigits); - } else if (exp > 0) { - return sign + s.substring(0, 1) + s.substring(2, 2 + exp) + '.' + s.substring(2 + exp, e); - } else { - while (s.charAt(e-1) == '0') e--; - return sign + "0." + zeros(-1 - exp) + s.substring(0, 1) + s.substring(2, e); - } - //-- - } +// +// if (Float.isNaN(val)) { +// return "NaN"; +// } +// if (Float.isInfinite(val)) { +// return (val > 0 ? "INF" : "-INF"); +// } +// +// Environment.log("float.toString1 " + val); +// double value = roundForOutput(val); +// Environment.log("float.toString2 " + val); +// String s = javaStrValue; +// if (val != value) +// s = ""+value; +// +//// //final float absval = (float)Math.abs(val); +//// if ((val > 0 && (val < (1.0e-6)-5e-10 || val >= 1.0e+6))|| +//// (val < 0 && (val > (-1.0e-6)+5e-10 || val <= -1.0e+6))) { +//// if (s.indexOf('E')<0) { +//// // need to use scientific notation, but Java isn't using it +//// // (Java's cutoff is 1.0E7, while XPath's is 1.0E6) +//// // So we have for example -2000000.0 rather than -2.0e6 +//// StringBuffer sb = new StringBuffer(32); +//// Matcher matcher = nonExponentialPattern.matcher(s); +//// +//// if (matcher.matches()) { +//// sb.append(matcher.group(1)); +//// sb.append('.'); +//// sb.append(matcher.group(2)); +//// final String fraction = matcher.group(4); +//// if ("0".equals(fraction)) { +//// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); +//// return sb.toString(); +//// } else { +//// sb.append(matcher.group(3)); +//// sb.append(matcher.group(4)); +//// sb.append("E" + (matcher.group(2).length() + matcher.group(3).length())); +//// return sb.toString(); +//// } +//// } else { +//// // fallback, this shouldn't happen +//// return s; +//// } +//// } else { +//// return s; +//// } +//// } +// +// int len = s.length(); +// if (s.endsWith("E0")) { +// s = s.substring(0, len - 2); +// } +// if (s.endsWith(".0")) { +// return s.substring(0, len - 2); +// } +// int e = s.indexOf('E'); +// if (e < 0) { +// // For some reason, Double.toString() in Java can return strings such as "0.0040" +// // so we remove any trailing zeros +// while (s.charAt(len - 1) == '0' && s.charAt(len - 2) != '.') { +// s = s.substring(0, --len); +// } +// return s; +// } +// +// //-- E is present in the number +// int exp = Integer.parseInt(s.substring(e + 1)); +// String sign; +// if (s.charAt(0) == '-') { +// sign = "-"; +// s = s.substring(1); +// --e; +// } else { +// sign = ""; +// } +// int nDigits = e - 2; +// if (exp >= nDigits) { +// return sign + s.substring(0, 1) + s.substring(2, e) + zeros(exp - nDigits); +// } else if (exp > 0) { +// return sign + s.substring(0, 1) + s.substring(2, 2 + exp) + '.' + s.substring(2 + exp, e); +// } else { +// while (s.charAt(e-1) == '0') e--; +// return sign + "0." + zeros(-1 - exp) + s.substring(0, 1) + s.substring(2, e); +// } +// //-- +// } static String zeros(int n) { char[] buf = new char[n]; @@ -452,15 +455,15 @@ public String toString() { - return MXQueryFloat.toString(val, ""+val, negativeZero); + return MXQueryDouble.toString(val, ""+val, negativeZero); } - public String toTypedString(boolean isFloat) { - if (isFloat) - return MXQueryFloat.toString((float)val, ""+(float)val, negativeZero); - else - return MXQueryFloat.toString(val, ""+val, negativeZero); - } +// public String toTypedString(boolean isFloat) { +// if (isFloat) +// return MXQueryFloat.toString((float)val, ""+(float)val, negativeZero); +// else +// return MXQueryFloat.toString(val, ""+val, negativeZero); +// } // public String toFormatString(int digit) { Modified: trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java =================================================================== --- trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java 2011-06-29 11:52:09 UTC (rev 4417) +++ trunk/MXQuery/xqib_src/ch/ethz/mxquery/update/store/domImpl/NodeToken.java 2011-06-30 14:18:19 UTC (rev 4418) @@ -18,6 +18,7 @@ import ch.ethz.mxquery.datamodel.Namespace; import ch.ethz.mxquery.datamodel.QName; import ch.ethz.mxquery.datamodel.StructuralIdentifier; +import ch.ethz.mxquery.datamodel.types.Type; import ch.ethz.mxquery.datamodel.xdm.TokenInterface; import ch.ethz.mxquery.datamodel.xdm.XDMScope; import ch.ethz.mxquery.exceptions.MXQueryException; @@ -85,12 +86,12 @@ if (other.node == this.node) return 0; short comp = this.node.compareDocumentPosition(other.node); - if ((comp | Node.DOCUMENT_POSITION_PRECEDING) != 0 || - (comp | Node.DOCUMENT_POSITION_CONTAINS) != 0)//the other is parent + if ((comp & Node.DOCUMENT_POSITION_PRECEDING) != 0 || + (comp & Node.DOCUMENT_POSITION_CONTAINS) != 0)//the other is parent return -1; - if ((comp | Node.DOCUMENT_POSITION_FOLLOWING) != 0 || - (comp | Node.DOCUMENT_POSITION_CONTAINED_BY) != 0)//the other is child + if ((comp & Node.DOCUMENT_POSITION_FOLLOWING) != 0 || + (comp & Node.DOCUMENT_POSITION_CONTAINED_BY) != 0)//the other is child return 1; return -2; @@ -153,7 +154,7 @@ @Override public int getTypeAnnotation() { - return 0; + return Type.UNTYPED; } public String getPrefix(){ Modified: trunk/XQIB_Testing/src/ch/ethz/mxquery/testsuite/XQueryTestCase.java =================================================================== --- trunk/XQIB_Testing/src/ch/ethz/mxquery/testsuite/XQueryTestCase.java 2011-06-29 11:52:09 UTC (rev 4417) +++ trunk/XQIB_Testing/src/ch/ethz/mxquery/testsuite/XQueryTestCase.java 2011-06-30 14:18:19 UTC (rev 4418) @@ -78,7 +78,7 @@ public void addSchemaMapping(String namespace, String uri) { schemas.add(new NamespaceToUri(namespace, uri)); - throw new UnsupportedOperationException("There is no schema support in XQIB"); +// throw new UnsupportedOperationException("There is no schema support in XQIB"); } public void addInputQuery(String varname, String source) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |