------ art_19636_12871379.1209994552938 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Rick, So you're saying that by doing it the way I was doing it (using rb_float_new) I am indeed doing it correctly? -- Thanks! Bryan On Sun, May 4, 2008 at 9:29 PM, Rick DeNatale <rick.denatale / gmail.com> wrote: > On Sun, May 4, 2008 at 11:13 PM, Bryan Richardson > <btrichardson / gmail.com> wrote: > > Hello all, > > > > I'm trying to use rb_iv_set to set a double value in a C extension I'm > > writing. > > > > rb_iv_set(self, "@voltage", 1.01); > > > > This doesn't seem to work, as I get a '0' instead of '1.01'. If I use > > rb_float_new(1.01), then it works. However, the voltage value in my C > > structure is a double, and rb_double_new doesn't exist. > > > > Any suggestions? > > rb_iv_set needs a VALUE for the third parameter. > and the value of a Ruby float is a C double: > > From the 1.8.6 source: > > in ruby.h > > VALUE rb_iv_set _((VALUE, const char*, VALUE)); > > and also: > > struct RFloat { > struct RBasic basic; > double value; > }; > > And from numeric.c > > VALUE > rb_float_new(d) > double d; > { > NEWOBJ(flt, struct RFloat); > OBJSETUP(flt, rb_cFloat, T_FLOAT); > > flt->value ; > return (VALUE)flt; > } > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > > ------ art_19636_12871379.1209994552938--