diff --git a/include/xo/numeric/FloatIntegerOps.hpp b/include/xo/numeric/FloatIntegerOps.hpp index 0ee99710..35827e6c 100644 --- a/include/xo/numeric/FloatIntegerOps.hpp +++ b/include/xo/numeric/FloatIntegerOps.hpp @@ -32,6 +32,8 @@ namespace xo { DFloat * x, DInteger * y); static obj cmp_notequal(obj rcx, DFloat * x, DInteger * y); + static obj cmp_less(obj rcx, + DFloat * x, DInteger * y); }; class IntegerFloatOps { @@ -52,6 +54,8 @@ namespace xo { DInteger * x, DFloat * y); static obj cmp_notequal(obj rcx, DInteger * x, DFloat * y); + static obj cmp_less(obj rcx, + DInteger * x, DFloat * y); }; } diff --git a/include/xo/numeric/FloatOps.hpp b/include/xo/numeric/FloatOps.hpp index 88b56442..dd088f90 100644 --- a/include/xo/numeric/FloatOps.hpp +++ b/include/xo/numeric/FloatOps.hpp @@ -31,6 +31,8 @@ namespace xo { DFloat * x, DFloat * y); static obj cmp_notequal(obj rcx, DFloat * x, DFloat * y); + static obj cmp_less(obj rcx, + DFloat * x, DFloat * y); }; } diff --git a/include/xo/numeric/IntegerOps.hpp b/include/xo/numeric/IntegerOps.hpp index 09306522..b5a8fba8 100644 --- a/include/xo/numeric/IntegerOps.hpp +++ b/include/xo/numeric/IntegerOps.hpp @@ -33,6 +33,8 @@ namespace xo { DInteger * x, DInteger * y); static obj cmp_notequal(obj rcx, DInteger * x, DInteger * y); + static obj cmp_less(obj rcx, + DInteger * x, DInteger * y); }; diff --git a/include/xo/numeric/NumericDispatch.hpp b/include/xo/numeric/NumericDispatch.hpp index c40f8155..9de42160 100644 --- a/include/xo/numeric/NumericDispatch.hpp +++ b/include/xo/numeric/NumericDispatch.hpp @@ -103,6 +103,11 @@ namespace xo { obj x, obj y); + /** compare two numeric values for inequality **/ + static obj cmp_less(obj rcx, + obj x, + obj y); + /** report memory use for owned arenas to @p visitor **/ void visit_pools(const MemorySizeVisitor & visitor); @@ -117,7 +122,8 @@ namespace xo { typename NumericOps::BinaryOp_Impl add_fn, typename NumericOps::BinaryOp_Impl sub_fn, typename NumericOps::BinaryOp_Impl cmpeq_fn, - typename NumericOps::BinaryOp_Impl cmpne_fn) { + typename NumericOps::BinaryOp_Impl cmpne_fn, + typename NumericOps::BinaryOp_Impl cmplt_fn) { KeyType key(typeseq::id().seqno(), typeseq::id().seqno()); @@ -129,7 +135,8 @@ namespace xo { add_fn, sub_fn, cmpeq_fn, - cmpne_fn); + cmpne_fn, + cmplt_fn); } private: diff --git a/include/xo/numeric/NumericOps.hpp b/include/xo/numeric/NumericOps.hpp index 6d888434..b69a0338 100644 --- a/include/xo/numeric/NumericOps.hpp +++ b/include/xo/numeric/NumericOps.hpp @@ -27,19 +27,22 @@ namespace xo { BinaryOp add, BinaryOp subtract, BinaryOp cmpeq, - BinaryOp cmpne) + BinaryOp cmpne, + BinaryOp cmplt) : multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract}, - cmpeq_{cmpeq}, cmpne_{cmpne} {} + cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt} {} BinaryOp multiply_ = nullptr; BinaryOp divide_ = nullptr; BinaryOp add_ = nullptr; BinaryOp subtract_ = nullptr; - /** compare numerics for equality **/ + /** compare numerics (==) **/ BinaryOp cmpeq_ = nullptr; - /** compare numerics for inequality **/ + /** compare numerics (!=) **/ BinaryOp cmpne_ = nullptr; + /** compare numerics (<) **/ + BinaryOp cmplt_ = nullptr; }; template @@ -56,13 +59,15 @@ namespace xo { BinaryOp_Impl add, BinaryOp_Impl subtract, BinaryOp_Impl cmpeq, - BinaryOp_Impl cmpne) { + BinaryOp_Impl cmpne, + BinaryOp_Impl cmplt) { return AnonymizedNumericOps(reinterpret_cast(multiply), reinterpret_cast(divide), reinterpret_cast(add), reinterpret_cast(subtract), reinterpret_cast(cmpeq), - reinterpret_cast(cmpne)); + reinterpret_cast(cmpne), + reinterpret_cast(cmplt)); } }; diff --git a/include/xo/numeric/NumericPrimitives.hpp b/include/xo/numeric/NumericPrimitives.hpp index a2cc3cdb..b67ec911 100644 --- a/include/xo/numeric/NumericPrimitives.hpp +++ b/include/xo/numeric/NumericPrimitives.hpp @@ -27,6 +27,8 @@ namespace xo { static DPrimitive_gco_2_gco_gco s_cmpeq_gco_gco_pm; /** polymorphic (in both arguments) compare (!=) **/ static DPrimitive_gco_2_gco_gco s_cmpne_gco_gco_pm; + /** polymorphic (in both arguments) compare (<) **/ + static DPrimitive_gco_2_gco_gco s_cmplt_gco_gco_pm; }; } } diff --git a/src/numeric/FloatIntegerOps.cpp b/src/numeric/FloatIntegerOps.cpp index f82e10dc..c601a2bf 100644 --- a/src/numeric/FloatIntegerOps.cpp +++ b/src/numeric/FloatIntegerOps.cpp @@ -58,6 +58,14 @@ namespace xo { x->value() != DFloat::value_type(y->value())); } + obj + FloatIntegerOps::cmp_less(obj rcx, + DFloat * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), + x->value() < DFloat::value_type(y->value())); + } + // ----- Integer op Float ----- obj @@ -104,6 +112,14 @@ namespace xo { DFloat::value_type(x->value()) != y->value()); } + obj + IntegerFloatOps::cmp_less(obj rcx, + DInteger * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), + DFloat::value_type(x->value()) < y->value()); + } + } } diff --git a/src/numeric/FloatOps.cpp b/src/numeric/FloatOps.cpp index 6f984728..8fbefc59 100644 --- a/src/numeric/FloatOps.cpp +++ b/src/numeric/FloatOps.cpp @@ -54,7 +54,12 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() != y->value()); } - + obj + FloatOps::cmp_less(obj rcx, + DFloat * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), x->value() < y->value()); + } } } diff --git a/src/numeric/IntegerOps.cpp b/src/numeric/IntegerOps.cpp index 31f9110d..52c9596c 100644 --- a/src/numeric/IntegerOps.cpp +++ b/src/numeric/IntegerOps.cpp @@ -55,6 +55,13 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() != y->value()); } + obj + IntegerOps::cmp_less(obj rcx, + DInteger * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), x->value() < y->value()); + } + } } diff --git a/src/numeric/NumericDispatch.cpp b/src/numeric/NumericDispatch.cpp index b0738342..9220207e 100644 --- a/src/numeric/NumericDispatch.cpp +++ b/src/numeric/NumericDispatch.cpp @@ -191,6 +191,18 @@ namespace xo { x, y); } + obj + NumericDispatch::cmp_less(obj rcx, + obj x, + obj y) + { + return dispatch(rcx, + "NumericDispatch::cmp_less", + "incomparable types in x (&FloatIntegerOps::multiply, @@ -48,7 +49,8 @@ namespace xo { &FloatIntegerOps::add, &FloatIntegerOps::subtract, &FloatIntegerOps::cmp_equal, - &FloatIntegerOps::cmp_notequal); + &FloatIntegerOps::cmp_notequal, + &FloatIntegerOps::cmp_less); NumericDispatch::instance().register_impl (&IntegerFloatOps::multiply, @@ -56,7 +58,8 @@ namespace xo { &IntegerFloatOps::add, &IntegerFloatOps::subtract, &IntegerFloatOps::cmp_equal, - &IntegerFloatOps::cmp_notequal); + &IntegerFloatOps::cmp_notequal, + &IntegerFloatOps::cmp_less); NumericDispatch::instance().register_impl (&IntegerOps::multiply, @@ -64,7 +67,8 @@ namespace xo { &IntegerOps::add, &IntegerOps::subtract, &IntegerOps::cmp_equal, - &IntegerOps::cmp_notequal); + &IntegerOps::cmp_notequal, + &IntegerOps::cmp_less); log && log(xtag("ANumeric.tseq", typeseq::id()));