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; }