d06 ex00 ajout qq tests avec limits des floats
This commit is contained in:
@@ -1,29 +1,15 @@
|
||||
#include "convert.h"
|
||||
|
||||
void fromFloat(float value) {
|
||||
static void fromFloat(float value) {
|
||||
// char
|
||||
std::cout << std::setw(7) << std::left << "char";
|
||||
if (value < 0 || value > std::numeric_limits<char>::max())
|
||||
std::cout << B_RED << "impossible" << RESET "\n";
|
||||
else if (!isprint(value))
|
||||
std::cout << B_RED << "non displayable" << RESET "\n";
|
||||
else
|
||||
std::cout << B_CYAN << static_cast<char>(value) << RESET "\n";
|
||||
|
||||
toChar(value);
|
||||
// int
|
||||
std::cout << std::setw(7) << std::left << "int";
|
||||
if (value < std::numeric_limits<int>::min()
|
||||
|| value > std::numeric_limits<int>::max() )
|
||||
std::cout << B_RED << "impossible" << RESET "\n";
|
||||
else
|
||||
std::cout << B_CYAN << static_cast<int>(value) << RESET "\n";
|
||||
|
||||
toInt(value);
|
||||
// double
|
||||
std::cout << std::setw(7) << std::left << "double";
|
||||
std::cout << B_CYAN << static_cast<double>(value) << RESET "\n";
|
||||
toDouble(value);
|
||||
}
|
||||
|
||||
bool isFloat(std::string str) {
|
||||
static bool isFloat(std::string str) {
|
||||
size_t l;
|
||||
size_t l2;
|
||||
|
||||
@@ -53,8 +39,11 @@ bool checkFloat(std::string str) {
|
||||
if (!isFloat(str))
|
||||
return false;
|
||||
|
||||
std::istringstream(str) >> f;
|
||||
std::cout << B_CYAN << f << B_YELLOW " float" RESET "\n";
|
||||
// std::istringstream(str) >> f;
|
||||
f = strtod(str.c_str(), NULL);
|
||||
std::cout << std::fixed << B_CYAN << f;
|
||||
// printDot(f);
|
||||
std::cout << "f" << B_YELLOW " float" RESET "\n";
|
||||
fromFloat(f);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user