Commit c40753ed authored by yanzg's avatar yanzg

修改日志打印功能,打印更加详细的日志

parent 6cb8a9a3
...@@ -208,6 +208,9 @@ public class CalcHelper { ...@@ -208,6 +208,9 @@ public class CalcHelper {
if (scale < 0) { if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero"); throw new IllegalArgumentException("The scale must be a positive integer or zero");
} }
if (d1 == 0) {
return 0;
}
BigDecimal b1 = new BigDecimal(Double.toString(d1)); BigDecimal b1 = new BigDecimal(Double.toString(d1));
BigDecimal b2 = new BigDecimal(Double.toString(d2)); BigDecimal b2 = new BigDecimal(Double.toString(d2));
return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue(); return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
...@@ -233,6 +236,9 @@ public class CalcHelper { ...@@ -233,6 +236,9 @@ public class CalcHelper {
* @return 结果 * @return 结果
*/ */
public static double divList(double d1, double... d2) { public static double divList(double d1, double... d2) {
if (d1 == 0) {
return 0;
}
double ret = d1; double ret = d1;
for (double item : d2) { for (double item : d2) {
ret = div(ret, item); ret = div(ret, item);
......
...@@ -36,6 +36,10 @@ public class TestCalc { ...@@ -36,6 +36,10 @@ public class TestCalc {
CalcHelper.mulList(d1, d2, 0.5); CalcHelper.mulList(d1, d2, 0.5);
CalcHelper.divList(d1, d2, 0.5); CalcHelper.divList(d1, d2, 0.5);
CalcHelper.divList(0, 0, 0.5);
CalcHelper.div(0, 0);
CalcHelper.divDouble(0D, 0D);
CalcHelper.addListDouble((Double)null, d2, 0.3); CalcHelper.addListDouble((Double)null, d2, 0.3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment