简体   繁体   中英

Java casting from float to int

I have this algorithm set (In my mind) which requires me to cast float to int many times in a loop(about 300 times for each 16 milli seconds) . My question is this:

How costly is process of casting from float to int in java/android and will it cause the game to slow down ?

Is it cheap enough to be implemented by my game? if not, what are the other options to convert decimal to integer?

Edit: Question solved!

A cast from float to int doesn't cost any more than any other assignment statement. It is handled by the hardware. An assignment (depending on the architecture) typically costs a single cycle or one trip through the pipeline (very, very fast). I wouldn't worry about the impact of this conversion on your performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM