interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / temperature-conversion / temperature-conversion.om

78 lines · 1385 bytes Raw Blame History
1note Rosetta Code task "Temperature conversion": https://rosettacode.org/wiki/Temperature_conversion
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tk "K "
6text tc "C "
7text tf "F "
8text tr "R "
9text minus "-"
10text dot "."
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note emitu writes n in decimal; 20 digits hold every ulong
23fn emitu n ulong to void
24d = new uchar 20 0
25i = ulong 20
26v = n
27while true bound 20
28i = sub i 1
29put d i uchar add rem v 10 48
30v = div v 10
31if eq v 0
32break
33end
34end
35emit part d i sub 20 i
36end
37note emitc2 writes v hundredths (signed) as a decimal with two places
38fn emitc2 v long to void
39u = ulong 0
40if lt v 0
41emit minus
42u = ulong neg v
43else
44u = ulong v
45end
46emitu div u 100
47emit dot
48f = rem u 100
49if lt f 10
50emitu 0
51end
52emitu f
53end
54note k is kelvin in hundredths, a multiple of 5 so every scale below is exact in hundredths:
55note C = K - 273.15, F = K * 9/5 - 459.67, R = K * 9/5
56fn show k long to void
57emit tk
58emitc2 k
59emit nl
60emit tc
61emitc2 sub k 27315
62emit nl
63emit tf
64emitc2 sub div mul k 9 5 45967
65emit nl
66emit tr
67emitc2 div mul k 9 5
68emit nl
69emit nl
70end
71fn main to int
72show 2100
73show 0
74show 27315
75show 37315
76show 31015
77ret 0
78end