interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / omc / tests / float / convert_sat.om

123 lines · 1930 bytes Raw Blame History
1note float to integer: truncate toward zero, then saturate to the destination type's own range; NaN is 0.
2note Every conversion runs through a function parameter, so it is the run-time path, not constant folding.
3note The expected values are the destination ranges themselves (uchar 0..255, ushort 0..65535, uint 0..2^32-1,
4note ulong 0..2^64-1, byte -128..127, short -32768..32767, int -2^31..2^31-1, long -2^63..2^63-1).
5fn du8 x f64 to uchar
6ret uchar x
7end
8fn du16 x f64 to ushort
9ret ushort x
10end
11fn du32 x f64 to uint
12ret uint x
13end
14fn du64 x f64 to ulong
15ret ulong x
16end
17fn di8 x f64 to byte
18ret byte x
19end
20fn di16 x f64 to short
21ret short x
22end
23fn di32 x f64 to int
24ret int x
25end
26fn di64 x f64 to long
27ret long x
28end
29fn su8 x f32 to uchar
30ret uchar x
31end
32fn su32 x f32 to uint
33ret uint x
34end
35fn si8 x f32 to byte
36ret byte x
37end
38fn si16 x f32 to short
39ret short x
40end
41fn nan to f64
42z = f64 0.0
43ret div z z
44end
45fn main to int
46if ne ulong du8 300.0 255
47ret 1
48end
49if ne ulong du8 -5.0 0
50ret 2
51end
52if ne ulong du8 200.7 200
53ret 3
54end
55if ne ulong du16 70000.0 65535
56ret 4
57end
58if ne ulong du32 -1.0 0
59ret 5
60end
61if ne ulong du32 5000000000.0 4294967295
62ret 6
63end
64if ne du64 -1.0 0
65ret 7
66end
67if ne du64 1.0e20 18446744073709551615
68ret 8
69end
70if ne du64 1.0e19 10000000000000000000
71ret 9
72end
73if ne long di8 200.0 127
74ret 10
75end
76if ne long di8 -200.0 -128
77ret 11
78end
79if ne long di8 -3.7 -3
80ret 12
81end
82if ne long di16 40000.0 32767
83ret 13
84end
85if ne long di16 -40000.0 -32768
86ret 14
87end
88if ne long di32 3000000000.0 2147483647
89ret 15
90end
91if ne long di32 -3000000000.0 -2147483648
92ret 16
93end
94if ne di64 1.0e19 9223372036854775807
95ret 17
96end
97if ne ulong su8 f32 300.0 255
98ret 18
99end
100if ne ulong su32 f32 -2.0 0
101ret 19
102end
103if ne long si8 f32 -300.0 -128
104ret 20
105end
106if ne long si16 f32 1.5 1
107ret 21
108end
109n = nan
110if ne ulong du8 n 0
111ret 22
112end
113if ne long di8 n 0
114ret 23
115end
116if ne ulong du32 n 0
117ret 24
118end
119if ne di64 n 0
120ret 25
121end
122ret 0
123end