WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
units::math Namespace Reference

namespace for unit-enabled versions of the <cmath> library More...

Functions

template<int power, class UnitType , class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
constexpr auto pow (const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
 computes the value of value raised to the power
 
template<int power, class UnitType , class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
constexpr auto cpow (const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
 computes the value of value raised to the power as a constexpr
 
template<class UnitTypeLhs , class UnitTypeRhs >
constexpr UnitTypeLhs min (const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
 
template<class UnitTypeLhs , class UnitTypeRhs >
constexpr UnitTypeLhs max (const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
 
template<class AngleUnit >
constexpr dimensionless::scalar_t cos (const AngleUnit angle) noexcept
 Compute cosine.
 
template<class AngleUnit >
constexpr dimensionless::scalar_t sin (const AngleUnit angle) noexcept
 Compute sine.
 
template<class AngleUnit >
constexpr dimensionless::scalar_t tan (const AngleUnit angle) noexcept
 Compute tangent.
 
template<class ScalarUnit >
constexpr angle::radian_t acos (const ScalarUnit x) noexcept
 Compute arc cosine.
 
template<class ScalarUnit >
constexpr angle::radian_t asin (const ScalarUnit x) noexcept
 Compute arc sine.
 
template<class ScalarUnit >
constexpr angle::radian_t atan (const ScalarUnit x) noexcept
 Compute arc tangent.
 
template<class Y , class X >
constexpr angle::radian_t atan2 (const Y y, const X x) noexcept
 Compute arc tangent with two parameters.
 
template<class AngleUnit >
constexpr dimensionless::scalar_t cosh (const AngleUnit angle) noexcept
 Compute hyperbolic cosine.
 
template<class AngleUnit >
constexpr dimensionless::scalar_t sinh (const AngleUnit angle) noexcept
 Compute hyperbolic sine.
 
template<class AngleUnit >
constexpr dimensionless::scalar_t tanh (const AngleUnit angle) noexcept
 Compute hyperbolic tangent.
 
template<class ScalarUnit >
constexpr angle::radian_t acosh (const ScalarUnit x) noexcept
 Compute arc hyperbolic cosine.
 
template<class ScalarUnit >
constexpr angle::radian_t asinh (const ScalarUnit x) noexcept
 Compute arc hyperbolic sine.
 
template<class ScalarUnit >
constexpr angle::radian_t atanh (const ScalarUnit x) noexcept
 Compute arc hyperbolic tangent.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t exp (const ScalarUnit x) noexcept
 Compute exponential function.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t log (const ScalarUnit x) noexcept
 Compute natural logarithm.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t log10 (const ScalarUnit x) noexcept
 Compute common logarithm.
 
template<class ScalarUnit >
dimensionless::scalar_t modf (const ScalarUnit x, ScalarUnit *intpart) noexcept
 Break into fractional and integral parts.
 
template<class ScalarUnit >
dimensionless::scalar_t exp2 (const ScalarUnit x) noexcept
 Compute binary exponential function.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t expm1 (const ScalarUnit x) noexcept
 Compute exponential minus one.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t log1p (const ScalarUnit x) noexcept
 Compute logarithm plus one.
 
template<class ScalarUnit >
constexpr dimensionless::scalar_t log2 (const ScalarUnit x) noexcept
 Compute binary logarithm.
 
template<class UnitType , std::enable_if_t< units::traits::has_linear_scale< UnitType >::value, int > = 0>
constexpr auto sqrt (const UnitType &value) noexcept -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
 computes the square root of value
 
template<class UnitTypeLhs , class UnitTypeRhs , std::enable_if_t< units::traits::has_linear_scale< UnitTypeLhs, UnitTypeRhs >::value, int > = 0>
constexpr UnitTypeLhs hypot (const UnitTypeLhs &x, const UnitTypeRhs &y)
 Computes the square root of the sum-of-squares of x and y.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType ceil (const UnitType x) noexcept
 Round up value.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType floor (const UnitType x) noexcept
 Round down value.
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
constexpr UnitTypeLhs fmod (const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept
 Compute remainder of division.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType trunc (const UnitType x) noexcept
 Truncate value.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType round (const UnitType x) noexcept
 Round to nearest.
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
constexpr UnitTypeLhs copysign (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Copy sign.
 
template<class UnitTypeLhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value>>
constexpr UnitTypeLhs copysign (const UnitTypeLhs x, const UNIT_LIB_DEFAULT_TYPE y) noexcept
 Overload to copy the sign from a raw double.
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
UnitTypeLhs fdim (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Positive difference.
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
constexpr UnitTypeLhs fmax (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Maximum value.
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
constexpr UnitTypeLhs fmin (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Minimum value.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType fabs (const UnitType x) noexcept
 Compute absolute value.
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
constexpr UnitType abs (const UnitType x) noexcept
 Compute absolute value.
 
template<class UnitTypeLhs , class UnitMultiply , class UnitAdd , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitMultiply>::value && traits::is_unit_t<UnitAdd>::value>>
auto fma (const UnitTypeLhs x, const UnitMultiply y, const UnitAdd z) noexcept -> decltype(x *y)
 Multiply-add.
 

Detailed Description

namespace for unit-enabled versions of the <cmath> library

Includes trigonometric functions, exponential/log functions, rounding functions, etc.

See also
See unit_t for more information on unit type containers.

Function Documentation

◆ copysign()

template<class UnitTypeLhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value>>
UnitTypeLhs units::math::copysign ( const UnitTypeLhs x,
const UNIT_LIB_DEFAULT_TYPE y )
constexprnoexcept

Overload to copy the sign from a raw double.

◆ cpow()

template<int power, class UnitType , class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
auto units::math::cpow ( const UnitType & value) -> unit_t<typename units::detail::power_of_unit<power, typename units::traits::unit_t_traits<UnitType>::unit_type>::type, typename units::traits::unit_t_traits<UnitType>::underlying_type, linear_scale>
constexprnoexcept

computes the value of value raised to the power as a constexpr

Only implemented for linear_scale units. Power must be known at compile time, so the resulting unit type can be deduced. Additionally, the power must be a positive, integral, value.

Template Parameters
powerexponential power to raise value by.
Parameters
[in]valueunit_t derived type to raise to the given power
Returns:
new unit_t, raised to the given exponent

◆ max()

template<class UnitTypeLhs , class UnitTypeRhs >
UnitTypeLhs units::math::max ( const UnitTypeLhs & lhs,
const UnitTypeRhs & rhs )
constexpr

◆ min()

template<class UnitTypeLhs , class UnitTypeRhs >
UnitTypeLhs units::math::min ( const UnitTypeLhs & lhs,
const UnitTypeRhs & rhs )
constexpr

◆ pow()

template<int power, class UnitType , class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
auto units::math::pow ( const UnitType & value) -> unit_t<typename units::detail::power_of_unit<power, typename units::traits::unit_t_traits<UnitType>::unit_type>::type, typename units::traits::unit_t_traits<UnitType>::underlying_type, linear_scale>
constexprnoexcept

computes the value of value raised to the power

Only implemented for linear_scale units. Power must be known at compile time, so the resulting unit type can be deduced.

Template Parameters
powerexponential power to raise value by.
Parameters
[in]valueunit_t derived type to raise to the given power
Returns:
new unit_t, raised to the given exponent