overpatch

This commit is contained in:
Leo Firmin 2026-02-02 05:21:00 +01:00
parent 7a8460f34d
commit 5a5528db10
4 changed files with 43 additions and 18 deletions

BIN
ex00/ScalarConverter Executable file

Binary file not shown.

View File

@ -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)
{
float f = static_cast<float>(atof(input.c_str()));
if (std::isinf(f))
return false;
return true; 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,8 +147,11 @@ 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);
if (i >= std::numeric_limits<char>::min() &&
i <= std::numeric_limits<char>::max())
{ {
char c = static_cast<char>(i); char c = static_cast<char>(i);
if (isprint(c)) if (isprint(c))
@ -138,8 +161,10 @@ void ScalarConverter::toInt(const std::string &input)
} }
else else
std::cout << "char: \timpossible" << std::endl; std::cout << "char: \timpossible" << std::endl;
std::cout << "int: \t" << i << 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 << "float: \t" << std::fixed << std::setprecision(1)
<< static_cast<float>(i) << "f" << std::endl;
std::cout << "double: \t" << static_cast<double>(i) << std::endl; std::cout << "double: \t" << static_cast<double>(i) << std::endl;
} }

BIN
ex00/obj/Main.o Normal file

Binary file not shown.

BIN
ex00/obj/ScalarConverter.o Normal file

Binary file not shown.