Top Description Constructors Methods
org.apache.poi.ss.formula.functions

pack-priv final Class MathX

extends Object
Class Inheritance
Imports
org.apache.poi.ss.util.NumberToTextConverter, org.apache.poi.util.Internal, java.math.BigDecimal, .MathContext, .RoundingMode

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.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static double
acosh(double d)

inverse hyperbolic cosine

public static double
asinh(double d)

inverse hyperbolic sine

public static double
atanh(double d)

inverse hyperbolic tangent

public static double
average(double[] values)

average of all values

public static double
ceiling(double n, double s)

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:

  • s is zero
  • n is negative and s is positive
  • n is positive and s is negative
public static double
cosh(double d)

hyperbolic cosine

public static double
factorial(int n)

for all n >= 1; factorial n = n * (n-1) * (n-2) * ...

public static double
factorial(double d)

public static double
floor(double n, double s)

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:

  • s is zero
  • n is negative and s is positive
  • n is positive and s is negative
public static double
max(double[] values)

min of all values.

public static double
min(double[] values)

min of all values.

public static double
mod(double n, double d)

returns the remainder resulting from operation: n / d.

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.

public static double
product(double[] values)

product of all values

public static double
round(double n, int p)

Returns a value rounded to p digits after decimal.

public static double
round(double n, double p)

private static double
round(double n, int p, RoundingMode rounding)

public static double
roundDown(double n, int p)

Returns a value rounded to p digits after decimal.

public static double
roundDown(double n, double p)

public static double
roundUp(double n, int p)

Returns a value rounded-up to p digits after decimal.

public static double
roundUp(double n, double p)

public static double
scaledRoundUsingBigDecimal(double xval, double multiplier, RoundingMode mode)

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.

public static double
sinh(double d)

hyperbolic sine

public static double
sum(double[] values)

sum of all values

public static double
sumsq(double[] values)

sum of squares of all values

public static double
tanh(double d)

hyperbolic tangent

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MathXback to summary
private MathX()

Method Detail

acoshback to summary
public static double acosh(double d)

inverse hyperbolic cosine

asinhback to summary
public static double asinh(double d)

inverse hyperbolic sine

atanhback to summary
public static double atanh(double d)

inverse hyperbolic tangent

averageback to summary
public static double average(double[] values)

average of all values

ceilingback to summary
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:

  • s is zero
  • n is negative and s is positive
  • n is positive and s is negative
In all such cases, Double.NaN is returned.
coshback to summary
public static double cosh(double d)

hyperbolic cosine

factorialback to summary
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.

factorialback to summary
public static double factorial(double d)
floorback to summary
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:

  • s is zero
  • n is negative and s is positive
  • n is positive and s is negative
In all such cases, Double.NaN is returned.
maxback to summary
public static double max(double[] values)

min of all values. If supplied array is zero length, Double.NEGATIVE_INFINITY is returned.

minback to summary
public static double min(double[] values)

min of all values. If supplied array is zero length, Double.POSITIVE_INFINITY is returned.

modback to summary
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:

  • mod(3.4, 2) = 1.4
  • mod(-3.4, 2) = 0.6
  • mod(-3.4, -2) = -1.4
  • mod(3.4, -2) = -0.6
If d == 0, result is NaN
nChooseKback to summary
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.

productback to summary
public static double product(double[] values)

product of all values

roundback to summary
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.

roundback to summary
public static double round(double n, double p)
roundback to summary
private static double round(double n, int p, RoundingMode rounding)
roundDownback to summary
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.

roundDownback to summary
public static double roundDown(double n, double p)
roundUpback to summary
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.

roundUpback to summary
public static double roundUp(double n, double p)
scaledRoundUsingBigDecimalback to summary
public static double scaledRoundUsingBigDecimal(double xval, double multiplier, RoundingMode mode)
Annotations
@Internal
signback to summary
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.

sinhback to summary
public static double sinh(double d)

hyperbolic sine

sumback to summary
public static double sum(double[] values)

sum of all values

sumsqback to summary
public static double sumsq(double[] values)

sum of squares of all values

tanhback to summary
public static double tanh(double d)

hyperbolic tangent