#ifndef FIXEDINT_H
#define FIXEDINT_H

#include <stdint.h>

#include <ostream>
using namespace std;

//implementing a simple Fixed Point math library.
//24:8 so it has 8 bits before and after the exclamation point.
//IMPORTANT: There is NO overflow checking in here!

int intSqrt (int);

class FixedInt {
 public:
  FixedInt ();
  ~FixedInt ();
  FixedInt (int);
  FixedInt (double);
  FixedInt (const FixedInt &);

  int rawValue() const;
  int toInt() const;
  float toFloat() const;

  bool operator == (const FixedInt & rhs);
  FixedInt & operator = (const FixedInt & rhs);

  FixedInt operator + (const FixedInt & rhs);
  FixedInt operator * (const FixedInt & rhs);
  FixedInt operator - (const FixedInt & rhs);
  FixedInt operator / (const FixedInt & rhs);
  FixedInt operator % (const FixedInt & rhs);

  void operator += (const FixedInt & rhs);
  void operator *= (const FixedInt & rhs);
  void operator -= (const FixedInt & rhs);
  void operator /= (const FixedInt & rhs);
  void operator %= (const FixedInt & rhs);

  bool operator == (const int & rhs);
  bool operator < (const int & rhs);
  bool operator > (const int & rhs);
  bool operator >= (const int & rhs);
  bool operator <= (const int & rhs);

  void sqrt();

  friend ostream & operator<< (ostream & os, const FixedInt & rhs);

  //returns an integer between 0 and 255 via modding.
  uint8_t toAngle();

 private:
  int32_t value;
};

const FixedInt fixSqrt(FixedInt);
#endif
