opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
constants.h
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <limits>
5#include <numbers>
6
7namespace osc
8{
9 namespace detail
10 {
11 // This stuff is necessary because `std::sqrt` isn't `constexpr` yet.
12
13 template<typename T>
15
16 template<>
17 struct sqrt_epsilon_impl<float> { static constexpr float value = 0.00034526698f; };
18
19 template<>
20 struct sqrt_epsilon_impl<double> { static constexpr double value = 0.000000014901161193847656; };
21 }
22
23 // the mathematical constant, pi
24 template<std::floating_point T>
25 inline constexpr T pi_v = std::numbers::pi_v<T>;
26
27 // the difference between `T{1}` and the next representable value of the given floating-point type
28 template<std::floating_point T>
29 inline constexpr T epsilon_v = std::numeric_limits<T>::epsilon();
30
31 // The square root of `epsilon_v` for `T`
32 template<std::floating_point T>
34
35 // a quiet Not-a-Number (NaN) value of the given floating-point type
36 template<std::floating_point T>
37 inline constexpr T quiet_nan_v = std::numeric_limits<T>::quiet_NaN();
38
39 // A multiplier that converts a degree value of type `T` to radians.
40 template<std::floating_point T>
41 inline constexpr T deg_to_rad_v = pi_v<T> / T{180};
42
43 // A multiplier that converts a radians value of type `T` to degrees.
44 template<std::floating_point T>
45 inline constexpr T rad_to_deg_v = T{180} / pi_v<T>;
46
47 // The maximum absolute dot product between two unit vectors such that
48 // normalizing their cross-product remains numerically stable.
49 template<std::floating_point T>
50 inline constexpr T max_abs_dot_for_cross_v = T(1) - sqrt_epsilon_v<T>;
51}
Definition custom_decoration_generator.h:5
constexpr T pi_v
Definition constants.h:25
constexpr T epsilon_v
Definition constants.h:29
constexpr T deg_to_rad_v
Definition constants.h:41
constexpr T quiet_nan_v
Definition constants.h:37
constexpr T sqrt_epsilon_v
Definition constants.h:33
constexpr T max_abs_dot_for_cross_v
Definition constants.h:50
constexpr T rad_to_deg_v
Definition constants.h:45
Definition constants.h:14