本文整理汇总了Java中org.openyu.commons.lang.NumberHelper.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java NumberHelper.subtract方法的具体用法?Java NumberHelper.subtract怎么用?Java NumberHelper.subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openyu.commons.lang.NumberHelper
的用法示例。
在下文中一共展示了NumberHelper.subtract方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcTotalProbSums
import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
* 計算3個相同及2個相同及安慰獎機率
*
* 但3個空及2個空,屬安慰獎
*
* [0]=三個相同圖案機率總和
*
* [1]=兩個相同圖案機率總和
*
* [2]=安慰獎的機率總和
*
*
* @return
*/
protected boolean calcTotalProbSums() {
boolean result = false;
//
probSums = new double[3];
double same3Sum = 0d;
double same2Sum = 0d;
for (SasangType sasangType : SasangType.values()) {
// 3個空及2個空,不列入3個相同及2個相同機率中
if (!sasangType.equals(SasangType.NOTHING)) {
same3Sum = NumberHelper.add(same3Sum, getSameThreeProb(sasangType));
same2Sum = NumberHelper.add(same2Sum, getSameTwoProb(sasangType));
}
}
probSums[0] = same3Sum;
probSums[1] = same2Sum;
// 其他獎的機率= 1 – (三個相同圖案機率+ 兩個相同圖案機率)
probSums[2] = NumberHelper.subtract(NumberHelper.subtract(1, probSums[0]), probSums[1]);
probSums[2] = probSums[2] < 0 ? 0 : probSums[2];
result = true;
return result;
}
示例2: calcDiffValue
import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
* 計算差異值 newValue - oldValue ,以下類別方能處理,其他則無法做差異值
*
* Number
*
* IntEnum
*
* @param oldValue
* @param newValue
* @return
*/
protected Double calcDiffValue(OLD_VALUE oldValue, NEW_VALUE newValue) {
Double result = null;
if (oldValue instanceof Number || newValue instanceof Number) {
result = NumberHelper.subtract(newValue, oldValue);
}
// byte
else if (oldValue instanceof ByteEnum || newValue instanceof ByteEnum) {
result = (double) ((ByteEnum) newValue).getValue()
- ((ByteEnum) oldValue).getValue();
}
// short
else if (oldValue instanceof ShortEnum || newValue instanceof ShortEnum) {
result = (double) ((ShortEnum) newValue).getValue()
- ((ShortEnum) oldValue).getValue();
}
// int
else if (oldValue instanceof IntEnum || newValue instanceof IntEnum) {
IntEnum oldEnum = (IntEnum) oldValue;
IntEnum newEnum = (IntEnum) newValue;
result = (double) safeGet(newEnum) - safeGet(oldEnum);
}
// long
else if (oldValue instanceof LongEnum || newValue instanceof LongEnum) {
result = (double) ((LongEnum) newValue).getValue()
- ((LongEnum) oldValue).getValue();
}
// float
else if (oldValue instanceof FloatEnum || newValue instanceof FloatEnum) {
result = (double) ((FloatEnum) newValue).getValue()
- ((FloatEnum) oldValue).getValue();
}
// double
else if (oldValue instanceof DoubleEnum
|| newValue instanceof DoubleEnum) {
result = (double) ((DoubleEnum) newValue).getValue()
- ((DoubleEnum) oldValue).getValue();
}
return result;
}
示例3: calcSameTwoProbs
import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
* 計算2個相同的機率
*
* 3*6=18
*
* *6=108
*
* @return
*/
protected boolean calcSameTwoProbs() {
boolean result = false;
//
sameTwoProbs.clear();
for (SasangType sasangType : SasangType.values()) {
double prob = 0d;
//
int[] weight = new int[ROUND];
int[] weightSum = new int[ROUND];
//
double weightSumFactor = 1.0d;
for (int i = 0; i < ROUND; i++) {
weight[i] = getSasangTypeWeight(sasangType, i);
weightSum[i] = getRoundWeightSum(i);
//
weightSumFactor = NumberHelper.multiply(weightSumFactor, weightSum[i]);
}
prob = (weight[0] * weight[1] * (NumberHelper.subtract(weightSum[2], weight[2])));
prob += (weight[0] * (NumberHelper.subtract(weightSum[1], weight[1])) * (weight[2]));
prob += ((NumberHelper.subtract(weightSum[0], weight[0])) * weight[1] * weight[2]);
prob = NumberHelper.divide(prob, weightSumFactor);
//
sameTwoProbs.put(sasangType, prob);
}
result = true;
return result;
}