From af6a58bfad54dc9d3cb49d1efa1c90a5d094bcb1 Mon Sep 17 00:00:00 2001 From: A404M Date: Sun, 23 Feb 2025 22:09:19 +0330 Subject: fix bugs in float types --- src/utils/string.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/string.c b/src/utils/string.c index ee8a354..17e27cd 100644 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -3,6 +3,7 @@ #include "utils/type.h" #include +#include #include size_t searchInStringArray(const char *array[], size_t array_size, @@ -34,8 +35,8 @@ u64 decimalToU64(char *str_begin, char *str_end, bool *success) { } f128 numberToFloat(char *str_begin, char *str_end, bool *success) { - f64 left = 0; - f64 right = 0; + f128 left = 0; + f128 right = 0; bool isPastPoint = false; while (str_begin < str_end) { @@ -46,12 +47,12 @@ f128 numberToFloat(char *str_begin, char *str_end, bool *success) { c = *str_begin++; } if (c >= '0' && c <= '9') { - if (isPastPoint) { + if (!isPastPoint) { left *= 10; left += c - '0'; } else { - right /= 10; right += c - '0'; + right /= 10; } } else if (c == '.' && !isPastPoint) { isPastPoint = true; -- cgit v1.2.3