org.apache.poi.hssf.record.formula.functions
Class MathX

java.lang.Object
  extended by org.apache.poi.hssf.record.formula.functions.MathX

public final class MathX
extends java.lang.Object

Author:
Amol S. Deshmukh < amolweb at ya hoo dot com > This class is an extension to the standard math library provided by java.lang.Math class. It follows the Math class in that it has a private constructor and all static methods.

Method Summary
static double acosh(double d)
          inverse hyperbolic cosine
static double asinh(double d)
          inverse hyperbolic sine
static double atanh(double d)
          inverse hyperbolic tangent
static double average(double[] values)
          average of all values
static double ceiling(double n, double s)
          Note: this function is different from java.lang.Math.ceil(..).
static double cosh(double d)
          hyperbolic cosine
static double factorial(int n)
          
for all n >= 1; factorial n = n * (n-1) * (n-2) * ...
static double floor(double n, double s)
          Note: this function is different from java.lang.Math.floor(..).
static double max(double[] values)
          min of all values.
static double min(double[] values)
          min of all values.
static double mod(double n, double d)
          returns the remainder resulting from operation: n / d.
static double nChooseK(int n, int k)
          returns the total number of combinations possible when k items are chosen out of total of n items.
static double product(double[] values)
          product of all values
static double round(double n, int p)
          Returns a value rounded to p digits after decimal.
static double roundDown(double n, int p)
          Returns a value rounded to p digits after decimal.
static double roundUp(double n, int p)
          Returns a value rounded-up to p digits after decimal.
static short sign(double d)
          If d < 0, returns short -1
If d > 0, returns short 1
If d == 0, returns short 0
static double sinh(double d)
          hyperbolic sine
static double sum(double[] values)
          sum of all values
static double sumproduct(double[][] arrays)
          returns the sum of product of corresponding double value in each subarray.
static double sumsq(double[] values)
          sum of squares of all values
static double sumx2my2(double[] xarr, double[] yarr)
          returns the sum of difference of squares of corresponding double value in each subarray: ie.
static double sumx2py2(double[] xarr, double[] yarr)
          returns the sum of sum of squares of corresponding double value in each subarray: ie.
static double sumxmy2(double[] xarr, double[] yarr)
          returns the sum of squares of difference of corresponding double value in each subarray: ie.
static double tanh(double d)
          hyperbolic tangent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

round

public static double round(double n,
                           int p)
Returns a value rounded to p digits after decimal. If p is negative, then the number is rounded to places to the left of the decimal point. eg. 10.23 rounded to -1 will give: 10. If p is zero, the returned value is rounded to the nearest integral value.

If n is negative, the resulting value is obtained as the round value of absolute value of n multiplied by the sign value of n (@see MathX.sign(double d)). Thus, -0.6666666 rounded to p=0 will give -1 not 0.

If n is NaN, returned value is NaN.

Parameters:
n -
p -

roundUp

public static double roundUp(double n,
                             int p)
Returns a value rounded-up to p digits after decimal. If p is negative, then the number is rounded to places to the left of the decimal point. eg. 10.23 rounded to -1 will give: 20. If p is zero, the returned value is rounded to the nearest integral value.

If n is negative, the resulting value is obtained as the round-up value of absolute value of n multiplied by the sign value of n (@see MathX.sign(double d)). Thus, -0.2 rounded-up to p=0 will give -1 not 0.

If n is NaN, returned value is NaN.

Parameters:
n -
p -

roundDown

public static double roundDown(double n,
                               int p)
Returns a value rounded to p digits after decimal. If p is negative, then the number is rounded to places to the left of the decimal point. eg. 10.23 rounded to -1 will give: 10. If p is zero, the returned value is rounded to the nearest integral value.

If n is negative, the resulting value is obtained as the round-up value of absolute value of n multiplied by the sign value of n (@see MathX.sign(double d)). Thus, -0.8 rounded-down to p=0 will give 0 not -1.

If n is NaN, returned value is NaN.

Parameters:
n -
p -

sign

public static short sign(double d)
If d < 0, returns short -1
If d > 0, returns short 1
If d == 0, returns short 0

If d is NaN, then 1 will be returned. It is the responsibility of caller to check for d isNaN if some other value is desired.

Parameters:
d -

average

public static double average(double[] values)
average of all values

Parameters:
values -

sum

public static double sum(double[] values)
sum of all values

Parameters:
values -

sumsq

public static double sumsq(double[] values)
sum of squares of all values

Parameters:
values -

product

public static double product(double[] values)
product of all values

Parameters:
values -

min

public static double min(double[] values)
min of all values. If supplied array is zero length, Double.POSITIVE_INFINITY is returned.

Parameters:
values -

max

public static double max(double[] values)
min of all values. If supplied array is zero length, Double.NEGATIVE_INFINITY is returned.

Parameters:
values -

floor

public static double floor(double n,
                           double s)
Note: this function is different from java.lang.Math.floor(..).

When n and s are "valid" arguments, the returned value is: Math.floor(n/s) * s;
n and s are invalid if any of following conditions are true:

In all such cases, Double.NaN is returned.

Parameters:
n -
s -

ceiling

public static double ceiling(double n,
                             double s)
Note: this function is different from java.lang.Math.ceil(..).

When n and s are "valid" arguments, the returned value is: Math.ceiling(n/s) * s;
n and s are invalid if any of following conditions are true:

In all such cases, Double.NaN is returned.

Parameters:
n -
s -

factorial

public static double factorial(int n)

for all n >= 1; factorial n = n * (n-1) * (n-2) * ... * 1
else if n == 0; factorial n = 1
else if n < 0; factorial n = Double.NaN
Loss of precision can occur if n is large enough. If n is large so that the resulting value would be greater than Double.MAX_VALUE; Double.POSITIVE_INFINITY is returned. If n < 0, Double.NaN is returned.

Parameters:
n -

mod

public static double mod(double n,
                         double d)
returns the remainder resulting from operation: n / d.
The result has the sign of the divisor.
Examples: If d == 0, result is NaN

Parameters:
n -
d -

acosh

public static double acosh(double d)
inverse hyperbolic cosine

Parameters:
d -

asinh

public static double asinh(double d)
inverse hyperbolic sine

Parameters:
d -

atanh

public static double atanh(double d)
inverse hyperbolic tangent

Parameters:
d -

cosh

public static double cosh(double d)
hyperbolic cosine

Parameters:
d -

sinh

public static double sinh(double d)
hyperbolic sine

Parameters:
d -

tanh

public static double tanh(double d)
hyperbolic tangent

Parameters:
d -

sumproduct

public static double sumproduct(double[][] arrays)
returns the sum of product of corresponding double value in each subarray. It is the responsibility of the caller to ensure that all the subarrays are of equal length. If the subarrays are not of equal length, the return value can be unpredictable.

Parameters:
arrays -

sumx2my2

public static double sumx2my2(double[] xarr,
                              double[] yarr)
returns the sum of difference of squares of corresponding double value in each subarray: ie. sigma (xarr[i]^2-yarr[i]^2)
It is the responsibility of the caller to ensure that the two subarrays are of equal length. If the subarrays are not of equal length, the return value can be unpredictable.

Parameters:
xarr -
yarr -

sumx2py2

public static double sumx2py2(double[] xarr,
                              double[] yarr)
returns the sum of sum of squares of corresponding double value in each subarray: ie. sigma (xarr[i]^2 + yarr[i]^2)
It is the responsibility of the caller to ensure that the two subarrays are of equal length. If the subarrays are not of equal length, the return value can be unpredictable.

Parameters:
xarr -
yarr -

sumxmy2

public static double sumxmy2(double[] xarr,
                             double[] yarr)
returns the sum of squares of difference of corresponding double value in each subarray: ie. sigma ( (xarr[i]-yarr[i])^2 )
It is the responsibility of the caller to ensure that the two subarrays are of equal length. If the subarrays are not of equal length, the return value can be unpredictable.

Parameters:
xarr -
yarr -

nChooseK

public static double nChooseK(int n,
                              int k)
returns the total number of combinations possible when k items are chosen out of total of n items. If the number is too large, loss of precision may occur (since returned value is double). If the returned value is larger than Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned. If either of the parameters is negative, Double.NaN is returned.

Parameters:
n -
k -


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.