diff --git a/ChangeLog b/ChangeLog index 5b80340a90..eea775963c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Tue Mar 26 01:48:01 2002 Akinori MUSHA + + * ext/bigfloat/extconf.rb: Downcase the module name. (BigFloat.so + -> bigfloat.so) + + * ext/bigfloat/bigfloat.c (BigFloat_inspect): Alter the inspect + format not to look like an array. (pointed out by akr) + + * ext/bigfloat/bigfloat.c (BigFloat_hash): Implement BigFloat#hash. + + * ext/bigfloat/bigfloat.c (BigFloat_dump, BigFloat_load): + Support marshaling. + Tue Mar 26 00:38:11 2002 Tanaka Akira * configure.in (FILE_READPTR): check _p for 4.4BSD. diff --git a/ext/bigfloat/bigfloat.c b/ext/bigfloat/bigfloat.c index 079709f892..253f4b709d 100644 --- a/ext/bigfloat/bigfloat.c +++ b/ext/bigfloat/bigfloat.c @@ -158,6 +158,9 @@ static VALUE BigFloat_sign();/* sign */ static VALUE BigFloat_mode(); /* mode */ static VALUE BigFloat_induced_from(); /* induced_from */ static void BigFloat_delete(); /* free */ +static VALUE BigFloat_hash(); +static VALUE BigFloat_dump(); +static VALUE BigFloat_load(); /* Added for ruby 1.6.0 */ static VALUE BigFloat_IsNaN(); @@ -246,6 +249,7 @@ Initialize(BIGFLOAT) rb_define_method(rb_cBigfloat, "div",BigFloat_divmod2, 2); rb_define_singleton_method(rb_cBigfloat, "induced_from",BigFloat_induced_from, 1); + rb_define_singleton_method(rb_cBigfloat, "_load", BigFloat_load, 1); rb_define_const(rb_cBigfloat, "BASE", INT2FIX((S_INT)VpBaseVal())); @@ -308,6 +312,8 @@ Initialize(BIGFLOAT) rb_define_method(rb_cBigfloat, "inspect", BigFloat_inspect, 0); rb_define_method(rb_cBigfloat, "exponent", BigFloat_exponent, 0); rb_define_method(rb_cBigfloat, "sign", BigFloat_sign, 0); + rb_define_method(rb_cBigfloat, "hash", BigFloat_hash, 0); + rb_define_method(rb_cBigfloat, "_dump", BigFloat_dump, 1); /* newly added for ruby 1.6.0 */ rb_define_method(rb_cBigfloat, "nan?", BigFloat_IsNaN, 0); rb_define_method(rb_cBigfloat, "infinite?", BigFloat_IsInfinite, 0); @@ -1506,7 +1512,7 @@ BigFloat_inspect(self) psz1 = ALLOCA_N(char,nc); pszAll = ALLOCA_N(char,nc+256); VpToString(vp, psz1, 10); - sprintf(pszAll,"[BigFloat:%x,'%s',%u(%u)]",self,psz1,VpPrec(vp)*VpBaseFig(),VpMaxPrec(vp)*VpBaseFig()); + sprintf(pszAll,"#",self,psz1,VpPrec(vp)*VpBaseFig(),VpMaxPrec(vp)*VpBaseFig()); obj = rb_str_new2(pszAll); return obj; @@ -1567,6 +1573,50 @@ BigFloat_new(argc,argv,self) return ToValue(pv); } +static VALUE +BigFloat_hash(self) + VALUE self; +{ + ENTER(1); + Real *p; + U_LONG hash, i; + S_INT sign, n; + + GUARD_OBJ(p,GetVpValue(self,1)); + + sign = p->sign; + hash = (U_LONG)sign; + + switch (sign) { + case 2: + case -2: + for (i = 0; i < p->Prec; i++) { + hash ^= p->frac[i]; + } + + /* rotate left */ + n = p->exponent & 0xf; + hash = hash << n | hash >> (sizeof(hash) * 8 - n); + break; + } + + return LONG2FIX((long)hash); +} + +static VALUE +BigFloat_dump(self, limit) + VALUE self, limit; +{ + return BigFloat_to_s(self); +} + +static VALUE +BigFloat_load(klass, str) + VALUE klass, str; +{ + return BigFloat_new(1, &str, klass); +} + static VALUE BigFloat_limit(argc,argv,self) int argc; diff --git a/ext/bigfloat/extconf.rb b/ext/bigfloat/extconf.rb index 7a2b270d34..883aebdd1b 100644 --- a/ext/bigfloat/extconf.rb +++ b/ext/bigfloat/extconf.rb @@ -1,2 +1,2 @@ require 'mkmf' -create_makefile('BigFloat') +create_makefile('bigfloat')