xboxscene.org forums

Author Topic: Datatype Float To Int/short Not Working?!  (Read 152 times)

Mios∞ft

  • Archived User
  • Full Member
  • *
  • Posts: 119
Datatype Float To Int/short Not Working?!
« on: May 09, 2008, 04:31:00 PM »

CODE
debugPrint("%g,%g\n",(((((float)(g_DefaultPad.sLThumbX+32767)/32767.0f)*100.0f)-100.0f)/100.0f)*255.0f,(((((float)(g_DefaultPad.sLThumbY+32767)/32767.0f)*100.0f)-100.0f)/100.0f)*255.0f);


Works,

However A VERY simple thing such as this show only extreme values  uhh.gif :

CODE
debugPrint("%d,%d\n",(int)(((((float)(g_DefaultPad.sLThumbX+32767)/32767.0f)*100.0f)-100.0f)/100.0f)*255.0f,(int)(((((float)(g_DefaultPad.sLThumbY+32767)/32767.0f)*100.0f)-100.0f)/100.0f)*255.0f);


Something wrong with FPU unit?
Logged

Mios∞ft

  • Archived User
  • Full Member
  • *
  • Posts: 119
Datatype Float To Int/short Not Working?!
« Reply #1 on: May 10, 2008, 07:50:00 AM »

CODE
sprintf("%.0f,%.0f",valx,valy);
 laugh.gif
Logged

obcd

  • Archived User
  • Hero Member
  • *
  • Posts: 881
Datatype Float To Int/short Not Working?!
« Reply #2 on: May 13, 2008, 03:25:00 AM »

Hi,

(int) is not really converting the floats. It is just telling the compiler to interpret them as integers.
Since integers and floating point numbers are stored on a totally different way, it is normal you get a strange result.
Casting is more a way to override the parameter check of a function, so it should be used carefully.

regards.
Logged