• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_cmpint函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_cmpint函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_cmpint函数的具体用法?C++ rb_cmpint怎么用?C++ rb_cmpint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_cmpint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: range_max

static VALUE
range_max(int argc, VALUE *argv, VALUE range)
{
    VALUE e = RANGE_END(range);
    int nm = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric);

    if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
	return rb_call_super(argc, argv);
    }
    else {
	VALUE b = RANGE_BEG(range);
	int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);

	if (c > 0)
	    return Qnil;
	if (EXCL(range)) {
	    if (!FIXNUM_P(e) && !rb_obj_is_kind_of(e, rb_cInteger)) {
		rb_raise(rb_eTypeError, "cannot exclude non Integer end value");
	    }
	    if (c == 0) return Qnil;
	    if (!FIXNUM_P(b) && !rb_obj_is_kind_of(b,rb_cInteger)) {
		rb_raise(rb_eTypeError, "cannot exclude end value with non Integer begin value");
	    }
	    if (FIXNUM_P(e)) {
		return LONG2NUM(FIX2LONG(e) - 1);
	    }
	    return rb_funcall(e, '-', 1, INT2FIX(1));
	}
	return e;
    }
}
开发者ID:DashYang,项目名称:sim,代码行数:31,代码来源:range.c


示例2: range_max

static VALUE
range_max(VALUE range, SEL sel)
{
    VALUE e = RANGE_END(range);
    int nm = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric);

    if (rb_block_given_p() || (EXCL(range) && !nm)) {
	if (sel == NULL) {
	    sel = sel_registerName("max");
	}
	return rb_vm_call_super(range, sel, 0, NULL);
    }
    else {
	VALUE b = RANGE_BEG(range);
	int c = rb_cmpint(rb_objs_cmp(b, e), b, e);

	if (c > 0)
	    return Qnil;
	if (EXCL(range)) {
	    if (!FIXNUM_P(e) && !rb_obj_is_kind_of(e, rb_cInteger)) {
		rb_raise(rb_eTypeError, "cannot exclude non Integer end value");
	    }
	    if (c == 0) {
		return Qnil;
	    }
	    if (FIXNUM_P(e)) {
		return LONG2NUM(FIX2LONG(e) - 1);
	    }
	    VALUE one = INT2FIX(1);
	    return rb_vm_call(e, selMINUS, 1, &one);
	}
	return e;
    }
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:34,代码来源:range.c


示例3: cmp_gt

static VALUE
cmp_gt(VALUE x, VALUE y)
{
    VALUE c = rb_funcall(x, cmp, 1, y);

    if (rb_cmpint(c, x, y) > 0) return Qtrue;
    return Qfalse;
}
开发者ID:brightbox,项目名称:deb-ruby1.9.1,代码行数:8,代码来源:compar.c


示例4: cmp_eq

static VALUE
cmp_eq(VALUE *a)
{
    VALUE c = rb_exec_recursive_paired_outer(cmp_eq_recursive, a[0], a[1], a[1]);

    if (NIL_P(c)) return Qfalse;
    if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
    return Qfalse;
}
开发者ID:brightbox,项目名称:deb-ruby1.9.1,代码行数:9,代码来源:compar.c


示例5: cmp_1

static int
cmp_1(const void *ap, const void *bp, void *dummy)
{
    struct sort_data *d = dummy;
    VALUE a = rb_enc_str_new(ap, d->elsize, d->enc);
    VALUE b = rb_enc_str_new(bp, d->elsize, d->enc);
    VALUE retval = rb_yield_values(2, a, b);
    return rb_cmpint(retval, a, b);
}
开发者ID:tenderlove,项目名称:ruby,代码行数:9,代码来源:qsort.c


示例6: cmp_eq

static VALUE
cmp_eq(VALUE *a)
{
    VALUE c = rb_funcall(a[0], cmp, 1, a[1]);

    if (NIL_P(c)) return Qfalse;
    if (rb_cmpint(c, a[0], a[1]) == 0) return Qtrue;
    return Qfalse;
}
开发者ID:yard,项目名称:yet-another-ruby-database,代码行数:9,代码来源:compar.c


示例7: cmp_gt

static VALUE
cmp_gt(VALUE x, SEL sel, VALUE y)
{
    VALUE c = rb_vm_call(x, cmp, 1, &y);
    if (rb_cmpint(c, x, y) > 0) {
	return Qtrue;
    }
    return Qfalse;
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:9,代码来源:compar.c


示例8: r_lt

static int
r_lt(VALUE a, VALUE b)
{
    VALUE r = rb_funcall(a, id_cmp, 1, b);

    if (NIL_P(r))
	return (int)Qfalse;
    if (rb_cmpint(r, a, b) < 0)
	return (int)Qtrue;
    return (int)Qfalse;
}
开发者ID:DashYang,项目名称:sim,代码行数:11,代码来源:range.c


示例9: r_lt

static int
r_lt(VALUE a, VALUE b)
{
    VALUE r = rb_objs_cmp(a, b);

    if (NIL_P(r))
	return Qfalse;
    if (rb_cmpint(r, a, b) < 0)
	return Qtrue;
    return Qfalse;
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:11,代码来源:range.c


示例10: rb_invcmp

VALUE
rb_invcmp(VALUE x, VALUE y)
{
    VALUE invcmp = rb_exec_recursive(invcmp_recursive, x, y);
    if (invcmp == Qundef || NIL_P(invcmp)) {
	return Qnil;
    }
    else {
	int result = -rb_cmpint(invcmp, x, y);
	return INT2FIX(result);
    }
}
开发者ID:Shopify,项目名称:ruby,代码行数:12,代码来源:compar.c


示例11: cmp_eq

static VALUE
cmp_eq(VALUE *a)
{
    VALUE c = rb_vm_call(a[0], cmp, 1, &a[1]);
    if (NIL_P(c)) {
	return Qfalse;
    }
    if (rb_cmpint(c, a[0], a[1]) == 0) {
	return Qtrue;
    }
    return Qfalse;
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:12,代码来源:compar.c


示例12: cmp_equal

static VALUE
cmp_equal(VALUE x, VALUE y)
{
    VALUE c;
    if (x == y) return Qtrue;

    c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y);

    if (NIL_P(c)) return Qfalse;
    if (rb_cmpint(c, x, y) == 0) return Qtrue;
    return Qfalse;
}
开发者ID:jbampton,项目名称:ruby-strip,代码行数:12,代码来源:compar.c


示例13: r_le

static int
r_le(VALUE a, VALUE b)
{
    int c;
    VALUE r = rb_objs_cmp(a, b);

    if (NIL_P(r))
	return Qfalse;
    c = rb_cmpint(r, a, b);
    if (c == 0)
	return INT2FIX(0);
    if (c < 0)
	return Qtrue;
    return Qfalse;
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:15,代码来源:range.c


示例14: r_le

static int
r_le(VALUE a, VALUE b)
{
    int c;
    VALUE r = rb_funcall(a, id_cmp, 1, b);

    if (NIL_P(r))
	return (int)Qfalse;
    c = rb_cmpint(r, a, b);
    if (c == 0)
	return (int)INT2FIX(0);
    if (c < 0)
	return (int)Qtrue;
    return (int)Qfalse;
}
开发者ID:DashYang,项目名称:sim,代码行数:15,代码来源:range.c


示例15: range_min

static VALUE
range_min(VALUE range)
{
    if (rb_block_given_p()) {
	return rb_call_super(0, 0);
    }
    else {
	VALUE b = RANGE_BEG(range);
	VALUE e = RANGE_END(range);
	int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);

	if (c > 0 || (c == 0 && EXCL(range)))
	    return Qnil;
	return b;
    }
}
开发者ID:agrimm,项目名称:ruby-benchmark-suite,代码行数:16,代码来源:range.c


示例16: range_min

static VALUE
range_min(VALUE range, SEL sel)
{
    if (rb_block_given_p()) {
	if (sel == NULL) {
	    sel = sel_registerName("min");
	}
	return rb_vm_call_super(range, sel, 0, NULL);
    }
    else {
	VALUE b = RANGE_BEG(range);
	VALUE e = RANGE_END(range);
	int c = rb_cmpint(rb_objs_cmp(b, e), b, e);

	if (c > 0 || (c == 0 && EXCL(range)))
	    return Qnil;
	return b;
    }
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:19,代码来源:range.c


示例17: range_min

static VALUE
range_min(int argc, VALUE *argv, VALUE range)
{
    if (rb_block_given_p()) {
	return rb_call_super(argc, argv);
    }
    else if (argc != 0) {
	return range_first(argc, argv, range);
    }
    else {
	VALUE b = RANGE_BEG(range);
	VALUE e = RANGE_END(range);
	int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);

	if (c > 0 || (c == 0 && EXCL(range)))
	    return Qnil;
	return b;
    }
}
开发者ID:DashYang,项目名称:sim,代码行数:19,代码来源:range.c


示例18: cmpint

static int
cmpint(VALUE x, VALUE y)
{
    return rb_cmpint(rb_cmp(x, y), x, y);
}
开发者ID:gferguson-gd,项目名称:ruby,代码行数:5,代码来源:compar.c


示例19: range_bsearch

static VALUE
range_bsearch(VALUE range)
{
    VALUE beg, end;
    int smaller, satisfied = 0;

    /* Implementation notes:
     * Floats are handled by mapping them to 64 bits integers.
     * Apart from sign issues, floats and their 64 bits integer have the
     * same order, assuming they are represented as exponent followed
     * by the mantissa. This is true with or without implicit bit.
     *
     * Finding the average of two ints needs to be careful about
     * potential overflow (since float to long can use 64 bits)
     * as well as the fact that -1/2 can be 0 or -1 in C89.
     *
     * Note that -0.0 is mapped to the same int as 0.0 as we don't want
     * (-1...0.0).bsearch to yield -0.0.
     */

#define BSEARCH_CHECK(val) \
    do { \
	VALUE v = rb_yield(val); \
	if (FIXNUM_P(v)) { \
	    if (FIX2INT(v) == 0) return val; \
	    smaller = FIX2INT(v) < 0; \
	} \
	else if (v == Qtrue) { \
	    satisfied = 1; \
	    smaller = 1; \
	} \
	else if (v == Qfalse || v == Qnil) { \
	    smaller = 0; \
	} \
	else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
	    int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
	    if (!cmp) return val; \
	    smaller = cmp < 0; \
	} \
	else { \
	    rb_raise(rb_eTypeError, "wrong argument type %s" \
		" (must be numeric, true, false or nil)", \
		rb_obj_classname(v)); \
	} \
    } while (0)

#define BSEARCH(conv) \
    do { \
	RETURN_ENUMERATOR(range, 0, 0); \
	if (EXCL(range)) high--; \
	org_high = high; \
	while (low < high) { \
	    mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
		: (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
	    BSEARCH_CHECK(conv(mid)); \
	    if (smaller) { \
		high = mid; \
	    } \
	    else { \
		low = mid + 1; \
	    } \
	} \
	if (low == org_high) { \
	    BSEARCH_CHECK(conv(low)); \
	    if (!smaller) return Qnil; \
	} \
	if (!satisfied) return Qnil; \
	return conv(low); \
    } while (0)


    beg = RANGE_BEG(range);
    end = RANGE_END(range);

    if (FIXNUM_P(beg) && FIXNUM_P(end)) {
	long low = FIX2LONG(beg);
	long high = FIX2LONG(end);
	long mid, org_high;
	BSEARCH(INT2FIX);
    }
#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
    else if (RB_TYPE_P(beg, T_FLOAT) || RB_TYPE_P(end, T_FLOAT)) {
	int64_t low  = double_as_int64(RFLOAT_VALUE(rb_Float(beg)));
	int64_t high = double_as_int64(RFLOAT_VALUE(rb_Float(end)));
	int64_t mid, org_high;
	BSEARCH(int64_as_double_to_num);
    }
#endif
    else if (is_integer_p(beg) && is_integer_p(end)) {
	VALUE low = rb_to_int(beg);
	VALUE high = rb_to_int(end);
	VALUE mid, org_high;
	RETURN_ENUMERATOR(range, 0, 0);
	if (EXCL(range)) high = rb_funcall(high, '-', 1, INT2FIX(1));
	org_high = high;

	while (rb_cmpint(rb_funcall(low, id_cmp, 1, high), low, high) < 0) {
	    mid = rb_funcall(rb_funcall(high, '+', 1, low), id_div, 1, INT2FIX(2));
	    BSEARCH_CHECK(mid);
	    if (smaller) {
//.........这里部分代码省略.........
开发者ID:DashYang,项目名称:sim,代码行数:101,代码来源:range.c


示例20: numeric_spec_rb_cmpint

static VALUE numeric_spec_rb_cmpint(VALUE self, VALUE val, VALUE b) {
  return INT2FIX(rb_cmpint(val, val, b));
}
开发者ID:ConradIrwin,项目名称:rubinius,代码行数:3,代码来源:numeric_spec.c



注:本文中的rb_cmpint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_color函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_class_name函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap