summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-11 05:00:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-07-11 05:00:02 +0000
commit4bacdc1e46ab788f9285ccd8eccd2776260f9528 (patch)
treea603c9435fcf3c432ecc1389be508a3aaa7cd4ca /ext/bigdecimal
parentfd66442a1d8cec73a14601f8056b9fad238f92be (diff)
* bignum.c (bignorm): sizeof(long) may be smaller than
sizeof(VALUE). [ruby-dev:29013] * ruby.h (FIXNUM_MAX): fixnum may be bigger than long. * ruby.h (SIGNED_VALUE): signed integer of size of VALUE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c15
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb5
2 files changed, 15 insertions, 5 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index bff9eacbe8..4de5672457 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2496,14 +2496,25 @@ VpAlloc(U_LONG mx, const char *szVal)
return vp;
}
- /* Skip all spaces */
+ /* Skip all '_' after digit: 2006-6-30 */
+ ni = 0;
psz = ALLOCA_N(char,strlen(szVal)+1);
i = 0;
ipn = 0;
while(psz[i]=szVal[ipn]) {
- if(ISSPACE(szVal[ipn])) {ipn++;continue;}
+ if(ISDIGIT(psz[i])) ++ni;
+ if(psz[i]=='_') {
+ if(ni>0) {ipn++;continue;}
+ psz[i]=0;
+ break;
+ }
++i; ++ipn;
}
+ /* Skip trailing spaces */
+ while((--i)>0) {
+ if(ISSPACE(psz[i])) psz[i] = 0;
+ else break;
+ }
szVal = psz;
/* Check on Inf & NaN */
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index 2c17aa6b8e..09e926acd5 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -46,11 +46,10 @@ class BigDecimal < Numeric
numerator = sign*digits.to_i
denomi_power = power - digits.size # base is always 10
if denomi_power < 0
- denominator = base ** (-denomi_power)
+ Rational(numerator,base ** (-denomi_power))
else
- denominator = base ** denomi_power
+ Rational(numerator * (base ** denomi_power),1)
end
- Rational(numerator,denominator)
end
end