From: Tim Pease Date: 2008-05-06T01:34:38+09:00 Subject: Re: Help with rb_iv_set On May 5, 2008, at 7:35 AM, Bryan Richardson wrote: > 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? > To be explicit about your specific case ... rb_iv_set(self, "@voltage", rb_float_new(1.01)); Blessings, TwP > -- > Thanks! > Bryan > > On Sun, May 4, 2008 at 9:29 PM, Rick DeNatale > > wrote: > >> On Sun, May 4, 2008 at 11:13 PM, Bryan Richardson >> 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 = d; >> return (VALUE)flt; >> } >> >> >> -- >> Rick DeNatale >> >> My blog on Ruby >> http://talklikeaduck.denhaven2.com/ >> >>