Defines a series of classes to obtain unit type information at compile-time.
More...
|
namespace | units::traits |
| namespace representing type traits which can access the properties of types provided by the units library.
|
|
|
template<typename Ratio , std::intmax_t Eps = 10000000000> |
using | units::ratio_sqrt = typename units::detail::Sqrt< Ratio, std::ratio< 1, Eps > >::type |
| Calculate square root of a ratio at compile-time. More...
|
|
Defines a series of classes to obtain unit type information at compile-time.
◆ ratio_sqrt
template<typename Ratio , std::intmax_t Eps = 10000000000>
Calculate square root of a ratio at compile-time.
Calculates a rational approximation of the square root of the ratio. The error in the calculation is bounded by 1/epsilon (Eps). E.g. for the default value of 10000000000, the maximum error will be a/10000000000, or 1e-8, or said another way, the error will be on the order of 10^-9. Since these calculations are done at compile time, it is advisable to set epsilon to the highest value that does not cause an integer overflow in the calculation. If you can't compile ratio_sqrt
due to overflow errors, reducing the value of epsilon sufficiently will correct the problem.
ratio_sqrt
is guaranteed to converge for all values of Ratio
which do not overflow.
- Note
- This function provides a rational approximation, NOT an exact value.
- Template Parameters
-
Ratio | ratio to take the square root of. This can represent any rational value, not just integers or values with integer roots. |
Eps | Value of epsilon, which represents the inverse of the maximum allowable error. This value should be chosen to be as high as possible before integer overflow errors occur in the compiler. |