3.11.2011

INCremenint, DECrementing, NOT(h)ing

I thought about how to archieve addition and substraction with a minimum of syntactical repetition to write and immediately remembered what I learned about the power of two complement. I knew that one day I'll benefit from knowing about it! Especially cause I started to think about making a mechanic arithmetic machine with Lego... HOWEVER, implementing a NOT for my 4 bit preprocessor toolset was quite beneficial: I remembered how you could avoid implementing a special subtraction command by NOTing the number you want to substract from something and then adding both. So it came to my mind that I should be able to effectively delete all increment macros by replacing it with such power of two complement "trick". It's essentially the same as ~((~num)+1)&15u in C/C++. I can create a decrement with it using nothing but the addition, it really decreases the amount of stuff one needs to write. Only thing bothering me at the moment is that you can't just namespace preprocessor macros. I began to use a prefix, but it looks so fucking ugly and hard to read... you also can't use so many character to seperate or distinguish the calls as it'll be inserted as a character then. I think as long as there's no reason to release it, I'll stick no prefix. I just dislike reading it, that's all. Makes stuff a lot harder to differentiate.

No comments: