From: Rick DeNatale Date: 2008-05-05T12:29:22+09:00 Subject: Re: Help with rb_iv_set 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/