List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:April 7 2008 5:54pm
Subject:Re: bk commit into 5.0 tree (kaa:1.2597) BUG#15936
View as plain text  
Hi Serg,

Sergei Golubchik wrote:
> Hi!
> 
> ok to push
> 
> On Mar 14, Alexey Kopytov wrote:
>> ChangeSet@stripped, 2008-03-14 13:25:37+03:00, kaa@kaamos.(none) +4 -0
>>   Fix for bug #15936: "round" differs on Windows to Unix
>>   
>>   Both of our own implementations of rint(3) were inconsistent with the
>>   most common behavior of rint() on those platforms that have it: round
>>   to nearest, break ties by rounding to nearest even.
> 
> perhaps we need to call fesetround() in mysqld to set
> rounding mode to nearest even explicitly ?
>    

Ok, better safe than sorry, added a call to fesetround() in the new patch.

>>   Fixed by leaving just one implementation of rint() in our source tree,
>>   and changing its behavior to match the most common native
>>   implementations on other platforms.
>>
>> diff -Nrup a/include/my_global.h b/include/my_global.h
>> --- a/include/my_global.h	2007-11-30 03:37:04 +03:00
>> +++ b/include/my_global.h	2008-03-14 13:25:36 +03:00
>> @@ -483,9 +483,42 @@ typedef unsigned short ushort;
>>  #define test_all_bits(a,b) (((a) & (b)) == (b))
>>  #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0
> : ((((type) 1) << (bit_count)) - (type) 1))
>>  #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
>> +
>>  #ifndef HAVE_RINT
>> -#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
>> -#endif
>> +/**
>> +  All integers up to this number can be represented exactly as double precision
>> +  values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
>> +*/
>> +#define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
>> +
>> +/**
>> +  rint(3) implementation for platforms that do not have it.
>> +  Always rounds to the nearest integer with ties being rounded to the nearest
>> +  even integer to mimic glibc's rint() behavior in the "round-to-nearest"
>> +  FPU mode. Hardware-specific optimizations are possible (frndint on x86).
>> +  Unlike this implementation, hardware will also honor the FPU rounding mode.
>> +*/
>> +
>> +inline double rint(double x)
> 
> use 'static inline'
> 

Done.

>> +{
>> +  double f, i;
>> +  f = modf(x, &i);
> 
> assuming, modf() is more portable than rint()...
> 

It seems to be. E.g. Windows doesn't have rint(), but does have modf().

Best regards,

-- 
Alexey Kopytov, Software Developer
MySQL AB, www.mysql.com

Are you MySQL certified?  www.mysql.com/certification
Thread
bk commit into 5.0 tree (kaa:1.2597) BUG#15936Alexey Kopytov14 Mar
  • Re: bk commit into 5.0 tree (kaa:1.2597) BUG#15936Sergei Golubchik31 Mar
    • Re: bk commit into 5.0 tree (kaa:1.2597) BUG#15936Alexey Kopytov7 Apr