64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* :::::::: */
|
|
/* Fixed.hpp :+: :+: */
|
|
/* +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
|
/* +#+ */
|
|
/* Created: 2025/03/24 15:22:48 by whaffman #+# #+# */
|
|
/* Updated: 2025/04/04 12:16:48 by whaffman ######## odam.nl */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
|
|
#define DEBUG 0
|
|
|
|
class Fixed {
|
|
public:
|
|
Fixed();
|
|
Fixed(const int value);
|
|
Fixed(const float value);
|
|
Fixed(const Fixed &fixed);
|
|
~Fixed();
|
|
|
|
Fixed &operator=(const Fixed &fixed);
|
|
Fixed operator+(const Fixed &fixed) const;
|
|
Fixed operator-(const Fixed &fixed) const;
|
|
Fixed operator*(const Fixed &fixed) const;
|
|
Fixed operator/(const Fixed &fixed) const;
|
|
|
|
Fixed &operator++();
|
|
Fixed operator++(int);
|
|
Fixed &operator--();
|
|
Fixed operator--(int);
|
|
|
|
bool operator>(const Fixed &fixed) const;
|
|
bool operator<(const Fixed &fixed) const;
|
|
bool operator>=(const Fixed &fixed) const;
|
|
bool operator<=(const Fixed &fixed) const;
|
|
bool operator==(const Fixed &fixed) const;
|
|
bool operator!=(const Fixed &fixed) const;
|
|
|
|
static Fixed &min(Fixed &a, Fixed &b);
|
|
static const Fixed &min(const Fixed &a, const Fixed &b);
|
|
static Fixed &max(Fixed &a, Fixed &b);
|
|
static const Fixed &max(const Fixed &a, const Fixed &b);
|
|
|
|
int getRawBits(void) const;
|
|
void setRawBits(int const raw);
|
|
float toFloat(void) const;
|
|
int toInt(void) const;
|
|
|
|
|
|
private:
|
|
int fixedPointValue;
|
|
static const int fractionalBits;
|
|
};
|
|
|
|
std::ostream &operator<<(std::ostream &out, const Fixed &fixed);
|
|
|
|
|