This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-connect-swift.git
The following commit(s) were added to refs/heads/main by this push:
new f77b7fe [SPARK-55895] Fix `pi` example to use `n` instead of `n-1`
f77b7fe is described below
commit f77b7feb13dcc9d50706a7ffc802fd11afd9d59e
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Mon Mar 9 14:50:29 2026 -0700
[SPARK-55895] Fix `pi` example to use `n` instead of `n-1`
### What changes were proposed in this pull request?
This PR fixes the `pi` example to use `Double(n)` instead of `Double(n) -
1` as the denominator in the Monte Carlo Pi estimation formula.
### Why are the changes needed?
`spark.range(n)` generates `n` samples (from 0 to n-1). The Monte Carlo
formula for Pi is `4 * (points inside circle) / (total points)`. The
denominator should be `n`, not `n - 1`, because the total number of samples is
`n`. Using `n - 1` causes a slight overestimation of Pi.
This is a similar fix for the main branch PR.
- https://github.com/apache/spark/pull/54696
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Manual review.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.6)
Closes #304 from dongjoon-hyun/SPARK-55895.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
Examples/pi/Sources/main.swift | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Examples/pi/Sources/main.swift b/Examples/pi/Sources/main.swift
index f894a54..ca791b1 100644
--- a/Examples/pi/Sources/main.swift
+++ b/Examples/pi/Sources/main.swift
@@ -30,6 +30,6 @@ let count =
.where("v <= 1")
.count()
-print("Pi is roughly \(4.0 * Double(count) / (Double(n) - 1))")
+print("Pi is roughly \(4.0 * Double(count) / Double(n))")
await spark.stop()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]