mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* time.c: fix rounding negative float.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									accaa5ad3b
								
							
						
					
					
						commit
						1ef7022310
					
				
					 3 changed files with 29 additions and 0 deletions
				
			
		|  | @ -1,3 +1,7 @@ | |||
| Sat Jun 28 01:08:42 2008  Tanaka Akira  <akr@fsij.org> | ||||
| 
 | ||||
| 	* time.c (time_timeval): fix rounding negative float. | ||||
| 
 | ||||
| Fri Jun 27 21:38:57 2008  Tanaka Akira  <akr@fsij.org> | ||||
| 
 | ||||
| 	* struct.c: __size__ removed.  use the length of __members__ instead. | ||||
|  |  | |||
|  | @ -71,4 +71,25 @@ class TestTime < Test::Unit::TestCase | |||
|       assert_equal(Time.at(0x7fffffff), Time.at(-0x80000000) - (-0xffffffff)) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def test_at | ||||
|     assert_equal(100000, Time.at(0.1).usec) | ||||
|     assert_equal(10000, Time.at(0.01).usec) | ||||
|     assert_equal(1000, Time.at(0.001).usec) | ||||
|     assert_equal(100, Time.at(0.0001).usec) | ||||
|     assert_equal(10, Time.at(0.00001).usec) | ||||
|     assert_equal(1, Time.at(0.000001).usec) | ||||
|     assert_equal(0, Time.at(1e-7).usec) | ||||
|     assert_equal(0, Time.at(4e-7).usec) | ||||
|     assert_equal(1, Time.at(6e-7).usec) | ||||
|     assert_equal(1, Time.at(14e-7).usec) | ||||
|     assert_equal(2, Time.at(16e-7).usec) | ||||
|     if negative_time_t? | ||||
|       assert_equal(0, Time.at(-1e-7).usec) | ||||
|       assert_equal(0, Time.at(-4e-7).usec) | ||||
|       assert_equal(999999, Time.at(-6e-7).usec) | ||||
|       assert_equal(999999, Time.at(-14e-7).usec) | ||||
|       assert_equal(999998, Time.at(-16e-7).usec) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  |  | |||
							
								
								
									
										4
									
								
								time.c
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								time.c
									
										
									
									
									
								
							|  | @ -192,6 +192,10 @@ time_timeval(time, interval) | |||
| 	    double f, d; | ||||
| 
 | ||||
| 	    d = modf(RFLOAT(time)->value, &f); | ||||
|             if (d < 0) { | ||||
|                 d += 1; | ||||
|                 f -= 1; | ||||
|             } | ||||
| 	    t.tv_sec = (time_t)f; | ||||
| 	    if (f != t.tv_sec) { | ||||
| 		rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT(time)->value); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 akr
						akr