From 647c77703793c6e9b004645b994846a5e6e3e066 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 24 Mar 2025 15:48:14 +0100 Subject: [PATCH] build: removing the debug mode --- cpp06/ex00/Makefile | 6 ++--- cpp06/ex00/sources/double.cpp | 39 +++++++++++++++++++++++++++ cpp06/ex00/sources/exeception.cpp | 35 ++++++++++++++++++++++++ cpp06/ex00/sources/float.cpp | 45 +++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 cpp06/ex00/sources/double.cpp create mode 100644 cpp06/ex00/sources/exeception.cpp create mode 100644 cpp06/ex00/sources/float.cpp diff --git a/cpp06/ex00/Makefile b/cpp06/ex00/Makefile index a54792d..ab519c9 100644 --- a/cpp06/ex00/Makefile +++ b/cpp06/ex00/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2025/03/24 14:51:15 by rparodi ### ########.fr # +# Updated: 2025/03/24 15:47:19 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -25,9 +25,9 @@ CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ # Flags to have the dependences (can be removed for correction) CXXFLAGS += -MMD # Flags to have the debug (can be removed for correction) -DEBUG = -g3 +# DEBUG = -g3 # DEBUG += -fsanitize=address -CXXFLAGS += $(DEBUG) +# CXXFLAGS += $(DEBUG) # Sources SRC = sources/char.cpp \ diff --git a/cpp06/ex00/sources/double.cpp b/cpp06/ex00/sources/double.cpp new file mode 100644 index 0000000..2f6efa5 --- /dev/null +++ b/cpp06/ex00/sources/double.cpp @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* double.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/22 22:11:44 by rparodi #+# #+# */ +/* Updated: 2025/03/24 15:11:15 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScalarConverter.hpp" + +bool isDouble(std::string const &str) { + if (str.empty()) + return false; + char *end; + int err = 0; + std::strtod(str.c_str(), &end); + if (*end) + return false; + if (err == ERANGE) + return false; + return true; +} + +void convertDouble(std::string const &str) { + char *end; + float the_double = std::strtod(str.c_str(), &end); + std::cout << CLR_BLUE << "Char:\t" << CLR_RESET; + if (the_double > -128 && the_double < 127 && std::isprint(the_double)) + std::cout << CLR_BLUE << "'" << CLR_GOLD << static_cast(the_double) << CLR_BLUE << "'" << CLR_RESET << std::endl; + else + std::cout << CLR_RED << "Non displayable" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Int:\t" << CLR_GOLD << static_cast(the_double)<< CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Float:\t" << CLR_GOLD << std::fixed << std::setprecision(1) << static_cast(the_double) << "f" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Double:\t" << CLR_GOLD << std::fixed << std::setprecision(1) << the_double << CLR_RESET << std::endl; +} diff --git a/cpp06/ex00/sources/exeception.cpp b/cpp06/ex00/sources/exeception.cpp new file mode 100644 index 0000000..2022025 --- /dev/null +++ b/cpp06/ex00/sources/exeception.cpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exeception.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/24 11:38:01 by rparodi #+# #+# */ +/* Updated: 2025/03/24 14:09:50 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScalarConverter.hpp" +#include "color.hpp" + +void not_a_number() { + std::cout << CLR_BLUE << "Char:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Int:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Float:\t" << CLR_GOLD << "nanf" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Double:\t" << CLR_GOLD << "nan" << CLR_RESET << std::endl; +} + +void minus_infinity() { + std::cout << CLR_BLUE << "Char:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Int:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Float:\t" << CLR_GOLD << "-inff" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Double:\t" << CLR_GOLD << "-inf" << CLR_RESET << std::endl; +} + +void plus_infinity() { + std::cout << CLR_BLUE << "Char:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Int:\t" << CLR_RED << "Impossible" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Float:\t" << CLR_GOLD << "+inff" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Double:\t" << CLR_GOLD << "+inf" << CLR_RESET << std::endl; +} diff --git a/cpp06/ex00/sources/float.cpp b/cpp06/ex00/sources/float.cpp new file mode 100644 index 0000000..28f5bca --- /dev/null +++ b/cpp06/ex00/sources/float.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* float.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/22 22:11:44 by rparodi #+# #+# */ +/* Updated: 2025/03/24 15:11:39 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScalarConverter.hpp" +#include "color.hpp" +#include +#include +#include +#include +#include + +bool isFloat(std::string const &str) { + if (str.empty()) + return false; + char *end; + int err = 0; + std::strtof(str.c_str(), &end); + if (*end) + return false; + if (err == ERANGE) + return false; + return true; +} + +void convertFloat(std::string const &str) { + char *end; + float floating = std::strtof(str.c_str(), &end); + std::cout << CLR_BLUE << "Char:\t" << CLR_RESET; + if (floating > -128 && floating < 127 && std::isprint(floating)) + std::cout << CLR_BLUE << "'" << CLR_GOLD << static_cast(floating) << CLR_BLUE << "'" << CLR_RESET << std::endl; + else + std::cout << CLR_RED << "Non displayable" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Int:\t" << CLR_GOLD << static_cast(floating)<< CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Float:\t" << CLR_GOLD << std::fixed << std::setprecision(1) << floating << "f" << CLR_RESET << std::endl; + std::cout << CLR_BLUE << "Double:\t" << CLR_GOLD << std::fixed << std::setprecision(1) << static_cast(floating) << CLR_RESET << std::endl; +}