File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- unit cod
2-
3- share Math {
4-
5- ~| result
6- share sqrt(float x) {
7- if x < 0 {
8- ~ result 0
9- } elif x == 0 {
10- ~ result 0
11- } else {
12- // Simple square root approximation
13- float guess = x / 2
14- for i in 1 to 10 {
15- guess = (guess + x / guess) / 2
16- }
17- ~ result guess
18- }
19- }
20-
21- ~| result
22- share pow(float base, float exponent) {
23- float temp = 1
24- for i in 1 to exponent {
25- temp = temp * base
26- }
27- ~ result temp
28- }
29-
30- ~| result
31- share max(float a, float b) {
32- if a > b {
33- ~ result a
34- } else {
35- ~ result b
36- }
37- }
38-
39- ~| result
40- share min(float a, float b) {
41- if a < b {
42- ~ result a
43- } else {
44- ~ result b
45- }
46- }
47-
48- ~| result
49- share abs(float x) {
50- if x < 0 {
51- ~ result -x
52- } else {
53- ~ result x
54- }
55- }
56- }
1+ unit cod
2+
3+ share Math {
4+
5+ ~| result
6+ share sqrt(float x) {
7+ if x < 0 {
8+ ~> 0
9+ } elif x == 0 {
10+ ~> 0
11+ } else {
12+ // Simple square root approximation
13+ float guess = x / 2
14+ for i in 1 to 10 {
15+ guess = (guess + x / guess) / 2
16+ }
17+ ~> guess
18+ }
19+ }
20+
21+ ~| result
22+ share pow(float base, float exponent) {
23+ float temp = 1
24+ for i in 1 to exponent {
25+ temp = temp * base
26+ }
27+ ~> temp
28+ }
29+
30+ ~| result
31+ share max(float a, float b) {
32+ if a > b {
33+ ~> a
34+ } else {
35+ ~> b
36+ }
37+ }
38+
39+ ~| result
40+ share min(float a, float b) {
41+ if a < b {
42+ ~> a
43+ } else {
44+ ~> b
45+ }
46+ }
47+
48+ ~| result
49+ share abs(float x) {
50+ if x < 0 {
51+ ~> -x
52+ } else {
53+ ~> x
54+ }
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments