d07 ex00 ok
This commit is contained in:
BIN
d06/ex00/a.out
BIN
d06/ex00/a.out
Binary file not shown.
BIN
d06/ex00/convert
BIN
d06/ex00/convert
Binary file not shown.
@@ -1,36 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
|
||||
#define MAX_INT 2147483647
|
||||
#define MIN_INT -2147483648
|
||||
#define MAX_FLOAT 340282346638528859811704183484516925440.0f
|
||||
#define MIN_FLOAT -340282346638528859811704183484516925440.0f
|
||||
|
||||
void isFloat(double d) {
|
||||
if (! (d <= std::numeric_limits<float>::max()
|
||||
&& d >= std::numeric_limits<float>::min()) )
|
||||
{
|
||||
std::cout << d << "is outside range of floats\n";
|
||||
return ;
|
||||
}
|
||||
std::cout << std::fixed << static_cast<float>(d) << "\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
double d;
|
||||
double d2;
|
||||
|
||||
d = std::numeric_limits<float>::max();
|
||||
std::cout << std::fixed << d << "\n";
|
||||
d2 = std::nextafter(d, DBL_MAX);
|
||||
std::cout << std::fixed << d2 << "\n";
|
||||
// isFloat(MAX_FLOAT);
|
||||
// d = std::numeric_limits<float>::lowest();
|
||||
// std::cout << std::fixed << d << "\n";
|
||||
// isFloat(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
75
d07/ex00/Makefile
Normal file
75
d07/ex00/Makefile
Normal file
@@ -0,0 +1,75 @@
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . name = value \ . += append to a variable #
|
||||
# VARIABLES . value . != set result of command #
|
||||
# . name is case sensitive . ?= set if not already set #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
NAME = templates
|
||||
|
||||
#TYPE = c
|
||||
TYPE = cpp
|
||||
|
||||
ifeq "$(TYPE)" "c"
|
||||
CC = c
|
||||
EXT = c
|
||||
else ifeq "$(TYPE)" "cpp"
|
||||
CC = c++
|
||||
EXT = cpp
|
||||
endif
|
||||
|
||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||
ifeq "$(TYPE)" "cpp"
|
||||
CFLAGS += -std=c++98
|
||||
endif
|
||||
|
||||
VPATH = $(D_SRCS)
|
||||
|
||||
LIBS =
|
||||
|
||||
INCLUDES = -I$(D_HEADERS)
|
||||
|
||||
D_SRCS = .
|
||||
SRCS = main.cpp
|
||||
|
||||
D_HEADERS = headers
|
||||
HEADERS = Templates.hpp
|
||||
|
||||
D_OBJS = builds
|
||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
||||
|
||||
ifeq "$(D_OBJS)" "."
|
||||
RM_OBJS = rm -f $(OBJS)
|
||||
else
|
||||
RM_OBJS = rm -rf $(D_OBJS)
|
||||
endif
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . target: prerequisites . $@ : target #
|
||||
# RULES . recipe . $< : 1st prerequisite #
|
||||
# . recipe . $^ : all prerequisites #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(D_OBJS):
|
||||
mkdir $@
|
||||
|
||||
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||
|
||||
clean:
|
||||
$(RM_OBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
|
||||
28
d07/ex00/headers/Templates.hpp
Normal file
28
d07/ex00/headers/Templates.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef TEMPLATES_HPP
|
||||
# define TEMPLATES_HPP
|
||||
|
||||
template< typename T >
|
||||
void swap(T &a, T &b) {
|
||||
|
||||
T tmp;
|
||||
|
||||
tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
T const & min(T const &a, T const &b) {
|
||||
if (a < b)
|
||||
return a;
|
||||
return b;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
T const & max(T const &a, T const &b) {
|
||||
if (a > b)
|
||||
return a;
|
||||
return b;
|
||||
}
|
||||
|
||||
#endif
|
||||
24
d07/ex00/main.cpp
Normal file
24
d07/ex00/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "Templates.hpp"
|
||||
|
||||
int main() {
|
||||
int a = 2;
|
||||
int b = 3;
|
||||
|
||||
::swap( a, b );
|
||||
std::cout << "a = " << a << ", b = " << b << std::endl;
|
||||
std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl;
|
||||
std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl;
|
||||
|
||||
std::string c = "chaine1";
|
||||
std::string d = "chaine2";
|
||||
|
||||
::swap(c, d);
|
||||
std::cout << "c = " << c << ", d = " << d << std::endl;
|
||||
std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl;
|
||||
std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
d07/ex00/templates
Executable file
BIN
d07/ex00/templates
Executable file
Binary file not shown.
Reference in New Issue
Block a user