HRCore V1.1.0
A High Resolution Calculation Library
Loading...
Searching...
No Matches
HRCore.h
Go to the documentation of this file.
1
12#pragma once
13
14// ============================ Begin User Configure =============================
15
32#define HRCORE_DEBUG_LEVEL 2
33
34#ifndef HRCORE_HIGHPERF
40#define HRCORE_HIGHPERF 0
41#endif
42
43#ifndef HRCORE_UNIT_SIZE
49#define HRCORE_UNIT_SIZE 32
50#endif
51
55#ifndef HRCORE_ENABLE_IO_DELIMETER
56#define HRCORE_ENABLE_IO_DELIMETER 1
57#endif
58
59#ifndef HRCORE_ENABLE_MD
65#define HRCORE_ENABLE_MD 1
66#endif
67
68#ifndef HRCORE_ENABLE_FP
74#define HRCORE_ENABLE_FP 1
75#endif
76
83#ifndef HRCORE_FP_BITS_BASE
84#define HRCORE_FP_BITS_BASE 24
85#endif
86
93#ifndef HRCORE_FP_BITS_PER_DIGIT
94#define HRCORE_FP_BITS_PER_DIGIT 8
95#endif
96
100#ifndef HRCORE_FP_DEFAULT_PRECISION
101#define HRCORE_FP_DEFAULT_PRECISION 10
102#endif
103
108#ifndef HRCORE_ENABLE_STORAGE_VMMU
109#define HRCORE_ENABLE_STORAGE_VMMU 1
110#endif
111
117#ifndef HRCORE_STORAGE_VMMU_MAX_LEN
118#define HRCORE_STORAGE_VMMU_MAX_LEN 1024
119#endif
120
124#ifndef HRCORE_ENABLE_UTILS
125#define HRCORE_ENABLE_UTILS 1
126
131#ifndef HRCORE_ENABLE_UTILS_IO
132#define HRCORE_ENABLE_UTILS_IO 1
133#endif
134
135#endif
136
138
139// ================================ End User Configure =============================
140
141#ifndef __MERGE__ // Define this to avoid preprocessor join STL headers into merged file
142#include <algorithm>
143#include <iostream>
144#include <exception>
145#include <cstdint>
146
147#include <deque> // For expressions
148#include <stack>
149#include <complex> // For FFT support in the future
150
151#endif
152
153// Pre-compile checks
154#if HRCORE_DEBUG_LEVEL >= 4
155#define HRCORE_DBG(x) x
156#else
157#define HRCORE_DBG(x)
158#endif
159
160#if HRCORE_DEBUG_LEVEL >= 3
161#define HRCORE_DBGI(x) x
162#else
163#define HRCORE_DBGI(x)
164#endif
165
166#if HRCORE_DEBUG_LEVEL >= 2
167#define HRCORE_DBGW(x) x
168#else
169#define HRCORE_DBGW(x)
170#endif
171
172#if HRCORE_DEBUG_LEVEL >= 1
173#define HRCORE_DBGE(x) x
174#else
175#define HRCORE_DBGE(x)
176#endif
177
178#if HRCORE_ENABLE_FP
179
180#if HRCORE_FP_BITS_BASE < 16
181#warning HRCORE_FP_BITS_BASE too small! Float may lose precision.
182#endif
183
184#if HRCORE_FP_BITS_PER_DIGIT < 6
185#warning HRCORE_FP_BITS_PER_DIGIT too small! Float may lose precision.
186#endif
187
188#endif
189
195namespace HRCore {
196
197#if (HRCORE_UNIT_SIZE == 16)
198using ival_t = uint16_t;
199using idval_t = uint32_t;
200#define HRCORE_UNIT_DIV 4
201#elif (HRCORE_UNIT_SIZE == 32)
202using ival_t = uint32_t;
203using idval_t = uint64_t;
204#define HRCORE_UNIT_DIV 5
205#elif (HRCORE_UNIT_SIZE == 64)
206using ival_t = uint64_t;
207using idval_t = __uint128_t; // Only support with GCC
208#define HRCORE_UNIT_DIV 6
209#else
210#error Invalid Unit Size (i.e. macro HRCORE_UNIT_SIZE) provided!
211#endif
212
214using complex_t = std::complex<float>;
215
217namespace Exception {
218
229#ifndef __HRCORE_EXCEPTION_HELPER__
230#define __HRCORE_EXCEPTION_HELPER__(w) \
231 : public std::exception \
232 { \
233 public: \
234 const char* what() const throw() override \
235 { \
236 return w; \
237 } \
238 }
239#endif
240
241 class InternalError __HRCORE_EXCEPTION_HELPER__("HRCore internal error");
242 class LLR __HRCORE_EXCEPTION_HELPER__("Left operator argument is not bigger than right");
243 class InvalidArgument __HRCORE_EXCEPTION_HELPER__("Invalid argument provided");
244 class DividedByZero __HRCORE_EXCEPTION_HELPER__("Devided by 0 is not allowed");
245
246#if HRCORE_ENABLE_FP
247 // class FPAdjustFailed __HRCORE_EXCEPTION_HELPER__("FixedPoint adjust point failed"); ///< @brief Exception of FixedPoint adjust point failed
248 class FPConvertFailed __HRCORE_EXCEPTION_HELPER__("FixedPoint failed to convert");
249#endif
250
251#if HRCORE_ENABLE_UTILS_IO
253 class ExpressionConvertFailed __HRCORE_EXCEPTION_HELPER__("Expression Failed to convert! Maybe the expression is invalid?");
255 class ExpressionInvalidOperation __HRCORE_EXCEPTION_HELPER__("Invalid operation on seleted data type");
256#endif
257
259} // namespace Exception
260}
261
262#include "inc/StorageIF.hpp"
263#include "inc/VirtualMMU.hpp"
264#include "inc/LinkedList.hpp"
265#include "inc/Value.hpp"
266#include "inc/Utils.hpp"
267
268namespace HRCore {
269using BINT = Value::Integer;
270
271#if HRCORE_ENABLE_FP
272using BFLOAT = Value::Float;
273#endif
274
275#if HRCORE_ENABLE_UTILS_IO
276template <typename T, typename U>
278#endif
279
280} // namespace HRCore
Linked List implement of Storage::Interface.
Storage Interface.
Privide utils for HRCore.
Implements of mathematic data type and calculation.
Virtual MMU implement of Storage::Interface.
Exception of divided by 0.
Definition: HRCore.h:244
Exception os Expression failed to convert.
Definition: HRCore.h:253
Exception of Expression evaluation: Invalid operation on seleted data type.
Definition: HRCore.h:255
Exception of FixedPoint failed to input.
Definition: HRCore.h:248
Exception of internal error. Please dig into it and solve.
Definition: HRCore.h:241
Exception of Invalid Argument.
Definition: HRCore.h:243
Exception of left < right.
Definition: HRCore.h:242
A class to get and evaluate expression.
Definition: Utils.hpp:431
Float type.
Definition: Value.hpp:648
Integer type.
Definition: Value.hpp:27
#define __HRCORE_EXCEPTION_HELPER__(w)
HRCore general exception implenent macro defination.
Definition: HRCore.h:230
HRCore main namespace, contains all classes.
Definition: LinkedList.hpp:14
std::complex< float > complex_t
Complex number type using std::complex<float>
Definition: HRCore.h:214