teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Classes | Namespaces | Macros | Typedefs | Functions
number.h File Reference
#include <stdint.h>
#include <cmath>
#include <string>
#include "core/utils.h"

Go to the source code of this file.

Classes

struct  teditor::calc::Number< IntT, FloatT >
 Core number used for computing in the calculator. More...
 

Namespaces

 std
 
 teditor
 
 teditor::calc
 

Macros

#define OP(b, op)
 
#define B_OP(b, op)
 
#define CONST(var, val)
 
#define FUNC(name)
 
#define FP_FUNC(name)
 
#define FP_FUNC2(name)
 

Typedefs

typedef Number< int32_t, float > teditor::calc::Num32
 
typedef Number< int64_t, double > teditor::calc::Num64
 

Functions

template<typename T >
std::sq (T in)
 
template<typename T >
std::cube (T in)
 
 teditor::calc::CONST (e, M_E)
 
 teditor::calc::CONST (pi, M_PI)
 
 teditor::calc::CONST (nan, NAN)
 
 teditor::calc::CONST (log2e, M_LOG2E)
 
 teditor::calc::CONST (log10e, M_LOG10E)
 
 teditor::calc::CONST (sqrt2, M_SQRT2)
 
 teditor::calc::CONST (sqrt1_2, M_SQRT1_2)
 
template<typename I , typename F >
Number< I, F > teditor::calc::operator+ (const Number< I, F > &a, const Number< I, F > &b)
 
template<typename I , typename F >
Number< I, F > teditor::calc::operator- (const Number< I, F > &a, const Number< I, F > &b)
 
template<typename I , typename F >
Number< I, F > teditor::calc::operator* (const Number< I, F > &a, const Number< I, F > &b)
 
template<typename I , typename F >
Number< I, F > teditor::calc::operator/ (const Number< I, F > &a, const Number< I, F > &b)
 
 teditor::calc::FUNC (sq)
 
 teditor::calc::FUNC (cube)
 
 teditor::calc::FP_FUNC (abs)
 
 teditor::calc::FP_FUNC (sin)
 
 teditor::calc::FP_FUNC (tan)
 
 teditor::calc::FP_FUNC (asin)
 
 teditor::calc::FP_FUNC (atan)
 
 teditor::calc::FP_FUNC (sinh)
 
 teditor::calc::FP_FUNC (tanh)
 
 teditor::calc::FP_FUNC (asinh)
 
 teditor::calc::FP_FUNC (atanh)
 
 teditor::calc::FP_FUNC (sqrt)
 
 teditor::calc::FP_FUNC (cbrt)
 
 teditor::calc::FP_FUNC (log)
 
 teditor::calc::FP_FUNC (log10)
 
 teditor::calc::FP_FUNC (exp)
 
 teditor::calc::FP_FUNC (floor)
 
 teditor::calc::FP_FUNC (ceil)
 
 teditor::calc::FP_FUNC (round)
 
template<typename I , typename F >
Number< I, F > teditor::calc::toInt (const Number< I, F > &a)
 
template<typename I , typename F >
Number< I, F > teditor::calc::toFloat (const Number< I, F > &a)
 
 teditor::calc::FP_FUNC2 (pow)
 
 teditor::calc::FP_FUNC2 (hypot)
 

Macro Definition Documentation

◆ B_OP

#define B_OP (   b,
  op 
)
Value:
do { \
if (isInt && b.isInt) return i op b.i; \
if (isInt && !b.isInt) return FloatT(i) op b.f; \
if (!isInt && b.isInt) return f op FloatT(b.i); \
return f op b.f; \
} while(0)

◆ CONST

#define CONST (   var,
  val 
)
Value:
template <typename I, typename F> \
const Number<I, F> Number<I, F>::var((F)val)

◆ FP_FUNC

#define FP_FUNC (   name)
Value:
template <typename I, typename F> \
Number<I, F> name(const Number<I, F>& in) { \
Number<I, F> out; \
out.isInt = false; \
out.f = std::name(in.isInt ? F(in.i) : in.f); \
return out; \
}

◆ FP_FUNC2

#define FP_FUNC2 (   name)
Value:
template <typename I, typename F> \
Number<I, F> name(const Number<I, F>& in1, const Number<I, F>& in2) { \
Number<I, F> out; \
out.isInt = false; \
out.f = std::name(in1.isInt ? F(in1.i) : in1.f, \
in2.isInt ? F(in2.i) : in2.f); \
return out; \
}

◆ FUNC

#define FUNC (   name)
Value:
template <typename I, typename F> \
Number<I, F> name(const Number<I, F>& in) { \
Number<I, F> out; \
out.isInt = in.isInt; \
if (out.isInt) { \
out.i = std::name(in.i); \
} else { \
out.f = std::name(in.f); \
} \
return out; \
}

◆ OP

#define OP (   b,
  op 
)
Value:
do { \
if (isInt && b.isInt) { \
i = i op b.i; \
} else if (isInt && !b.isInt) { \
isInt = false; \
f = FloatT(i) op b.f; \
} else if (!isInt && b.isInt) { \
f = f op FloatT(b.i); \
} else { \
f = f op b.f; \
} \
} while(0); \
return *this