Fixed.class.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Fixed.class.hpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@gmail.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/07/16 15:46:39 by bchanot #+# #+# */
  9. /* Updated: 2025/07/17 18:52:26 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #ifndef FIXED_CLASS_H
  13. # define FIXED_CLASS_H
  14. #include <iostream>
  15. class Fixed {
  16. public:
  17. Fixed(void);
  18. Fixed(Fixed const &src);
  19. Fixed(int const num);
  20. Fixed(float const num);
  21. ~Fixed(void);
  22. int getRawBits(void) const;
  23. void setRawBits(int const raw);
  24. float toFloat(void) const;
  25. int toInt(void) const;
  26. Fixed &operator=(Fixed const &rhs);
  27. bool operator!=(Fixed const &rhs) const;
  28. bool operator==(Fixed const &rhs) const;
  29. bool operator<=(Fixed const &rhs) const;
  30. bool operator>=(Fixed const &rhs) const;
  31. bool operator<(Fixed const &rhs) const;
  32. bool operator>(Fixed const &rhs) const;
  33. Fixed operator+(Fixed const &rhs) const;
  34. Fixed operator-(Fixed const &rhs) const;
  35. Fixed operator*(Fixed const &rhs) const;
  36. Fixed operator/(Fixed const &rhs) const;
  37. Fixed &operator++();
  38. Fixed &operator--();
  39. Fixed operator++(int);
  40. Fixed operator--(int);
  41. static const Fixed &min(Fixed const &left, Fixed const &right);
  42. static Fixed &min(Fixed &left, Fixed &right);
  43. static const Fixed &max(Fixed const &left, Fixed const &right);
  44. static Fixed &max(Fixed &left, Fixed &right);
  45. private:
  46. int _value;
  47. static int const _frac = 8;
  48. };
  49. std::ostream &operator<<(std::ostream &o, Fixed const &i);
  50. #endif