hm wrote:Thierry, not everyone is working one the same program as you do... ;-)
I do not follow you. My fixed class works very well in every program. It is also being used in our code base at work.
hm wrote:Take the example of normalizing a vector (i.e. without overflow): You probably have this function rather in your vector class than in your fixed point primitive. So how do you go about writing it in the implementation of the vector class?
Again I do not follow you. To normalize a vector, I just divide it by its length. All the maths are done using the fixed point class:
- Code:
struct Vector3
{
Fixed x,y,z;
void Normalize()
{
Fixed t = Fixed(1) / sqrt( x*x+y*y+z*z );
x *= t; y *= t; z *= t;
}
};
I am assuming all the operators are properly overloaded and sqrt() defined for Fixed. It works here anyways (+/- some precision issues that I haven't illustrated above).
hm wrote:Maybe the macros are good building blocks for that.
Macros are evil. Period. They should only be used for include guards and configuration (platform, compiler, etc). You don't need them for anything else in C++.
hm wrote:Or take a matrix inversion? Wouldn't that fit much better in a matrix class? How about color format conversion with correct rounding? I rather put this stuff in my color class than exploding the fixed point wrapper class.
Again just provide the proper operator overloads and you can use normal maths in any class you want (matrix, color, etc). I don't understand why/how your Fixed class would become bloated.
hm wrote:You asked why people use macros. These are the reasons I do: in many cases, there are better high-level abstractions,
They never are.
hm wrote:and using the primitive class is not always the best way to sufficient precision and performance.
Here I would agree. But using helper functions and/or closure constructs, you can solve these problems in a type-safe manner without resorting to macros.