ScalarConverter improved
This commit is contained in:
@@ -49,12 +49,12 @@ void ScalarConverter::convert(const std::string &literal)
|
||||
convertFromSpecialCase(literal);
|
||||
else if (isChar(literal))
|
||||
convertFromChar(literal);
|
||||
else if(isInt(literal))
|
||||
convertFromInt(literal);
|
||||
else if(isFloat(literal))
|
||||
convertFromFloat(literal);
|
||||
else if (isDouble(literal))
|
||||
convertFromDouble(literal);
|
||||
else if (isInt(literal))
|
||||
convertFromInt(literal);
|
||||
else
|
||||
std::cout << "Error: invalid literal" << std::endl;
|
||||
}
|
||||
@@ -101,8 +101,6 @@ bool ScalarConverter::isDouble(const std::string &literal)
|
||||
{
|
||||
char *end;
|
||||
|
||||
if (literal.find('.') == std::string::npos)
|
||||
return (false);
|
||||
strtod(literal.c_str(), &end);
|
||||
if (*end != '\0')
|
||||
return (false);
|
||||
@@ -176,6 +174,9 @@ void ScalarConverter::convertFromFloat(const std::string &literal)
|
||||
std::cout << "char: Non displayable" << std::endl;
|
||||
else
|
||||
std::cout << "char: '" << static_cast<char>(nb) << "'" << std::endl;
|
||||
if (nb > static_cast<float>(INT_MAX) || nb < static_cast<float>(INT_MIN))
|
||||
std::cout << "int: impossible" << std::endl;
|
||||
else
|
||||
std::cout << "int: " << static_cast<int>(nb) << std::endl;
|
||||
std::cout << std::fixed << std::setprecision(1);
|
||||
std::cout << "float: " << nb << "f" << std::endl;
|
||||
@@ -194,6 +195,9 @@ void ScalarConverter::convertFromDouble(const std::string &literal)
|
||||
std::cout << "char: Non displayable" << std::endl;
|
||||
else
|
||||
std::cout << "char: '" << static_cast<char>(nb) << "'" << std::endl;
|
||||
if (nb > static_cast<double>(INT_MAX) || nb < static_cast<double>(INT_MIN))
|
||||
std::cout << "int: impossible" << std::endl;
|
||||
else
|
||||
std::cout << "int: " << static_cast<int>(nb) << std::endl;
|
||||
std::cout << std::fixed << std::setprecision(1);
|
||||
std::cout << "float: " << static_cast<float>(nb) << "f" << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user