sandbox
Loading...
Searching...
No Matches
algorithm.hpp File Reference

Generic math algorithms and helpers. More...

#include <cmath>
#include <limits>
#include <libsbx/math/concepts.hpp>
#include <libsbx/math/algorithm.ipp>

Go to the source code of this file.

Namespaces

namespace  libsbx
 

Functions

template<floating_point Type>
constexpr auto sbx::math::mix (const Type x, const Type y, const Type a) -> Type
 Linearly interpolates between two values. More...
 
template<floating_point Type>
constexpr auto sbx::math::abs (const Type value) -> Type
 Computes the absolute value. More...
 
template<floating_point Type>
constexpr auto sbx::math::sqrt (const Type value) -> Type
 Computes the square root using iterative refinement. More...
 

Detailed Description

Generic math algorithms and helpers.

This header provides small, constexpr-friendly utilities for common mathematical operations on floating-point types. Implementations are provided in the accompanying .ipp file.

Author
KAJ

Function Documentation

◆ abs()

template<floating_point Type>
constexpr auto sbx::math::abs ( const Type  value) -> Type
inlineconstexpr

Computes the absolute value.

This function forwards to std::abs.

Template Parameters
TypeFloating-point type.
Parameters
valueInput value.
Returns
Absolute value of the input.

◆ mix()

template<floating_point Type>
constexpr auto sbx::math::mix ( const Type  x,
const Type  y,
const Type  a 
) -> Type
inlineconstexpr

Linearly interpolates between two values.

Computes x * (1 - a) + y * a.

Template Parameters
TypeFloating-point type.
Parameters
xStart value.
yEnd value.
aInterpolation factor.
Returns
Interpolated value.

◆ sqrt()

template<floating_point Type>
constexpr auto sbx::math::sqrt ( const Type  value) -> Type
inlineconstexpr

Computes the square root using iterative refinement.

This implementation uses Newton iteration to approximate the square root.

For negative inputs and positive infinity, this function returns quiet_NaN().

Template Parameters
TypeFloating-point type.
Parameters
valueInput value.
Returns
Square root approximation, or NaN for invalid inputs.