#include "convert.h" void fromDouble(double d) { char c; int i; float f; c = static_cast(d); std::cout << std::setw(7) << std::left << "char" << B_CYAN << c << RESET "\n"; i = static_cast(d); std::cout << std::setw(7) << std::left << "int" << B_CYAN << i << RESET "\n"; f = static_cast(d); std::cout << std::setw(7) << std::left << "float" << B_CYAN << f << RESET "\n"; } //Char toChar(str) { // char c; // std::istringstream(str) >> c; // return c; //} bool isDouble(std::string str) { size_t l; std::string neg = ""; if (str[0] == '-') neg = "-"; if (str[0] == '+' || str[0] == '-') str.erase(str.begin()); if (!str.length()) return false; if (!str.compare("inf") || !str.compare("nan")) return true; l = str.find_first_not_of("0123456789"); if (l == std::string::npos || str[l] != '.') return false; str.erase(0,l + 1); if (str.find_first_not_of("0123456789") != std::string::npos) return false; str.insert(0, neg); strtod(str.c_str(), NULL); if (errno == ERANGE) return false; return true; } bool checkDouble(std::string str) { // double d; std::cout << "double\n"; if (!isDouble(str)) return false; // d = toDouble(str); // std::cout << "double"RESET" equal to : "B_CYAN << d << RESET << "\n"; // fromDouble(d); return true; }