C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 13th, 2005, 01:19 PM
selene selene is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 selene User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 41 sec
Reputation Power: 0
Question double to long/int

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

Reply With Quote
  #2  
Old June 13th, 2005, 05:33 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
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.



Reply With Quote
  #3  
Old June 14th, 2005, 01:49 AM
selene selene is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 selene User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 41 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old June 14th, 2005, 01:05 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 275 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 45 m 43 sec
Reputation Power: 4
Use templates. Depending on the type argument passed, operation will be perfromed.
Comments on this post
B-Con agrees: I shudda thought of that

Reply With Quote
  #5  
Old June 14th, 2005, 11:50 PM
selene selene is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 selene User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 41 sec
Reputation Power: 0
Thank you, yes, that's what I will do.

/Selene

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > double to long/int


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway