12#define M_PI 3.14159265358979323846
55 T next = 0.5 * (curr + x / curr);
76 long double fact = 1.0;
78 for (
int i = 1; i < 10; ++i) {
80 fact *= (2 * i) * (2 * i + 1);
83 result -= power / fact;
85 result += power / fact;
104 long double fact = 1.0;
106 for (
int i = 1; i < 10; ++i) {
108 fact *= (2 * i - 1) * (2 * i);
111 result -= power / fact;
113 result += power / fact;
143requires std::is_floating_point_v<T>
145 return rad * 180.0 /
M_PI;
155requires std::is_floating_point_v<T>
157 return deg *
M_PI / 180.0;
180 if (std::is_constant_evaluated()) {
182 throw "Compile-time error: sqrt of negative number";
186 throw std::runtime_error(
"sqrt of negative number");
196 if (std::is_constant_evaluated()) {
215requires std::is_floating_point_v<T>
217 if (std::is_constant_evaluated()) {
218 constexpr T pi = T(
M_PI);
219 constexpr T two_pi = 2 * pi;
223 while (reduced_x > two_pi) { reduced_x -= two_pi; }
224 while (reduced_x < -two_pi) { reduced_x += two_pi; }
228 return -
sin(-reduced_x);
230 if (reduced_x > pi) {
231 return -
sin(reduced_x - pi);
233 if (reduced_x > pi / 2) {
234 return sin(pi - reduced_x);
251requires std::is_floating_point_v<T>
253 if (std::is_constant_evaluated()) {
270requires std::is_floating_point_v<T>
286requires std::is_floating_point_v<T>
300requires std::is_floating_point_v<T>
314requires std::is_floating_point_v<T>
328requires std::is_floating_point_v<T>
342requires std::is_floating_point_v<T>
#define M_PI
Define _USE_MATH_DEFINES for M_PI on MSVC, or just define pi ourselves for portability.
Definition function.hpp:12
Defines the primary floating-point type alias for the math library.
#define EPSILON
The epsilon value used for floating-point comparisons.
Definition global.hpp:41
Contains internal implementation details for the math library.
Definition function.hpp:33
constexpr T sqrt_newton_raphson(T x, T curr, T prev)
A constexpr implementation of the square root function using the Newton-Raphson method.
Definition function.hpp:47
constexpr T sin_taylor(T x)
A constexpr implementation of the sine function using a Taylor series expansion.
Definition function.hpp:71
constexpr T cos_taylor(T x)
A constexpr implementation of the cosine function using a Taylor series expansion.
Definition function.hpp:100
The namespace for math library implementation.
Definition bounding_box.hpp:9
constexpr T rad2deg(T rad)
Converts an angle from radians to degrees.
Definition function.hpp:144
constexpr T deg2rad(T deg)
Converts an angle from degrees to radians.
Definition function.hpp:156
constexpr T sqrt(T x)
Calculates the square root of a number with constexpr support.
Definition function.hpp:177
constexpr bool is_greater_equal(T a, T b)
Compares if a is greater than or equal to b.
Definition function.hpp:343
constexpr bool is_greater(T a, T b)
Compares if a is greater than b.
Definition function.hpp:301
constexpr T cos(T x)
Calculates the cosine of an angle with constexpr support.
Definition function.hpp:252
constexpr T abs(T x)
A constexpr implementation of the absolute value function.
Definition function.hpp:128
constexpr bool is_less_equal(T a, T b)
Compares if a is less than or equal to b.
Definition function.hpp:315
constexpr bool is_equal(T a, T b)
Compares two floating-point values for equality.
Definition function.hpp:287
constexpr T sin(T x)
Calculates the sine of an angle with constexpr support.
Definition function.hpp:216
constexpr bool is_less(T a, T b)
Compares if a is less than b.
Definition function.hpp:329
constexpr T tan(T x)
Calculates the tangent of an angle with constexpr support.
Definition function.hpp:271