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 / tests / compiler / progs / fib.osc

36 lines · 740 bytes Raw Blame History
1// entry: fib_i64 fib_u8 sum_squares
2// Fibonacci (i64 checked: OVERFLOW past fib 92), u8 wrapping, sum of squares.
3fn fib_i64(n: u8) -> i64 {
4 let mut a: i64 = 0;
5 let mut b: i64 = 1;
6 let mut k: u8 = 0;
7 while k < n bound 255 {
8 let t: i64 = a + b;
9 a = b;
10 b = t;
11 k = k + 1;
12 }
13 return a;
14}
15
16fn fib_u8(n: u8) -> u8 {
17 let mut a: u8 = 0;
18 let mut b: u8 = 1;
19 for k in 0 .. 255 {
20 if (k as u8) >= n { return a; }
21 let t: u8 = a + b;
22 a = b;
23 b = t;
24 }
25 return a;
26}
27
28fn sum_squares(n: u16) -> u32 {
29 let mut s: u32 = 0;
30 let mut i: u32 = 1;
31 while i <= (n as u32) bound 3000 {
32 s = s + i * i;
33 i = i + 1;
34 }
35 return s;
36}