mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	bignum.c: Bignum#fdiv avoids double division when divisor is bignum
`Rational(int, bignum).to_f` sometimes returned a wrong result because `Bignum#div` casted its divisor to double. [Bug #14637] [ruby-core:86330] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									ab73022cb2
								
							
						
					
					
						commit
						85bcd2b35f
					
				
					 2 changed files with 2 additions and 3 deletions
				
			
		
							
								
								
									
										4
									
								
								bignum.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								bignum.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -6178,9 +6178,7 @@ rb_big_fdiv_double(VALUE x, VALUE y)
 | 
			
		|||
	    return big_fdiv_int(x, rb_int2big(FIX2LONG(y)));
 | 
			
		||||
    }
 | 
			
		||||
    else if (RB_BIGNUM_TYPE_P(y)) {
 | 
			
		||||
	dy = rb_big2dbl(y);
 | 
			
		||||
	if (isinf(dx) || isinf(dy))
 | 
			
		||||
	    return big_fdiv_int(x, y);
 | 
			
		||||
	return big_fdiv_int(x, y);
 | 
			
		||||
    }
 | 
			
		||||
    else if (RB_FLOAT_TYPE_P(y)) {
 | 
			
		||||
	dy = RFLOAT_VALUE(y);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -837,6 +837,7 @@ class Rational_Test < Test::Unit::TestCase
 | 
			
		|||
  def test_to_f
 | 
			
		||||
    assert_equal(1.5, Rational(3,2).to_f)
 | 
			
		||||
    assert_equal(1.5, Float(Rational(3,2)))
 | 
			
		||||
    assert_equal(1e-23, Rational(1, 10**23).to_f, "Bug #14637")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_to_c
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue