🎉」 init: hello world !

This commit is contained in:
2025-08-15 14:48:31 +02:00
commit e72927e52c
13 changed files with 618 additions and 0 deletions

128
ex00/PrintValue.hpp Normal file
View File

@@ -0,0 +1,128 @@
#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<char>(s[0]) << "'" << std::endl;
std::cout << "int: " << static_cast<int>(s[0]) << std::endl;
std::cout << "float: " << std::fixed << static_cast<float>(s[0]) << "f" << std::endl;
std::cout << "double: " << std::fixed << static_cast<double>(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<char>::min() ||
nb > std::numeric_limits<char>::max())
std::cout << "impossible" << std::endl;
else if (!std::isprint(nb))
std::cout << "Non displayable" << std::endl;
else
std::cout << "'" << static_cast<char>(nb) << "'" << std::endl;
std::cout << "int: ";
if (nb < std::numeric_limits<int>::min() ||
nb > std::numeric_limits<int>::max())
std::cout << "impossible" << std::endl;
else
std::cout << static_cast<int>(nb) << std::endl;
std::cout << "float: " << std::fixed << static_cast<float>(nb) << "f" << std::endl;
std::cout << "double: " << std::fixed << static_cast<double>(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<char>::min() ||
nb > std::numeric_limits<char>::max())
std::cout << "impossible" << std::endl;
else if (!std::isprint(nb))
std::cout << "Non displayable" << std::endl;
else
std::cout << "'" << static_cast<char>(nb) << "'" << std::endl;
std::cout << "int: ";
if (nb < std::numeric_limits<int>::min() ||
nb > std::numeric_limits<int>::max())
std::cout << "impossible" << std::endl;
else
std::cout << static_cast<int>(nb) << std::endl;
std::cout << "float: ";
if (nb < std::numeric_limits<float>::min() ||
nb > std::numeric_limits<float>::max())
std::cout << "impossible" << std::endl;
else
std::cout << std::fixed << static_cast<float>(nb) << "f" << std::endl;
std::cout << "double: " << std::fixed << static_cast<double>(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<char>::min() ||
nb > std::numeric_limits<char>::max())
std::cout << "impossible" << std::endl;
else if (!std::isprint(nb))
std::cout << "Non displayable" << std::endl;
else
std::cout << "'" << static_cast<char>(nb) << "'" << std::endl;
std::cout << "int: ";
if (nb < std::numeric_limits<int>::min() ||
nb > std::numeric_limits<int>::max())
std::cout << "impossible" << std::endl;
else
std::cout << static_cast<int>(nb) << std::endl;
std::cout << "float: ";
if (nb < std::numeric_limits<float>::min() ||
nb > std::numeric_limits<float>::max())
std::cout << "impossible" << std::endl;
else
std::cout << std::fixed << static_cast<float>(nb) << "f" << std::endl;
std::cout << "double: " << std::fixed << static_cast<double>(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;
}
}