LOST 0.0.1
LOST: Open-source Star Tracker
Loading...
Searching...
No Matches
decimal.hpp
Go to the documentation of this file.
1#ifndef DECIMAL_H
2#define DECIMAL_H
3
4#include <cmath>
5#include <string>
6
7#ifdef LOST_FLOAT_MODE
8 typedef float decimal;
9 #define STR_TO_DECIMAL(x) std::stof(x)
10#else
11 typedef double decimal;
12 #define STR_TO_DECIMAL(x) std::stod(x)
13#endif
14
15// This should only be used sparingly.
16// It's better to verbosely typecast sometimes. Only use these to prevent promotions.
17// The reason why this isn't used everywhere instead of the wrapped macros is
18// because the code becomes hard to read when there are multiple layers of typecasting.
19// With this method, we might have more preprocessing to do BUT the code remains readable
20// as the methods remain relatively the same.
21#define DECIMAL(x) ((decimal) x)
22
23// Math Constants wrapped with Decimal typecast
24#define DECIMAL_M_E ((decimal) M_E) /* e */
25#define DECIMAL_M_LOG2E ((decimal) M_LOG2E) /* log_2 e */
26#define DECIMAL_M_LOG10E ((decimal) M_LOG10E) /* log_10 e */
27#define DECIMAL_M_LN2 ((decimal) M_LN2) /* log_e 2 */
28#define DECIMAL_M_LN10 ((decimal) M_LN10) /* log_e 10 */
29#define DECIMAL_M_PI ((decimal) M_PI) /* pi */
30#define DECIMAL_M_PI_2 ((decimal) M_PI_2) /* pi/2 */
31#define DECIMAL_M_PI_4 ((decimal) M_PI_4) /* pi/4 */
32#define DECIMAL_M_1_PI ((decimal) M_1_PI) /* 1/pi */
33#define DECIMAL_M_2_PI ((decimal) M_2_PI) /* 2/pi */
34#define DECIMAL_M_2_SQRTPI ((decimal) M_2_SQRTPI) /* 2/sqrt(pi) */
35#define DECIMAL_M_SQRT2 ((decimal) M_SQRT2) /* sqrt(2) */
36#define DECIMAL_M_SQRT1_2 ((decimal) M_SQRT1_2) /* 1/sqrt(2) */
37
38// Math Functions wrapped with Decimal typecast
39#define DECIMAL_POW(base,power) ((decimal) std::pow(base, power))
40#define DECIMAL_SQRT(x) ((decimal) std::sqrt(x))
41#define DECIMAL_LOG(x) ((decimal) std::log(x))
42#define DECIMAL_EXP(x) ((decimal) std::exp(x))
43#define DECIMAL_ERF(x) ((decimal) std::erf(x))
44
45// Rouding methods wrapped with Decimal typecast)
46#define DECIMAL_ROUND(x) ((decimal) std::round(x))
47#define DECIMAL_CEIL(x) ((decimal) std::ceil(x))
48#define DECIMAL_FLOOR(x) ((decimal) std::floor(x))
49#define DECIMAL_ABS(x) ((decimal) std::abs(x))
50
51// Trig Methods wrapped with Decimal typecast)
52#define DECIMAL_SIN(x) ((decimal) std::sin(x))
53#define DECIMAL_COS(x) ((decimal) std::cos(x))
54#define DECIMAL_TAN(x) ((decimal) std::tan(x))
55#define DECIMAL_ASIN(x) ((decimal) std::asin(x))
56#define DECIMAL_ACOS(x) ((decimal) std::acos(x))
57#define DECIMAL_ATAN(x) ((decimal) std::atan(x))
58#define DECIMAL_ATAN2(x,y) ((decimal) std::atan2(x,y))
59
60// Float methods wrapped with Decimal typecast)
61#define DECIMAL_FMA(x,y,z) ((decimal) std::fma(x,y,z))
62#define DECIMAL_HYPOT(x,y) ((decimal) std::hypot(x,y))
63
64#endif // decimal.hpp
double decimal
Definition decimal.hpp:11