UnitMath(3)

UnitMath(3) Unit Conversion and Dimensional Analysis Library UnitMath(3)

NAME

UnitMath - Unit Math


- Defines a collection of unit-enabled, strongly-typed versions of <cmath> functions.

SYNOPSIS

Functions


template<class AngleUnit> dimensionless::scalar_t units::math::cos (const AngleUnit angle) noexcept
Compute cosine. template<class AngleUnit> dimensionless::scalar_t units::math::sin (const AngleUnit angle) noexcept
Compute sine. template<class AngleUnit> dimensionless::scalar_t units::math::tan (const AngleUnit angle) noexcept
Compute tangent. template<class ScalarUnit> angle::radian_t units::math::acos (const ScalarUnit x) noexcept
Compute arc cosine. template<class ScalarUnit> angle::radian_t units::math::asin (const ScalarUnit x) noexcept
Compute arc sine. template<class ScalarUnit> angle::radian_t units::math::atan (const ScalarUnit x) noexcept
Compute arc tangent. template<class Y, class X> angle::radian_t units::math::atan2 (const Y y, const X x) noexcept
Compute arc tangent with two parameters. template<class AngleUnit> dimensionless::scalar_t units::math::cosh (const AngleUnit angle) noexcept
Compute hyperbolic cosine. template<class AngleUnit> dimensionless::scalar_t units::math::sinh (const AngleUnit angle) noexcept
Compute hyperbolic sine. template<class AngleUnit> dimensionless::scalar_t units::math::tanh (const AngleUnit angle) noexcept
Compute hyperbolic tangent. template<class ScalarUnit> angle::radian_t units::math::acosh (const ScalarUnit x) noexcept
Compute arc hyperbolic cosine. template<class ScalarUnit> angle::radian_t units::math::asinh (const ScalarUnit x) noexcept
Compute arc hyperbolic sine. template<class ScalarUnit> angle::radian_t units::math::atanh (const ScalarUnit x) noexcept
Compute arc hyperbolic tangent. template<class ScalarUnit> dimensionless::scalar_t units::math::exp (const ScalarUnit x) noexcept
Compute exponential function. template<class ScalarUnit> dimensionless::scalar_t units::math::log (const ScalarUnit x) noexcept
Compute natural logarithm. template<class ScalarUnit> dimensionless::scalar_t units::math::log10 (const ScalarUnit x) noexcept
Compute common logarithm. template<class ScalarUnit> dimensionless::scalar_t units::math::modf (const ScalarUnit x, ScalarUnit *intpart) noexcept
Break into fractional and integral parts. template<class ScalarUnit> dimensionless::scalar_t units::math::exp2 (const ScalarUnit x) noexcept
Compute binary exponential function. template<class ScalarUnit> dimensionless::scalar_t units::math::expm1 (const ScalarUnit x) noexcept
Compute exponential minus one. template<class ScalarUnit> dimensionless::scalar_t units::math::log1p (const ScalarUnit x) noexcept
Compute logarithm plus one. template<class ScalarUnit> dimensionless::scalar_t units::math::log2 (const ScalarUnit x) noexcept
Compute binary logarithm. template<class UnitType, std::enable_if_t< units::traits::has_linear_scale< UnitType >::value, int > = 0> auto units::math::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> UnitTypeLhs units::math::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>> UnitType units::math::ceil (const UnitType x) noexcept
Round up value. template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::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>> UnitTypeLhs units::math::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>> UnitType units::math::trunc (const UnitType x) noexcept
Truncate value. template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::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>> UnitTypeLhs units::math::copysign (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
Copy sign. template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::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>> UnitTypeLhs units::math::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>> UnitTypeLhs units::math::fmin (const UnitTypeLhs x, const UnitTypeRhs y) noexcept
Minimum value. template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::fabs (const UnitType x) noexcept
Compute absolute value. template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::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 units::math::fma (const UnitTypeLhs x, const UnitMultiply y, const UnitAdd z) noexcept -> decltype(x *y)
Multiply-add.

Detailed Description

Defines a collection of unit-enabled, strongly-typed versions of <cmath> functions.

Includes most c++11 extensions.

Function Documentation

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::abs (const UnitType x) [noexcept]

Compute absolute value. Returns the absolute value of x, i.e. |x|.

Parameters

x Value whose absolute value is returned.

Returns

The absolute value of x.

template<class ScalarUnit> angle::radian_t units::math::acos (const ScalarUnit x) [noexcept]

Compute arc cosine. Returns the principal value of the arc cosine of x, expressed in radians.

Parameters

x Value whose arc cosine is computed, in the interval [-1,+1].

Returns

Principal arc cosine of x, in the interval [0,pi] radians.

template<class ScalarUnit> angle::radian_t units::math::acosh (const ScalarUnit x) [noexcept]

Compute arc hyperbolic cosine. Returns the nonnegative arc hyperbolic cosine of x, expressed in radians.

Parameters

x Value whose arc hyperbolic cosine is computed. If the argument is less than 1, a domain error occurs.

Returns

Nonnegative arc hyperbolic cosine of x, in the interval [0,+INFINITY] radians.

template<class ScalarUnit> angle::radian_t units::math::asin (const ScalarUnit x) [noexcept]

Compute arc sine. Returns the principal value of the arc sine of x, expressed in radians.

Parameters

x Value whose arc sine is computed, in the interval [-1,+1].

Returns

Principal arc sine of x, in the interval [-pi/2,+pi/2] radians.

template<class ScalarUnit> angle::radian_t units::math::asinh (const ScalarUnit x) [noexcept]

Compute arc hyperbolic sine. Returns the arc hyperbolic sine of x, expressed in radians.

Parameters

x Value whose arc hyperbolic sine is computed.

Returns

Arc hyperbolic sine of x, in radians.

template<class ScalarUnit> angle::radian_t units::math::atan (const ScalarUnit x) [noexcept]

Compute arc tangent. Returns the principal value of the arc tangent of x, expressed in radians. Notice that because of the sign ambiguity, the function cannot determine with certainty in which quadrant the angle falls only by its tangent value. See atan2 for an alternative that takes a fractional argument instead.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

x Value whose arc tangent is computed, in the interval [-1,+1].

Returns

Principal arc tangent of x, in the interval [-pi/2,+pi/2] radians.

template<class Y, class X> angle::radian_t units::math::atan2 (const Y y, const X x) [noexcept]

Compute arc tangent with two parameters. To compute the value, the function takes into account the sign of both arguments in order to determine the quadrant.

Parameters

y y-component of the triangle expressed.
x x-component of the triangle expressed.

Returns

Returns the principal value of the arc tangent of y/x, expressed in radians.

template<class ScalarUnit> angle::radian_t units::math::atanh (const ScalarUnit x) [noexcept]

Compute arc hyperbolic tangent. Returns the arc hyperbolic tangent of x, expressed in radians.

Parameters

x Value whose arc hyperbolic tangent is computed, in the interval [-1,+1]. If the argument is out of this interval, a domain error occurs. For values of -1 and +1, a pole error may occur.

Returns

units::angle::radian_t

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::ceil (const UnitType x) [noexcept]

Round up value. Rounds x upward, returning the smallest integral value that is not less than x.

Parameters

x Unit value to round up.

Returns

The smallest integral value that is not less than x.

template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::copysign (const UnitTypeLhs x, const UnitTypeRhs y) [noexcept]

Copy sign. Returns a value with the magnitude and dimension of x, and the sign of y. Values x and y do not have to be compatible units.

Parameters

x Value with the magnitude of the resulting value.
y Value with the sign of the resulting value.

Returns

value with the magnitude and dimension of x, and the sign of y.

template<class AngleUnit> dimensionless::scalar_t units::math::cos (const AngleUnit angle) [noexcept]

Compute cosine. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the cosine of

Returns

Returns the cosine of angle

template<class AngleUnit> dimensionless::scalar_t units::math::cosh (const AngleUnit angle) [noexcept]

Compute hyperbolic cosine. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the hyperbolic cosine of

Returns

Returns the hyperbolic cosine of angle

template<class ScalarUnit> dimensionless::scalar_t units::math::exp (const ScalarUnit x) [noexcept]

Compute exponential function. Returns the base-e exponential function of x, which is e raised to the power x: ex.

Parameters

x scalar value of the exponent.

Returns

Exponential value of x. If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL (or HUGE_VALF or HUGE_VALL) with the proper sign, and an overflow range error occurs

template<class ScalarUnit> dimensionless::scalar_t units::math::exp2 (const ScalarUnit x) [noexcept]

Compute binary exponential function. Returns the base-2 exponential function of x, which is 2 raised to the power x: 2^x. 2param[in] x Value of the exponent.

Returns

2 raised to the power of x.

template<class ScalarUnit> dimensionless::scalar_t units::math::expm1 (const ScalarUnit x) [noexcept]

Compute exponential minus one. Returns e raised to the power x minus one: e^x-1. For small magnitude values of x, expm1 may be more accurate than exp(x)-1.

Parameters

x Value of the exponent.

Returns

e raised to the power of x, minus one.

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::fabs (const UnitType x) [noexcept]

Compute absolute value. Returns the absolute value of x, i.e. |x|.

Parameters

x Value whose absolute value is returned.

Returns

The absolute value of x.

template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::fdim (const UnitTypeLhs x, const UnitTypeRhs y) [noexcept]

Positive difference. The function returns x-y if x>y, and zero otherwise, in the same units as x. Values x and y do not have to be the same type of units, but they do have to be compatible.

Parameters

x Values whose difference is calculated.
y Values whose difference is calculated.

Returns

The positive difference between x and y.

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::floor (const UnitType x) [noexcept]

Round down value. Rounds x downward, returning the largest integral value that is not greater than x.

Parameters

x Unit value to round down.

Returns

The value of x rounded downward.

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 units::math::fma (const UnitTypeLhs x, const UnitMultiply y, const UnitAdd z) -> decltype(x *y) [noexcept]

Multiply-add. Returns x*y+z. The function computes the result without losing precision in any intermediate result. The resulting unit type is a compound unit of x* y.

Parameters

x Values to be multiplied.
y Values to be multiplied.
z Value to be added.

Returns

The result of x*y+z

template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::fmax (const UnitTypeLhs x, const UnitTypeRhs y) [noexcept]

Maximum value. Returns the larger of its arguments: either x or y, in the same units as x. Values x and y do not have to be the same type of units, but they do have to be compatible.

Parameters

x Values among which the function selects a maximum.
y Values among which the function selects a maximum.

Returns

The maximum numeric value of its arguments.

template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::fmin (const UnitTypeLhs x, const UnitTypeRhs y) [noexcept]

Minimum value. Returns the smaller of its arguments: either x or y, in the same units as x. If one of the arguments in a NaN, the other is returned. Values x and y do not have to be the same type of units, but they do have to be compatible.

Parameters

x Values among which the function selects a minimum.
y Values among which the function selects a minimum.

Returns

The minimum numeric value of its arguments.

template<class UnitTypeLhs, class UnitTypeRhs, class = std::enable_if_t<traits::is_unit_t<UnitTypeLhs>::value && traits::is_unit_t<UnitTypeRhs>::value>> UnitTypeLhs units::math::fmod (const UnitTypeLhs numer, const UnitTypeRhs denom) [noexcept]

Compute remainder of division. Returns the floating-point remainder of numer/denom (rounded towards zero).

Parameters

numer Value of the quotient numerator.
denom Value of the quotient denominator.

Returns

The remainder of dividing the arguments.

template<class UnitTypeLhs, class UnitTypeRhs, std::enable_if_t< units::traits::has_linear_scale< UnitTypeLhs, UnitTypeRhs >::value, int > = 0> UnitTypeLhs units::math::hypot (const UnitTypeLhs & x, const UnitTypeRhs & y) [inline]

Computes the square root of the sum-of-squares of x and y. Only implemented for linear_scale units.

Parameters

x unit_t type value
y unit_t type value

Returns

square root of the sum-of-squares of x and y in the same units as x.

template<class ScalarUnit> dimensionless::scalar_t units::math::log (const ScalarUnit x) [noexcept]

Compute natural logarithm. Returns the natural logarithm of x.

Parameters

x scalar value whose logarithm is calculated. If the argument is negative, a domain error occurs.

See also

log10 for more common base-10 logarithms

Returns

Natural logarithm of x.

template<class ScalarUnit> dimensionless::scalar_t units::math::log10 (const ScalarUnit x) [noexcept]

Compute common logarithm. Returns the common (base-10) logarithm of x.

Parameters

x Value whose logarithm is calculated. If the argument is negative, a domain error occurs.

Returns

Common logarithm of x.

template<class ScalarUnit> dimensionless::scalar_t units::math::log1p (const ScalarUnit x) [noexcept]

Compute logarithm plus one. Returns the natural logarithm of one plus x. For small magnitude values of x, logp1 may be more accurate than log(1+x).

Parameters

x Value whose logarithm is calculated. If the argument is less than -1, a domain error occurs.

Returns

The natural logarithm of (1+x).

template<class ScalarUnit> dimensionless::scalar_t units::math::log2 (const ScalarUnit x) [noexcept]

Compute binary logarithm. Returns the binary (base-2) logarithm of x.

Parameters

x Value whose logarithm is calculated. If the argument is negative, a domain error occurs.

Returns

The binary logarithm of x: log2x.

template<class ScalarUnit> dimensionless::scalar_t units::math::modf (const ScalarUnit x, ScalarUnit * intpart) [noexcept]

Break into fractional and integral parts. The integer part is stored in the object pointed by intpart, and the fractional part is returned by the function. Both parts have the same sign as x.

Parameters

x scalar value to break into parts.
intpart Pointer to an object (of the same type as x) where the integral part is stored with the same sign as x.

Returns

The fractional part of x, with the same sign.

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::round (const UnitType x) [noexcept]

Round to nearest. Returns the integral value that is nearest to x, with halfway cases rounded away from zero.

Parameters

x value to round.

Returns

The value of x rounded to the nearest integral.

template<class AngleUnit> dimensionless::scalar_t units::math::sin (const AngleUnit angle) [noexcept]

Compute sine. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the since of

Returns

Returns the sine of angle

template<class AngleUnit> dimensionless::scalar_t units::math::sinh (const AngleUnit angle) [noexcept]

Compute hyperbolic sine. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the hyperbolic sine of

Returns

Returns the hyperbolic sine of angle

template<class UnitType, std::enable_if_t< units::traits::has_linear_scale< UnitType >::value, int > = 0> auto units::math::sqrt (const UnitType & value) -> unit_t< square_root< typename units::traits::unit_t_traits< UnitType >::unit_type >, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale > [inline], [noexcept]

computes the square root of value Only implemented for linear_scale units.

Parameters

value unit_t derived type to compute the square root of.

Returns

new unit_t, whose units are the square root of value's. E.g. if values had units of square_meter, then the return type will have units of meter.

Note

sqrt provides a rational approximation of the square root of value. In some cases, both the returned value and conversion factor of the returned unit type may have errors no larger than 1e-10.

template<class AngleUnit> dimensionless::scalar_t units::math::tan (const AngleUnit angle) [noexcept]

Compute tangent. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the tangent of

Returns

Returns the tangent of angle

template<class AngleUnit> dimensionless::scalar_t units::math::tanh (const AngleUnit angle) [noexcept]

Compute hyperbolic tangent. The input value can be in any unit of angle, including radians or degrees.

Template Parameters

AngleUnit any unit_t type of category::angle_unit.

Parameters

angle angle to compute the hyperbolic tangent of

Returns

Returns the hyperbolic tangent of angle

template<class UnitType, class = std::enable_if_t<traits::is_unit_t<UnitType>::value>> UnitType units::math::trunc (const UnitType x) [noexcept]

Truncate value. Rounds x toward zero, returning the nearest integral value that is not larger in magnitude than x. Effectively rounds towards 0.

Parameters

x Value to truncate

Returns

The nearest integral value that is not larger in magnitude than x.

Author

Generated automatically by Doxygen for Unit Conversion and Dimensional Analysis Library from the source code.

Wed Feb 11 2026 09:38:34 Version 2.3.0