Skip to content

Commit

Permalink
Fix for JRUBY-3090: Fix endless loop with Math.frexp(inf)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@7957 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information
headius committed Oct 30, 2008
1 parent 41139e2 commit 6708aaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/jruby/RubyMath.java
Expand Up @@ -325,7 +325,7 @@ public static RubyArray frexp(IRubyObject recv, IRubyObject other) {
short sign = 1;
long exponent = 0;

if (mantissa != 0.0) {
if (!Double.isInfinite(mantissa) && mantissa != 0.0) {
// Make mantissa same sign so we only have one code path.
if (mantissa < 0) {
mantissa = -mantissa;
Expand Down
14 changes: 14 additions & 0 deletions test/test_math.rb
Expand Up @@ -5,4 +5,18 @@ class TestMath < Test::Unit::TestCase
def test_tanh_returns_1_when_given_1_over_0
assert_equal(1.0, Math.tanh(1.0/0.0))
end

def test_frexp_inf
inf = 1.0 / 0
assert_nothing_raised{ Math.frexp(inf) }
assert_equal(inf, Math.frexp(inf).first)
assert_equal(0, Math.frexp(inf).last)
end

def test_frexp_nan
nan = 0.0 / 0
assert_nothing_raised{ Math.frexp(nan) }
assert(Math.frexp(nan).first.nan?)
assert_equal(0, Math.frexp(nan).last)
end
end

0 comments on commit 6708aaa

Please sign in to comment.