CPP02 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Fixed.hpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* Fixed.hpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/04/28 17:17:18 by kamitsui #+# #+# */
9/* Updated: 2025/05/06 17:11:29 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
26#ifndef FIXED_HPP
27#define FIXED_HPP
28
29#include <iostream>
30
31class Fixed {
32 private:
33 int fixedPointValue;
34 static const int fractionalBits = 8;
35
36 public:
38 Fixed(const int raw);
39 Fixed(const float raw);
40 Fixed(const Fixed &other);
41 Fixed &operator=(const Fixed &other);
43
44 int getRawBits(void) const;
45 void setRawBits(int const raw);
46 float toFloat(void) const;
47 int toInt(void) const;
48
49 // Comparison operators
50 bool operator>(const Fixed &other) const;
51 bool operator<(const Fixed &other) const;
52 bool operator>=(const Fixed &other) const;
53 bool operator<=(const Fixed &other) const;
54 bool operator==(const Fixed &other) const;
55 bool operator!=(const Fixed &other) const;
56
57 // Arithmetic operators
58 Fixed operator+(const Fixed &other) const;
59 Fixed operator-(const Fixed &other) const;
60 Fixed operator*(const Fixed &other) const;
61 Fixed operator/(const Fixed &other) const;
62
63 // Increment/decrement operators
64 Fixed &operator++(); // Pre-increment
65 Fixed operator++(int); // Post-increment
66 Fixed &operator--(); // Pre-decrement
67 Fixed operator--(int); // Post-decrement
68
69 // Min/Max functions
70 static Fixed &min(Fixed &a, Fixed &b);
71 static const Fixed &min(const Fixed &a, const Fixed &b);
72 static Fixed &max(Fixed &a, Fixed &b);
73 static const Fixed &max(const Fixed &a, const Fixed &b);
74};
75
76std::ostream &operator<<(std::ostream &o, const Fixed &fixed);
77
78#endif
ex00 Fixed Class
Definition Fixed.hpp:28
int toInt(void) const
bool operator>=(const Fixed &other) const
int getRawBits(void) const
bool operator<(const Fixed &other) const
void setRawBits(int const raw)
static Fixed & min(Fixed &a, Fixed &b)
static const Fixed & min(const Fixed &a, const Fixed &b)
Fixed & operator--()
static Fixed & max(Fixed &a, Fixed &b)
Fixed operator/(const Fixed &other) const
Fixed(const Fixed &other)
bool operator<=(const Fixed &other) const
bool operator>(const Fixed &other) const
bool operator==(const Fixed &other) const
Fixed & operator=(const Fixed &other)
Fixed operator-(const Fixed &other) const
static const Fixed & max(const Fixed &a, const Fixed &b)
Fixed operator*(const Fixed &other) const
Fixed operator--(int)
Fixed & operator++()
Fixed operator+(const Fixed &other) const
float toFloat(void) const
Fixed(const int raw)
bool operator!=(const Fixed &other) const
Fixed(const float raw)
Fixed operator++(int)
std::ostream & operator<<(std::ostream &o, const Fixed &fixed)
Overloads the output stream operator to insert the float representation of the fixed-point number int...
Definition Fixed.cpp:113