morten      01/12/04 08:59:10

  Modified:    java/src/org/apache/xalan/xsltc/compiler Parser.java
                        RoundCall.java
               java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
  Log:
  Changed the return-type of the round() function form int to double. The result
  is still rounded (of course), but it is returned as a double to be able to
  return NaN and infinite values.
  PR:           bugzilla 2805
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.38      +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Parser.java       2001/11/27 13:55:28     1.37
  +++ Parser.java       2001/12/04 16:59:09     1.38
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Parser.java,v 1.37 2001/11/27 13:55:28 morten Exp $
  + * @(#)$Id: Parser.java,v 1.38 2001/12/04 16:59:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -705,7 +705,7 @@
        _symbolTable.addPrimop("generate-id", S_A);
        _symbolTable.addPrimop("ceiling", R_R);
        _symbolTable.addPrimop("floor", R_R);
  -     _symbolTable.addPrimop("round", I_R);
  +     _symbolTable.addPrimop("round", R_R);
        _symbolTable.addPrimop("contains", B_SS);
        _symbolTable.addPrimop("number", R_O);
        _symbolTable.addPrimop("number", R_V);
  
  
  
  1.3       +11 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RoundCall.java
  
  Index: RoundCall.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RoundCall.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RoundCall.java    2001/09/19 17:54:15     1.2
  +++ RoundCall.java    2001/12/04 16:59:09     1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: RoundCall.java,v 1.2 2001/09/19 17:54:15 morten Exp $
  + * @(#)$Id: RoundCall.java,v 1.3 2001/12/04 16:59:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -76,9 +76,18 @@
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
        final ConstantPoolGen cpg = classGen.getConstantPool();
        final InstructionList il = methodGen.getInstructionList();
  +
  +     // Get two copies of the argument on the stack
        argument().translate(classGen, methodGen);
  +     il.append(DUP2);
  +
  +     // Check if the argument is NaN
  +     il.append(new INVOKESTATIC(cpg.addMethodref("java.lang.Double",
  +                                                 "isNaN", "(D)Z")));
  +     final BranchHandle skip = il.append(new IFNE(null));
        il.append(new INVOKESTATIC(cpg.addMethodref(MATH_CLASS,
                                                    "round", "(D)J")));
  -     il.append(L2I);         // no long type :-(
  +     il.append(L2D);
  +     skip.setTarget(il.append(NOP));
       }
   }
  
  
  
  1.33      +8 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
  
  Index: BasisLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- BasisLibrary.java 2001/12/04 12:59:40     1.32
  +++ BasisLibrary.java 2001/12/04 16:59:10     1.33
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: BasisLibrary.java,v 1.32 2001/12/04 12:59:40 morten Exp $
  + * @(#)$Id: BasisLibrary.java,v 1.33 2001/12/04 16:59:10 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -827,9 +827,13 @@
   
       private static double lowerBounds = 0.001;
       private static double upperBounds = 10000000;
  -    private static DecimalFormat defaultFormatter = new DecimalFormat();
  +    private static DecimalFormat defaultFormatter;
       private static String defaultPattern = "####################.#########";
   
  +    static {
  +     defaultFormatter = new DecimalFormat();
  +    }
  +
       /**
        * Utility function: used in RealType to convert a real to a string.
        * Removes the decimal if null.
  @@ -847,6 +851,8 @@
                return result;
        }
        else {
  +         if (Double.isNaN(d) || Double.isInfinite(d))
  +             return(Double.toString(d));
            return formatNumber(d, defaultPattern, defaultFormatter);
        }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to