mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	merge revision(s) 57232: [Backport #13084]
rational.c: fix for mathn * rational.c (read_num, read_rat_nos): dispatch by the type of numerator, for mathn. [ruby-core:78893] [Bug #13084] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@57843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									8edc6f4487
								
							
						
					
					
						commit
						a704e21fce
					
				
					 3 changed files with 32 additions and 6 deletions
				
			
		
							
								
								
									
										21
									
								
								rational.c
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								rational.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -2365,12 +2365,23 @@ read_num(const char **s, int numsign, int strict,
 | 
			
		|||
	    exp = rb_int_uminus(exp);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (numsign == '-')
 | 
			
		||||
    if (numsign == '-') {
 | 
			
		||||
	if (RB_TYPE_P(*num, T_RATIONAL)) {
 | 
			
		||||
	    *num = rb_rational_uminus(*num);
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
	    *num = rb_int_uminus(*num);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    if (!NIL_P(exp)) {
 | 
			
		||||
	VALUE l = f_expt10(exp);
 | 
			
		||||
	if (RB_TYPE_P(*num, T_RATIONAL)) {
 | 
			
		||||
	    *num = nurat_mul(*num, l);
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
	    *num = rb_int_mul(*num, l);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2395,9 +2406,15 @@ read_rat_nos(const char **s, int sign, int strict,
 | 
			
		|||
	(*s)++;
 | 
			
		||||
	if (!read_den(s, strict, &den))
 | 
			
		||||
	    return 0;
 | 
			
		||||
	if (!(FIXNUM_P(den) && FIX2LONG(den) == 1))
 | 
			
		||||
	if (!(FIXNUM_P(den) && FIX2LONG(den) == 1)) {
 | 
			
		||||
	    if (RB_TYPE_P(*num, T_RATIONAL)) {
 | 
			
		||||
		*num = nurat_div(*num, den);
 | 
			
		||||
	    }
 | 
			
		||||
	    else {
 | 
			
		||||
		*num = rb_int_div(*num, den);
 | 
			
		||||
	    }
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,4 +180,13 @@ class TestMathn < Test::Unit::TestCase
 | 
			
		|||
      assert_equal((-13/5), (-13/5).round(2, half: :down))
 | 
			
		||||
    EOS
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_rational
 | 
			
		||||
    assert_separately(%w[-rmathn], "#{<<-"begin;"}\n#{<<-"end;"}", ignore_stderr: true)
 | 
			
		||||
    begin;
 | 
			
		||||
      assert_equal(-5, "-5".to_r)
 | 
			
		||||
      assert_equal(1, "5/5".to_r)
 | 
			
		||||
      assert_equal(5, "5e0".to_r)
 | 
			
		||||
    end;
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#define RUBY_VERSION "2.4.0"
 | 
			
		||||
#define RUBY_RELEASE_DATE "2017-03-11"
 | 
			
		||||
#define RUBY_PATCHLEVEL 10
 | 
			
		||||
#define RUBY_PATCHLEVEL 11
 | 
			
		||||
 | 
			
		||||
#define RUBY_RELEASE_YEAR 2017
 | 
			
		||||
#define RUBY_RELEASE_MONTH 3
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue