Skip to content

Instantly share code, notes, and snippets.

@jgigault
Created June 18, 2015 20:54
Show Gist options
  • Save jgigault/07d5d0bc37e92f85a396 to your computer and use it in GitHub Desktop.
Save jgigault/07d5d0bc37e92f85a396 to your computer and use it in GitHub Desktop.

Revisions

  1. Jean-Michel Gigault renamed this gist Jun 18, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Jean-Michel Gigault created this gist Jun 18, 2015.
    51 changes: 51 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #ifndef FIXED_CLASS_HPP
    # define FIXED_CLASS_HPP

    # include <iostream>

    class Fixed
    {
    public:
    Fixed(void);
    ~Fixed(void);
    Fixed(Fixed const & src);
    Fixed(int const i);
    Fixed(float const i);
    Fixed & operator=(Fixed const & rhs);
    bool operator>(Fixed const & rhs);
    bool operator<(Fixed const & rhs);
    bool operator>=(Fixed const & rhs);
    bool operator<=(Fixed const & rhs);
    bool operator==(Fixed const & rhs);
    bool operator!=(Fixed const & rhs);
    Fixed operator+(Fixed const & rhs);
    Fixed operator-(Fixed const & rhs);
    Fixed operator*(Fixed const & rhs);
    Fixed operator/(Fixed const & rhs);
    Fixed & operator++(void);
    Fixed & operator--(void);
    Fixed operator++(int n);
    Fixed operator--(int n);
    int getRawBits(void) const;
    void setRawBits(int const raw);
    int toInt(void) const;
    float toFloat(void) const;
    static Fixed & min(Fixed & i, Fixed & j);
    static Fixed & max(Fixed & i, Fixed & j);
    static Fixed const & min(Fixed const & i, Fixed const & j);
    static Fixed const & max(Fixed const & i, Fixed const & j);

    static int pow(int const n, int p);
    static int rpow(int const n, int p);
    static float fpow(float const f, int p);
    static float rfpow(float const f, int p);

    private:
    int _value;
    static int const f = 8;
    static int const accuracy = 128;
    };

    std::ostream & operator<<(std::ostream & o, Fixed const & i);

    #endif