omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / si / rosetta / exercises / square-root / .meta / example.om
| 1 | note Exercism-style exercise "square-root": https://exercism.org/tracks/python/exercises/square-root |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note squareroot is the integer square root of n: the largest r with r * r <= n. |
| 4 | note Check it with: sh exercise.sh exercises/square-root |
| 5 | om2 |
| 6 | fn squareroot n ulong to ulong |
| 7 | lo = ulong 0 |
| 8 | hi = add div n 2 1 |
| 9 | while lt lo hi bound 64 |
| 10 | m = div add add lo hi 1 2 |
| 11 | if le m div n m |
| 12 | lo = m |
| 13 | else |
| 14 | hi = sub m 1 |
| 15 | end |
| 16 | end |
| 17 | ret lo |
| 18 | end |