本文整理汇总了C++中RFLOAT_VALUE函数的典型用法代码示例。如果您正苦于以下问题:C++ RFLOAT_VALUE函数的具体用法?C++ RFLOAT_VALUE怎么用?C++ RFLOAT_VALUE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RFLOAT_VALUE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_gsl_blas_dscal
static VALUE rb_gsl_blas_dscal(int argc, VALUE *argv, VALUE obj)
{
double a;
gsl_vector *x = NULL;
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
case T_OBJECT:
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
argc);
Need_Float(argv[0]);
CHECK_VECTOR(argv[1]);
a = RFLOAT_VALUE(argv[0]);
Data_Get_Struct(argv[1], gsl_vector, x);
gsl_blas_dscal(a, x);
return argv[1];
break;
default:
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
argc);
Need_Float(argv[0]);
a = RFLOAT_VALUE(argv[0]);
Data_Get_Struct(obj, gsl_vector, x);
gsl_blas_dscal(a, x);
return obj;
break;
}
return Qnil; /* never reach here */
}
示例2: type_to_native
static void
type_to_native(VALUE value, ID data_type, void *native_value)
{
if (id_type_char == data_type || id_type_uchar == data_type) {
if (TYPE(value) == T_FIXNUM) {
value = rb_funcall(value, rb_intern("chr"), 0);
}
*((cl_char *)native_value) = RSTRING_PTR(value)[0];
return;
}
if (id_type_float == data_type || id_type_double == data_type) {
*((cl_float *)native_value) = TYPE(value) == T_FIXNUM ?
(cl_float)FIX2INT(value) : RFLOAT_VALUE(value);
return;
}
if (id_type_half == data_type) {
*((cl_half *)native_value) = TYPE(value) == T_FIXNUM ?
(cl_half)FIX2INT(value) : RFLOAT_VALUE(value);
return;
}
TYPE_TO_NATIVE(bool, char, FIX2INT);
TYPE_TO_NATIVE(short, cl_short, FIX2INT);
TYPE_TO_NATIVE(ushort, cl_ushort, NUM2UINT);
TYPE_TO_NATIVE(int, cl_int, FIX2INT);
TYPE_TO_NATIVE(uint, cl_uint, NUM2UINT);
TYPE_TO_NATIVE(long, cl_long, NUM2LONG);
TYPE_TO_NATIVE(ulong, cl_ulong, NUM2ULONG);
TYPE_TO_NATIVE(size_t, cl_uint, NUM2UINT);
TYPE_TO_NATIVE(ptrdiff_t, cl_uint, NUM2UINT);
TYPE_TO_NATIVE(intptr_t, cl_uint, NUM2UINT);
TYPE_TO_NATIVE(uintptr_t, cl_uint, NUM2UINT);
}
示例3: rb_gsl_blas_daxpy2
static VALUE rb_gsl_blas_daxpy2(int argc, VALUE *argv, VALUE obj)
{
double a;
gsl_vector *x = NULL, *y = NULL, *y2 = NULL;
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
case T_OBJECT:
get_vector2(argc-1, argv+1, obj, &x, &y);
Need_Float(argv[0]);
a = RFLOAT_VALUE(argv[0]);
break;
default:
Data_Get_Struct(obj, gsl_vector, x);
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
argc);
Need_Float(argv[0]);
CHECK_VECTOR(argv[1]);
a = RFLOAT_VALUE(argv[0]);
Data_Get_Struct(argv[1], gsl_vector, y);
break;
}
y2 = gsl_vector_alloc(y->size);
gsl_vector_memcpy(y2, y);
gsl_blas_daxpy(a, x, y2);
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, y2);
}
示例4: num2dbl_with_to_f
static inline double
num2dbl_with_to_f(VALUE num)
{
if (SPECIAL_CONST_P(num)) {
if (FIXNUM_P(num)) {
if (basic_to_f_p(rb_cFixnum))
return fix2dbl_without_to_f(num);
}
else if (FLONUM_P(num)) {
return RFLOAT_VALUE(num);
}
}
else {
switch (BUILTIN_TYPE(num)) {
case T_FLOAT:
return RFLOAT_VALUE(num);
case T_BIGNUM:
if (basic_to_f_p(rb_cBignum))
return big2dbl_without_to_f(num);
break;
case T_RATIONAL:
if (basic_to_f_p(rb_cRational))
return rat2dbl_without_to_f(num);
break;
}
}
return RFLOAT_VALUE(rb_to_float(num));
}
示例5: point_in_poly
VALUE point_in_poly(VALUE self, VALUE rb_x, VALUE rb_y, VALUE rb_points) {
Check_Type(rb_x, T_FLOAT);
Check_Type(rb_y, T_FLOAT);
Check_Type(rb_points, T_ARRAY);
int i = 0;
int s = (int)RARRAY_LEN(rb_points);
double *vertx;
double *verty;
vertx = calloc(s, sizeof(double));
verty = calloc(s, sizeof(double));
double test_x = RFLOAT_VALUE(rb_x);
double test_y = RFLOAT_VALUE(rb_y);
ID i_x = rb_intern("x");
ID i_y = rb_intern("y");
for(i = 0; i < s; i++) {
VALUE point = RARRAY_PTR(rb_points)[i];
VALUE x = rb_funcall(point, i_x, 0);
VALUE y = rb_funcall(point, i_y, 0);
Check_Type(x, T_FLOAT);
Check_Type(y, T_FLOAT);
vertx[i] = RFLOAT_VALUE(x);
verty[i] = RFLOAT_VALUE(y);
}
return pnpoly(s, vertx, verty, test_x, test_y);
}
示例6: math_atan2
static VALUE
math_atan2(VALUE obj, VALUE y, VALUE x)
{
double dx, dy;
Need_Float2(y, x);
dx = RFLOAT_VALUE(x);
dy = RFLOAT_VALUE(y);
if (dx == 0.0 && dy == 0.0) domain_error("atan2");
if (isinf(dx) && isinf(dy)) domain_error("atan2");
return DBL2NUM(atan2(dy, dx));
}
示例7: safe_mul
static VALUE
safe_mul(VALUE a, VALUE b, int az, int bz)
{
double v;
if (!az && bz && RB_FLOAT_TYPE_P(a) && (v = RFLOAT_VALUE(a), !isnan(v))) {
a = signbit(v) ? DBL2NUM(-1.0) : DBL2NUM(1.0);
}
if (!bz && az && RB_FLOAT_TYPE_P(b) && (v = RFLOAT_VALUE(b), !isnan(v))) {
b = signbit(v) ? DBL2NUM(-1.0) : DBL2NUM(1.0);
}
return f_mul(a, b);
}
示例8: comp_score
// comparison function for use with qsort
int comp_score(const void *a, const void *b)
{
VALUE a_val = *(VALUE *)a;
VALUE b_val = *(VALUE *)b;
ID score = rb_intern("score");
double a_score = RFLOAT_VALUE(rb_funcall(a_val, score, 0));
double b_score = RFLOAT_VALUE(rb_funcall(b_val, score, 0));
if (a_score > b_score)
return -1; // a scores higher, a should appear sooner
else if (a_score < b_score)
return 1; // b scores higher, a should appear later
else
return comp_alpha(a, b);
}
示例9: rb_IupPPlotAdd
VALUE rb_IupPPlotAdd(VALUE node,VALUE v_x,VALUE v_y)
{
float x,y;
VALUE v_ih = rb_iv_get(node,"@ihandle");
if(TYPE(v_x)==T_FIXNUM)
x = NUM2INT(v_x);
else
x = RFLOAT_VALUE(v_x);
if(TYPE(v_y)==T_FIXNUM)
y = NUM2INT(v_y);
else
y = RFLOAT_VALUE(v_y);
IupPPlotAdd((Ihandle*)NUM2ULONG(v_ih),x,y);
return Qnil;
}
示例10: math_sin
VALUE
math_sin(VALUE obj, SEL sel, VALUE x)
{
Need_Float(x);
return DBL2NUM(sin(RFLOAT_VALUE(x)));
}
示例11: rb_czmq_poller_poll
/*
* call-seq:
* poller.poll(1) => Fixnum
*
* Multiplexes input/output events in a level-triggered fashion over a set of registered sockets.
*
* === Examples
*
* Supported timeout values :
*
* -1 : block until any sockets are ready (no timeout)
* 0 : non-blocking poll
* 1 : block for up to 1 second (1000ms)
* 0.1 : block for up to 0.1 seconds (100ms)
*
* poller = ZMQ::Poller.new => ZMQ::Poller
* poller.register(req) => true
* poller.poll(1) => Fixnum
*
*/
VALUE rb_czmq_poller_poll(int argc, VALUE *argv, VALUE obj)
{
VALUE tmout;
size_t timeout;
struct nogvl_poll_args args;
int rc;
ZmqGetPoller(obj);
rb_scan_args(argc, argv, "01", &tmout);
if (NIL_P(tmout)) tmout = INT2NUM(0);
if (TYPE(tmout) != T_FIXNUM && TYPE(tmout) != T_FLOAT) rb_raise(rb_eTypeError, "wrong timeout type %s (expected Fixnum or Float)", RSTRING_PTR(rb_obj_as_string(tmout)));
if (poller->poll_size == 0) return INT2NUM(0);
if (poller->dirty == TRUE) {
rc = rb_czmq_poller_rebuild_pollset(poller);
if (rc == -1) rb_raise(rb_eZmqError, "failed in rebuilding the pollset!");
}
timeout = (size_t)(((TYPE(tmout) == T_FIXNUM) ? FIX2LONG(tmout) : RFLOAT_VALUE(tmout)) * 1000);
if (timeout < 0) timeout = -1;
args.items = poller->pollset;
args.nitems = poller->poll_size;
args.timeout = (long)timeout;
rc = (int)rb_thread_blocking_region(rb_czmq_nogvl_poll, (void *)&args, RUBY_UBF_IO, 0);
ZmqAssert(rc);
if (rc == 0) {
rb_ary_clear(poller->readables);
rb_ary_clear(poller->writables);
} else {
rb_czmq_poller_rebuild_selectables(poller);
}
return INT2NUM(rc);
}
示例12: mFloat_to_json
/*
* call-seq: to_json(*)
*
* Returns a JSON string representation for this Float number.
*/
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self)
{
JSON_Generator_State *state = NULL;
VALUE Vstate, rest, tmp, result;
double value = RFLOAT_VALUE(self);
rb_scan_args(argc, argv, "01*", &Vstate, &rest);
if (!NIL_P(Vstate)) Data_Get_Struct(Vstate, JSON_Generator_State, state);
if (isinf(value)) {
if (!state || state->allow_nan) {
result = rb_funcall(self, i_to_s, 0);
} else {
tmp = rb_funcall(self, i_to_s, 0);
rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
}
} else if (isnan(value)) {
if (!state || state->allow_nan) {
result = rb_funcall(self, i_to_s, 0);
} else {
tmp = rb_funcall(self, i_to_s, 0);
rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
}
} else {
result = rb_funcall(self, i_to_s, 0);
}
FORCE_UTF8(result);
return result;
}
示例13: t_set_heartbeat_interval
static VALUE t_set_heartbeat_interval (VALUE self, VALUE interval)
{
float iv = RFLOAT_VALUE(interval);
if (evma_set_heartbeat_interval(iv))
return Qtrue;
return Qfalse;
}
示例14: t_set_comm_inactivity_timeout
static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
{
float ti = RFLOAT_VALUE(timeout);
if (evma_set_comm_inactivity_timeout (NUM2ULONG (signature), ti));
return Qtrue;
return Qfalse;
}
示例15: enumerator_initialize
/*
* call-seq:
* Enumerator.new(size = nil) { |yielder| ... }
* Enumerator.new(obj, method = :each, *args)
*
* Creates a new Enumerator object, which can be used as an
* Enumerable.
*
* In the first form, iteration is defined by the given block, in
* which a "yielder" object, given as block parameter, can be used to
* yield a value by calling the +yield+ method (aliased as +<<+):
*
* fib = Enumerator.new do |y|
* a = b = 1
* loop do
* y << a
* a, b = b, a + b
* end
* end
*
* p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
*
* The optional parameter can be used to specify how to calculate the size
* in a lazy fashion (see Enumerator#size). It can either be a value or
* a callable object.
*
* In the second, deprecated, form, a generated Enumerator iterates over the
* given object using the given method with the given arguments passed.
*
* Use of this form is discouraged. Use Kernel#enum_for or Kernel#to_enum
* instead.
*
* e = Enumerator.new(ObjectSpace, :each_object)
* #-> ObjectSpace.enum_for(:each_object)
*
* e.select { |obj| obj.is_a?(Class) } #=> array of all classes
*
*/
static VALUE
enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE recv, meth = sym_each;
VALUE size = Qnil;
if (rb_block_given_p()) {
rb_check_arity(argc, 0, 1);
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
if (argc) {
if (NIL_P(argv[0]) || rb_obj_is_proc(argv[0]) ||
(RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
size = argv[0];
}
else {
size = rb_to_int(argv[0]);
}
argc = 0;
}
}
else {
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
recv = *argv++;
if (--argc) {
meth = *argv++;
--argc;
}
}
return enumerator_init(obj, recv, meth, argc, argv, 0, size);
}