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 |
|
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
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
|
|
|
|
|
Some new functions
By: koldo on Sat, 20 November 2010 01:01
|
|
|
Re: Some new functions
By: Didier on Sat, 20 November 2010 17:22
|
|
|
Re: Some new functions
|
|
|
Re: Some new functions
By: koldo on Sat, 20 November 2010 23:22
|
|
|
Re: Some new functions
By: koldo on Sun, 21 November 2010 00:05
|
|
|
Re: Some new functions
|
|
|
Re: Some new functions
By: koldo on Sun, 21 November 2010 08:26
|
|
|
Re: Some new functions
By: Novo on Thu, 25 November 2010 16:43
|
|
|
Re: Some new functions
By: mirek on Sat, 20 November 2010 18:07
|
|
|
Re: Some new functions
By: mr_ped on Mon, 22 November 2010 09:09
|
|
|
Re: Some new functions
By: mirek on Sat, 04 December 2010 20:38
|
|
|
Re: Some new functions
By: koldo on Sat, 04 December 2010 23:44
|
Goto Forum:
Current Time: Thu May 16 22:05:34 CEST 2024
Total time taken to generate the page: 0.03125 seconds
|