91 lines
2.0 KiB
C++
91 lines
2.0 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Fixed.hpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/09/10 00:54:53 by tigos #+# #+# */
|
|
/* Updated: 2025/09/10 22:01:18 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef FIXED_HPP
|
|
|
|
# define FIXED_HPP
|
|
|
|
# include <iostream>
|
|
# include <cmath>
|
|
|
|
class Fixed
|
|
{
|
|
private:
|
|
int value;
|
|
static const int fract = 8;
|
|
|
|
public:
|
|
// Default constructor
|
|
Fixed();
|
|
|
|
// Constructor with constant integer
|
|
Fixed(const int nb);
|
|
|
|
// Constructor with constant floating-point number
|
|
Fixed(const float nb);
|
|
|
|
// Copy constructor
|
|
Fixed(const Fixed &other);
|
|
|
|
// Copy assignment operator overload
|
|
Fixed& operator=(Fixed const &other);
|
|
|
|
// Destructor
|
|
~Fixed();
|
|
|
|
// getRawBits
|
|
int getRawBits( void ) const;
|
|
|
|
// setRawBits
|
|
void setRawBits( int const raw );
|
|
|
|
// toFloat
|
|
float toFloat( void ) const;
|
|
|
|
// toInt
|
|
int toInt( void ) const;
|
|
|
|
// · Comparison operators
|
|
bool operator<(const Fixed &other) const;
|
|
bool operator<=(const Fixed &other) const;
|
|
bool operator>(const Fixed &other) const;
|
|
bool operator>=(const Fixed &other) const;
|
|
bool operator==(const Fixed &other) const;
|
|
bool operator!=(const Fixed &other) const;
|
|
|
|
// · Arithmetic operators
|
|
Fixed operator+(Fixed const &other) const;
|
|
Fixed operator-(Fixed const &other) const;
|
|
Fixed operator*(Fixed const &other) const;
|
|
Fixed operator/(Fixed const &other) const;
|
|
|
|
// · Increments / decrements
|
|
|
|
Fixed& operator++();
|
|
Fixed operator++(int);
|
|
|
|
Fixed& operator--();
|
|
Fixed operator--(int);
|
|
|
|
// · Max and min
|
|
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);
|
|
|
|
};
|
|
|
|
// << operator overload
|
|
std::ostream& operator<<(std::ostream& os, Fixed const &other);
|
|
|
|
#endif |