Aug 20, 2014
06:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 20, 2014
06:37 AM
Hi all,
How can I set Rounding mode for data type conversion (float to integer) ?
Is it possible?
(I use XMC4500)
Is it same as in http://www.infineonforums.com/threads/2096-float-data-type
??
BR
Koumak
How can I set Rounding mode for data type conversion (float to integer) ?
Is it possible?
float f_var = 1.6F;
int32_t i_var = 0;
i_var = (int32_t)f_var;
sometimes I need i_var == 1 another time I need i_var == 2
(I use XMC4500)
Is it same as in http://www.infineonforums.com/threads/2096-float-data-type
??
BR
Koumak
- Tags:
- IFX
1 Reply
Not applicable
Aug 20, 2014
07:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 20, 2014
07:42 AM
Hi Koumak,
One method for your example is to add 0.4 before casting if you want to round up...
But if you want anything above 0.5 to round up then add 0.5 first
Best regards
Aaron
One method for your example is to add 0.4 before casting if you want to round up...
i_var = (int32_t)(f_var + 0.4);
But if you want anything above 0.5 to round up then add 0.5 first
Best regards
Aaron