这篇教程C++ FIX2LONG函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中FIX2LONG函数的典型用法代码示例。如果您正苦于以下问题:C++ FIX2LONG函数的具体用法?C++ FIX2LONG怎么用?C++ FIX2LONG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了FIX2LONG函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: Constant_Traverser_rootVALUE Constant_Traverser_root(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_autovar_4=Qnil,_autovar_5=Qnil,_it=Qnil,_autovar_6=Qnil,__result=Qnil,_autovar_7=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=rb_funcall(self,sy_Constant_Traverser_src_dot_dup_d768,1,bind2); _autovar_3=it;;cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ptr->src=failobj;ptr->ary=alloca(sizeof(VALUE));ptr->ary[0]=_autovar_3;ptr->len=1; switch(FIX2LONG(rb_hash_aref(switchhash_Constant_Traverser_1,rb_obj_class(ame_curobj2(ptr))))){case 0/*Rule*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_4=it;; break;case 1/*Object*/:; if (1){it=failobj;goto pass1;} break;} goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; it=_autovar_4; _autovar_5=it;;cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_5); bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser_bind_lb_1_rb__lb__cf87,1,bind2);_autovar_2=bind_aget(bind2,1);;it=rb_funcall(self,sy_Constant_Traverser_src_dot_cfg_eq__15aa,1,bind2);bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Constant_Traverser_traverse(self ); if (it==failobj){it=failobj;goto pass2;} _it=it;;bind_aset(bind2,1,_it);it=rb_funcall(self,sy_Constant_Traverser_bind_lb_1_rb__dot__f702,1,bind2);_it=bind_aget(bind2,1);; _autovar_6=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto fail;} success2: *ptr=oldpass2; it=_autovar_6; __result=it;; _autovar_7=it;;bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_7);it=rb_funcall(self,sy_Constant_Traverser__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_7=bind_aget(bind2,2);;fail: return it;}
开发者ID:neleai,项目名称:mthyst,代码行数:24,
示例2: nurat_eqeq_p/* * call-seq: * rat == object -> true or false * * Returns true if rat equals object numerically. * * For example: * * Rational(2, 3) == Rational(2, 3) #=> true * Rational(5) == 5 #=> true * Rational(0) == 0.0 #=> true * Rational('1/3') == 0.33 #=> false * Rational('1/2') == '1/2' #=> false */static VALUEnurat_eqeq_p(VALUE self, SEL sel, VALUE other){ switch (TYPE(other)) { case T_FIXNUM: case T_BIGNUM: { get_dat1(self); if (f_zero_p(dat->num) && f_zero_p(other)) return Qtrue; if (!FIXNUM_P(dat->den)) return Qfalse; if (FIX2LONG(dat->den) != 1) return Qfalse; if (f_eqeq_p(dat->num, other)) return Qtrue; return Qfalse; } case T_FLOAT: return f_eqeq_p(f_to_f(self), other); case T_RATIONAL: { get_dat2(self, other); if (f_zero_p(adat->num) && f_zero_p(bdat->num)) return Qtrue; return f_boolcast(f_eqeq_p(adat->num, bdat->num) && f_eqeq_p(adat->den, bdat->den)); } default: return f_eqeq_p(other, self); }}
开发者ID:alloy,项目名称:mr-experimental,代码行数:50,
示例3: watchman_dump/** * Encodes and appends the serialized Ruby object `serializable` to `w` * * Examples of serializable objects include arrays, hashes, strings, numbers * (integers, floats), booleans, and nil. */void watchman_dump(watchman_t *w, VALUE serializable) { switch (TYPE(serializable)) { case T_ARRAY: return watchman_dump_array(w, serializable); case T_HASH: return watchman_dump_hash(w, serializable); case T_STRING: return watchman_dump_string(w, serializable); case T_FIXNUM: // up to 63 bits return watchman_dump_int(w, FIX2LONG(serializable)); case T_BIGNUM: return watchman_dump_int(w, NUM2LL(serializable)); case T_FLOAT: return watchman_dump_double(w, NUM2DBL(serializable)); case T_TRUE: return watchman_append(w, &watchman_true, sizeof(watchman_true)); case T_FALSE: return watchman_append(w, &watchman_false, sizeof(watchman_false)); case T_NIL: return watchman_append(w, &watchman_nil, sizeof(watchman_nil)); default: rb_raise(rb_eTypeError, "unsupported type"); }}
开发者ID:jiayong,项目名称:myvim,代码行数:30,
示例4: Detect_Contextual_Arguments_visitVALUE Detect_Contextual_Arguments_visit(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,__result=Qnil;VALUE bind2=bind_new2(1); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_1,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;;cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto pass1;} _autovar_2=it;;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Detect_Contextual_Arguments__append_lp__6b01,1,bind2);_autovar_2=bind_aget(bind2,1);;it=_autovar_2; _autovar_3=it;; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; it=_autovar_3; __result=it;; break;case 1/*Object*/:; if (1){it=failobj;goto fail;} break;}fail: return it;}
开发者ID:neleai,项目名称:mthyst,代码行数:15,
示例5: grpc_rb_time_timeval/** * grpc_rb_time_timeval creates a time_eval from a ruby time object. * * This func is copied from ruby source, MRI/source/time.c, which is published * under the same license as the ruby.h, on which the entire extensions is * based. */gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) { gpr_timespec t; gpr_timespec *time_const; const char *tstr = interval ? "time interval" : "time"; const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>"; t.clock_type = GPR_CLOCK_REALTIME; switch (TYPE(time)) { case T_DATA: if (CLASS_OF(time) == grpc_rb_cTimeVal) { TypedData_Get_Struct(time, gpr_timespec, &grpc_rb_timespec_data_type, time_const); t = *time_const; } else if (CLASS_OF(time) == rb_cTime) { t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0)); t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0)); } else { rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, rb_obj_classname(time), want); } break; case T_FIXNUM: t.tv_sec = FIX2LONG(time); if (interval && t.tv_sec < 0) rb_raise(rb_eArgError, "%s must be positive", tstr); t.tv_nsec = 0; break; case T_FLOAT: if (interval && RFLOAT_VALUE(time) < 0.0) rb_raise(rb_eArgError, "%s must be positive", tstr); else { double f, d; d = modf(RFLOAT_VALUE(time), &f); if (d < 0) { d += 1; f -= 1; } t.tv_sec = (time_t)f; if (f != t.tv_sec) { rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(time)); } t.tv_nsec = (int)(d * 1e9 + 0.5); } break; case T_BIGNUM: t.tv_sec = NUM2LONG(time); if (interval && t.tv_sec < 0) rb_raise(rb_eArgError, "%s must be positive", tstr); t.tv_nsec = 0; break; default: rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, rb_obj_classname(time), want); break; } return t;}
开发者ID:larsonmpdx,项目名称:grpc,代码行数:70,
示例6: ruby_curl_multi_set_default_timeout/* * call-seq: * Curl::Multi.default_timeout = 4 => 4 * * Set the global default time out for all Curl::Multi Handles. This value is used * when libcurl cannot determine a timeout value when calling curl_multi_timeout. * */VALUE ruby_curl_multi_set_default_timeout(VALUE klass, VALUE timeout) { cCurlMutiDefaulttimeout = FIX2LONG(timeout); return timeout;}
开发者ID:FooBarWidget,项目名称:curb,代码行数:12,
示例7: rb_str_format//.........这里部分代码省略......... if (flags & FSHARP) { switch (*p) { case 'o': prefix = "0"; break; case 'x': prefix = "0x"; break; case 'X': prefix = "0X"; break; case 'b': prefix = "0b"; break; case 'B': prefix = "0B"; break; } } bin_retry: switch (TYPE(val)) { case T_FLOAT: if (FIXABLE(RFLOAT_VALUE(val))) { val = LONG2FIX((long)RFLOAT_VALUE(val)); goto bin_retry; } val = rb_dbl2big(RFLOAT_VALUE(val)); if (FIXNUM_P(val)) goto bin_retry; bignum = 1; break; case T_STRING: val = rb_str_to_inum(val, 0, TRUE); goto bin_retry; case T_BIGNUM: bignum = 1; break; case T_FIXNUM: v = FIX2LONG(val); break; default: val = rb_Integer(val); goto bin_retry; } switch (*p) { case 'o': base = 8; break; case 'x': case 'X': base = 16; break; case 'b': case 'B': base = 2; break; case 'u': case 'd': case 'i': default: base = 10; break; } if (base != 10) { int numbits = ffs(base)-1; size_t abs_nlz_bits; size_t numdigits = rb_absint_numwords(val, numbits, &abs_nlz_bits); long i; if (INT_MAX-1 < numdigits) /* INT_MAX is used because rb_long2int is used later. */ rb_raise(rb_eArgError, "size too big"); if (sign) { if (numdigits == 0) numdigits = 1;
开发者ID:DashYang,项目名称:sim,代码行数:67,
示例8: my_methodVALUE my_method(VALUE self, VALUE num) { unsigned long myVal = FIX2LONG(num); printf("the int is %lu?/n", myVal); return LONG2FIX(num);}
开发者ID:bshlgrs,项目名称:big_o,代码行数:6,
示例9: symbol_spec_rb_intern3_c_compareVALUE symbol_spec_rb_intern3_c_compare(VALUE self, VALUE string, VALUE len, VALUE enc, VALUE sym) { ID symbol = rb_intern3(RSTRING_PTR(string), FIX2LONG(len), rb_enc_get(enc)); return (SYM2ID(sym) == symbol) ? Qtrue : Qfalse;}
开发者ID:jruby,项目名称:jruby,代码行数:4,
示例10: symbol_spec_rb_intern3VALUE symbol_spec_rb_intern3(VALUE self, VALUE string, VALUE len, VALUE enc) { return ID2SYM(rb_intern3(RSTRING_PTR(string), FIX2LONG(len), rb_enc_get(enc)));}
开发者ID:jruby,项目名称:jruby,代码行数:3,
示例11: symbol_spec_rb_intern2VALUE symbol_spec_rb_intern2(VALUE self, VALUE string, VALUE len) { return ID2SYM(rb_intern2(RSTRING_PTR(string), FIX2LONG(len)));}
开发者ID:jruby,项目名称:jruby,代码行数:3,
示例12: range_bsearchstatic VALUErange_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,
示例13: range_stepstatic VALUErange_step(int argc, VALUE *argv, VALUE range){ VALUE b, e, step, tmp; RETURN_SIZED_ENUMERATOR(range, argc, argv, range_step_size); b = RANGE_BEG(range); e = RANGE_END(range); if (argc == 0) { step = INT2FIX(1); } else { rb_scan_args(argc, argv, "01", &step); if (!rb_obj_is_kind_of(step, rb_cNumeric)) { step = rb_to_int(step); } if (rb_funcall(step, '<', 1, INT2FIX(0))) { rb_raise(rb_eArgError, "step can't be negative"); } else if (!rb_funcall(step, '>', 1, INT2FIX(0))) { rb_raise(rb_eArgError, "step can't be 0"); } } if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */ long end = FIX2LONG(e); long i, unit = FIX2LONG(step); if (!EXCL(range)) end += 1; i = FIX2LONG(b); while (i < end) { rb_yield(LONG2NUM(i)); if (i + unit < i) break; i += unit; } } else if (SYMBOL_P(b) && SYMBOL_P(e)) { /* symbols are special */ VALUE args[2], iter[2]; args[0] = rb_sym_to_s(e); args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_block_call(rb_sym_to_s(b), rb_intern("upto"), 2, args, sym_step_i, (VALUE)iter); } else if (ruby_float_step(b, e, step, EXCL(range))) { /* done */ } else if (rb_obj_is_kind_of(b, rb_cNumeric) || !NIL_P(rb_check_to_integer(b, "to_int")) || !NIL_P(rb_check_to_integer(e, "to_int"))) { ID op = EXCL(range) ? '<' : idLE; VALUE v = b; int i = 0; while (RTEST(rb_funcall(v, op, 1, e))) { rb_yield(v); i++; v = rb_funcall(b, '+', 1, rb_funcall(INT2NUM(i), '*', 1, step)); } } else { tmp = rb_check_string_type(b); if (!NIL_P(tmp)) { VALUE args[2], iter[2]; b = tmp; args[0] = e; args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_block_call(b, rb_intern("upto"), 2, args, step_i, (VALUE)iter); } else { VALUE args[2]; if (!discrete_object_p(b)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(b)); } args[0] = INT2FIX(1); args[1] = step; range_each_func(range, step_i, (VALUE)args); } } return range;}
开发者ID:DashYang,项目名称:sim,代码行数:91,
示例14: set_oci_number_from_num/* 1 - success, 0 - error */static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp){ signed long sl; if (!RTEST(rb_obj_is_kind_of(num, rb_cNumeric))) rb_raise(rb_eTypeError, "expect Numeric but %s", rb_class2name(CLASS_OF(num))); if (rb_respond_to(num, id_finite_p) && !RTEST(rb_funcall(num, id_finite_p, 0))) { rb_raise(rb_eTypeError, "cannot accept number which isn't finite."); } switch (rb_type(num)) { case T_FIXNUM: /* set from long. */ sl = NUM2LONG(num); chkerr(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); return 1; case T_FLOAT: /* set from double. */ oci8_dbl_to_onum(result, NUM2DBL(num), errhp); return 1; case T_BIGNUM: /* change via string. */ num = rb_big2str(num, 10); set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) { /* OCI::Number */ chkerr(OCINumberAssign(errhp, DATA_PTR(num), result)); return 1; } if (rb_respond_to(num, id_split)) { /* BigDecimal */ VALUE split = rb_funcall(num, id_split, 0); if (TYPE(split) == T_ARRAY && RARRAY_LEN(split) == 4) { /* * sign, significant_digits, base, exponent = num.split * onum = sign * "0.#{significant_digits}".to_f * (base ** exponent) */ VALUE *ary = RARRAY_PTR(split); int sign; OCINumber digits; int exponent; int digits_len; OCINumber work; /* check sign */ if (TYPE(ary[0]) != T_FIXNUM) { goto is_not_big_decimal; } sign = FIX2INT(ary[0]); /* check digits */ StringValue(ary[1]); digits_len = RSTRING_LEN(ary[1]); set_oci_number_from_str(&digits, ary[1], Qnil, Qnil, errhp); /* check base */ if (TYPE(ary[2]) != T_FIXNUM || FIX2LONG(ary[2]) != 10) { goto is_not_big_decimal; } /* check exponent */ if (TYPE(ary[3]) != T_FIXNUM) { goto is_not_big_decimal; } exponent = FIX2INT(ary[3]); chkerr(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); if (sign >= 0) { chkerr(OCINumberAssign(errhp, &work, result)); } else { chkerr(OCINumberNeg(errhp, &work, result)); } return 1; } }is_not_big_decimal: if (rb_respond_to(num, id_numerator) && rb_respond_to(num, id_denominator)) { /* Rational */ OCINumber numerator; OCINumber denominator; if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) && set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) { chkerr(OCINumberDiv(errhp, &numerator, &denominator, result)); return 1; } } if (force) { /* change via string as a last resort. */ /* TODO: if error, raise TypeError instead of OCI::Error */ set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } return 0;}
开发者ID:ashleysharpe,项目名称:ruby-oci8,代码行数:95,
示例15: cState_configure/* * call-seq: configure(opts) * * Configure this State instance with the Hash _opts_, and return * itself. */static VALUE cState_configure(VALUE self, VALUE opts){ VALUE tmp; GET_STATE(self); tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h"); if (NIL_P(tmp)) { rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash"); } opts = tmp; tmp = rb_hash_aref(opts, ID2SYM(i_indent)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->indent = fstrndup(RSTRING_PTR(tmp), len); state->indent_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_space)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->space = fstrndup(RSTRING_PTR(tmp), len); state->space_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_space_before)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->space_before = fstrndup(RSTRING_PTR(tmp), len); state->space_before_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_array_nl)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->array_nl = fstrndup(RSTRING_PTR(tmp), len); state->array_nl_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_object_nl)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->object_nl = fstrndup(RSTRING_PTR(tmp), len); state->object_nl_len = len; } tmp = ID2SYM(i_max_nesting); state->max_nesting = 19; if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); state->max_nesting = FIX2LONG(max_nesting); } else { state->max_nesting = 0; } } tmp = ID2SYM(i_depth); state->depth = 0; if (option_given_p(opts, tmp)) { VALUE depth = rb_hash_aref(opts, tmp); if (RTEST(depth)) { Check_Type(depth, T_FIXNUM); state->depth = FIX2LONG(depth); } else { state->depth = 0; } } tmp = ID2SYM(i_buffer_initial_length); if (option_given_p(opts, tmp)) { VALUE buffer_initial_length = rb_hash_aref(opts, tmp); if (RTEST(buffer_initial_length)) { long initial_length; Check_Type(buffer_initial_length, T_FIXNUM); initial_length = FIX2LONG(buffer_initial_length); if (initial_length > 0) state->buffer_initial_length = initial_length; } } tmp = rb_hash_aref(opts, ID2SYM(i_allow_nan)); state->allow_nan = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only)); state->ascii_only = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode)); state->quirks_mode = RTEST(tmp); return self;}
开发者ID:1nueve,项目名称:MacRuby,代码行数:96,
示例16: generate_json_fixnumstatic void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj){ fbuffer_append_long(buffer, FIX2LONG(obj));}
开发者ID:1nueve,项目名称:MacRuby,代码行数:4,
示例17: fix2intlong fix2int(VALUE x) { printf("fix2long called/n"); // return rb_num2int(x); return FIX2LONG(x); // return FIX2INT(x);}
开发者ID:SohumB,项目名称:Hubris-Haskell,代码行数:6,
示例18: rb_keychain_findstatic VALUE rb_keychain_find(int argc, VALUE *argv, VALUE self){ VALUE kind; VALUE attributes; VALUE first_or_all; rb_scan_args(argc, argv, "2:", &first_or_all, &kind, &attributes); Check_Type(first_or_all, T_SYMBOL); Check_Type(kind, T_STRING); CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(query, kSecReturnAttributes, kCFBooleanTrue); CFDictionarySetValue(query, kSecReturnRef, kCFBooleanTrue); if(rb_to_id(first_or_all) == rb_intern("all")){ CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitAll); } rb_add_value_to_cf_dictionary(query, kSecClass, kind); if(!NIL_P(attributes)){ Check_Type(attributes, T_HASH); VALUE rb_keychains = rb_hash_aref(attributes, ID2SYM(rb_intern("keychains"))); if(!NIL_P(rb_keychains)){ Check_Type(rb_keychains, T_ARRAY); CFMutableArrayRef searchArray = CFArrayCreateMutable(NULL, RARRAY_LEN(rb_keychains), &kCFTypeArrayCallBacks); for(int index=0; index < RARRAY_LEN(rb_keychains); index++){ SecKeychainRef keychain = NULL; Data_Get_Struct(RARRAY_PTR(rb_keychains)[index], struct OpaqueSecKeychainRef, keychain); CFArrayAppendValue(searchArray, keychain); } CFDictionarySetValue(query, kSecMatchSearchList,searchArray); CFRelease(searchArray); } VALUE limit = rb_hash_aref(attributes, ID2SYM(rb_intern("limit"))); if(!NIL_P(limit)){ Check_Type(limit, T_FIXNUM); long c_limit = FIX2LONG(limit); CFNumberRef cf_limit = CFNumberCreate(NULL, kCFNumberLongType, &c_limit); CFDictionarySetValue(query, kSecMatchLimit, cf_limit); CFRelease(cf_limit); } VALUE conditions = rb_hash_aref(attributes, ID2SYM(rb_intern("conditions"))); if(!NIL_P(conditions)){ Check_Type(conditions, T_HASH); VALUE rQuery = Data_Wrap_Struct(rb_cPointerWrapper, NULL, NULL, query); rb_block_call(conditions, rb_intern("each"), 0, NULL, RUBY_METHOD_FUNC(add_conditions_to_query), rQuery); } } CFDictionaryRef result; OSStatus status = SecItemCopyMatching(query, (CFTypeRef*)&result); CFRelease(query); VALUE rb_item = rb_ary_new2(0); switch(status){ case errSecItemNotFound: break; default: CheckOSStatusOrRaise(status); if(CFArrayGetTypeID() == CFGetTypeID(result)){ CFArrayRef result_array = (CFArrayRef)result; for(CFIndex i = 0; i < CFArrayGetCount(result_array); i++){ rb_ary_push(rb_item,rb_keychain_item_from_sec_dictionary(CFArrayGetValueAtIndex(result_array,i))); } } else{ rb_ary_push(rb_item, rb_keychain_item_from_sec_dictionary(result)); } CFRelease(result); } if(rb_to_id(first_or_all) == rb_intern("first")){ return rb_ary_entry(rb_item,0); } else{ return rb_item; }}
开发者ID:fcheung,项目名称:keychain_c,代码行数:87,
示例19: rb_feature_pstatic intrb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn){ VALUE features, this_feature_index = Qnil, v, p, load_path = 0; const char *f, *e; long i, len, elen, n; st_table *loading_tbl, *features_index; st_data_t data; int type; if (fn) *fn = 0; if (ext) { elen = strlen(ext); len = strlen(feature) - elen; type = rb ? 'r' : 's'; } else { len = strlen(feature); elen = 0; type = 0; } features = get_loaded_features(); features_index = get_loaded_features_index(); st_lookup(features_index, (st_data_t)feature, (st_data_t *)&this_feature_index); /* We search `features` for an entry such that either "#{features[i]}" == "#{load_path[j]}/#{feature}#{e}" for some j, or "#{features[i]}" == "#{feature}#{e}" Here `e` is an "allowed" extension -- either empty or one of the extensions accepted by IS_RBEXT, IS_SOEXT, or IS_DLEXT. Further, if `ext && rb` then `IS_RBEXT(e)`, and if `ext && !rb` then `IS_SOEXT(e) || IS_DLEXT(e)`. If `expanded`, then only the latter form (without load_path[j]) is accepted. Otherwise either form is accepted, *unless* `ext` is false and an otherwise-matching entry of the first form is preceded by an entry of the form "#{features[i2]}" == "#{load_path[j2]}/#{feature}#{e2}" where `e2` matches %r{^/.[^./]*$} but is not an allowed extension. After a "distractor" entry of this form, only entries of the form "#{feature}#{e}" are accepted. In `rb_provide_feature()` and `get_loaded_features_index()` we maintain an invariant that the array `this_feature_index` will point to every entry in `features` which has the form "#{prefix}#{feature}#{e}" where `e` is empty or matches %r{^/.[^./]*$}, and `prefix` is empty or ends in '/'. This includes both match forms above, as well as any distractors, so we may ignore all other entries in `features`. */ if (!NIL_P(this_feature_index)) { for (i = 0; ; i++) { VALUE entry; long index; if (RB_TYPE_P(this_feature_index, T_ARRAY)) { if (i >= RARRAY_LEN(this_feature_index)) break; entry = RARRAY_AREF(this_feature_index, i); } else { if (i > 0) break; entry = this_feature_index; } index = FIX2LONG(entry); v = RARRAY_AREF(features, index); f = StringValuePtr(v); if ((n = RSTRING_LEN(v)) < len) continue; if (strncmp(f, feature, len) != 0) { if (expanded) continue; if (!load_path) load_path = rb_get_expanded_load_path(); if (!(p = loaded_feature_path(f, n, feature, len, type, load_path))) continue; expanded = 1; f += RSTRING_LEN(p) + 1; } if (!*(e = f + len)) { if (ext) continue; return 'u'; } if (*e != '.') continue; if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) { return 's'; } if ((rb || !ext) && (IS_RBEXT(e))) { return 'r'; } } } loading_tbl = get_loading_table(); f = 0; if (!expanded) { struct loaded_feature_searching fs; fs.name = feature; fs.len = len; fs.type = type; fs.load_path = load_path ? load_path : rb_get_expanded_load_path(); fs.result = 0; st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);//.........这里部分代码省略.........
开发者ID:scorpion007,项目名称:ruby,代码行数:101,
示例20: oily_png_encode_png_image_pass_to_streamVALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE bit_depth, VALUE filtering) { UNUSED_PARAMETER(bit_depth); // Get the data char depth = (char) FIX2INT(bit_depth); long width = FIX2LONG(rb_funcall(self, rb_intern("width"), 0)); long height = FIX2LONG(rb_funcall(self, rb_intern("height"), 0)); VALUE pixels = rb_funcall(self, rb_intern("pixels"), 0); if (RARRAY_LEN(pixels) != width * height) { rb_raise(rb_eRuntimeError, "The number of pixels does not match the canvas dimensions."); } // Get the encoding palette if we're encoding to an indexed bytestream. VALUE encoding_palette = Qnil; if (FIX2INT(color_mode) == OILY_PNG_COLOR_INDEXED) { encoding_palette = oily_png_encode_palette(self); } char pixel_size = oily_png_pixel_bytesize(FIX2INT(color_mode), depth); long line_size = oily_png_scanline_bytesize(FIX2INT(color_mode), depth, width); long pass_size = oily_png_pass_bytesize(FIX2INT(color_mode), depth, width, height); // Allocate memory for the byte array. BYTE* bytes = ALLOC_N(BYTE, pass_size); // Get the scanline encoder function. scanline_encoder_func scanline_encoder = oily_png_encode_scanline_func(FIX2INT(color_mode), depth); if (scanline_encoder == NULL) { rb_raise(rb_eRuntimeError, "No encoder for color mode %d and bit depth %d", FIX2INT(color_mode), depth); } long y, pos; for (y = height - 1; y >= 0; y--) { pos = line_size * y; bytes[pos] = (BYTE) FIX2INT(filtering); scanline_encoder(bytes + pos + 1, pixels, y, width, encoding_palette); } if (FIX2INT(filtering) != OILY_PNG_FILTER_NONE) { // Get the scanline filter function void (*scanline_filter)(BYTE*, long, long, char) = NULL; switch (FIX2INT(filtering)) { case OILY_PNG_FILTER_SUB: scanline_filter = &oily_png_encode_filter_sub; break; case OILY_PNG_FILTER_UP: scanline_filter = &oily_png_encode_filter_up; break; case OILY_PNG_FILTER_AVERAGE: scanline_filter = &oily_png_encode_filter_average; break; case OILY_PNG_FILTER_PAETH: scanline_filter = &oily_png_encode_filter_paeth; break; default: rb_raise(rb_eRuntimeError, "Unsupported filter type: %d", FIX2INT(filtering)); } for (y = height - 1; y >= 0; y--) { scanline_filter(bytes, line_size * y, line_size, pixel_size); } } // Append to encoded image pass to the output stream. rb_str_cat(stream, (char*) bytes, pass_size); xfree(bytes); return Qnil;}
开发者ID:applitools,项目名称:oily_png,代码行数:62,
示例21: XFORMOBJ_bApplyXform// www.osr.com/ddk/graphics/gdifncs_027b.htmBOOLAPIENTRYXFORMOBJ_bApplyXform( IN XFORMOBJ *pxo, IN ULONG iMode, IN ULONG cPoints, IN PVOID pvIn, OUT PVOID pvOut){ MATRIX mx; XFORMOBJ xoInv; POINTL *pptl; INT i; /* Check parameters */ if (!pxo || !pvIn || !pvOut || cPoints < 1) { return FALSE; } /* Use inverse xform? */ if (iMode == XF_INV_FXTOL || iMode == XF_INV_LTOL) { XFORMOBJ_vInit(&xoInv, &mx); if (XFORMOBJ_iInverse(&xoInv, pxo) == DDI_ERROR) { return FALSE; } pxo = &xoInv; } /* Convert POINTL to POINTFIX? */ if (iMode == XF_LTOFX || iMode == XF_LTOL || iMode == XF_INV_LTOL) { pptl = pvIn; for (i = cPoints - 1; i >= 0; i--) { pptl[i].x = LONG2FIX(pptl[i].x); pptl[i].y = LONG2FIX(pptl[i].y); } } /* Do the actual fixpoint transformation */ if (!XFORMOBJ_bXformFixPoints(pxo, cPoints, pvIn, pvOut)) { return FALSE; } /* Convert POINTFIX to POINTL? */ if (iMode == XF_INV_FXTOL || iMode == XF_INV_LTOL || iMode == XF_LTOL) { pptl = pvOut; for (i = cPoints - 1; i >= 0; i--) { pptl[i].x = FIX2LONG(pptl[i].x); pptl[i].y = FIX2LONG(pptl[i].y); } } return TRUE;}
开发者ID:Nevermore2015,项目名称:reactos,代码行数:62,
示例22: Dead_Code_Deleter3_visitVALUE Dead_Code_Deleter3_visit(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_this=Qnil,__result=Qnil,_autovar_4=Qnil,_autovar_5=Qnil,_autovar_6=Qnil,_autovar_7=Qnil,_autovar_8=Qnil,_autovar_9=Qnil,_autovar_10=Qnil,_autovar_11=Qnil,_autovar_12=Qnil,_autovar_13=Qnil,_t=Qnil,_autovar_14=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Dead_Code_Deleter3_2,rb_obj_class(ame_curobj2(ptr))))){case 0/*Act*/:case 1/*CAct*/:case 2/*Local*/:case 3/*Result*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;;cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_funcall(self,sy_Dead_Code_Deleter3_src_25d9,1,bind2); _this=it;;ptr->pos=ptr->len; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; bind_aset(bind2,1,_autovar_2);bind_aset(bind2,2,_this);it=rb_funcall(self,sy_Dead_Code_Deleter3__lp_,1,bind2);_autovar_2=bind_aget(bind2,1);;_this=bind_aget(bind2,2);; __result=it;; _autovar_4=it;;bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break;case 4/*Apply*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_5=it;;cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_5); ptr->pos=ptr->len;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_d_eq_src_dot_du_2b46,1,bind2);_autovar_2=bind_aget(bind2,1);; _autovar_6=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto fail;} success2: *ptr=oldpass2; it=_autovar_6; __result=it;; _autovar_4=it;;bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break;case 5/*Bind*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_7=it;;cstruct oldpass3=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_7); ptr->pos=ptr->len;it=rb_funcall(self,sy_Dead_Code_Deleter3_src_25d9,1,bind2);bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_bind_lb_1_rb__lb__146c,1,bind2);_autovar_2=bind_aget(bind2,1);;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Dead_Code_Deleter3_traverse(self ); if (it==failobj){it=failobj;goto pass3;} _autovar_8=it;;cstruct oldpass4=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_8); ptr->pos=ptr->len;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_bind_lb_1_rb__lb__8eca,1,bind2);_autovar_2=bind_aget(bind2,1);; _autovar_9=it;; goto success4; pass4: *ptr=oldpass4;if (1){it=failobj;goto pass3;} success4: *ptr=oldpass4; it=_autovar_9; _autovar_10=it;; goto success3; pass3: *ptr=oldpass3;if (1){it=failobj;goto fail;} success3: *ptr=oldpass3; it=_autovar_10; __result=it;; _autovar_4=it;;bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break;case 6/*Pass*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_11=it;;cstruct oldpass5=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_11); it=rb_funcall(self,sy_Dead_Code_Deleter3_src_dot_to_5e99,1,bind2); _autovar_12=it;;cstruct oldpass6=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ptr->src=failobj;ptr->ary=alloca(sizeof(VALUE));ptr->ary[0]=_autovar_12;ptr->len=1; bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Dead_Code_Deleter3_traverse_item(self ); if (it==failobj){it=failobj;goto pass6;} _autovar_13=it;; goto success6; pass6: *ptr=oldpass6;if (1){it=failobj;goto pass5;} success6: *ptr=oldpass6; it=_autovar_13; _t=it;;bind_aset(bind2,1,_t);it=rb_funcall(self,sy_Dead_Code_Deleter3_d_eq_src_dot_du_d571,1,bind2);_t=bind_aget(bind2,1);; _autovar_14=it;; goto success5; pass5: *ptr=oldpass5;if (1){it=failobj;goto fail;} success5: *ptr=oldpass5; it=_autovar_14; __result=it;; _autovar_4=it;;bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break;case 7/*Object*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;if (1){it=failobj;goto fail;} break;}fail: return it;}
开发者ID:neleai,项目名称:mthyst,代码行数:65,
示例23: MessagePack_Fixnum_to_msgpack/* * Document-method: Fixnum#to_msgpack * * call-seq: * fixnum.to_msgpack(out = '') -> String * * Serializes the Fixnum into raw bytes. */static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self){ ARG_BUFFER(out, argc, argv); msgpack_pack_long(out, FIX2LONG(self)); return out;}
开发者ID:vincentdephily,项目名称:msgpack,代码行数:14,
示例24: range_stepstatic VALUErange_step(VALUE range, SEL sel, int argc, VALUE *argv){ VALUE b, e, step, tmp; RETURN_ENUMERATOR(range, argc, argv); b = RANGE_BEG(range); e = RANGE_END(range); if (argc == 0) { step = INT2FIX(1); } else { rb_scan_args(argc, argv, "01", &step); if (!rb_obj_is_kind_of(step, rb_cNumeric)) { step = rb_to_int(step); } VALUE zero = INT2FIX(0); if (rb_vm_call(step, selLT, 1, &zero)) { rb_raise(rb_eArgError, "step can't be negative"); } else if (!rb_vm_call(step, selGT, 1, &zero)) { rb_raise(rb_eArgError, "step can't be 0"); } } if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */ long end = FIX2LONG(e); long i, unit = FIX2LONG(step); if (!EXCL(range)) end += 1; i = FIX2LONG(b); while (i < end) { rb_yield(LONG2NUM(i)); RETURN_IF_BROKEN(); if (i + unit < i) break; i += unit; } } else if (SYMBOL_P(b) && SYMBOL_P(e)) { /* symbols are special */ VALUE args[2]; VALUE iter[2]; args[0] = rb_sym_to_s(e); args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_objc_block_call(rb_sym_to_s(b), selUpto, 2, args, sym_step_i, (VALUE)iter); } else if (ruby_float_step(b, e, step, EXCL(range))) { /* done */ } else if (rb_obj_is_kind_of(b, rb_cNumeric) || !NIL_P(rb_check_to_integer(b, "to_int")) || !NIL_P(rb_check_to_integer(e, "to_int"))) { SEL op = EXCL(range) ? selLT : selLE; VALUE v = b; int i = 0; while (RTEST(rb_vm_call(v, op, 1, &e))) { rb_yield(v); RETURN_IF_BROKEN(); i++; VALUE tmp = rb_vm_call(INT2NUM(i), selMULT, 1, &step); v = rb_vm_call(b, selPLUS, 1, &tmp); } } else { tmp = rb_check_string_type(b); if (!NIL_P(tmp)) { VALUE args[2], iter[2]; b = tmp; args[0] = e; args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_objc_block_call(b, selUpto, 2, args, step_i, (VALUE)iter); } else { VALUE args[2]; if (!discrete_object_p(b)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(b)); } args[0] = INT2FIX(1); args[1] = step; return range_each_func(range, step_i, args); } } return range;}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:96,
示例25: nucomp_expt/* * call-seq: * cmp ** numeric -> complex * * Performs exponentiation. * * Complex('i') ** 2 #=> (-1+0i) * Complex(-8) ** Rational(1, 3) #=> (1.0000000000000002+1.7320508075688772i) */static VALUEnucomp_expt(VALUE self, VALUE other){ if (k_numeric_p(other) && k_exact_zero_p(other)) return f_complex_new_bang1(CLASS_OF(self), ONE); if (k_rational_p(other) && f_one_p(f_denominator(other))) other = f_numerator(other); /* c14n */ if (k_complex_p(other)) { get_dat1(other); if (k_exact_zero_p(dat->imag)) other = dat->real; /* c14n */ } if (k_complex_p(other)) { VALUE r, theta, nr, ntheta; get_dat1(other); r = f_abs(self); theta = f_arg(self); nr = m_exp_bang(f_sub(f_mul(dat->real, m_log_bang(r)), f_mul(dat->imag, theta))); ntheta = f_add(f_mul(theta, dat->real), f_mul(dat->imag, m_log_bang(r))); return f_complex_polar(CLASS_OF(self), nr, ntheta); } if (k_fixnum_p(other)) { if (f_gt_p(other, ZERO)) { VALUE x, z; long n; x = self; z = x; n = FIX2LONG(other) - 1; while (n) { long q, r; while (1) { get_dat1(x); q = n / 2; r = n % 2; if (r) break; x = nucomp_s_new_internal(CLASS_OF(self), f_sub(f_mul(dat->real, dat->real), f_mul(dat->imag, dat->imag)), f_mul(f_mul(TWO, dat->real), dat->imag)); n = q; } z = f_mul(z, x); n--; } return z; } return f_expt(f_reciprocal(self), f_negate(other)); } if (k_numeric_p(other) && f_real_p(other)) { VALUE r, theta; if (k_bignum_p(other)) rb_warn("in a**b, b may be too big"); r = f_abs(self); theta = f_arg(self); return f_complex_polar(CLASS_OF(self), f_expt(r, other), f_mul(theta, other)); } return rb_num_coerce_bin(self, other, id_expt);}
开发者ID:gogotanaka,项目名称:ruby_svn,代码行数:87,
示例26: date_strftime_with_tmxstatic size_tdate_strftime_with_tmx(char *s, size_t maxsize, const char *format, const struct tmx *tmx){ char *endp = s + maxsize; char *start = s; const char *sp, *tp; auto char tbuf[100]; ptrdiff_t i; int v, w; size_t colons; int precision, flags; char padding; /* LOCALE_[OE] and COLONS are actually modifiers, not flags */ enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E, COLONS};#define BIT_OF(n) (1U<<(n)) /* various tables for locale C */ static const char days_l[][10] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", }; static const char months_l[][10] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", }; static const char ampm[][3] = { "AM", "PM", }; if (s == NULL || format == NULL || tmx == NULL || maxsize == 0) return 0; /* quick check if we even need to bother */ if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize) { err: errno = ERANGE; return 0; } for (; *format && s < endp - 1; format++) {#define FLAG_FOUND() do { / if (precision > 0 || flags & (BIT_OF(LOCALE_E) | BIT_OF(LOCALE_O) | BIT_OF(COLONS))) / goto unknown; / } while (0)#define NEEDS(n) do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)#define FILL_PADDING(i) do { / if (!(flags & BIT_OF(LEFT)) && precision > (i)) { / NEEDS(precision); / memset(s, padding ? padding : ' ', precision - (i)); / s += precision - (i); / } / else { / NEEDS(i); / } / } while (0);#define FMT(def_pad, def_prec, fmt, val) / do { / int l; / if (precision <= 0) precision = (def_prec); / if (flags & BIT_OF(LEFT)) precision = 1; / l = snprintf(s, endp - s, / ((padding == '0' || (!padding && (def_pad) == '0')) ? / "%0*"fmt : "%*"fmt), / precision, (val)); / if (l < 0) goto err; / s += l; / } while (0)#define STRFTIME(fmt) / do { / i = date_strftime_with_tmx(s, endp - s, (fmt), tmx); / if (!i) return 0; / if (flags & BIT_OF(UPPER)) / upcase(s, i); / if (!(flags & BIT_OF(LEFT)) && precision > i) { / if (start + maxsize < s + precision) { / errno = ERANGE; / return 0; / } / memmove(s + precision - i, s, i); / memset(s, padding ? padding : ' ', precision - i); / s += precision; / } / else s += i; / } while (0)#define FMTV(def_pad, def_prec, fmt, val) / do { / VALUE tmp = (val); / if (FIXNUM_P(tmp)) { / FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); / } / else { / VALUE args[2], result; / size_t l; / if (precision <= 0) precision = (def_prec); / if (flags & BIT_OF(LEFT)) precision = 1; / args[0] = INT2FIX(precision); / args[1] = (val); / if (padding == '0' || (!padding && (def_pad) == '0')) / result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); / else ///.........这里部分代码省略.........
开发者ID:0x00evil,项目名称:ruby,代码行数:101,
示例27: Detect_Contextual_Arguments_traverse_itemVALUE Detect_Contextual_Arguments_traverse_item(VALUE self ){VALUE vals[0]; VALUE it ,__result=Qnil,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_ar=Qnil,_it=Qnil,_autovar_4=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_2,rb_obj_class(ame_curobj2(ptr))))){case 0/*AmethystAST*/:; switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_3,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; int oldpos1=ptr->pos;int cut1=0;alt1_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=3; it=Detect_Contextual_Arguments_visit(self ); if (it==failobj){it=failobj;goto revert1;} __result=it;;;goto accept2;revert1:; goto alt1_2; accept2:;;ptr->branches-=3; goto accept1;alt1_2: ptr->pos=oldpos1;ptr->branches-=1; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;;cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=Detect_Contextual_Arguments_traverse(self ); if (it==failobj){it=failobj;goto pass1;} _autovar_2=it;; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto revert2;} success1: *ptr=oldpass1; it=_autovar_2; __result=it;;;goto accept3;revert2:; goto alt1_3; accept3:;;ptr->branches-=2; goto accept1;alt1_3: ptr->pos=oldpos1;ptr->branches-=1; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto revert3;} __result=it;;;goto accept4;revert3:; goto alt1_4; accept4:;;ptr->branches-=1; goto accept1;alt1_4: ptr->pos=oldpos1;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept1:; break;case 1/*Object*/:; int oldpos2=ptr->pos;int cut2=0;alt2_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;;cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=Detect_Contextual_Arguments_traverse(self ); if (it==failobj){it=failobj;goto pass2;} _autovar_2=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto revert4;} success2: *ptr=oldpass2; it=_autovar_2; __result=it;;;goto accept6;revert4:; goto alt2_2; accept6:;;ptr->branches-=2; goto accept5;alt2_2: ptr->pos=oldpos2;ptr->branches-=1; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto revert5;} __result=it;;;goto accept7;revert5:; goto alt2_3; accept7:;;ptr->branches-=1; goto accept5;alt2_3: ptr->pos=oldpos2;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept5:; break;} break;case 1/*Array*/:; switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_4,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; int oldpos3=ptr->pos;int cut3=0;alt3_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_visit(self ); if (it==failobj){it=failobj;goto revert6;} __result=it;;;goto accept9;revert6:; goto alt3_2; accept9:;;ptr->branches-=2; goto accept8;alt3_2: ptr->pos=oldpos3;ptr->branches-=1; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;;cstruct oldpass3=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_ary_new3(0); _ar=it;;int stop1=0; while(!stop1){ int oldpos4=ptr->pos;int cut4=0;alt4_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_traverse_item(self ); if (it==failobj){it=failobj;goto revert8;} _it=it;;bind_aset(bind2,1,_ar);bind_aset(bind2,2,_it);it=rb_funcall(self,sy_Detect_Contextual_Arguments_bind_lb_1_rb__lt__7b20,1,bind2);_ar=bind_aget(bind2,1);;_it=bind_aget(bind2,2);;;goto accept12;revert8:; goto alt4_2; accept12:;;ptr->branches-=2; goto accept11;alt4_2: ptr->pos=oldpos4;ptr->branches-=1; stop1=1;;goto accept13;revert9:; goto alt4_3; accept13:;;ptr->branches-=1; goto accept11;alt4_3: ptr->pos=oldpos4;ptr->branches-=1;if (1){it=failobj;goto pass3;}; accept11:; } it=_ar; _autovar_4=it;; goto success3; pass3: *ptr=oldpass3;if (1){it=failobj;goto revert7;} success3: *ptr=oldpass3; it=_autovar_4; __result=it;;;goto accept10;revert7:; goto alt3_3; accept10:;;ptr->branches-=1; goto accept8;alt3_3: ptr->pos=oldpos3;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept8:; break;case 1/*Object*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;;cstruct oldpass4=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_ary_new3(0); _ar=it;;int stop2=0; while(!stop2){ int oldpos5=ptr->pos;int cut5=0;alt5_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_traverse_item(self ); if (it==failobj){it=failobj;goto revert10;} _it=it;;bind_aset(bind2,1,_ar);bind_aset(bind2,2,_it);it=rb_funcall(self,sy_Detect_Contextual_Arguments_bind_lb_1_rb__lt__7b20,1,bind2);_ar=bind_aget(bind2,1);;_it=bind_aget(bind2,2);;;goto accept15;revert10:; goto alt5_2; accept15:;;ptr->branches-=2; goto accept14;alt5_2: ptr->pos=oldpos5;ptr->branches-=1; stop2=1;;goto accept16;revert11:; goto alt5_3; accept16:;;ptr->branches-=1; goto accept14;alt5_3: ptr->pos=oldpos5;ptr->branches-=1;if (1){it=failobj;goto pass4;};//.........这里部分代码省略.........
开发者ID:neleai,项目名称:mthyst,代码行数:101,
示例28: cState_max_nesting_set/* * call-seq: max_nesting=(depth) * * This sets the maximum level of data structure nesting in the generated JSON * to the integer depth, max_nesting = 0 if no maximum should be checked. */static VALUE cState_max_nesting_set(VALUE self, VALUE depth){ GET_STATE(self); Check_Type(depth, T_FIXNUM); return state->max_nesting = FIX2LONG(depth);}
开发者ID:1nueve,项目名称:MacRuby,代码行数:12,
注:本文中的FIX2LONG函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ FIXED_TO_INT函数代码示例 C++ FIX2INT函数代码示例 |