Fix count to actually _be_ a count

Also, start from 1 in the positive direction, instead of 5, since that
is more how the thing works (sorry, mathematician brain).

Additionally, adds some extra information in the comments:
information about how long the code would take if one actually sets
count to 2,5 * 10^12, and adding a plus in front of the 4/1 to show that
that is in fact the first element of the "plus" side.

Finally, add an (floating point) error to the debug print.
This commit is contained in:
Nicole Patricia Mazzuca
2026-06-01 22:25:08 +02:00
parent 83a89702b2
commit a03b676bed
3 changed files with 19 additions and 18 deletions
+4 -5
View File
@@ -1,13 +1,12 @@
--- exercises/108_threading2.zig 2026-04-14 06:44:18.848246237 +0200
+++ answers/108_threading2.zig 2026-04-14 08:15:30.894485037 +0200
@@ -81,8 +81,8 @@
--- exercises/108_threading2.zig 2026-06-29 23:25:53
+++ answers/108_threading2.zig 2026-06-29 23:25:25
@@ -82,7 +82,8 @@
defer handle1.join();
// Second thread to calculate the minus numbers.
- ???
-
+ const handle2 = try std.Thread.spawn(.{}, thread_pi, .{ &pi_minus, 3, count });
+ defer handle2.join();
}
// Here we add up the results.
std.debug.print("PI ≈ {d:.8}\n", .{4 + pi_plus - pi_minus});