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