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