ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy::math Namespace Reference

Mathematical types, constants, and utilities: fixed-point, vectors, point. More...

Namespaces

namespace  constants
 Variable templates for mathematical constants.

Classes

class  fixed
 Fixed-point numeric type with configurable storage and fractional precision. More...
struct  is_fixed_point
 Unary type trait: true if T is an instantiation of toy::math::fixed, false otherwise. More...
struct  is_fixed_point< fixed< Base, Intermediate, Fraction, Rounding > >
class  Point
 2D integer point for UI and input coordinates. More...
class  Vector2
 2D vector with floating-point or fixed-point components for positions, movement, and physics. More...

Concepts

concept  FractionalConstantType
 Type that can be used with toy::math::constants variable templates.
concept  ValidFixedPointTypes
 Concept constraining template parameters for toy::math::fixed.
concept  fixed_point
 Concept satisfied when T is an instantiation of toy::math::fixed.
concept  PointScalar
 Concept satisfied when T is a signed integral, floating-point, or fixed-point type.
concept  Vector2Component
 Concept satisfied when T is a component type allowed as toy::math::Vector2 template parameter.

Typedefs

using real_t = float
 Floating‑point scalar type.

Functions

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator- (const fixed< Base, Intermediate, Fraction, Rounding > &value) noexcept
 Unary minus: returns the negation of a toy::math::fixed value.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator+ (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Returns a + b as a new toy::math::fixed (same type as left operand).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator+ (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Returns a + b as a new toy::math::fixed (fixed plus integral whole units).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator+ (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Returns a + b as a new toy::math::fixed (integral whole units plus fixed).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator- (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Returns a - b as a new toy::math::fixed (same type as left operand).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator- (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Returns a - b as a new toy::math::fixed (fixed minus integral whole units).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator- (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Returns a - b as a new toy::math::fixed (integral whole units minus fixed).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator* (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Returns a * b as a new toy::math::fixed (same type as left toy::math::fixed operand).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator* (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Returns a * b as a new toy::math::fixed (fixed times integral whole units).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator* (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Returns a * b as a new toy::math::fixed (integral whole units times fixed).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator/ (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Returns a / b as a new toy::math::fixed.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator/ (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Returns a / b as a new toy::math::fixed (fixed divided by integral whole units).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
constexpr fixed< Base, Intermediate, Fraction, Rounding > operator/ (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Returns a / b as a new toy::math::fixed (integral whole units divided by fixed).
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr bool operator== (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Compares two toy::math::fixed values for equality.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
constexpr bool operator== (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Compares a toy::math::fixed value with an integral for equality.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
constexpr bool operator== (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Compares an integral with a toy::math::fixed value for equality.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
constexpr strong_ordering operator<=> (const fixed< Base, Intermediate, Fraction, Rounding > &a, const fixed< Base, Intermediate, Fraction, OtherRounding > &b) noexcept
 Three-way comparison of two toy::math::fixed values.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
constexpr strong_ordering operator<=> (const fixed< Base, Intermediate, Fraction, Rounding > &a, const T &b) noexcept
 Three-way comparison of a toy::math::fixed value with an integral.
template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
constexpr strong_ordering operator<=> (const T &a, const fixed< Base, Intermediate, Fraction, Rounding > &b) noexcept
 Three-way comparison of an integral with a toy::math::fixed value.
constexpr Point operator- (const Point &point) noexcept
 Unary minus: negated coordinates.
constexpr Point operator+ (const Point &left, const Point &right) noexcept
 Addition of two points.
constexpr Point operator- (const Point &left, const Point &right) noexcept
 Subtraction of two points.
template<PointScalar T>
constexpr Point operator* (const Point &point, const T &scalar) noexcept
 Point scaled by scalar and truncated to integer.
template<PointScalar T>
constexpr Point operator* (const T &scalar, const Point &point) noexcept
 Point scaled by scalar (scalar on the left).
template<PointScalar T>
constexpr Point operator/ (const Point &point, const T &scalar) noexcept
 Point divided by scalar and truncated to integer.
constexpr bool operator== (const Point &left, const Point &right) noexcept
 Exact equality of two points.
template<typename T>
constexpr T abs (const T &value) noexcept
 Returns the absolute value of value.
template<typename T>
constexpr bool isEqual (const T &a, const T &b, T absEpsilon=8 *numeric_limits< T >::epsilon(), T relEpsilon=64 *numeric_limits< T >::epsilon()) noexcept
 Compares two values for approximate equality.
template<typename T>
constexpr T deg2rad (const T &angle) noexcept
 Converts angle from degrees to radians.
template<typename T>
constexpr T rad2deg (const T &angle) noexcept
 Converts angle from radians to degrees.
template<Vector2Component T>
constexpr Vector2< T > operator- (const Vector2< T > &vector) noexcept
 Unary minus: negated components.
template<Vector2Component T>
constexpr Vector2< T > operator+ (const Vector2< T > &left, const Vector2< T > &right) noexcept
 Addition of two vectors.
template<Vector2Component T>
constexpr Vector2< T > operator- (const Vector2< T > &left, const Vector2< T > &right) noexcept
 Subtraction of two vectors.
template<Vector2Component T>
constexpr Vector2< T > operator* (const Vector2< T > &left, const T &right) noexcept
 Vector scaled by scalar.
template<Vector2Component T>
constexpr Vector2< T > operator* (const T &left, const Vector2< T > &right) noexcept
 Vector scaled by scalar (scalar on the left).
template<Vector2Component T>
constexpr T operator* (const Vector2< T > &left, const Vector2< T > &right) noexcept
 Dot product of two vectors.
template<Vector2Component T>
constexpr Vector2< T > operator/ (const Vector2< T > &left, const T &right) noexcept
 Vector divided by scalar.
template<Vector2Component T>
constexpr bool operator== (const Vector2< T > &left, const Vector2< T > &right) noexcept
 Exact equality of two vectors.
template<Vector2Component T>
constexpr bool operator!= (const Vector2< T > &left, const Vector2< T > &right) noexcept
 Inequality of two vectors.
template<Vector2Component T>
constexpr T cross (const Vector2< T > &left, const Vector2< T > &right) noexcept
 2D cross product (scalar result).
template<Vector2Component T>
 Vector2 (const T &, const T &) -> Vector2< T >
 Deduction guide: enables Vector2(x, y) without an explicit template argument when both arguments have the same toy::math::Vector2Component type.

Variables

template<typename T>
constexpr bool is_fixed_point_v = is_fixed_point<T>::value
 Helper variable template: true if T is toy::math::fixed, false otherwise.

Detailed Description

Mathematical types, constants, and utilities: fixed-point, vectors, point.

See also
toy::math::Point, toy::math::Vector2, toy::math::fixed

Typedef Documentation

◆ real_t

using toy::math::real_t = float

Floating‑point scalar type.

Function Documentation

◆ cross()

template<Vector2Component T>
T toy::math::cross ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

2D cross product (scalar result).

Parameters
leftFirst operand.
rightSecond operand.
Returns
left.x * right.y - left.y * right.x.

◆ operator!=()

template<Vector2Component T>
bool toy::math::operator!= ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Inequality of two vectors.

Parameters
leftFirst operand.
rightSecond operand.
Returns
true if !(left == right).

◆ operator*() [1/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator* ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Returns a * b as a new toy::math::fixed (same type as left toy::math::fixed operand).

Parameters
aLeft operand (fixed-point value).
bRight operand (fixed-point value).
Returns
Product as toy::math::fixed with same type as a.

◆ operator*() [2/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator* ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Returns a * b as a new toy::math::fixed (fixed times integral whole units).

Parameters
aFixed-point value.
bIntegral value (whole units).
Returns
Product as toy::math::fixed.

◆ operator*() [3/8]

template<PointScalar T>
Point toy::math::operator* ( const Point & point,
const T & scalar )
nodiscardconstexprnoexcept

Point scaled by scalar and truncated to integer.

Template Parameters
TType satisfying toy::math::PointScalar.
Parameters
pointPoint operand.
scalarScale factor.
Returns
toy::math::Point with coordinates multiplied by scalar then cast to int32_t.

◆ operator*() [4/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator* ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Returns a * b as a new toy::math::fixed (integral whole units times fixed).

Parameters
aIntegral value (whole units).
bFixed-point value.
Returns
Product as toy::math::fixed.

◆ operator*() [5/8]

template<Vector2Component T>
Vector2< T > toy::math::operator* ( const T & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Vector scaled by scalar (scalar on the left).

Template Parameters
TComponent type satisfy toy::math::Vector2Component.
Parameters
leftScale factor.
rightVector operand.
Returns
toy::math::Vector2 with components multiplied by scalar.

◆ operator*() [6/8]

template<PointScalar T>
Point toy::math::operator* ( const T & scalar,
const Point & point )
nodiscardconstexprnoexcept

Point scaled by scalar (scalar on the left).

Template Parameters
TType satisfying toy::math::PointScalar (signed integral, floating-point, or fixed-point).
Parameters
scalarScale factor.
pointPoint operand.
Returns
toy::math::Point with coordinates multiplied by scalar then cast to int32_t.

◆ operator*() [7/8]

template<Vector2Component T>
Vector2< T > toy::math::operator* ( const Vector2< T > & left,
const T & right )
nodiscardconstexprnoexcept

Vector scaled by scalar.

Template Parameters
TComponent type satisfy toy::math::Vector2Component.
Parameters
leftVector operand.
rightScale factor.
Returns
toy::math::Vector2 with components multiplied by scalar.

◆ operator*() [8/8]

template<Vector2Component T>
T toy::math::operator* ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Dot product of two vectors.

Parameters
leftFirst operand.
rightSecond operand.
Returns
left.x * right.x + left.y * right.y.

◆ operator+() [1/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator+ ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Returns a + b as a new toy::math::fixed (same type as left operand).

b may be a toy::math::fixed with different rounding (OtherRounding) or an integral; the result uses Rounding of the toy::math::fixed operand.

Parameters
aLeft operand (fixed-point value).
bRight operand (fixed-point or integral whole units).
Returns
Sum as toy::math::fixed with same type as a.

◆ operator+() [2/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator+ ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Returns a + b as a new toy::math::fixed (fixed plus integral whole units).

Parameters
aFixed-point value.
bIntegral value (whole units).
Returns
Sum as toy::math::fixed.

◆ operator+() [3/5]

Point toy::math::operator+ ( const Point & left,
const Point & right )
nodiscardconstexprnoexcept

Addition of two points.

Parameters
leftFirst operand.
rightSecond operand.
Returns
toy::math::Point with (left.x + right.x, left.y + right.y).

◆ operator+() [4/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator+ ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Returns a + b as a new toy::math::fixed (integral whole units plus fixed).

Parameters
aIntegral value (whole units).
bFixed-point value.
Returns
Sum as toy::math::fixed.

◆ operator+() [5/5]

template<Vector2Component T>
Vector2< T > toy::math::operator+ ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Addition of two vectors.

Parameters
leftFirst operand.
rightSecond operand.
Returns
toy::math::Vector2 with (left.x + right.x, left.y + right.y).

◆ operator-() [1/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator- ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Returns a - b as a new toy::math::fixed (same type as left operand).

Parameters
aLeft operand (fixed-point value).
bRight operand (fixed-point value).
Returns
Difference as toy::math::fixed with same type as a.

◆ operator-() [2/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator- ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Returns a - b as a new toy::math::fixed (fixed minus integral whole units).

Parameters
aFixed-point value.
bIntegral value (whole units).
Returns
Difference as toy::math::fixed.

◆ operator-() [3/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator- ( const fixed< Base, Intermediate, Fraction, Rounding > & value)
nodiscardconstexprnoexcept

Unary minus: returns the negation of a toy::math::fixed value.

The result has the same raw storage as value with sign flipped. The operand is not modified.

Parameters
valueFixed-point value to negate.
Returns
A new toy::math::fixed instance representing -value.

◆ operator-() [4/8]

Point toy::math::operator- ( const Point & left,
const Point & right )
nodiscardconstexprnoexcept

Subtraction of two points.

Parameters
leftFirst operand.
rightSecond operand.
Returns
toy::math::Point with (left.x - right.x, left.y - right.y).

◆ operator-() [5/8]

Point toy::math::operator- ( const Point & point)
nodiscardconstexprnoexcept

Unary minus: negated coordinates.

Parameters
pointOperand.
Returns
toy::math::Point with (-point.x, -point.y).

◆ operator-() [6/8]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator- ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Returns a - b as a new toy::math::fixed (integral whole units minus fixed).

Parameters
aIntegral value (whole units).
bFixed-point value.
Returns
Difference as toy::math::fixed.

◆ operator-() [7/8]

template<Vector2Component T>
Vector2< T > toy::math::operator- ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Subtraction of two vectors.

Parameters
leftFirst operand.
rightSecond operand.
Returns
toy::math::Vector2 with (left.x - right.x, left.y - right.y).

◆ operator-() [8/8]

template<Vector2Component T>
Vector2< T > toy::math::operator- ( const Vector2< T > & vector)
nodiscardconstexprnoexcept

Unary minus: negated components.

Parameters
vectorOperand.
Returns
toy::math::Vector2 with (-vector.x, -vector.y).

◆ operator/() [1/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator/ ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Returns a / b as a new toy::math::fixed.

Behavior is undefined if b is zero.

Parameters
aDividend (fixed-point value).
bDivisor (fixed-point value, must not be zero).
Returns
Quotient as toy::math::fixed.

◆ operator/() [2/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator/ ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Returns a / b as a new toy::math::fixed (fixed divided by integral whole units).

Behavior is undefined if b is zero.

Parameters
aDividend (fixed-point value).
bDivisor (integral, must not be zero).
Returns
Quotient as toy::math::fixed.

◆ operator/() [3/5]

template<PointScalar T>
Point toy::math::operator/ ( const Point & point,
const T & scalar )
nodiscardconstexprnoexcept

Point divided by scalar and truncated to integer.

Template Parameters
TType satisfying toy::math::PointScalar (signed integral, floating-point, or fixed-point).
Parameters
pointPoint operand.
scalarDivisor.
Returns
toy::math::Point with coordinates divided by scalar then cast to int32_t.
Precondition
scalar != 0.

◆ operator/() [4/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, typename T>
fixed< Base, Intermediate, Fraction, Rounding > toy::math::operator/ ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Returns a / b as a new toy::math::fixed (integral whole units divided by fixed).

Behavior is undefined if b is zero.

Parameters
aDividend (integral value).
bDivisor (fixed-point value, must not be zero).
Returns
Quotient as toy::math::fixed.

◆ operator/() [5/5]

template<Vector2Component T>
Vector2< T > toy::math::operator/ ( const Vector2< T > & left,
const T & right )
nodiscardconstexprnoexcept

Vector divided by scalar.

Template Parameters
TComponent type satisfy toy::math::Vector2Component.
Parameters
leftVector operand.
rightDivisor.
Returns
toy::math::Vector2 with components divided by scalar.
Precondition
right != 0.

◆ operator<=>() [1/3]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
strong_ordering toy::math::operator<=> ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Three-way comparison of two toy::math::fixed values.

Compares raw storage values; Rounding of either operand does not affect the result. Enables <, <=, >, >=, and != via the compiler-generated operators.

Template Parameters
BaseStorage type (shared by both operands).
IntermediateIntermediate type (shared by both operands).
FractionNumber of fractional bits (shared by both operands).
RoundingRounding policy of the left operand.
OtherRoundingRounding policy of the right operand.
Parameters
aLeft operand.
bRight operand.
Returns
strong_ordering::less if a is less than b, strong_ordering::equal if equal, strong_ordering::greater if a is greater than b.

◆ operator<=>() [2/3]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
strong_ordering toy::math::operator<=> ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Three-way comparison of a toy::math::fixed value with an integral.

Converts b to the same toy::math::fixed type and compares raw storage values. Enables <, <=, >, >=, and != for fixed and integral operands.

Template Parameters
BaseStorage type of the fixed operand.
IntermediateIntermediate type of the fixed operand.
FractionNumber of fractional bits of the fixed operand.
RoundingRounding policy of the fixed operand.
TIntegral type; must satisfy integral.
Parameters
aLeft operand (fixed-point).
bRight operand (integral whole units).
Returns
strong_ordering::less if a is less than b, strong_ordering::equal if equal, strong_ordering::greater if a is greater than b.

◆ operator<=>() [3/3]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
strong_ordering toy::math::operator<=> ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Three-way comparison of an integral with a toy::math::fixed value.

Converts a to the same toy::math::fixed type as b and compares raw storage values. Enables <, <=, >, >=, and != for integral and fixed operands.

Template Parameters
BaseStorage type of the fixed operand.
IntermediateIntermediate type of the fixed operand.
FractionNumber of fractional bits of the fixed operand.
RoundingRounding policy of the fixed operand.
TIntegral type; must satisfy integral.
Parameters
aLeft operand (integral whole units).
bRight operand (fixed-point).
Returns
strong_ordering::less if a is less than b, strong_ordering::equal if equal, strong_ordering::greater if a is greater than b.

◆ operator==() [1/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, bool OtherRounding>
bool toy::math::operator== ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const fixed< Base, Intermediate, Fraction, OtherRounding > & b )
nodiscardconstexprnoexcept

Compares two toy::math::fixed values for equality.

Compares raw storage values; Rounding of either operand does not affect the result. Two values are equal if and only if their raw values are equal.

Template Parameters
BaseStorage type (shared by both operands).
IntermediateIntermediate type (shared by both operands).
FractionNumber of fractional bits (shared by both operands).
RoundingRounding policy of the left operand.
OtherRoundingRounding policy of the right operand.
Parameters
aLeft operand.
bRight operand.
Returns
true if a and b represent the same value, false otherwise.

◆ operator==() [2/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
bool toy::math::operator== ( const fixed< Base, Intermediate, Fraction, Rounding > & a,
const T & b )
nodiscardconstexprnoexcept

Compares a toy::math::fixed value with an integral for equality.

Converts b to the same toy::math::fixed type and compares raw storage values. Two values are equal if and only if their raw values are equal.

Template Parameters
BaseStorage type of the fixed operand.
IntermediateIntermediate type (shared).
FractionNumber of fractional bits.
RoundingRounding policy of the fixed operand.
TIntegral type; must satisfy integral.
Parameters
aLeft operand (fixed-point).
bRight operand (integral whole units).
Returns
true if a and b represent the same value, false otherwise.

◆ operator==() [3/5]

bool toy::math::operator== ( const Point & left,
const Point & right )
nodiscardconstexprnoexcept

Exact equality of two points.

Parameters
leftFirst operand.
rightSecond operand.
Returns
true if left.x == right.x and left.y == right.y, false otherwise.
See also
isEqual() for tolerance-based comparison.

◆ operator==() [4/5]

template<typename Base, typename Intermediate, unsigned Fraction, bool Rounding, integral T>
bool toy::math::operator== ( const T & a,
const fixed< Base, Intermediate, Fraction, Rounding > & b )
nodiscardconstexprnoexcept

Compares an integral with a toy::math::fixed value for equality.

Converts a to the same toy::math::fixed type as b and compares raw storage values. Two values are equal if and only if their raw values are equal.

Template Parameters
BaseStorage type of the fixed operand.
IntermediateIntermediate type (shared).
FractionNumber of fractional bits.
RoundingRounding policy of the fixed operand.
TIntegral type; must satisfy integral.
Parameters
aLeft operand (integral whole units).
bRight operand (fixed-point).
Returns
true if a and b represent the same value, false otherwise.

◆ operator==() [5/5]

template<Vector2Component T>
bool toy::math::operator== ( const Vector2< T > & left,
const Vector2< T > & right )
nodiscardconstexprnoexcept

Exact equality of two vectors.

For floating-point T, delegates to isEqual() with default epsilons. For fixed-point T, compares raw storage of both components.

Parameters
leftFirst operand.
rightSecond operand.
Returns
For floating-point T: true if isEqual(right) with default tolerances. For fixed-point T: true if left and right have equal raw component values.
See also
isEqual() for custom tolerances (floating-point).

◆ Vector2()

template<Vector2Component T>
toy::math::Vector2 ( const T & ,
const T &  ) -> Vector2< T >

Deduction guide: enables Vector2(x, y) without an explicit template argument when both arguments have the same toy::math::Vector2Component type.

Template Parameters
TComponent type; must satisfy toy::math::Vector2Component.

Variable Documentation

◆ is_fixed_point_v

template<typename T>
bool toy::math::is_fixed_point_v = is_fixed_point<T>::value
inlineconstexpr

Helper variable template: true if T is toy::math::fixed, false otherwise.