Files
42_INT_09_piscine_cpp/d06/ex00/srcs/checkFloat.cpp
2022-03-07 22:30:41 +01:00

51 lines
1.0 KiB
C++

#include "convert.h"
//Char toChar(str) {
//
//}
bool isFloat(std::string str) {
size_t l;
// std::string float_xtrem = MAX_FLOAT;
if (str[0] == '+' || str[0] == '-')
str.erase(str.begin());
// if (str.length() == 0 || str.length() > FLOAT_MAX_LENGTH)
if (str.length() == 0)
return false;
if (!str.compare("inff") || !str.compare("nanf"))
return true;
l = str.find_first_not_of("0123456789");
if (l == std::string::npos || str[l] != '.')
return false;
str.erase(0,l + 1);
l = str.find_first_not_of("0123456789");
if (l == std::string::npos || str[l] != 'f')
return false;
// to work, one should check the decimal and the integer part
// str.erase(str.end() - 1);
// if (str.length() < FLOAT_MAX_LENGTH)
// return true;
// if (str.compare(float_xtrem) > 0)
// return false;
return true;
}
bool checkFloat(std::string str) {
// float f;
std::cout << "float\n";
if (!isFloat(str))
return false;
// f = toFloat(str);
// std::cout << "float"RESET" equal to : "B_CYAN << f << RESET << "\n";
// fromFloat(f);
return true;
}