From 992895067efa7ceb835a347e7084f6a05c45a184 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 19 Sep 2023 09:03:29 +0000 Subject: [PATCH] ex00: fix: inf(f) is possible now --- ex00/src/ScalarConverter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ex00/src/ScalarConverter.cpp b/ex00/src/ScalarConverter.cpp index 2c81521..c98c7db 100644 --- a/ex00/src/ScalarConverter.cpp +++ b/ex00/src/ScalarConverter.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include ScalarConverter::ScalarConverter() {} @@ -36,7 +38,7 @@ double get_value(const std::string& str) if (str.length() == 3 && str[0] == '\'' && str[2] == '\'') return str[1]; double value = std::strtod(str.c_str(), &pos); - if (errno == ERANGE || (pos != NULL && strcmp(pos, "f"))) + if (errno == ERANGE || (pos[0] != '\0' && strcmp(pos, "f"))) throw std::exception(); return value; } @@ -66,10 +68,10 @@ void convert2int(const double value) void convert2float(const double value) { std::cout << "float: "; - if (value > FLT_MAX || FLT_MIN > value) + if ((value > FLT_MAX || FLT_MIN > value) && !std::isinf(value)) std::cout << "imposible"; else - std::cout << static_cast(value); + std::cout << static_cast(value) << "f"; std::cout << std::endl; }