Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/lib/libc/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ float_to_str(fmtcb_t *cb, void *aux,
size_t total = 0;
int significands = fp->decimals > 0 ? fp->decimals : 6;

// Round half up at the last printed digit before the layout is fixed:
// a carry out of the leading digit adds one (9.998 -> "10.00", not "9.00")
int digits = significands + e10;
if(digits >= 0) {
uint64_t r = 1ULL << 59;
for(int i = 0; i < digits; i++)
r /= 10;
mantissa += r;
if(mantissa >= (1ULL << 60)) {
mantissa /= 10;
e10++;
}
}

int chars = flt_count_output_chars(sign, e10, significands, fp);
int pad = fp->width - chars;

Expand Down Expand Up @@ -368,11 +382,6 @@ float_to_str(fmtcb_t *cb, void *aux,
}
}

uint64_t r = 1ULL << 59;
for(int i = 0; i < significands; i++)
r /= 10;
mantissa += r;

for(int i = 0; i < significands; i++) {

mantissa *= 10;
Expand Down
1 change: 1 addition & 0 deletions src/platform/stm32f4/stm32f4_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ stm32f4_ccm_init(void)
heap_add_mem(0x10000000 + sizeof(cpu_t), CRASHLOG_ADDR,
MEM_TYPE_LOCAL, 5);

crashlog_init((void *)CRASHLOG_ADDR);
crashlog_recover();
}
Loading