本文整理汇总了C++中NUM2DBL函数的典型用法代码示例。如果您正苦于以下问题:C++ NUM2DBL函数的具体用法?C++ NUM2DBL怎么用?C++ NUM2DBL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NUM2DBL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_gsl_pow_int
static VALUE rb_gsl_pow_int(VALUE obj, VALUE xx, VALUE nn)
{
VALUE x, ary, argv[2];
size_t i, j, size;
int n;
gsl_vector *v = NULL, *vnew = NULL;
gsl_matrix *m = NULL, *mnew = NULL;
if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
switch (TYPE(xx)) {
case T_FIXNUM:
case T_BIGNUM:
case T_FLOAT:
return rb_float_new(gsl_pow_int(NUM2DBL(xx), FIX2INT(nn)));
break;
case T_ARRAY:
CHECK_FIXNUM(nn);
n = FIX2INT(nn);
size = RARRAY_LEN(xx);
ary = rb_ary_new2(size);
for (i = 0; i < size; i++) {
x = rb_ary_entry(xx, i);
Need_Float(x);
// rb_ary_store(ary, i, rb_float_new(gsl_pow_int(RFLOAT(x)->value, n)));
rb_ary_store(ary, i, rb_float_new(gsl_pow_int(NUM2DBL(x), n)));
}
return ary;
break;
default:
#ifdef HAVE_NARRAY_H
if (NA_IsNArray(xx)) {
struct NARRAY *na;
double *ptr1, *ptr2;
CHECK_FIXNUM(nn);
n = FIX2INT(nn);
GetNArray(xx, na);
ptr1 = (double*) na->ptr;
size = na->total;
ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
ptr2 = NA_PTR_TYPE(ary, double*);
for (i = 0; i < size; i++) ptr2[i] = gsl_pow_int(ptr1[i], n);
return ary;
}
#endif
if (VECTOR_P(xx)) {
CHECK_FIXNUM(nn);
n = FIX2INT(nn);
Data_Get_Struct(xx, gsl_vector, v);
vnew = gsl_vector_alloc(v->size);
for (i = 0; i < v->size; i++) {
gsl_vector_set(vnew, i, gsl_pow_int(gsl_vector_get(v, i), n));
}
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
} else if (MATRIX_P(xx)) {
CHECK_FIXNUM(nn);
n = FIX2INT(nn);
Data_Get_Struct(xx, gsl_matrix, m);
mnew = gsl_matrix_alloc(m->size1, m->size2);
for (i = 0; i < m->size1; i++) {
for (j = 0; j < m->size2; j++) {
gsl_matrix_set(mnew, i, j, gsl_pow_int(gsl_matrix_get(m, i, j), n));
}
}
return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
} else if (COMPLEX_P(xx) || VECTOR_COMPLEX_P(xx) || MATRIX_COMPLEX_P(xx)) {
argv[0] = xx;
argv[1] = nn;
return rb_gsl_complex_pow_real(2, argv, obj);
} else {
rb_raise(rb_eTypeError, "wrong argument type %s (Array or Vector or Matrix expected)", rb_class2name(CLASS_OF(xx)));
}
break;
}
/* never reach here */
return Qnil;
}
示例2: rb_array_set_right
/**
@section Instance methods
@method left
@method left=( left )
@method right
@method right=( right )
@method top
@method top=( top )
@method bottom
@method bottom=( bottom )
These can be set and read at will.
Differences with x, y, w and h are:
* @right and @bottom are screen coordinates.
@right is @x + @w and @bottom is @y + @h .
*/
static VALUE rb_array_set_right(VALUE self, VALUE new_right)
{
SET_X(NUM2DBL(new_right)-array_get_w(self));
return self;
}
示例3: array_get_h
__inline__ static double array_get_h(VALUE array) {return NUM2DBL(rb_ary_entry(array, 3));}
示例4: get_parameter
static void* get_parameter(const ool_conmin_minimizer_type *T, ool_conmin_pgrad_parameters *Pp,
ool_conmin_spg_parameters *Ps, ool_conmin_gencan_parameters *Pg, VALUE ary)
{
if (T == ool_conmin_minimizer_pgrad) {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Pp);
} else {
Pp->fmin = NUM2DBL(rb_ary_entry(ary, 0));
Pp->tol = NUM2DBL(rb_ary_entry(ary, 1));
Pp->alpha = NUM2DBL(rb_ary_entry(ary, 2));
Pp->sigma1 = NUM2DBL(rb_ary_entry(ary, 3));
Pp->sigma2 = NUM2DBL(rb_ary_entry(ary, 4));
}
return (void*) Pp;
} else if (T == ool_conmin_minimizer_spg) {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Ps);
} else {
Ps->fmin = NUM2DBL(rb_ary_entry(ary, 0));
Ps->tol = NUM2DBL(rb_ary_entry(ary, 1));
Ps->M = NUM2DBL(rb_ary_entry(ary, 2));
Ps->alphamin = NUM2DBL(rb_ary_entry(ary, 3));
Ps->alphamax = NUM2DBL(rb_ary_entry(ary, 4));
Ps->gamma = NUM2DBL(rb_ary_entry(ary, 5));
Ps->sigma2 = NUM2DBL(rb_ary_entry(ary, 6));
Ps->sigma2 = NUM2DBL(rb_ary_entry(ary, 7));
}
return (void*) Ps;
} else {
if (ary == Qnil) {
ool_conmin_parameters_default(T, (void*) Pg);
} else {
Pg->epsgpen = NUM2DBL(rb_ary_entry(ary, 0));
Pg->epsgpsn = NUM2DBL(rb_ary_entry(ary, 1));
Pg->fmin = NUM2DBL(rb_ary_entry(ary, 2));
Pg->udelta0 = NUM2DBL(rb_ary_entry(ary, 3));
Pg->ucgmia = NUM2DBL(rb_ary_entry(ary, 4));
Pg->ucgmib = NUM2DBL(rb_ary_entry(ary, 5));
Pg->cg_scre = FIX2INT(rb_ary_entry(ary, 6));
Pg->cg_gpnf = NUM2DBL(rb_ary_entry(ary, 7));
Pg->cg_epsi = NUM2DBL(rb_ary_entry(ary, 8));
Pg->cg_epsf = NUM2DBL(rb_ary_entry(ary, 9));
Pg->cg_epsnqmp = NUM2DBL(rb_ary_entry(ary, 10));
Pg->cg_maxitnqmp = (size_t) FIX2INT(rb_ary_entry(ary, 11));
Pg->nearlyq = FIX2INT(rb_ary_entry(ary, 12));
Pg->nint = NUM2DBL(rb_ary_entry(ary, 13));
Pg->next = NUM2DBL(rb_ary_entry(ary, 14));
Pg->mininterp = (size_t) FIX2INT(rb_ary_entry(ary, 15));
Pg->maxextrap = (size_t) FIX2INT(rb_ary_entry(ary, 16));
Pg->trtype = FIX2INT(rb_ary_entry(ary, 17));
Pg->eta = NUM2DBL(rb_ary_entry(ary, 18));
Pg->delmin = NUM2DBL(rb_ary_entry(ary, 19));
Pg->lspgmi = NUM2DBL(rb_ary_entry(ary, 20));
Pg->lspgma = NUM2DBL(rb_ary_entry(ary, 21));
Pg->theta = NUM2DBL(rb_ary_entry(ary, 22));
Pg->gamma = NUM2DBL(rb_ary_entry(ary, 23));
Pg->beta = NUM2DBL(rb_ary_entry(ary, 24));
Pg->sigma1 = NUM2DBL(rb_ary_entry(ary, 25));
Pg->sigma2 = NUM2DBL(rb_ary_entry(ary, 26));
Pg->epsrel = NUM2DBL(rb_ary_entry(ary, 27));
Pg->epsabs = NUM2DBL(rb_ary_entry(ary, 28));
Pg->infrel = NUM2DBL(rb_ary_entry(ary, 29));
Pg->infabs = NUM2DBL(rb_ary_entry(ary, 30));
}
return (void*) Pg;
}
}
示例5: rg_set_increments
static VALUE
rg_set_increments(VALUE self, VALUE step, VALUE page)
{
gtk_spin_button_set_increments(_SELF(self), NUM2DBL(step), NUM2DBL(page));
return self;
}
示例6: Draw_composite
/*
Method: Draw#composite(x,y,width,height,img,operator=OverCompositeOp)
Purpose: Implement the "image" drawing primitive
Notes: The "img" argument can be either an ImageList object
or an Image argument.
*/
VALUE
Draw_composite(int argc, VALUE *argv, VALUE self)
{
Draw *draw;
const char *op = "Over";
double x, y, width, height;
CompositeOperator cop = OverCompositeOp;
volatile VALUE image;
Image *comp_img;
struct TmpFile_Name *tmpfile_name;
char name[MaxTextExtent];
// Buffer for "image" primitive
char primitive[MaxTextExtent];
if (argc < 5 || argc > 6)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 5 or 6)", argc);
}
// Retrieve the image to composite
image = rm_cur_image(argv[4]);
(void) rm_check_destroyed(image);
x = NUM2DBL(argv[0]);
y = NUM2DBL(argv[1]);
width = NUM2DBL(argv[2]);
height = NUM2DBL(argv[3]);
// The default composition operator is "Over".
if (argc == 6)
{
VALUE_TO_ENUM(argv[5], cop, CompositeOperator);
switch (cop)
{
case AddCompositeOp:
op = "Add";
break;
case AtopCompositeOp:
op = "Atop";
break;
case BumpmapCompositeOp:
op = "Bumpmap";
break;
case ClearCompositeOp:
op = "Clear";
break;
case CopyBlueCompositeOp:
op = "CopyBlue";
break;
case CopyGreenCompositeOp:
op = "CopyGreen";
break;
case CopyOpacityCompositeOp:
op = "CopyOpacity";
break;
case CopyRedCompositeOp:
op = "CopyRed";
break;
case CopyCompositeOp:
op = "Copy";
break;
case DifferenceCompositeOp:
op = "Difference";
break;
case InCompositeOp:
op = "In";
break;
case MinusCompositeOp:
op = "Minus";
break;
case MultiplyCompositeOp:
op = "Multiply";
break;
case OutCompositeOp:
op = "Out";
break;
case OverCompositeOp:
op = "Over";
break;
case PlusCompositeOp:
op = "Plus";
break;
case SubtractCompositeOp:
op = "Subtract";
break;
case XorCompositeOp:
op = "Xor";
break;
default:
rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
break;
}
}
//.........这里部分代码省略.........
示例7: rb_gsl_finite2
static VALUE rb_gsl_finite2(VALUE obj, VALUE x)
{
Need_Float(x);
if (gsl_finite(NUM2DBL(x))) return Qtrue;
else return Qfalse;
}
示例8: method_caller
static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
{
const xmlChar * function;
const xmlChar * functionURI;
size_t i, count;
xsltTransformContextPtr transform;
xmlXPathObjectPtr xpath;
VALUE obj;
VALUE *args;
VALUE result;
transform = xsltXPathGetTransformContext(ctxt);
function = ctxt->context->function;
functionURI = ctxt->context->functionURI;
obj = (VALUE)xsltGetExtData(transform, functionURI);
count = (size_t)ctxt->valueNr;
args = calloc(count, sizeof(VALUE *));
for(i = 0; i < count; i++) {
VALUE thing;
xpath = valuePop(ctxt);
switch(xpath->type) {
case XPATH_STRING:
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
break;
case XPATH_NODESET:
if(NULL == xpath->nodesetval) {
thing = Nokogiri_wrap_xml_node_set(
xmlXPathNodeSetCreate(NULL),
DOC_RUBY_OBJECT(ctxt->context->doc));
} else {
thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
DOC_RUBY_OBJECT(ctxt->context->doc));
}
break;
default:
rb_raise(rb_eRuntimeError, "do not handle type: %d", xpath->type);
}
args[i] = thing;
xmlFree(xpath);
}
result = rb_funcall3(obj, rb_intern((const char *)function), (int)count, args);
free(args);
switch(TYPE(result)) {
case T_FLOAT:
case T_BIGNUM:
case T_FIXNUM:
xmlXPathReturnNumber(ctxt, NUM2DBL(result));
break;
case T_STRING:
xmlXPathReturnString(
ctxt,
xmlStrdup((xmlChar *)StringValuePtr(result))
);
break;
case T_TRUE:
xmlXPathReturnTrue(ctxt);
break;
case T_FALSE:
xmlXPathReturnFalse(ctxt);
break;
case T_NIL:
break;
default:
rb_raise(rb_eRuntimeError, "Invalid return type");
}
}
示例9: rb_gsl_isinf2
static VALUE rb_gsl_isinf2(VALUE obj, VALUE x)
{
// Need_Float(x);
if (gsl_isinf(NUM2DBL(x))) return Qtrue;
else return Qfalse;
}
示例10: rb_gsl_finite
static VALUE rb_gsl_finite(VALUE obj, VALUE x)
{
Need_Float(x);
return INT2FIX(gsl_finite(NUM2DBL(x)));
}
示例11: rb_gsl_ldexp
static VALUE rb_gsl_ldexp(VALUE obj, VALUE x, VALUE e)
{
return rb_float_new(gsl_ldexp(NUM2DBL(x), FIX2INT(e)));
}
示例12: rb_GSL_MIN_DBL
static VALUE rb_GSL_MIN_DBL(VALUE obj, VALUE aa, VALUE bb)
{
Need_Float(aa); Need_Float(bb);
return rb_float_new(GSL_MAX_DBL(NUM2DBL(aa), NUM2DBL(bb)));
}
示例13: rb_GSL_SIGN
static VALUE rb_GSL_SIGN(VALUE obj, VALUE x)
{
return INT2FIX(GSL_SIGN(NUM2DBL(x)));
}
示例14: adj_clamp_page
static VALUE
adj_clamp_page(VALUE self, VALUE lower, VALUE upper)
{
gtk_adjustment_clamp_page(_SELF(self), NUM2DBL(lower), NUM2DBL(upper));
return self;
}
示例15: rb_gsl_interp_evaluate
static VALUE rb_gsl_interp_evaluate(VALUE obj, VALUE xxa, VALUE yya, VALUE xx,
double (*eval)(const gsl_interp *, const double [],
const double [], double,
gsl_interp_accel *))
{
rb_gsl_interp *rgi = NULL;
double *ptrx = NULL, *ptry = NULL;
gsl_vector *v = NULL, *vnew = NULL;
gsl_matrix *m = NULL, *mnew = NULL;
VALUE ary, x;
double val;
size_t n, i, j, size, stridex, stridey;
#ifdef HAVE_NARRAY_H
struct NARRAY *na = NULL;
double *ptrz = NULL, *ptr = NULL;
#endif
Data_Get_Struct(obj, rb_gsl_interp, rgi);
ptrx = get_vector_ptr(xxa, &stridex, &size);
if (size != rgi->p->size ){
rb_raise(rb_eTypeError, "size mismatch (xa:%d != %d)", (int) size, (int) rgi->p->size);
}
ptry = get_vector_ptr(yya, &stridey, &size);
if (size != rgi->p->size ){
rb_raise(rb_eTypeError, "size mismatch (ya:%d != %d)", (int) size, (int) rgi->p->size);
}
if (CLASS_OF(xx) == rb_cRange) xx = rb_gsl_range2ary(xx);
switch (TYPE(xx)) {
case T_FIXNUM: case T_BIGNUM: case T_FLOAT:
Need_Float(xx);
return rb_float_new((*eval)(rgi->p, ptrx, ptry, NUM2DBL(xx), rgi->a));
break;
case T_ARRAY:
n = RARRAY(xx)->len;
ary = rb_ary_new2(n);
for (i = 0; i < n; i++) {
x = rb_ary_entry(xx, i);
Need_Float(x);
val = (*eval)(rgi->p, ptrx, ptry, NUM2DBL(x), rgi->a);
rb_ary_store(ary, i, rb_float_new(val));
}
return ary;
break;
default:
#ifdef HAVE_NARRAY_H
if (NA_IsNArray(xx)) {
GetNArray(xx, na);
ptrz = (double*) na->ptr;
ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(xx));
ptr = NA_PTR_TYPE(ary, double*);
for (i = 0; i < na->total; i++)
ptr[i] = (*eval)(rgi->p, ptrx, ptry, ptrz[i], rgi->a);
return ary;
}
#endif
if (VECTOR_P(xx)) {
Data_Get_Struct(xx, gsl_vector, v);
vnew = gsl_vector_alloc(v->size);
for (i = 0; i < v->size; i++) {
val = (*eval)(rgi->p, ptrx, ptry, gsl_vector_get(v, i), rgi->a);
gsl_vector_set(vnew, i, val);
}
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
} else if (MATRIX_P(xx)) {
Data_Get_Struct(xx, gsl_matrix, m);
mnew = gsl_matrix_alloc(m->size1, m->size2);
for (i = 0; i < m->size1; i++) {
for (j = 0; j < m->size2; j++) {
val = (*eval)(rgi->p, ptrx, ptry, gsl_matrix_get(m, i, j), rgi->a);
gsl_matrix_set(mnew, i, j, val);
}
}
return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
} else {
rb_raise(rb_eTypeError, "wrong argument type %s", rb_class2name(CLASS_OF(xx)));
}
break;
}
/* never reach here */
return Qnil;
}