[PATCH] Bug in difftime() for H8300

J. Johnston jjohnstn@redhat.com
Tue Jan 21 19:40:00 GMT 2003


Patch applied.

-- Jeff J.

Anita Kulkarni wrote:
> Hi,
>  
> The current implementation of difftime() gives incorrect results for H8300.
> This is because of long int to double conversion. On H8300 double is of 4 bytes. 
> Hence for bigger integer values, the conversion of the integer to the double results
> in rounding off the value and so you get incorrect results from difftime.
> 
> Performing integer arithmetic and then converting result to double increases chances 
> of getting correct results.
> 
> The following patch first calculates the difference of time and then converts 
> the result to double. This should also help other targets where double is 32 bits.
> 
> -------------------------------------------------------------------------------
> 
>   2002-12-03  Anita Kulkarni  <anitak@kpit.com>
>   
>          * libc/time/difftime.c : Typecast the result to double.
>   
> 	  
> 	*** difftime.c.orig.txt	Tue Dec 10 16:03:08 2002
> 	--- difftime.c	Tue Dec 10 16:04:38 2002
> 	***************
> 	*** 40,45 ****
> 	  	time_t tim1 _AND
> 	  	time_t tim2)
> 	  {
> 	!   return ((double) tim1 - tim2);
> 	  }
> 	  
> 	--- 40,45 ----
> 	  	time_t tim1 _AND
> 	  	time_t tim2)
> 	  {
> 	!   return (double) (tim1 - tim2);
> 	  }
> 	   
> -----------------------------------------------------------------------------
> Regards,
> Anita Kulkarni
> 
> -----------------------------------------------------------------------------
> Free download of GNUSH and GNUH8 tool chains for Hitachi's SH and H8 Series.
> The following site also offers free support to European customers.
> Read more at http://www.kpit.com/products/support.htm
> Latest versions of GNUSH and GNUH8 are released on January 1, 2003.
> -----------------------------------------------------------------------------
> 
> 




More information about the Newlib mailing list