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