diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-10-19 12:42:39 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-10-19 12:42:39 +0200 |
| commit | 60c4c5309af87480fb32f3815bc02031eff43e9b (patch) | |
| tree | 7e50e0728d320735ea3fbcf2ff10d2239acf97a1 /cpp02/ex02/Fixed.hpp | |
| parent | a3ff15046fa3d367ff7304dc9482e81597eb76b9 (diff) | |
| download | piscine_cpp-60c4c5309af87480fb32f3815bc02031eff43e9b.tar.gz piscine_cpp-60c4c5309af87480fb32f3815bc02031eff43e9b.tar.bz2 piscine_cpp-60c4c5309af87480fb32f3815bc02031eff43e9b.zip | |
Added cpp02/ex02
Diffstat (limited to 'cpp02/ex02/Fixed.hpp')
| -rw-r--r-- | cpp02/ex02/Fixed.hpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cpp02/ex02/Fixed.hpp b/cpp02/ex02/Fixed.hpp new file mode 100644 index 0000000..d839260 --- /dev/null +++ b/cpp02/ex02/Fixed.hpp @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:40:49 by charles #+# #+# */ +/* Updated: 2020/10/19 12:41:46 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FIXED_HPP +# define FIXED_HPP + +# include <iostream> +# include <cmath> + +class Fixed +{ +public: + Fixed(); + Fixed(Fixed const& other); + ~Fixed(); + Fixed& operator=(Fixed const& other); + + Fixed(const int from); + Fixed(const float from); + + int getRawBits() const; + void setRawBits(int const raw); + + float toFloat() const; + int toInt() const; + + Fixed operator+(Fixed const& other) const; + Fixed operator-(Fixed const& other) const; + Fixed operator*(Fixed const& other) const; + Fixed operator/(Fixed const& other) const; + + Fixed& operator++(); + Fixed& operator--(); + Fixed operator++(int); + Fixed operator--(int); + + bool operator<(Fixed const& other) const; + bool operator>(Fixed const& other) const; + bool operator<=(Fixed const& other) const; + bool operator>=(Fixed const& other) const; + bool operator==(Fixed const& other) const; + bool operator!=(Fixed const& other) const; + + static Fixed& max(Fixed& a, Fixed& b); + static Fixed& min(Fixed& a, Fixed& b); + static const Fixed& max(Fixed const& a, Fixed const& b); + static const Fixed& min(Fixed const& a, Fixed const& b); + + static int getFractionalBits(); + +private: + int m_value; + static int const m_fractionalBits = 8; +}; + +std::ostream& operator<<(std::ostream& out, Fixed const& f); + + + +#endif |
