ext/integration.c in gsl-1.12.109 vs ext/integration.c in gsl-1.14.5

- old
+ new

@@ -30,10 +30,14 @@ static VALUE cgsl_integration_qaws_table, cgsl_integration_qawo_table; static VALUE cgsl_integration_workspace; +#ifdef GSL_1_14_LATER +static VALUE cgsl_integration_glfixed_table; +#endif + static int get_a_b(int argc, VALUE *argv, int argstart, double *a, double *b); static int get_epsabs_epsrel(int argc, VALUE *argv, int argstart, double *epsabs, double *epsrel); static int get_a_b_epsabs_epsrel(int argc, VALUE *argv, int argstart, double *a, double *b, double *epsabs, @@ -1023,10 +1027,37 @@ Data_Get_Struct(obj, gsl_integration_workspace, w); v = rb_gsl_make_vector_view(w->elist, w->limit, 1); return Data_Wrap_Struct(cgsl_vector_view_ro, 0, free, v); } +#ifdef GSL_1_14_LATER +static VALUE rb_gsl_integration_glfixed_table_alloc(VALUE klass, VALUE n) +{ + gsl_integration_glfixed_table *t; + t = gsl_integration_glfixed_table_alloc(FIX2INT(n)); + return Data_Wrap_Struct(cgsl_integration_glfixed_table, 0, gsl_integration_glfixed_table_free, t); +} + +static VALUE rb_gsl_integration_glfixed(VALUE obj, VALUE aa, VALUE bb, VALUE tt) +{ + gsl_function *f; + double a, b; + gsl_integration_glfixed_table *t; + double res; + if (!rb_obj_is_kind_of(tt, cgsl_integration_glfixed_table)) { + rb_raise(rb_eTypeError, "Wrong arugment type (%s for GSL::Integration::Glfixed_table)", + rb_class2name(CLASS_OF(tt))); + } + Data_Get_Struct(tt, gsl_integration_glfixed_table, t); + a = NUM2DBL(aa); + b = NUM2DBL(bb); + Data_Get_Struct(obj, gsl_function, f); + res = gsl_integration_glfixed(f, a, b, t); + return rb_float_new(res); +} +#endif + void Init_gsl_integration(VALUE module) { VALUE mgsl_integ; mgsl_integ = rb_define_module_under(module, "Integration"); @@ -1123,9 +1154,17 @@ rb_define_module_function(mgsl_integ, "qagil", rb_gsl_integration_qagil, -1); rb_define_module_function(mgsl_integ, "qawc", rb_gsl_integration_qawc, -1); rb_define_module_function(mgsl_integ, "qaws", rb_gsl_integration_qaws, -1); rb_define_module_function(mgsl_integ, "qawo", rb_gsl_integration_qawo, -1); rb_define_module_function(mgsl_integ, "qawf", rb_gsl_integration_qawf, -1); + +#ifdef GSL_1_14_LATER + cgsl_integration_glfixed_table = rb_define_class_under(mgsl_integ, "Glfixed_table", cGSL_Object); + rb_define_singleton_method(cgsl_integration_glfixed_table, "alloc", + rb_gsl_integration_glfixed_table_alloc, 1); + rb_define_method(cgsl_function, "glfixed", rb_gsl_integration_glfixed, 3); +#endif + } #undef EPSABS_DEFAULT #undef EPSREL_DEFAULT #undef LIMIT_DEFAULT