Are all the types you convert to integer types (It looks like it, given your "ideal" solution) ? If so, then the solution is trivial, and you won't be needing all this C/C++ boilerplate
Are all the types you convert to integer types (It looks like it, given your "ideal" solution) ? If so, then the solution is trivial, and you won't be needing all this C/C++ boilerplate
Last edited by Ronix; 06-10-2010 at 11:51 AM.
Stick close to your desks and never program a thing,
And you all may sit in the standards commitee!
Ah to dream.
The elements in the structures can be any of the following:
uint8_t
uint8_t * (Only one in all structures -- it is a user defined description)
uint16_t
uint32_t
float
double
So, along the lines your thinking, I could have just assigned an int to the data, then allow the type conversion to occur within the compiler, but nope, it ain't that simple. I have too many cases of floating point numbers to make this work right (that'd be: it is still the same amount of code either way).
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Altho it's hard to see how a design that you do not understand could be considered "simple to use". I totally followed Kennedy's original idea and don't see why he'd think there is some better option (altho it never hurts to ask).
Also, your maxim here totally ignores the question of expense. Switching from C to C++ just for this kind of screams "spend" to me.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Well, the interface is about as simple as it gets: pass a reference to the constructor, and then invoke the object like a function. Easy. If you're talking about the internals of the class, well, consider the STL - how many people *really* understand how it works? Not many!Altho it's hard to see how a design that you do not understand could be considered "simple to use".
Fortunately, in this day and age, the cost is (typically) pretty cheap.Also, your maxim here totally ignores the question of expense. Switching from C to C++ just for this kind of screams "spend" to me.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }