diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..246533a --- /dev/null +++ b/.clang-format @@ -0,0 +1,61 @@ +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: true +AlignConsecutiveAssignments: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Linux +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 80 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 22312 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 2123 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never diff --git a/bin/format.sh b/bin/format.sh new file mode 100755 index 0000000..d18ab8e --- /dev/null +++ b/bin/format.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +find ext/symengine/ -iname *.h -o -iname *.c | xargs clang-format-3.7 -style=file -i diff --git a/ext/symengine/ruby_basic.c b/ext/symengine/ruby_basic.c index 8630615..ea3f7cd 100644 --- a/ext/symengine/ruby_basic.c +++ b/ext/symengine/ruby_basic.c @@ -1,21 +1,27 @@ #include "ruby_basic.h" -void cbasic_free(void *ptr){ +void cbasic_free(void *ptr) +{ basic_struct *basic_ptr = ptr; basic_free_stack(basic_ptr); } -void cbasic_free_heap(void *ptr) { +void cbasic_free_heap(void *ptr) +{ basic_struct *basic_ptr = ptr; basic_free_heap(basic_ptr); } -VALUE cbasic_alloc(VALUE klass){ +VALUE cbasic_alloc(VALUE klass) +{ basic_struct *struct_ptr = basic_new_heap(); return Data_Wrap_Struct(klass, NULL, cbasic_free_heap, struct_ptr); } -VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*)){ +VALUE cbasic_binary_op(VALUE self, VALUE operand2, + void (*cwfunc_ptr)(basic_struct *, const basic_struct *, + const basic_struct *)) +{ basic_struct *this, *cresult; VALUE result; @@ -27,13 +33,16 @@ VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_stru cresult = basic_new_heap(); cwfunc_ptr(cresult, this, cbasic_operand2); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); basic_free_stack(cbasic_operand2); return result; } -VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_struct*)){ +VALUE cbasic_unary_op(VALUE self, + void (*cwfunc_ptr)(basic_struct *, const basic_struct *)) +{ basic_struct *this, *cresult; VALUE result; @@ -41,32 +50,39 @@ VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_ cresult = basic_new_heap(); cwfunc_ptr(cresult, this); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); return result; } -VALUE cbasic_add(VALUE self, VALUE operand2){ +VALUE cbasic_add(VALUE self, VALUE operand2) +{ return cbasic_binary_op(self, operand2, basic_add); } -VALUE cbasic_sub(VALUE self, VALUE operand2){ +VALUE cbasic_sub(VALUE self, VALUE operand2) +{ return cbasic_binary_op(self, operand2, basic_sub); } -VALUE cbasic_mul(VALUE self, VALUE operand2){ +VALUE cbasic_mul(VALUE self, VALUE operand2) +{ return cbasic_binary_op(self, operand2, basic_mul); } -VALUE cbasic_div(VALUE self, VALUE operand2){ +VALUE cbasic_div(VALUE self, VALUE operand2) +{ return cbasic_binary_op(self, operand2, basic_div); } -VALUE cbasic_pow(VALUE self, VALUE operand2){ +VALUE cbasic_pow(VALUE self, VALUE operand2) +{ return cbasic_binary_op(self, operand2, basic_pow); } -VALUE cbasic_diff(VALUE self, VALUE operand2) { +VALUE cbasic_diff(VALUE self, VALUE operand2) +{ basic_struct *this, *cresult; VALUE result; @@ -83,13 +99,15 @@ VALUE cbasic_diff(VALUE self, VALUE operand2) { basic_free_heap(cresult); return Qnil; } - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); basic_free_stack(cbasic_operand2); return result; } -VALUE cbasic_eq(VALUE self, VALUE operand2) { +VALUE cbasic_eq(VALUE self, VALUE operand2) +{ basic_struct *this; @@ -98,7 +116,8 @@ VALUE cbasic_eq(VALUE self, VALUE operand2) { Data_Get_Struct(self, basic_struct, this); VALUE ret = check_sympify(operand2, cbasic_operand2); - if (ret == Qfalse) return Qfalse; + if (ret == Qfalse) + return Qfalse; VALUE ret_val = basic_eq(this, cbasic_operand2) ? Qtrue : Qfalse; basic_free_stack(cbasic_operand2); @@ -106,7 +125,8 @@ VALUE cbasic_eq(VALUE self, VALUE operand2) { return ret_val; } -VALUE cbasic_neq(VALUE self, VALUE operand2) { +VALUE cbasic_neq(VALUE self, VALUE operand2) +{ basic_struct *this; basic cbasic_operand2; @@ -114,19 +134,22 @@ VALUE cbasic_neq(VALUE self, VALUE operand2) { Data_Get_Struct(self, basic_struct, this); VALUE ret = check_sympify(operand2, cbasic_operand2); - if (ret == Qfalse) return Qtrue; + if (ret == Qfalse) + return Qtrue; - VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse; + VALUE ret_val = basic_neq(this, cbasic_operand2) ? Qtrue : Qfalse; basic_free_stack(cbasic_operand2); return ret_val; } -VALUE cbasic_neg(VALUE self){ +VALUE cbasic_neg(VALUE self) +{ return cbasic_unary_op(self, basic_neg); } -VALUE cbasic_get_args(VALUE self) { +VALUE cbasic_get_args(VALUE self) +{ basic_struct *this; CVecBasic *args = vecbasic_new(); int size = 0; @@ -138,17 +161,19 @@ VALUE cbasic_get_args(VALUE self) { VALUE ruby_array = rb_ary_new2(size); int i = 0; VALUE temp; - for(i = 0; i < size; i++) { + for (i = 0; i < size; i++) { basic_struct *temp_basic = basic_new_heap(); vecbasic_get(args, i, temp_basic); - temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic); + temp = Data_Wrap_Struct(rb_obj_class(self), NULL, cbasic_free_heap, + temp_basic); rb_ary_push(ruby_array, temp); } vecbasic_free(args); return ruby_array; } -VALUE cbasic_free_symbols(VALUE self) { +VALUE cbasic_free_symbols(VALUE self) +{ basic_struct *this; CSetBasic *symbols = setbasic_new(); int size = 0; @@ -160,17 +185,19 @@ VALUE cbasic_free_symbols(VALUE self) { VALUE ruby_array = rb_ary_new2(size); int i = 0; VALUE temp; - for(i = 0; i < size; i++) { + for (i = 0; i < size; i++) { basic_struct *temp_basic = basic_new_heap(); setbasic_get(symbols, i, temp_basic); - temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic); + temp = Data_Wrap_Struct(rb_obj_class(self), NULL, cbasic_free_heap, + temp_basic); rb_ary_push(ruby_array, temp); } setbasic_free(symbols); return ruby_array; } -VALUE cbasic_to_str(VALUE self){ +VALUE cbasic_to_str(VALUE self) +{ basic_struct *this; char *str_ptr; VALUE result; @@ -184,11 +211,13 @@ VALUE cbasic_to_str(VALUE self){ return result; } -VALUE cbasic_expand(VALUE self){ +VALUE cbasic_expand(VALUE self) +{ return cbasic_unary_op(self, basic_expand); } -VALUE cbasic_hash(VALUE self){ +VALUE cbasic_hash(VALUE self) +{ basic_struct *this; Data_Get_Struct(self, basic_struct, this); // All ruby objects return FIXNUM when `hash` method is called. @@ -203,7 +232,8 @@ VALUE cbasic_hash(VALUE self){ return SIZET2NUM(basic_hash(this)); } -int insert_entries(VALUE key, VALUE val, VALUE input) { +int insert_entries(VALUE key, VALUE val, VALUE input) +{ CMapBasicBasic *cmapbb; Data_Get_Struct(input, CMapBasicBasic, cmapbb); @@ -220,18 +250,21 @@ int insert_entries(VALUE key, VALUE val, VALUE input) { return ST_CONTINUE; } -VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) { +VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) +{ basic_struct *this, *cresult; cresult = basic_new_heap(); VALUE val_a, val_b; Data_Get_Struct(self, basic_struct, this); - rb_scan_args(argc, argv, "11", &val_a, &val_b); // 1 mandatory and 1 optional parameter + rb_scan_args(argc, argv, "11", &val_a, + &val_b); // 1 mandatory and 1 optional parameter if (argc == 1) { Check_Type(val_a, T_HASH); CMapBasicBasic *cmapbb = mapbasicbasic_new(); - VALUE mapbb = Data_Wrap_Struct(rb_cObject, NULL, mapbasicbasic_free, cmapbb); + VALUE mapbb + = Data_Wrap_Struct(rb_cObject, NULL, mapbasicbasic_free, cmapbb); rb_hash_foreach(val_a, insert_entries, mapbb); basic_subs(cresult, this, cmapbb); @@ -248,13 +281,16 @@ VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) { basic_free_stack(b); } - return Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, cresult); + return Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); } -VALUE cbasic_coerce(VALUE self, VALUE other){ +VALUE cbasic_coerce(VALUE self, VALUE other) +{ basic_struct *cbasic_operand2; cbasic_operand2 = basic_new_heap(); sympify(other, cbasic_operand2); - VALUE new_other = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand2), NULL , cbasic_free_heap, cbasic_operand2); + VALUE new_other = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand2), NULL, + cbasic_free_heap, cbasic_operand2); return rb_assoc_new(new_other, self); } diff --git a/ext/symengine/ruby_basic.h b/ext/symengine/ruby_basic.h index 792efaa..dc5304e 100644 --- a/ext/symengine/ruby_basic.h +++ b/ext/symengine/ruby_basic.h @@ -12,9 +12,12 @@ void cbasic_free_heap(void *ptr); VALUE cbasic_alloc(VALUE klass); -VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*)); +VALUE cbasic_binary_op(VALUE self, VALUE operand2, + void (*cwfunc_ptr)(basic_struct *, const basic_struct *, + const basic_struct *)); -VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_struct*)); +VALUE cbasic_unary_op(VALUE self, + void (*cwfunc_ptr)(basic_struct *, const basic_struct *)); VALUE cbasic_add(VALUE self, VALUE operand2); @@ -50,4 +53,4 @@ VALUE cbasic_subs(int argc, VALUE *argv, VALUE self); VALUE cbasic_coerce(VALUE self, VALUE other); -#endif //RUBY_BASIC_H_ +#endif // RUBY_BASIC_H_ diff --git a/ext/symengine/ruby_complex.c b/ext/symengine/ruby_complex.c index eba2437..4f7734b 100644 --- a/ext/symengine/ruby_complex.c +++ b/ext/symengine/ruby_complex.c @@ -1,9 +1,11 @@ #include "ruby_complex.h" -VALUE ccomplex_real_part(VALUE self) { +VALUE ccomplex_real_part(VALUE self) +{ return function_onearg(complex_real_part, self); } -VALUE ccomplex_imaginary_part(VALUE self) { +VALUE ccomplex_imaginary_part(VALUE self) +{ return function_onearg(complex_imaginary_part, self); } diff --git a/ext/symengine/ruby_complex.h b/ext/symengine/ruby_complex.h index 7df00a7..a735fb3 100644 --- a/ext/symengine/ruby_complex.h +++ b/ext/symengine/ruby_complex.h @@ -10,4 +10,4 @@ VALUE ccomplex_real_part(VALUE self); VALUE ccomplex_imaginary_part(VALUE self); -#endif //RUBY_COMPLEX_H_ +#endif // RUBY_COMPLEX_H_ diff --git a/ext/symengine/ruby_complex_double.c b/ext/symengine/ruby_complex_double.c index 34882ad..f39e2a9 100644 --- a/ext/symengine/ruby_complex_double.c +++ b/ext/symengine/ruby_complex_double.c @@ -1,9 +1,11 @@ #include "ruby_complex_double.h" -VALUE ccomplex_double_real_part(VALUE self) { +VALUE ccomplex_double_real_part(VALUE self) +{ return function_onearg(complex_double_real_part, self); } -VALUE ccomplex_double_imaginary_part(VALUE self) { +VALUE ccomplex_double_imaginary_part(VALUE self) +{ return function_onearg(complex_double_imaginary_part, self); } diff --git a/ext/symengine/ruby_complex_double.h b/ext/symengine/ruby_complex_double.h index 664894d..69a099c 100644 --- a/ext/symengine/ruby_complex_double.h +++ b/ext/symengine/ruby_complex_double.h @@ -10,4 +10,4 @@ VALUE ccomplex_double_real_part(VALUE self); VALUE ccomplex_double_imaginary_part(VALUE self); -#endif //RUBY_COMPLEX_DOUBLE_H_ +#endif // RUBY_COMPLEX_DOUBLE_H_ diff --git a/ext/symengine/ruby_constant.c b/ext/symengine/ruby_constant.c index fb17110..33b0c98 100644 --- a/ext/symengine/ruby_constant.c +++ b/ext/symengine/ruby_constant.c @@ -1,44 +1,51 @@ #include "ruby_constant.h" -VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*), VALUE klass) { +VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct *), VALUE klass) +{ basic_struct *cresult; VALUE result; cresult = basic_new_heap(); cwfunc_ptr(cresult); - + result = Data_Wrap_Struct(klass, NULL, cbasic_free_heap, cresult); return result; } -VALUE cconstant_pi() { +VALUE cconstant_pi() +{ return cconstant_const(basic_const_pi, c_constant); } -VALUE cconstant_e() { +VALUE cconstant_e() +{ return cconstant_const(basic_const_E, c_constant); } -VALUE cconstant_euler_gamma() { +VALUE cconstant_euler_gamma() +{ return cconstant_const(basic_const_EulerGamma, c_constant); } -VALUE cconstant_i() { +VALUE cconstant_i() +{ return cconstant_const(basic_const_I, c_complex); } -VALUE cconstant_have_mpfr() { - #ifdef HAVE_SYMENGINE_MPFR - return Qtrue; - #else - return Qfalse; - #endif //HAVE_SYMENGINE_MPFR +VALUE cconstant_have_mpfr() +{ +#ifdef HAVE_SYMENGINE_MPFR + return Qtrue; +#else + return Qfalse; +#endif // HAVE_SYMENGINE_MPFR } -VALUE cconstant_have_mpc() { - #ifdef HAVE_SYMENGINE_MPC - return Qtrue; - #else - return Qfalse; - #endif //HAVE_SYMENGINE_MPC +VALUE cconstant_have_mpc() +{ +#ifdef HAVE_SYMENGINE_MPC + return Qtrue; +#else + return Qfalse; +#endif // HAVE_SYMENGINE_MPC } diff --git a/ext/symengine/ruby_constant.h b/ext/symengine/ruby_constant.h index 8154e88..937cc37 100644 --- a/ext/symengine/ruby_constant.h +++ b/ext/symengine/ruby_constant.h @@ -7,7 +7,7 @@ #include "symengine.h" #include "symengine_utils.h" -VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*), VALUE klass); +VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct *), VALUE klass); VALUE cconstant_pi(); @@ -21,4 +21,4 @@ VALUE cconstant_have_mpfr(); VALUE cconstant_have_mpc(); -#endif //RUBY_CONSTANTS_H_ +#endif // RUBY_CONSTANTS_H_ diff --git a/ext/symengine/ruby_function.c b/ext/symengine/ruby_function.c index 017a8b7..c36cdb2 100644 --- a/ext/symengine/ruby_function.c +++ b/ext/symengine/ruby_function.c @@ -2,10 +2,11 @@ typedef struct CVecBasic CVecBasic; -#define IMPLEMENT_ONE_ARG_FUNC(func) \ -VALUE cfunction_ ## func(VALUE self, VALUE operand1) { \ - return function_onearg(basic_ ## func, operand1); \ -} +#define IMPLEMENT_ONE_ARG_FUNC(func) \ + VALUE cfunction_##func(VALUE self, VALUE operand1) \ + { \ + return function_onearg(basic_##func, operand1); \ + } IMPLEMENT_ONE_ARG_FUNC(abs); IMPLEMENT_ONE_ARG_FUNC(sin); @@ -51,24 +52,23 @@ VALUE cfunction_functionsymbol_init(VALUE self, VALUE args) rb_raise(rb_eTypeError, "String expected as first argument"); } char *name = StringValueCStr(first); - + CVecBasic *cargs = vecbasic_new(); basic x; basic_new_stack(x); int i; - for (i = 0; i < argc-1; i++) { + for (i = 0; i < argc - 1; i++) { sympify(rb_ary_shift(args), x); vecbasic_push_back(cargs, x); } - + basic_struct *this; Data_Get_Struct(self, basic_struct, this); function_symbol_set(this, name, cargs); - + vecbasic_free(cargs); basic_free_stack(x); return self; } - diff --git a/ext/symengine/ruby_function.h b/ext/symengine/ruby_function.h index b271353..a02e072 100644 --- a/ext/symengine/ruby_function.h +++ b/ext/symengine/ruby_function.h @@ -39,4 +39,4 @@ VALUE cfunction_gamma(VALUE self, VALUE operand1); VALUE cfunction_functionsymbol_init(VALUE self, VALUE args); -#endif //RUBY_FUNCTION_H_ +#endif // RUBY_FUNCTION_H_ diff --git a/ext/symengine/ruby_integer.c b/ext/symengine/ruby_integer.c index 7195884..41cc748 100644 --- a/ext/symengine/ruby_integer.c +++ b/ext/symengine/ruby_integer.c @@ -1,9 +1,9 @@ #include "ruby_integer.h" -VALUE cinteger_init(VALUE self, VALUE num_value) { +VALUE cinteger_init(VALUE self, VALUE num_value) +{ basic_struct *this; Data_Get_Struct(self, basic_struct, this); get_symintfromval(num_value, this); return self; } - diff --git a/ext/symengine/ruby_integer.h b/ext/symengine/ruby_integer.h index 886bad2..59df9a9 100644 --- a/ext/symengine/ruby_integer.h +++ b/ext/symengine/ruby_integer.h @@ -5,4 +5,4 @@ VALUE cinteger_init(VALUE self, VALUE num_value); -#endif //RUBY_INTEGER_H_ +#endif // RUBY_INTEGER_H_ diff --git a/ext/symengine/ruby_ntheory.c b/ext/symengine/ruby_ntheory.c index 141ee70..ea749c0 100644 --- a/ext/symengine/ruby_ntheory.c +++ b/ext/symengine/ruby_ntheory.c @@ -1,28 +1,34 @@ #include "ruby_ntheory.h" -VALUE cntheory_nextprime(VALUE self, VALUE operand1) { +VALUE cntheory_nextprime(VALUE self, VALUE operand1) +{ return function_onearg(ntheory_nextprime, operand1); } -VALUE cntheory_gcd(VALUE self, VALUE operand1, VALUE operand2) { +VALUE cntheory_gcd(VALUE self, VALUE operand1, VALUE operand2) +{ return function_twoarg(ntheory_gcd, operand1, operand2); } -VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) { +VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) +{ return function_twoarg(ntheory_lcm, operand1, operand2); } -VALUE cntheory_mod(VALUE self, VALUE operand2) { +VALUE cntheory_mod(VALUE self, VALUE operand2) +{ VALUE ans = function_twoarg(ntheory_mod, self, operand2); VALUE ans1 = cbasic_add(ans, operand2); return function_twoarg(ntheory_mod, ans1, operand2); } -VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) { +VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) +{ return function_twoarg(ntheory_quotient, operand1, operand2); } -VALUE cntheory_fibonacci(VALUE self, VALUE operand1){ +VALUE cntheory_fibonacci(VALUE self, VALUE operand1) +{ basic_struct *cresult; VALUE result; @@ -31,12 +37,14 @@ VALUE cntheory_fibonacci(VALUE self, VALUE operand1){ cresult = basic_new_heap(); ntheory_fibonacci(cresult, cbasic_operand1); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); return result; } -VALUE cntheory_lucas(VALUE self, VALUE operand1){ +VALUE cntheory_lucas(VALUE self, VALUE operand1) +{ basic_struct *cresult; VALUE result; @@ -45,12 +53,14 @@ VALUE cntheory_lucas(VALUE self, VALUE operand1){ cresult = basic_new_heap(); ntheory_lucas(cresult, cbasic_operand1); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); return result; } -VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2){ +VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2) +{ basic_struct *cresult; VALUE result; @@ -63,7 +73,8 @@ VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2){ cresult = basic_new_heap(); ntheory_binomial(cresult, cbasic_operand1, cbasic_operand2); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); basic_free_stack(cbasic_operand1); return result; diff --git a/ext/symengine/ruby_ntheory.h b/ext/symengine/ruby_ntheory.h index a5508c0..923a1b1 100644 --- a/ext/symengine/ruby_ntheory.h +++ b/ext/symengine/ruby_ntheory.h @@ -17,4 +17,4 @@ VALUE cntheory_fibonacci(VALUE self, VALUE operand1); VALUE cntheory_lucas(VALUE self, VALUE operand1); VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2); -#endif //RUBY_NTHEORY_H_ +#endif // RUBY_NTHEORY_H_ diff --git a/ext/symengine/ruby_real_double.c b/ext/symengine/ruby_real_double.c index fa00e03..bf46655 100644 --- a/ext/symengine/ruby_real_double.c +++ b/ext/symengine/ruby_real_double.c @@ -1,6 +1,5 @@ #include "ruby_real_double.h" - VALUE crealdouble_to_float(VALUE self) { VALUE result; diff --git a/ext/symengine/ruby_real_double.h b/ext/symengine/ruby_real_double.h index 0d5154b..e94b02d 100644 --- a/ext/symengine/ruby_real_double.h +++ b/ext/symengine/ruby_real_double.h @@ -9,4 +9,4 @@ VALUE crealdouble_to_float(VALUE self); -#endif //RUBY_REAL_DOUBLE_H_ +#endif // RUBY_REAL_DOUBLE_H_ diff --git a/ext/symengine/ruby_real_mpfr.c b/ext/symengine/ruby_real_mpfr.c index 5fe8666..c311573 100644 --- a/ext/symengine/ruby_real_mpfr.c +++ b/ext/symengine/ruby_real_mpfr.c @@ -10,9 +10,9 @@ VALUE crealmpfr_init(VALUE self, VALUE num_value, VALUE prec_value) Data_Get_Struct(self, basic_struct, cresult); - switch( TYPE(num_value) ) { + switch (TYPE(num_value)) { case T_FLOAT: - d = RFLOAT_VALUE(num_value); + d = RFLOAT_VALUE(num_value); real_mpfr_set_d(cresult, d, prec); break; case T_STRING: @@ -21,12 +21,14 @@ VALUE crealmpfr_init(VALUE self, VALUE num_value, VALUE prec_value) break; case T_DATA: if (strcmp(rb_obj_classname(num_value), "BigDecimal") == 0) { - c = RSTRING_PTR(rb_funcall(num_value, rb_intern("to_s"), 1, rb_str_new2("F"))); + c = RSTRING_PTR(rb_funcall(num_value, rb_intern("to_s"), 1, + rb_str_new2("F"))); real_mpfr_set_str(cresult, c, prec); break; } default: - rb_raise(rb_eTypeError, "Invalid Type: Float, BigDecimal or String required."); + rb_raise(rb_eTypeError, + "Invalid Type: Float, BigDecimal or String required."); break; } @@ -36,13 +38,13 @@ VALUE crealmpfr_init(VALUE self, VALUE num_value, VALUE prec_value) VALUE crealmpfr_to_float(VALUE self) { // TODO: Make the following method work - //VALUE result; - //basic cbasic_operand1; - //basic_new_stack(cbasic_operand1); - //sympify(self, cbasic_operand1); - //result = rb_float_new(real_mpfr_get_d(cbasic_operand1)); + // VALUE result; + // basic cbasic_operand1; + // basic_new_stack(cbasic_operand1); + // sympify(self, cbasic_operand1); + // result = rb_float_new(real_mpfr_get_d(cbasic_operand1)); - return rb_funcall(rb_funcall(self, rb_intern("to_s"), 0, NULL), rb_intern("to_f"), 0, NULL); + return rb_funcall(rb_funcall(self, rb_intern("to_s"), 0, NULL), + rb_intern("to_f"), 0, NULL); } -#endif //HAVE_SYMENGINE_MPFR - +#endif // HAVE_SYMENGINE_MPFR diff --git a/ext/symengine/ruby_real_mpfr.h b/ext/symengine/ruby_real_mpfr.h index eab556e..dfff0f4 100644 --- a/ext/symengine/ruby_real_mpfr.h +++ b/ext/symengine/ruby_real_mpfr.h @@ -10,6 +10,6 @@ #ifdef HAVE_SYMENGINE_MPFR VALUE crealmpfr_init(VALUE self, VALUE num_value, VALUE prec_value); VALUE crealmpfr_to_float(VALUE self); -#endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR -#endif //RUBY_REAL_MPFR_H_ +#endif // RUBY_REAL_MPFR_H_ diff --git a/ext/symengine/ruby_symbol.c b/ext/symengine/ruby_symbol.c index e48a1df..abe3750 100644 --- a/ext/symengine/ruby_symbol.c +++ b/ext/symengine/ruby_symbol.c @@ -1,6 +1,7 @@ #include "ruby_symbol.h" -VALUE csymbol_init(VALUE self, VALUE name_or_id) { +VALUE csymbol_init(VALUE self, VALUE name_or_id) +{ const char *str_ptr; switch (TYPE(name_or_id)) { @@ -9,9 +10,11 @@ VALUE csymbol_init(VALUE self, VALUE name_or_id) { break; case T_SYMBOL: str_ptr = rb_id2name(rb_to_id(name_or_id)); - break; + break; default: - rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol or String)", rb_obj_classname(name_or_id)); + rb_raise(rb_eTypeError, + "wrong argument type %s (expected Symbol or String)", + rb_obj_classname(name_or_id)); } basic_struct *this; diff --git a/ext/symengine/ruby_symbol.h b/ext/symengine/ruby_symbol.h index 0c2900b..b23be11 100644 --- a/ext/symengine/ruby_symbol.h +++ b/ext/symengine/ruby_symbol.h @@ -5,4 +5,4 @@ VALUE csymbol_init(VALUE self, VALUE name); -#endif //RUBY_SYMBOL_H_ +#endif // RUBY_SYMBOL_H_ diff --git a/ext/symengine/ruby_utils.c b/ext/symengine/ruby_utils.c index fd80893..24ec50d 100644 --- a/ext/symengine/ruby_utils.c +++ b/ext/symengine/ruby_utils.c @@ -1,15 +1,16 @@ #include "ruby_utils.h" -VALUE cutils_sympify(VALUE self, VALUE operand) { - +VALUE cutils_sympify(VALUE self, VALUE operand) +{ + VALUE result; basic_struct *cbasic_operand; cbasic_operand = basic_new_heap(); - + sympify(operand, cbasic_operand); - result = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand), NULL , cbasic_free_heap, cbasic_operand); + result = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand), NULL, + cbasic_free_heap, cbasic_operand); return result; } - diff --git a/ext/symengine/ruby_utils.h b/ext/symengine/ruby_utils.h index 84df641..de004ff 100644 --- a/ext/symengine/ruby_utils.h +++ b/ext/symengine/ruby_utils.h @@ -3,7 +3,7 @@ #include "symengine_utils.h" -//Returns the Ruby Value after going through sympify +// Returns the Ruby Value after going through sympify VALUE cutils_sympify(VALUE self, VALUE operand); -#endif //RUBY_UTILS_H_ +#endif // RUBY_UTILS_H_ diff --git a/ext/symengine/symengine.c b/ext/symengine/symengine.c index cb7e15e..98908f7 100644 --- a/ext/symengine/symengine.c +++ b/ext/symengine/symengine.c @@ -17,19 +17,22 @@ // Ruby Bindings // /////////////////// -VALUE msymengine_ascii_art(VALUE self) { - char* str = ascii_art_str(); +VALUE msymengine_ascii_art(VALUE self) +{ + char *str = ascii_art_str(); VALUE ascii_art = rb_str_new_cstr(str); basic_str_free(str); return ascii_art; } -void Init_symengine() { +void Init_symengine() +{ m_symengine = rb_define_module("SymEngine"); - rb_define_singleton_method(m_symengine, "ascii_art", msymengine_ascii_art, 0); + rb_define_singleton_method(m_symengine, "ascii_art", msymengine_ascii_art, + 0); - //Basic class + // Basic class c_basic = rb_define_class_under(m_symengine, "Basic", rb_cObject); rb_define_alloc_func(c_basic, cbasic_alloc); rb_define_method(c_basic, "+", cbasic_add, 1); @@ -45,101 +48,109 @@ void Init_symengine() { rb_define_method(c_basic, "to_s", cbasic_to_str, 0); rb_define_method(c_basic, "expand", cbasic_expand, 0); rb_define_method(c_basic, "args", cbasic_get_args, 0); - rb_define_protected_method(c_basic, "pr_free_symbols", cbasic_free_symbols, 0); + rb_define_protected_method(c_basic, "pr_free_symbols", cbasic_free_symbols, + 0); rb_define_method(c_basic, "hash", cbasic_hash, 0); rb_define_method(c_basic, "subs", cbasic_subs, -1); rb_define_method(c_basic, "coerce", cbasic_coerce, 1); - //Sympify as a Module Level Function + // Sympify as a Module Level Function rb_define_module_function(m_symengine, "convert", cutils_sympify, 1); rb_define_global_function("SymEngine", cutils_sympify, 1); - //Symbol class + // Symbol class c_symbol = rb_define_class_under(m_symengine, "Symbol", c_basic); rb_define_alloc_func(c_symbol, cbasic_alloc); rb_define_method(c_symbol, "initialize", csymbol_init, 1); - //Integer class + // Integer class c_integer = rb_define_class_under(m_symengine, "Integer", c_basic); rb_define_alloc_func(c_integer, cbasic_alloc); rb_define_method(c_integer, "initialize", cinteger_init, 1); rb_define_method(c_integer, "%", cntheory_mod, 1); - //RealDouble Class + // RealDouble Class c_real_double = rb_define_class_under(m_symengine, "RealDouble", c_basic); rb_define_alloc_func(c_real_double, cbasic_alloc); rb_define_method(c_real_double, "to_f", crealdouble_to_float, 0); - //Rational class + // Rational class c_rational = rb_define_class_under(m_symengine, "Rational", c_basic); rb_define_alloc_func(c_rational, cbasic_alloc); - //Complex class + // Complex class c_complex = rb_define_class_under(m_symengine, "Complex", c_basic); rb_define_alloc_func(c_complex, cbasic_alloc); rb_define_method(c_complex, "real", ccomplex_real_part, 0); rb_define_method(c_complex, "imaginary", ccomplex_imaginary_part, 0); - //ComplexDouble class - c_complex_double = rb_define_class_under(m_symengine, "ComplexDouble", c_basic); + // ComplexDouble class + c_complex_double + = rb_define_class_under(m_symengine, "ComplexDouble", c_basic); rb_define_alloc_func(c_complex_double, cbasic_alloc); rb_define_method(c_complex_double, "real", ccomplex_double_real_part, 0); - rb_define_method(c_complex_double, "imaginary", ccomplex_double_imaginary_part, 0); + rb_define_method(c_complex_double, "imaginary", + ccomplex_double_imaginary_part, 0); - #ifdef HAVE_SYMENGINE_MPFR - //RealMPFR class +#ifdef HAVE_SYMENGINE_MPFR + // RealMPFR class c_real_mpfr = rb_define_class_under(m_symengine, "RealMPFR", c_basic); rb_define_alloc_func(c_real_mpfr, cbasic_alloc); rb_define_method(c_real_mpfr, "initialize", crealmpfr_init, 2); rb_define_method(c_real_mpfr, "to_f", crealmpfr_to_float, 0); - #endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR - #ifdef HAVE_SYMENGINE_MPC - //ComplexMPC class +#ifdef HAVE_SYMENGINE_MPC + // ComplexMPC class c_complex_mpc = rb_define_class_under(m_symengine, "ComplexMPC", c_basic); rb_define_alloc_func(c_complex_mpc, cbasic_alloc); - #endif //HAVE_SYMENGINE_MPC +#endif // HAVE_SYMENGINE_MPC - //Constant class + // Constant class c_constant = rb_define_class_under(m_symengine, "Constant", c_basic); - //Constants as Module Level Constants + // Constants as Module Level Constants rb_define_const(m_symengine, "PI", cconstant_pi()); rb_define_const(m_symengine, "E", cconstant_e()); rb_define_const(m_symengine, "EULER_GAMMA", cconstant_euler_gamma()); rb_define_const(m_symengine, "I", cconstant_i()); rb_define_const(m_symengine, "HAVE_MPFR", cconstant_have_mpfr()); rb_define_const(m_symengine, "HAVE_MPC", cconstant_have_mpc()); - - //Subs class + + // Subs class c_subs = rb_define_class_under(m_symengine, "Subs", c_basic); - //Add class + // Add class c_add = rb_define_class_under(m_symengine, "Add", c_basic); - //Mul class + // Mul class c_mul = rb_define_class_under(m_symengine, "Mul", c_basic); - //Pow class + // Pow class c_pow = rb_define_class_under(m_symengine, "Pow", c_basic); - //Functions Class + // Functions Class c_function = rb_define_class_under(m_symengine, "Function", c_basic); - //Function SubClasses - c_trig_function = rb_define_class_under(m_symengine, "TrigFunction", c_function); - c_hyperbolic_function = rb_define_class_under(m_symengine, "HyperbolicFunction", c_function); + // Function SubClasses + c_trig_function + = rb_define_class_under(m_symengine, "TrigFunction", c_function); + c_hyperbolic_function + = rb_define_class_under(m_symengine, "HyperbolicFunction", c_function); c_lambertw = rb_define_class_under(m_symengine, "LambertW", c_function); - c_dirichlet_eta = rb_define_class_under(m_symengine, "Dirichlet_eta", c_function); + c_dirichlet_eta + = rb_define_class_under(m_symengine, "Dirichlet_eta", c_function); c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function); c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function); c_abs = rb_define_class_under(m_symengine, "Abs", c_function); - //FunctionSymbol Class - c_function_symbol = rb_define_class_under(m_symengine, "FunctionSymbol", c_function); - rb_define_method(c_function_symbol, "initialize", cfunction_functionsymbol_init, -2); + // FunctionSymbol Class + c_function_symbol + = rb_define_class_under(m_symengine, "FunctionSymbol", c_function); + rb_define_method(c_function_symbol, "initialize", + cfunction_functionsymbol_init, -2); - //TrigFunction SubClasses + // TrigFunction SubClasses c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function); c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function); c_tan = rb_define_class_under(m_symengine, "Tan", c_trig_function); @@ -153,21 +164,27 @@ void Init_symengine() { c_asec = rb_define_class_under(m_symengine, "ASec", c_trig_function); c_acot = rb_define_class_under(m_symengine, "ACot", c_trig_function); - //HyperbolicFunction SubClasses + // HyperbolicFunction SubClasses c_sinh = rb_define_class_under(m_symengine, "Sinh", c_hyperbolic_function); c_cosh = rb_define_class_under(m_symengine, "Cosh", c_hyperbolic_function); c_tanh = rb_define_class_under(m_symengine, "Tanh", c_hyperbolic_function); c_csch = rb_define_class_under(m_symengine, "Csch", c_hyperbolic_function); c_sech = rb_define_class_under(m_symengine, "Sech", c_hyperbolic_function); c_coth = rb_define_class_under(m_symengine, "Coth", c_hyperbolic_function); - c_asinh = rb_define_class_under(m_symengine, "ASinh", c_hyperbolic_function); - c_acosh = rb_define_class_under(m_symengine, "ACosh", c_hyperbolic_function); - c_atanh = rb_define_class_under(m_symengine, "ATanh", c_hyperbolic_function); - c_acsch = rb_define_class_under(m_symengine, "ACsch", c_hyperbolic_function); - c_asech = rb_define_class_under(m_symengine, "ASech", c_hyperbolic_function); - c_acoth = rb_define_class_under(m_symengine, "ACoth", c_hyperbolic_function); - - //SymEngine Functions as Module Level Funcions + c_asinh + = rb_define_class_under(m_symengine, "ASinh", c_hyperbolic_function); + c_acosh + = rb_define_class_under(m_symengine, "ACosh", c_hyperbolic_function); + c_atanh + = rb_define_class_under(m_symengine, "ATanh", c_hyperbolic_function); + c_acsch + = rb_define_class_under(m_symengine, "ACsch", c_hyperbolic_function); + c_asech + = rb_define_class_under(m_symengine, "ASech", c_hyperbolic_function); + c_acoth + = rb_define_class_under(m_symengine, "ACoth", c_hyperbolic_function); + + // SymEngine Functions as Module Level Funcions rb_define_module_function(m_symengine, "abs", cfunction_abs, 1); rb_define_module_function(m_symengine, "sin", cfunction_sin, 1); rb_define_module_function(m_symengine, "cos", cfunction_cos, 1); @@ -194,11 +211,12 @@ void Init_symengine() { rb_define_module_function(m_symengine, "atanh", cfunction_atanh, 1); rb_define_module_function(m_symengine, "acoth", cfunction_acoth, 1); rb_define_module_function(m_symengine, "lambertw", cfunction_lambertw, 1); - rb_define_module_function(m_symengine, "dirichlet_eta", cfunction_dirichlet_eta, 1); + rb_define_module_function(m_symengine, "dirichlet_eta", + cfunction_dirichlet_eta, 1); rb_define_module_function(m_symengine, "zeta", cfunction_zeta, 1); - rb_define_module_function(m_symengine, "gamma", cfunction_gamma, 1); + rb_define_module_function(m_symengine, "gamma", cfunction_gamma, 1); - //NTheory Functions as Module Level Functions + // NTheory Functions as Module Level Functions rb_define_module_function(m_symengine, "gcd", cntheory_gcd, 2); rb_define_module_function(m_symengine, "lcm", cntheory_lcm, 2); rb_define_module_function(m_symengine, "nextprime", cntheory_nextprime, 1); diff --git a/ext/symengine/symengine.h b/ext/symengine/symengine.h index 35a5947..9284f61 100644 --- a/ext/symengine/symengine.h +++ b/ext/symengine/symengine.h @@ -4,10 +4,10 @@ #include #include -//variable name for a module starts with m +// variable name for a module starts with m VALUE m_symengine; -//variable names for classes begin with c +// variable names for classes begin with c VALUE c_basic; VALUE c_symbol; VALUE c_integer; @@ -17,10 +17,10 @@ VALUE c_complex; VALUE c_complex_double; #ifdef HAVE_SYMENGINE_MPFR VALUE c_real_mpfr; -#endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR #ifdef HAVE_SYMENGINE_MPC VALUE c_complex_mpc; -#endif //HAVE_SYMENGINE_MPC +#endif // HAVE_SYMENGINE_MPC VALUE c_constant; VALUE c_subs; VALUE c_add; @@ -60,5 +60,4 @@ VALUE c_acsch; VALUE c_asech; VALUE c_acoth; - -#endif //SYMENGINE_H_ +#endif // SYMENGINE_H_ diff --git a/ext/symengine/symengine_utils.c b/ext/symengine/symengine_utils.c index 9ea19e5..f17489a 100644 --- a/ext/symengine/symengine_utils.c +++ b/ext/symengine/symengine_utils.c @@ -1,19 +1,20 @@ #include "symengine_utils.h" #include "symengine.h" -VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2) { +VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2) +{ basic_struct *temp; VALUE a, b; double f; - switch(TYPE(operand2)) { + switch (TYPE(operand2)) { case T_FIXNUM: case T_BIGNUM: get_symintfromval(operand2, cbasic_operand2); break; - case T_FLOAT: + case T_FLOAT: f = RFLOAT_VALUE(operand2); real_double_set_d(cbasic_operand2, f); break; @@ -63,33 +64,36 @@ VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2) { basic_assign(cbasic_operand2, temp); break; } - #ifdef HAVE_SYMENGINE_MPFR +#ifdef HAVE_SYMENGINE_MPFR if (strcmp(rb_obj_classname(operand2), "BigDecimal") == 0) { const char *c; - c = RSTRING_PTR( rb_funcall(operand2, rb_intern("to_s"), 1, rb_str_new2("F")) ); + c = RSTRING_PTR(rb_funcall(operand2, rb_intern("to_s"), 1, + rb_str_new2("F"))); real_mpfr_set_str(cbasic_operand2, c, 200); break; } - #endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR default: return Qfalse; } return Qtrue; } -void sympify(VALUE operand2, basic_struct *cbasic_operand2) { +void sympify(VALUE operand2, basic_struct *cbasic_operand2) +{ VALUE ret = check_sympify(operand2, cbasic_operand2); if (ret == Qfalse) { - rb_raise(rb_eTypeError, "%s can't be coerced into SymEngine::Basic", rb_obj_classname(operand2)); + rb_raise(rb_eTypeError, "%s can't be coerced into SymEngine::Basic", + rb_obj_classname(operand2)); } } void get_symintfromval(VALUE operand2, basic_struct *cbasic_operand2) { - if ( TYPE(operand2) == T_FIXNUM ){ - int i = NUM2INT( operand2 ); + if (TYPE(operand2) == T_FIXNUM) { + int i = NUM2INT(operand2); integer_set_si(cbasic_operand2, i); - } else if ( TYPE(operand2) == T_BIGNUM ){ + } else if (TYPE(operand2) == T_BIGNUM) { VALUE Rb_Temp_String = rb_funcall(operand2, rb_intern("to_s"), 0, NULL); integer_set_str(cbasic_operand2, StringValueCStr(Rb_Temp_String)); } else { @@ -97,28 +101,29 @@ void get_symintfromval(VALUE operand2, basic_struct *cbasic_operand2) } } -VALUE Klass_of_Basic(const basic_struct *basic_ptr) { - switch(basic_get_type(basic_ptr)) { +VALUE Klass_of_Basic(const basic_struct *basic_ptr) +{ + switch (basic_get_type(basic_ptr)) { case SYMENGINE_SYMBOL: return c_symbol; case SYMENGINE_INTEGER: return c_integer; case SYMENGINE_REAL_DOUBLE: return c_real_double; - #ifdef HAVE_SYMENGINE_MPFR +#ifdef HAVE_SYMENGINE_MPFR case SYMENGINE_REAL_MPFR: return c_real_mpfr; - #endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR case SYMENGINE_RATIONAL: return c_rational; case SYMENGINE_COMPLEX: return c_complex; case SYMENGINE_COMPLEX_DOUBLE: return c_complex_double; - #ifdef HAVE_SYMENGINE_MPC +#ifdef HAVE_SYMENGINE_MPC case SYMENGINE_COMPLEX_MPC: return c_complex_mpc; - #endif //HAVE_SYMENGINE_MPFR +#endif // HAVE_SYMENGINE_MPFR case SYMENGINE_CONSTANT: return c_constant; case SYMENGINE_SUBS: @@ -194,7 +199,9 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) { } } -VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) { +VALUE function_onearg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *), + VALUE operand1) +{ basic_struct *cresult; VALUE result; @@ -204,14 +211,17 @@ VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VA cresult = basic_new_heap(); cwfunc_ptr(cresult, cbasic_operand1); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); basic_free_stack(cbasic_operand1); return result; } -VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), - VALUE operand1, VALUE operand2) { +VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *, + const basic_struct *), + VALUE operand1, VALUE operand2) +{ basic_struct *cresult; VALUE result; @@ -225,7 +235,8 @@ VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, con cresult = basic_new_heap(); cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2); - result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, + cresult); basic_free_stack(cbasic_operand1); basic_free_stack(cbasic_operand2); diff --git a/ext/symengine/symengine_utils.h b/ext/symengine/symengine_utils.h index b5d4b2b..b2baeac 100644 --- a/ext/symengine/symengine_utils.h +++ b/ext/symengine/symengine_utils.h @@ -7,18 +7,22 @@ VALUE rb_cBigDecimal; -//Coerces operand2 into a SymEngine object +// Coerces operand2 into a SymEngine object void sympify(VALUE operand2, basic_struct *cbasic_operand2); -//Coerces operand2 into a SymEngine object and returns whether successful +// Coerces operand2 into a SymEngine object and returns whether successful VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2); -//Returns the pointer wrapped inside the Ruby Fixnum or Bignum +// Returns the pointer wrapped inside the Ruby Fixnum or Bignum void get_symintfromval(VALUE operand2, basic_struct *cbasic_operand2); -//Returns the Ruby class of the corresponding basic_struct pointer +// Returns the Ruby class of the corresponding basic_struct pointer VALUE Klass_of_Basic(const basic_struct *basic_ptr); -//Returns the result from the function pointed by cwfunc_ptr: for one argument functions -VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1); -//Returns the result from the function pointed by cwfunc_ptr: for two argument functions -VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), +// Returns the result from the function pointed by cwfunc_ptr: for one argument +// functions +VALUE function_onearg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *), + VALUE operand1); +// Returns the result from the function pointed by cwfunc_ptr: for two argument +// functions +VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct *, const basic_struct *, + const basic_struct *), VALUE operand1, VALUE operand2); -#endif //SYMENGINE_UTILS_H_ +#endif // SYMENGINE_UTILS_H_