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 #29827 is a reply to message #29822] Sat, 20 November 2010 20:55 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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;}


Regarding the image access: The img[y][x] is great, but still it would be nice to have a wrapper that would allow to put the arguments in (imho) more natural order. For example something like
RGBA* Image::Get(int x,int y){return (*this)[y][x];}


Best regards,
Honza
 
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: Thu May 16 22:05:34 CEST 2024

Total time taken to generate the page: 0.03125 seconds