diff options
Diffstat (limited to 'meowpp/math/utility.h')
-rw-r--r-- | meowpp/math/utility.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/meowpp/math/utility.h b/meowpp/math/utility.h new file mode 100644 index 0000000..9bfbb7a --- /dev/null +++ b/meowpp/math/utility.h @@ -0,0 +1,82 @@ +#ifndef math_utility_H__ +#define math_utility_H__ + +#include <cstdlib> + +namespace meow{ + static const double PI = 3.14159265358979323846264338327950288; + //# + //# === meow:: *Functios* in math/utility.h + //# + //# [options="header",width="100%",cols="1>s,5<,1<,10<",grid="rows"] + //# |============================================================== + //# |Name | Parameters | Return_Type | Description + + + //# |noEPS<T> |(T `value`, T `eps` = 1e-9) | T | + //# 如果abs(輸入的數值) < eps, 則回傳0, 否則回傳輸入的數值 + template<class T> + inline T noEPS(T value, T eps = 1e-9); + + + //# |normalize<T> |(T `lower`, T `upper`, \ T value) + //# | T | `(value - lower) / (upper - lower)` + template<class T> + inline T normalize(T lower, T upper, T value); + + + //# |denormalize<T> |(T `lower`, T `upper`, + //# \ T `ratio`) | T | `lower + (upper - lower) * ratio` + template<class T> + inline T denormalize(T lower, T upper, T ratio); + + + //# |ratioMapping<T>|(T `l1`, T `u1`, + //# \T `m1`, T `l2`,\T `u2`) + //# | T | `denormalize(l2, u2, normalize(l1, u1, m1))` + template<class T> + inline T ratioMapping(T l1, T u1, T m1, T l2, T u2); + + + //# |inRange<T> |(T const& `mn`, T const& `mx`, \ T const& `v`) | T | + //# `std::max(mn, std::min(mx, v))` + template<class T> + inline T inRange(T const& mn, T const& mx, T const& v); + + + //# |squ<T> |(T const& `x`) | T| `x * x` + template<class T> + inline T squ(T const& x); + + + //# |cub<T> |(T const& `x`) | T| `x * x * x` + template<class T> + inline T cub(T const& x); + + //# |average<T>|(T const& `beg`, T const& `end`, \ double `sigs`)| T| + //# 只將 `sigs` 個標準差以內的數據拿來取平均 + template<class T> + inline double average(T const& beg, T const& end, double sigs); + + + //# |average<T>|(T const& `beg`, T const& `end`, + //# \ T const& `p`, double `sigs`)| T| 同上, 不過這次用 `p` 來加權平均 + template<class T> + inline double average(T const& beg, T const& end, T const& p, double sigs); + + //# |============================================================== + + + //# + //# [NOTE] + //# ==================================== + //# * 額外附贈一個 `const double PI = 3.141592653589......` + //# ==================================== + //# + //# ''' + //# +} + +#include "utility.hpp" + +#endif // math_utility_H__ |