summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/date2.rb25
-rw-r--r--lib/getoptlong.rb4
-rw-r--r--lib/jcode.rb2
-rw-r--r--lib/matrix.rb5
-rw-r--r--lib/parsedate.rb2
-rw-r--r--lib/rational.rb34
6 files changed, 48 insertions, 24 deletions
diff --git a/lib/date2.rb b/lib/date2.rb
index 58bfbe5a23..cc5e7f4238 100644
--- a/lib/date2.rb
+++ b/lib/date2.rb
@@ -1,5 +1,5 @@
# date2.rb: Written by Tadayoshi Funaba 1998, 1999
-# $Id: date2.rb,v 1.13 1999/08/11 01:10:02 tadf Exp $
+# $Id: date2.rb,v 1.15 1999/08/29 15:23:52 tadf Exp $
class Date
@@ -31,10 +31,10 @@ class Date
y -= 1
m += 12
end
- a = (y / 100).to_i
- b = 2 - a + (a / 4).to_i
- jd = (365.25 * (y + 4716)).to_i +
- (30.6001 * (m + 1)).to_i +
+ a = (y / 100.0).floor
+ b = 2 - a + (a / 4.0).floor
+ jd = (365.25 * (y + 4716)).floor +
+ (30.6001 * (m + 1)).floor +
d + b - 1524
if os?(jd, sg)
jd -= b
@@ -46,14 +46,14 @@ class Date
if os?(jd, sg)
a = jd
else
- x = ((jd - 1867216.25) / 36524.25).to_i
- a = jd + 1 + x - (x / 4).to_i
+ x = ((jd - 1867216.25) / 36524.25).floor
+ a = jd + 1 + x - (x / 4.0).floor
end
b = a + 1524
- c = ((b - 122.1) / 365.25).to_i
- d = (365.25 * c).to_i
- e = ((b - d) / 30.6001).to_i
- dom = b - d - (30.6001 * e).to_i
+ c = ((b - 122.1) / 365.25).floor
+ d = (365.25 * c).floor
+ e = ((b - d) / 30.6001).floor
+ dom = b - d - (30.6001 * e).floor
if e <= 13
m = e - 1
y = c - 4716
@@ -70,8 +70,7 @@ class Date
def jd_to_ordinal(jd, sg=true)
y = jd_to_civil(jd, sg)[0]
- pl = civil_to_jd(y - 1, 12, 31, ns?(jd, sg))
- doy = jd - pl
+ doy = jd - civil_to_jd(y - 1, 12, 31, ns?(jd, sg))
return y, doy
end
diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb
index a37714cafd..82cccf43b9 100644
--- a/lib/getoptlong.rb
+++ b/lib/getoptlong.rb
@@ -303,7 +303,7 @@ class GetoptLong
when STATUS_YET
@status = STATUS_STARTED
when STATUS_TERMINATED
- return
+ return nil
end
#
@@ -320,7 +320,7 @@ class GetoptLong
end
if ARGV.length == 0
terminate
- return
+ return nil
end
$_ = ARGV.shift
elsif @ordering == REQUIRE_ORDER
diff --git a/lib/jcode.rb b/lib/jcode.rb
index 92b9284471..6e5bc9e99d 100644
--- a/lib/jcode.rb
+++ b/lib/jcode.rb
@@ -104,7 +104,7 @@ class String
self.gsub!(pattern, last)
else
h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
- self.gsub!(pattern) do |c| h[c] end
+ self.gsub!(pattern) do |c| p [c,h[c]]; h[c] end
end
end
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 4d4ca343fd..a408f4be91 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1,8 +1,8 @@
#
# matrix.rb -
# $Release Version: 1.0$
-# $Revision: 1.8 $
-# $Date: 1999/02/17 12:34:19 $
+# $Revision: 1.9 $
+# $Date: 1999/08/24 10:25:00 $
# Original Version from Smalltalk-80 version
# on July 23, 1985 at 8:37:17 am
# by Keiju ISHITSUKA
@@ -593,6 +593,7 @@ class Matrix
end while a[i][k] == 0
a[i], a[k] = a[k], a[i]
akk = a[k][k]
+ det *= -1
end
(k + 1).upto(size) do
|i|
diff --git a/lib/parsedate.rb b/lib/parsedate.rb
index ff41d162ad..f49266d2e5 100644
--- a/lib/parsedate.rb
+++ b/lib/parsedate.rb
@@ -73,7 +73,7 @@ module ParseDate
elsif date.sub!(/\d\d/i, ' ')
year = $&.to_i
end
- if guess
+ if guess and year
if year < 100
if year >= 69
year += 1900
diff --git a/lib/rational.rb b/lib/rational.rb
index f976cf034f..decf26b1ba 100644
--- a/lib/rational.rb
+++ b/lib/rational.rb
@@ -1,8 +1,8 @@
#
# rational.rb -
# $Release Version: 0.5 $
-# $Revision: 1.3 $
-# $Date: 1998/03/11 14:09:03 $
+# $Revision: 1.7 $
+# $Date: 1999/08/24 12:49:28 $
# by Keiju ISHITSUKA(SHL Japan Inc.)
#
# --
@@ -44,7 +44,7 @@ def Rational(a, b = 1)
end
class Rational < Numeric
- @RCS_ID='-$Id: rational.rb,v 1.3 1998/03/11 14:09:03 keiju Exp keiju $-'
+ @RCS_ID='-$Id: rational.rb,v 1.7 1999/08/24 12:49:28 keiju Exp keiju $-'
def Rational.reduce(num, den = 1)
raise ZeroDivisionError, "denometor is 0" if den == 0
@@ -235,6 +235,10 @@ class Rational < Numeric
self
end
+ def inspect
+ sprintf("Rational(%s, %s)", @numerator.inspect, @denominator.inspect)
+ end
+
def hash
@numerator ^ @denominator
end
@@ -258,7 +262,27 @@ class Integer
Rational(self, 1)
end
- def gcd(int)
+ def gcd(n)
+ m = self.abs
+ n = n.abs
+
+ return n if m == 0
+ return m if n == 0
+
+ b = 0
+ while n[0] == 0 && m[0] == 0
+ b += 1; n >>= 1; m >>= 1
+ end
+ m >>= 1 while m[0] == 0
+ n >>= 1 while n[0] == 0
+ while m != n
+ m, n = n, m if n > m
+ m -= n; m >>= 1 while m[0] == 0
+ end
+ m << b
+ end
+
+ def gcd2(int)
a = self.abs
b = int.abs
@@ -270,7 +294,7 @@ class Integer
end
return a
end
-
+
def lcm(int)
a = self.abs
b = int.abs