d06 ex00 all checks are ok

This commit is contained in:
hugogogo
2022-03-07 22:30:41 +01:00
parent 142687283e
commit 4ee3ae3e7d
10 changed files with 234 additions and 73 deletions

View File

@@ -1,16 +1,50 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
#include "convert.h"
void fromDouble(double d) {
char c;
int i;
float f;
c = static_cast<char>(d);
std::cout << std::setw(7) << std::left << "char" << B_CYAN << c << RESET "\n";
i = static_cast<int>(d);
std::cout << std::setw(7) << std::left << "int" << B_CYAN << i << RESET "\n";
f = static_cast<float>(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) {
if (str.length() == 3)
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;
return false;
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) {