interplane.Get Omega
Read in your language

omega-harness

Agent skills for operating, encoding and communicating in Omega (.om) and the AIEN repositories

Brought by drakestapleton

branch main Branches Tags History

omega-harness / examples / float_arith.om

63 lines · 1276 bytes Raw Blame History
1note float_arith: IEEE binary64, round to nearest even, no float operation traps
2note ---- output helpers: a function works on a global by naming it (a global is never an argument)
3global ob uchar 32
4note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90
5note bound: every pass writes at least one byte and n <= 32, so at most 32 passes
6fn outb off ulong n ulong to void
7e = add off n
8p = off
9while lt p e bound 32
10k = write 1 ob p sub e p
11if le k 0
12exit 90
13end
14p = add p ulong k
15end
16end
17note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes
18fn putu v ulong to void
19i = ulong 31
20put ob 31 10
21n = v
22while true bound 20
23i = sub i 1
24put ob i uchar add rem n 10 48
25n = div n 10
26if eq n 0
27break
28end
29end
30outb i sub 32 i
31end
32note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1
33fn putl v long to void
34if lt v 0
35put ob 0 45
36outb 0 1
37putu add ulong neg add v 1 1
38ret
39end
40putu ulong v
41end
42fn main to int
43r = fsqrt 2.0f64
44putl long mul r 1000000000.0
45s = add 0.1f64 0.2
46putu bitcast ulong s
47putu bitcast ulong 1.0f64
48z = f64 0.0
49n = div z z
50if ne n n
51putu 1
52end
53if eq n n
54putu 2
55end
56i = div 1.0 z
57if gt i 1.0e308
58putu 3
59end
60putl long fmin -2.5f64 3.0f64
61putl long fabs -7.9f64
62ret 0
63end