diff options
| author | eunhhu <[email protected]> | 2026-10-05 13:24:59 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-05 13:24:59 +0100 |
| commit | 6b4580607efa698abdc07718f00c6cbdb425c210 (patch) | |
| tree | 0cad9cddfd332140ecce47d17e439573f32ea11e /research/experiments/040-against-c/roots.aup | |
| parent | 5a3466e8ff4d8f3c4271719b90858b7d08697dcd (diff) | |
| download | pure-6b4580607efa698abdc07718f00c6cbdb425c210.tar.gz pure-6b4580607efa698abdc07718f00c6cbdb425c210.zip | |
Research 124's suite: seven kinds of work in one event each (roots, knapsack, sort, join, words, matmul, BFS), each against the C one would write, in one process with the same inputs and answers; PURE_AHEAD=0 to measure the code without reading ahead
Diffstat (limited to 'research/experiments/040-against-c/roots.aup')
| -rw-r--r-- | research/experiments/040-against-c/roots.aup | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/research/experiments/040-against-c/roots.aup b/research/experiments/040-against-c/roots.aup new file mode 100644 index 0000000..22c9189 --- /dev/null +++ b/research/experiments/040-against-c/roots.aup @@ -0,0 +1,23 @@ +# Numbers in a loop (research 124's suite): the square roots of 1 .. n by +# Newton's steps, each until a step stops shrinking, and their sum. +state total = 0 +state steps = 0 +input go = message { + n: u32 +} +on go { + let sum = 0 + let count = 0 + for i in 1 .. go.n + 1 { + let r = i + for s in 0 .. 64 { + let next = (r + i / r) / 2 + if next >= r { break } + r = next + count = count + 1 + } + sum = sum + r + } + total = sum + steps = count +} |
