aboutsummaryrefslogtreecommitdiff
path: root/cpp02/ex01/Fixed.hpp
blob: 43edba230f82a4fa0c0b67d88e92a2854b6c2328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   Fixed.hpp                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/13 11:40:49 by charles           #+#    #+#             */
/*   Updated: 2020/11/10 10:02:06 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef FIXED_HPP
# define FIXED_HPP

# include <iostream>
# include <cmath>

class Fixed
{
public:
    Fixed();
    Fixed(Fixed const& other);
    ~Fixed();
    Fixed& operator=(Fixed const& other);

    Fixed(const int   from);
    Fixed(const float from);

    int   getRawBits() const;
    void  setRawBits(int const raw);

    float toFloat(void) const;  // void asked by subject
    int   toInt(void)   const;

    static int getFractionalBits();

private:
    int              m_value;
    static int const m_fractionalBits = 8;
};

std::ostream& operator<<(std::ostream& out, Fixed const& f);

#endif