overpatch
This commit is contained in:
parent
7a8460f34d
commit
5a5528db10
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
|||
#include "ScalarConverter.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
ScalarConverter::ScalarConverter()
|
||||
{
|
||||
|
|
@ -45,6 +45,12 @@ bool ScalarConverter::isInt(const std::string& input)
|
|||
return false;
|
||||
i++;
|
||||
}
|
||||
char* end;
|
||||
long value = strtol(input.c_str(), &end, 10);
|
||||
|
||||
if (value < std::numeric_limits<int>::min() ||
|
||||
value > std::numeric_limits<int>::max())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -63,13 +69,19 @@ bool ScalarConverter::isFloat(const std::string& input)
|
|||
hasDigit = true;
|
||||
else if (input[i] == '.' && !hasPoint)
|
||||
hasPoint = true;
|
||||
else if (input[i] == 'f' && i == input.length() - 1 && hasDigit)
|
||||
return true;
|
||||
else if (input[i] == 'f' && i == input.length() - 1 && hasDigit && hasPoint)
|
||||
{
|
||||
float f = static_cast<float>(atof(input.c_str()));
|
||||
|
||||
if (std::isinf(f))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
i++;
|
||||
}
|
||||
return (hasDigit && hasPoint);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScalarConverter::isDouble(const std::string& input)
|
||||
|
|
@ -91,6 +103,12 @@ bool ScalarConverter::isDouble(const std::string& input)
|
|||
return false;
|
||||
i++;
|
||||
}
|
||||
double d = atof(input.c_str());
|
||||
std::cout << "DEBUG double: d = " << d << std::endl; // ← AJOUTE
|
||||
std::cout << "DEBUG isinf: " << std::isinf(d) << std::endl; // ← AJOUTE
|
||||
if (std::isinf(d))
|
||||
return false;
|
||||
|
||||
return (hasDigit && hasPoint);
|
||||
}
|
||||
bool ScalarConverter::isOther(const std::string &input)
|
||||
|
|
@ -108,6 +126,8 @@ bool ScalarConverter::isOther(const std::string &input)
|
|||
void ScalarConverter::toChar(const std::string &input)
|
||||
{
|
||||
char c = input[0];
|
||||
if (input.size() == 3 && input[0] == '\'' && input[2] == '\'')
|
||||
c = input[1];
|
||||
int i = static_cast<int>(c);
|
||||
float f = static_cast<float>(c);
|
||||
double d = static_cast<double>(c);
|
||||
|
|
@ -127,20 +147,25 @@ void ScalarConverter::toChar(const std::string &input)
|
|||
|
||||
void ScalarConverter::toInt(const std::string &input)
|
||||
{
|
||||
int i = atoi(input.c_str());
|
||||
if (i >= std::numeric_limits<char>::min() && i <= std::numeric_limits<char>::max())
|
||||
{
|
||||
char c = static_cast<char>(i);
|
||||
if (isprint(c))
|
||||
std::cout << "char: \t'" << c << "'" << std::endl;
|
||||
else
|
||||
std::cout << "char: \tnon displayable" << std::endl;
|
||||
}
|
||||
else
|
||||
std::cout << "char: \timpossible" << std::endl;
|
||||
std::cout << "int: \t" << i << std::endl;
|
||||
std::cout << "float: \t" << std::fixed << std::setprecision(1) << static_cast<float>(i) << "f" << std::endl;
|
||||
std::cout << "double: \t" << static_cast<double>(i) << std::endl;
|
||||
char* end;
|
||||
long temp = strtol(input.c_str(), &end, 10);
|
||||
int i = static_cast<int>(temp);
|
||||
if (i >= std::numeric_limits<char>::min() &&
|
||||
i <= std::numeric_limits<char>::max())
|
||||
{
|
||||
char c = static_cast<char>(i);
|
||||
if (isprint(c))
|
||||
std::cout << "char: \t'" << c << "'" << std::endl;
|
||||
else
|
||||
std::cout << "char: \tnon displayable" << std::endl;
|
||||
}
|
||||
else
|
||||
std::cout << "char: \timpossible" << std::endl;
|
||||
|
||||
std::cout << "int: \t" << i << std::endl;
|
||||
std::cout << "float: \t" << std::fixed << std::setprecision(1)
|
||||
<< static_cast<float>(i) << "f" << std::endl;
|
||||
std::cout << "double: \t" << static_cast<double>(i) << std::endl;
|
||||
}
|
||||
|
||||
void ScalarConverter::toFloat(const std::string &input)
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue