FileDocCategorySizeDatePackage
ExsltMath.javaAPI DocJava SE 5 API11467Fri Aug 26 14:55:32 BST 2005com.sun.org.apache.xalan.internal.lib

ExsltMath

public class ExsltMath extends ExsltBase
This class contains EXSLT math extension functions. It is accessed by specifying a namespace URI as follows:
xmlns:math="http://exslt.org/math"
The documentation for each function has been copied from the relevant EXSLT Implementer page.
see
EXSLT
xsl.usage
general

Fields Summary
private static String
PI
private static String
E
private static String
SQRRT2
private static String
LN2
private static String
LN10
private static String
LOG2E
private static String
SQRT1_2
Constructors Summary
Methods Summary
public static doubleabs(double num)
The math:abs function returns the absolute value of a number.

param
num A number
return
The absolute value of the number

     return Math.abs(num);
   
public static doubleacos(double num)
The math:acos function returns the arccosine value of a number.

param
num A number
return
The arccosine value of the number

     return Math.acos(num);
   
public static doubleasin(double num)
The math:asin function returns the arcsine value of a number.

param
num A number
return
The arcsine value of the number

     return Math.asin(num);
   
public static doubleatan(double num)
The math:atan function returns the arctangent value of a number.

param
num A number
return
The arctangent value of the number

     return Math.atan(num);
   
public static doubleatan2(double num1, double num2)
The math:atan2 function returns the angle ( in radians ) from the X axis to a point (y,x).

param
num1 The X axis value
param
num2 The Y axis value
return
The angle (in radians) from the X axis to a point (y,x)

     return Math.atan2(num1, num2);
   
public static doubleconstant(java.lang.String name, double precision)
The math:constant function returns the specified constant to a set precision. The possible constants are:
PI
E
SQRRT2
LN2
LN10
LOG2E
SQRT1_2

param
name The name of the constant
param
precision The precision
return
The value of the specified constant to the given precision

     String value = null;
     if (name.equals("PI"))
       value = PI;
     else if (name.equals("E"))
       value = E;
     else if (name.equals("SQRRT2"))
       value = SQRRT2;
     else if (name.equals("LN2"))
       value = LN2;
     else if (name.equals("LN10"))
       value = LN10;
     else if (name.equals("LOG2E"))
       value = LOG2E;
     else if (name.equals("SQRT1_2"))
       value = SQRT1_2;
     
     if (value != null)
     {
       int bits = new Double(precision).intValue();
       
       if (bits <= value.length())
         value = value.substring(0, bits);
         
       return new Double(value).doubleValue();
     }
     else
       return Double.NaN;
            
   
public static doublecos(double num)
The math:cos function returns cosine of the passed argument.

param
num A number
return
The cosine value of the number

     return Math.cos(num);
   
public static doubleexp(double num)
The math:exp function returns e (the base of natural logarithms) raised to a power.

param
num A number
return
The value of e raised to the given power

     return Math.exp(num);
   
public static org.w3c.dom.NodeListhighest(org.w3c.dom.NodeList nl)
The math:highest function returns the nodes in the node set whose value is the maximum value for the node set. The maximum value for the node set is the same as the value as calculated by math:max. A node has this maximum value if the result of converting its string value to a number as if by the number function is equal to the maximum value, where the equality comparison is defined as a numerical comparison using the = operator.

If any of the nodes in the node set has a non-numeric value, the math:max function will return NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any of the nodes in the node set has a non-numeric value, math:highest will return an empty node set.

param
nl The NodeList for the node-set to be evaluated.
return
node-set with nodes containing the maximum value found, an empty node-set if any node cannot be converted to a number.

        
    double maxValue = max(nl);

    NodeSet highNodes = new NodeSet();
    highNodes.setShouldCacheNodes(true);    
    
    if (Double.isNaN(maxValue))
      return highNodes;  // empty Nodeset
    
    for (int i = 0; i < nl.getLength(); i++)
    {
      Node n = nl.item(i);
      double d = toNumber(n); 
      if (d == maxValue)
        highNodes.addElement(n);
    }
    return highNodes;
  
public static doublelog(double num)
The math:log function returns the natural logarithm of a number.

param
num A number
return
The natural logarithm of the number

     return Math.log(num);
   
public static org.w3c.dom.NodeListlowest(org.w3c.dom.NodeList nl)
The math:lowest function returns the nodes in the node set whose value is the minimum value for the node set. The minimum value for the node set is the same as the value as calculated by math:min. A node has this minimum value if the result of converting its string value to a number as if by the number function is equal to the minimum value, where the equality comparison is defined as a numerical comparison using the = operator.

If any of the nodes in the node set has a non-numeric value, the math:min function will return NaN. The definition numeric comparisons entails that NaN != NaN. Therefore if any of the nodes in the node set has a non-numeric value, math:lowest will return an empty node set.

param
nl The NodeList for the node-set to be evaluated.
return
node-set with nodes containing the minimum value found, an empty node-set if any node cannot be converted to a number.

    double minValue = min(nl);

    NodeSet lowNodes = new NodeSet();
    lowNodes.setShouldCacheNodes(true);
    
    if (Double.isNaN(minValue))
      return lowNodes;  // empty Nodeset
    
    for (int i = 0; i < nl.getLength(); i++)
    {
      Node n = nl.item(i);
      double d = toNumber(n); 
      if (d == minValue)
        lowNodes.addElement(n);
    }
    return lowNodes;
  
public static doublemax(org.w3c.dom.NodeList nl)
The math:max function returns the maximum value of the nodes passed as the argument. The maximum value is defined as follows. The node set passed as an argument is sorted in descending order as it would be by xsl:sort with a data type of number. The maximum is the result of converting the string value of the first node in this sorted list to a number using the number function.

If the node set is empty, or if the result of converting the string values of any of the nodes to a number is NaN, then NaN is returned.

param
nl The NodeList for the node-set to be evaluated.
return
the maximum value found, NaN if any node cannot be converted to a number.
see
EXSLT

	
                                                                                                                                              
       
  
    if (nl == null || nl.getLength() == 0)
      return Double.NaN;
      
    double m = - Double.MAX_VALUE;
    for (int i = 0; i < nl.getLength(); i++)
    {
      Node n = nl.item(i);
      double d = toNumber(n);
      if (Double.isNaN(d))
        return Double.NaN;
      else if (d > m)
        m = d;
    }
  	
    return m;  	
  
public static doublemin(org.w3c.dom.NodeList nl)
The math:min function returns the minimum value of the nodes passed as the argument. The minimum value is defined as follows. The node set passed as an argument is sorted in ascending order as it would be by xsl:sort with a data type of number. The minimum is the result of converting the string value of the first node in this sorted list to a number using the number function.

If the node set is empty, or if the result of converting the string values of any of the nodes to a number is NaN, then NaN is returned.

param
nl The NodeList for the node-set to be evaluated.
return
the minimum value found, NaN if any node cannot be converted to a number.
see
EXSLT

    if (nl == null || nl.getLength() == 0)
      return Double.NaN;

    double m = Double.MAX_VALUE;
    for (int i = 0; i < nl.getLength(); i++)
    {
      Node n = nl.item(i);
      double d = toNumber(n);
      if (Double.isNaN(d))
        return Double.NaN;
      else if (d < m)
        m = d;
    }
    
    return m;
  
public static doublepower(double num1, double num2)
The math:power function returns the value of a base expression taken to a specified power.

param
num1 The base
param
num2 The power
return
The value of the base expression taken to the specified power

     return Math.pow(num1, num2);
   
public static doublerandom()
The math:random function returns a random number from 0 to 1.

return
A random double from 0 to 1

     return Math.random();
   
public static doublesin(double num)
The math:sin function returns the sine of the number.

param
num A number
return
The sine value of the number

     return Math.sin(num);
   
public static doublesqrt(double num)
The math:sqrt function returns the square root of a number.

param
num A number
return
The square root of the number

     return Math.sqrt(num);
   
public static doubletan(double num)
The math:tan function returns the tangent of the number passed as an argument.

param
num A number
return
The tangent value of the number

     return Math.tan(num);