self-review 2026-06-07: fix uptime display in awareness loop
elapsed_human() used % and * operators which are broken in this EL compiler version. Replace with repeated-doubling arithmetic: 60 = 64 - 4 = 2^6 - 2^2, computed via three doubling steps. Fixes uptime displaying "44h 2694m" instead of "44h 14m".
This commit is contained in:
+23
-8
@@ -44,21 +44,36 @@ fn elapsed_ms() -> Int {
|
||||
return time_now() - boot
|
||||
}
|
||||
|
||||
// elapsed_human — uptime as a human-readable string: "2h 14m", "45m 3s", "12s".
|
||||
// elapsed_human — uptime as a human-readable string: "2h 14m", "45m", "12s".
|
||||
//
|
||||
// CODEGEN NOTE: EL's % and * operators are both broken in this compiler version
|
||||
// (% drops the modulo, * is similarly unreliable). We avoid them entirely:
|
||||
// - For h*60: use repeated doubling. 60 = 64 - 4 = 2^6 - 2^2.
|
||||
// Build h*64 via three doublings of h*4, then subtract h*4.
|
||||
// - For m-within-hour: total_minutes - h*60 (subtraction only).
|
||||
// - For s-within-minute not shown when m > 0: avoids the s%60 problem entirely.
|
||||
// (2026-06-07 self-review: fixed from broken "44h 2694m" output)
|
||||
fn elapsed_human() -> String {
|
||||
let ms: Int = elapsed_ms()
|
||||
let total_secs: Int = ms / 1000
|
||||
let h: Int = total_secs / 3600
|
||||
let rem: Int = total_secs % 3600
|
||||
let m: Int = rem / 60
|
||||
let s: Int = rem % 60
|
||||
let total_minutes: Int = total_secs / 60
|
||||
let h: Int = total_minutes / 60
|
||||
if h > 0 {
|
||||
// h*60 via repeated doubling (avoids broken * operator). 60 = 64-4.
|
||||
let h4: Int = h + h + h + h
|
||||
let h8: Int = h4 + h4
|
||||
let h16: Int = h8 + h8
|
||||
let h32: Int = h16 + h16
|
||||
let h64: Int = h32 + h32
|
||||
let h60: Int = h64 - h4
|
||||
let m: Int = total_minutes - h60
|
||||
return int_to_str(h) + "h " + int_to_str(m) + "m"
|
||||
}
|
||||
if m > 0 {
|
||||
return int_to_str(m) + "m " + int_to_str(s) + "s"
|
||||
// For < 1h: total_minutes < 60, no modulo needed.
|
||||
if total_minutes > 0 {
|
||||
return int_to_str(total_minutes) + "m"
|
||||
}
|
||||
return int_to_str(s) + "s"
|
||||
return int_to_str(total_secs) + "s"
|
||||
}
|
||||
|
||||
// embed_ok — returns 1 if Ollama embedding service is reachable, 0 if not.
|
||||
|
||||
Reference in New Issue
Block a user