lib/nio/repdec.rb in nio-0.2.0 vs lib/nio/repdec.rb in nio-0.2.1
- old
+ new
@@ -72,11 +72,11 @@
@nan_txt = 'NaN'
@digits = DigitsDef.new
@digits_defined = false
- @max_d = 2048
+ @max_d = 5000
end
attr_accessor :begin_rep, :end_rep, :auto_rep, :dec_sep, :grp_sep, :grp, :max_d
attr_accessor :nan_txt, :inf_txt
@@ -377,10 +377,21 @@
#def !=(c)
# return !(self==c);
#end
+ # Change the maximum number of digits that RepDec objects
+ # can handle.
+ def RepDec.maximum_number_of_digits=(n)
+ @max_d = [n,2048].max
+ end
+ # Return the maximum number of digits that RepDec objects
+ # can handle.
+ def RepDec.maximum_number_of_digits
+ @max_d
+ end
+
def setQ(x,y, opt=DEF_OPT)
@radix = opt.digits.radix if opt.digits_defined?
xy_sign = x==0 ? 0 : x<0 ? -1 : +1;
xy_sign = -xy_sign if y<0;
@sign = xy_sign
@@ -397,23 +408,23 @@
@ip = xy_sign==-1 ? :neginfinity : :posinfinity
end
return self
end
- k = [];
+ k = {};
@ip = x.div(y) #x/y;
x -= @ip*y;
i = 0;
ended = false;
max_d = opt.max_d
while x>0 && @rep_i==nil && (max_d<=0 || i<max_d)
- @rep_i = k.index(x)
+ @rep_i = k[x]
if @rep_i.nil? then
- k.push x;
+ k[x] = i;
x *= @radix
- @d.push x.div(y) # x/y;
- x-= @d[i]*y;
+ d,x = x.divmod(y)
+ @d.push d
i += 1;
end
end
self
end