Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/number-names/number-names.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / number-names / number-names.om` 127 lines ยท 2214 bytes Raw Blame History 1 note Rosetta Code task "Number names": https://rosettacode.org/wiki/Number_names 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text hy "-" 7 text colon ": " 8 text ones "zero\none\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\ntwelve\nthirteen\nfourteen\nfifteen\nsixteen\nseventeen\neighteen\nnineteen\n" 9 text tens "twenty\nthirty\nforty\nfifty\nsixty\nseventy\neighty\nninety\n" 10 text scales "thousand\nmillion\nbillion\ntrillion\nquadrillion\nquintillion\n" 11 text hund " hundred" 12 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 13 fn emit a view uchar * to void 14 o = ulong 0 15 while lt o len a bound 4096 16 k = write 1 a o sub len a o 17 if le k 0 18 exit 1 19 end 20 o = add o ulong k 21 end 22 end 23 note emitu writes n in decimal; 20 digits hold every ulong 24 fn emitu n ulong to void 25 d = new uchar 20 0 26 i = ulong 20 27 v = n 28 while true bound 20 29 i = sub i 1 30 put d i uchar add rem v 10 48 31 v = div v 10 32 if eq v 0 33 break 34 end 35 end 36 emit part d i sub 20 i 37 end 38 note word writes element k of a newline-terminated list 39 fn word t view uchar * k ulong to void 40 s = ulong 0 41 m = ulong 0 42 for i ulong len t 43 if eq get t i 10 44 if eq m k 45 emit part t s sub i s 46 ret 47 end 48 m = add m 1 49 s = add i 1 50 end 51 end 52 trap 9 53 end 54 note three writes 1..999 in words: hundreds, then the rest (under 20 by name, else tens-ones) 55 fn three g ulong to void 56 h = div g 100 57 r = rem g 100 58 if gt h 0 59 word ones h 60 emit hund 61 if gt r 0 62 emit sp 63 end 64 end 65 if and gt r 0 lt r 20 66 word ones r 67 end 68 if ge r 20 69 word tens sub div r 10 2 70 if gt rem r 10 0 71 emit hy 72 word ones rem r 10 73 end 74 end 75 end 76 note spell splits n into groups of three digits and writes each non-zero one with its scale 77 fn spell n ulong to void 78 if eq n 0 79 word ones 0 80 ret 81 end 82 g = new ulong 7 0 83 v = n 84 for i ulong 7 85 put g i rem v 1000 86 v = div v 1000 87 end 88 first = true 89 for k ulong 7 90 i = sub 6 k 91 x = get g i 92 if gt x 0 93 if not first 94 emit sp 95 end 96 three x 97 if gt i 0 98 emit sp 99 word scales sub i 1 100 end 101 first = false 102 end 103 end 104 end 105 fn show n ulong to void 106 emitu n 107 emit colon 108 spell n 109 emit nl 110 end 111 fn main to int 112 show 0 113 show 7 114 show 13 115 show 21 116 show 99 117 show 100 118 show 101 119 show 999 120 show 1000 121 show 1001 122 show 12345 123 show `1000000` 124 show `1234567890` 125 show `18446744073709551615` 126 ret 0 127 end