2021-01-07 17:08:34 +08:00
|
|
|
#include <math.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryMax {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return std::max(x, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryMin {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return std::min(x, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryMul {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x * y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryAdd {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinarySub {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x - y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryRealDiv {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x / y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryMod {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x - x / y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryGreater {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x > y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryLess {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x < y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryGreaterEqual {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x >= y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryLessEqual {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x <= y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryEqual {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x == y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryFloorDiv {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
2021-02-07 10:45:07 +08:00
|
|
|
return floor(static_cast<float>(x) / y);
|
2021-01-07 17:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryFloorMod {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return x - floor(x / y) * y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinarySquaredDifference {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (x - y) * (x - y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryPow {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return pow(x, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryAtan2 {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return atan(x / y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryLogicalOr {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x || y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _Arg1, typename _Arg2, typename _ErrorCode>
|
2021-04-08 15:34:23 +08:00
|
|
|
struct BinaryNotEqual {
|
2021-01-07 17:08:34 +08:00
|
|
|
_ErrorCode operator()(const _Arg1& x, const _Arg2& y) const {
|
|
|
|
return (_ErrorCode)((x != y) ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|