| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi!
I've got a very performance important piece of code using integer divisions, so to speed it up I want to use ints whenever possible and long only when necessary. I get data in doubles. Is there any nifty way to do this in c++? Or do I need to check the value of the double and make a manual cast? Thanks! /Selene |
|
#2
|
||||
|
||||
|
To my knowledge, it's not possible to perform integer division without either using an integer variable, or manually casting it.
Depending on where your performance demands are, it might be best to simply convert the double to an integer before the operation.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#3
|
|||
|
|||
|
Thanks for responding so quickly! Perhaps I wasn't clear though. I did intend to cast it, but I would like to use ints when possible and long ints only when necessary, since it's quicker to do integer division on ints compared to long ints. So I was wondering if I could automatically get the right size of int, so to speak...?
/Selene |
|
#4
|
|||
|
|||
|
Use templates. Depending on the type argument passed, operation will be perfromed.
|
|
#5
|
|||
|
|||
|
Thank you, yes, that's what I will do.
/Selene |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > double to long/int |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|