当前位置: 首页>>代码示例>>C++>>正文


C++ FIXNUM_P函数代码示例

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


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

示例1: r_gmprandstatesg_new

/*
 * call-seq:
 *   GMP::RandState.new()
 *   GMP::RandState.new(:mt) #=> uses gmp_randinit_mt
 *   GMP::RandState.new(:lc_2exp, a, c, m2exp) #=> uses gmp_randinit_lc_2exp
 *   GMP::RandState.new(:lc_2exp_size, size) #=> uses gmp_randinit_lc_2exp_size
 *
 * Initializes a new Random State object. Multiple GMP::RandState objects can
 * be instantiated. They may use different generators and the states
 * are kept separate.
 */
VALUE r_gmprandstatesg_new(int argc, VALUE *argv, VALUE klass)
{
  MP_RANDSTATE *rs_val;
  VALUE rs;
  VALUE algorithm, arg2, arg3, arg4;
  ID algorithm_id = rb_intern("default");
  MP_INT *a_val;
  unsigned long c_val, m2exp_val;
  unsigned long size_val;
  int free_a_val = 0;

  ID default_algorithm      = rb_intern("default");
  ID mt_algorithm           = rb_intern("mt");
  ID lc_2exp_algorithm      = rb_intern("lc_2exp");
  ID lc_2exp_size_algorithm = rb_intern("lc_2exp_size");

  (void)klass;

  mprandstate_make_struct(rs, rs_val);
  rb_scan_args(argc, argv, "04", &algorithm, &arg2, &arg3, &arg4);
  if (NIL_P(algorithm))    { algorithm_id = rb_intern("default"); }  /* default value */
  if (SYMBOL_P(algorithm)) { algorithm_id = rb_to_id(algorithm); }
  if (algorithm_id == default_algorithm ||
      algorithm_id == mt_algorithm) {
    if (argc > 1)
      rb_raise(rb_eArgError, "wrong # of arguments (%d for 0 or 1)", argc);
    gmp_randinit_default(rs_val);
  } else if (algorithm_id == lc_2exp_algorithm) {
    if (argc != 4)
      rb_raise(rb_eArgError, "wrong # of arguments (%d for 4)", argc);
    if (GMPZ_P(arg2)) {
      mpz_get_struct(arg2, a_val);
    } else if (FIXNUM_P(arg2)) {
      mpz_temp_alloc(a_val);
      mpz_init_set_ui(a_val, FIX2INT(arg2));
      free_a_val = 1;
    } else if (BIGNUM_P(arg2)) {
      mpz_temp_from_bignum(a_val, arg2);
      free_a_val = 1;
    } else {
      typeerror_as(ZXB, "b");
    }
    c_val     = NUM2LONG(arg3);
    m2exp_val = NUM2LONG(arg4);
    gmp_randinit_lc_2exp(rs_val, a_val, c_val, m2exp_val);
  } else if (algorithm_id == lc_2exp_size_algorithm) {
    if (argc != 2)
      rb_raise(rb_eArgError, "wrong # of arguments (%d for 2)", argc);
    size_val = NUM2LONG(arg2);
    if (size_val > 128)
      rb_raise(rb_eArgError, "size must be within [0..128]");
    if (gmp_randinit_lc_2exp_size (rs_val, size_val) == 0)
      rb_raise(rb_eArgError, "could not gmp_randinit_lc_2exp_size with %lu", size_val);
  }

  if (free_a_val) { mpz_temp_free(a_val); }
  rb_obj_call_init(rs, argc, argv);

  return rs;
}
开发者ID:sagmor,项目名称:gmp,代码行数:71,代码来源:gmprandstate.c

示例2: f_div

inline static VALUE
f_div(VALUE x, VALUE y)
{
    if (FIXNUM_P(y) && FIX2LONG(y) == 1)
	return x;
    return rb_funcall(x, '/', 1, y);
}
开发者ID:Netfart,项目名称:rhodes,代码行数:7,代码来源:rational.c

示例3: r_gmprandstate_urandomm

/*
 * call-seq:
 *   rand_state.urandomm(integer)
 *
 * From the GMP Manual:
 *
 * Generate a uniformly distributed random integer in the range 0 to
 * _integer-1_, inclusive. _integer_ can be an instance of GMP::Z,
 *  Fixnum, or Bignum
 */
VALUE r_gmprandstate_urandomm(VALUE self, VALUE arg)
{
  MP_RANDSTATE *self_val;
  MP_INT *res_val, *arg_val;
  int free_arg_val = 0;
  VALUE res;

  mprandstate_get_struct(self,self_val);

  if (GMPZ_P(arg)) {
    mpz_get_struct(arg, arg_val);
  } else if (FIXNUM_P(arg)) {
    mpz_temp_alloc(arg_val);
    mpz_init_set_ui(arg_val, FIX2INT(arg));
    free_arg_val = 1;
  } else if (BIGNUM_P(arg)) {
    mpz_temp_from_bignum(arg_val, arg);
    free_arg_val = 1;
  } else {
    typeerror_as(ZXB, "arg");
  }

  mpz_make_struct_init(res, res_val);
  mpz_urandomm(res_val, self_val, arg_val);
  if (free_arg_val) { mpz_temp_free(arg_val); }

  return res;
}
开发者ID:sagmor,项目名称:gmp,代码行数:38,代码来源:gmprandstate.c

示例4: f_zero_p

inline static VALUE
f_zero_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) == 0);
    return rb_funcall(x, id_equal_p, 1, ZERO);
}
开发者ID:Netfart,项目名称:rhodes,代码行数:7,代码来源:rational.c

示例5: wrap_snd_seq_remove_events_set_time

/** call-seq:  time = time

Set the timestamp as removal condition.
Parameters:
[time]   an integer, for specifying ticks, or a tuple of splat of seconds and nanoseconds

Normally used with the flags +SND_SEQ_REMOVE_TIME_AFTER+ or +SND_SEQ_REMOVE_TIME_BEFORE+.

See RRTS::Driver::AlsaRemoveClass_i#condition=.

*/
static VALUE
wrap_snd_seq_remove_events_set_time(int argc, VALUE *argv, VALUE v_rmp)
{
  snd_seq_remove_events_t *rmp;
  Data_Get_Struct(v_rmp, snd_seq_remove_events_t, rmp);
  VALUE v_sec, v_nsec;
  rb_scan_args(argc, argv, "11", &v_sec, &v_nsec);
  snd_seq_timestamp_t time;
  if (NIL_P(v_nsec))
    {
      if (FIXNUM_P(v_sec))
          time.tick = NUM2UINT(v_sec);
      else
        {
          v_sec = rb_check_array_type(v_sec);
          if (!RTEST(v_sec)) RAISE_MIDI_ERROR_FMT0("API call error: bad time format");
          time.time.tv_sec = NUM2UINT(rb_ary_entry(v_sec, 0));
          time.time.tv_nsec = NUM2UINT(rb_ary_entry(v_sec, 1));
        }
    }
  else
    {
      time.time.tv_sec = NUM2UINT(v_sec);
      time.time.tv_nsec = NUM2UINT(v_nsec);
    }
  snd_seq_remove_events_set_time(rmp, &time);
  return Qnil;
}
开发者ID:EugeneBrazwick,项目名称:Midibox,代码行数:39,代码来源:alsa_remove.cpp

示例6: f_one_p

inline static VALUE
f_one_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) == 1);
    return rb_funcall(x, id_equal_p, 1, ONE);
}
开发者ID:Netfart,项目名称:rhodes,代码行数:7,代码来源:rational.c

示例7: f_negative_p

inline static VALUE
f_negative_p(VALUE x)
{
    if (FIXNUM_P(x))
	return f_boolcast(FIX2LONG(x) < 0);
    return rb_funcall(x, '<', 1, ZERO);
}
开发者ID:Netfart,项目名称:rhodes,代码行数:7,代码来源:rational.c

示例8: f_sub

inline static VALUE
f_sub(VALUE x, VALUE y)
{
    if (FIXNUM_P(y) && FIX2LONG(y) == 0)
	return x;
    return rb_funcall(x, '-', 1, y);
}
开发者ID:Netfart,项目名称:rhodes,代码行数:7,代码来源:rational.c

示例9: console_key_pressed_p

static VALUE
console_key_pressed_p(VALUE io, VALUE k)
{
    int vk = -1;

    if (FIXNUM_P(k)) {
	vk = NUM2UINT(k);
    }
    else {
	const struct vktable *t;
	const char *kn;
	if (SYMBOL_P(k)) {
	    k = rb_sym2str(k);
	    kn = RSTRING_PTR(k);
	}
	else {
	    kn = StringValuePtr(k);
	}
	t = console_win32_vk(kn, RSTRING_LEN(k));
	if (!t || (vk = (short)t->vk) == -1) {
	    rb_raise(rb_eArgError, "unknown virtual key code: % "PRIsVALUE, k);
	}
    }
    return GetKeyState(vk) & 0x80 ? Qtrue : Qfalse;
}
开发者ID:gferguson-gd,项目名称:ruby,代码行数:25,代码来源:console.c

示例10: r_gmprandstate_mpfr_urandomb

/*
 * call-seq:
 *   rand_state.mpfr_urandomb()
 *
 * From the MPFR Manual:
 *
 * Generate a uniformly distributed random float in the interval 0 <= rop < 1.
 */
VALUE r_gmprandstate_mpfr_urandomb(int argc, VALUE *argv, VALUE self)
{
  MP_RANDSTATE *self_val;
  MP_FLOAT *res_val;
  VALUE res;
  unsigned long prec = 0;
  
  if (argc > 1)
    rb_raise (rb_eArgError, "wrong # of arguments(%d for 0 or 1)", argc);

  mprandstate_get_struct (self,self_val);
  
  if (argc == 1) {
    if (FIXNUM_P (argv[0])) {
      if (FIX2INT (argv[0]) >= 0)
        prec = FIX2INT (argv[0]);
      else
        rb_raise (rb_eRangeError, "prec must be non-negative");
    } else {
      rb_raise (rb_eTypeError, "prec must be a Fixnum");
    }
  }
  
  mpf_make_struct (res, res_val);
  if (prec == 0) { mpf_init (res_val); }
  else           { mpf_init2 (res_val, prec); }
  
  mpfr_urandomb (res_val, self_val);
  
  return res;
}
开发者ID:sagmor,项目名称:gmp,代码行数:39,代码来源:gmprandstate.c

示例11: rb_builtin_class_name

const char *
rb_builtin_class_name(VALUE x)
{
    const char *etype;

    if (NIL_P(x)) {
	etype = "nil";
    }
    else if (FIXNUM_P(x)) {
	etype = "Fixnum";
    }
    else if (SYMBOL_P(x)) {
	etype = "Symbol";
    }
    else if (RB_TYPE_P(x, T_TRUE)) {
	etype = "true";
    }
    else if (RB_TYPE_P(x, T_FALSE)) {
	etype = "false";
    }
    else {
	etype = rb_obj_classname(x);
    }
    return etype;
}
开发者ID:corinroyal,项目名称:serenegreens,代码行数:25,代码来源:error.c

示例12: subIconDrawPoint

VALUE
subIconDrawPoint(int argc,
  VALUE *argv,
  VALUE self)
{
  VALUE data[4] = { Qnil };

  rb_scan_args(argc, argv, "22", &data[0], &data[1], &data[2], &data[3]);

  /* Check object types */
  if(FIXNUM_P(data[0]) && FIXNUM_P(data[1]))
    {
      SubtlextIcon *i = NULL;

      Data_Get_Struct(self, SubtlextIcon, i);
      if(i)
        {
          XGCValues gvals;

          /* Create on demand */
          if(0 == i->gc)
            i->gc = XCreateGC(display, i->pixmap, 0, NULL);

          /* Update GC */
          gvals.foreground = 1;
          gvals.background = 0;

          if(i->flags & ICON_PIXMAP)
            {
              if(!NIL_P(data[2]))
                gvals.foreground = subColorPixel(data[2], Qnil, Qnil, NULL);
              if(!NIL_P(data[3]))
                gvals.background = subColorPixel(data[3], Qnil, Qnil, NULL);
            }

          XChangeGC(display, i->gc, GCForeground|GCBackground, &gvals);

          XDrawPoint(display, i->pixmap, i->gc,
            FIX2INT(data[0]), FIX2INT(data[1]));

          XFlush(display);
        }
    }
  else rb_raise(rb_eArgError, "Unexpected value-types");

  return Qnil;
} /* }}} */
开发者ID:guns,项目名称:subtle,代码行数:47,代码来源:icon.c

示例13: range_each

static VALUE
range_each(VALUE range)
{
    VALUE beg, end;

    RETURN_SIZED_ENUMERATOR(range, 0, 0, range_enum_size);

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

    if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */
	long lim = FIX2LONG(end);
	long i;

	if (!EXCL(range))
	    lim += 1;
	for (i = FIX2LONG(beg); i < lim; i++) {
	    rb_yield(LONG2FIX(i));
	}
    }
    else if (SYMBOL_P(beg) && SYMBOL_P(end)) { /* symbols are special */
	VALUE args[2];

	args[0] = rb_sym_to_s(end);
	args[1] = EXCL(range) ? Qtrue : Qfalse;
	rb_block_call(rb_sym_to_s(beg), rb_intern("upto"), 2, args, sym_each_i, 0);
    }
    else {
	VALUE tmp = rb_check_string_type(beg);

	if (!NIL_P(tmp)) {
	    VALUE args[2];

	    args[0] = end;
	    args[1] = EXCL(range) ? Qtrue : Qfalse;
	    rb_block_call(tmp, rb_intern("upto"), 2, args, each_i, 0);
	}
	else {
	    if (!discrete_object_p(beg)) {
		rb_raise(rb_eTypeError, "can't iterate from %s",
			 rb_obj_classname(beg));
	    }
	    range_each_func(range, each_i, 0);
	}
    }
    return range;
}
开发者ID:DashYang,项目名称:sim,代码行数:47,代码来源:range.c

示例14: range_include

static VALUE
range_include(VALUE range, VALUE val)
{
    VALUE beg = RANGE_BEG(range);
    VALUE end = RANGE_END(range);
    int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
	     rb_obj_is_kind_of(beg, rb_cNumeric) ||
	     rb_obj_is_kind_of(end, rb_cNumeric);

    if (nv ||
	!NIL_P(rb_check_to_integer(beg, "to_int")) ||
	!NIL_P(rb_check_to_integer(end, "to_int"))) {
	if (r_le(beg, val)) {
	    if (EXCL(range)) {
		if (r_lt(val, end))
		    return Qtrue;
	    }
	    else {
		if (r_le(val, end))
		    return Qtrue;
	    }
	}
	return Qfalse;
    }
    else if (TYPE(beg) == T_STRING && TYPE(end) == T_STRING &&
	     RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) {
	if (NIL_P(val)) return Qfalse;
	if (TYPE(val) == T_STRING) {
	    if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1)
		return Qfalse;
	    else {
		char b = RSTRING_PTR(beg)[0];
		char e = RSTRING_PTR(end)[0];
		char v = RSTRING_PTR(val)[0];

		if (ISASCII(b) && ISASCII(e) && ISASCII(v)) {
		    if (b <= v && v < e) return Qtrue;
		    if (!EXCL(range) && v == e) return Qtrue;
		    return Qfalse;
		}
	    }
	}
    }
    /* TODO: ruby_frame->this_func = rb_intern("include?"); */
    return rb_call_super(1, &val);
}
开发者ID:agrimm,项目名称:ruby-benchmark-suite,代码行数:46,代码来源:range.c

示例15: vm_fast_minus

PRIMITIVE VALUE
vm_fast_minus(VALUE left, VALUE right, unsigned char overriden)
{
    if (overriden == 0 && NUMERIC_IMM_P(left) && NUMERIC_IMM_P(right)) {
	if (FIXNUM_P(left) && FIXNUM_P(right)) {
	    const long res = FIX2LONG(left) - FIX2LONG(right);
	    if (FIXABLE(res)) {
		return LONG2FIX(res);
	    }
	}
	else {
	    const double res = IMM2DBL(left) - IMM2DBL(right);
	    return DBL2FIXFLOAT(res);
	}
    }
    return vm_dispatch(0, left, selMINUS, NULL, 0, 1, &right);
}
开发者ID:silicon,项目名称:MacRuby,代码行数:17,代码来源:kernel.c


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