check leaks on d02 ok
This commit is contained in:
17
d02/<
Normal file
17
d02/<
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "colors.h"
|
||||||
|
|
||||||
|
#define N_TEST "1"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||||
|
<< "tests :" RESET "\n";
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ CONVERSIONS
|
|||||||
1 / 2 = 0 -> 1
|
1 / 2 = 0 -> 1
|
||||||
75 :
|
75 :
|
||||||
.75 *2^2 = 2,88 ~= 3
|
.75 *2^2 = 2,88 ~= 3
|
||||||
(*2^x parce que c le moyen dont fait "bouger" la virgule
|
(*2^x parce que c le moyen dont on fait "bouger" la virgule
|
||||||
en base 2 (*10^x) en base 10)
|
en base 2 (*10^x) en base 10)
|
||||||
3 / 2 = 1 -> 1
|
3 / 2 = 1 -> 1
|
||||||
1 / 2 = 0 -> 1
|
1 / 2 = 0 -> 1
|
||||||
@@ -312,5 +312,3 @@ integer = (integer << (30 - this->_frac - exponent)) | sign; // add sign
|
|||||||
integer >>= (30 - this->_frac - exponent); // align right
|
integer >>= (30 - this->_frac - exponent); // align right
|
||||||
std::cout << "integer : " << printBitsInt(integer) << " (" << integer << ")\n";
|
std::cout << "integer : " << printBitsInt(integer) << " (" << integer << ")\n";
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ SRCS = main.cpp \
|
|||||||
Fixed.cpp
|
Fixed.cpp
|
||||||
|
|
||||||
D_HEADERS = .
|
D_HEADERS = .
|
||||||
HEADERS = Fixed.hpp
|
HEADERS = Fixed.hpp \
|
||||||
|
colors.h
|
||||||
|
|
||||||
D_OBJS = builds
|
D_OBJS = builds
|
||||||
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||||
@@ -50,6 +51,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
|
|
||||||
|
|||||||
25
d02/ex00/colors.h
Normal file
25
d02/ex00/colors.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef COLORS_H
|
||||||
|
# define COLORS_H
|
||||||
|
|
||||||
|
# define GRAY "\e[0;30m"
|
||||||
|
# define RED "\e[0;31m"
|
||||||
|
# define GREEN "\e[0;32m"
|
||||||
|
# define YELLOW "\e[0;33m"
|
||||||
|
# define BLUE "\e[0;34m"
|
||||||
|
# define PURPLE "\e[0;35m"
|
||||||
|
# define CYAN "\e[0;36m"
|
||||||
|
# define WHITE "\e[0;37m"
|
||||||
|
|
||||||
|
# define B_GRAY "\e[1;30m"
|
||||||
|
# define B_RED "\e[1;31m"
|
||||||
|
# define B_GREEN "\e[1;32m"
|
||||||
|
# define B_YELLOW "\e[1;33m"
|
||||||
|
# define B_BLUE "\e[1;34m"
|
||||||
|
# define B_PURPLE "\e[1;35m"
|
||||||
|
# define B_CYAN "\e[1;36m"
|
||||||
|
# define B_WHITE "\e[1;37m"
|
||||||
|
|
||||||
|
# define RESET "\e[0m"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -1,17 +1,54 @@
|
|||||||
#include "Fixed.hpp"
|
#include "Fixed.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "colors.h"
|
||||||
|
|
||||||
|
#define N_TEST "1"
|
||||||
|
|
||||||
int main( void ) {
|
int main( void ) {
|
||||||
|
|
||||||
Fixed a;
|
int i = 0;
|
||||||
Fixed b( a );
|
|
||||||
Fixed c;
|
|
||||||
|
|
||||||
c = b;
|
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||||
|
<< "tests subject :" RESET "\n";
|
||||||
|
{
|
||||||
|
Fixed a;
|
||||||
|
Fixed b( a );
|
||||||
|
Fixed c;
|
||||||
|
|
||||||
|
c = b;
|
||||||
|
|
||||||
|
std::cout << a.getRawBits() << std::endl;
|
||||||
|
std::cout << b.getRawBits() << std::endl;
|
||||||
|
std::cout << c.getRawBits() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << a.getRawBits() << std::endl;
|
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
|
||||||
std::cout << b.getRawBits() << std::endl;
|
<< "tests sets :" RESET "\n";
|
||||||
std::cout << c.getRawBits() << std::endl;
|
{
|
||||||
|
Fixed a;
|
||||||
|
Fixed b( a );
|
||||||
|
Fixed c;
|
||||||
|
|
||||||
|
c = b;
|
||||||
|
|
||||||
|
std::cout << "\n" B_BLUE "sets a(4), b(6.3), c(-187)" RESET "\n";
|
||||||
|
a.setRawBits(4);
|
||||||
|
b.setRawBits(6.3);
|
||||||
|
c.setRawBits(-187);
|
||||||
|
|
||||||
|
std::cout << a.getRawBits() << std::endl;
|
||||||
|
std::cout << b.getRawBits() << std::endl;
|
||||||
|
std::cout << c.getRawBits() << std::endl;
|
||||||
|
|
||||||
|
std::cout << "\n" B_BLUE "sets a(76.76), b(0), c(0.0)" RESET "\n";
|
||||||
|
a.setRawBits(76.76);
|
||||||
|
b.setRawBits(0);
|
||||||
|
c.setRawBits(0.0);
|
||||||
|
|
||||||
|
std::cout << a.getRawBits() << std::endl;
|
||||||
|
std::cout << b.getRawBits() << std::endl;
|
||||||
|
std::cout << c.getRawBits() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
* statics variables initialisation
|
* statics variables initialisation
|
||||||
*
|
*
|
||||||
* for MAX integer :
|
* for MAX integer :
|
||||||
* 00000000 01111111 11111111 11111111 ( 8388607) (-1U >> (this->_frac +1))
|
* 00000000 01111111 11111111 11111111 ( 8388607) (-1U >> (this->_frac + 1))
|
||||||
* <= ... >=
|
* <= ... >=
|
||||||
* 11111111 10000000 00000000 00000000 (-8388608) ~MAX
|
* 11111111 10000000 00000000 00000000 (-8388608) ~MAX
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int const Fixed::_frac = 8;
|
int const Fixed::_frac = 8;
|
||||||
int const Fixed::_max = -1U >> (_frac +1);
|
int const Fixed::_max = -1U >> (_frac + 1);
|
||||||
int const Fixed::_min = ~_max;
|
int const Fixed::_min = ~_max;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -55,6 +55,18 @@ Fixed::Fixed(float const floater) {
|
|||||||
std::cout << "error: float out of range" << '\n';
|
std::cout << "error: float out of range" << '\n';
|
||||||
else
|
else
|
||||||
this->_value = roundf(floater * (1 << Fixed::_frac));
|
this->_value = roundf(floater * (1 << Fixed::_frac));
|
||||||
|
|
||||||
|
// this->_value = *((int *)&floater); // access float adress content as int
|
||||||
|
// int sign = this->_value & (1 << 31); // extract sign
|
||||||
|
// int exponent = ((unsigned int)(this->_value << 1) >> 24) - 127; // extract exponent
|
||||||
|
// int integer = (this->_value << 8) | (1 << 31); // add left 1
|
||||||
|
// integer = (unsigned int)integer >> (31 - this->_frac - exponent);// align to right
|
||||||
|
// if (sign != 0)
|
||||||
|
// integer = (~integer + 1); // reverse negatif
|
||||||
|
// integer = (integer << (30 - this->_frac - exponent)) | sign; // add sign
|
||||||
|
// integer >>= (30 - this->_frac - exponent); // align right
|
||||||
|
// std::cout << "integer : " << printBitsInt(integer) << " (" << integer << ")\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
|
|
||||||
|
|||||||
BIN
d02/ex01/fixed
BIN
d02/ex01/fixed
Binary file not shown.
@@ -50,6 +50,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user