teditor
1.8.0@@fee5e94
Terminal based editor written in C++
|
Go to the documentation of this file.
9 template <
typename T> T
sq(T in) {
return in * in; }
10 template <
typename T> T
cube(T in) {
return in * in * in; }
16 #define OP(b, op) do { \
17 if (isInt && b.isInt) { \
19 } else if (isInt && !b.isInt) { \
21 f = FloatT(i) op b.f; \
22 } else if (!isInt && b.isInt) { \
23 f = f op FloatT(b.i); \
30 #define B_OP(b, op) do { \
31 if (isInt && b.isInt) return i op b.i; \
32 if (isInt && !b.isInt) return FloatT(i) op b.f; \
33 if (!isInt && b.isInt) return f op FloatT(b.i); \
39 T toNumber(
const std::string& str,
bool& processed);
41 int32_t toNumber(
const std::string& str,
bool& processed) {
43 auto i = std::stoi(str, &pos);
44 processed = pos == str.size();
48 int64_t toNumber(
const std::string& str,
bool& processed) {
50 auto i = std::stol(str, &pos);
51 processed = pos == str.size();
55 float toNumber(
const std::string& str,
bool& processed) {
57 auto i = std::stof(str, &pos);
58 processed = pos == str.size();
62 double toNumber(
const std::string& str,
bool& processed) {
64 auto i = std::stod(str, &pos);
65 processed = pos == str.size();
75 template <
typename IntT,
typename FloatT>
93 IntT tmpi = toNumber<IntT>(str, processed);
99 FloatT tmpf = toNumber<FloatT>(str, processed);
105 ASSERT(
false,
"Incorrect number passed '%s'!", str.c_str());
148 ret.
f = FloatT(ret.
i);
166 #define CONST(var, val) \
167 template <typename I, typename F> \
168 const Number<I, F> Number<I, F>::var((F)val)
172 CONST(log2e, M_LOG2E);
173 CONST(log10e, M_LOG10E);
174 CONST(sqrt2, M_SQRT2);
175 CONST(sqrt1_2, M_SQRT1_2);
180 template <
typename I,
typename F>
186 template <
typename I,
typename F>
192 template <
typename I,
typename F>
198 template <
typename I,
typename F>
207 template <typename I, typename F> \
208 Number<I, F> name(const Number<I, F>& in) { \
210 out.isInt = in.isInt; \
212 out.i = std::name(in.i); \
214 out.f = std::name(in.f); \
223 #define FP_FUNC(name) \
224 template <typename I, typename F> \
225 Number<I, F> name(const Number<I, F>& in) { \
228 out.f = std::name(in.isInt ? F(in.i) : in.f); \
253 template <
typename I,
typename F>
255 template <
typename I,
typename F>
258 #define FP_FUNC2(name) \
259 template <typename I, typename F> \
260 Number<I, F> name(const Number<I, F>& in1, const Number<I, F>& in2) { \
263 out.f = std::name(in1.isInt ? F(in1.i) : in1.f, \
264 in2.isInt ? F(in2.i) : in2.f); \
static const Num e
Definition: number.h:153
static const Num log10e
Definition: number.h:157
bool operator<(const Num &b) const
Definition: number.h:130
T sq(T in)
Definition: number.h:9
Num & operator-()
Definition: number.h:115
Core number used for computing in the calculator.
Definition: number.h:76
bool operator!=(const Num &b) const
Definition: number.h:129
#define OP(b, op)
Definition: number.h:16
Number< I, F > toFloat(const Number< I, F > &a)
Definition: number.h:256
static const Num sqrt1_2
Definition: number.h:159
T cube(T in)
Definition: number.h:10
#define B_OP(b, op)
Definition: number.h:30
Num toInt() const
Definition: number.h:136
static const Num log2e
Definition: number.h:156
Number< I, F > operator+(const Number< I, F > &a, const Number< I, F > &b)
Definition: number.h:181
Number< I, F > toInt(const Number< I, F > &a)
Definition: number.h:254
bool operator>(const Num &b) const
Definition: number.h:132
Num & operator+()
Definition: number.h:114
Number()
Definition: number.h:87
Number< IntT, FloatT > Num
Definition: number.h:77
Number< I, F > operator*(const Number< I, F > &a, const Number< I, F > &b)
Definition: number.h:193
Number< int32_t, float > Num32
Definition: number.h:271
Num toFloat() const
Definition: number.h:144
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
const Num & operator-=(const Num &b)
Definition: number.h:123
Number(IntT v)
Definition: number.h:88
Number(const std::string &str)
Definition: number.h:91
Number< I, F > operator/(const Number< I, F > &a, const Number< I, F > &b)
Definition: number.h:199
const Num & operator/=(const Num &b)
Definition: number.h:125
const Num & operator*=(const Num &b)
Definition: number.h:124
Number(const Num &n)
Definition: number.h:90
bool operator>=(const Num &b) const
Definition: number.h:133
Number(FloatT v)
Definition: number.h:89
static const Num sqrt2
Definition: number.h:158
Number< I, F > operator-(const Number< I, F > &a, const Number< I, F > &b)
Definition: number.h:187
IntT i
Definition: number.h:81
bool operator==(const Num &b) const
Definition: number.h:128
const Num & operator+=(const Num &b)
Definition: number.h:122
bool isInt
Definition: number.h:85
FloatT f
Definition: number.h:82
const Num & operator=(const Num &n)
Definition: number.h:108
Number< int64_t, double > Num64
Definition: number.h:272
static const Num nan
Definition: number.h:155
bool operator<=(const Num &b) const
Definition: number.h:131
static const Num pi
Definition: number.h:154