Re: [AD] a fix struct for dallegro

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Monday 16 April 2007 08:13:30 am torhus@xxxxxxxxxx wrote:
> I could simply remove the floating point overloads of the operators.  So
> the only interaction between fixed and floats would be this:
>
> fix(2.5);       // static opCall, wraps ftofix()
> fix f = 2.5;    // same function as above is called here
> double d = f.toDouble();  // wrapper for fixtof()
>
> f + 2.5;       // error, no opAdd(double)
> f + fix(2.5);  // ok
> f = 2.5;       // error, no opAssign(double)
> f = fix(2.5);  // ok
>
> etc.
>
> Does this match your idea of explicit?

Then what does that gain over the fixed type and its functions? If all you're 
doing is a one-to-one member function wrap, why not just use the existing 
C-based functions?

double d = f.toDouble();
double d = fixtof(f);

f + fix(2.5);
f + ftofix(2.5);

f = fix(2.5);
f = ftofix(2.5);


Basically what I'm trying to avoid is something like this:

// Original:
float f = M_PI;
f /= 2.0;
// f is now quarter circle in radians

// Decides to use fixed
fix f = fix(M_PI);
f /= fix(2.0);
// f is now quarter circle, but fixed doesn't use radians. Expect problems!

Since all you had to do is change the type and add some casts, the user 
wouldn't know anything was wrong. It should be:

fixed f = fixmul(ftofix(M_PI), radtofix_r);
f = fixdiv(f, itofix(2));
// f is now quarter circle in allegro degrees, ready for use

That's my idea of explicit. Being able to just cast it all discourages users 
from reading the docs, missing important information.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/