gp
This commit is contained in:
parent
1179527d22
commit
5a33a3c5b7
4 changed files with 0 additions and 349 deletions
|
|
@ -1,129 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* Fixed.cpp :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/12/21 19:52:44 by rparodi #+# #+# */
|
|
||||||
/* Updated: 2024/12/27 14:13:47 by rparodi ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "Fixed.hpp"
|
|
||||||
#include <cmath>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
Fixed::Fixed() {
|
|
||||||
std::cout << "Default constructor called" << std::endl;
|
|
||||||
_fixed_value = 0;
|
|
||||||
_floating_value = 0;
|
|
||||||
_integer_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed::Fixed(const Fixed ©) {
|
|
||||||
std::cout << "Copy constructor called" << std::endl;
|
|
||||||
this->_fixed_value = copy._fixed_value;
|
|
||||||
this->_integer_value = copy._integer_value;
|
|
||||||
this->_floating_value = copy._floating_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed::Fixed(const int &integer) {
|
|
||||||
this->_fixed_value = integer << _fractionnal;
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed::Fixed(const float &floating) {
|
|
||||||
this->_fixed_value = (int)(roundf(floating * (1 << this->_fractionnal)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed::~Fixed() {
|
|
||||||
std::cout << "Destructor called" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed& Fixed::operator=(const Fixed &value){
|
|
||||||
std::cout << "Copy assignment operator called" << std::endl;
|
|
||||||
this->_fixed_value = value._fixed_value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream &output, const Fixed &value) {
|
|
||||||
output << value.toFloat();
|
|
||||||
return (output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Fixed::setRawBits(const int value) {
|
|
||||||
std::cout << "setRawBits member function called" << std::endl;
|
|
||||||
this->_fixed_value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Fixed::toInt() const {
|
|
||||||
return ((int)this->_fixed_value >> this->_fractionnal);
|
|
||||||
}
|
|
||||||
|
|
||||||
float Fixed::toFloat() const {
|
|
||||||
return ((float)this->_fixed_value / ( 1 << this->_fractionnal));
|
|
||||||
}
|
|
||||||
|
|
||||||
int Fixed::getRawBits() const {
|
|
||||||
std::cout << "getRawBits member function called" << std::endl;
|
|
||||||
return this->_fixed_value;
|
|
||||||
}
|
|
||||||
Fixed & Fixed::operator > (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
Fixed & Fixed::operator < (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator >= (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator <= (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator == (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator != (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator + (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator - (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator / (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator * (const Fixed &value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fixed fixed::operator ++ () {
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed Fixed::operator -- () {
|
|
||||||
this->_fixed_value++;
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Fixed & Fixed::operator ++ () {
|
|
||||||
this->_fixed_value++;
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Fixed & Fixed::operator -- () {
|
|
||||||
this->_fixed_value--;
|
|
||||||
return (*this);
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* Fixed.hpp :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/12/21 19:30:23 by rparodi #+# #+# */
|
|
||||||
/* Updated: 2024/12/27 14:13:47 by rparodi ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef FIXED_HPP
|
|
||||||
#define FIXED_HPP
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class Fixed {
|
|
||||||
public:
|
|
||||||
Fixed();
|
|
||||||
Fixed(const Fixed ©);
|
|
||||||
Fixed(const int &integer);
|
|
||||||
Fixed(const float &floating);
|
|
||||||
~Fixed();
|
|
||||||
int getRawBits() const;
|
|
||||||
void setRawBits(const int value);
|
|
||||||
int toInt() const;
|
|
||||||
float toFloat() const;
|
|
||||||
Fixed & operator = (const Fixed &value);
|
|
||||||
Fixed & operator > (const Fixed &value);
|
|
||||||
Fixed & operator < (const Fixed &value);
|
|
||||||
Fixed & operator >= (const Fixed &value);
|
|
||||||
Fixed & operator <= (const Fixed &value);
|
|
||||||
Fixed & operator == (const Fixed &value);
|
|
||||||
Fixed & operator != (const Fixed &value);
|
|
||||||
Fixed & operator + (const Fixed &value);
|
|
||||||
Fixed & operator - (const Fixed &value);
|
|
||||||
Fixed & operator / (const Fixed &value);
|
|
||||||
Fixed & operator * (const Fixed &value);
|
|
||||||
Fixed operator ++ ();
|
|
||||||
Fixed operator -- ();
|
|
||||||
Fixed & operator ++ ();
|
|
||||||
Fixed & operator -- ();
|
|
||||||
private:
|
|
||||||
int _integer_value;
|
|
||||||
float _floating_value;
|
|
||||||
int _fixed_value;
|
|
||||||
static const int _fractionnal = 8;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream& output, const Fixed &value);
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,124 +0,0 @@
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
|
||||||
# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr #
|
|
||||||
# #
|
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
# Variables
|
|
||||||
|
|
||||||
# Name
|
|
||||||
NAME = Fixed
|
|
||||||
|
|
||||||
# Commands
|
|
||||||
CXX = c++
|
|
||||||
RM = rm -rf
|
|
||||||
|
|
||||||
# Flags
|
|
||||||
# Mandatory flags for 42 cpp
|
|
||||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
|
||||||
# Flags to debug and have the dependences (can be removed for correction)
|
|
||||||
CXXFLAGS += -MMD -g3
|
|
||||||
# Flag to debug (TO REMOVE)
|
|
||||||
# CXXFLAGS += -D DEBUG=1
|
|
||||||
# Sources
|
|
||||||
SRC = Fixed.cpp \
|
|
||||||
main.cpp
|
|
||||||
|
|
||||||
# Objects
|
|
||||||
OBJDIRNAME = ./build
|
|
||||||
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o))
|
|
||||||
|
|
||||||
# Colors
|
|
||||||
GREEN = \033[32m
|
|
||||||
GREY = \033[0;90m
|
|
||||||
RED = \033[0;31m
|
|
||||||
GOLD = \033[38;5;220m
|
|
||||||
END = \033[0m
|
|
||||||
|
|
||||||
# Rules
|
|
||||||
|
|
||||||
# All (make all)
|
|
||||||
all: header $(NAME) footer
|
|
||||||
|
|
||||||
# Bonus (make bonus)
|
|
||||||
bonus: header $(OBJ) footer
|
|
||||||
@mkdir -p $(OBJDIRNAME)
|
|
||||||
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
|
|
||||||
@$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ)
|
|
||||||
|
|
||||||
# Clean (make clean)
|
|
||||||
clean:
|
|
||||||
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'
|
|
||||||
@printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n'
|
|
||||||
@$(RM) $(OBJDIRNAME)
|
|
||||||
|
|
||||||
# Clean (make fclean)
|
|
||||||
fclean: clean
|
|
||||||
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
|
|
||||||
@$(RM) $(NAME)
|
|
||||||
@echo ""
|
|
||||||
|
|
||||||
# Restart (make re)
|
|
||||||
re: header fclean all
|
|
||||||
|
|
||||||
# Dependences for all
|
|
||||||
$(NAME): $(OBJ)
|
|
||||||
@mkdir -p $(OBJDIRNAME)
|
|
||||||
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
|
|
||||||
@$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ)
|
|
||||||
|
|
||||||
# Creating the objects
|
|
||||||
$(OBJDIRNAME)/%.o: %.cpp
|
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
|
|
||||||
@$(CXX) $(CXXFLAGS) -o $@ -c $<
|
|
||||||
|
|
||||||
# Header
|
|
||||||
header:
|
|
||||||
@clear
|
|
||||||
@printf '\n\n'
|
|
||||||
@printf '$(GOLD) ******* ****** ******* $(END)\n'
|
|
||||||
@printf '$(GOLD) ****** *** ******* $(END)\n'
|
|
||||||
@printf '$(GOLD) ******* * ******* $(END)\n'
|
|
||||||
@printf '$(GOLD) ****** ******* $(END)\n'
|
|
||||||
@printf '$(GOLD) ******* ******* $(END)\n'
|
|
||||||
@printf '$(GOLD) ******************* ******* * $(END)\n'
|
|
||||||
@printf '$(GOLD) ******************* ******* *** $(END)\n'
|
|
||||||
@printf '$(GOLD) ****** ******* ****** $(END)\n'
|
|
||||||
@printf '$(GOLD) ****** $(END)\n'
|
|
||||||
@printf '$(GOLD) ****** $(END)\n'
|
|
||||||
@printf '$(GREY) Made by rparodi$(END)\n\n'
|
|
||||||
|
|
||||||
# Footer
|
|
||||||
footer:
|
|
||||||
@printf "\n"
|
|
||||||
@printf "$(GOLD) ,_ _,$(END)\n"
|
|
||||||
@printf "$(GOLD) | \\___//|$(END)\n"
|
|
||||||
@printf "$(GOLD) |=6 6=|$(END)\n"
|
|
||||||
@printf "$(GOLD) \\=._Y_.=/$(END)\n"
|
|
||||||
@printf "$(GOLD) ) \` ( ,$(END)\n"
|
|
||||||
@printf "$(GOLD) / \\ (('$(END)\n"
|
|
||||||
@printf "$(GOLD) | | ))$(END)\n"
|
|
||||||
@printf "$(GOLD) /| | | |\\_//$(END)\n"
|
|
||||||
@printf "$(GOLD) \\| |._.| |/-\`$(END)\n"
|
|
||||||
@printf "$(GOLD) '\"' '\"'$(END)\n"
|
|
||||||
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
|
|
||||||
|
|
||||||
clangd:
|
|
||||||
@echo \
|
|
||||||
"CompileFlags:\n" \
|
|
||||||
" Add:\n" \
|
|
||||||
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \
|
|
||||||
" - \"-I"$(shell pwd)"/includes\"\n" \
|
|
||||||
" - \"-xc++\"\n" \
|
|
||||||
> .clangd
|
|
||||||
|
|
||||||
# Phony
|
|
||||||
.PHONY: all bonus clean fclean re clangd
|
|
||||||
-include ${OBJ:.o=.d}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.cpp :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/12/23 14:41:58 by rparodi #+# #+# */
|
|
||||||
/* Updated: 2024/12/27 13:33:43 by rparodi ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "Fixed.hpp"
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
int main( void ) {
|
|
||||||
Fixed a;
|
|
||||||
Fixed const b( 10 );
|
|
||||||
Fixed const c( 42.42f );
|
|
||||||
Fixed const d( b );
|
|
||||||
|
|
||||||
a = Fixed( 1234.4321f );
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "a is " << a << std::endl;
|
|
||||||
std::cout << "b is " << b << std::endl;
|
|
||||||
std::cout << "c is " << c << std::endl;
|
|
||||||
std::cout << "d is " << d << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "a is " << a.toInt() << " as integer" << std::endl;
|
|
||||||
std::cout << "b is " << b.toInt() << " as integer" << std::endl;
|
|
||||||
std::cout << "c is " << c.toInt() << " as integer" << std::endl;
|
|
||||||
std::cout << "d is " << d.toInt() << " as integer" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "a is " << a.toFloat() << " as float" << std::endl;
|
|
||||||
std::cout << "b is " << b.toFloat() << " as float" << std::endl;
|
|
||||||
std::cout << "c is " << c.toFloat() << " as float" << std::endl;
|
|
||||||
std::cout << "d is " << d.toFloat() << " as float" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "a is " << a.getRawBits() << " as raw" << std::endl;
|
|
||||||
std::cout << "b is " << b.getRawBits() << " as raw" << std::endl;
|
|
||||||
std::cout << "c is " << c.getRawBits() << " as raw" << std::endl;
|
|
||||||
std::cout << "d is " << d.getRawBits() << " as raw" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue