#pragma once #include "ScalarConverter.hpp" void _printChar(const std::string &s) { std::cout << "char: "; if (!std::isprint(s[0])) std::cout << "Non displayable" << std::endl; else std::cout << "'" << static_cast(s[0]) << "'" << std::endl; std::cout << "int: " << static_cast(s[0]) << std::endl; std::cout << "float: " << std::fixed << static_cast(s[0]) << "f" << std::endl; std::cout << "double: " << std::fixed << static_cast(s[0]) << std::endl; } void _printInt(const std::string &s) { long int nb = std::strtol(s.c_str(), NULL, 10); std::cout << "char: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else if (!std::isprint(nb)) std::cout << "Non displayable" << std::endl; else std::cout << "'" << static_cast(nb) << "'" << std::endl; std::cout << "int: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << static_cast(nb) << std::endl; std::cout << "float: " << std::fixed << static_cast(nb) << "f" << std::endl; std::cout << "double: " << std::fixed << static_cast(nb) << std::endl; } void _printFloat(const std::string &s) { long int nb = std::strtod(s.c_str(), NULL); std::cout << "char: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else if (!std::isprint(nb)) std::cout << "Non displayable" << std::endl; else std::cout << "'" << static_cast(nb) << "'" << std::endl; std::cout << "int: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << static_cast(nb) << std::endl; std::cout << "float: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << std::fixed << static_cast(nb) << "f" << std::endl; std::cout << "double: " << std::fixed << static_cast(nb) << std::endl; } void _printDouble(const std::string &s) { long int nb = std::strtod(s.c_str(), NULL); std::cout << "char: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else if (!std::isprint(nb)) std::cout << "Non displayable" << std::endl; else std::cout << "'" << static_cast(nb) << "'" << std::endl; std::cout << "int: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << static_cast(nb) << std::endl; std::cout << "float: "; if (nb < std::numeric_limits::min() || nb > std::numeric_limits::max()) std::cout << "impossible" << std::endl; else std::cout << std::fixed << static_cast(nb) << "f" << std::endl; std::cout << "double: " << std::fixed << static_cast(nb) << std::endl; } void _printNan(const std::string &s) { std::string input = s; if (input == "inf" || input == "inff") input = "+inf"; if (input == "nan" || input == "-inf" || input == "+inf") { std::cout << "char: impossible\n"; std::cout << "int: impossible\n"; std::cout << "float: " << input << "f" << std::endl; std::cout << "double: " << input << std::endl; return; } if (input == "nanf" || input == "-inff" || input == "+inff") { std::cout << "char: impossible\n"; std::cout << "int: impossible\n"; std::cout << "float: " << input << std::endl; std::cout << "double: "; if (input == "nanf") std::cout << "nan"; else if (input == "-inff") std::cout << "-inf"; else std::cout << "+inf"; std::cout << std::endl; } }