|
| constexpr | fixed () noexcept=default |
| | Default constructor.
|
| template<integral T> |
| constexpr | fixed (const T &value) noexcept |
| | Constructs from an integral value.
|
| template<floating_point T> |
| constexpr | fixed (const T &value) noexcept |
| | Constructs from a floating-point value.
|
| template<typename OtherBase, typename OtherIntermediate, unsigned OtherFraction, bool OtherRounding> |
| constexpr | fixed (const fixed< OtherBase, OtherIntermediate, OtherFraction, OtherRounding > &value) noexcept |
| | Constructs by converting from another toy::math::fixed type.
|
| template<integral T> |
| constexpr | operator T () const noexcept |
| | Converts to an integral type.
|
| template<floating_point T> |
| constexpr | operator T () const noexcept |
| | Converts to a floating-point type.
|
| constexpr Base | rawValue () const noexcept |
| | Returns raw fixed-point storage value.
|
| template<bool OtherRounding> |
| constexpr fixed & | operator= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| | Assigns from another toy::math::fixed with the same Base, Intermediate, and Fraction.
|
| template<integral T> |
| constexpr fixed & | operator= (const T &other) noexcept |
| | Assigns from an integral value.
|
| template<bool OtherRounding> |
| constexpr fixed & | operator+= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| | Adds another toy::math::fixed value in place.
|
| template<integral T> |
| constexpr fixed & | operator+= (const T &other) noexcept |
| | Adds an integral value in place.
|
| template<bool OtherRounding> |
| constexpr fixed & | operator-= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| | Subtracts another toy::math::fixed value in place.
|
| template<integral T> |
| constexpr fixed & | operator-= (const T &other) noexcept |
| | Subtracts an integral value in place.
|
| template<bool OtherRounding> |
| constexpr fixed & | operator*= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| | Multiplies by another toy::math::fixed value in place.
|
| template<integral T> |
| constexpr fixed & | operator*= (const T &other) noexcept |
| | Multiplies by an integral value in place.
|
| template<bool OtherRounding> |
| constexpr fixed & | operator/= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| | Divides by another toy::math::fixed value in place.
|
| template<integral T> |
| constexpr fixed & | operator/= (const T &other) noexcept |
| | Divides by an integral value in place.
|
| template<unsigned NumFractionBits, integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > | fromFixedPoint (const T &value) noexcept |
| template<bool OtherRounding> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| template<integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator= (const T &other) noexcept |
| template<bool OtherRounding> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator+= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| template<integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator+= (const T &other) noexcept |
| template<bool OtherRounding> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator-= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| template<integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator-= (const T &other) noexcept |
| template<bool OtherRounding> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator*= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| template<integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator*= (const T &other) noexcept |
| template<bool OtherRounding> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator/= (const fixed< Base, Intermediate, Fraction, OtherRounding > &other) noexcept |
| template<integral T> |
| constexpr fixed< Base, Intermediate, Fraction, Rounding > & | operator/= (const T &other) noexcept |
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding = true>
requires ValidFixedPointTypes<Base, Intermediate, Fraction>
class toy::math::fixed< Base, Intermediate, Fraction, Rounding >
Fixed-point numeric type with configurable storage and fractional precision.
Stores values as scaled integers using Fraction fractional bits. Conversions from integral and floating-point types are explicit.
- Template Parameters
-
| Base | Storage type for raw fixed-point value. |
| Intermediate | Wider type used for intermediate calculations. |
| Fraction | Number of fractional bits. |
| Rounding | If true, floating-point construction rounds to nearest value. |
Key Features
- Constexpr: All operations and constructors are
constexpr; usable at compile time.
- Configurable precision: Base and Fraction choose storage size and fractional bits.
- No exceptions: All operations are
noexcept; no dynamic allocation.
- Type safety: toy::math::ValidFixedPointTypes concept constrains template parameters.
- Rounding policy: Optional rounding when converting from floating-point or scaling down fraction bits.
Usage Example
constexpr fixed_type a(2);
constexpr fixed_type b(3);
constexpr auto sum = a + b;
constexpr auto raw = fixed_type::fromRawValue(256);
Fixed-point numeric type with configurable storage and fractional precision.
Definition fixed.hpp:110
Umbrella header for the math module.
Performance Characteristics
- Construction, conversion, arithmetic: O(1). All operations are integer-based.
- Memory: sizeof(Base); no heap allocation.
Safety Guarantees
- Contracts: Division by zero is checked in debug builds via
assert_message; undefined behavior if divisor is zero in release.
- Exception safety: All operations are
noexcept; no exceptions thrown.
- Type safety: Explicit conversions only; no implicit narrowing.
Compatibility
- C++ standard: C++20 (concepts,
constexpr, consteval).
- Embedded: No heap allocation; suitable for constrained environments.
- See also
- toy::math::ValidFixedPointTypes