« Previous entry | Next entry » Browse > Bad code

Skip to comments (1) ftoi conversion magic
Posted by cipher on Jul 25 2009 @ 04:53  :: 1149 unique visits

CODE: C
#define iman_ 0
const lreal _double2fixmagic = 68719476736.0*1.5;
const int32 _shiftamt        = 16;

static inline long Real2Int(double val)
{
        val = val + _double2fixmagic;
        //printf(\"%lf\", val); //if we print the results, all works without any flaw
        return ((int32*)&val)[iman_] >> _shiftamt;
}

//due to compiler optimizations the return fails
//warning: dereferencing type-punned pointer will break strict-aliasing rules
//how can i get this to work without turning off compiler optimizations in general?
 

1 comment posted so far
Add your own »

1. On Jan 05 2010 @ 15:22 uggbaileybutton wrote:

bailey button uggs

-ugg boots cheap

ugg boots uk

ugg classic

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: