diff --git a/libc/printf_impl.cpp b/libc/printf_impl.cpp index a4d788f2de..58b8ec24d7 100644 --- a/libc/printf_impl.cpp +++ b/libc/printf_impl.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -106,6 +107,12 @@ static void integer_to_string(char* buffer, T value, int base, bool upper, forma template static void floating_point_to_string(char* buffer, T value, bool upper, const format_options_t options) { + if (isnan(value)) + { + strcpy(buffer, "-nan"); + return; + } + int percision = 6; if (options.percision != -1) percision = options.percision; @@ -123,6 +130,12 @@ static void floating_point_to_string(char* buffer, T value, bool upper, const fo else if (options.show_plus_sign_as_space) buffer[offset++] = ' '; + if (isinf(value)) + { + strcpy(buffer + offset, "inf"); + return; + } + // Round last digit value += (T)0.5 * BAN::Math::pow(10.0, -percision);