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


C++ rb_float_new函数代码示例

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


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

示例1: rb_gsl_function_graph

static VALUE rb_gsl_function_graph(int argc, VALUE *argv, VALUE obj)
{
#ifdef HAVE_GNU_GRAPH
  gsl_function *F = NULL;
  gsl_vector *v = NULL;
  double x, y;
  char opt[256] = "", command[1024];
  size_t i, n;
  int flag = 0;
  FILE *fp = NULL;
  VALUE ary, params, proc;
  switch (argc) {
  case 2:
    Check_Type(argv[1], T_STRING);
    strcpy(opt, STR2CSTR(argv[1]));
    /* no break, do next */
  case 1:
    if (CLASS_OF(argv[0]) == rb_cRange) argv[0] = rb_gsl_range2ary(argv[0]);
    if (TYPE(argv[0]) == T_ARRAY) {
      n = RARRAY(argv[0])->len;
      v = gsl_vector_alloc(n);
      flag = 1;
      for (i = 0; i < n; i++) 
	gsl_vector_set(v, i, NUM2DBL(rb_ary_entry(argv[0], i)));
    } else if (rb_obj_is_kind_of(argv[0], cgsl_vector)) {
      Data_Get_Struct(argv[0], gsl_vector, v);
      n = v->size;
      flag = 0;
    } else {
      rb_raise(rb_eTypeError, 
	       "wrong argument type %s (Array or GSL::Vector expected)", 
	       rb_class2name(CLASS_OF(argv[0])));
    }
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
    break;
  }
  Data_Get_Struct(obj, gsl_function, F);
  ary = (VALUE) F->params;
  proc = rb_ary_entry(ary, 0);
  params = rb_ary_entry(ary, 1);
  sprintf(command, "graph -T X -g 3 %s", opt);
  fp = popen(command, "w");
  if (fp == NULL)
    rb_raise(rb_eIOError, "GNU graph not found.");
  for (i = 0; i < n; i++) {
    x = gsl_vector_get(v, i);
    if (NIL_P(params)) y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 1, rb_float_new(x)));
    else y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 2, rb_float_new(x), params));
    fprintf(fp, "%e %e\n", x, y);
  }
  fflush(fp);
 pclose(fp);
  fp = NULL;
  if (flag == 1) gsl_vector_free(v);
  return Qtrue;
#else
  rb_raise(rb_eNoMethodError, "not implemented");
  return Qfalse;
#endif
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:62,代码来源:function.c

示例2: rb_ool_conmin_minimizer_size

static VALUE rb_ool_conmin_minimizer_size(VALUE obj)
{
	ool_conmin_minimizer *m;
	Data_Get_Struct(obj, ool_conmin_minimizer, m);
	return rb_float_new(ool_conmin_minimizer_size(m));
}
开发者ID:engineyard,项目名称:rb-gsl,代码行数:6,代码来源:ool.c

示例3: Nokogiri_marshal_xpath_funcall_and_return_values

void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
{
  int i;
  VALUE result, doc;
  VALUE *argv;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;
  nokogiriNodeSetTuple *node_set_tuple;

  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_register_address(&argv[i]);
  }

  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  if (nargs > 0) {
    i = nargs - 1;
    do {
      obj = valuePop(ctx);
      switch(obj->type) {
        case XPATH_STRING:
          argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
          break;
        case XPATH_BOOLEAN:
          argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
          break;
        case XPATH_NUMBER:
          argv[i] = rb_float_new(obj->floatval);
          break;
        case XPATH_NODESET:
          argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
          break;
        default:
          argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
      }
      xmlXPathFreeNodeSetList(obj);
    } while(i-- > 0);
  }

  result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);

  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_unregister_address(&argv[i]);
  }
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          xmlCharStrdup(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
	args[0] = doc;
	args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
      break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
  }
}
开发者ID:00zl00,项目名称:AlfredWorkflow.com,代码行数:94,代码来源:xml_xpath_context.c

示例4: prof_call_info_total_time

/* call-seq:
   total_time -> float

Returns the total amount of time spent in this method and its children. */
static VALUE
prof_call_info_total_time(VALUE self)
{
    prof_call_info_t *result = prof_get_call_info(self);
    return rb_float_new(result->total_time);
}
开发者ID:skyandsy,项目名称:CoinPost,代码行数:10,代码来源:rp_call_info.c

示例5: rb_io_convert_time

/*
 * Converts a D time metric to a Ruby float in ms
*/
static VALUE
rb_io_convert_time(uint64_t t)
{
    return rb_float_new((double) t / 1000000);
}
开发者ID:methodmissing,项目名称:io-trace,代码行数:8,代码来源:trace.c

示例6: Music_GetDuration

/* call-seq:
 *   music.getDuration()	-> float
 *
 * Get the total duration of the music. 
 */
static VALUE Music_GetDuration( VALUE self )
{
	sf::Music *object = NULL;
	Data_Get_Struct( self, sf::Music, object );
	return rb_float_new( object->GetDuration() );
}
开发者ID:vidjogamer,项目名称:ProjectTemplate,代码行数:11,代码来源:Music.cpp

示例7: t_to_mel

static VALUE t_to_mel(VALUE self, VALUE m) {
  return rb_float_new(mel(NUM2DBL(m)));
}
开发者ID:hmoody87,项目名称:noyes,代码行数:3,代码来源:mel_filter.c

示例8: rb_cqpminimizer_gap

static VALUE rb_cqpminimizer_gap(VALUE obj)
{
  gsl_cqpminimizer *m;
  Data_Get_Struct(obj, gsl_cqpminimizer, m);
  return rb_float_new(gsl_cqpminimizer_gap(m));
}
开发者ID:AbhimanyuAryan,项目名称:rb-gsl,代码行数:6,代码来源:cqp.c

示例9: rb_cqpminimizer_residuals_norm

static VALUE rb_cqpminimizer_residuals_norm(VALUE obj)
{
  gsl_cqpminimizer *m;
  Data_Get_Struct(obj, gsl_cqpminimizer, m);
  return rb_float_new(gsl_cqpminimizer_residuals_norm(m));
}
开发者ID:AbhimanyuAryan,项目名称:rb-gsl,代码行数:6,代码来源:cqp.c

示例10: pg_text_dec_float

/*
 * Document-class: PG::TextDecoder::Float < PG::SimpleDecoder
 *
 * This is a decoder class for conversion of PostgreSQL float4 and float8 types
 * to Ruby Float objects.
 *
 */
static VALUE
pg_text_dec_float(t_pg_coder *conv, char *val, int len, int tuple, int field, int enc_idx)
{
	return rb_float_new(strtod(val, NULL));
}
开发者ID:RapsIn4,项目名称:pg,代码行数:12,代码来源:pg_text_decoder.c

示例11: rb_cpBBGetT

static VALUE
rb_cpBBGetT(VALUE self) {
  return rb_float_new(BBGET(self)->t);
}
开发者ID:Anaxim,项目名称:chipmunk,代码行数:4,代码来源:rb_cpBB.c

示例12: Init_carray_numeric

void
Init_carray_numeric ()
{
  /* hack Fixnum and Bignum's "|", "&", "^", "<<", ">>" */

  id___or__ = rb_intern("__or__");
  id___and__ = rb_intern("__and__");
  id___xor__ = rb_intern("__xor__");
  id___rshift__ = rb_intern("__rshift__");
  id___lshift__ = rb_intern("__lshift__");

  CA_NAN = rb_float_new(0.0/0.0);
  CA_INF = rb_float_new(1.0/0.0);
  rb_define_const(rb_cObject, "CA_NAN", CA_NAN);
  rb_define_const(rb_cObject, "CA_INF", CA_INF);
  rb_define_global_function("nan", rb_num_nan, 0);
  rb_define_global_function("inf", rb_num_inf, 0);

  rb_define_alias(rb_cTrueClass, "__or__", "|");
  rb_define_alias(rb_cTrueClass, "__and__", "&");
  rb_define_alias(rb_cTrueClass, "__xor__", "^");

  rb_define_alias(rb_cFalseClass, "__or__", "|");
  rb_define_alias(rb_cFalseClass, "__and__", "&");
  rb_define_alias(rb_cFalseClass, "__xor__", "^");

  rb_define_alias(rb_cFixnum, "__or__", "|");
  rb_define_alias(rb_cFixnum, "__and__", "&");
  rb_define_alias(rb_cFixnum, "__xor__", "^");
  rb_define_alias(rb_cFixnum, "__lshift__", "<<");
  rb_define_alias(rb_cFixnum, "__rshift__", ">>");

  rb_define_alias(rb_cBignum, "__or__", "|");
  rb_define_alias(rb_cBignum, "__and__", "&");
  rb_define_alias(rb_cBignum, "__xor__", "^");
  rb_define_alias(rb_cBignum, "__lshift__", "<<");
  rb_define_alias(rb_cBignum, "__rshift__", ">>");

  rb_define_method(rb_cTrueClass, "|", rb_hack_or, 1);
  rb_define_method(rb_cTrueClass, "&", rb_hack_and, 1);
  rb_define_method(rb_cTrueClass, "^", rb_hack_xor, 1);
  rb_define_method(rb_cTrueClass, "*", rb_hack_star, 1);

  rb_define_method(rb_cFalseClass, "|", rb_hack_or, 1);
  rb_define_method(rb_cFalseClass, "&", rb_hack_and, 1);
  rb_define_method(rb_cFalseClass, "^", rb_hack_xor, 1);
  rb_define_method(rb_cFalseClass, "*", rb_hack_star, 1);

  rb_define_method(rb_cFixnum, "|", rb_hack_or, 1);
  rb_define_method(rb_cFixnum, "&", rb_hack_and, 1);
  rb_define_method(rb_cFixnum, "^", rb_hack_xor, 1);
  rb_define_method(rb_cFixnum, "<<", rb_hack_lshift, 1);
  rb_define_method(rb_cFixnum, ">>", rb_hack_rshift, 1);

  rb_define_method(rb_cBignum, "|", rb_hack_or, 1);
  rb_define_method(rb_cBignum, "&", rb_hack_and, 1);
  rb_define_method(rb_cBignum, "^", rb_hack_xor, 1);
  rb_define_method(rb_cBignum, "<<", rb_hack_lshift, 1);
  rb_define_method(rb_cBignum, ">>", rb_hack_rshift, 1);

#ifdef HAVE_COMPLEX_H
  rb_define_method(rb_cCArray, "arg", rb_ca_arg, 0);
#endif

}
开发者ID:himotoyoshi,项目名称:carray,代码行数:65,代码来源:carray_numeric.c

示例13: callback

void
callback(ffi_cif *cif, void *resp, void **args, void *ctx)
{
    VALUE self      = (VALUE)ctx;
    VALUE rbargs    = rb_iv_get(self, "@args");
    VALUE ctype     = rb_iv_get(self, "@ctype");
    int argc        = RARRAY_LENINT(rbargs);
    VALUE *params   = xcalloc(argc, sizeof(VALUE *));
    VALUE ret;
    VALUE cPointer;
    int i, type;

    cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));

    for (i = 0; i < argc; i++) {
        type = NUM2INT(RARRAY_PTR(rbargs)[i]);
        switch (type) {
	  case TYPE_VOID:
	    argc = 0;
	    break;
	  case TYPE_INT:
	    params[i] = INT2NUM(*(int *)args[i]);
	    break;
	  case TYPE_VOIDP:
            params[i] = rb_funcall(cPointer, rb_intern("[]"), 1,
              PTR2NUM(*(void **)args[i]));
	    break;
	  case TYPE_LONG:
	    params[i] = LONG2NUM(*(long *)args[i]);
	    break;
	  case TYPE_CHAR:
	    params[i] = INT2NUM(*(char *)args[i]);
	    break;
	  case TYPE_DOUBLE:
	    params[i] = rb_float_new(*(double *)args[i]);
	    break;
	  case TYPE_FLOAT:
	    params[i] = rb_float_new(*(float *)args[i]);
	    break;
#if HAVE_LONG_LONG
	  case TYPE_LONG_LONG:
	    params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]);
	    break;
#endif
	  default:
	    rb_raise(rb_eRuntimeError, "closure args: %d", type);
        }
    }

    ret = rb_funcall2(self, rb_intern("call"), argc, params);

    type = NUM2INT(ctype);
    switch (type) {
      case TYPE_VOID:
	break;
      case TYPE_LONG:
	*(long *)resp = NUM2LONG(ret);
	break;
      case TYPE_CHAR:
	*(char *)resp = NUM2INT(ret);
	break;
      case TYPE_VOIDP:
	*(void **)resp = NUM2PTR(ret);
	break;
      case TYPE_INT:
	*(int *)resp = NUM2INT(ret);
	break;
      case TYPE_DOUBLE:
	*(double *)resp = NUM2DBL(ret);
	break;
      case TYPE_FLOAT:
	*(float *)resp = (float)NUM2DBL(ret);
	break;
#if HAVE_LONG_LONG
      case TYPE_LONG_LONG:
	*(unsigned LONG_LONG *)resp = rb_big2ull(ret);
	break;
#endif
      default:
	rb_raise(rb_eRuntimeError, "closure retval: %d", type);
    }
    xfree(params);
}
开发者ID:2220142,项目名称:ruby,代码行数:83,代码来源:closure.c

示例14: ruby_funcall

static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
{
  VALUE xpath_handler = Qnil;
  VALUE result;
  VALUE *argv;
  VALUE doc;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;
  int i;

  assert(ctx);
  assert(ctx->context);
  assert(ctx->context->userData);
  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  xpath_handler = (VALUE)(ctx->context->userData);

  argv = (VALUE *)calloc((unsigned int)nargs, sizeof(VALUE));
  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  i = nargs - 1;
  do {
    obj = valuePop(ctx);
    switch(obj->type) {
      case XPATH_STRING:
        argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
        break;
      case XPATH_BOOLEAN:
        argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
        break;
      case XPATH_NUMBER:
        argv[i] = rb_float_new(obj->floatval);
        break;
      case XPATH_NODESET:
        argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
        break;
      default:
        argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
    }
    xmlXPathFreeNodeSetList(obj);
  } while(i-- > 0);

  result = rb_funcall2(
      xpath_handler,
      rb_intern((const char *)ctx->context->function),
      nargs,
      argv
  );
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          (xmlChar *)xmlXPathWrapCString(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
	args[0] = doc;
	args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
      break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, xmlNodeSet, xml_node_set);
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
  }
}
开发者ID:glebm,项目名称:glebm-nokogiri,代码行数:93,代码来源:xml_xpath_context.c

示例15: rb_read_number

STATIC VALUE rb_read_number(ramf0_load_context_t* context)
{
  return rb_float_new(c_read_number(context));
}
开发者ID:mrhenry,项目名称:ramf,代码行数:4,代码来源:ramf_AMF0Deserializer.c


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