llvm-mos-sdk
fixed_point.h
Go to the documentation of this file.
1 // Copyright 2024 LLVM-MOS Project
2 // Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3 // See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4 // information.
5 
6 #ifndef _FIXED_POINT_H
7 #define _FIXED_POINT_H
8 
9 #include <cstdint>
10 #include <limits.h>
11 #include <stdio.h>
12 #include <type_traits>
13 
14 #if __cplusplus >= 202002L
15 #define __fp_consteval consteval
16 #else
17 #define __fp_consteval constexpr
18 #endif
19 
47 template <intmax_t IntSize, intmax_t FracSize, bool Signed = true>
48 class FixedPoint;
49 
50 template <intmax_t IntSize, intmax_t FracSize, bool Signed> class FixedPoint {
51  static __fp_consteval auto bytesForBits(intmax_t v) { return ((v + 7) / 8); }
52  static constexpr auto storage_size = bytesForBits(IntSize + FracSize) * 8;
53 
54  // The result type for binary operations, similar to the C integer rules. The
55  // larger of the integer and fractional sizes are used. If the integer sizes
56  // differ, has the signedness of the larger. Otherwise, signed iff both
57  // are signed.
58  template <intmax_t OI, intmax_t OF, bool S>
59  using BinaryResultT =
60  FixedPoint<(OI > IntSize ? OI : IntSize), (OF > FracSize ? OF : FracSize),
61  (OI > IntSize ? S
62  : OI < IntSize ? Signed
63  : S && Signed)>;
64 
65 public:
66  using IntType =
67  std::conditional_t<Signed, _BitInt(IntSize), unsigned _BitInt(IntSize)>;
68  using FracType = unsigned _BitInt(FracSize);
69  using StorageType = std::conditional_t<Signed, _BitInt(storage_size),
70  unsigned _BitInt(storage_size)>;
71 
72 private:
73  // Underlying storage for the type
74  union {
76  struct {
77  FracType f : FracSize;
78  IntType i : IntSize;
79  };
80  };
81 
82 public:
83  // Constructors
84  template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
85  [[clang::always_inline]] constexpr FixedPoint(T i)
86  : val((StorageType)i << FracSize) {}
87 
89  [[clang::always_inline]] constexpr FixedPoint(IntType i, FracType f)
90  : val((StorageType)i << FracSize | f) {}
91 
92  [[clang::always_inline]] constexpr FixedPoint(const FixedPoint &o)
93  : val(o.val) {}
94  [[clang::always_inline]] constexpr FixedPoint &operator=(FixedPoint o) {
95  val = o.val;
96  return *this;
97  }
98 
103  template <typename T,
104  std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
105  [[clang::always_inline]] __fp_consteval explicit FixedPoint(T f) {
106  set(f * ((StorageType)1 << FracSize));
107  }
108 
109  // Implicit conversion. Like C/C++ integers, silently truncate on conversion
110  // to a smaller type.
111  template <intmax_t OI, intmax_t OF, bool S>
112  [[clang::always_inline]] constexpr FixedPoint(FixedPoint<OI, OF, S> o) {
113  if constexpr (FracSize > OF)
114  *this = FixedPoint(o.as_i(), (FracType)o.as_f() << (FracSize - OF));
115  else
116  *this = FixedPoint(o.as_i(), o.as_f() >> (OF - FracSize));
117  }
118 
119  // Direct value accessor and setter methods
120 
122  [[clang::always_inline]] constexpr IntType as_i() const { return i; }
124  [[clang::always_inline]] constexpr FracType as_f() const { return f; }
126  [[clang::always_inline]] constexpr StorageType get() const { return val; }
128  [[clang::always_inline]] constexpr void set_i(IntType value) { i = value; }
130  [[clang::always_inline]] constexpr void set_f(FracType value) { f = value; }
132  [[clang::always_inline]] constexpr void set(StorageType value) {
133  val = value;
134  }
135 
139  template <intmax_t OI, intmax_t OF, bool S = true>
140  [[clang::always_inline]] constexpr FixedPoint<OI, OF, S> as() {
141  return FixedPoint<OI, OF, S>(*this);
142  }
143 
144  [[clang::always_inline]] constexpr bool is_signed() const { return Signed; }
145  [[clang::always_inline]] constexpr intmax_t bitcount() const {
146  return IntSize + FracSize;
147  }
148  [[clang::always_inline]] constexpr intmax_t int_bitcount() const {
149  return IntSize;
150  }
151  [[clang::always_inline]] constexpr intmax_t frac_bitcount() const {
152  return FracSize;
153  }
154 
155  // Operator overloads
156 
157  // Unary operators
158  [[clang::always_inline]] constexpr FixedPoint operator-() const {
159  FixedPoint n = *this;
160  n.set(-n.get());
161  return n;
162  }
163  [[clang::always_inline]] constexpr FixedPoint operator~() const {
164  FixedPoint n = *this;
165  n.set(~n.get());
166  return n;
167  }
168 
169  // Bitwise operators
170  [[clang::always_inline]] constexpr FixedPoint &operator%=(FixedPoint o) {
171  val %= o.val;
172  return *this;
173  }
174  [[clang::always_inline]] constexpr FixedPoint operator%(FixedPoint o) const {
175  FixedPoint n = *this;
176  n %= o;
177  return n;
178  }
179  [[clang::always_inline]] constexpr FixedPoint &operator&=(FixedPoint o) {
180  val &= o.val;
181  return *this;
182  }
183  [[clang::always_inline]] constexpr FixedPoint operator&(FixedPoint o) const {
184  FixedPoint n = *this;
185  n &= o;
186  return n;
187  }
188  [[clang::always_inline]] constexpr FixedPoint &operator|=(FixedPoint o) {
189  val |= o.val;
190  return *this;
191  }
192  [[clang::always_inline]] constexpr FixedPoint operator|(FixedPoint o) const {
193  FixedPoint n = *this;
194  n |= o;
195  return n;
196  }
197  [[clang::always_inline]] constexpr FixedPoint &operator^=(FixedPoint o) {
198  val ^= o.val;
199  return *this;
200  }
201  [[clang::always_inline]] constexpr FixedPoint operator^(FixedPoint o) const {
202  FixedPoint n = *this;
203  n ^= o;
204  return n;
205  }
206 
207  // Arithimetic operators for same sized types
208  [[clang::always_inline]] constexpr FixedPoint &operator+=(FixedPoint o) {
209  val += o.val;
210  return *this;
211  }
212  [[clang::always_inline]] constexpr FixedPoint operator+(FixedPoint o) const {
213  FixedPoint n = *this;
214  n += o;
215  return n;
216  }
217 
218  [[clang::always_inline]] constexpr FixedPoint &operator-=(FixedPoint o) {
219  val -= o.val;
220  return *this;
221  }
222  [[clang::always_inline]] constexpr FixedPoint operator-(FixedPoint o) const {
223  FixedPoint n = *this;
224  n -= o;
225  return n;
226  }
227 
228  [[clang::always_inline]] constexpr FixedPoint &operator/=(FixedPoint o) {
229  val /= o.get();
230  return *this;
231  }
232  [[clang::always_inline]] constexpr FixedPoint operator/(FixedPoint o) const {
233  FixedPoint n = *this;
234  n /= o;
235  return n;
236  }
237 
238  [[clang::always_inline]] constexpr FixedPoint &operator*=(FixedPoint o) {
239  // Fixed point mult is (n * m / FracSize)
240  // Expand the immediate value before multiplying
243  // Truncate the final result to fit inside our value
244  val = (temp.get() * other.get()) >> FracSize;
245  return *this;
246  }
247  [[clang::always_inline]] constexpr FixedPoint operator*(FixedPoint o) const {
248  FixedPoint n = *this;
249  n *= o;
250  return n;
251  }
252 
253  [[clang::always_inline]] constexpr FixedPoint &operator>>=(StorageType v) {
254  val >>= v;
255  return *this;
256  }
257  [[clang::always_inline]] constexpr FixedPoint
259  FixedPoint n = *this;
260  n >>= v;
261  return n;
262  }
263 
264  [[clang::always_inline]] constexpr FixedPoint &operator<<=(StorageType v) {
265  val <<= v;
266  return *this;
267  }
268  [[clang::always_inline]] constexpr FixedPoint
270  FixedPoint n = *this;
271  n <<= v;
272  return n;
273  }
274 
275  [[clang::always_inline]] FixedPoint &operator++() {
276  i += 1;
277  return *this;
278  }
279  [[clang::always_inline]] FixedPoint operator++(int) {
280  FixedPoint old = *this;
281  ++*this;
282  return old;
283  }
284 
285  template <intmax_t OI, intmax_t OF, bool S>
286  [[clang::always_inline]] constexpr auto
288  BinaryResultT<OI, OF, S> l = *this;
290  l += r;
291  return l;
292  }
293  template <intmax_t OI, intmax_t OF, bool S>
294  [[clang::always_inline]] constexpr FixedPoint &
296  *this = *this + o;
297  return *this;
298  }
299 
300  template <intmax_t OI, intmax_t OF, bool S>
301  [[clang::always_inline]] constexpr auto
303  BinaryResultT<OI, OF, S> l = *this;
305  l -= r;
306  return l;
307  }
308  template <intmax_t OI, intmax_t OF, bool S>
309  [[clang::always_inline]] constexpr FixedPoint &
311  *this = *this - o;
312  return *this;
313  }
314  template <intmax_t OI, intmax_t OF, bool S>
315  [[clang::always_inline]] constexpr auto
317  BinaryResultT<OI, OF, S> l = *this;
319  l %= r;
320  return l;
321  }
322  template <intmax_t OI, intmax_t OF, bool S>
323  [[clang::always_inline]] constexpr FixedPoint &
325  *this = *this % o;
326  return *this;
327  }
328  template <intmax_t OI, intmax_t OF, bool S>
329  [[clang::always_inline]] constexpr auto
331  BinaryResultT<OI, OF, S> l = *this;
333  l ^= r;
334  return l;
335  }
336  template <intmax_t OI, intmax_t OF, bool S>
337  [[clang::always_inline]] constexpr FixedPoint &
339  *this = *this ^ o;
340  return *this;
341  }
342  template <intmax_t OI, intmax_t OF, bool S>
343  [[clang::always_inline]] constexpr auto
345  BinaryResultT<OI, OF, S> l = *this;
347  l &= r;
348  return l;
349  }
350  template <intmax_t OI, intmax_t OF, bool S>
351  [[clang::always_inline]] constexpr FixedPoint &
353  *this = *this & o;
354  return *this;
355  }
356  template <intmax_t OI, intmax_t OF, bool S>
357  [[clang::always_inline]] constexpr auto
359  BinaryResultT<OI, OF, S> l = *this;
361  l |= r;
362  return l;
363  }
364  template <intmax_t OI, intmax_t OF, bool S>
365  [[clang::always_inline]] constexpr FixedPoint &
367  *this = *this | o;
368  return *this;
369  }
370 
371  template <intmax_t OI, intmax_t OF, bool S>
372  [[clang::always_inline]] constexpr auto
374  BinaryResultT<OI, OF, S> l = *this;
376  return l * r;
377  }
378  template <intmax_t OI, intmax_t OF, bool S>
379  [[clang::always_inline]] constexpr FixedPoint &
381  *this = *this * o;
382  return *this;
383  }
384 
385  // Comparison overloads
386  [[clang::always_inline]] constexpr bool
387  operator==(const FixedPoint &o) const noexcept {
388  return val == o.val;
389  }
390  [[clang::always_inline]] constexpr bool
391  operator<(const FixedPoint &o) const noexcept {
392  return val < o.val;
393  }
394  [[clang::always_inline]] constexpr bool
395  operator!=(const FixedPoint &o) const noexcept {
396  return val != o.val;
397  }
398  [[clang::always_inline]] constexpr bool
399  operator>(const FixedPoint &o) const noexcept {
400  return val > o.val;
401  }
402  [[clang::always_inline]] constexpr bool
403  operator>=(const FixedPoint &o) const noexcept {
404  return val >= o.val;
405  }
406  [[clang::always_inline]] constexpr bool
407  operator<=(const FixedPoint &o) const noexcept {
408  return val <= o.val;
409  }
410  template <intmax_t OI, intmax_t OF, bool S>
411  [[clang::always_inline]] constexpr auto
412  operator==(FixedPoint<OI, OF, S> o) const noexcept {
413  BinaryResultT<OI, OF, S> l = *this;
415  return l == r;
416  }
417  template <intmax_t OI, intmax_t OF, bool S>
418  [[clang::always_inline]] constexpr auto
419  operator<(FixedPoint<OI, OF, S> o) const noexcept {
420  BinaryResultT<OI, OF, S> l = *this;
422  return l < r;
423  }
424  template <intmax_t OI, intmax_t OF, bool S>
425  [[clang::always_inline]] constexpr auto
426  operator!=(FixedPoint<OI, OF, S> o) const noexcept {
427  BinaryResultT<OI, OF, S> l = *this;
429  return l != r;
430  }
431  template <intmax_t OI, intmax_t OF, bool S>
432  [[clang::always_inline]] constexpr auto
433  operator>(FixedPoint<OI, OF, S> o) const noexcept {
434  BinaryResultT<OI, OF, S> l = *this;
436  return l > r;
437  }
438  template <intmax_t OI, intmax_t OF, bool S>
439  [[clang::always_inline]] constexpr auto
440  operator>=(FixedPoint<OI, OF, S> o) const noexcept {
441  BinaryResultT<OI, OF, S> l = *this;
443  return l >= r;
444  }
445  template <intmax_t OI, intmax_t OF, bool S>
446  [[clang::always_inline]] constexpr auto
447  operator<=(FixedPoint<OI, OF, S> o) const noexcept {
448  BinaryResultT<OI, OF, S> l = *this;
450  return l <= r;
451  }
452 };
453 
463 
471 
479 
480 using f8_8 = fs8_8;
481 using f12_4 = fs12_4;
482 using f16_8 = fs16_8;
483 using f8_16 = fs8_16;
484 using f12_12 = fs12_12;
485 using f16_16 = fs16_16;
486 using f24_8 = fs24_8;
487 
488 [[clang::always_inline]] __fp_consteval fs8_8
489 operator""_s8_8(long double fixed) {
490  return FixedPoint<8, 8, true>{fixed};
491 }
492 [[clang::always_inline]] __fp_consteval fs12_4
493 operator""_s12_4(long double fixed) {
494  return FixedPoint<12, 4, true>{fixed};
495 }
496 [[clang::always_inline]] __fp_consteval fs16_8
497 operator""_s16_8(long double fixed) {
498  return FixedPoint<16, 8, true>{fixed};
499 }
500 [[clang::always_inline]] __fp_consteval fs8_16
501 operator""_s8_16(long double fixed) {
502  return FixedPoint<8, 16, true>{fixed};
503 }
504 [[clang::always_inline]] __fp_consteval fs12_12
505 operator""_s12_12(long double fixed) {
506  return FixedPoint<12, 12, true>{fixed};
507 }
508 [[clang::always_inline]] __fp_consteval fs16_16
509 operator""_s16_16(long double fixed) {
510  return FixedPoint<16, 16, true>{fixed};
511 }
512 [[clang::always_inline]] __fp_consteval fs24_8
513 operator""_s24_8(long double fixed) {
514  return FixedPoint<24, 8, true>{fixed};
515 }
516 
517 [[clang::always_inline]] __fp_consteval fu8_8
518 operator""_u8_8(long double fixed) {
519  return FixedPoint<8, 8, false>{fixed};
520 }
521 [[clang::always_inline]] __fp_consteval fu12_4
522 operator""_u12_4(long double fixed) {
523  return FixedPoint<12, 4, false>{fixed};
524 }
525 [[clang::always_inline]] __fp_consteval fu16_8
526 operator""_u16_8(long double fixed) {
527  return FixedPoint<16, 8, false>{fixed};
528 }
529 [[clang::always_inline]] __fp_consteval fu8_16
530 operator""_u8_16(long double fixed) {
531  return FixedPoint<8, 16, false>{fixed};
532 }
533 [[clang::always_inline]] __fp_consteval fu12_12
534 operator""_u12_12(long double fixed) {
535  return FixedPoint<12, 12, false>{fixed};
536 }
537 [[clang::always_inline]] __fp_consteval fu16_16
538 operator""_u16_16(long double fixed) {
539  return FixedPoint<16, 16, false>{fixed};
540 }
541 [[clang::always_inline]] __fp_consteval fu24_8
542 operator""_u24_8(long double fixed) {
543  return FixedPoint<24, 8, false>{fixed};
544 }
545 
546 [[clang::always_inline]] __fp_consteval fs8_8
547 operator""_8_8(long double fixed) {
548  return FixedPoint<8, 8, true>{fixed};
549 }
550 [[clang::always_inline]] __fp_consteval fs12_4
551 operator""_12_4(long double fixed) {
552  return FixedPoint<12, 4, true>{fixed};
553 }
554 [[clang::always_inline]] __fp_consteval fs16_8
555 operator""_16_8(long double fixed) {
556  return FixedPoint<16, 8, true>{fixed};
557 }
558 [[clang::always_inline]] __fp_consteval fs8_16
559 operator""_8_16(long double fixed) {
560  return FixedPoint<8, 16, true>{fixed};
561 }
562 [[clang::always_inline]] __fp_consteval fs12_12
563 operator""_12_12(long double fixed) {
564  return FixedPoint<12, 12, true>{fixed};
565 }
566 [[clang::always_inline]] __fp_consteval fs16_16
567 operator""_16_16(long double fixed) {
568  return FixedPoint<16, 16, true>{fixed};
569 }
570 [[clang::always_inline]] __fp_consteval fs24_8
571 operator""_24_8(long double fixed) {
572  return FixedPoint<24, 8, true>{fixed};
573 }
574 } // namespace fixedpoint_literals
575 
576 #endif // _FIXED_POINT_H
FixedPoint::operator/=
constexpr FixedPoint & operator/=(FixedPoint o)
Definition: fixed_point.h:228
FixedPoint::operator^
constexpr FixedPoint operator^(FixedPoint o) const
Definition: fixed_point.h:201
FixedPoint::operator/
constexpr FixedPoint operator/(FixedPoint o) const
Definition: fixed_point.h:232
FixedPoint::operator+
constexpr FixedPoint operator+(FixedPoint o) const
Definition: fixed_point.h:212
FixedPoint::operator&
constexpr auto operator&(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:344
FixedPoint::operator&=
constexpr FixedPoint & operator&=(FixedPoint o)
Definition: fixed_point.h:179
FixedPoint::as_f
constexpr FracType as_f() const
Returns just the fractional portion.
Definition: fixed_point.h:124
type_traits
FixedPoint::operator&
constexpr FixedPoint operator&(FixedPoint o) const
Definition: fixed_point.h:183
FixedPoint::frac_bitcount
constexpr intmax_t frac_bitcount() const
Definition: fixed_point.h:151
FixedPoint::FixedPoint
constexpr FixedPoint(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:112
FixedPoint::FixedPoint
constexpr FixedPoint(T i)
Definition: fixed_point.h:85
FixedPoint::operator^
constexpr auto operator^(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:330
FixedPoint::operator&=
constexpr FixedPoint & operator&=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:352
FixedPoint::set_f
constexpr void set_f(FracType value)
Update just the fractional portion.
Definition: fixed_point.h:130
fixedpoint_literals::fs16_16
FixedPoint< 16, 16, true > fs16_16
Definition: fixed_point.h:469
fixedpoint_literals::fu16_8
FixedPoint< 16, 8, false > fu16_8
Definition: fixed_point.h:474
FixedPoint::i
IntType i
Definition: fixed_point.h:78
FixedPoint::operator*
constexpr FixedPoint operator*(FixedPoint o) const
Definition: fixed_point.h:247
FixedPoint::operator>
constexpr auto operator>(FixedPoint< OI, OF, S > o) const noexcept
Definition: fixed_point.h:433
FixedPoint::operator>=
constexpr bool operator>=(const FixedPoint &o) const noexcept
Definition: fixed_point.h:403
fixedpoint_literals::fu8_16
FixedPoint< 8, 16, false > fu8_16
Definition: fixed_point.h:475
FixedPoint::operator>
constexpr bool operator>(const FixedPoint &o) const noexcept
Definition: fixed_point.h:399
FixedPoint::operator|
constexpr auto operator|(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:358
FixedPoint::operator<<=
constexpr FixedPoint & operator<<=(StorageType v)
Definition: fixed_point.h:264
FixedPoint::operator-=
constexpr FixedPoint & operator-=(FixedPoint o)
Definition: fixed_point.h:218
FixedPoint::set_i
constexpr void set_i(IntType value)
Update just the integral portion.
Definition: fixed_point.h:128
FixedPoint::operator+
constexpr auto operator+(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:287
FixedPoint::operator+=
constexpr FixedPoint & operator+=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:295
FixedPoint::operator>=
constexpr auto operator>=(FixedPoint< OI, OF, S > o) const noexcept
Definition: fixed_point.h:440
fixedpoint_literals::fs12_12
FixedPoint< 12, 12, true > fs12_12
Definition: fixed_point.h:468
FixedPoint::as
constexpr FixedPoint< OI, OF, S > as()
Definition: fixed_point.h:140
FixedPoint::operator-
constexpr FixedPoint operator-() const
Definition: fixed_point.h:158
FixedPoint::operator-
constexpr auto operator-(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:302
FixedPoint::f
FracType f
Definition: fixed_point.h:77
FixedPoint::operator<=
constexpr bool operator<=(const FixedPoint &o) const noexcept
Definition: fixed_point.h:407
FixedPoint::operator-
constexpr FixedPoint operator-(FixedPoint o) const
Definition: fixed_point.h:222
FixedPoint::operator>>=
constexpr FixedPoint & operator>>=(StorageType v)
Definition: fixed_point.h:253
FixedPoint::operator==
constexpr bool operator==(const FixedPoint &o) const noexcept
Definition: fixed_point.h:387
FixedPoint::FixedPoint
constexpr FixedPoint(IntType i, FracType f)
Constructor for setting both the integral and fractional part.
Definition: fixed_point.h:89
FixedPoint::operator++
FixedPoint & operator++()
Definition: fixed_point.h:275
std::intmax_t
::intmax_t intmax_t
Definition: cstdint:19
FixedPoint::operator*=
constexpr FixedPoint & operator*=(FixedPoint o)
Definition: fixed_point.h:238
FixedPoint::bitcount
constexpr intmax_t bitcount() const
Definition: fixed_point.h:145
FixedPoint::operator-=
constexpr FixedPoint & operator-=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:310
fixedpoint_literals::fs16_8
FixedPoint< 16, 8, true > fs16_8
Definition: fixed_point.h:466
FixedPoint::operator==
constexpr auto operator==(FixedPoint< OI, OF, S > o) const noexcept
Definition: fixed_point.h:412
fixedpoint_literals::fs12_4
FixedPoint< 12, 4, true > fs12_4
Definition: fixed_point.h:465
FixedPoint::operator<<
constexpr FixedPoint operator<<(StorageType v) const
Definition: fixed_point.h:269
cstdint
stdio.h
fixedpoint_literals::fu24_8
FixedPoint< 24, 8, false > fu24_8
Definition: fixed_point.h:478
FixedPoint::operator^=
constexpr FixedPoint & operator^=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:338
FixedPoint::set
constexpr void set(StorageType value)
Update the entire value.
Definition: fixed_point.h:132
FixedPoint::operator%=
constexpr FixedPoint & operator%=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:324
FixedPoint::IntType
std::conditional_t< Signed, _BitInt(IntSize), unsigned _BitInt(IntSize)> IntType
Definition: fixed_point.h:67
FixedPoint::operator*=
constexpr FixedPoint & operator*=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:380
fixedpoint_literals::fs8_8
FixedPoint< 8, 8, true > fs8_8
Definition: fixed_point.h:464
FixedPoint::is_signed
constexpr bool is_signed() const
Definition: fixed_point.h:144
FixedPoint::operator+=
constexpr FixedPoint & operator+=(FixedPoint o)
Definition: fixed_point.h:208
fixedpoint_literals::fs24_8
FixedPoint< 24, 8, true > fs24_8
Definition: fixed_point.h:470
fixedpoint_literals::fs8_16
FixedPoint< 8, 16, true > fs8_16
Definition: fixed_point.h:467
fixedpoint_literals
Definition: fixed_point.h:462
fixedpoint_literals::fu12_12
FixedPoint< 12, 12, false > fu12_12
Definition: fixed_point.h:476
FixedPoint::as_i
constexpr IntType as_i() const
Returns just the integral portion.
Definition: fixed_point.h:122
FixedPoint::FracType
unsigned _BitInt(FracSize) FracType
Definition: fixed_point.h:68
FixedPoint::operator|=
constexpr FixedPoint & operator|=(FixedPoint< OI, OF, S > o)
Definition: fixed_point.h:366
std::conditional_t
typename conditional< B, T, F >::type conditional_t
Definition: type_traits:26
FixedPoint::operator%
constexpr auto operator%(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:316
fixedpoint_literals::fu16_16
FixedPoint< 16, 16, false > fu16_16
Definition: fixed_point.h:477
fixedpoint_literals::fu12_4
FixedPoint< 12, 4, false > fu12_4
Definition: fixed_point.h:473
FixedPoint::operator!=
constexpr bool operator!=(const FixedPoint &o) const noexcept
Definition: fixed_point.h:395
fixedpoint_literals::fu8_8
FixedPoint< 8, 8, false > fu8_8
Definition: fixed_point.h:472
FixedPoint::operator~
constexpr FixedPoint operator~() const
Definition: fixed_point.h:163
FixedPoint::operator=
constexpr FixedPoint & operator=(FixedPoint o)
Definition: fixed_point.h:94
FixedPoint
Definition: fixed_point.h:48
FixedPoint::operator^=
constexpr FixedPoint & operator^=(FixedPoint o)
Definition: fixed_point.h:197
FixedPoint::operator|
constexpr FixedPoint operator|(FixedPoint o) const
Definition: fixed_point.h:192
FixedPoint::FixedPoint
constexpr FixedPoint(const FixedPoint &o)
Definition: fixed_point.h:92
FixedPoint::operator|=
constexpr FixedPoint & operator|=(FixedPoint o)
Definition: fixed_point.h:188
FixedPoint::operator!=
constexpr auto operator!=(FixedPoint< OI, OF, S > o) const noexcept
Definition: fixed_point.h:426
FixedPoint::operator*
constexpr auto operator*(FixedPoint< OI, OF, S > o) const
Definition: fixed_point.h:373
FixedPoint::operator++
FixedPoint operator++(int)
Definition: fixed_point.h:279
FixedPoint::get
constexpr StorageType get() const
Returns the entire value.
Definition: fixed_point.h:126
FixedPoint::val
StorageType val
Definition: fixed_point.h:75
FixedPoint::operator>>
constexpr FixedPoint operator>>(StorageType v) const
Definition: fixed_point.h:258
FixedPoint::operator%
constexpr FixedPoint operator%(FixedPoint o) const
Definition: fixed_point.h:174
FixedPoint::int_bitcount
constexpr intmax_t int_bitcount() const
Definition: fixed_point.h:148
FixedPoint::StorageType
std::conditional_t< Signed, _BitInt(storage_size), unsigned _BitInt(storage_size)> StorageType
Definition: fixed_point.h:70
FixedPoint::operator<
constexpr bool operator<(const FixedPoint &o) const noexcept
Definition: fixed_point.h:391
FixedPoint::operator%=
constexpr FixedPoint & operator%=(FixedPoint o)
Definition: fixed_point.h:170