Repository: hadoop Updated Branches: refs/heads/branch-1 a8eee1fd0 -> 0860d1a26
MAPREDUCE-6196. Fix BigDecimal ArithmeticException in PiEstimator (rchiang via rkanter) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0860d1a2 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0860d1a2 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0860d1a2 Branch: refs/heads/branch-1 Commit: 0860d1a26bc1ea4a4d89d2c8bc7e6797553f656a Parents: a8eee1f Author: Robert Kanter <[email protected]> Authored: Mon Dec 15 17:54:31 2014 -0800 Committer: Robert Kanter <[email protected]> Committed: Mon Dec 15 17:54:31 2014 -0800 ---------------------------------------------------------------------- CHANGES.txt | 3 +++ .../org/apache/hadoop/examples/PiEstimator.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/0860d1a2/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 59bef6c..10644bf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -259,6 +259,9 @@ Release 1.3.0 - unreleased HDFS-7503. Namenode restart after large deletions can cause slow processReport (Arpit Agarwal) + MAPREDUCE-6196. Fix BigDecimal ArithmeticException in PiEstimator + (rchiang via rkanter) + Release 1.2.2 - unreleased INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/0860d1a2/src/examples/org/apache/hadoop/examples/PiEstimator.java ---------------------------------------------------------------------- diff --git a/src/examples/org/apache/hadoop/examples/PiEstimator.java b/src/examples/org/apache/hadoop/examples/PiEstimator.java index 7c3dd3e..c0a8c78 100644 --- a/src/examples/org/apache/hadoop/examples/PiEstimator.java +++ b/src/examples/org/apache/hadoop/examples/PiEstimator.java @@ -20,6 +20,7 @@ package org.apache.hadoop.examples; import java.io.IOException; import java.math.BigDecimal; +import java.math.MathContext; import java.util.Iterator; import org.apache.hadoop.conf.Configured; @@ -67,6 +68,9 @@ public class PiEstimator extends Configured implements Tool { /** tmp directory for input/output */ static private final Path TMP_DIR = new Path( PiEstimator.class.getSimpleName() + "_TMP_3_141592654"); + + /* Default value for maximum precision during estimation */ + public static int DEFAULT_PRECISION = 20; /** 2-dimensional Halton sequence {H(i)}, * where H(i) is a 2-dimensional point and i >= 1 is the index. @@ -310,10 +314,12 @@ public class PiEstimator extends Configured implements Tool { } //compute estimated value - return BigDecimal.valueOf(4).setScale(20) - .multiply(BigDecimal.valueOf(numInside.get())) - .divide(BigDecimal.valueOf(numMaps)) - .divide(BigDecimal.valueOf(numPoints)); + int precision = PiEstimator.DEFAULT_PRECISION; + MathContext mc = new MathContext(precision); + return BigDecimal.valueOf(4).setScale(precision) + .multiply(BigDecimal.valueOf(numInside.get()),mc) + .divide(BigDecimal.valueOf(numMaps),mc) + .divide(BigDecimal.valueOf(numPoints),mc); } finally { fs.delete(TMP_DIR, true); }
