/ ex01 / Fixed.hpp
Fixed.hpp
 1  #include <iostream>
 2  
 3  class Fixed {
 4  private:
 5    int _value;
 6    static const int _fractionalBits = 8;
 7  
 8  public:
 9    Fixed();
10    Fixed(const Fixed &other);
11    Fixed(const int &other);
12    Fixed(const float &other);
13  
14    friend std::ostream &operator<<(std::ostream &os, const Fixed &obj);
15    float toFloat() const;
16  
17    // Accessors to extract the raw fixed-point integer and fractional bits
18    int getRawBits() const;
19    static int getFractionalBits();
20  
21    // Comparison operators
22    bool operator>(const Fixed &other) const;
23    bool operator<(const Fixed &other) const;
24    bool operator>=(const Fixed &other) const;
25    bool operator<=(const Fixed &other) const;
26    bool operator==(const Fixed &other) const;
27    bool operator!=(const Fixed &other) const;
28  
29    // Arithmetic operators
30    Fixed operator+(const Fixed &other) const;
31    Fixed operator-(const Fixed &other) const;
32    Fixed operator*(const Fixed &other) const;
33    Fixed operator/(const Fixed &other) const;
34  
35    // Increment and decrement operators
36    Fixed &operator++();   // Prefix increment
37    Fixed operator++(int); // Postfix increment
38    Fixed &operator--();   // Prefix decrement
39    Fixed operator--(int); // Postfix decrement
40  
41    // Min and max functions
42    static Fixed &min(Fixed &a, Fixed &b);
43    static const Fixed &min(const Fixed &a, const Fixed &b);
44    static Fixed &max(Fixed &a, Fixed &b);
45    static const Fixed &max(const Fixed &a, const Fixed &b);
46  
47    Fixed &operator=(const Fixed &other);
48    ~Fixed();
49  };