dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx::math Namespace Reference

The main namespace of the dxx::math module. More...

Namespaces

namespace  norms
 Built-in norms.

Classes

struct  Norm
 Defines a norm. Only norm field is required, all other fields can be assigned a nullptr More...
struct  Sub
 Default difference is subtraction. More...

Concepts

concept  vector
 We can treat any input range as a vector.
concept  mut_vector
 A vector for which the elements can be written to.
concept  vector_like
 Vector for which the element type is convertible to a target vector's type.
concept  mut_vector_like
 Similar to vector_like, but also satisfies mut_vector.

Typedefs

template<typename T>
using dxx::math::RealOf = detail::RealOf<T>::Type
 (Non-cv-qualified) Real type of the linalg type

Enumerations

enum class  dxx::math::Sign : int { Positive = 1 , Zero = 0 , Negative = -1 }
 Return type of sign. Use std::to_underlying to convert to int

Functions

template<mut_vector Out, vector_like< Out > U, vector_like< Out > V>
void dxx::math::cross (const U &u, const V &v, Out &out)
 Cross product of two 3D vectors (via out parameter)
template<mut_vector Out, vector_like< Out > U, vector_like< Out > V>
constexpr Out dxx::math::cross (const U &u, const V &v)
 Cross product of two 3D vectors (via return value)
template<mut_vector U, vector_like< U > V>
constexpr U dxx::math::cross (const U &u, const V &v)
 Cross product of two 3D vectors (via return value of default type)
template<vector U, vector_like< U > V>
constexpr RealOf< U > dxx::math::dot (const U &u, const V &v)
template<Norm t_norm = norms::euclidean, vector V>
constexpr RealOf< V > dxx::math::norm (const V &v)
 Calculates norm t_norm for vector v
template<Norm t_norm = norms::euclidean, vector V>
constexpr RealOf< V > dxx::math::sq_norm (const V &v)
 Calculates the square of the norm t_norm for vector v
template<Norm t_norm = norms::euclidean, vector V, vector_like< V > U>
constexpr RealOf< V > dxx::math::dist (const V &v, const U &u)
 Calculates the distance between vector v and u according to norm t_norm
template<Norm t_norm = norms::euclidean, vector V, vector_like< V > U>
constexpr RealOf< V > dxx::math::sq_dist (const V &v, const U &u)
 Calculates the square of the distance between vector v and u according to norm t_norm
template<typename T, typename Compare = std::less<T>, typename Diff = Sub>
constexpr T dxx::math::abs_diff (const T &a, const T &b, Compare comp={}, Diff diff={})
 Underflow-safe absolute difference between two numbers.
template<typename T, typename Less = std::less<T>>
constexpr Sign dxx::math::sign (T t, Less less={}, T zero={})
 Gets the sign of a number.

Detailed Description

The main namespace of the dxx::math module.

Function Documentation

◆ abs_diff()

template<typename T, typename Compare = std::less<T>, typename Diff = Sub>
T dxx::math::abs_diff ( const T & a,
const T & b,
Compare comp = {},
Diff diff = {} )
inlinenodiscardconstexprexport

Underflow-safe absolute difference between two numbers.

Inspired by ARM's vabdq_u8 instruction and copied from https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4318.pdf