https://github.com/akkartik/mu/blob/main/408float.mu
 1 # Some quick-n-dirty ways to create floats.
 2 
 3 fn fill-in-rational _out: (addr float), nr: int, dr: int {
 4   var out/edi: (addr float) <- copy _out
 5   var result/xmm0: float <- convert nr
 6   var divisor/xmm1: float <- convert dr
 7   result <- divide divisor
 8   copy-to *out, result
 9 }
10 
11 fn fill-in-sqrt _out: (addr float), n: int {
12   var out/edi: (addr float) <- copy _out
13   var result/xmm0: float <- convert n
14   result <- square-root result
15   copy-to *out, result
16 }
17 
18 fn rational nr: int, dr: int -> _/xmm0: float {
19   var result/xmm0: float <- convert nr
20   var divisor/xmm1: float <- convert dr
21   result <- divide divisor
22   return result
23 }
24 
25 # n/m rounded up
26 fn scale-down-and-round-up n: int, m: int -> _/ecx: int {
27   var result/ecx: int <- copy n
28   result <- add m
29   result <- decrement
30   var result-f/xmm0: float <- convert result
31   var m-f/xmm1: float <- convert m
32   result-f <- divide m-f
33   result <- truncate result-f
34   return result
35 }