Skip to content

Commit

Permalink
Merge branch 'master', remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavio committed Oct 20, 2011
2 parents fc403fe + a805ad6 commit 479646f
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 91 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Expand Up @@ -61,6 +61,7 @@
- David Waite: { irc: ddubs }
- David Whittington: { irc: djwhitt }
- David Yip:
- Davor Babic: { irc: davorb, github: davorb, email: davor@davor.se }
- Defn:
- Dirkjan Bussink: { irc: dbussink }
- Drew Olson:
Expand All @@ -76,6 +77,7 @@
- Glenn Davy:
- Graham:
- Gregor Schmidt:
- Guillermo Iguaran: { irc: guilleiguaran, github: guilleiguaran }
- Haofei Wang:
- Hapk:
- Hemant Kumar: { irc: gnufied }
Expand Down Expand Up @@ -159,6 +161,7 @@
- Sean Bryant:
- Shoaib Kamil:
- Stephen Bannasch:
- Steve Klabnik: { irc: steveklabnik }
- Stuart Halloway:
- Thomas Lachmann:
- Tilman Sauerbeck: { irc: tilman }
Expand Down
1 change: 0 additions & 1 deletion kernel/common/integer.rb
Expand Up @@ -148,4 +148,3 @@ def downto(val)
self
end
end

78 changes: 78 additions & 0 deletions kernel/common/integer19.rb
@@ -1,3 +1,81 @@
class Integer
alias_method :magnitude, :abs

#
# In an integer, the value _is_ the numerator of its rational equivalent.
# Therefore, this method returns +self+.
#
def numerator
self
end

#
# In an integer, the denominator is 1. Therefore, this method returns 1.
#
def denominator
1
end

#
# Returns a Rational representation of this integer.
#
def to_r
Rational(self, 1)
end

#
# Returns the <em>greatest common denominator</em> of the two numbers (+self+
# and +n+).
#
# Examples:
# 72.gcd 168 # -> 24
# 19.gcd 36 # -> 1
#
# The result is positive, no matter the sign of the arguments.
#
def gcd(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
min = self.abs
max = other.abs
while min > 0
tmp = min
min = max % min
max = tmp
end
max
end

#
# Returns the <em>lowest common multiple</em> (LCM) of the two arguments
# (+self+ and +other+).
#
# Examples:
# 6.lcm 7 # -> 42
# 6.lcm 9 # -> 18
#
def lcm(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
if self.zero? or other.zero?
0
else
(self.div(self.gcd(other)) * other).abs
end
end

#
# Returns the GCD _and_ the LCM (see #gcd and #lcm) of the two arguments
# (+self+ and +other+). This is more efficient than calculating them
# separately.
#
# Example:
# 6.gcdlcm 9 # -> [3, 18]
#
def gcdlcm(other)
gcd = self.gcd(other)
if self.zero? or other.zero?
[gcd, 0]
else
[gcd, (self.div(gcd) * other).abs]
end
end
end
6 changes: 6 additions & 0 deletions kernel/common/range.rb
Expand Up @@ -323,5 +323,11 @@ def to_a
super
end

def max &a
return super(&a) if block_given?
return nil if @end < @begin
@end
end

end

79 changes: 0 additions & 79 deletions kernel/common/rational.rb
Expand Up @@ -438,85 +438,6 @@ def hash
private :initialize
end

class Integer
#
# In an integer, the value _is_ the numerator of its rational equivalent.
# Therefore, this method returns +self+.
#
def numerator
self
end

#
# In an integer, the denominator is 1. Therefore, this method returns 1.
#
def denominator
1
end

#
# Returns a Rational representation of this integer.
#
def to_r
Rational(self, 1)
end

#
# Returns the <em>greatest common denominator</em> of the two numbers (+self+
# and +n+).
#
# Examples:
# 72.gcd 168 # -> 24
# 19.gcd 36 # -> 1
#
# The result is positive, no matter the sign of the arguments.
#
def gcd(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
min = self.abs
max = other.abs
while min > 0
tmp = min
min = max % min
max = tmp
end
max
end

#
# Returns the <em>lowest common multiple</em> (LCM) of the two arguments
# (+self+ and +other+).
#
# Examples:
# 6.lcm 7 # -> 42
# 6.lcm 9 # -> 18
#
def lcm(other)
if self.zero? or other.zero?
0
else
(self.div(self.gcd(other)) * other).abs
end
end

#
# Returns the GCD _and_ the LCM (see #gcd and #lcm) of the two arguments
# (+self+ and +other+). This is more efficient than calculating them
# separately.
#
# Example:
# 6.gcdlcm 9 # -> [3, 18]
#
def gcdlcm(other)
gcd = self.gcd(other)
if self.zero? or other.zero?
[gcd, 0]
else
[gcd, (self.div(gcd) * other).abs]
end
end
end

class Fixnum
remove_method :quo

Expand Down
16 changes: 9 additions & 7 deletions kernel/common/string19.rb
Expand Up @@ -51,13 +51,15 @@ def upto(stop, exclusive=false)
current += 1
end
else
after_stop = exclusive ? stop : stop.succ
current = self

until current == after_stop
yield current
current = StringValue(current.succ)
break if current.size > stop.size || current.size == 0
unless stop.size < size
after_stop = exclusive ? stop : stop.succ
current = self

until current == after_stop
yield current
current = StringValue(current.succ)
break if current.size > stop.size || current.size == 0
end
end
end
self
Expand Down
1 change: 0 additions & 1 deletion spec/tags/19/ruby/core/integer/gcdlcm_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/19/ruby/core/integer/lcm_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/19/ruby/core/string/upto_tags.txt
@@ -1 +0,0 @@
fails:String#upto doesn't call block with self even if self is less than stop but stop length is less than self length
Empty file.
Empty file.
Empty file.
1 change: 0 additions & 1 deletion spec/tags/19/ruby/library/mathn/rational/inspect_tags.txt

This file was deleted.

3 changes: 3 additions & 0 deletions vm/environment.cpp
Expand Up @@ -13,6 +13,7 @@
#include "builtin/string.hpp"
#include "builtin/symbol.hpp"
#include "builtin/module.hpp"
#include "builtin/nativemethod.hpp"

#ifdef ENABLE_LLVM
#include "llvm/state.hpp"
Expand Down Expand Up @@ -539,6 +540,8 @@ namespace rubinius {
state->shared.checkpoint(state);
}

NativeMethod::cleanup_thread(state);

#ifdef ENABLE_LLVM
LLVMState::shutdown(state);
#endif
Expand Down

0 comments on commit 479646f

Please sign in to comment.