From db83a7a2e45fd0f00e76ad01bca3eb922ad1de03 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 3 Jan 2024 21:07:45 +0300 Subject: [PATCH] reverse-ramdisk.c: improve `len_digit` calculation --- c-programming/reverse-ramdisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index c8b0669..ff1618b 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -64,7 +64,7 @@ int tf_alloc(size_t n, size_t type_size) { if (num_temp_files == 0) len_digit = 1; else - len_digit = (size_t) ceil(log((double) num_temp_files + 1.) / log(10.)); + len_digit = (size_t) floor(log10((double) num_temp_files)) + 1; size_t file_path_len = len_digit + strlen("tf_.tmp"); char* file_path = malloc((file_path_len + 1) * sizeof(char)); if (file_path == NULL) {