2017-02-08 01:13:49 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
2017-02-09 20:59:14 +01:00
|
|
|
#include <climits>
|
2017-02-08 01:07:35 +01:00
|
|
|
#include <functional>
|
2017-02-08 01:13:49 +01:00
|
|
|
#include <algorithm>
|
2017-02-08 01:07:35 +01:00
|
|
|
|
2017-06-20 21:21:39 +02:00
|
|
|
#include <cubescript/cubescript.hh>
|
2016-08-17 20:17:12 +02:00
|
|
|
|
2016-08-02 02:21:36 +02:00
|
|
|
namespace cscript {
|
|
|
|
|
2017-02-13 18:10:40 +01:00
|
|
|
static constexpr cs_float PI = 3.14159265358979f;
|
|
|
|
static constexpr cs_float RAD = PI / 180.0f;
|
2016-08-02 02:21:36 +02:00
|
|
|
|
2016-08-17 20:17:12 +02:00
|
|
|
template<typename T>
|
|
|
|
struct CsMathVal;
|
|
|
|
|
|
|
|
template<>
|
2017-02-13 18:10:40 +01:00
|
|
|
struct CsMathVal<cs_int> {
|
|
|
|
static cs_int get(cs_value &tv) {
|
2016-08-17 20:17:12 +02:00
|
|
|
return tv.get_int();
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
static void set(cs_value &res, cs_int val) {
|
2016-08-17 20:17:12 +02:00
|
|
|
res.set_int(val);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2017-02-13 18:10:40 +01:00
|
|
|
struct CsMathVal<cs_float> {
|
|
|
|
static cs_float get(cs_value &tv) {
|
2016-08-17 20:17:12 +02:00
|
|
|
return tv.get_float();
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
static void set(cs_value &res, cs_float val) {
|
2016-08-17 20:17:12 +02:00
|
|
|
res.set_float(val);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct CsMathNoop {
|
|
|
|
T operator()(T arg) {
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename F1, typename F2>
|
|
|
|
static inline void cs_mathop(
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_value_r args, cs_value &res, T initval,
|
2016-08-17 20:17:12 +02:00
|
|
|
F1 binop, F2 unop
|
|
|
|
) {
|
|
|
|
T val;
|
|
|
|
if (args.size() >= 2) {
|
|
|
|
val = binop(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 2; i < args.size(); ++i) {
|
2016-08-17 20:17:12 +02:00
|
|
|
val = binop(val, CsMathVal<T>::get(args[i]));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = unop(!args.empty() ? CsMathVal<T>::get(args[0]) : initval);
|
|
|
|
}
|
|
|
|
CsMathVal<T>::set(res, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename F>
|
2017-02-13 18:10:40 +01:00
|
|
|
static inline void cs_cmpop(cs_value_r args, cs_value &res, F cmp) {
|
2016-08-17 20:17:12 +02:00
|
|
|
bool val;
|
|
|
|
if (args.size() >= 2) {
|
|
|
|
val = cmp(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 2; (i < args.size()) && val; ++i) {
|
2016-09-15 19:21:06 +02:00
|
|
|
val = cmp(CsMathVal<T>::get(args[i - 1]), CsMathVal<T>::get(args[i]));
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = cmp(!args.empty() ? CsMathVal<T>::get(args[0]) : T(0), T(0));
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
res.set_int(cs_int(val));
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
|
2017-02-13 18:10:40 +01:00
|
|
|
void cs_init_lib_math(cs_state &cs) {
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("sin", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::sin(args[0].get_float() * RAD));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("cos", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::cos(args[0].get_float() * RAD));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("tan", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::tan(args[0].get_float() * RAD));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("asin", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::asin(args[0].get_float()) / RAD);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("acos", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::acos(args[0].get_float()) / RAD);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("atan", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::atan(args[0].get_float()) / RAD);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("atan2", "ff", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::atan2(args[0].get_float(), args[1].get_float()) / RAD);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("sqrt", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::sqrt(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("loge", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::log(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("log2", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::log(args[0].get_float()) / M_LN2);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("log10", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::log10(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("exp", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::exp(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("min", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_int v = (!args.empty() ? args[0].get_int() : 0);
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 1; i < args.size(); ++i) {
|
2017-02-08 01:13:49 +01:00
|
|
|
v = std::min(v, args[i].get_int());
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
res.set_int(v);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("max", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_int v = (!args.empty() ? args[0].get_int() : 0);
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 1; i < args.size(); ++i) {
|
2017-02-08 01:13:49 +01:00
|
|
|
v = std::max(v, args[i].get_int());
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
res.set_int(v);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("minf", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_float v = (!args.empty() ? args[0].get_float() : 0);
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 1; i < args.size(); ++i) {
|
2017-02-08 01:13:49 +01:00
|
|
|
v = std::min(v, args[i].get_float());
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
res.set_float(v);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("maxf", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_float v = (!args.empty() ? args[0].get_float() : 0);
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 1; i < args.size(); ++i) {
|
2017-02-08 01:13:49 +01:00
|
|
|
v = std::max(v, args[i].get_float());
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
|
|
|
res.set_float(v);
|
|
|
|
});
|
2016-08-02 02:21:36 +02:00
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("abs", "i", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_int(std::abs(args[0].get_int()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("absf", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::abs(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("floor", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::floor(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("ceil", "f", [](auto &, auto args, auto &res) {
|
2017-02-08 01:13:49 +01:00
|
|
|
res.set_float(std::ceil(args[0].get_float()));
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("round", "ff", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_float step = args[1].get_float();
|
|
|
|
cs_float r = args[0].get_float();
|
2016-08-02 02:21:36 +02:00
|
|
|
if (step > 0) {
|
|
|
|
r += step * ((r < 0) ? -0.5 : 0.5);
|
2017-02-08 01:13:49 +01:00
|
|
|
r -= std::fmod(r, step);
|
2016-08-02 02:21:36 +02:00
|
|
|
} else {
|
2017-02-08 01:13:49 +01:00
|
|
|
r = (r < 0) ? std::ceil(r - 0.5) : std::floor(r + 0.5);
|
2016-08-02 02:21:36 +02:00
|
|
|
}
|
2016-09-09 17:43:23 +02:00
|
|
|
res.set_float(r);
|
2016-08-02 02:21:36 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("+", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(args, res, 0, std::plus<cs_int>(), CsMathNoop<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("*", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 1, std::multiplies<cs_int>(), CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("-", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, std::minus<cs_int>(), std::negate<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("^", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, std::bit_xor<cs_int>(), [](cs_int val) { return ~val; }
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("~", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, std::bit_xor<cs_int>(), [](cs_int val) { return ~val; }
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("&", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, std::bit_and<cs_int>(), CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("|", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, std::bit_or<cs_int>(), CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* special combined cases */
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("^~", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_int val;
|
2016-08-17 20:17:12 +02:00
|
|
|
if (args.size() >= 2) {
|
|
|
|
val = args[0].get_int() ^ ~args[1].get_int();
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 2; i < args.size(); ++i) {
|
2016-08-17 20:17:12 +02:00
|
|
|
val ^= ~args[i].get_int();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = !args.empty() ? args[0].get_int() : 0;
|
|
|
|
}
|
|
|
|
res.set_int(val);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("&~", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_int val;
|
2016-08-17 20:17:12 +02:00
|
|
|
if (args.size() >= 2) {
|
|
|
|
val = args[0].get_int() & ~args[1].get_int();
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 2; i < args.size(); ++i) {
|
2016-08-17 20:17:12 +02:00
|
|
|
val &= ~args[i].get_int();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = !args.empty() ? args[0].get_int() : 0;
|
|
|
|
}
|
|
|
|
res.set_int(val);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("|~", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_int val;
|
2016-08-17 20:17:12 +02:00
|
|
|
if (args.size() >= 2) {
|
|
|
|
val = args[0].get_int() | ~args[1].get_int();
|
2017-01-25 02:09:50 +01:00
|
|
|
for (size_t i = 2; i < args.size(); ++i) {
|
2016-08-17 20:17:12 +02:00
|
|
|
val |= ~args[i].get_int();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = !args.empty() ? args[0].get_int() : 0;
|
|
|
|
}
|
|
|
|
res.set_int(val);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, [](cs_int val1, cs_int val2) {
|
|
|
|
return (val2 < cs_int(sizeof(cs_int) * CHAR_BIT))
|
|
|
|
? (val1 << std::max(val2, cs_int(0)))
|
2016-08-17 20:17:12 +02:00
|
|
|
: 0;
|
2017-02-13 18:10:40 +01:00
|
|
|
}, CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command(">>", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, [](cs_int val1, cs_int val2) {
|
2017-02-08 01:13:49 +01:00
|
|
|
return val1 >> std::clamp(
|
2017-02-13 18:10:40 +01:00
|
|
|
val2, cs_int(0), cs_int(sizeof(cs_int) * CHAR_BIT)
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
2017-02-13 18:10:40 +01:00
|
|
|
}, CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("+f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 0, std::plus<cs_float>(), CsMathNoop<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("*f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 1, std::multiplies<cs_float>(), CsMathNoop<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("-f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 0, std::minus<cs_float>(), std::negate<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("div", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, [](cs_int val1, cs_int val2) {
|
2016-08-17 20:17:12 +02:00
|
|
|
if (val2) {
|
|
|
|
return val1 / val2;
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
return cs_int(0);
|
|
|
|
}, CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("mod", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_int>(
|
|
|
|
args, res, 0, [](cs_int val1, cs_int val2) {
|
2016-08-17 20:17:12 +02:00
|
|
|
if (val2) {
|
|
|
|
return val1 % val2;
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
return cs_int(0);
|
|
|
|
}, CsMathNoop<cs_int>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("divf", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 0, [](cs_float val1, cs_float val2) {
|
2016-08-17 20:17:12 +02:00
|
|
|
if (val2) {
|
|
|
|
return val1 / val2;
|
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
return cs_float(0);
|
|
|
|
}, CsMathNoop<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("modf", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 0, [](cs_float val1, cs_float val2) {
|
2016-08-17 20:17:12 +02:00
|
|
|
if (val2) {
|
2017-02-13 18:10:40 +01:00
|
|
|
return cs_float(fmod(val1, val2));
|
2016-08-17 20:17:12 +02:00
|
|
|
}
|
2017-02-13 18:10:40 +01:00
|
|
|
return cs_float(0);
|
|
|
|
}, CsMathNoop<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("pow", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_mathop<cs_float>(
|
|
|
|
args, res, 0, [](cs_float val1, cs_float val2) {
|
|
|
|
return cs_float(pow(val1, val2));
|
|
|
|
}, CsMathNoop<cs_float>()
|
2016-08-17 20:17:12 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("=", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::equal_to<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("!=", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::not_equal_to<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("<", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::less<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command(">", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::greater<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("<=", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::less_equal<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command(">=", "i1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_int>(args, res, std::greater_equal<cs_int>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
|
|
|
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("=f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::equal_to<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("!=f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::not_equal_to<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("<f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::less<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command(">f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::greater<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command("<=f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::less_equal<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-09-15 00:42:19 +02:00
|
|
|
cs.new_command(">=f", "f1V", [](auto &, auto args, auto &res) {
|
2017-02-13 18:10:40 +01:00
|
|
|
cs_cmpop<cs_float>(args, res, std::greater_equal<cs_float>());
|
2016-08-17 20:17:12 +02:00
|
|
|
});
|
2016-08-02 02:21:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace cscript */
|