1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2002-03-25 16:51:22 +00:00
parent 6696999417
commit c4af72cd46
3 changed files with 65 additions and 2 deletions

View file

@ -1,3 +1,16 @@
Tue Mar 26 01:48:01 2002 Akinori MUSHA <knu@iDaemons.org>
* 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 <akr@m17n.org>
* configure.in (FILE_READPTR): check _p for 4.4BSD.

View file

@ -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,"#<BigFloat:%x,'%s',%u(%u)>",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;

View file

@ -1,2 +1,2 @@
require 'mkmf'
create_makefile('BigFloat')
create_makefile('bigfloat')