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:
Vendored
+16
-11
@@ -194,21 +194,22 @@ el_val_t elapsed_ms(void) {
|
||||
el_val_t elapsed_human(void) {
|
||||
el_val_t ms = elapsed_ms();
|
||||
el_val_t total_secs = (ms / 1000);
|
||||
el_val_t h = (total_secs / 3600);
|
||||
el_val_t rem = total_secs;
|
||||
EL_NULL;
|
||||
3600;
|
||||
el_val_t m = (rem / 60);
|
||||
el_val_t s = rem;
|
||||
EL_NULL;
|
||||
60;
|
||||
el_val_t total_minutes = (total_secs / 60);
|
||||
el_val_t h = (total_minutes / 60);
|
||||
if (h > 0) {
|
||||
el_val_t h4 = (((h + h) + h) + h);
|
||||
el_val_t h8 = (h4 + h4);
|
||||
el_val_t h16 = (h8 + h8);
|
||||
el_val_t h32 = (h16 + h16);
|
||||
el_val_t h64 = (h32 + h32);
|
||||
el_val_t h60 = (h64 - h4);
|
||||
el_val_t m = (total_minutes - h60);
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(h), EL_STR("h ")), int_to_str(m)), EL_STR("m"));
|
||||
}
|
||||
if (m > 0) {
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(m), EL_STR("m ")), int_to_str(s)), EL_STR("s"));
|
||||
if (total_minutes > 0) {
|
||||
return el_str_concat(int_to_str(total_minutes), EL_STR("m"));
|
||||
}
|
||||
return el_str_concat(int_to_str(s), EL_STR("s"));
|
||||
return el_str_concat(int_to_str(total_secs), EL_STR("s"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -482,6 +483,10 @@ el_val_t awareness_run(void) {
|
||||
if (should_beat) {
|
||||
emit_heartbeat();
|
||||
state_set(EL_STR("soul.last_beat_ts"), int_to_str(now_ts));
|
||||
el_val_t snap_path = state_get(EL_STR("soul_snapshot_path"));
|
||||
if (!str_eq(snap_path, EL_STR(""))) {
|
||||
mem_save(snap_path);
|
||||
}
|
||||
}
|
||||
el_val_t last_scan_str = state_get(EL_STR("soul.last_scan_ts"));
|
||||
el_val_t last_scan_ts = ({ el_val_t _if_result_7 = 0; if (str_eq(last_scan_str, EL_STR(""))) { _if_result_7 = (0); } else { _if_result_7 = (str_to_int(last_scan_str)); } _if_result_7; });
|
||||
|
||||
Reference in New Issue
Block a user