Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Some new functions
Re: Some new functions [message #29870 is a reply to message #29827] Thu, 25 November 2010 16:43 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1371
Registered: December 2006
Ultimate Contributor
dolik.rce wrote on Sat, 20 November 2010 14:55

Fun fact: I tried to come up with optimal solution for Even() and all of the following appear to have same speed as the one from Koldo (with gcc optimal+speed flag):
inline bool even1(int val)		{return !(val&1);}
inline bool even2(int val)		{return ~val&1;}
inline bool even3(int val)		{return !(val%2);}

Without the speed flag even2() seems to be slightly faster.

Also val%2 and val&1 for Odd() yields the same speed in both cases Smile

However, the proposed RoundEven() function is suboptimal thanks to the branching. Even though it won't probably be used often, I would suggest faster version:
inline int roundeven(int val)	{return ((1+val)>>1)<<1;}
//for completeness also rounding to odd numbers:
inline int roundodd(int val)	{return ((val>>1)<<1)+1;}



Best regards,
Honza


Hi Honza,

I posted a link to a collection of optimized functions here http://www.ultimatepp.org/forum/index.php?t=msg&th=5683& amp;start=0&

It looks like it might be helpful for your experiments.


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to commit on svn ?
Next Topic: FileSel change
Goto Forum:
  


Current Time: Fri Nov 01 00:53:58 CET 2024

Total time taken to generate the page: 0.02207 seconds