interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / temperature-conversion.wiki

108 lines · 1698 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text tk "K "
8text tc "C "
9text tf "F "
10text tr "R "
11text minus "-"
12text dot "."
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note emitu writes n in decimal; 20 digits hold every ulong
25fn emitu n ulong to void
26d = new uchar 20 0
27i = ulong 20
28v = n
29while true bound 20
30i = sub i 1
31put d i uchar add rem v 10 48
32v = div v 10
33if eq v 0
34break
35end
36end
37emit part d i sub 20 i
38end
39note emitc2 writes v hundredths (signed) as a decimal with two places
40fn emitc2 v long to void
41u = ulong 0
42if lt v 0
43emit minus
44u = ulong neg v
45else
46u = ulong v
47end
48emitu div u 100
49emit dot
50f = rem u 100
51if lt f 10
52emitu 0
53end
54emitu f
55end
56note k is kelvin in hundredths, a multiple of 5 so every scale below is exact in hundredths:
57note C = K - 273.15, F = K * 9/5 - 459.67, R = K * 9/5
58fn show k long to void
59emit tk
60emitc2 k
61emit nl
62emit tc
63emitc2 sub k 27315
64emit nl
65emit tf
66emitc2 sub div mul k 9 5 45967
67emit nl
68emit tr
69emitc2 div mul k 9 5
70emit nl
71emit nl
72end
73fn main to int
74show 2100
75show 0
76show 27315
77show 37315
78show 31015
79ret 0
80end
81</syntaxhighlight>
82{{out}}
83<pre>
84K 21.00
85C -252.15
86F -421.87
87R 37.80
88
89K 0.00
90C -273.15
91F -459.67
92R 0.00
93
94K 273.15
95C 0.00
96F 32.00
97R 491.67
98
99K 373.15
100C 100.00
101F 212.00
102R 671.67
103
104K 310.15
105C 37.00
106F 98.60
107R 558.27
108</pre>