WPILibC++ 2023.4.3
units::math Namespace Reference

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

Functions

template<class AngleUnit >
dimensionless::scalar_t cos (const AngleUnit angle) noexcept
 Compute cosine. More...
 
template<class AngleUnit >
dimensionless::scalar_t sin (const AngleUnit angle) noexcept
 Compute sine. More...
 
template<class AngleUnit >
dimensionless::scalar_t tan (const AngleUnit angle) noexcept
 Compute tangent. More...
 
template<class ScalarUnit >
angle::radian_t acos (const ScalarUnit x) noexcept
 Compute arc cosine. More...
 
template<class ScalarUnit >
angle::radian_t asin (const ScalarUnit x) noexcept
 Compute arc sine. More...
 
template<class ScalarUnit >
angle::radian_t atan (const ScalarUnit x) noexcept
 Compute arc tangent. More...
 
template<class Y , class X >
angle::radian_t atan2 (const Y y, const X x) noexcept
 Compute arc tangent with two parameters. More...
 
template<class AngleUnit >
dimensionless::scalar_t cosh (const AngleUnit angle) noexcept
 Compute hyperbolic cosine. More...
 
template<class AngleUnit >
dimensionless::scalar_t sinh (const AngleUnit angle) noexcept
 Compute hyperbolic sine. More...
 
template<class AngleUnit >
dimensionless::scalar_t tanh (const AngleUnit angle) noexcept
 Compute hyperbolic tangent. More...
 
template<class ScalarUnit >
angle::radian_t acosh (const ScalarUnit x) noexcept
 Compute arc hyperbolic cosine. More...
 
template<class ScalarUnit >
angle::radian_t asinh (const ScalarUnit x) noexcept
 Compute arc hyperbolic sine. More...
 
template<class ScalarUnit >
angle::radian_t atanh (const ScalarUnit x) noexcept
 Compute arc hyperbolic tangent. More...
 
template<class ScalarUnit >
dimensionless::scalar_t exp (const ScalarUnit x) noexcept
 Compute exponential function. More...
 
template<class ScalarUnit >
dimensionless::scalar_t log (const ScalarUnit x) noexcept
 Compute natural logarithm. More...
 
template<class ScalarUnit >
dimensionless::scalar_t log10 (const ScalarUnit x) noexcept
 Compute common logarithm. More...
 
template<class ScalarUnit >
dimensionless::scalar_t modf (const ScalarUnit x, ScalarUnit *intpart) noexcept
 Break into fractional and integral parts. More...
 
template<class ScalarUnit >
dimensionless::scalar_t exp2 (const ScalarUnit x) noexcept
 Compute binary exponential function. More...
 
template<class ScalarUnit >
dimensionless::scalar_t expm1 (const ScalarUnit x) noexcept
 Compute exponential minus one. More...
 
template<class ScalarUnit >
dimensionless::scalar_t log1p (const ScalarUnit x) noexcept
 Compute logarithm plus one. More...
 
template<class ScalarUnit >
dimensionless::scalar_t log2 (const ScalarUnit x) noexcept
 Compute binary logarithm. More...
 
template<class UnitType , std::enable_if_t< units::traits::has_linear_scale< UnitType >::value, int > = 0>
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 More...
 
template<class UnitTypeLhs , class UnitTypeRhs , std::enable_if_t< units::traits::has_linear_scale< UnitTypeLhs, UnitTypeRhs >::value, int > = 0>
UnitTypeLhs hypot (const UnitTypeLhs &x, const UnitTypeRhs &y)
 Computes the square root of the sum-of-squares of x and y. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType ceil (const UnitType x) noexcept
 Round up value. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType floor (const UnitType x) noexcept
 Round down value. More...
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
UnitTypeLhs fmod (const UnitTypeLhs numer, const UnitTypeRhs denom) noexcept
 Compute remainder of division. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType trunc (const UnitType x) noexcept
 Truncate value. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType round (const UnitType x) noexcept
 Round to nearest. More...
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
UnitTypeLhs copysign (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Copy sign. More...
 
template<class UnitTypeLhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value>>
UnitTypeLhs copysign (const UnitTypeLhs x, const UNIT_LIB_DEFAULT_TYPE y) noexcept
 Overload to copy the sign from a raw double. More...
 
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. More...
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
UnitTypeLhs fmax (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Maximum value. More...
 
template<class UnitTypeLhs , class UnitTypeRhs , class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>>
UnitTypeLhs fmin (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
 Minimum value. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType fabs (const UnitType x) noexcept
 Compute absolute value. More...
 
template<class UnitType , class = std::enable_if_t<traits::is_unit_t<UnitType>::value>>
UnitType abs (const UnitType x) noexcept
 Compute absolute value. More...
 
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. More...
 
template<int power, class UnitType , class = typename std::enable_if<traits::has_linear_scale<UnitType>::value, int>>
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 More...
 
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 More...
 
template<class UnitTypeLhs , class UnitTypeRhs >
UnitTypeLhs() min (const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
 
template<class UnitTypeLhs , class UnitTypeRhs >
UnitTypeLhs() max (const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
 

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 
)
noexcept

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>>
constexpr 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>
inlineconstexprnoexcept

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 
)

◆ min()

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

◆ 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>
inlinenoexcept

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