mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
patches from T.Saito etc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e4de8e7566
commit
15c3df744f
3 changed files with 28 additions and 17 deletions
|
@ -254,7 +254,7 @@ BigDecimal_load(VALUE self, VALUE str)
|
||||||
pch = RSTRING(str)->ptr;
|
pch = RSTRING(str)->ptr;
|
||||||
/* First get max prec */
|
/* First get max prec */
|
||||||
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
|
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
|
||||||
if(ch<'0' || ch>'9') {
|
if(!ISDIGIT(ch)) {
|
||||||
rb_raise(rb_eTypeError, "Load failed: invalid character in the marshaled string");
|
rb_raise(rb_eTypeError, "Load failed: invalid character in the marshaled string");
|
||||||
}
|
}
|
||||||
m = m*10 + (unsigned long)(ch-'0');
|
m = m*10 + (unsigned long)(ch-'0');
|
||||||
|
@ -325,7 +325,7 @@ GetPositiveInt(VALUE v)
|
||||||
Check_Type(v, T_FIXNUM);
|
Check_Type(v, T_FIXNUM);
|
||||||
n = FIX2INT(v);
|
n = FIX2INT(v);
|
||||||
if(n <= 0) {
|
if(n <= 0) {
|
||||||
rb_fatal("Zero or negative argument not permitted.");
|
rb_raise(rb_eArgError, "argument must be positive");
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,17 @@ BigDecimal_to_i(VALUE self)
|
||||||
|
|
||||||
GUARD_OBJ(p,GetVpValue(self,1));
|
GUARD_OBJ(p,GetVpValue(self,1));
|
||||||
|
|
||||||
if(!VpIsDef(p)) return Qnil; /* Infinity or NaN not converted. */
|
/* Infinity or NaN not converted. */
|
||||||
|
if(VpIsNaN(p)) {
|
||||||
|
VpException(VP_EXCEPTION_NaN,"Computation results to 'NaN'(Not a Number)",0);
|
||||||
|
return Qnil;
|
||||||
|
} else if(VpIsPosInf(p)) {
|
||||||
|
VpException(VP_EXCEPTION_INFINITY,"Computation results to 'Infinity'",0);
|
||||||
|
return Qnil;
|
||||||
|
} else if(VpIsNegInf(p)) {
|
||||||
|
VpException(VP_EXCEPTION_INFINITY,"Computation results to '-Infinity'",0);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
e = VpExponent10(p);
|
e = VpExponent10(p);
|
||||||
if(e<=0) return INT2FIX(0);
|
if(e<=0) return INT2FIX(0);
|
||||||
|
@ -431,19 +441,17 @@ BigDecimal_to_f(VALUE self)
|
||||||
{
|
{
|
||||||
ENTER(1);
|
ENTER(1);
|
||||||
Real *p;
|
Real *p;
|
||||||
double d, d2, da;
|
double d, d2;
|
||||||
S_LONG e;
|
S_LONG e;
|
||||||
|
|
||||||
GUARD_OBJ(p,GetVpValue(self,1));
|
GUARD_OBJ(p,GetVpValue(self,1));
|
||||||
if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d);
|
if(VpVtoD(&d, &e, p)!=1) return rb_float_new(d);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
d2 = pow(10.0,(double)e);
|
d2 = pow(10.0,(double)e);
|
||||||
da = fabs(d);
|
if((errno == ERANGE && e>0) || (d2>1.0 && (fabs(d) > (DBL_MAX / d2)))) {
|
||||||
if(errno == ERANGE || da > (DBL_MAX / d2) || da < (DBL_MIN / d2)) {
|
VpException(VP_EXCEPTION_OVERFLOW,"BigDecimal to Float conversion.",0);
|
||||||
U_LONG nc = VpNumOfChars(p)+1;
|
if(d>0.0) return rb_float_new(DBL_MAX);
|
||||||
char *psz = ALLOCA_N(char, nc);
|
else return rb_float_new(-DBL_MAX);
|
||||||
VpToString(p, psz, 0);
|
|
||||||
rb_raise(rb_eRangeError, "BigDecimal %s out of Float range", psz);
|
|
||||||
}
|
}
|
||||||
return rb_float_new(d*d2);
|
return rb_float_new(d*d2);
|
||||||
}
|
}
|
||||||
|
@ -1955,7 +1963,7 @@ overflow:
|
||||||
VP_EXPORT Real *
|
VP_EXPORT Real *
|
||||||
VpAlloc(U_LONG mx, char *szVal)
|
VpAlloc(U_LONG mx, char *szVal)
|
||||||
{
|
{
|
||||||
U_LONG i, ni, ipf, nf, ipe, ne, nalloc;
|
U_LONG i, ni, ipn, ipf, nf, ipe, ne, nalloc;
|
||||||
char v;
|
char v;
|
||||||
int sign=1;
|
int sign=1;
|
||||||
Real *vp = NULL;
|
Real *vp = NULL;
|
||||||
|
@ -2007,12 +2015,13 @@ VpAlloc(U_LONG mx, char *szVal)
|
||||||
|
|
||||||
/* check on number szVal[] */
|
/* check on number szVal[] */
|
||||||
i = SkipWhiteChar(szVal);
|
i = SkipWhiteChar(szVal);
|
||||||
|
ipn = i;
|
||||||
if (szVal[i] == '-') {sign=-1;++i;}
|
if (szVal[i] == '-') {sign=-1;++i;}
|
||||||
else if(szVal[i] == '+') ++i;
|
else if(szVal[i] == '+') ++i;
|
||||||
/* Skip digits */
|
/* Skip digits */
|
||||||
ni = 0; /* digits in mantissa */
|
ni = 0; /* digits in mantissa */
|
||||||
while(v = szVal[i]) {
|
while(v = szVal[i]) {
|
||||||
if((v > '9') ||(v < '0')) break;
|
if(!ISDIGIT(v)) break;
|
||||||
++i;
|
++i;
|
||||||
++ni;
|
++ni;
|
||||||
}
|
}
|
||||||
|
@ -2026,7 +2035,7 @@ VpAlloc(U_LONG mx, char *szVal)
|
||||||
++i;
|
++i;
|
||||||
ipf = i;
|
ipf = i;
|
||||||
while(v = szVal[i]) { /* get fraction part. */
|
while(v = szVal[i]) { /* get fraction part. */
|
||||||
if((v > '9') ||(v < '0')) break;
|
if(!ISDIGIT(v)) break;
|
||||||
++i;
|
++i;
|
||||||
++nf;
|
++nf;
|
||||||
}
|
}
|
||||||
|
@ -2061,7 +2070,7 @@ VpAlloc(U_LONG mx, char *szVal)
|
||||||
/* xmalloc() alway returns(or throw interruption) */
|
/* xmalloc() alway returns(or throw interruption) */
|
||||||
vp->MaxPrec = mx; /* set max precision */
|
vp->MaxPrec = mx; /* set max precision */
|
||||||
VpSetZero(vp,sign);
|
VpSetZero(vp,sign);
|
||||||
VpCtoV(vp, szVal, ni, &(szVal[ipf]), nf, &(szVal[ipe]), ne);
|
VpCtoV(vp, &(szVal[ipn]), ni, &(szVal[ipf]), nf, &(szVal[ipe]), ne);
|
||||||
return vp;
|
return vp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2868,7 +2877,6 @@ out_side:
|
||||||
goto Exit;
|
goto Exit;
|
||||||
|
|
||||||
space_error:
|
space_error:
|
||||||
rb_fatal("ERROR(VpDivd): space for remainder too small.\n");
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if(gfDebug) {
|
if(gfDebug) {
|
||||||
printf(" word_a=%lu\n", word_a);
|
printf(" word_a=%lu\n", word_a);
|
||||||
|
@ -2878,6 +2886,7 @@ space_error:
|
||||||
printf(" ind_r =%lu\n", ind_r);
|
printf(" ind_r =%lu\n", ind_r);
|
||||||
}
|
}
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
rb_bug("ERROR(VpDivd): space for remainder too small.");
|
||||||
|
|
||||||
Exit:
|
Exit:
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|
|
@ -108,6 +108,7 @@ where:<BR>
|
||||||
s: Initial value string.<BR>
|
s: Initial value string.<BR>
|
||||||
n: Maximum number of significant digits of a. n must be a Fixnum object.
|
n: Maximum number of significant digits of a. n must be a Fixnum object.
|
||||||
If n is omitted or is equal to 0,then the maximum number of significant digits of a is determined from the length of s.
|
If n is omitted or is equal to 0,then the maximum number of significant digits of a is determined from the length of s.
|
||||||
|
Currently, n has no actual meaning(reserved for future use).
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
|
|
||||||
<LI><B>mode</B></LI><BLOCKQUOTE>
|
<LI><B>mode</B></LI><BLOCKQUOTE>
|
||||||
|
|
|
@ -118,6 +118,7 @@ n
|
||||||
n が 0 または省略されたときは、n の値は s の有効桁数とみなされます。
|
n が 0 または省略されたときは、n の値は s の有効桁数とみなされます。
|
||||||
s の有効桁数より n が小さいときも n=0 のときと同じです。
|
s の有効桁数より n が小さいときも n=0 のときと同じです。
|
||||||
a の最大有効桁数は n より若干大い値が採用されます。
|
a の最大有効桁数は n より若干大い値が採用されます。
|
||||||
|
現時点では n を指定しても余り意味がありません(予約)。
|
||||||
</BLOCKQUOTE>
|
</BLOCKQUOTE>
|
||||||
|
|
||||||
<LI><B>mode</B></LI><BLOCKQUOTE>
|
<LI><B>mode</B></LI><BLOCKQUOTE>
|
||||||
|
|
Loading…
Add table
Reference in a new issue