Re: [AD] a fix struct for dallegro |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Sunday 15 April 2007 02:40:15 pm torhus@xxxxxxxxxx wrote:
> I don't know how useful this is. It was done in part to see how
> different from the C++ version it would be. It's based on allegro's C++
> fix class. But it sure simplifies fixed point calculations when you
> need them. Most of the my current implementation is attached. Most of
> the actual fix.d file is comprised of the unit test, which isn't
> complete yet. I can post the rest of the implementation when it's
> cleaned up a bit.
I'm not sure we really need to worry about a fix class. I'd even recommend
taking it out of Allegro proper, but we can't for compatibility reasons.
AFAIK, the reason for having a fixed type was because floats were too slow at
the time, if even available at all. The fixed type was made to use integers
in an efficient manner to do the same job as floats. This is generally not
the case anymore, as FPUs are much faster these days, but I'll still be the
first to admit there are uses for fixed types. However, I'd still be hesitant
in making them freely mixable with other number types.
IMO the fixed type should not be made transparent as the fix class makes
it. 'fixed's designed use is fundamentally different than floats (speed over
correctness), and it's use should be explicit, even outside of the scope of
casting. The difference is easilly apparent in the functions that take/return
Allegro Degrees instead of radians.
Being able to use fixed types the same way as floats is just asking for
problems, especially when users can be expected to mix types (float here,
fixed here for this tight loop, double here because I need the accuracy..).
People need to know the full ins-and-outs of the fixed type, and being able
to just change a few type names and add a couple casts encourages people to
be careless, which leads to errors and obscure bugs.
That's my opinion, anyway. I haven't liked the fix class ever since I found
out about it all those years ago, so I may be biased. :P