Exemple #1
0
static VALUE
stackprof_results(VALUE self)
{
    VALUE results, frames;

    if (!_stackprof.frames || _stackprof.running)
	return Qnil;

    results = rb_hash_new();
    rb_hash_aset(results, sym_version, DBL2NUM(1.1));
    rb_hash_aset(results, sym_mode, _stackprof.mode);
    rb_hash_aset(results, sym_interval, _stackprof.interval);
    rb_hash_aset(results, sym_samples, SIZET2NUM(_stackprof.overall_samples));
    rb_hash_aset(results, sym_gc_samples, SIZET2NUM(_stackprof.during_gc));
    rb_hash_aset(results, sym_missed_samples, SIZET2NUM(_stackprof.overall_signals - _stackprof.overall_samples));

    frames = rb_hash_new();
    rb_hash_aset(results, sym_frames, frames);
    st_foreach(_stackprof.frames, frame_i, (st_data_t)frames);

    st_free_table(_stackprof.frames);
    _stackprof.frames = NULL;

    return results;
}
Exemple #2
0
static VALUE
newsegment_parse(VALUE self)
{
    gboolean update;
    gdouble rate, applied_rate;
    GstFormat format;
    gint64 start, stop, position;

    gst_event_parse_new_segment_full(RGST_EVENT(self), &update, &rate,
                                     &applied_rate, &format, &start, &stop,
                                     &position);

    return rb_ary_new3(7, CBOOL2RVAL(update), DBL2NUM(update), DBL2NUM(rate),
                       GST_FORMAT2RVAL(format), LL2NUM(start), LL2NUM(stop),
                       LL2NUM(position));
}
Exemple #3
0
static VALUE
math_gamma(VALUE obj, VALUE x)
{
    static const double fact_table[] = {
        /* fact(0) */ 1.0,
        /* fact(1) */ 1.0,
        /* fact(2) */ 2.0,
        /* fact(3) */ 6.0,
        /* fact(4) */ 24.0,
        /* fact(5) */ 120.0,
        /* fact(6) */ 720.0,
        /* fact(7) */ 5040.0,
        /* fact(8) */ 40320.0,
        /* fact(9) */ 362880.0,
        /* fact(10) */ 3628800.0,
        /* fact(11) */ 39916800.0,
        /* fact(12) */ 479001600.0,
        /* fact(13) */ 6227020800.0,
        /* fact(14) */ 87178291200.0,
        /* fact(15) */ 1307674368000.0,
        /* fact(16) */ 20922789888000.0,
        /* fact(17) */ 355687428096000.0,
        /* fact(18) */ 6402373705728000.0,
        /* fact(19) */ 121645100408832000.0,
        /* fact(20) */ 2432902008176640000.0,
        /* fact(21) */ 51090942171709440000.0,
        /* fact(22) */ 1124000727777607680000.0,
        /* fact(23)=25852016738884976640000 needs 56bit mantissa which is
         * impossible to represent exactly in IEEE 754 double which have
         * 53bit mantissa. */
    };
    double d0, d;
    double intpart, fracpart;
    int n;
    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    fracpart = modf(d0, &intpart);
    if (fracpart == 0.0 &&
	0 < intpart &&
	(n = (int)intpart - 1) < numberof(fact_table)) {
        return DBL2NUM(fact_table[n]);
    }
    errno = 0;
    d = tgamma(d0);
    domain_check(d0, d, "gamma");
    return DBL2NUM(d);
}
Exemple #4
0
VALUE
math_sqrt(VALUE obj, SEL sel, VALUE x)
{
    double d0, d;

    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    /* check for domain error */
    if (d0 < 0.0) {
	domain_error("sqrt");
    }
    if (d0 == 0.0) {
	return DBL2NUM(0.0);
    }
    d = sqrt(d0);
    return DBL2NUM(d);
}
Exemple #5
0
static VALUE
math_atanh(VALUE obj, SEL sel, VALUE x)
{
    double d0, d;

    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    /* check for domain error */
    if (d0 <  -1.0 || +1.0 <  d0) {
	domain_error("atanh");
    }
    /* check for pole error */
    if (d0 == -1.0) return DBL2NUM(-INFINITY);
    if (d0 == +1.0) return DBL2NUM(+INFINITY);
    d = atanh(d0);
    return DBL2NUM(d);
}
Exemple #6
0
/**
 * Convert the bytes for the double into a Ruby float.
 *
 * @example Convert the bytes to a float.
 *    rb_float_from_bson_double(class, bytes);
 *
 * @param [ Class ] The float class.
 * @param [ String ] The double bytes.
 *
 * @return [ Float ] The ruby float value.
 *
 * @since 2.0.0
 */
static VALUE rb_float_from_bson_double(VALUE self, VALUE value)
{
  const char * bytes;
  double v;
  bytes = RSTRING_PTR(value);
  memcpy(&v, bytes, RSTRING_LEN(value));
  return DBL2NUM(v);
}
/*
 * call-seq:
 *   second_best_key -> float
 *
 * Returns the priority of the second best element in the priority queue.
 */
static VALUE pq_second_best_key(VALUE self) {
   fc_pq::PQueue queue = pq_from_self(self);
   if(fc_pq::size(queue) < 2)
      return Qnil;
   
   double priority = fc_pq::second_best_key(queue);
   return DBL2NUM(priority);
}
Exemple #8
0
static VALUE length(VALUE self)
{
  Leap::Pointable * pointer;

  Data_Get_Struct(self, Leap::Pointable, pointer);

  return DBL2NUM(pointer->length());
}
Exemple #9
0
VALUE rb_rt_result(VALUE self) {
    rt_ctx *ctx;
    VALUE ret;

    Data_Get_Struct(self, rt_ctx, ctx);

    if(! ctx->ended)
        rt_end(ctx);

    ret = rb_hash_new();
    rb_hash_aset(ret, ID2SYM(rb_intern("entropy")), DBL2NUM(ctx->r_ent));
    rb_hash_aset(ret, ID2SYM(rb_intern("mean")), DBL2NUM(ctx->r_mean));
    rb_hash_aset(ret, ID2SYM(rb_intern("chisquare")), DBL2NUM(ctx->r_chisq));
    rb_hash_aset(ret, ID2SYM(rb_intern("montepi")), DBL2NUM(ctx->r_montepicalc));
    rb_hash_aset(ret, ID2SYM(rb_intern("scc")), DBL2NUM(ctx->r_scc));
    return ret;
}
/*
 * call-seq:
 *   top_key -> float
 *
 * Returns the priority of the object at the top of the priority queue.
 */
static VALUE pq_top_key(VALUE self) {
  fc_pq::PQueue queue = pq_from_self(self);
  if(fc_pq::empty(queue))
    return Qnil;
  
  double priority = fc_pq::top_key(queue);
  return DBL2NUM(priority);
}
Exemple #11
0
static VALUE touch_distance(VALUE self)
{
  Leap::Pointable * pointer;

  Data_Get_Struct(self, Leap::Pointable, pointer);

  return DBL2NUM(pointer->touchDistance());
}
Exemple #12
0
static VALUE
math_lgamma(VALUE obj, VALUE x)
{
    double d0, d;
    int sign=1;
    VALUE v;
    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    /* check for domain error */
    if (isinf(d0)) {
	if (signbit(d0)) domain_error("lgamma");
	return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1));
    }
    d = lgamma_r(d0, &sign);
    v = DBL2NUM(d);
    return rb_assoc_new(v, INT2FIX(sign));
}
Exemple #13
0
int ltns_parse_float(const char* payload, size_t length, VALUE* out)
{
	char *end;
	double parsed_val = strtod(payload, &end);
	if (end != (payload + length) || *end != LTNS_FLOAT)
		return FALSE;
	*out = DBL2NUM(parsed_val);
	return TRUE;
}
Exemple #14
0
static VALUE strstat_timer_percentile(VALUE self, VALUE rb_percentile) {
  int percentile;

  percentile = NUM2INT(rb_percentile);
  if (percentile < 0 || percentile > 100)
    rb_raise(rb_eRuntimeError, "invalid percentile");

  return strstat_timer_query(self, DBL2NUM(percentile / 100.0));
}
Exemple #15
0
VALUE rb_rt_scc(VALUE self) {
    rt_ctx *ctx;
    Data_Get_Struct(self, rt_ctx, ctx);

    if(ctx->ended)
        return DBL2NUM(ctx->r_scc);
    else
        return Qnil;
}
void CCONV ph_current_input_on_current_change(PhidgetCurrentInputHandle phid, void *userPtr, double current) {
  ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
  while(sem_wait(&callback_data->handler_ready)!=0) {};
  callback_data->arg1 = DBL2NUM(current);
  callback_data->arg2 = Qnil;
  callback_data->arg3 = Qnil;
  callback_data->arg4 = Qnil;
  sem_post(&callback_data->callback_called);
}
void CCONV ph_voltage_ratio_input_on_sensor_change(PhidgetVoltageRatioInputHandle phid, void *userPtr, double sensor_value, Phidget_UnitInfo *sensor_unit) {
  ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
  while(sem_wait(&callback_data->handler_ready)!=0) {};
  callback_data->arg1 = DBL2NUM(sensor_value);
  callback_data->arg2 = INT2NUM(sensor_unit->unit);
  callback_data->arg3 = rb_str_new2(sensor_unit->name);
  callback_data->arg4 = rb_str_new2(sensor_unit->symbol);
  sem_post(&callback_data->callback_called);
}
Exemple #18
0
void CCONV ph_phsensor_on_ph_change(PhidgetPHSensorHandle phid, void *userPtr, double ph) {
  ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
  while(sem_wait(&callback_data->handler_ready)!=0) {};
  callback_data->arg1 = DBL2NUM(ph);
  callback_data->arg2 = Qnil;
  callback_data->arg3 = Qnil;
  callback_data->arg4 = Qnil;
  sem_post(&callback_data->callback_called);
}
Exemple #19
0
static VALUE str2et(VALUE self, VALUE epoch) {
  double ephemeris_time;

  str2et_c(StringValuePtr(epoch), &ephemeris_time);
  
  if(spice_error(SPICE_ERROR_SHORT)) return Qnil;
  
  return DBL2NUM(ephemeris_time);
}
Exemple #20
0
/*
SpiceDouble phaseq_c ( SpiceDouble       et,
                       ConstSpiceChar  * target,
                       ConstSpiceChar  * illmn,
                       ConstSpiceChar  * obsrvr,
                       ConstSpiceChar  * abcorr )

*/
static VALUE phaseq(VALUE self, VALUE et, VALUE target, VALUE illmn, VALUE obsrvr, VALUE abcorr) {
  double phase_angle;

  phase_angle = phaseq_c(NUM2DBL(et), RB_SYM2STR(target), RB_SYM2STR(illmn), RB_SYM2STR(obsrvr), RB_SYM2STR(abcorr));

  if(spice_error(SPICE_ERROR_SHORT)) return Qnil;

  return DBL2NUM(phase_angle);
}
Exemple #21
0
//TODO : Test this, current kernel files do not cover this 
static VALUE lspcn(int argc, VALUE *argv, VALUE self) {
  double result;

  result = lspcn_c(RB_SYM2STR(argv[0]), NUM2DBL(argv[1]), RB_SYM2STR(argv[2]));

  if(spice_error(SPICE_ERROR_SHORT)) return Qnil;

  return DBL2NUM(result); 
}
Exemple #22
0
static VALUE
math_log10(VALUE obj, SEL sel, VALUE x)
{
    double d0, d;

    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    /* check for domain error */
    if (d0 < 0.0) {
	domain_error("log10");
    }
    /* check for pole error */
    if (d0 == 0.0) {
	return DBL2NUM(-INFINITY);
    }
    d = log10(d0);
    return DBL2NUM(d);
}
Exemple #23
0
VALUE rb_rt_scc_force(VALUE self) {
    rt_ctx *ctx;
    Data_Get_Struct(self, rt_ctx, ctx);

    if(! ctx->ended)
        rt_end(ctx);

    return DBL2NUM(ctx->r_scc);
}
Exemple #24
0
static VALUE
str2num(char *s)
{
    if (strchr(s, '/'))
	return rb_cstr_to_rat(s, 0);
    if (strpbrk(s, ".eE"))
	return DBL2NUM(rb_cstr_to_dbl(s, 0));
    return rb_cstr_to_inum(s, 10, 0);
}
void CCONV ph_voltage_ratio_input_on_voltage_ratio_change(PhidgetVoltageRatioInputHandle phid, void *userPtr, double voltage_ratio) {
  ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
  while(sem_wait(&callback_data->handler_ready)!=0) {};
  callback_data->arg1 = DBL2NUM(voltage_ratio);
  callback_data->arg2 = Qnil;
  callback_data->arg3 = Qnil;
  callback_data->arg4 = Qnil;
  sem_post(&callback_data->callback_called);
}
Exemple #26
0
static VALUE
math_frexp(VALUE unused_obj, VALUE x)
{
    double d;
    int exp;

    d = frexp(Get_Double(x), &exp);
    return rb_assoc_new(DBL2NUM(d), INT2NUM(exp));
}
Exemple #27
0
static VALUE
math_gamma(VALUE obj, VALUE x)
{
    static const double fact_table[] = {
        /* fact(0) */ 1.0,
        /* fact(1) */ 1.0,
        /* fact(2) */ 2.0,
        /* fact(3) */ 6.0,
        /* fact(4) */ 24.0,
        /* fact(5) */ 120.0,
        /* fact(6) */ 720.0,
        /* fact(7) */ 5040.0,
        /* fact(8) */ 40320.0,
        /* fact(9) */ 362880.0,
        /* fact(10) */ 3628800.0,
        /* fact(11) */ 39916800.0,
        /* fact(12) */ 479001600.0,
        /* fact(13) */ 6227020800.0,
        /* fact(14) */ 87178291200.0,
        /* fact(15) */ 1307674368000.0,
        /* fact(16) */ 20922789888000.0,
        /* fact(17) */ 355687428096000.0,
        /* fact(18) */ 6402373705728000.0,
        /* fact(19) */ 121645100408832000.0,
        /* fact(20) */ 2432902008176640000.0,
        /* fact(21) */ 51090942171709440000.0,
        /* fact(22) */ 1124000727777607680000.0,
        /* fact(23)=25852016738884976640000 needs 56bit mantissa which is
         * impossible to represent exactly in IEEE 754 double which have
         * 53bit mantissa. */
    };
    enum {NFACT_TABLE = numberof(fact_table)};
    double d;
    d = Get_Double(x);
    /* check for domain error */
    if (isinf(d) && signbit(d)) domain_error("gamma");
    if (d == floor(d)) {
	if (d < 0.0) domain_error("gamma");
	if (1.0 <= d && d <= (double)NFACT_TABLE) {
	    return DBL2NUM(fact_table[(int)d - 1]);
	}
    }
    return DBL2NUM(tgamma(d));
}
Exemple #28
0
static VALUE
math_lgamma(VALUE unused_obj, VALUE x)
{
    double d;
    int sign=1;
    VALUE v;
    d = Get_Double(x);
    /* check for domain error */
    if (isinf(d)) {
	if (signbit(d)) domain_error("lgamma");
	return rb_assoc_new(DBL2NUM(HUGE_VAL), INT2FIX(1));
    }
    if (d == 0.0) {
	VALUE vsign = signbit(d) ? INT2FIX(-1) : INT2FIX(+1);
	return rb_assoc_new(DBL2NUM(HUGE_VAL), vsign);
    }
    v = DBL2NUM(lgamma_r(d, &sign));
    return rb_assoc_new(v, INT2FIX(sign));
}
Exemple #29
0
static VALUE
math_acosh(VALUE unused_obj, VALUE x)
{
    double d;

    d = Get_Double(x);
    /* check for domain error */
    if (d < 1.0) domain_error("acosh");
    return DBL2NUM(acosh(d));
}
Exemple #30
0
static VALUE
math_asin(VALUE unused_obj, VALUE x)
{
    double d;

    d = Get_Double(x);
    /* check for domain error */
    if (d < -1.0 || 1.0 < d) domain_error("asin");
    return DBL2NUM(asin(d));
}