Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 97f6ea3efe64
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 885370d54ca7
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Aug 19, 2015

  1. Copy the full SHA
    4271102 View commit details
  2. Add Number#bit_length

    meh committed Aug 19, 2015
    Copy the full SHA
    2f164c6 View commit details
  3. Add Integer::MAX and Integer::MIN

    meh committed Aug 19, 2015
    Copy the full SHA
    885370d View commit details
Showing with 29 additions and 6 deletions.
  1. +29 −6 opal/corelib/number.rb
35 changes: 29 additions & 6 deletions opal/corelib/number.rb
Original file line number Diff line number Diff line change
@@ -7,15 +7,17 @@ class Number < Numeric

def coerce(other)
%x{
if (!#{other.is_a? Numeric}) {
if (other === nil) {
#{raise TypeError, "can't convert #{other.class} into Float"};
}
if (other.$$is_number) {
return [self, other];
else if (other.$$is_string) {
return [#{Float(other)}, self];
}
else if (#{self.respond_to?(:to_f)} && #{other.respond_to?(:to_f)}) {
return [self.$to_f(), other.$to_f()];
else if (#{other.respond_to?(:to_f)}) {
return [#{Opal.coerce_to!(other, Float, :to_f)}, self];
}
else if (other.$$is_number) {
return [other, self];
}
else {
#{raise TypeError, "can't convert #{other.class} into Float"};
@@ -285,6 +287,24 @@ def angle
alias arg angle
alias phase angle

def bit_length
unless Integer === self
raise NoMethodError, "undefined method `bit_length` for #{self}:Float"
end

%x{
var result = 0,
value = self;
while (value != 0) {
result += 1;
value >>= 1;
}
return result;
}
end

def ceil
`Math.ceil(self)`
end
@@ -633,6 +653,9 @@ def self.===(other)
return (other % 1) === 0;
}
end

MAX = `Math.pow(2, 30) - 1`
MIN = `-Math.pow(2, 30)`
end

class Float < Numeric