blackwinter / rb-gsl

Ruby interface to the GNU Scientific Library [Ruby 2.x and GSL 1.16 compatible fork of the gsl gem]
https://blackwinter.github.io/rb-gsl
Other
27 stars 7 forks source link

Fixes multiplication with floating point numbers. #17

Closed v0dro closed 9 years ago

v0dro commented 9 years ago

Reason for fix: Previously the method was using NUMCONV, which resolved to FIX2INT for GSL::Matrix::Int or GSL::Vector::Int. It would use FIX2INT irrespective of whether the object being passed to it was a Fixnum or a Float. This, somehow caused a malfunction on my system (ruby 2.2.1 on rvm with debian 8 jessie) and the converted INT value would turn out to be garbage.

Converting the NUMCONV to NUMCONV2 makes sure that the macro resolves to NUM2INT for GSL::Matrix::Int and GSL::Vector::Int. This way, it is ensured that the object, whether a Float or Fixnum is appropriately converted to an INT without error, since both are of type Numeric.

No tests break now, and I think NUMCONV2 would be more fool-proof too.

blackwinter commented 9 years ago

Thanks. I've merged your changes and updated rb_gsl_matrix_scale_bang and rb_gsl_vector_scale_bang as well. What about rb_gsl_{matrix,vector}_add_constant{,_bang}, don't they also need fixing?

v0dro commented 9 years ago

I'll investigate. Didn't get time to prod further yesterday. Will send a PR directly in a while.

blackwinter commented 9 years ago

No need for a PR. I'm ready to push (or revert), just need your confirmation.

v0dro commented 9 years ago

Yes I think it should be NUMCONV2 over there as well.

blackwinter commented 9 years ago

Thanks, done.