diff --git a/include/xo/numeric/FloatIntegerOps.hpp b/include/xo/numeric/FloatIntegerOps.hpp index da13d7c4..8508402f 100644 --- a/include/xo/numeric/FloatIntegerOps.hpp +++ b/include/xo/numeric/FloatIntegerOps.hpp @@ -36,6 +36,8 @@ namespace xo { DFloat * x, DInteger * y); static obj cmp_lessequal(obj rcx, DFloat * x, DInteger * y); + static obj cmp_greatequal(obj rcx, + DFloat * x, DInteger * y); }; class IntegerFloatOps { @@ -60,6 +62,8 @@ namespace xo { DInteger * x, DFloat * y); static obj cmp_lessequal(obj rcx, DInteger * x, DFloat * y); + static obj cmp_greatequal(obj rcx, + DInteger * x, DFloat * y); }; } diff --git a/include/xo/numeric/FloatOps.hpp b/include/xo/numeric/FloatOps.hpp index 3c32960b..3eaabc9c 100644 --- a/include/xo/numeric/FloatOps.hpp +++ b/include/xo/numeric/FloatOps.hpp @@ -35,6 +35,8 @@ namespace xo { DFloat * x, DFloat * y); static obj cmp_lessequal(obj rcx, DFloat * x, DFloat * y); + static obj cmp_greatequal(obj rcx, + DFloat * x, DFloat * y); }; } diff --git a/include/xo/numeric/IntegerOps.hpp b/include/xo/numeric/IntegerOps.hpp index 4612e365..b8342555 100644 --- a/include/xo/numeric/IntegerOps.hpp +++ b/include/xo/numeric/IntegerOps.hpp @@ -37,6 +37,8 @@ namespace xo { DInteger * x, DInteger * y); static obj cmp_lessequal(obj rcx, DInteger * x, DInteger * y); + static obj cmp_greatequal(obj rcx, + DInteger * x, DInteger * y); }; diff --git a/include/xo/numeric/NumericDispatch.hpp b/include/xo/numeric/NumericDispatch.hpp index 3680a508..53b35b97 100644 --- a/include/xo/numeric/NumericDispatch.hpp +++ b/include/xo/numeric/NumericDispatch.hpp @@ -113,6 +113,11 @@ namespace xo { obj x, obj y); + /** compare two numeric values for greater-or-equal **/ + static obj cmp_greatequal(obj rcx, + obj x, + obj y); + /** report memory use for owned arenas to @p visitor **/ void visit_pools(const MemorySizeVisitor & visitor); @@ -129,7 +134,8 @@ namespace xo { typename NumericOps::BinaryOp_Impl cmpeq_fn, typename NumericOps::BinaryOp_Impl cmpne_fn, typename NumericOps::BinaryOp_Impl cmplt_fn, - typename NumericOps::BinaryOp_Impl cmple_fn) { + typename NumericOps::BinaryOp_Impl cmple_fn, + typename NumericOps::BinaryOp_Impl cmpge_fn) { KeyType key(typeseq::id().seqno(), typeseq::id().seqno()); @@ -143,7 +149,8 @@ namespace xo { cmpeq_fn, cmpne_fn, cmplt_fn, - cmple_fn); + cmple_fn, + cmpge_fn); } private: diff --git a/include/xo/numeric/NumericOps.hpp b/include/xo/numeric/NumericOps.hpp index d8916133..5d983a98 100644 --- a/include/xo/numeric/NumericOps.hpp +++ b/include/xo/numeric/NumericOps.hpp @@ -29,9 +29,10 @@ namespace xo { BinaryOp cmpeq, BinaryOp cmpne, BinaryOp cmplt, - BinaryOp cmple) + BinaryOp cmple, + BinaryOp cmpge) : multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract}, - cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt}, cmple_{cmple} {} + cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt}, cmple_{cmple}, cmpge_{cmpge} {} BinaryOp multiply_ = nullptr; BinaryOp divide_ = nullptr; @@ -46,6 +47,8 @@ namespace xo { BinaryOp cmplt_ = nullptr; /** compare numerics (<=) **/ BinaryOp cmple_ = nullptr; + /** compare numerics (>=) **/ + BinaryOp cmpge_ = nullptr; }; template @@ -64,7 +67,8 @@ namespace xo { BinaryOp_Impl cmpeq, BinaryOp_Impl cmpne, BinaryOp_Impl cmplt, - BinaryOp_Impl cmple) { + BinaryOp_Impl cmple, + BinaryOp_Impl cmpge) { return AnonymizedNumericOps(reinterpret_cast(multiply), reinterpret_cast(divide), reinterpret_cast(add), @@ -72,7 +76,8 @@ namespace xo { reinterpret_cast(cmpeq), reinterpret_cast(cmpne), reinterpret_cast(cmplt), - reinterpret_cast(cmple)); + reinterpret_cast(cmple), + reinterpret_cast(cmpge)); } }; diff --git a/src/numeric/FloatIntegerOps.cpp b/src/numeric/FloatIntegerOps.cpp index c23d70f4..d2fedcfa 100644 --- a/src/numeric/FloatIntegerOps.cpp +++ b/src/numeric/FloatIntegerOps.cpp @@ -74,6 +74,14 @@ namespace xo { x->value() <= DFloat::value_type(y->value())); } + obj + FloatIntegerOps::cmp_greatequal(obj rcx, + DFloat * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), + x->value() >= DFloat::value_type(y->value())); + } + // ----- Integer op Float ----- obj @@ -136,6 +144,14 @@ namespace xo { DFloat::value_type(x->value()) <= y->value()); } + obj + IntegerFloatOps::cmp_greatequal(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 8c59bb1f..a549c8ac 100644 --- a/src/numeric/FloatOps.cpp +++ b/src/numeric/FloatOps.cpp @@ -23,49 +23,64 @@ namespace xo { FloatOps::divide(obj rcx, DFloat * x, DFloat * y) { - return DFloat::box(rcx.allocator(), x->value() / y->value()); + return DFloat::box(rcx.allocator(), + x->value() / y->value()); } obj FloatOps::add(obj rcx, DFloat * x, DFloat * y) { - return DFloat::box(rcx.allocator(), x->value() + y->value()); + return DFloat::box(rcx.allocator(), + x->value() + y->value()); } obj FloatOps::subtract(obj rcx, DFloat * x, DFloat * y) { - return DFloat::box(rcx.allocator(), x->value() - y->value()); + return DFloat::box(rcx.allocator(), + x->value() - y->value()); } obj FloatOps::cmp_equal(obj rcx, DFloat * x, DFloat * y) { - return DBoolean::box(rcx.allocator(), x->value() == y->value()); + return DBoolean::box(rcx.allocator(), + x->value() == y->value()); } obj FloatOps::cmp_notequal(obj rcx, DFloat * x, DFloat * y) { - return DBoolean::box(rcx.allocator(), x->value() != y->value()); + 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()); + 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()); + return DBoolean::box(rcx.allocator(), + x->value() <= y->value()); + } + + obj + FloatOps::cmp_greatequal(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 65874439..af67a5ee 100644 --- a/src/numeric/IntegerOps.cpp +++ b/src/numeric/IntegerOps.cpp @@ -69,6 +69,13 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() <= y->value()); } + obj + IntegerOps::cmp_greatequal(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 42c507ee..0cc0af11 100644 --- a/src/numeric/NumericDispatch.cpp +++ b/src/numeric/NumericDispatch.cpp @@ -162,6 +162,18 @@ namespace xo { x, y); } + obj + NumericDispatch::cmp_greatequal(obj rcx, + obj x, + obj y) + { + return dispatch(rcx, + "NumericDispatch::cmp_great", + "incomparable types in x>=y", + &AnonymizedNumericOps::cmpge_, + x, y); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/numeric/numeric_register_facets.cpp b/src/numeric/numeric_register_facets.cpp index fce3dc27..e70abe39 100644 --- a/src/numeric/numeric_register_facets.cpp +++ b/src/numeric/numeric_register_facets.cpp @@ -42,7 +42,8 @@ namespace xo { &FloatOps::cmp_equal, &FloatOps::cmp_notequal, &FloatOps::cmp_less, - &FloatOps::cmp_lessequal); + &FloatOps::cmp_lessequal, + &FloatOps::cmp_greatequal); NumericDispatch::instance().register_impl (&FloatIntegerOps::multiply, @@ -52,7 +53,8 @@ namespace xo { &FloatIntegerOps::cmp_equal, &FloatIntegerOps::cmp_notequal, &FloatIntegerOps::cmp_less, - &FloatIntegerOps::cmp_lessequal); + &FloatIntegerOps::cmp_lessequal, + &FloatIntegerOps::cmp_greatequal); NumericDispatch::instance().register_impl (&IntegerFloatOps::multiply, @@ -62,7 +64,8 @@ namespace xo { &IntegerFloatOps::cmp_equal, &IntegerFloatOps::cmp_notequal, &IntegerFloatOps::cmp_less, - &IntegerFloatOps::cmp_lessequal); + &IntegerFloatOps::cmp_lessequal, + &IntegerFloatOps::cmp_greatequal); NumericDispatch::instance().register_impl (&IntegerOps::multiply, @@ -72,7 +75,8 @@ namespace xo { &IntegerOps::cmp_equal, &IntegerOps::cmp_notequal, &IntegerOps::cmp_less, - &IntegerOps::cmp_lessequal); + &IntegerOps::cmp_lessequal, + &IntegerOps::cmp_greatequal); log && log(xtag("ANumeric.tseq", typeseq::id())); diff --git a/src/numeric/numeric_register_primitives.cpp b/src/numeric/numeric_register_primitives.cpp index ed5d777f..63c6f5fe 100644 --- a/src/numeric/numeric_register_primitives.cpp +++ b/src/numeric/numeric_register_primitives.cpp @@ -74,6 +74,8 @@ namespace xo { flags & InstallFlags::f_essential); ok = ok & install_aux(sink, mm, "_cmple", &NumericDispatch::cmp_lessequal, flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, mm, "_cmpge", &NumericDispatch::cmp_greatequal, + flags & InstallFlags::f_essential); return ok; }