[PATCH 02/27] Input: Add round_towards_zero helper

walter harms wharms at bfs.de
Fri Jun 3 10:33:26 PDT 2011


hi,
i see your point. my understand was fesetround() vs C99.
I am still happy with your solution.
My impression is that fesetround() was intended to change
all rounding behavier inside a program, not just a particular
function.

ntl: i never used that in the wild  :)

re,
 wh


Am 03.06.2011 18:14, schrieb Daniel Stone:
> Hi,
> 
> On Fri, Jun 03, 2011 at 06:04:34PM +0200, walter harms wrote:
>> C99 defines FE_TOWARDZERO, so any compiler that support c99 should work
>> with the example below.
> 
> Well ... there aren't many of those. :)
> 
> I had started with fesetround, but there were a couple of concerns:
>     - code density
>     - potentially missing a spot: you'd have to make sure every user was
>       correct, rather than just doing it in one place
>     - performance?
>     - thread safety: if we ever merge the input thread, then doing
>       fesetround() under people might make them deeply, deeply unhappy
>       and result in bizzare, impossible-to-debug errors.  Is
>       fesetround() thread-safe? Who knows, the manpage says nothing
>       about threads.
> 
>> ntl: i guess you code will work also with older compilers
> 
> See corrections in your code, which I think illustrates my point
> somewhat ...
> 
>> #include <stdio.h>
>> #include <fenv.h>
>> #include <math.h>
>>
>> /* gcc fesetround.c -lm -std=c99 */
>> int main()
>> {
>>   double ii;
>     int old_rounding = fegetround();
>>
>>   fesetround(FE_TOWARDZERO);
>>
>>   for(ii=-2.0;ii<2.0;ii+=0.2)
>>        printf("%f,nextint=%f\n",ii,nearbyint(ii));
> 
>     fesetround(old_rounding);
>>
>>   return 0;
>> }
> 
> Cheers,
> Daniel
> 


More information about the xorg-devel mailing list