Merge branch 'master' of bitbucket.org:hugogogo/piscine_cpp

This commit is contained in:
hugogogo
2022-08-01 20:06:44 +02:00
90 changed files with 2583 additions and 235 deletions

BIN
d06/ex00/convert Executable file

Binary file not shown.

View File

@@ -28,7 +28,6 @@ template <typename T> void toDouble(T value);
#define MAX_INT "2147483647"
#define MIN_INT "-2147483648"
#define MAX_INT_1 "2147483648"
#define MIN_INT_1 "-2147483649"
#define INT_MAX_LENGTH 10
#define MAX_FLOAT_INT_PRECISION "16777216"
#define MAX_FLOAT "340282346638528859811704183484516925440"
@@ -38,6 +37,27 @@ template <typename T> void toDouble(T value);
#define DOUBLE_MAX_LENGTH 309
// for tests
#define MAX_I__5 "2147483642"
#define MAX_I__4 "2147483643"
#define MAX_I__3 "2147483644"
#define MAX_I__2 "2147483645"
#define MAX_I__1 "2147483646"
#define MAX_I_2 "2147483649"
#define MAX_I_3 "2147483650"
#define MAX_I_4 "2147483651"
#define MAX_I_5 "2147483652"
#define MIN_I__5 "-2147483643"
#define MIN_I__4 "-2147483644"
#define MIN_I__3 "-2147483645"
#define MIN_I__2 "-2147483646"
#define MIN_I__1 "-2147483647"
#define MIN_I_1 "-2147483649"
#define MIN_I_2 "-2147483650"
#define MIN_I_3 "-2147483651"
#define MIN_I_4 "-2147483652"
#define MIN_I_5 "-2147483653"
#define MAX_FLOAT_INT_PREC__1 "16777215"
#define MAX_FLOAT_INT_PREC__2 "16777214"
#define MAX_FLOAT_INT_PREC__3 "16777213"

View File

@@ -15,6 +15,8 @@ int main(int ac, char **av) {
return 0;
}
std::cout << "\n\n" B_GREEN "----------------------------------------------------\n"
<< "\nCHAR" RESET "\n";
// char
convert("!");
convert("\"");
@@ -100,6 +102,9 @@ int main(int ac, char **av) {
convert("|");
convert("}");
convert("~");
std::cout << "\n\n" B_GREEN "----------------------------------------------------\n"
<< "\nINT" RESET "\n";
// int
convert("0");
convert("-42");
@@ -132,10 +137,33 @@ int main(int ac, char **av) {
convert("256");
convert("257");
convert("258");
convert(MAX_INT);
std::cout << "\n\n" B_PURPLE "[min - max int]" RESET "\n";
convert(MIN_I_5);
convert(MIN_I_4);
convert(MIN_I_3);
convert(MIN_I_2);
convert(MIN_I_1);
convert(MIN_INT);
convert(MIN_I__1);
convert(MIN_I__2);
convert(MIN_I__3);
convert(MIN_I__4);
convert(MIN_I__5);
convert(MAX_I__5);
convert(MAX_I__4);
convert(MAX_I__3);
convert(MAX_I__2);
convert(MAX_I__1);
convert(MAX_INT);
convert(MAX_INT_1);
convert(MIN_INT_1);
convert(MAX_I_2);
convert(MAX_I_3);
convert(MAX_I_4);
convert(MAX_I_5);
std::cout << "\n" B_PURPLE "[END min - max int]" RESET "\n\n";
convert(MAX_FLOAT_INT_PRECISION);
convert(MAX_FLOAT_INT_PREC__1);
convert(MAX_FLOAT_INT_PREC__2);
@@ -147,6 +175,9 @@ int main(int ac, char **av) {
convert(MAX_FLOAT_INT_PREC_4);
convert(MAX_FLOAT_INT_PREC_5);
convert(MAX_FLOAT_INT_PREC_6);
std::cout << "\n\n" B_GREEN "----------------------------------------------------\n"
<< "\nFLOAT" RESET "\n";
// float
convert("0.0f");
convert("-4.2f");
@@ -154,10 +185,33 @@ int main(int ac, char **av) {
convert("-inff");
convert("+inff");
convert("nanf");
convert(MAX_INT".0f");
convert(MIN_INT".0f");
convert(MAX_INT_1".0f");
convert(MIN_INT_1".0f");
std::cout << "\n\n" B_PURPLE "[min - max int]" RESET "\n";
convert(MIN_I_5 ".0f");
convert(MIN_I_4 ".0f");
convert(MIN_I_3 ".0f");
convert(MIN_I_2 ".0f");
convert(MIN_I_1 ".0f");
convert(MIN_INT ".0f");
convert(MIN_I__1 ".0f");
convert(MIN_I__2 ".0f");
convert(MIN_I__3 ".0f");
convert(MIN_I__4 ".0f");
convert(MIN_I__5 ".0f");
convert(MAX_I__5 ".0f");
convert(MAX_I__4 ".0f");
convert(MAX_I__3 ".0f");
convert(MAX_I__2 ".0f");
convert(MAX_I__1 ".0f");
convert(MAX_INT ".0f");
convert(MAX_INT_1 ".0f");
convert(MAX_I_2 ".0f");
convert(MAX_I_3 ".0f");
convert(MAX_I_4 ".0f");
convert(MAX_I_5 ".0f");
std::cout << "\n" B_PURPLE "[END min - max int]" RESET "\n\n";
convert(MAX_FLOAT_INT_PRECISION".0f");
convert(MAX_FLOAT_INT_PREC__1".0f");
convert(MAX_FLOAT_INT_PREC__2".0f");
@@ -181,6 +235,9 @@ int main(int ac, char **av) {
convert(MAX_F_5".0f");
convert(MAX_F_6".0f");
convert(MAX_F_N".0f");
std::cout << "\n\n" B_GREEN "----------------------------------------------------\n"
<< "\nDOUBLE" RESET "\n";
//double
convert("0.0");
convert("-4.2");
@@ -188,10 +245,33 @@ int main(int ac, char **av) {
convert("-inf");
convert("+inf");
convert("nan");
convert(MAX_INT".0");
convert(MIN_INT".0");
convert(MAX_INT_1".0");
convert(MIN_INT_1".0");
std::cout << "\n\n" B_PURPLE "[min - max int]" RESET "\n";
convert(MIN_I_5 ".0");
convert(MIN_I_4 ".0");
convert(MIN_I_3 ".0");
convert(MIN_I_2 ".0");
convert(MIN_I_1 ".0");
convert(MIN_INT ".0");
convert(MIN_I__1 ".0");
convert(MIN_I__2 ".0");
convert(MIN_I__3 ".0");
convert(MIN_I__4 ".0");
convert(MIN_I__5 ".0");
convert(MAX_I__5 ".0");
convert(MAX_I__4 ".0");
convert(MAX_I__3 ".0");
convert(MAX_I__2 ".0");
convert(MAX_I__1 ".0");
convert(MAX_INT ".0");
convert(MAX_INT_1 ".0");
convert(MAX_I_2 ".0");
convert(MAX_I_3 ".0");
convert(MAX_I_4 ".0");
convert(MAX_I_5 ".0");
std::cout << "\n" B_PURPLE "[END min - max int]" RESET "\n\n";
convert(MAX_FLOAT_INT_PRECISION".0");
convert(MAX_FLOAT_INT_PREC__1".0");
convert(MAX_FLOAT_INT_PREC__2".0");

View File

@@ -22,10 +22,10 @@ bool isChar(std::string str) {
bool checkChar(std::string str) {
char c;
if (str.length() != 1 || isdigit(str[0]))
if (!isChar(str))
return false;
c = str[0];
c = str[0];
std::cout << B_CYAN << c << B_YELLOW " char" RESET "\n";
fromChar(c);

View File

@@ -2,6 +2,12 @@
#include <string>
#include "convert.h"
// f[] : is an array
// *f[] : is an array of pointers
// (*f[])() : is an array of pointers to functions with no parameters
// (*f[])(str) : is an array of pointers to functions with parameter str
// see :
// https://stackoverflow.com/questions/31643245/declaring-an-array-of-functions-of-type-void-c
bool (*checkFunc[])(std::string str) =
{
checkChar,

View File

@@ -22,8 +22,6 @@ void toChar(T value) {
template <typename T>
void toInt(T value) {
std::cout << std::setw(7) << std::left << "int";
// if (value < std::numeric_limits<int>::min()
// || value > std::numeric_limits<int>::max() )
if (! (value <= std::numeric_limits<int>::max()
&& value >= std::numeric_limits<int>::min()) )
{

View File

@@ -37,7 +37,10 @@ int main() {
raw = serialize(data_ptr);
std::cout << " " << raw << "\n";
// unsigned long int *li = (unsigned long int *)&data_ptr;
// std::cout << " " << *li << "\n";
data_ptr = deserialize(raw);
std::cout << " " << data_ptr << "\n";

BIN
d06/ex01/serialize Executable file

Binary file not shown.