summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
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