diff --git a/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp b/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp index 35827e6c..da13d7c4 100644 --- a/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp +++ b/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp @@ -34,6 +34,8 @@ namespace xo { DFloat * x, DInteger * y); static obj cmp_less(obj rcx, DFloat * x, DInteger * y); + static obj cmp_lessequal(obj rcx, + DFloat * x, DInteger * y); }; class IntegerFloatOps { @@ -56,6 +58,8 @@ namespace xo { DInteger * x, DFloat * y); static obj cmp_less(obj rcx, DInteger * x, DFloat * y); + static obj cmp_lessequal(obj rcx, + DInteger * x, DFloat * y); }; } diff --git a/xo-numeric/include/xo/numeric/FloatOps.hpp b/xo-numeric/include/xo/numeric/FloatOps.hpp index dd088f90..3c32960b 100644 --- a/xo-numeric/include/xo/numeric/FloatOps.hpp +++ b/xo-numeric/include/xo/numeric/FloatOps.hpp @@ -33,6 +33,8 @@ namespace xo { DFloat * x, DFloat * y); static obj cmp_less(obj rcx, DFloat * x, DFloat * y); + static obj cmp_lessequal(obj rcx, + DFloat * x, DFloat * y); }; } diff --git a/xo-numeric/include/xo/numeric/IntegerOps.hpp b/xo-numeric/include/xo/numeric/IntegerOps.hpp index b5a8fba8..4612e365 100644 --- a/xo-numeric/include/xo/numeric/IntegerOps.hpp +++ b/xo-numeric/include/xo/numeric/IntegerOps.hpp @@ -35,6 +35,8 @@ namespace xo { DInteger * x, DInteger * y); static obj cmp_less(obj rcx, DInteger * x, DInteger * y); + static obj cmp_lessequal(obj rcx, + DInteger * x, DInteger * y); }; diff --git a/xo-numeric/include/xo/numeric/NumericDispatch.hpp b/xo-numeric/include/xo/numeric/NumericDispatch.hpp index 1dc68a3d..3680a508 100644 --- a/xo-numeric/include/xo/numeric/NumericDispatch.hpp +++ b/xo-numeric/include/xo/numeric/NumericDispatch.hpp @@ -103,11 +103,16 @@ namespace xo { obj x, obj y); - /** compare two numeric values for inequality **/ + /** compare two numeric values for less **/ static obj cmp_less(obj rcx, obj x, obj y); + /** compare two numeric values for less-or-equal **/ + static obj cmp_lessequal(obj rcx, + obj x, + obj y); + /** report memory use for owned arenas to @p visitor **/ void visit_pools(const MemorySizeVisitor & visitor); @@ -123,7 +128,8 @@ namespace xo { typename NumericOps::BinaryOp_Impl sub_fn, typename NumericOps::BinaryOp_Impl cmpeq_fn, typename NumericOps::BinaryOp_Impl cmpne_fn, - typename NumericOps::BinaryOp_Impl cmplt_fn) { + typename NumericOps::BinaryOp_Impl cmplt_fn, + typename NumericOps::BinaryOp_Impl cmple_fn) { KeyType key(typeseq::id().seqno(), typeseq::id().seqno()); @@ -136,7 +142,8 @@ namespace xo { sub_fn, cmpeq_fn, cmpne_fn, - cmplt_fn); + cmplt_fn, + cmple_fn); } private: diff --git a/xo-numeric/include/xo/numeric/NumericOps.hpp b/xo-numeric/include/xo/numeric/NumericOps.hpp index 580efcf1..d8916133 100644 --- a/xo-numeric/include/xo/numeric/NumericOps.hpp +++ b/xo-numeric/include/xo/numeric/NumericOps.hpp @@ -28,9 +28,10 @@ namespace xo { BinaryOp subtract, BinaryOp cmpeq, BinaryOp cmpne, - BinaryOp cmplt) + BinaryOp cmplt, + BinaryOp cmple) : multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract}, - cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt} {} + cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt}, cmple_{cmple} {} BinaryOp multiply_ = nullptr; BinaryOp divide_ = nullptr; @@ -43,6 +44,8 @@ namespace xo { BinaryOp cmpne_ = nullptr; /** compare numerics (<) **/ BinaryOp cmplt_ = nullptr; + /** compare numerics (<=) **/ + BinaryOp cmple_ = nullptr; }; template @@ -60,14 +63,16 @@ namespace xo { BinaryOp_Impl subtract, BinaryOp_Impl cmpeq, BinaryOp_Impl cmpne, - BinaryOp_Impl cmplt) { + BinaryOp_Impl cmplt, + BinaryOp_Impl cmple) { return AnonymizedNumericOps(reinterpret_cast(multiply), reinterpret_cast(divide), reinterpret_cast(add), reinterpret_cast(subtract), reinterpret_cast(cmpeq), reinterpret_cast(cmpne), - reinterpret_cast(cmplt)); + reinterpret_cast(cmplt), + reinterpret_cast(cmple)); } }; diff --git a/xo-numeric/include/xo/numeric/NumericPrimitives.hpp b/xo-numeric/include/xo/numeric/NumericPrimitives.hpp index feacb480..a703af4a 100644 --- a/xo-numeric/include/xo/numeric/NumericPrimitives.hpp +++ b/xo-numeric/include/xo/numeric/NumericPrimitives.hpp @@ -33,6 +33,8 @@ namespace xo { static DPrimitive_gco_2_gco_gco * make_cmpne_pm(obj mm); /** polymorphic (in both arguments) compare (<) **/ static DPrimitive_gco_2_gco_gco * make_cmplt_pm(obj mm); + /** polymorphic (in both arguments) compare (<=) **/ + static DPrimitive_gco_2_gco_gco * make_cmple_pm(obj mm); }; } } diff --git a/xo-numeric/src/numeric/FloatIntegerOps.cpp b/xo-numeric/src/numeric/FloatIntegerOps.cpp index c601a2bf..c23d70f4 100644 --- a/xo-numeric/src/numeric/FloatIntegerOps.cpp +++ b/xo-numeric/src/numeric/FloatIntegerOps.cpp @@ -66,6 +66,14 @@ namespace xo { x->value() < DFloat::value_type(y->value())); } + obj + FloatIntegerOps::cmp_lessequal(obj rcx, + DFloat * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), + x->value() <= DFloat::value_type(y->value())); + } + // ----- Integer op Float ----- obj @@ -120,6 +128,14 @@ namespace xo { DFloat::value_type(x->value()) < y->value()); } + obj + IntegerFloatOps::cmp_lessequal(obj rcx, + DInteger * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), + DFloat::value_type(x->value()) <= y->value()); + } + } } diff --git a/xo-numeric/src/numeric/FloatOps.cpp b/xo-numeric/src/numeric/FloatOps.cpp index 8fbefc59..8c59bb1f 100644 --- a/xo-numeric/src/numeric/FloatOps.cpp +++ b/xo-numeric/src/numeric/FloatOps.cpp @@ -60,6 +60,13 @@ namespace xo { { return DBoolean::box(rcx.allocator(), x->value() < y->value()); } + + obj + FloatOps::cmp_lessequal(obj rcx, + DFloat * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), x->value() <= y->value()); + } } } diff --git a/xo-numeric/src/numeric/IntegerOps.cpp b/xo-numeric/src/numeric/IntegerOps.cpp index 52c9596c..65874439 100644 --- a/xo-numeric/src/numeric/IntegerOps.cpp +++ b/xo-numeric/src/numeric/IntegerOps.cpp @@ -62,6 +62,13 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() < y->value()); } + obj + IntegerOps::cmp_lessequal(obj rcx, + DInteger * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), x->value() <= y->value()); + } + } } diff --git a/xo-numeric/src/numeric/NumericDispatch.cpp b/xo-numeric/src/numeric/NumericDispatch.cpp index 85936171..42c507ee 100644 --- a/xo-numeric/src/numeric/NumericDispatch.cpp +++ b/xo-numeric/src/numeric/NumericDispatch.cpp @@ -99,18 +99,6 @@ namespace xo { "incomparable types in x+y", &AnonymizedNumericOps::add_, x, y); - -#ifdef OBSOLETE - KeyType key(x._typeseq(), y._typeseq()); - - auto target_fn - = NumericDispatch::instance().dispatch_[key].add_; - - if (!target_fn) - assert(false); - - return (*target_fn)(rcx, x.data(), y.data()); -#endif } obj @@ -123,18 +111,6 @@ namespace xo { "incomparable types in x-y", &AnonymizedNumericOps::subtract_, x, y); - -#ifdef OBSOLETE - KeyType key(x._typeseq(), y._typeseq()); - - auto target_fn - = NumericDispatch::instance().dispatch_[key].subtract_; - - if (!target_fn) - assert(false); - - return (*target_fn)(rcx, x.data(), y.data()); -#endif } obj @@ -148,27 +124,6 @@ namespace xo { &AnonymizedNumericOps::cmpeq_, x, y); -#ifdef OBSOLETE - KeyType key(x._typeseq(), y._typeseq()); - - auto target_fn - = NumericDispatch::instance().dispatch_[key].cmpeq_; - - if (!target_fn) { - // FIXME: use {fmt} here - std::stringstream ss; - tosn(ss, - "incomparable types in x==y", - xtag("x.type", TypeRegistry::id2name(x._typeseq())), - xtag("y.type", TypeRegistry::id2name(y._typeseq()))); - - return DRuntimeError::make(rcx.allocator(), - "NumericDispatch::cmp_equal", - ss.str().c_str()); - } - - return (*target_fn)(rcx, x.data(), y.data()); -#endif } obj @@ -195,6 +150,18 @@ namespace xo { x, y); } + obj + NumericDispatch::cmp_lessequal(obj rcx, + obj x, + obj y) + { + return dispatch(rcx, + "NumericDispatch::cmp_lessequal", + "incomparable types in x<=y", + &AnonymizedNumericOps::cmple_, + x, y); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-numeric/src/numeric/NumericPrimitives.cpp b/xo-numeric/src/numeric/NumericPrimitives.cpp index fabc3648..e48c1a30 100644 --- a/xo-numeric/src/numeric/NumericPrimitives.cpp +++ b/xo-numeric/src/numeric/NumericPrimitives.cpp @@ -61,6 +61,13 @@ namespace xo { &NumericDispatch::cmp_less); } + DPrimitive_gco_2_gco_gco * + NumericPrimitives::make_cmple_pm(obj mm) + { + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmple", + &NumericDispatch::cmp_lessequal); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/xo-numeric/src/numeric/numeric_register_facets.cpp b/xo-numeric/src/numeric/numeric_register_facets.cpp index 1d7a6a13..fce3dc27 100644 --- a/xo-numeric/src/numeric/numeric_register_facets.cpp +++ b/xo-numeric/src/numeric/numeric_register_facets.cpp @@ -41,7 +41,8 @@ namespace xo { &FloatOps::subtract, &FloatOps::cmp_equal, &FloatOps::cmp_notequal, - &FloatOps::cmp_less); + &FloatOps::cmp_less, + &FloatOps::cmp_lessequal); NumericDispatch::instance().register_impl (&FloatIntegerOps::multiply, @@ -50,7 +51,8 @@ namespace xo { &FloatIntegerOps::subtract, &FloatIntegerOps::cmp_equal, &FloatIntegerOps::cmp_notequal, - &FloatIntegerOps::cmp_less); + &FloatIntegerOps::cmp_less, + &FloatIntegerOps::cmp_lessequal); NumericDispatch::instance().register_impl (&IntegerFloatOps::multiply, @@ -59,7 +61,8 @@ namespace xo { &IntegerFloatOps::subtract, &IntegerFloatOps::cmp_equal, &IntegerFloatOps::cmp_notequal, - &IntegerFloatOps::cmp_less); + &IntegerFloatOps::cmp_less, + &IntegerFloatOps::cmp_lessequal); NumericDispatch::instance().register_impl (&IntegerOps::multiply, @@ -68,7 +71,8 @@ namespace xo { &IntegerOps::subtract, &IntegerOps::cmp_equal, &IntegerOps::cmp_notequal, - &IntegerOps::cmp_less); + &IntegerOps::cmp_less, + &IntegerOps::cmp_lessequal); log && log(xtag("ANumeric.tseq", typeseq::id()));