Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
  • Loading branch information
chrisseaton committed Jan 25, 2015
2 parents 63a99be + 48b7055 commit 231b213
Show file tree
Hide file tree
Showing 49 changed files with 459 additions and 207 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1110,7 +1110,7 @@ public Operand buildSClass(SClassNode sclassNode) {
Variable sClassVar = addResultInstr(new DefineMetaClassInstr(createTemporaryVariable(), receiver, body));

// sclass bodies inherit the block of their containing method
Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), sClassVar, NullBlock.INSTANCE));
Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), sClassVar, scope.getYieldClosureVariable()));
newIRBuilder(manager, body).buildModuleOrClassBody(sclassNode.getBodyNode(), sclassNode.getPosition().getLine());
return processBodyResult;
}
Expand Down
45 changes: 40 additions & 5 deletions core/src/main/ruby/jruby/truffle/core/float.rb
Expand Up @@ -6,14 +6,40 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Float

NAN = 0.0 / 0.0
INFINITY = 1.0 / 0.0
EPSILON = 2.2204460492503131e-16
RADIX = 2
ROUNDS = 1
MIN = 2.2250738585072014e-308
MIN = 4.9E-324
MAX = 1.7976931348623157e+308
MIN_EXP = -1021
MAX_EXP = 1024
Expand All @@ -22,10 +48,6 @@ class Float
DIG = 15
MANT_DIG = 53

def negative?
self < 0
end

# for Float ** Rational we would normally do Rational.convert(a) ** b, but
# this ends up being recursive using Rubinius' code, so we use this helper
# instead.
Expand All @@ -36,4 +58,17 @@ def pow_rational(rational)

private :pow_rational

def equal_fallback(other)
# Fallback from Rubinius' Float#==, after the primitive call

begin
b, a = math_coerce(other)
return a == b
rescue TypeError
return other == self
end
end

private :equal_fallback

end
Expand Up @@ -41,4 +41,60 @@ def to_r
(f * (RADIX ** e)).to_r
end

def arg
if nan?
self
elsif negative?
Math::PI
else
0
end
end
alias_method :angle, :arg
alias_method :phase, :arg

def negative?
Rubinius.primitive :float_negative
raise PrimitiveFailure, "Float#negative primitive failed"
end

def numerator
if nan?
NAN
elsif infinite? == 1
INFINITY
elsif infinite? == -1
-INFINITY
else
super
end
end

def denominator
if infinite? || nan?
1
else
super
end
end

alias_method :quo, :/
alias_method :modulo, :%

def finite?
not (nan? or infinite?)
end

def rationalize(eps=undefined)
if undefined.equal?(eps)
f, n = Math.frexp self
f = Math.ldexp(f, Float::MANT_DIG).to_i
n -= Float::MANT_DIG

Rational.new(2 * f, 1 << (1 - n)).rationalize(Rational.new(1, 1 << (1 - n)))
else
to_r.rationalize(eps)
end
end

end
Expand Up @@ -112,4 +112,12 @@ def real?
true
end

def numerator
to_r.numerator
end

def denominator
to_r.denominator
end

end
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/float/abs_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/float/angle_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/float/arg_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/ceil_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/coerce_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/float/comparison_tags.txt

This file was deleted.

13 changes: 0 additions & 13 deletions spec/truffle/tags/core/float/constants_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/float/denominator_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/float/divide_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/float/divmod_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/float/eql_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/float/exponent_tags.txt

This file was deleted.

14 changes: 0 additions & 14 deletions spec/truffle/tags/core/float/fdiv_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/float/finite_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/float_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/floor_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/float/hash_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/float/infinite_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/float/magnitude_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/minus_tags.txt

This file was deleted.

14 changes: 0 additions & 14 deletions spec/truffle/tags/core/float/modulo_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/float/multiply_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/nan_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/float/numerator_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/float/phase_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/plus_tags.txt

This file was deleted.

14 changes: 0 additions & 14 deletions spec/truffle/tags/core/float/quo_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/float/rationalize_tags.txt
@@ -1,6 +1,3 @@
fails:Float#rationalize returns self as a simplified Rational with no argument
fails:Float#rationalize simplifies self to the degree specified by a Rational argument
fails:Float#rationalize simplifies self to the degree specified by a Float argument
fails:Float#rationalize raises a FloatDomainError for Infinity
fails:Float#rationalize raises a FloatDomainError for NaN
fails:Float#rationalize raises ArgumentError when passed more than one argument
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/float/round_tags.txt
@@ -1,5 +1,3 @@
fails:Float#round returns the nearest Integer
fails:Float#round raises FloatDomainError for exceptional values
fails:Float#round rounds self to an optionally given precision
fails:Float#round returns zero when passed a negative argument with magitude greater the magitude of the whole number portion of the Float
fails:Float#round raises a TypeError when its argument can not be converted to an Integer
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/to_r_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/float/to_s_tags.txt
Expand Up @@ -11,5 +11,3 @@ fails:Float#to_s uses e format for a positive value with whole part having 18 si
fails:Float#to_s uses e format for a negative value with whole part having 18 significant figures
fails:Float#to_s uses non-e format for a positive value with whole part having 17 significant figures
fails:Float#to_s uses non-e format for a negative value with whole part having 17 significant figures
fails:Float#to_s returns a String in US-ASCII encoding when Encoding.default_internal is nil
fails:Float#to_s returns a String in US-ASCII encoding when Encoding.default_internal is not nil
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/float/uminus_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/uplus_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/float/zero_tags.txt

This file was deleted.

8 changes: 8 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Expand Up @@ -283,6 +283,14 @@ public boolean isForeignObject(Object object) {
return (object instanceof TruffleObject) && !(isRubyBasicObject(object));
}

public boolean isNaN(double value) {
return Double.isNaN(value);
}

public boolean isInfinity(double value) {
return Double.isInfinite(value);
}

// Copied from RubyTypesGen

@SuppressWarnings("static-method")
Expand Down

0 comments on commit 231b213

Please sign in to comment.