- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The problem with this code is it is restriced to multiplying in base 2. We can easily generalize it to be valid for any base:
Now you don't need to update your code every time you swap out your CPU for one in a different base.
Admin
Wouldn't simply n = -n be about the simplest, easiest to read, most language/compiler neutral and perhaps fastest way to go?
Admin
Admin
That why when comparing distances between coplaner points instead of the "sqrt(a^2+b^2) > c" that I used years ago, I use "a^2 + b^2 > c^2".
I would hope that compilers would generally optimize any divisions by a constant into a multiplication by the precomputed recipricol of the constant... but dividing by a variable would kill perf.
Admin
I can't believe it took so much code to perform such a basic task. Every fool knows how to do simple negation of a number.
All you have to do is implement elementary Peano numbers...
Then, it's nothing more than:
Ah, but this isn't enterprisey enough, and besides, it doesn't have enough LoC — I'm sure no company would buy that! Let's do it in Java...
... and to negate a number:
Easy as pie. All those geniuses in professional software development, and they couldn't even think up an obvious technique like that? shakes head sadly
P.S. Cookies to anyone who can work XML into the solution, for increased agile workflow synergy!
Admin
-(-LOL)
Admin
the solution is pretty obvious,
Admin
This made me think of The Millisecond Converter which I submitted a few years ago.
Admin
A lot of negativity in the responses today...
Admin
Admin
I am personally guilty of this, though not nearly to the same extent as the poor people who wrote the functions in this article...
I once did:
The most depressing part of it all for me was that I pride myself on successful and simple solutions to difficult problems with my programming (though negating a number is far from difficult >__>), and at the time this seriously seemed like the best way to negate a number. A colleague was looking through my code later and was like, "Dude, what's this? Just multiply by negative one." I did perhaps the biggest facepalm in the history of facepalms.