CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
FixedPoint.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
15
16#include <cmath>
17#include <limits>
18
19namespace CeresEngine::inline Math {
20
23 template<typename T = Int64, unsigned int P = 20> struct FixedPoint {
24 static_assert(P <= sizeof(T) * 8);
25
29
31 // NOLINTNEXTLINE(hicpp-signed-bitwise)
32 static const constexpr T one = T(1) << P;
33
35 T raw; // NOLINT(misc-non-private-member-variables-in-classes)
36
38 constexpr FixedPoint() = default;
39
43 constexpr explicit FixedPoint(T raw) noexcept : raw(raw) {}
44
46 constexpr FixedPoint(const FixedPoint&) = default;
47
50 constexpr FixedPoint& operator=(const FixedPoint&) = default;
51
54 constexpr FixedPoint( // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
55 float f) noexcept
56 : raw(static_cast<T>(f * one)) {}
57
60 [[nodiscard]] explicit constexpr operator float() const { return static_cast<float>(raw) / one; }
61
64 constexpr FixedPoint( // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
65 const double d) noexcept
66 : raw(static_cast<T>(d * double(one))) {}
67
70 [[nodiscard]] explicit constexpr operator double() const { return double(raw) / double(one); }
71
74 constexpr FixedPoint( // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
75 long double d) noexcept
76 : raw(static_cast<T>(d * one)) {}
77
80 [[nodiscard]] explicit constexpr operator long double() const { return static_cast<long double>(raw) / one; }
81
87 template<typename TT, unsigned int TP>
88 constexpr FixedPoint( // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
89 const FixedPoint<TT, TP>& other)
90 : raw(other.template convert<T, P>()) {}
91
92 template<typename TT, unsigned int TP> [[nodiscard]] TT convert() const {
93 if constexpr(TP > P) {
94 return static_cast<TT>(raw) << (TP - P);
95 } else {
96 return static_cast<TT>(raw) >> (P - TP);
97 }
98 }
99 };
100
103
106
109
112
115
121 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> operator-(const FixedPoint<T, P> a) noexcept {
122 return FixedPoint<T, P>(T(-a.raw));
123 }
124
130 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> operator+(const FixedPoint<T, P> a) noexcept { return a; }
131
138 template<typename T, unsigned int P>
139 [[nodiscard]] inline constexpr FixedPoint<T, P> operator+(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
140 return FixedPoint<T, P>(T(a.raw + b.raw));
141 }
142
149 template<typename T, unsigned int P>
150 [[nodiscard]] inline constexpr FixedPoint<T, P> operator-(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
151 return FixedPoint<T, P>(T(a.raw - b.raw));
152 }
153
160 template<typename T, unsigned int P>
161 [[nodiscard]] inline constexpr FixedPoint<T, P> operator*(const FixedPoint<T, P> x, const typename FixedPoint<T, P>::Self y) noexcept {
162 using UT = typename std::make_unsigned<T>::type;
163
164 constexpr size_t bits = sizeof(T) * 8;
165 constexpr size_t halfBits = bits / 2;
166 constexpr UT halfMask = (UT(1) << (4 * sizeof(T))) - UT(1);
167
168 UT a = UT(x.raw) >> halfBits;
169 UT b = UT(x.raw) & halfMask;
170 UT c = UT(y.raw) >> halfBits;
171 UT d = UT(y.raw) & halfMask;
172
173 UT ac = a * c;
174 UT bc = b * c;
175 UT ad = a * d;
176 UT bd = b * d;
177
178 UT mid34 = (bd >> halfBits) + (bc & halfMask) + (ad & halfMask);
179
180 UT upper64 = ac + (bc >> halfBits) + (ad >> halfBits) + (mid34 >> halfBits);
181 UT lower64 = (mid34 << halfBits) | (bd & halfMask);
182
183 if constexpr(std::is_signed<T>::value) {
184 T upper64s = T(upper64);
185 if(x.raw < T(0))
186 upper64s -= y.raw;
187 if(y.raw < T(0))
188 upper64s -= x.raw;
190
191 UT raw = ((upper64 << (bits - P + 1)) >> 1) | (lower64 >> P);
192 if(upper64s < T(0)) {
193 raw |= UT(std::numeric_limits<T>::lowest());
194 }
195 return FixedPoint<T, P>((T)raw);
196 } else {
197 return FixedPoint<T, P>(T((upper64 << (bits - P)) | (lower64 >> P)));
198 }
199 }
200
207 template<typename T, unsigned int P>
208 [[nodiscard]] inline constexpr FixedPoint<T, P> operator/(const FixedPoint<T, P> x, const typename FixedPoint<T, P>::Self y) noexcept {
209 if constexpr(sizeof(T) * 4 <= P) {
210 return FixedPoint<T, P>(T((x.raw << P) / y.raw));
211 } else {
212 return x * FixedPoint<T, P>(T((FixedPoint<T, P>::one << P) / y.raw));
213 }
214 }
215
216 // ---------------------------------------------------------------------------------------------
217
224 template<typename T, unsigned int P> inline constexpr FixedPoint<T, P>& operator+=(FixedPoint<T, P>& a, const typename FixedPoint<T, P>::Self b) noexcept {
225 a = a + b;
226 return a;
227 }
228
234 template<typename T, unsigned int P> inline constexpr FixedPoint<T, P>& operator++(FixedPoint<T, P>& a) noexcept {
235 a.raw = a.raw + FixedPoint<T, P>::one;
236 return a;
237 }
238
244 template<typename T, unsigned int P>
245 inline constexpr FixedPoint<T, P> // NOLINT(cert-dcl21-cpp)
246 operator++(FixedPoint<T, P>& a, int) noexcept {
248 ++a;
249 return copy;
250 }
251
258 template<typename T, unsigned int P> inline constexpr FixedPoint<T, P>& operator-=(FixedPoint<T, P>& a, const typename FixedPoint<T, P>::Self b) noexcept {
259 a = a - b;
260 return a;
261 }
262
268 template<typename T, unsigned int P> inline constexpr FixedPoint<T, P>& operator--(FixedPoint<T, P>& a) noexcept {
269 a.raw = a.raw - FixedPoint<T, P>::one;
270 return a;
271 }
272
278 template<typename T, unsigned int P>
279 inline constexpr FixedPoint<T, P> // NOLINT(cert-dcl21-cpp)
280 operator--(FixedPoint<T, P>& a, int) noexcept {
282 --a;
283 return copy;
284 }
285
292 template<typename T, unsigned int P> inline constexpr FixedPoint<T, P>& operator*=(FixedPoint<T, P>& a, const typename FixedPoint<T, P>::Self b) noexcept {
293 a = a * b;
294 return a;
295 }
296
297 // ---------------------------------------------------------------------------------------------
298
305 template<typename T, unsigned int P>
306 [[nodiscard]] inline constexpr bool operator==(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
307 return a.raw == b.raw;
308 }
309
316 template<typename T, unsigned int P>
317 [[nodiscard]] inline constexpr bool operator!=(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
318 return a.raw != b.raw;
319 }
320
327 template<typename T, unsigned int P>
328 [[nodiscard]] inline constexpr bool operator<(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
329 return a.raw < b.raw;
330 }
331
338 template<typename T, unsigned int P> [[nodiscard]] inline constexpr bool operator<(const FixedPoint<T, P> a, double b) noexcept {
339 return a.raw < FixedPoint<T, P>(b).raw;
340 }
341
348 template<typename T, unsigned int P>
349 [[nodiscard]] inline constexpr bool operator<=(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
350 return a.raw <= b.raw;
351 }
352
359 template<typename T, unsigned int P> [[nodiscard]] inline constexpr bool operator<=(const FixedPoint<T, P> a, double b) noexcept {
360 return a.raw <= FixedPoint<T, P>(b).raw;
361 }
362
369 template<typename T, unsigned int P>
370 [[nodiscard]] inline constexpr bool operator>(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
371 return a.raw > b.raw;
372 }
373
380 template<typename T, unsigned int P> [[nodiscard]] inline constexpr bool operator>(const FixedPoint<T, P> a, double b) noexcept {
381 return a.raw > FixedPoint<T, P>(b).raw;
382 }
383
390 template<typename T, unsigned int P>
391 [[nodiscard]] inline constexpr bool operator>=(const FixedPoint<T, P> a, const typename FixedPoint<T, P>::Self b) noexcept {
392 return a.raw >= b.raw;
393 }
394
401 template<typename T, unsigned int P> [[nodiscard]] inline constexpr bool operator>=(const FixedPoint<T, P> a, double b) noexcept {
402 return a.raw >= FixedPoint<T, P>(b).raw;
403 }
404
405 // ---------------------------------------------------------------------------------------------
406
408 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> abs(const FixedPoint<T, P>& x) {
409 if constexpr(std::is_signed<T>::value) {
410 return x.raw < T(0) ? -x : x;
411 } else {
412 return x;
413 }
414 }
415
417 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> frac(const FixedPoint<T, P>& x) {
418 if constexpr(std::is_signed<T>::value) {
420 } else {
422 }
423 }
424
429 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> sign(const FixedPoint<T, P>& x) {
430 if(x.raw == T(0)) {
431 return x;
432 }
433
434 if constexpr(std::is_signed<T>::value) {
436 } else {
438 }
439 }
440
442 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> floor(const FixedPoint<T, P>& x) {
443 return FixedPoint<T, P>((x.raw >> P) << P);
444 }
445
447 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> ceil(const FixedPoint<T, P>& x) {
449 }
450
453 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> round(const FixedPoint<T, P>& x) {
454 return FixedPoint<T, P>(((x.raw + FixedPoint<T, P>::one / T(2)) >> P) << P);
455 }
456
458 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> sqrt(const FixedPoint<T, P>& x) {
459 T r = x.raw;
460 T b = T(1) << ((sizeof(T) * 8) - 2);
461 T q = 0;
462 while(b > 0x40) {
463 T t = q + b;
464 if(r >= t) {
465 r -= t;
466 q = t + b; // equivalent to q += 2*b
467 }
468 r <<= 1;
469 b >>= 1;
470 }
471 return FixedPoint<T, P>(q >> (P - 1));
472 }
473
475 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> acos(FixedPoint<T, P> x) {
476 const FixedPoint<T, P> negate = FixedPoint<T, P>(x.raw < T(0) ? FixedPoint<T, P>::one : T(0));
477 x = abs(x);
479 ret = ret * x;
480 ret = ret + FixedPoint<T, P>(0.0742610);
481 ret = ret * x;
482 ret = ret - FixedPoint<T, P>(0.2121144);
483 ret = ret * x;
484 ret = ret + FixedPoint<T, P>(1.5707288);
486 ret = ret - FixedPoint<T, P>(2.0) * negate * ret;
487 return negate * FixedPoint<T, P>(3.14159265358979) + ret;
488 }
489
491 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> asin(FixedPoint<T, P> x) {
492 const FixedPoint<T, P> negate = FixedPoint<T, P>(x.raw < T(0) ? FixedPoint<T, P>::one : T(0));
493 x = abs(x);
495 ret = ret * x;
496 ret = ret + FixedPoint<T, P>(0.0742610);
497 ret = ret * x;
498 ret = ret - FixedPoint<T, P>(0.2121144);
499 ret = ret * x;
500 ret = ret + FixedPoint<T, P>(1.5707288);
502 return ret - FixedPoint<T, P>(FixedPoint<T, P>::one * 2) * negate * ret;
503 }
504
508 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> atan2(const FixedPoint<T, P>& y, const FixedPoint<T, P>& x) {
509 static_assert(std::is_signed_v<T>);
510
511 using Type = FixedPoint<T, P>;
512
513 Type t0, t1, t3, t4;
514
515 t3 = abs(x);
516 t1 = abs(y);
517 t0 = max(t3, t1);
518 t1 = min(t3, t1);
519 t3 = Type(1.0) / t0;
520 t3 = t1 * t3;
521
522 t4 = t3 * t3;
523 t0 = -Type(0.013480470);
524 t0 = t0 * t4 + Type(0.057477314);
525 t0 = t0 * t4 - Type(0.121239071);
526 t0 = t0 * t4 + Type(0.195635925);
527 t0 = t0 * t4 - Type(0.332994597);
528 t0 = t0 * t4 + Type(0.999995630);
529 t3 = t0 * t3;
530
531 t3 = (abs(y) > abs(x)) ? Type(1.570796327) - t3 : t3;
532 t3 = (x < 0) ? Type(3.141592654) - t3 : t3;
533 t3 = (y < 0) ? -t3 : t3;
534
535 return t3;
536 }
537
540 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> atan(const FixedPoint<T, P>& x) {
542 }
543
544
545 template <typename B, unsigned int F>
547 {
548 return
549 assert(y.raw != 0),
550 FixedPoint<B, F>(x.raw % y.raw);
551 }
552
553 template <typename B, unsigned int F>
555 {
556 // This sine uses a fifth-order curve-fitting approximation originally
557 // described by Jasper Vijn on coranac.com which has a worst-case
558 // relative error of 0.07% (over [-pi:pi]).
559 using Fixed = FixedPoint<B, F>;
560
561 // Turn x from [0..2*PI] domain into [0..4] domain
562 x = fmod(x, Fixed(2.0 / Math::PI));
563 x = x / Fixed(Math::PI / 2.0);
564
565 // Take x modulo one rotation, so [-4..+4].
566 if (x < Fixed(0.0)) {
567 x += Fixed(4.0);
568 }
569
570 int sign = +1;
571 if (x > Fixed(2.0)) {
572 // Reduce domain to [0..2].
573 sign = -1;
574 x -= Fixed(2.0);
575 }
576
577 if (x > Fixed(1.0)) {
578 // Reduce domain to [0..1].
579 x = Fixed(2.0) - x;
580 }
581
582 const Fixed x2 = x*x;
583 return Fixed(sign * 1.0) * x * (Fixed(Math::PI) - x2*(Fixed(2.0 / Math::PI) - 5.0 - x2*(Fixed(Math::PI) - 3.0)))/2.0;
584 }
585
588 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> cos(const FixedPoint<T, P>& x) {
589// static_assert(std::is_signed_v<T>::value);
590
591 using Fixed = FixedPoint<T, P>;
592 if (x > Fixed(0.0)) { // Prevent an overflow due to the addition of π/2
593 return sin(x - (Fixed(Math::PI * 2.0) - Fixed(Math::PI / 2.0)));
594 } else {
595 return sin(Fixed(Math::PI / 2.0) + x);
596 }
597 }
598
600 template<typename T, unsigned int P> [[nodiscard]] inline constexpr FixedPoint<T, P> tan(const FixedPoint<T, P>& x) {
601 const FixedPoint<T, P> sine = sin(x);
602 const FixedPoint<T, P> cosine = cos(x);
603 if(cosine.raw == T(0)) {
604 return std::numeric_limits<FixedPoint<T, P>>::infinity();
605 }
606
607 return sine / cosine;
608 }
609
610 // ---------------------------------------------------------------------------------------------
611
616 [[nodiscard]] constexpr FixedPoint<Int64, sizeof(Int64) * 8 - std::numeric_limits<double>::digits> operator"" _fp(const long double v) { return v; }
617
618} // namespace CeresEngine::inline Math
619
620template<typename T, unsigned int P> struct std::is_integral<CeresEngine::Math::FixedPoint<T, P>> : std::false_type {};
621
622template<typename T, unsigned int P> struct std::is_signed<CeresEngine::Math::FixedPoint<T, P>> : std::is_signed<T> {};
623
624template<typename T, unsigned int P> struct std::is_unsigned<CeresEngine::Math::FixedPoint<T, P>> : std::is_unsigned<T> {};
625
626template<typename T, unsigned int P> struct std::make_signed<CeresEngine::Math::FixedPoint<T, P>> {
627 typedef CeresEngine::Math::FixedPoint<typename std::make_signed<T>::type, P> type;
628};
629
630template<typename T, unsigned int P> struct std::make_unsigned<CeresEngine::Math::FixedPoint<T, P>> {
631 typedef CeresEngine::Math::FixedPoint<typename std::make_unsigned<T>::type, P> type;
632};
633
634template<typename T, unsigned int P> struct std::hash<CeresEngine::Math::FixedPoint<T, P>> {
635 using Type = CeresEngine::Math::FixedPoint<T, P>;
636 constexpr size_t operator()(const Type& obj) const { return CeresEngine::hash(obj.raw); }
637};
638
639template<typename T, unsigned int P> struct std::numeric_limits<CeresEngine::Math::FixedPoint<T, P>> {
641 using Tp = CeresEngine::Math::FixedPoint<T, P>;
642
644 static inline constexpr bool is_specialized = true;
645
647 static inline constexpr bool is_integer = false;
648
650 static inline constexpr bool is_signed = numeric_limits<T>::is_signed;
651
653 static inline constexpr bool is_exact = true;
654
657 static inline constexpr bool has_infinity = false;
658
661 static inline constexpr bool has_quiet_NaN = false;
662
665 static inline constexpr bool has_signaling_NaN = false;
666
668 static inline constexpr float_denorm_style has_denorm = denorm_absent;
669
672 static inline constexpr bool has_denorm_loss = false;
673
675 static inline constexpr float_round_style round_style = round_toward_zero;
676
678 static inline constexpr bool is_iec559 = true;
679
681 static inline constexpr bool is_bounded = true;
682
684 static inline constexpr bool is_modulo = false;
685
687 static inline constexpr int digits = static_cast<int>(P);
688
690 static inline constexpr int digits10 = static_cast<int>(digits * 0.3010299956639812);
691
694 static inline constexpr int max_digits10 = 0;
695
697 static inline constexpr int radix = 2;
698
701 static inline constexpr int min_exponent = 0;
702
705 static inline constexpr int min_exponent10 = 0;
706
709 static inline constexpr int max_exponent = 0;
710
713 static inline constexpr int max_exponent10 = 0;
714
716 static inline constexpr bool traps = std::numeric_limits<T>::traps;
717
719 static inline constexpr bool tinyness_before = false;
720
722 [[nodiscard]] static constexpr Tp min() noexcept { return Tp(T(0)); }
723
725 [[nodiscard]] static constexpr Tp lowest() noexcept { return Tp(std::numeric_limits<T>::lowest()); }
726
728 [[nodiscard]] static constexpr Tp max() noexcept { return Tp(std::numeric_limits<T>::max()); }
729
732 [[nodiscard]] static constexpr Tp epsilon() noexcept { return Tp(T(1)); }
733
735 [[nodiscard]] static constexpr Tp round_error() noexcept { return Tp(0); }
736
738 [[nodiscard]] static constexpr Tp infinity() noexcept { return max(); }
739
741 [[nodiscard]] static constexpr Tp quiet_NaN() noexcept { return Tp(0); }
742
744 [[nodiscard]] static constexpr Tp signaling_NaN() noexcept { return Tp(0); }
745
748 [[nodiscard]] static constexpr Tp denorm_min() noexcept { return Tp(0); }
749};
Definition Application.hpp:19
ButtonSet & operator-=(ButtonSet &set, const Button button)
Removes a button from a set.
Definition Input.hpp:257
constexpr bool operator<(const Optional< A > &lhs, const Optional< B > &rhs)
Definition Optional.hpp:162
bool operator!=(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:416
ButtonSet & operator+=(ButtonSet &set, const Button button)
Adds a button to a set.
Definition Input.hpp:207
constexpr bool operator>=(const Optional< A > &lhs, const Optional< B > &rhs)
Definition Optional.hpp:157
ButtonSet operator-(const ButtonSet &set, const Button button)
Removes a button from a set.
Definition Input.hpp:270
bool operator==(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:411
std::int64_t Int64
Definition DataTypes.hpp:24
constexpr bool operator>(const Optional< A > &lhs, const Optional< B > &rhs)
Definition Optional.hpp:152
void copy(const A &a, B &b, T &&t=T())
Copies values from one container to another.
Definition Iterator.hpp:564
BasicString< T, CharTraits, RawAllocator > operator+(const BasicString< T, CharTraits, RawAllocator > &lhs, const T *rhs)
Definition String.hpp:119
@ Fixed
Renders the shadow map from a fixed point.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
constexpr bool operator<=(const Optional< A > &lhs, const Optional< B > &rhs)
Definition Optional.hpp:167
const T epsilon
Return the epsilon constant for floating point types.
Definition Math.hpp:860
Definition Angle.hpp:20
constexpr FixedPoint< T, P > frac(const FixedPoint< T, P > &x)
Returns the fractional portion of a fixed-point value.
Definition FixedPoint.hpp:417
constexpr FixedPoint< T, P > & operator++(FixedPoint< T, P > &a) noexcept
Increment the fixed-point value by adding 1.0 to it.
Definition FixedPoint.hpp:234
constexpr FixedPoint< T, P > floor(const FixedPoint< T, P > &x)
Returns largest integer not greater than a fixed-point value.
Definition FixedPoint.hpp:442
constexpr FixedPoint< T, P > ceil(const FixedPoint< T, P > &x)
Returns smallest integer not less than a fixed-point value.
Definition FixedPoint.hpp:447
constexpr FixedPoint< T, P > cos(const FixedPoint< T, P > &x)
Returns cosine of a fixed-point value.
Definition FixedPoint.hpp:588
constexpr FixedPoint< T, P > atan(const FixedPoint< T, P > &x)
Returns arctangent of a fixed-point value.
Definition FixedPoint.hpp:540
constexpr FixedPoint< T, P > atan2(const FixedPoint< T, P > &y, const FixedPoint< T, P > &x)
Returns arctangent of a fixed-point value.
Definition FixedPoint.hpp:508
constexpr FixedPoint< B, F > fmod(FixedPoint< B, F > x, FixedPoint< B, F > y) noexcept
Definition FixedPoint.hpp:546
constexpr FixedPoint< T, P > abs(const FixedPoint< T, P > &x)
Returns the absolute value of a fixed-point value.
Definition FixedPoint.hpp:408
constexpr FixedPoint< T, P > round(const FixedPoint< T, P > &x)
Returns the rounded value a fixed-point value.
Definition FixedPoint.hpp:453
constexpr FixedPoint< T, P > sqrt(const FixedPoint< T, P > &x)
Returns square root of a fixed-point value.
Definition FixedPoint.hpp:458
FixedPoint< B, F > sin(FixedPoint< B, F > x) noexcept
Definition FixedPoint.hpp:554
constexpr FixedPoint< T, P > & operator--(FixedPoint< T, P > &a) noexcept
Decrement the fixed-point value by subtracting 1.0 from it.
Definition FixedPoint.hpp:268
constexpr FixedPoint< T, P > sign(const FixedPoint< T, P > &x)
Returns sign of scalar a fixed-point value.
Definition FixedPoint.hpp:429
constexpr TExtent2< T > & operator*=(TExtent2< T > &lhs, T rhs) noexcept
Returns the multiplication of left hand side extent 'lhs' and the right hand side extent 'rhs'.
Definition Extent.hpp:151
constexpr FixedPoint< T, P > asin(FixedPoint< T, P > x)
Returns arcsine of a fixed-point value.
Definition FixedPoint.hpp:491
constexpr FixedPoint< T, P > acos(FixedPoint< T, P > x)
Returns arccosine of a fixed-point value.
Definition FixedPoint.hpp:475
constexpr FixedPoint< T, P > tan(const FixedPoint< T, P > &x)
Returns tangent of a fixed-point value. Returns the tangent of a in radians.
Definition FixedPoint.hpp:600
Definition FixedPoint.hpp:23
constexpr FixedPoint(float f) noexcept
Creates a new fixed-point number from an existing float value.
Definition FixedPoint.hpp:54
TT convert() const
Definition FixedPoint.hpp:92
constexpr FixedPoint(long double d) noexcept
Creates a new fixed-point number from an existing double value.
Definition FixedPoint.hpp:74
constexpr FixedPoint()=default
Creates a new fixed-point number and initializes it with 0.0.
constexpr FixedPoint(const FixedPoint< TT, TP > &other)
Creates a new fixed-point number by converting representation from another fixed-point.
Definition FixedPoint.hpp:88
constexpr FixedPoint(const FixedPoint &)=default
Creates a new fixed-point number by copying another.
constexpr FixedPoint(const double d) noexcept
Creates a new fixed-point number from an existing double value.
Definition FixedPoint.hpp:64
T raw
The underlying integer value.
Definition FixedPoint.hpp:35
constexpr FixedPoint(T raw) noexcept
Creates a new fixed-point number and initializes it with the given raw integer value.
Definition FixedPoint.hpp:43
constexpr FixedPoint & operator=(const FixedPoint &)=default
Assigns the fixed-point number by copying another.