/*
* This file is part of libgim.
*
* libgim is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see .
*
* Copyright 2011-2014 Danny Robson
*/
#ifndef __UTIL_FIXED_HPP
#define __UTIL_FIXED_HPP
#include "types/bits.hpp"
#include
#include
namespace util {
template
class fixed {
public:
typedef typename std::conditional<
std::is_signed::value,
typename bits_type::sint,
typename bits_type::uint
>::type native_t;
typedef native_t integer_t;
fixed (double);
fixed (float);
fixed (native_t);
double to_double (void) const;
float to_float (void) const;
integer_t to_integer (void) const;
native_t to_native (void) const;
static fixed from_native (native_t);
static integer_t to_integer (native_t);
fixed& operator +=(const fixed);
fixed& operator -=(const fixed);
fixed& operator *=(const fixed);
fixed& operator /=(const fixed);
fixed operator +(const fixed) const;
fixed operator -(const fixed) const;
fixed operator *(const fixed) const;
fixed operator /(const fixed) const;
fixed& operator +=(integer_t);
fixed& operator -=(integer_t);
fixed& operator *=(integer_t);
fixed& operator /=(integer_t);
fixed operator +(integer_t) const;
fixed operator -(integer_t) const;
fixed operator *(integer_t) const;
fixed operator /(integer_t) const;
private:
fixed () = default;
native_t m_value;
};
template bool operator== (util::fixed, util::fixed);
template bool operator!= (util::fixed, util::fixed);
template bool operator< (util::fixed, util::fixed);
template bool operator<= (util::fixed, util::fixed);
template bool operator> (util::fixed, util::fixed);
template bool operator>= (util::fixed, util::fixed);
template
std::ostream& operator<< (std::ostream&, fixed);
}
#endif // __UTIL_FIXED_HPP