4#include <AH/STL/cstdint>
5#include <AH/STL/limits>
6#include <AH/STL/type_traits>
63template <
class T, u
int8_t N,
class T2 = DoubleW
idthInt_t<T>>
67 constexpr static T
one = 1 << N;
95 return raw(
static_cast<T
>(
96 static_cast<typename std::make_unsigned<T>::type
>(this->
val) +
97 static_cast<typename std::make_unsigned<T>::type
>(rhs.
val)));
121 return raw(T2(this->
val) * one / rhs.
val);
126 static_assert(std::is_unsigned<T2>::value || (-97 * 2) >> 1 == -97,
127 "Negative signed right shift incorrect");
128 int neg =
val < 0 ? 1 : 0;
129 return (
val + (1 << (N - 1)) - neg) >> N;
132 explicit operator long double()
const {
return (
long double)
val /
one; }
133 explicit operator double()
const {
return (
double)
val /
one; }
134 explicit operator float()
const {
return (
float)
val /
one; }
141template <
class T, u
int8_t N,
class T2>
147template <
class T, u
int8_t N,
class T2>
157template <
class T,
class T2, u
int8_t N>
159 return os << double(fp);
167template <
class T, u
int8_t N,
class T2>
169 return os << double(fp);
Very basic fixed-point integer implementation.
FixedPoint()
Default constructor.
FixedPoint operator/(FixedPoint rhs) const
Division.
FixedPoint operator-() const
Invert.
FixedPoint operator+(FixedPoint rhs) const
Addition.
static constexpr T one
Fixed-point representation of the number one.
FixedPoint operator*(FixedPoint rhs) const
Multiplication.
static constexpr FixedPoint raw(T t)
Convert a raw integer representation to fixed point type.
FixedPoint(U f)
Initialize U from a numeric value.
static T div_N(T2 val)
Divide the given integer by .
FixedPoint operator-(FixedPoint rhs) const
Subtraction.
T2 operator*(T2 rhs) const
Multiplication with normal integer.
Array< decltype(T1{} *T2{}), N1 > operator*(ArraySlice< T1, N1, Reverse1, Const1 > a, T2 b)
Slice * Scalar.
typename DoubleWidthInt< T >::type DoubleWidthInt_t
Get the integer type that has twice the number of bits as the given type.
Print & operator<<(Print &os, Quaternion e)
Printing.