Package org.zkoss.zss.engine.xel

Examples of org.zkoss.zss.engine.xel.SSErrorXelException


   */
  public static Object mathFloor(Object[] args, XelContext ctx){
    final double number = CommonFns.toNumber(args[0]).doubleValue();
    double significance = CommonFns.toNumber(args[1]).doubleValue();
    if(significance == 0) {
      throw new SSErrorXelException(SSError.DIV0);
    } else if(number*significance < 0) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      double result = significance*Math.floor(number/significance);
      return new Double(result);
    }
  }
View Full Code Here


   * @param n - number 2
   * @return the greatest common divisor
   */
  public static int gcd(int m, int n) {
    if(m < 0 || n < 0) {
      throw new SSErrorXelException(SSError.NUM);
    }
    return MathUtils.gcd(m, n);
    }
View Full Code Here

  public static Object mathMdeterm(Object[] args, XelContext ctx){
    double[][] d = UtilFns.toDoubleMatrix(args);
    //not a valid square matrix, return #VALUE!
    if(d.length != d[0].length
    {
      throw new SSErrorXelException(SSError.VALUE);
    }
    else
    {
      RealMatrix m = new RealMatrixImpl(d);
      try{
        double result = m.getDeterminant();
        return UtilFns.toDouble15(result, BigDecimal.ROUND_HALF_UP);
      }
      //shouldn't happen to run into this exception. because we already check the matrix if it is square.
      catch(InvalidMatrixException e)
      {
        throw new SSErrorXelException(SSError.VALUE);
      }
    }
  }
View Full Code Here

  public static Object mathMinverse(Object[] args, XelContext ctx){
    double array[][] = UtilFns.toDoubleMatrix(args);
    // we don't process non-square matrix.
    if (array.length != array[0].length)
    {
      throw new SSErrorXelException(SSError.VALUE);
    }
    else
   
      RealMatrix m = new RealMatrixImpl(array);
      try{
        RealMatrix invM = m.inverse();
        Double result[][] = new Double[invM.getRowDimension()][invM.getColumnDimension()];
        for(int row =0; row < invM.getRowDimension(); row++)
        {
          for(int column =0; column < invM.getColumnDimension(); column++)
          {
            // put the answer to return matrix and use toDouble15() to get around the floating-point arithm conversion problem. 
            result[row][column] = UtilFns.toDouble15(invM.getEntry(row, column), BigDecimal.ROUND_HALF_UP);
          }
        }
        return result;
      }
      // non-invertible square matrix
      catch (InvalidMatrixException e){
        throw new SSErrorXelException(SSError.NUM);
      }
    }
  }
View Full Code Here

    double array2[][] = UtilFns.toDoubleMatrix(args[1]);
   
    //if array dimension mismatch, can't do anymore, return #VALUE! error
    if (array1[0].length != array2.length)
    {
      throw new SSErrorXelException(SSError.VALUE);
    }
    else
    {
      RealMatrix m1 = new RealMatrixImpl(array1);
      RealMatrix m2 = new RealMatrixImpl(array2);

      try{
        //now do the really matrix multiplication.
        RealMatrix mmultResult = m1.multiply(m2);
        Double result[][] = new Double[mmultResult.getRowDimension()][mmultResult.getColumnDimension()];
 
        for(int row =0; row < mmultResult.getRowDimension(); row++)
        {
          for(int column =0; column < mmultResult.getColumnDimension(); column++)
          {
            // put the answer to return matrix and use toDouble15() to get around the floating-point arithm conversion problem. 
            result[row][column] = UtilFns.toDouble15(mmultResult.getEntry(row, column), BigDecimal.ROUND_HALF_UP);
          }
        }
        return result;
      }
      //shouldn't happen to run into this exception. because the dimensions had been checked above.
      catch(IllegalArgumentException e){
        throw new SSErrorXelException(SSError.VALUE);
      }
    }
  }
View Full Code Here

     */
    int n = CommonFns.toNumber(args[0]).intValue();
    int d = CommonFns.toNumber(args[1]).intValue();
   
    if(n == 0)
      throw new SSErrorXelException(SSError.DIV0);
    else{
      int r = Math.abs(n % d);
      if(d>0)
        return UtilFns.validateNumber(r);
      else
View Full Code Here

    double number = CommonFns.toNumber(args[0]).doubleValue();
    double multiple = CommonFns.toNumber(args[1]).doubleValue();
    //if number and multiple have different sign, MROUND returns #NUM! error.
    if((number > 0 && multiple < 0) || (number < 0 && multiple > 0))
    {
      throw new SSErrorXelException(SSError.NUM);
    }
    else
    {
      if(multiple == 0)//weird result for MSFT Excel compatible.
      {
View Full Code Here

    int[] number = UtilFns.toIntArray(args);
    int sum = 0;
    int product = 1;
    for(int i = 0; i < number.length; ++i) {
      if(number[i] < 0 || number[i] >= 255) {
        throw new SSErrorXelException(SSError.NUM);
      }
      sum += number[i];
      product *= factorial(number[i]);
    }
    return new Double(factorial(sum)/product);
View Full Code Here

   */
  public static Object mathQuotient(Object[] args, XelContext ctx){
    //if denominator is 0, return #DIV/0! for MSFT Excel compatibility.
    if(CommonFns.toNumber(args[1]).doubleValue() == 0)
    {
      throw new SSErrorXelException(SSError.DIV0);
    }
    else
      return new Double(Math.rint(CommonFns.toNumber(args[0]).doubleValue()/CommonFns.toNumber(args[1]).doubleValue()));
  }
View Full Code Here

   */
  public static Object mathRandbetween(Object[] args, XelContext ctx){
    double bottom = CommonFns.toNumber(args[0]).doubleValue();
    double top = CommonFns.toNumber(args[1]).doubleValue();
    if(bottom > top) {
      throw new SSErrorXelException(SSError.NUM);
    } else {
      return new Double(Math.floor(bottom + Math.random()*(top - bottom)));     
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.zss.engine.xel.SSErrorXelException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.