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