Skip to content

Commit 62d7cd7

Browse files
committed
Add a commit to explain the modify
Add a commit to tell the user why we had a judgement here. And use `until` instead of `to` for the purpose of avoid the limit size of the input seq and make the code more readable.
1 parent 4cdc388 commit 62d7cd7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

examples/src/main/scala/org/apache/spark/examples/SparkPi.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ object SparkPi {
2727
val conf = new SparkConf().setAppName("Spark Pi")
2828
val spark = new SparkContext(conf)
2929
val slices = if (args.length > 0) args(0).toInt else 2
30-
val n = math.min(100000L * slices, Int.MaxValue -1).toInt
31-
val count = spark.parallelize(1 to n, slices).map { i =>
30+
val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow
31+
val count = spark.parallelize(1 until n, slices).map { i =>
3232
val x = random * 2 - 1
3333
val y = random * 2 - 1
3434
if (x*x + y*y < 1) 1 else 0

0 commit comments

Comments
 (0)