Strogian
05-01-2004, 09:10 PM
I've got two options here:
#define hdiv(x,div) ((x-1+div)/div) /* x,div both integer types */
#define hdiv(x,div) (x/div + (x%div ? 1 : 0))
Which one is better? Or is there something even better than I haven't thought of?
I like the second one because it doesn't need the comment. It also is actually a bit easier to understand, I think.
first one: add, subtract, integer divide
second one: integer divide, cmp, jmp, mov, add? or div, cmp, jmp, add? something like that..
i'd say the first one is better directly...
then again, I don't know what it would get optimized into. It's pretty complicated. :D
#define hdiv(x,div) ((x-1+div)/div) /* x,div both integer types */
#define hdiv(x,div) (x/div + (x%div ? 1 : 0))
Which one is better? Or is there something even better than I haven't thought of?
I like the second one because it doesn't need the comment. It also is actually a bit easier to understand, I think.
first one: add, subtract, integer divide
second one: integer divide, cmp, jmp, mov, add? or div, cmp, jmp, add? something like that..
i'd say the first one is better directly...
then again, I don't know what it would get optimized into. It's pretty complicated. :D